events - Threading wxPython app with background process for multitouch detection -


so have code multitouch detection , run separate thread sends custom events wxpython gui upon multitouch event.

now post code multitouch tracking use require trackpad, server app , detection code, think it's better consider simple example sake of question.

so example lets assume event simulator sending event every 10 seconds:

import wx import wx.lib.newevent import time  multitouchevent, evt_multitouch = wx.lib.newevent.newevent()  class eventsimulator:      def __init__(self):         self.eventdata = 0      def start(self):         self.runtuio()      def runtuio(self):          while true:             time.sleep(10)             wx.postevent(gui, multitouchevent(self.eventdata))             self.eventdata += 1  if __name__ == '__main__':      multitouchtracker = eventsimulator()      multitouchtracker.start() 

now receive these events whenever occur within wxpython gui (something this):

import wx  class frame(wx.frame):      def __init__(self, title):          wx.frame.__init__(self, none, title=title, size=(350,200))          self.bind(evt_multitouch, self.handler)       def handler(self, event):          data = event.data,           print data  if __name__ == '__main__':      app = wx.app(redirect=false)     window = frame("my basic gui")     window.show()     app.mainloop() 

the problem cannot workout how combine these 2 pieces of code working example. understand need run event simulator separate thread within gui code. please can explain how this, thanks!

for details on multi-threading in python see docs threading module in stock python library. there example of using in gui in threads module in wxpython demo, although there other viable approaches well. (deriving thread class instead of using one, etc.) demo module shows convenient way make new event class , binder using wx.lib.newevent module.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -