pygi-gio - org.fcitx.Fcitx
相關連結
Script
- get-current-im.py
#!/usr/bin/env python3
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gio, GLib
bus = Gio.bus_get_sync(Gio.BusType.SESSION, None)
rtn = bus.call_sync(
bus_name = 'org.fcitx.Fcitx',
object_path = '/inputmethod',
interface_name = 'org.fcitx.Fcitx.InputMethod',
method_name = 'GetCurrentIM',
parameters = None,
reply_type = GLib.VariantType('(s)'),
flags = Gio.DBusCallFlags.NONE,
timeout_msec = -1,
cancellable = None
)
print(rtn.unpack()[0])
- set-current-im.py
#!/usr/bin/env python3
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gio, GLib
bus = Gio.bus_get_sync(Gio.BusType.SESSION, None)
rtn = bus.call_sync(
bus_name = 'org.fcitx.Fcitx',
object_path = '/inputmethod',
interface_name = 'org.fcitx.Fcitx.InputMethod',
method_name = 'SetCurrentIM',
parameters = GLib.Variant('(s)', ('fcitx-keyboard-us',)),
reply_type = GLib.VariantType('()'),
flags = Gio.DBusCallFlags.NONE,
timeout_msec = -1,
cancellable = None
)
print(rtn.unpack())
- set-current-im-chewing.py
#!/usr/bin/env python3
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gio, GLib
bus = Gio.bus_get_sync(Gio.BusType.SESSION, None)
rtn = bus.call_sync(
bus_name = 'org.fcitx.Fcitx',
object_path = '/inputmethod',
interface_name = 'org.fcitx.Fcitx.InputMethod',
method_name = 'SetCurrentIM',
parameters = GLib.Variant('(s)', ('chewing',)),
reply_type = GLib.VariantType('()'),
flags = Gio.DBusCallFlags.NONE,
timeout_msec = -1,
cancellable = None
)
print(rtn.unpack())
使用範例
執行
$ ./get-current-im.py
顯示
fcitx-keyboard-us
執行
$ ./set-current-im-chewing.py
顯示
()
執行
$ ./get-current-im.py
顯示
chewing
執行
$ ./set-current-im.py
顯示
()
執行
$ ./get-current-im.py
顯示
fcitx-keyboard-us
查詢 Help
執行
$ python3
顯示
Python 3.5.1+ (default, Mar 30 2016, 22:46:26)
[GCC 5.3.1 20160330] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
輸入
>>> from gi.repository import Gio
輸入
>>> print(Gio.bus_get_sync.__doc__)
顯示
bus_get_sync(bus_type:Gio.BusType, cancellable:Gio.Cancellable=None) -> Gio.DBusConnection
輸入
>>> help(Gio.DBusConnection)
查詢「call_sync」
/call_sync
可以找到
| call_sync = gi.FunctionInfo(call_sync)
| call_sync(self, bus_name:str=None, object_path:str, interface_name:str, method_name:str, parameters:GLib.Variant=None, reply_type:GLib.VariantType=None, flags:Gio.DBusCallFlags, timeout_msec:int, cancellable:Gio.Cancellable=None) -> GLib.Variant