I am getting an error.
newsink AttributeError: '<AlphaListBoxsetup object>' has no attribute
'onalphaItemSelected'
class AlphaListBoxsetup(SimplePanel):
def __init__(self):
SimplePanel.__init__(self)
self.list1=ListBox()
self.list1.setVisibleItemCount(8)
A.alpha.sort()
for item in A.alpha:
self.list1.addItem(item)
self.add(self.list1)
self.list1.addChangeListener(getattr(self, 'onalphaItemSelected'))
def generic(self):
item = self.list1.getItemText(self.list1.getSelectedIndex())
Window.alert("You selected %s from the stack Alphabetic" %(item))
generic.__name__ = 'onalphaItemSelected'
locals()['onalphaItemSelected'] = generic
is the relevant code. Of course, with the def generic() line changed to
def onalphaItemSelected(), it works just fine.
I have a situation where I do not know until runtime how many listboxes
with selections I need to produce. This may be an area where Python will
and Pyjs won't, but in Python that code should allow the generation of
functions with names set from strings. Immediate mode example follows:
>>>> def generic(x):
.... return x**2
....
>>>> globals()['squareit']=generic
>>>> squareit(25)
625
>>>> def generic(x):
.... return x**3
....
>>>> globals()['cubeit']=generic
>>>> squareit(25)
625
>>>> cubeit(25)
15625
>>>>
This allows the definition of functions whose names are generated by code
without resorting to metaprogramming with exec, but it seems not to work in
Pyjs.
Any suggestions for accomplishing this? I have a group of scripts to be
picked to be part of a workflow, and I have one list where they are in
alphabetical order, then another list of those used most frequently, then
another list of those concerned with just alignment, and so on. Many tags
are possible and more functional tags may be added to the script nodes at
any time, so when the list of scripts is pulled from the database, the tags
are basically a list for each script that defines every folder in which the
script name should appear. I have no difficulty generating that on the
controller, but when I shoot that information over as a JSON object, I have
to manufacture a stack panel full of lists and allow one choice from one
selected list.
Michael
--