def onExit(self, event): print "debug1" log.write('Exiting application') # let twisted reactor shut down first ... reactor.addSystemEventTrigger('after', 'shutdown', self.Close, True) reactor.stop()
def _getDeviceMapSuccess(self, devicemap, connector): log.write("TwistedBridge Connector(%s,%s) received devicemap: %s" % (connector.host, connector.port, devicemap)) for devicetype, devicelist in devicemap.items(): for device in devicelist: log.write("\tPosting WXEvent adding '%s' (%s)" % (device, devicetype)) event = self.eventregistry.createEvent("addDevice") event.devicetype = devicetype event.device = device PostEvent(self.wxbridge, event) self.devicetypemap[device] = devicetype self.deviceconnectormap[device] = connector
def __init__(self, parent, id, title): # baseclass constructor WXBridge.__init__( self, parent, id, title) # configure menu bar (also sets the local onExit callback) self.SetMenuBar( MenuBar(self) ) self.CreateStatusBar() # notebook with one tab per device type, e.g., 'Cameras', 'Projectors' log.write('Creating TabbedNotebook') self.notebook = DeviceNotebook(self, -1, self) self.Layout() # super-duper important .... reactor.interleave(wx.CallAfter)
def onAbout(self, event): log.write("About dialog activated") d = wx.MessageDialog(self, MenuBar._about, "AGDeviceControl client %s" % version.version, wx.OK) d.ShowModal() log.write("About dialog closed") d.Destroy()
def _addConnectorFailure(self, failure, connector): log.write( "TwistedBridge Connector(%s,%d) failed to connect, redetectHeartbeat" % (connector.host, connector.port) ) self.monitor.redetectHeartbeat(connector.host)
def _addConnectorSuccess(self, connector): log.write("TwistedBridge Connector(%s,%d) connected successfully" % (connector.host, connector.port)) connector.notifyOnDisconnect(self._onConnectionDropped) connector.getDeviceMap(self._getDeviceMapSuccess)
def addConnector(self, host, port, passwd): """Attempt connection to Aggregator, notification via callback""" log.write("TwistedBridge attempting Connector(%s,%d)" % (host, port)) connector = Connector(host, port) connector.connect(self._addConnectorSuccess, errback=self._addConnectorFailure, password=passwd)
def commandResult(self, event): log.write("WXBridge: %s.%s(%s) = %s" % (event.device, event.command, event.parameters, event.returnvalue)) cb = self.callables[(event.device, event.command, event.parameters)].pop(0) if cb: cb(event.returnvalue)
def removeDevice(self, event): log.write("WXBridge.removeDevice: %s" % event.device) self.notebook.removeDevice(event.device, event.devicetype)
def addDevice(self, event): log.write("WXBridge.addDevice: %s %s" % (event.device, event.devicetype)) self.notebook.addDevice(event.device, event.devicetype)