def OnCommand(self, event): """ Catch commands and pass them along to the blocks. Our events have ids greater than wx.ID_HIGHEST Delay imports to avoid circular references. """ from osaf.framework.blocks.Block import Block wxID = event.GetId() if wxID > wx.ID_HIGHEST: block = Block.widgetIDToBlock (wxID) updateUIEvent = event.GetEventType() == wx.EVT_UPDATE_UI.evtType[0] try: blockEvent = block.event except AttributeError: """ Ignore blocks that don't have events. """ assert updateUIEvent else: arguments = {} if updateUIEvent: arguments ['UpdateUI'] = True else: try: arguments ['buttonState'] = event.GetEventObject().GetToolState (wxID) except AttributeError: pass block.post (blockEvent, arguments) if updateUIEvent: try: event.Check (arguments ['Check']) except KeyError: pass try: enable = arguments ['Enable'] except KeyError: enable = True event.Enable (enable) try: text = arguments ['Text'] except KeyError: pass else: event.SetText (text) widget = block.widget """ Some widgets, e.g. wxToolbarItems don't properly handle setting the text of buttons, so we'll handle it here by looking for the method OnSetTextEvent to handle it """ try: method = widget.OnSetTextEvent except AttributeError: pass else: method (event) else: event.Skip()
def OnCommand(self, event): """ Catch commands and pass them along to the blocks. Our events have ids greater than wx.ID_HIGHEST Delay imports to avoid circular references. """ from osaf.framework.blocks.Block import Block wxID = event.GetId() if wxID > wx.ID_HIGHEST: block = Block.widgetIDToBlock(wxID) updateUIEvent = event.GetEventType() == wx.EVT_UPDATE_UI.evtType[0] try: blockEvent = block.event except AttributeError: """ Ignore blocks that don't have events. """ assert updateUIEvent else: arguments = {} if updateUIEvent: arguments['UpdateUI'] = True else: try: arguments['buttonState'] = event.GetEventObject( ).GetToolState(wxID) except AttributeError: pass block.post(blockEvent, arguments) if updateUIEvent: try: event.Check(arguments['Check']) except KeyError: pass try: enable = arguments['Enable'] except KeyError: enable = True event.Enable(enable) try: text = arguments['Text'] except KeyError: pass else: event.SetText(text) widget = block.widget """ Some widgets, e.g. wxToolbarItems don't properly handle setting the text of buttons, so we'll handle it here by looking for the method OnSetTextEvent to handle it """ try: method = widget.OnSetTextEvent except AttributeError: pass else: method(event) else: event.Skip()