2009-07-14 11 views

答えて

6

wx.CommandEventオブジェクトを作成し、settersを呼び出して適切な属性を設定し、wx.PostEventに渡します。

http://docs.wxwidgets.org/stable/wx_wxcommandevent.html#wxcommandeventctor

http://docs.wxwidgets.org/stable/wx_miscellany.html#wxpostevent

これは重複して、より多くの情報は、これらのオブジェクトを構築する上でここにあります:

wxPython: Calling an event manually

+0

あなたは私のより詳細な説明を与えるだろうか?私は実際に初心者以上のものではありません。また、答えに感謝します。 –

9

のWikiは参照のためにかなりいいです。 Andrea Gavanaには、自分自身を構築するための完全なレシピがありますcustom controls。以下は、そこから直接採取し(ノート自己wx.PyControlのサブクラスを参照している)何FogleBird answered with延びている。

def SendCheckBoxEvent(self): 
    """ Actually sends the wx.wxEVT_COMMAND_CHECKBOX_CLICKED event. """ 

    # This part of the code may be reduced to a 3-liner code 
    # but it is kept for better understanding the event handling. 
    # If you can, however, avoid code duplication; in this case, 
    # I could have done: 
    # 
    # self._checked = not self.IsChecked() 
    # checkEvent = wx.CommandEvent(wx.wxEVT_COMMAND_CHECKBOX_CLICKED, 
    #        self.GetId()) 
    # checkEvent.SetInt(int(self._checked)) 
    if self.IsChecked(): 

     # We were checked, so we should become unchecked 
     self._checked = False 

     # Fire a wx.CommandEvent: this generates a 
     # wx.wxEVT_COMMAND_CHECKBOX_CLICKED event that can be caught by the 
     # developer by doing something like: 
     # MyCheckBox.Bind(wx.EVT_CHECKBOX, self.OnCheckBox) 
     checkEvent = wx.CommandEvent(wx.wxEVT_COMMAND_CHECKBOX_CLICKED, 
            self.GetId()) 

     # Set the integer event value to 0 (we are switching to unchecked state) 
     checkEvent.SetInt(0) 

    else: 

     # We were unchecked, so we should become checked 
     self._checked = True 

     checkEvent = wx.CommandEvent(wx.wxEVT_COMMAND_CHECKBOX_CLICKED, 
            self.GetId()) 

     # Set the integer event value to 1 (we are switching to checked state) 
     checkEvent.SetInt(1) 

    # Set the originating object for the event (ourselves) 
    checkEvent.SetEventObject(self) 

    # Watch for a possible listener of this event that will catch it and 
    # eventually process it 
    self.GetEventHandler().ProcessEvent(checkEvent) 

    # Refresh ourselves: the bitmap has changed 
    self.Refresh() 
関連する問題