本文整理汇总了Python中system.mbus.Bus.subscribe方法的典型用法代码示例。如果您正苦于以下问题:Python Bus.subscribe方法的具体用法?Python Bus.subscribe怎么用?Python Bus.subscribe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类system.mbus.Bus
的用法示例。
在下文中一共展示了Bus.subscribe方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from system.mbus import Bus [as 别名]
# 或者: from system.mbus.Bus import subscribe [as 别名]
def __init__(self, glade_file, testing=False):
self.testing=testing
self.builder = gtk.Builder()
self.builder.add_from_file(glade_file)
self.dialog = self.builder.get_object("config_dialog")
self.dialog._testing=testing
self.dialog._builder=self.builder
self.mb_proxy_detected=False
self.lb_proxy_detected=False
signals={"visibility-notify-event": self.on_show,
"on_show": self.on_show,
"on_close_clicked": self.on_close_clicked,
"on_config_dialog_destroy": self.on_config_dialog_destroy}
self.builder.connect_signals(signals, self)
Bus.subscribe("Config", "musicbrainz_proxy_detected", self.on_musicbrainz_proxy_detected)
示例2: __init__
# 需要导入模块: from system.mbus import Bus [as 别名]
# 或者: from system.mbus.Bus import subscribe [as 别名]
def __init__ (self):
rb.Plugin.__init__ (self)
self.active=None
self.current_entry=None
self.dbcount=0
self.load_complete=False
self.done=False
self.db=None
self.type_song=None
self.start_phase=True
self.current_entries_count=0
self.previous_entries_count=0
self.song_entries={}
self.sourcescb=[]
Bus.subscribe(self.BUSNAME, "devmode?", self.hq_devmode)
Bus.subscribe(self.BUSNAME, "appname?", self.hq_appname)
Bus.subscribe(self.BUSNAME, "__tick__", self.h_tick)
示例3: _hlogpath
# 需要导入模块: from system.mbus import Bus [as 别名]
# 或者: from system.mbus.Bus import subscribe [as 别名]
def _hlogpath(self, name, path):
self._path=path
self._name=name
self._setup()
def _hlog(self, *arg):
if self._shutdown:
return
if self._logger is None:
self._setup()
if len(arg) == 1:
self._logger.log(logging.INFO, arg[0])
else:
level=self.mlevel.get(arg[0], logging.INFO)
self._logger.log(level, arg[1])
def _hshutdown(self, *arg):
self._shutdown=True
self._logger=None
logging.shutdown([self.fhdlr])
_log=Logger()
Bus.subscribe("%log", _log._hlog)
Bus.subscribe("%logpath", _log._hlogpath)
Bus.subscribe("shutdown", _log._hshutdown)
示例4: serial
# 需要导入模块: from system.mbus import Bus [as 别名]
# 或者: from system.mbus.Bus import subscribe [as 别名]
except:
Bus.publish(self, "%log", "warning",
"Cannot find previsouly registered device, serial(%s)" % serial)
def _hdevice(self, details):
""" %device - local message handler
"""
dtype=details.get("type", None)
if dtype!="PhidgetInterfaceKit":
return
serial=details.get("serial", None)
entry=self._devices.get(serial, {})
if not entry:
Bus.publish(self, "%log", "Found IFK device, serial(%s)" % serial)
Bus.publish(self, "%attached", details)
try: device=IfkAgent(self._q, serial)
except: device=None
if device:
self._devices[serial] = device
## =====================================================================
_ifkManager=IfkManager()
Bus.subscribe("%device", _ifkManager._hdevice)
Bus.subscribe("%detached", _ifkManager._hdetached)
Bus.subscribe("%poll", _ifkManager._hpoll)
示例5: validateConfig
# 需要导入模块: from system.mbus import Bus [as 别名]
# 或者: from system.mbus.Bus import subscribe [as 别名]
return
self.validateConfig(config)
def validateConfig(self, config):
""" Validates (as much as possible) the configuration information
before handing it off
Categories: "States", "Devices"
Pins: integer
"""
for param in self.PARAMS:
try: _value=config[param]
except:
self.log("warning", "Missing '%s' entry in configuration file(%s)" % (param, self.cpath))
self.usedefaults()
return
self.config=config
self.log("info", "Successfully validated configuration file(%s)" % self.cpath)
def _qconfig_amqp(self, *_):
""" Answers the question `%config-amqp` """
Bus.publish(self, "%config-amqp", self.config)
_ac=AmqpConfig()
Bus.subscribe("%poll", _ac._hpoll)
Bus.subscribe("%config-amqp?", _ac._qconfig_amqp)
示例6: gMsg
# 需要导入模块: from system.mbus import Bus [as 别名]
# 或者: from system.mbus.Bus import subscribe [as 别名]
break
def gMsg(self):
try: msg=self.iq.get_nowait()
except Empty: msg=(None, None)
return msg
def processMsg(self, data):
try:
devices=json.loads(data)
except Exception,e:
Bus.publish(self, "%llog", "%json-decode",
"warning", "Error(%s) decoding json object: %s" % (e, data))
return
## We need to itemize the devices list
## for the benefit of the other agents sitting on the Bus
try:
for device in devices:
Bus.publish(self, "%device", device)
except Exception, e:
Bus.publish(self, "%llog", "%json-decode",
"warning", "Error(%s) accessing json list object: %s" % (e, devices))
_ifkm=IfkManagerAgent(qToManagerConsumer, qFromManagerConsumer)
Bus.subscribe("%config-amqp", _ifkm._hConfigAmqp)
Bus.subscribe("%poll", _ifkm._hpoll)
Bus.subscribe("%quit", _ifkm._hquit)
示例7: _onError
# 需要导入模块: from system.mbus import Bus [as 别名]
# 或者: from system.mbus.Bus import subscribe [as 别名]
self._q.put(["%device-detached", details], block=True)
def _onError(self, e):
try:
details=self._getDeviceDetails(e.device)
self._q.put(["%device-error", details], block=True)
Bus.publish(self, "%log", "warning", "Device error: %s" % details)
except Exception,e:
Bus.publish(self, "%log", "error", "exception whilst attempting to report Phidgets.onError (%s)" % e)
def _getDeviceDetails(self, device):
details={}
## should at least have serial number
try: details["serial"] = device.getSerialNum()
except: pass
try:
details["name"] = device.getDeviceName()
details["type"] = device.getDeviceType()
details["version"] = device.getDeviceVersion()
#details["label"] = device.getDeviceLabel() # crashes DBus
except:
pass
return details
_manager=ManagerAgent()
Bus.subscribe("%poll", _manager._hpoll)
示例8: __init__
# 需要导入模块: from system.mbus import Bus [as 别名]
# 或者: from system.mbus.Bus import subscribe [as 别名]
def __init__ (self):
rb.Plugin.__init__ (self)
self.main=PluginAgent()
Bus.subscribe(self.BUSNAME, "devmode?", self.hq_devmode)
Bus.subscribe(self.BUSNAME, "appname?", self.hq_appname)
示例9: Exception
# 需要导入模块: from system.mbus import Bus [as 别名]
# 或者: from system.mbus.Bus import subscribe [as 别名]
try:
self.chan.exchange_declare(exchange=self.EXCH,
type="topic", durable=False, auto_delete=True,)
except Exception,e:
Bus.publish(self, "%conn-error")
self.log("%conn-error", "error",
"Failed to declare exchange on connection to AMQP broker. Exception(%s)" % e)
try:
self.chan.close()
self.conn.close()
self.chan=None
self.conn=None
except: pass
return
self.log("%conn-open", "info", "Connection to AMQP broker opened")
def log(self, ltype, level, msg):
Bus.publish(self, "%llog", ltype, level, msg)
_handler=APIHandler()
Bus.subscribe("%devices", _handler.Devices)
Bus.subscribe("%device-attached", _handler.Attached)
Bus.subscribe("%device-detached", _handler.Detached)
Bus.subscribe("%device-error", _handler.Error)
Bus.subscribe("%config-amqp", _handler._hconfig)
Bus.subscribe("%poll", _handler._hpoll)
示例10: device
# 需要导入模块: from system.mbus import Bus [as 别名]
# 或者: from system.mbus.Bus import subscribe [as 别名]
pinnames.extend([pname])
try: _ipin=int(pin)
except:
self.log("warning", "Expecting 'integer' value for pin entry, device(%s)" % device)
return
## stringify for less headache: normalize type
m="%s.%s" % (device_name, pin)
pinmap[m] = pname
except:
self.log("warning", "Error whilst validating 'Devices' section of configuration file")
return
#print "pinnames: ",pinnames
try:
for pinname in states:
if not pinname in pinnames:
self.log("warning", "Pin name(%s) not found in any 'Device' definition" % pinname)
except:
self.log("warning", "Error whilst validating 'States' section of configuration file")
return
self.config=config
self.log("info", "Successfully validated configuration file(%s)" % self.cpath)
Bus.publish(self, "%config-sensors", self.config)
Bus.publish(self, "%pin-map", pinmap)
_ca=ConfigAgent()
Bus.subscribe("%poll", _ca._hpoll)
示例11: Error
# 需要导入模块: from system.mbus import Bus [as 别名]
# 或者: from system.mbus.Bus import subscribe [as 别名]
## ============================================================================
## SIGNAL GENERATORS
## ============================================================================
@dbus.service.signal(dbus_interface="com.phidgets.Phidgets", signature="a{sv}")
def Error(self, dic):
"""Generated when an error on a device is detected"""
@dbus.service.signal(dbus_interface="com.phidgets.Phidgets", signature="sii")
def Din(self, serial, pin, value):
"""Generated when the state of a digital input changes"""
@dbus.service.signal(dbus_interface="com.phidgets.Phidgets", signature="sii")
def Dout(self, serial, pin, value):
"""Generated when the state of a digital output changes"""
@dbus.service.signal(dbus_interface="com.phidgets.Phidgets", signature="sii")
def Ain(self, serial, pin, value):
"""Generated when the state of an analog input changes"""
_handler=DBusAPIHandler()
Bus.subscribe("%device-error", _handler.Error)
Bus.subscribe("%device-din", _handler.Din)
Bus.subscribe("%device-dout", _handler.Dout)
Bus.subscribe("%device-ain", _handler.Ain)
示例12: EchoString
# 需要导入模块: from system.mbus import Bus [as 别名]
# 或者: from system.mbus.Bus import subscribe [as 别名]
@dbus.service.method('com.phidgets.Phidgets', in_signature="s")
def EchoString(self, original):
return original
@dbus.service.signal(dbus_interface="com.phidgets.Phidgets", signature="aa{sv}")
def Devices(self, liste):
"""Generated when a device is attached to the host"""
@dbus.service.signal(dbus_interface="com.phidgets.Phidgets", signature="a{sv}")
def Attached(self, dic):
"""Generated when a device is attached to the host"""
@dbus.service.signal(dbus_interface="com.phidgets.Phidgets", signature="a{sv}")
def Detached(self, dic):
"""Generated when a device is detached to the host"""
@dbus.service.signal(dbus_interface="com.phidgets.Phidgets", signature="a{sv}")
def Error(self, dic):
"""Generated when an error on a device is detected"""
_handler=DBusAPIHandler()
Bus.subscribe("%devices", _handler.Devices)
Bus.subscribe("%device-attached", _handler.Attached)
Bus.subscribe("%device-detached", _handler.Detached)
Bus.subscribe("%device-error", _handler.Error)
示例13: processMsgQueue
# 需要导入模块: from system.mbus import Bus [as 别名]
# 或者: from system.mbus.Bus import subscribe [as 别名]
Bus.publish(self, "%conn-error", "warning", "Connection to AMQP broker failed")
del self.currentWorker
self.currentWorker = None
if self.currentWorker is not None:
self.processMsgQueue()
def processMsgQueue(self):
while True:
msg=self.currentWorker.rxFromWorker()
if msg is None:
break
try:
mtype=msg.pop(0)
mdata=msg.pop(0)
except:
Bus.publish(self, "%llog", "%msg-error", "error", "Error whilst decoding message from AMQP exchange 'org.sensors' ")
continue
## e.g. "state.io.din"
Bus.publish(self, mtype, mdata)
def _hquit(self):
self.update()
_mng=Manager()
Bus.subscribe("%config-amqp", _mng._hconfig)
Bus.subscribe("%poll", _mng._hpoll)
Bus.subscribe("%quit", _mng._hquit)
示例14: RuntimeError
# 需要导入模块: from system.mbus import Bus [as 别名]
# 或者: from system.mbus.Bus import subscribe [as 别名]
try: msg = p[0]
except: raise RuntimeError("LogLimiter: invalid usage")
cdelta=self.map.get(ltype, self.DEFAULT_CDELTA)
lpoll=self.st.get(ltype, 0)
delta=self.cpoll - lpoll
#print "cpoll(%s) ltype(%s) delta(%s) cdelta(%s) msg(%s)" % (self.cpoll, ltype, delta, cdelta, msg)
if delta >= cdelta or lpoll==0:
self.st[ltype] = self.cpoll
Bus.publish(self, "%log", level, "(%s:%s) %s" % (ltype, c, msg))
_ll=LogLimiter()
Bus.subscribe("%llog", _ll._hllog)
Bus.subscribe("%llconfig", _ll._hllconfig)
Bus.subscribe("%poll", _ll._hpoll)
## ======================================================================
## ======================================================================
if __name__=="__main__":
Bus.debug=True
Bus.publish(None, "%llog", "l1", "info", "msg1")
Bus.publish(None, "%llog", "l2", "warning", "msg2")
Bus.publish(None, "%llog", "l3", "msg3")
示例15: _hAin
# 需要导入模块: from system.mbus import Bus [as 别名]
# 或者: from system.mbus.Bus import subscribe [as 别名]
Bus.publish(self, "%state-changed", serial, "dout:%s" % pin, mval)
def _hAin(self, serial, pin, value):
pname, mval=self.domap(serial, pin, value)
if mval is not None:
Bus.publish(self, "%state-changed", serial, pname, mval)
else:
Bus.publish(self, "%state-changed", serial, "ain:%s" % pin, mval)
## ==================================================
def domap(self, serial, pin, value):
pn=self.pmap(serial, pin)
pstates=self.states.get(pn, {})
mvalue=pstates.get(value, None)
return (pn, mvalue)
def pmap(self, serial, pin):
key="%s.%s" % (serial, pin)
return self.map.get(key, None)
_sa=SensorsAgent()
Bus.subscribe("%config-sensors", _sa.hConfig)
Bus.subscribe("%pin-map", _sa.hPinMap)
Bus.subscribe("%din", _sa._hDin)
Bus.subscribe("%dout", _sa._hDout)
Bus.subscribe("%ain", _sa._hAin)