-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathibus_test.py
56 lines (41 loc) · 1 KB
/
ibus_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/python
# Simple script to easy testing IBUS commands
import sys
import time
import threading
try:
from gi.repository import GObject
except ImportError:
import gobject as GObject
import ibus as ibus_
ibus = None
def onIBUSready():
pass
def onIBUSpacket(packet):
print(packet)
def main():
global ibus
ibus = ibus_.IBUSService(onIBUSready, onIBUSpacket)
ibus.cmd = ibus_.IBUSCommands(ibus)
ibus.main_thread = threading.Thread(target=ibus.start)
ibus.main_thread.daemon = True
ibus.main_thread.start()
try:
mainloop = GObject.MainLoop()
mainloop.run()
except KeyboardInterrupt:
pass
except:
print("Unable to run the gobject main loop")
print("")
shutdown()
sys.exit(0)
def shutdown():
global ibus
if ibus.main_thread.isAlive():
print("Stopping IBUS main thread...")
ibus.stop()
print("Destroying IBUS service...")
ibus.shutdown()
if __name__ == '__main__':
main()