5 # Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
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.
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.
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
25 from engine import Engine
27 class EngineFactory (ibus.Object):
28 def __init__ (self, ibusconn, object_path):
29 ibus.Object.__init__ (self)
30 self._ibusconn = ibusconn
31 self._object_path = object_path
32 self._factory = self._ibusconn.get_object (self._object_path)
34 self._ibusconn.connect ("destroy", self._ibusconn_destroy_cb)
36 self._ibusconn.connect ("dbus-signal", self._dbus_signal_cb)
37 self._engines = weakref.WeakValueDictionary ()
41 def get_object_path (self):
42 return self._object_path
45 if self._info == None:
46 self._info = self._factory.GetInfo ()
49 def create_engine (self):
50 object_path = self._factory.CreateEngine ()
51 engine = Engine (self, self._ibusconn, object_path)
52 self._engines[object_path] = engine
56 ibus.Object.destroy (self)
60 def _ibusconn_destroy_cb (self, ibusconn):
63 def _dbus_signal_cb (self, ibusconn, message):
64 object_path = message.get_path ()
65 if object_path in self._engines:
66 self._engines[object_path].handle_dbus_signal (message)
69 def __lt__ (self, other):
72 if x[1] < y[1]: return True
73 if x[1] == y[1]: return x[0] < y[0]
75 def __gt__ (self, other):
78 if x[1] > y[1]: return True
79 if x[1] == y[1]: return x[0] > y[0]