如何從我自己的代碼手動調用特定事件?wxPython:手動調用事件
回答
我想你想wx.PostEvent。
還有一些關於從long running tasks on the wxPython wiki其他帖子發佈活動的信息。
您的意思是你想要派遣活動?
:: wxPostEvent空隙 wxPostEvent(wxEvtHandler * DEST, wxEvent &事件)
在GUI應用程序,該功能 帖事件使用 wxEvtHandler :: AddPendingEvent指定DEST 對象。 否則,它立即使用 wxEvtHandler :: ProcessEvent調度事件 。有關詳細信息,請參閱 相關文檔 (和注意事項)。
包含文件
<wx/app.h>
老話題,但我想我已經弄清了很長一段時間了,所以如果有其他人通過這裏尋找答案,這可能會有所幫助。
手動方式發佈事件,您可以使用
self.GetEventHandler().ProcessEvent(event)
(wxWidgets的文檔here,wxPython的文檔here)
或
wx.PostEvent(self.GetEventHandler(), event)
(wxWidgets docs,wxPython docs)
其中event
是您要發佈的活動。用例如事件構建事件
wx.PyCommandEvent(wx.EVT_BUTTON.typeId, self.GetId())
如果您想發佈EVT_BUTTON事件。使其成爲PyCommandEvent意味着它會向上傳播;其他事件類型默認情況下不會傳播。
您還可以創建自定義事件,以便隨身攜帶任何您想要的數據。這裏有一個例子:!
myEVT_CUSTOM = wx.NewEventType()
EVT_CUSTOM = wx.PyEventBinder(myEVT_CUSTOM, 1)
class MyEvent(wx.PyCommandEvent):
def __init__(self, evtType, id):
wx.PyCommandEvent.__init__(self, evtType, id)
myVal = None
def SetMyVal(self, val):
self.myVal = val
def GetMyVal(self):
return self.myVal
(我想我發現在某處的郵件列表歸檔這個代碼,但我似乎無法再找到它,如果這是你的榜樣,謝謝請添加評論和採取信用!)
所以,現在,上傳自定義事件:
event = MyEvent(myEVT_CUSTOM, self.GetId())
event.SetMyVal('here is some custom data')
self.GetEventHandler().ProcessEvent(event)
,你可以綁定它就像任何其他事件
self.Bind(EVT_CUSTOM, self.on_event)
,並在事件處理程序獲取自定義數據
def on_event(self, e):
data = e.GetMyVal()
print 'custom data is: {0}'.format(data)
或者在事件構造函數中包含自定義數據並保存一個步驟:
class MyEvent(wx.PyCommandEvent):
def __init__(self, evtType, id, val = None):
wx.PyCommandEvent.__init__(self, evtType, id)
self.myVal = val
等
希望這是有幫助的人。
有一個簡單,直接的方式與wxPython中的最新版本(見http://wiki.wxpython.org/CustomEventClasses)做到這一點:
# create event class
import wx.lib.newevent
SomeNewEvent, EVT_SOME_NEW_EVENT = wx.lib.newevent.NewEvent()
# post it, with arbitrary data attached
wx.PostEvent(target, SomeNewEvent(attr1=foo, attr2=bar))
# bind it as usual
target.Bind(EVT_SOME_NEW_EVENT, target.handler)
- 1. 如何解決調用的wxpython事件?
- 2. 手動調用事件處理程序
- 3. 如何手動觸發wx.Frame關閉事件(wxPython)?
- 4. 用於panel.Show()的wxpython事件
- 5. 手動調度集合變化事件
- 6. 如何手動調度hashchange事件
- 7. wxPython插入符號移動事件
- 8. 手動調用組件的檢票事件處理程序
- 9. 如何手動調用事件時使用event.dataTransfer設置數據?
- 10. 查找wxpython事件文檔
- 11. wxpython按鈕按下事件
- 12. wxPython的事件多類
- 13. wxpython中的事件處理
- 14. wxpython遊標關閉事件?
- 15. 綁定菜單事件wxpython
- 16. 在wxPython中處理事件
- 17. wxPython:在面板更新上未調用的onPaint事件
- 18. wxPython字典的類他們調用的事件
- 19. wxPython的 - 手動調整內部分級機
- 20. 如何調用jQuery的單擊事件手動
- 21. C# - RadGrid - 如何手動調用ItemDatabound事件?
- 22. 有沒有辦法手動調用鼠標事件?
- 23. 如何在iPhone上手動調用UIView的觸摸事件?
- 24. 如何在C#中手動調用事件?
- 25. 調用dropdownlist手動選擇索引更改事件
- 26. Javascript手動重設事件
- 27. C#激活手動事件
- 28. 手動觸發LocationListener事件
- 29. 手動提高ContextMenuClosing事件
- 30. ReactiveCocoa:手動發送事件
我不知道C,這是令人困惑的。你能給我我應該運行的Python系列嗎? – 2009-04-14 14:38:54