python dbus note

..

python dbus 设置

import dbus
bus = dbus.SessionBus()
//参数为prog 和path
obj = bus.get_object('com.deepin.wm','/com/deepin/wm')
//参数为interface
intf = dbus.Interface(obj,'org.freedesktop.DBus.Properties')
//参数为方法
meth = intf.get_dbus_method('Set')
meth(dbus.String('com.deepin.wm'),dbus.String('compositingEnabled'),dbus.Boolean(True, variant_level=1))

 

 

 

 

 

 

..占位

 1 #Method
 2 def mothodAddUserLayout():
 3     progname = 'com.deepin.daemon.InputDevices'
 4     objpath = '/com/deepin/daemon/InputDevice/Keyboard'
 5     intfname = 'com.deepin.daemon.InputDevice.Keyboard'
 6     methname = 'AddUserLayout'
 7 
 8     bus = dbus.SessionBus()
 9     obj = bus.get_object(progname, objpath)  # Here we get object
10     intf = dbus.Interface(obj, intfname)      # Here we get interface
11     meth = intf.get_dbus_method(methname)      # Here we get method
12     #参数
13     meth("cn;altgr-pinyin")
14 
15 #propties GetAll
16 def propGetAll():
17     progname = 'com.deepin.daemon.InputDevices'
18     objpath = '/com/deepin/daemon/InputDevice/Keyboard'
19     intfname = 'org.freedesktop.DBus.Properties'
20     methname = 'GetAll'
21 
22     bus = dbus.SessionBus()
23     obj = bus.get_object(progname, objpath)  # Here we get object
24     intf = dbus.Interface(obj, intfname)      # Here we get interface
25     meth = intf.get_dbus_method(methname)      # Here we get method
26     # print(meth)
27     # print(meth())
28     v = meth("com.deepin.daemon.InputDevice.Keyboard")
29     # v 是字典
30     layout_arr = v["UserLayoutList"]
31     # for x in v:
32     #     print(x)
33 
34     return layout_arr

 

 

 

 

posted @ 2021-02-23 17:27  voh99800  阅读(80)  评论(0编辑  收藏  举报