DirectOptionMenu Problem (Bug?)

hi,

depending on the setup of a DirectOptionMenu, i can get a traceback or all is fine:

following setup gives the traceback below:

       self.layers[self.activeLayer] = [<some list of strings>]
       self.activeModel = 0
    
       ...

       self.modelSelector = DirectOptionMenu(
            pos = (0.6, 0, -0.18),
            scale = 0.05, 
            items = self.layers[self.activeLayer], 
            initialitem = self.activeModel,
            highlightColor = (0.65, 0.65, 0.65, 1),
            command = self.changeActiveModel,
            textMayChange = 1,
            )

the traceback happens when i later change the ‘items’ configuration of the active modelSelector DirectOptionMenu, like this:

        self.modelSelector['items'] = self.layers[self.activeLayer]

now if i change the setup and remove the ‘initialitem’ configuration like this…

       self.modelSelector = DirectOptionMenu(
            pos = (0.6, 0, -0.18),
            scale = 0.05, 
            items = self.layers[self.activeLayer], 
            highlightColor = (0.65, 0.65, 0.65, 1),
            command = self.changeActiveModel,
            textMayChange = 1,
            )

… all is fine!

i believe the code block in DirectOptionMenu.py (lines #153-#158)

        # Determine what initial item to display and set text accordingly
        if self['initialitem']:
            self.set(self['initialitem'], fCommand = 0)
        else:
            # No initial item specified, just use first item
            self.set(0, fCommand = 0)

is called to early (still taking the last items list with the last initialvalue into account) and is not reseted correctly when a new list is set for the DirectOptionMenu. this only happens if ‘initialitem’ is set at creation time.

interestingly enough i can’t set ‘initialitem’ after the creation of the DirectOptionMenu (only getting a ‘Cannot configure initialisation option “initialitem” for DirectOptionMenu’ message in the console window), so i can’t influence through setting a valid ‘initialitem’ value.

i have a workaround now (just do no set ‘initialitem’ at creation time), but i believe this is a bug nonetheless.

hth,
kaweh

traceback:

  File "/Users/kaweh/Projects/MyProject/Editor.py", line 109, in changeActiveLayer
    self.modelSelector['items'] = self.layers[self.activeLayer]
  File "/usr/local/panda/lib/direct/gui/DirectGuiBase.py", line 430, in __setitem__
    apply(self.configure, (), {key: value})
  File "/usr/local/panda/lib/direct/gui/DirectGuiBase.py", line 426, in configure
    func()
  File "/usr/local/panda/lib/direct/gui/DirectOptionMenu.py", line 155, in setItems
    self.set(self['initialitem'], fCommand = 0)
  File "/usr/local/panda/lib/direct/gui/DirectOptionMenu.py", line 268, in set
    item = self['items'][self.selectedIndex]
IndexError: list index out of range