passing strdef from python and List.browser

When Python is the interpreter, what is a good
design for the interface to the basic NEURON
concepts.

Moderator: hines

Post Reply
ramcdougal
Posts: 153
Joined: Fri Nov 28, 2008 3:38 pm
Location: Yale School of Medicine

passing strdef from python and List.browser

Post by ramcdougal » Wed Mar 07, 2012 5:39 pm

Is there a way to work with strdefs in the abstract in python without them being evaluated to a particular value?

For example, the List object's browser method takes a strdef and a function that is called repeatedly which is supposed to change the strdef to define list labels.

In the following code, it seems that gui_string_ is being copied instead of passed by reference, so the List browser does not see the changes. (All items are named "initial")

Code: Select all

from neuron import h, gui

h('strdef gui_string_')
h('gui_string_ = "initial"')

def name_it():
    h('gui_string_ = "obj %d"' % h.hoc_ac_)

listbox = h.List()
for i in xrange(3):
    listbox.append(h.Random())
listbox.browser('title', h.gui_string_, 'nrnpython("name_it()")')
Using HOC to call the browser method works correctly (Items are named "obj 0", "obj 1", and "obj 2"):

Code: Select all

from neuron import h, gui 

h('strdef gui_string_')
h('gui_string_ = "initial"')

def name_it():
    h('gui_string_ = "obj %d"' % h.hoc_ac_)

listbox = h.List()
h('objref listbox')
h.listbox = listbox
for i in xrange(3):
    listbox.append(h.Random())
h('listbox.browser("title", gui_string_, "nrnpython(\\"name_it()\\")")')
Is there a way to do the same thing in pure python (ie no HOC)? Thanks!

ramcdougal
Posts: 153
Joined: Fri Nov 28, 2008 3:38 pm
Location: Yale School of Medicine

Re: passing strdef from python and List.browser

Post by ramcdougal » Fri Mar 09, 2012 1:13 pm

Pure Python version, thanks to mctavish:

Code: Select all

from neuron import h, gui

listbox = h.List()
for i in xrange(3):
    listbox.append(h.Random())
listbox.browser('title', lambda: 'obj %d' % h.hoc_ac_)

Post Reply