1 # vim:set et sts=4 sw=4:
5 # Copyright (c) 2012 Daiki Ueno <ueno@unixuser.org>
6 # Copyright (c) 2011 Peng Huang <shawn.p.huang@gmail.com>
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.
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.
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
23 from gi.repository import GObject
25 from ..overrides import override
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
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)
39 Attribute = override(Attribute)
40 __all__.append('Attribute')
42 class Component(IBus.Component):
43 # Backward compatibility: allow non-keyword arguments
54 super(Component, self).__init__(name=name,
55 description=description,
60 command_line=command_line,
61 textdomain=textdomain,
64 # Backward compatibility: allow keyword arguments
65 def add_engine(self, engine=None, **kwargs):
67 engine = EngineDesc(**kwargs)
68 super(Component, self).add_engine(engine)
70 Component = override(Component)
71 __all__.append('Component')
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)
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):
85 self.unset(section, name)
87 super(Config, self).set_value(section, name, value)
89 Config = override(Config)
90 __all__.append('Config')
92 class EngineDesc(IBus.EngineDesc):
93 # Backward compatibility: allow non-keyword arguments
111 super(EngineDesc, self).__init__(name=name,
113 description=description,
123 layout_variant=layout_variant,
124 layout_option=layout_option,
128 EngineDesc = override(EngineDesc)
129 __all__.append('EngineDesc')
131 class Factory(IBus.Factory):
132 # Backward compatibility: allow non-keyword arguments
133 def __init__(self, bus=None, **kwargs):
135 kwargs.setdefault('connection', bus.get_connection())
136 kwargs.setdefault('object_path', IBus.PATH_FACTORY)
137 super(Factory, self).__init__(**kwargs)
139 Factory = override(Factory)
140 __all__.append('Factory')
142 class Keymap(IBus.Keymap):
143 # Backward compatibility: allow non-keyword arguments
144 def __new__(cls, name):
145 return IBus.Keymap.new(name)
147 def __init__(*args, **kwargs):
150 Keymap = override(Keymap)
151 __all__.append('Keymap')
153 class LookupTable(IBus.LookupTable):
154 # Backward compatibility: allow non-keyword arguments
160 orientation=IBus.Orientation.SYSTEM,
163 table = IBus.LookupTable.new(page_size,
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)
174 def __init__(self, *args, **kwargs):
177 # Backward compatibility: rename
178 def show_cursor(self, visible):
179 self.set_cursor_visible(visible)
181 # Backward compatibility: rename
185 LookupTable = override(LookupTable)
186 __all__.append('LookupTable')
188 class Property(IBus.Property):
189 # Backward compatibility: allow non-keyword arguments
192 type=IBus.PropType.NORMAL,
198 state=IBus.PropState.UNCHECKED,
201 prop_type = kwargs.get('prop_type', type)
202 if not isinstance(label, IBus.Text):
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,
219 Property = override(Property)
220 __all__.append('Property')
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)
230 def __init__(self, *args, **kwargs):
233 Text = override(Text)
234 __all__.append('Text')