xvalue for strings?

NMODL and the Channel Builder.
Post Reply
Annik
Posts: 27
Joined: Fri Sep 07, 2012 1:02 pm

xvalue for strings?

Post by Annik »

Hi, I was wondering if it is possible to create a field editor like xvalue, but which takes a string input like a file name. I'm trying to create a prompt window which asks the user to specify a binary file to be read in before running the simulation. Is such a thing possible?

Thanks,
Annik
ted
Site Admin
Posts: 5810
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: xvalue for strings?

Post by ted »

Good question. Use the File class's chooser() method; documented in the Programmer's Reference.
Annik
Posts: 27
Joined: Fri Sep 07, 2012 1:02 pm

Re: xvalue for strings?

Post by Annik »

Great, I got a button to bring up a window to choose a file using the following code (as per the programmer's reference):

Code: Select all

	
objref TC_f
TC_f = new File()

proc read_TC() {
		TC_f.chooser("r", "Select a File to Read", "*.txt", "Execute")
		if (TC_f.chooser()) {
			str = TC_f.getname(str)
			xopen(str)
		}
	}	
With

Code: Select all

xbutton("Choose A File...", "read_TC()")
in the code for the prompt window where the user specifies parameters for a simulation.

But when I choose a file, I get an error saying "Expecting string argument" - I thought the name of the file selected is the string argument given to the TC_f.chooser() ?
What has gone wrong here?

Thanks,
Annik
Annik
Posts: 27
Joined: Fri Sep 07, 2012 1:02 pm

Re: xvalue for strings?

Post by Annik »

Got it. The code below works:

Code: Select all

	proc read_TC() {
		TC_file_loc.chooser("", "Choose a File to Read", "*.txt", "Execute")
		if (TC_file_loc.chooser()) {
			strdef str
			str = TC_file_loc.getname()
			TC_read.ropen(str)
		}
	}	
ted
Site Admin
Posts: 5810
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: xvalue for strings?

Post by ted »

That does work, but it's a bit longer and more involved than it has to be, because it's based on the example for the workaround for the fact that the "x" style ("select and open a file for execution") is not implemented. For those who only need to read or write a file, something like this simpler example is sufficient:

Code: Select all

objref f
f = new File()
proc read_TC() {
  f.chooser("r", "Choose a File to Read", "*.txt", "Select")
  if (f.chooser()) { // clicking on the "Select" button makes f.chooser return 1
    f.ropen()
//    print "opened ", f.getname(), "for reading" // optional, for debugging
  }
}
Post Reply