Add notifications.py
[platform/upstream/ibus.git] / ibus / common.py
1 # vim:set et sts=4 sw=4:
2 #
3 # ibus - The Input Bus
4 #
5 # Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
6 #
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2 of the License, or (at your option) any later version.
11 #
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU Lesser General Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this program; if not, write to the
19 # Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20 # Boston, MA  02111-1307  USA
21
22 __all__ = (
23         "IBUS_ADDR",
24         "IBUS_IFACE",
25         "IBUS_NAME",
26         "IBUS_PATH",
27         "IBUS_CONFIG_IFACE",
28         "IBUS_ENGINE_FACTORY_IFACE",
29         "IBUS_ENGINE_IFACE",
30         "IBUS_PANEL_IFACE",
31         "IBUS_NOTIFICATIONS_IFACE",
32         "default_reply_handler",
33         "default_error_handler",
34         "DEFAULT_ASYNC_HANDLERS",
35         "CONFIG_GENERAL_SHORTCUT_TRIGGER",
36         "CONFIG_GENERAL_SHORTCUT_NEXT_ENGINE",
37         "CONFIG_GENERAL_SHORTCUT_PREV_ENGINE",
38         "CONFIG_GENERAL_SHORTCUT_TRIGGER_DEFAULT",
39         "CONFIG_GENERAL_SHORTCUT_NEXT_ENGINE_DEFAULT",
40         "CONFIG_GENERAL_SHORTCUT_PREV_ENGINE_DEFAULT",
41         "main",
42         "main_quit",
43         "main_iteration"
44     )
45
46 import os
47 import sys
48
49 display = os.environ["DISPLAY"]
50 if "." not in display:
51     display += ".0" 
52
53 __username = None
54 try:
55     __username = os.getlogin()
56 except:
57     pass
58 if not __username:
59     __username = os.getenv ("LOGNAME")
60 if not __username:
61     __username = os.getenv ("USER")
62 if not __username:
63     __username = os.getenv ("LNAME")
64 if not __username:
65     __username = os.getenv ("USERNAME")
66
67 IBUS_ADDR = "unix:path=/tmp/ibus-%s/ibus-%s" % (__username, display.replace(":", "-"))
68 # IBUS_ADDR  = "tcp:host=localhost,port=7799"
69
70 IBUS_IFACE = "org.freedesktop.IBus"
71 IBUS_PATH  = "/org/freedesktop/IBus"
72 IBUS_NAME  = "org.freedesktop.IBus"
73
74 IBUS_CONFIG_IFACE = "org.freedesktop.ibus.Config"
75 IBUS_ENGINE_FACTORY_IFACE = "org.freedesktop.ibus.EngineFactory"
76 IBUS_ENGINE_IFACE = "org.freedesktop.ibus.Engine"
77 IBUS_PANEL_IFACE = "org.freedesktop.ibus.Panel"
78 IBUS_NOTIFICATIONS_IFACE = "org.freedesktop.ibus.Notifications"
79
80 def default_reply_handler( *args):
81     pass
82
83 def default_error_handler(e):
84     print >> sys.stderr, e
85
86 DEFAULT_ASYNC_HANDLERS = {
87     "reply_handler" : default_reply_handler,
88     "error_handler" : default_error_handler
89 }
90
91 CONFIG_GENERAL_SHORTCUT_TRIGGER     = "/general/keyboard_shortcut_trigger"
92 CONFIG_GENERAL_SHORTCUT_TRIGGER_DEFAULT = [
93     "Ctrl+space",
94     "Zenkaku_Hankaku",
95     "Hangul"]
96 CONFIG_GENERAL_SHORTCUT_NEXT_ENGINE = "/general/keyboard_shortcut_next_engine"
97 CONFIG_GENERAL_SHORTCUT_NEXT_ENGINE_DEFAULT = [
98     "Ctrl+Shift+Release+Shift_L",
99     "Ctrl+Shift+Release+Shift_R",
100     ]
101 CONFIG_GENERAL_SHORTCUT_PREV_ENGINE = "/general/keyboard_shortcut_prev_engine"
102 CONFIG_GENERAL_SHORTCUT_PREV_ENGINE_DEFAULT = []
103
104 __mainloop = None
105
106 def __init_main_loop():
107     global __mainloop
108     if __mainloop == None:
109         import gobject
110         __mainloop = gobject.MainLoop()
111
112 def main():
113     __init_main_loop()
114     __mainloop.run()
115
116 def main_quit():
117     global __mainloop
118     if __mainloop:
119         __mainloop.quit()
120     
121 def main_iteration(may_block=False):
122     __init_main_loop()
123     return __mainloop.get_context().iteration(may_block)