python [Qiita] [python 3] DBusことはじめ
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python [Qiita] [python 3] DBusことはじめ相关的知识,希望对你有一定的参考价值。
# dbus sample
#!/usr/bin/env python3
import argparse
import dbus
import dbus.service
from dbus.mainloop.glib import DBusGMainLoop
from gi.repository import GObject, GLib
iface = 'jp.co.itage.fooiface'
class FooSession(dbus.service.Object):
def __init__(self):
service = 'jp.co.itage'
obj = '/jp/co/itage/foo'
bus = dbus.SessionBus()
bus_name = dbus.service.BusName(service, bus=bus)
super(FooSession, self).__init__(bus_name, obj)
self._proxy = bus.get_object(service, obj)
bus.add_signal_receiver(
self.finish, dbus_interface=iface, bus_name=service, path=obj)
def start(self, area):
print('call start(): {}'.format(area))
ret = self._proxy.start(area, dbus_interface=iface)
print('start ret value: {}'.format(ret))
def stop(self):
print('call stop()')
self._proxy.stop(dbus_interface=iface)
def finish(self, result):
print('called finish(): {}'.format(result))
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--area',
required=True,
type=int)
args = parser.parse_args()
DBusGMainLoop(set_as_default=True)
loop = GObject.MainLoop()
session = FooSession()
try:
session.start(args.area)
loop.run()
except KeyboardInterrupt:
session.stop()
loop.quit()
dbus-python==1.2.8
pkg-resources==0.0.0
pycairo==1.17.1
PyGObject==3.30.1
#!/usr/bin/env python3
import dbus
import dbus.service
from dbus.mainloop.glib import DBusGMainLoop
from gi.repository import GObject, GLib
iface = 'jp.co.itage.fooiface'
class FooServer(dbus.service.Object):
def __init__(self):
service = 'jp.co.itage'
obj = '/jp/co/itage/foo'
bus = dbus.SessionBus()
bus_name = dbus.service.BusName(service, bus=bus)
super(FooServer, self).__init__(bus_name, obj)
@dbus.service.method(iface, in_signature='u', out_signature='u')
def start(self, area):
"""Register [start method]"""
print(area)
self.finish(0)
if area == 1:
return 1
elif area == 2:
return 2
return 0
@dbus.service.method(iface, signature=None)
def stop(self):
"""Register [stop method]"""
print('called stop')
@dbus.service.signal(iface, signature='u')
def finish(self, result):
"""Register [finish signal]"""
print('called xfinish: {}'.format(result))
if __name__ == '__main__':
DBusGMainLoop(set_as_default=True)
loop = GObject.MainLoop()
foo = FooServer()
try:
loop.run()
except KeyboardInterrupt:
loop.quit()
以上是关于python [Qiita] [python 3] DBusことはじめ的主要内容,如果未能解决你的问题,请参考以下文章
python graphcut - networkx ref:https://qiita.com/naivete5656/items/d8d1219719e802574d4f
text 【メモ】Python3复数の数字を空白区切りで1行に出力するref:https://qiita.com/shunak/items/66fc1375b7743cd1e413
sh GCCのsysrootオプションについて调べてみたref:http://qiita.com/maskedw/items/e73df32007934e75d9e3
xml qiita-股票search.xml
javascript 【气】Qiitaのコントリビュート取得
php GuzzleでQiita APIv2で投稿をPOSTする小さなサンプル