Python and Phidgets: want to send event/message from object to its parent -


i have phidgets stepper controller (stepper class) , allows event handlers methods of class:

self.setonattachhandler(self.stepperattached) self.setondetachhandler(self.stepperdetached) 

these useful can perform tasks when stepper controller attached/detached pc.

i have created stepper object in wxframe in python , know how send messages wxframe can, example, indicated controller has been attached/dettached without polling.

or in general, how send events/messages object parent in python?

thanks!

the canonical way pass reference of parent object down children.

from phidgets.devices.stepper import stepper  class parent(object):     "parent class"      def stepperattached(self, event):         print 'connected device ', event.device.getserialnum()      def eventhandler (self, event):         print "event fired!", event.state  class child(object):     "child class"      def __init__(self, parent):         self.parent = parent         self.stepper =  stepper()         self.stepper.setonattachhandler(self.parent.stepperattached)         self.stepper.setoninputchangedhandler(self.parent.eventhandler)  p = parent() c = child(p) c2 = child(p) # etc.. 

hopefully helps. code might not quite accurate, don't have reference handy, principal same if code above off.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -