本文整理匯總了Python中pydbus.SessionBus.publish方法的典型用法代碼示例。如果您正苦於以下問題:Python SessionBus.publish方法的具體用法?Python SessionBus.publish怎麽用?Python SessionBus.publish使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pydbus.SessionBus
的用法示例。
在下文中一共展示了SessionBus.publish方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: Hello
# 需要導入模塊: from pydbus import SessionBus [as 別名]
# 或者: from pydbus.SessionBus import publish [as 別名]
"""
<node>
<interface name='net.lew21.pydbus.ClientServerExample'>
<method name='Hello'>
<arg type='s' name='response' direction='out'/>
</method>
<method name='EchoString'>
<arg type='s' name='a' direction='in'/>
<arg type='s' name='response' direction='out'/>
</method>
<method name='Quit'/>
</interface>
</node>
"""
def Hello(self):
"""returns the string 'Hello, World!'"""
return "Hello, World!"
def EchoString(self, s):
"""returns whatever is passed to it"""
return s
def Quit(self):
"""removes this object from the DBUS connection and exits"""
loop.quit()
bus = SessionBus()
bus.publish("net.lew21.pydbus.ClientServerExample", MyDBUSService())
loop.run()
示例2: Method2
# 需要導入模塊: from pydbus import SessionBus [as 別名]
# 或者: from pydbus.SessionBus import publish [as 別名]
global done
done += 1
if done == 2:
loop.quit()
return "M1"
def Method2(self):
global done
done += 1
if done == 2:
loop.quit()
return "M2"
bus = SessionBus()
with bus.publish("net.lew21.pydbus.tests.expose_multiface", TestObject()):
remote = bus.get("net.lew21.pydbus.tests.expose_multiface")
def t1_func():
print(remote.Method1())
print(remote.Method2())
t1 = Thread(None, t1_func)
t1.daemon = True
def handle_timeout():
print("ERROR: Timeout.")
sys.exit(1)
GLib.timeout_add_seconds(2, handle_timeout)
示例3: hello
# 需要導入模塊: from pydbus import SessionBus [as 別名]
# 或者: from pydbus.SessionBus import publish [as 別名]
self._who = "human"
self._state = "good"
def hello(self):
return "Hello %s!" % self._who
def quit(self):
loop.quit()
def whatsup(self):
return "@!#$*&@!, %s!" % self._who
@property
def State(self):
return self._state
@property
def Who(self):
return self._who
@Who.setter
def Who(self, value):
self._who = value
self.PropertiesChanged("org.me.test1", {"Who": self._who}, [])
PropertiesChanged = signal()
bus = SessionBus()
bus.publish("org.me.test", MyDBUSService())
loop.run()
示例4: __init__
# 需要導入模塊: from pydbus import SessionBus [as 別名]
# 或者: from pydbus.SessionBus import publish [as 別名]
<property name="Foo" type="s" access="read"/>
<property name="Bar" type="s" access="write"/>
<method name='Quit'/>
</interface>
</node>
'''
def __init__(self):
self.Foo = "foo"
self.Foobar = "foobar"
def Quit(self):
loop.quit()
bus = SessionBus()
with bus.publish("net.lew21.pydbus.tests.publish_properties", TestObject()):
remote = bus.get("net.lew21.pydbus.tests.publish_properties")
remote_iface = remote['net.lew21.pydbus.tests.publish_properties']
def t1_func():
for obj in [remote, remote_iface]:
assert(obj.Foo == "foo")
assert(obj.Foobar == "foobar")
obj.Foobar = "barfoo"
assert(obj.Foobar == "barfoo")
obj.Foobar = "foobar"
assert(obj.Foobar == "foobar")
obj.Bar = "rab"
remote.Foobar = "barfoo"
示例5: Mpvplayer
# 需要導入模塊: from pydbus import SessionBus [as 別名]
# 或者: from pydbus.SessionBus import publish [as 別名]
from playthread import Mpvplayer
loop = GLib.MainLoop()
player = Mpvplayer()
player.start()
class DBUSPlayerService(object):
"""
<node>
<interface name='github.zhangn1985.dbplay'>
<method name='play'>
<arg type='s' name='playinfo' direction='in'/>
</method>
<method name='stop'/>
<method name='exit'/>
</interface>
</node>
"""
def play(self, playinfo):
player.play(playinfo)
def stop(self):
player.stop()
def exit(self):
player.exit()
loop.quit()
bus = SessionBus()
bus.publish("github.zhangn1985.dbplay", DBUSPlayerService())
loop.run()
示例6: stop
# 需要導入模塊: from pydbus import SessionBus [as 別名]
# 或者: from pydbus.SessionBus import publish [as 別名]
if not self.is_running:
self.next_call += self.interval
self._timer = threading.Timer(self.next_call - time.time(), self._run)
self._timer.start()
self.is_running = True
def stop(self):
self._timer.cancel()
self.is_running = False
if __name__=="__main__":
# Launch the server
# Use pydbus to establish a session gdbus. Rather than system gdbus
# TODO: Use try/except, etc. in case bus already exists. e.g. bus.get(BUS)
bus = SessionBus()
bus.publish(BUS, DBusService())
# Start the repeating timer. It auto-starts, no need of rt.start()
# RepeatedTimer(period between function calls, function())
rt = RepeatedTimer(period, timer_event)
# Enable R-Pi channel to perform callbacks on detection of a pulse.
if not simulated_pulse:
#GPIO.add_event_detect(channel, GPIO.RISING, callback=pulse_callback,
# bouncetime=1)
GPIO.add_event_detect(channel, GPIO.FALLING, callback=pulse_callback,
bouncetime=1)
print("server running...")
try:
loop.run()
except KeyboardInterrupt:
示例7: __init__
# 需要導入模塊: from pydbus import SessionBus [as 別名]
# 或者: from pydbus.SessionBus import publish [as 別名]
'''
def __init__(self, id):
self.id = id
def HelloWorld(self, a, b):
res = self.id + ": " + a + str(b)
global done
done += 1
if done == 2:
loop.quit()
print(res)
return res
bus = SessionBus()
with bus.publish("net.lew21.pydbus.Test", TestObject("Main"), ("Lol", TestObject("Lol"))):
remoteMain = bus.get("net.lew21.pydbus.Test")
remoteLol = bus.get("net.lew21.pydbus.Test", "Lol")
def t1_func():
print(remoteMain.HelloWorld("t", 1))
def t2_func():
print(remoteLol.HelloWorld("t", 2))
t1 = Thread(None, t1_func)
t2 = Thread(None, t2_func)
t1.daemon = True
t2.daemon = True
def handle_timeout():