Page 1 of 1

passing strdef from python and List.browser

Posted: Wed Mar 07, 2012 5:39 pm
by ramcdougal
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!

Re: passing strdef from python and List.browser

Posted: Fri Mar 09, 2012 1:13 pm
by ramcdougal
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_)