Rename folder ibusdaemon to daemon.
[ibus.git] / daemon / enginefactory.py
blob24974b1a3de59197ebbd88ec2dea1e168c1e9b98
1 # vim:set noet ts=4:
3 # ibus - The Input Bus
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
22 import weakref
23 import gobject
24 import ibus
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 ()
39 self._info = None
41 def get_object_path (self):
42 return self._object_path
44 def get_info (self):
45 if self._info == None:
46 self._info = self._factory.GetInfo ()
47 return self._info
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
53 return engine
55 def destroy (self):
56 ibus.Object.destroy (self)
57 self._ibusconn = None
58 self._factory = None
60 def _ibusconn_destroy_cb (self, ibusconn):
61 self.destroy ()
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)
68 # methods for cmp
69 def __lt__ (self, other):
70 x = self.get_info ()
71 y = other.get_info ()
72 if x[1] < y[1]: return True
73 if x[1] == y[1]: return x[0] < y[0]
75 def __gt__ (self, other):
76 x = self.get_info ()
77 y = other.get_info ()
78 if x[1] > y[1]: return True
79 if x[1] == y[1]: return x[0] > y[0]