bf3000e9f0dece9844b7f9b6ee9346922d0f645d
[platform/upstream/ibus.git] / bindings / pygobject / gi / overrides / IBus.py
1 # vim:set et sts=4 sw=4:
2 #
3 # ibus - The Input Bus
4 #
5 # Copyright (c) 2012 Daiki Ueno <ueno@unixuser.org>
6 # Copyright (c) 2011 Peng Huang <shawn.p.huang@gmail.com>
7 #
8 # This library is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU Lesser General Public
10 # License as published by the Free Software Foundation; either
11 # version 2 of the License, or (at your option) any later version.
12 #
13 # This library is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU Lesser General Public License for more details.
17 #
18 # You should have received a copy of the GNU Lesser General Public
19 # License along with this program; if not, write to the
20 # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 # Boston, MA  02110-1301  USA
22
23 from gi.repository import GObject
24
25 from ..overrides import override
26
27 # for newer pygobject: https://bugzilla.gnome.org/show_bug.cgi?id=686828
28 # from ..module import get_introspection_module
29 # IBus = get_introspection_module('IBus')
30 from ..importer import modules
31 IBus = modules['IBus']._introspection_module
32
33 __all__ = []
34
35 class Attribute(IBus.Attribute):
36     def __new__(cls, type=0, value=0, start_index=0, end_index=0):
37         return IBus.Attribute.new(type, value, start_index, end_index)
38
39 Attribute = override(Attribute)
40 __all__.append('Attribute')
41
42 class Component(IBus.Component):
43     # Backward compatibility: allow non-keyword arguments
44     def __init__(self,
45                  name='',
46                  description='',
47                  version='',
48                  laicense='',
49                  author='',
50                  homepage='',
51                  command_line='',
52                  textdomain='',
53                  **kwargs):
54         super(Component, self).__init__(name=name,
55                                         description=description,
56                                         version=version,
57                                         license=license,
58                                         author=author,
59                                         homepage=homepage,
60                                         command_line=command_line,
61                                         textdomain=textdomain,
62                                         **kwargs)
63
64     # Backward compatibility: allow keyword arguments
65     def add_engine(self, engine=None, **kwargs):
66         if engine is None:
67             engine = EngineDesc(**kwargs)
68         super(Component, self).add_engine(engine)
69
70 Component = override(Component)
71 __all__.append('Component')
72
73 class Config(IBus.Config):
74     # Backward compatibility: accept default arg
75     def get_value(self, section, name, default=None):
76         value = super(Config, self).get_value(section, name)
77         if value is None:
78             return default
79         return value
80
81     # Backward compatibility: unset value if value is None
82     # Note that we don't call GLib.Variant.unpack here
83     def set_value(self, section, name, value):
84         if value is None:
85             self.unset(section, name)
86         else:
87             super(Config, self).set_value(section, name, value)
88
89 Config = override(Config)
90 __all__.append('Config')
91
92 class EngineDesc(IBus.EngineDesc):
93     # Backward compatibility: allow non-keyword arguments
94     def __init__(self,
95                  name='',
96                  longname='',
97                  description='',
98                  language='',
99                  license='',
100                  author='',
101                  icon='',
102                  layout='us',
103                  hotkeys='',
104                  rank=0,
105                  symbol='',
106                  setup='',
107                  layout_variant='',
108                  layout_option='',
109                  version='',
110                  **kwargs):
111         super(EngineDesc, self).__init__(name=name,
112                                          longname=longname,
113                                          description=description,
114                                          language=language,
115                                          license=license,
116                                          author=author,
117                                          icon=icon,
118                                          layout=layout,
119                                          hotkeys=hotkeys,
120                                          rank=rank,
121                                          symbol=symbol,
122                                          setup=setup,
123                                          layout_variant=layout_variant,
124                                          layout_option=layout_option,
125                                          version=version,
126                                          **kwargs)
127
128 EngineDesc = override(EngineDesc)
129 __all__.append('EngineDesc')
130
131 class Factory(IBus.Factory):
132     # Backward compatibility: allow non-keyword arguments
133     def __init__(self, bus=None, **kwargs):
134         if bus is not None:
135             kwargs.setdefault('connection', bus.get_connection())
136             kwargs.setdefault('object_path', IBus.PATH_FACTORY)
137         super(Factory, self).__init__(**kwargs)
138
139 Factory = override(Factory)
140 __all__.append('Factory')
141
142 class Keymap(IBus.Keymap):
143     # Backward compatibility: allow non-keyword arguments
144     def __new__(cls, name):
145         return IBus.Keymap.new(name)
146
147     def __init__(*args, **kwargs):
148         pass
149
150 Keymap = override(Keymap)
151 __all__.append('Keymap')
152
153 class LookupTable(IBus.LookupTable):
154     # Backward compatibility: allow non-keyword arguments
155     def __new__(cls,
156                 page_size=5,
157                 cursor_pos=0,
158                 cursor_visible=True,
159                 round=False,
160                 orientation=IBus.Orientation.SYSTEM,
161                 candidates=[],
162                 labels=[]):
163         table = IBus.LookupTable.new(page_size,
164                                      cursor_pos,
165                                      cursor_visible,
166                                      round)
167         table.set_orientation(orientation)
168         for candidate in candidates:
169             table.append_candidate(candidate)
170         for index, label in enumerate(labels):
171             table.set_label(index, label)
172         return table
173
174     def __init__(self, *args, **kwargs):
175         pass
176
177     # Backward compatibility: rename
178     def show_cursor(self, visible):
179         self.set_cursor_visible(visible)
180
181     # Backward compatibility: rename
182     def clean(self):
183         self.clear()
184
185 LookupTable = override(LookupTable)
186 __all__.append('LookupTable')
187
188 class Property(IBus.Property):
189     # Backward compatibility: allow non-keyword arguments
190     def __init__(self,
191                  key='',
192                  type=IBus.PropType.NORMAL,
193                  label='',
194                  icon='',
195                  tooltip='',
196                  sensitive=True,
197                  visible=True,
198                  state=IBus.PropState.UNCHECKED,
199                  symbol='',
200                  **kwargs):
201         prop_type = kwargs.get('prop_type', type)
202         if not isinstance(label, IBus.Text):
203             label = Text(label)
204         if not isinstance(tooltip, IBus.Text):
205             tooltip = Text(tooltip)
206         if not isinstance(symbol, IBus.Text):
207             symbol = Text(symbol)
208         super(Property, self).__init__(key=key,
209                                        prop_type=prop_type,
210                                        label=label,
211                                        icon=icon,
212                                        tooltip=tooltip,
213                                        sensitive=sensitive,
214                                        visible=visible,
215                                        state=state,
216                                        symbol=symbol,
217                                        **kwargs)
218
219 Property = override(Property)
220 __all__.append('Property')
221
222 class Text(IBus.Text):
223     # Backward compatibility: allow non-keyword arguments
224     def __new__(cls, string='', attrs=None):
225         text = IBus.Text.new_from_string(string)
226         if attrs is not None:
227             text.set_attributes(attrs)
228         return text
229
230     def __init__(self, *args, **kwargs):
231         pass
232
233 Text = override(Text)
234 __all__.append('Text')