Python wx.PyEventBinder() Examples

The following are 5 code examples of wx.PyEventBinder(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module wx , or try the search function .
Example #1
Source File: Core.py    From EventGhost with GNU General Public License v2.0 6 votes vote down vote up
def _CommandEvent():
    """Generate new (CmdEvent, Binder) tuple
        e.g. MooCmdEvent, EVT_MOO = EgCommandEvent()
    """
    evttype = wx.NewEventType()

    class _Event(wx.PyCommandEvent):
        def __init__(self, id, **kw):
            wx.PyCommandEvent.__init__(self, evttype, id)
            self.__dict__.update(kw)
            if not hasattr(self, "value"):
                self.value = None

        def GetValue(self):
            return self.value

        def SetValue(self, value):
            self.value = value

    return _Event, wx.PyEventBinder(evttype, 1) 
Example #2
Source File: core.py    From wafer_map with GNU General Public License v3.0 5 votes vote down vote up
def _EvtHandler_Bind(self, event, handler, source=None, id=wx.ID_ANY, id2=wx.ID_ANY):
    """
    Bind an event to an event handler.
    
    :param event: One of the ``EVT_*`` event binder objects that
                  specifies the type of event to bind.
    
    :param handler: A callable object to be invoked when the
                    event is delivered to self.  Pass ``None`` to
                    disconnect an event handler.
    
    :param source: Sometimes the event originates from a
                   different window than self, but you still
                   want to catch it in self.  (For example, a
                   button event delivered to a frame.)  By
                   passing the source of the event, the event
                   handling system is able to differentiate
                   between the same event type from different
                   controls.
    
    :param id: Used to spcify the event source by ID instead
               of instance.
    
    :param id2: Used when it is desirable to bind a handler
                to a range of IDs, such as with EVT_MENU_RANGE.
    """
    assert isinstance(event, wx.PyEventBinder)
    assert callable(handler) or handler is None
    assert source is None or hasattr(source, 'GetId')
    if source is not None:
        id  = source.GetId()
    event.Bind(self, id, id2, handler) 
Example #3
Source File: widgets.py    From youtube-dl-gui with The Unlicense 5 votes vote down vote up
def __init__(self, parent, id=wx.ID_ANY, value="", pos=wx.DefaultPosition,
            size=wx.DefaultSize, choices=[], style=0, validator=wx.DefaultValidator, name=NAME):
        super(CustomComboBox, self).__init__(parent, id, pos, size, 0, name)

        assert style == self.CB_READONLY or style == 0

        # Create components
        self.textctrl = wx.TextCtrl(self, wx.ID_ANY, style=style, validator=validator)
        tc_height = self.textctrl.GetSize()[1]

        self.button = wx.Button(self, wx.ID_ANY, "▾", size=(tc_height, tc_height))

        # Create the ListBoxPopup in two steps
        self.listbox = ListBoxPopup(self)
        self.listbox.Init()
        self.listbox.Create(self.listbox)

        # Set layout
        sizer = wx.BoxSizer()
        sizer.Add(self.textctrl, 1, wx.ALIGN_CENTER_VERTICAL)
        sizer.Add(self.button)
        self.SetSizer(sizer)

        # Bind events
        self.button.Bind(wx.EVT_BUTTON, self._on_button)

        for event in ListBoxPopup.EVENTS_TABLE.values():
            self.listbox.Bind(wx.PyEventBinder(event.GetEventType()), self._propagate)

        # Append items since the ListBoxPopup does not have the 'choices' arg
        self.listbox.GetControl().AppendItems(choices)
        self.SetStringSelection(value) 
Example #4
Source File: controlcontainer.py    From admin4 with Apache License 2.0 5 votes vote down vote up
def _bind(self, ctlName, evt=None, proc=None):
    if isinstance(ctlName, wx.PyEventBinder): # binding to self
      ctl=super(wx.Window, self)
      proc=evt
      evt=ctlName
    elif isinstance(ctlName, wx.Window):
      ctl=ctlName
    else:
      ctl=self[ctlName]

    if not proc:
      if not isinstance(evt, wx.PyEventBinder):
        proc=evt
        evt=None
      if not proc:
        proc=self.OnCheck

    if not evt:
      if isinstance(ctl, wx.Button):
        evt=wx.EVT_BUTTON
      elif isinstance(ctl, wx.CheckBox):
        evt=wx.EVT_CHECKBOX
      elif isinstance(ctl, wx.CheckListBox):
        evt=wx.EVT_CHECKLISTBOX
      elif isinstance(ctl, wx.RadioButton):
        evt=wx.EVT_RADIOBUTTON
      else:
        evt=wx.EVT_TEXT
        if isinstance(ctl, wx.ComboBox):
          ctl.Bind(wx.EVT_COMBOBOX, proc)
    ctl.Bind(evt, proc) 
Example #5
Source File: OLVEvent.py    From bookhub with MIT License 5 votes vote down vote up
def _EventMaker():
    evt = wx.NewEventType()
    return (evt, wx.PyEventBinder(evt))