From: Huang Peng Date: Fri, 30 May 2008 09:55:14 +0000 (+0800) Subject: Modifid IPanel and IEngine interfaces. X-Git-Tag: 0.1.0.20080810~462 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e911456cf2c1f4e17c5ccf909e4fb80e4fccb780;p=platform%2Fupstream%2Fibus.git Modifid IPanel and IEngine interfaces. --- diff --git a/engine/demo/engine.py b/engine/demo/engine.py index ff7ea08..467ad4d 100644 --- a/engine/demo/engine.py +++ b/engine/demo/engine.py @@ -37,9 +37,10 @@ class Engine (interface.IEngine): self._update () return True elif keyval == keysyms.space: - self._commit_string (self._preedit_string) - self._preedit_string = "" - self._update () + if self._lookup_table.get_number_of_candidates () > 0: + self._commit_string (self._lookup_table.get_current_candidate ()[0]) + else: + self._commit_string (self._preedit_string) return False elif keyval >= keysyms._1 and keyval <= keysyms._9: index = keyval - keysyms._1 @@ -103,14 +104,14 @@ class Engine (interface.IEngine): attrs.append (ibus.AttributeForeground (0xff0000, 0, preedit_len)) for text in self._dict.suggest (self._preedit_string): self._lookup_table.append_candidate (text) - - self.AuxStringChanged (self._preedit_string, attrs.to_dbus_value ()) + self.UpdateAuxString (self._preedit_string, attrs.to_dbus_value (), preedit_len > 0) attrs.append (ibus.AttributeUnderline (pango.UNDERLINE_SINGLE, 0, preedit_len)) - self.PreeditChanged (self._preedit_string, attrs.to_dbus_value (), dbus.Int32 (preedit_len)) + self.UpdatePreedit (self._preedit_string, attrs.to_dbus_value (), dbus.Int32 (preedit_len), preedit_len > 0) self._update_lookup_table () def _update_lookup_table (self): - self.UpdateLookupTable (self._lookup_table.to_dbus_value ()) + show = self._lookup_table.get_number_of_candidates () > 0 + self.UpdateLookupTable (self._lookup_table.to_dbus_value (), show) def FocusIn (self): diff --git a/gtk2/gikimclient.c b/gtk2/gikimclient.c index 72dce71..1e7e876 100644 --- a/gtk2/gikimclient.c +++ b/gtk2/gikimclient.c @@ -50,6 +50,7 @@ struct _GikIMClientPrivate { gchar *preedit_string; PangoAttrList *preedit_attrs; gint preedit_cursor; + gboolean preedit_show; }; /* functions prototype */ @@ -59,11 +60,12 @@ static void gik_im_client_finalize (GObject *obj); static void gik_im_client_commit_string(GikIMClient *client, const gchar *string); -static void gik_im_client_preedit_changed +static void gik_im_client_update_preedit (GikIMClient *client, const gchar *string, PangoAttrList *attrs, - gint cursor_pos); + gint cursor_pos, + gboolean show); static void gik_im_client_sync_hotkeys (GikIMClient *client); static gboolean _ibus_call_with_reply_and_block @@ -421,7 +423,8 @@ gik_im_client_commit_string (GikIMClient *client, const gchar *string) } static void -gik_im_client_preedit_changed (GikIMClient *client, const gchar *string, PangoAttrList *attrs, gint cursor_pos) +gik_im_client_update_preedit (GikIMClient *client, const gchar *string, + PangoAttrList *attrs, gint cursor_pos, gboolean show) { GikIMClientPrivate *priv = client->priv; if (priv->preedit_string) { @@ -439,6 +442,7 @@ gik_im_client_preedit_changed (GikIMClient *client, const gchar *string, PangoAt } priv->preedit_cursor = cursor_pos; + priv->preedit_show = show; if (priv->context) { g_signal_emit_by_name (priv->context, "preedit-changed"); } @@ -462,24 +466,26 @@ _gik_signal_commit_string_handler (DBusConnection *connection, DBusMessage *mess } static void -_gik_signal_preedit_changed_handler (DBusConnection *connection, DBusMessage *message, GikIMClient *client) +_gik_signal_update_preedit_handler (DBusConnection *connection, DBusMessage *message, GikIMClient *client) { - /* Handle PreeditChanged signal */ + /* Handle UpdatePreedit signal */ DBusError error = {0}; - gchar *string = NULL; - gint cursor = 0; DBusMessageIter iter, sub_iter; gint type, sub_type; + + gchar *string = NULL; PangoAttrList *attrs = NULL; + gint cursor = 0; + gboolean show = False; if (!dbus_message_iter_init (message, &iter)) { - g_warning ("The PreeditChanged signal does have args!"); + g_warning ("The UpdatePreedit signal does have args!"); return; } type = dbus_message_iter_get_arg_type (&iter); if (type != DBUS_TYPE_STRING) { - g_warning ("The frist argument of PreeditChanged signal must be a String"); + g_warning ("The frist argument of UpdatePreedit signal must be a String"); return; } dbus_message_iter_get_basic (&iter, &string); @@ -488,7 +494,7 @@ _gik_signal_preedit_changed_handler (DBusConnection *connection, DBusMessage *me type = dbus_message_iter_get_arg_type (&iter); if (type != DBUS_TYPE_ARRAY) { - g_warning ("The secode argument of PreeditChanged signal must be a Struct Array"); + g_warning ("The secode argument of UpdatePreedit signal must be a Struct Array"); return; } @@ -497,7 +503,7 @@ _gik_signal_preedit_changed_handler (DBusConnection *connection, DBusMessage *me if (dbus_message_iter_get_array_len (&sub_iter) > 0) { if (dbus_message_iter_get_arg_type (&sub_iter) != DBUS_TYPE_ARRAY || dbus_message_iter_get_element_type (&sub_iter) != DBUS_TYPE_INT32 ) { - g_warning ("The secode argument of PreeditChanged signal must be a Struct Array"); + g_warning ("The secode argument of UpdatePreedit signal must be a Struct Array"); return; } @@ -512,7 +518,7 @@ _gik_signal_preedit_changed_handler (DBusConnection *connection, DBusMessage *me dbus_message_iter_get_fixed_array (&sub_sub_iter, &values, &length); if (length <= 0) { - g_warning ("The element of the second argument of PreeditChanged should not be a empty array"); + g_warning ("The element of the second argument of UpdatePreedit should not be a empty array"); continue; } @@ -557,14 +563,23 @@ _gik_signal_preedit_changed_handler (DBusConnection *connection, DBusMessage *me type = dbus_message_iter_get_arg_type (&iter); if (type != DBUS_TYPE_INT32) { - g_warning ("The third argument of PreeditChanged signal must be an Int32 %c", type); + g_warning ("The third argument of UpdatePreedit signal must be an Int32 %c", type); pango_attr_list_unref (attrs); return; } dbus_message_iter_get_basic (&iter, &cursor); dbus_message_iter_next (&iter); - gik_im_client_preedit_changed (client, string, attrs, cursor); + type = dbus_message_iter_get_arg_type (&iter); + if (type != DBUS_TYPE_BOOLEAN) { + g_warning ("The third argument of UpdatePreedit signal must be an Int32 %c", type); + pango_attr_list_unref (attrs); + return; + } + dbus_message_iter_get_basic (&iter, &show); + dbus_message_iter_next (&iter); + + gik_im_client_update_preedit (client, string, attrs, cursor, show); pango_attr_list_unref (attrs); } @@ -626,7 +641,7 @@ _gik_im_client_message_filter_cb (DBusConnection *connection, DBusMessage *messa } handlers[] = { { DBUS_INTERFACE_DBUS, "NameOwnerChanged", _gik_signal_name_owner_changed_handler }, { IBUS_IFACE, "CommitString", _gik_signal_commit_string_handler }, - { IBUS_IFACE, "PreeditChanged", _gik_signal_preedit_changed_handler }, + { IBUS_IFACE, "UpdatePreedit", _gik_signal_update_preedit_handler }, { IBUS_IFACE, "Enabled", _gik_signal_enabled_handler }, { IBUS_IFACE, "Disabled", _gik_signal_disabled_handler }, {0}, @@ -940,6 +955,13 @@ gik_im_client_get_preedit_string ( { GikIMClientPrivate *priv = client->priv; + if (priv->preedit_show) { + if (str) *str = g_strdup (""); + if (attrs) *attrs = pango_attr_list_new (); + if (cursor_pos) *cursor_pos = 0; + return True; + } + if (str) { *str = g_strdup (priv->preedit_string ? priv->preedit_string: ""); } diff --git a/ibus/interface/iengine.py b/ibus/interface/iengine.py index 04539be..7b7fd72 100644 --- a/ibus/interface/iengine.py +++ b/ibus/interface/iengine.py @@ -34,20 +34,20 @@ class IEngine (dbus.service.Object): @method () def Reset (self): pass - + # signals for lookup table @method () def PageUp (self): pass - + @method () def PageDown (self): pass - + @method () def CursorUp (self): pass - + @method () def CursorDown (self): pass - + @method (in_signature = "b") def SetEnable (self, enable): pass @@ -63,18 +63,24 @@ class IEngine (dbus.service.Object): @signal (signature="ubu") def ForwardKeyEvent (self, keyval, is_press, state): pass - @signal (signature="saaii") - def PreeditChanged (self, text, attrs, cursor_pos): pass + @signal (signature="saaiib") + def UpdatePreedit (self, text, attrs, cursor_pos, show): pass # below signals are optional. The engine could create and maintain panel by self. @signal (signature="v") def UpdateProperties (self, properties): pass - @signal (signature="sv") - def AuxStringChanged (self, text, attrs): pass + @signal (signature="svb") + def UpdateAuxString (self, text, attrs, show): pass - @signal (signature="v") - def UpdateLookupTable (self, lookup_table): pass + @signal () + def ShowAuxStringChanged (self): pass + + @signal () + def HideAuxStringChanged (self): pass + + @signal (signature="vb") + def UpdateLookupTable (self, lookup_table, show): pass @signal () def ShowLookupTable (self): pass diff --git a/ibus/interface/ipanel.py b/ibus/interface/ipanel.py index 618c5e3..93a8b47 100644 --- a/ibus/interface/ipanel.py +++ b/ibus/interface/ipanel.py @@ -21,8 +21,8 @@ class IPanel (dbus.service.Object): @method (in_signature="iiii") def SetCursorLocation (self, x, y, w, h): pass - @method (in_signature="svu") - def SetPreeditString (self, text, attrs, cursor_pos): pass + @method (in_signature="svub") + def UpdatePreedit (self, text, attrs, cursor_pos, show): pass @method () def ShowPreeditString (self): pass @@ -30,8 +30,8 @@ class IPanel (dbus.service.Object): @method () def HidePreeditString (self): pass - @method (in_signature="sv") - def SetAuxString (self, text, attrs): pass + @method (in_signature="svb") + def UpdateAuxString (self, text, attrs, show): pass @method () def ShowAuxString (self): pass @@ -39,8 +39,8 @@ class IPanel (dbus.service.Object): @method () def HideAuxString (self): pass - @method (in_signature="v") - def UpdateLookupTable (self, lookup_table): pass + @method (in_signature="vb") + def UpdateLookupTable (self, lookup_table, show): pass @method () def ShowCandidateWindow (self): pass @@ -55,6 +55,9 @@ class IPanel (dbus.service.Object): def HideLanguageBar (self): pass @method () + def Reste (self): pass + + @method () def Destroy (self): pass #signals diff --git a/ibusdaemon/bus.py b/ibusdaemon/bus.py index 3a099fb..be20f58 100644 --- a/ibusdaemon/bus.py +++ b/ibusdaemon/bus.py @@ -60,17 +60,14 @@ class IBus (ibus.Object): self._focused_client.focus_out () # Install all callback functions - id = client.connect ("preedit-changed", self._preedit_changed_cb) + id = client.connect ("update-preedit", self._update_preedit_cb) self._client_handlers.append (id) - id = client.connect ("aux-string-changed", self._aux_string_changed_cb) + id = client.connect ("update-aux-string", self._update_aux_string_cb) self._client_handlers.append (id) id = client.connect ("update-lookup-table", self._update_lookup_table_cb) self._client_handlers.append (id) - id = client.connect ("show-lookup-table", self._show_lookup_table_cb) - self._client_handlers.append (id) - id = client.connect ("hide-lookup-table", self._hide_lookup_table_cb) - self._client_handlers.append (id) + self._panel.reset () self._focused_client = client self._last_focused_client = client client.focus_in () @@ -83,9 +80,11 @@ class IBus (ibus.Object): del self._client_handlers[:] self._focused_client = None client.focus_out () + self._panel.reset () def reset (self, dbusconn): client = self._lookup_client (dbusconn) + self._panel.reset () client.reset () def is_enabled (self, dbusconn): @@ -127,20 +126,20 @@ class IBus (ibus.Object): raise ibus.IBusException ("not register the client") return self._clients[dbusconn] - def _preedit_changed_cb (self, client, text, attrs, cursor_pos): + def _update_preedit_cb (self, client, text, attrs, cursor_pos, show): assert self._focused_client == client - self._panel.set_preedit_string (text, attrs, cursor_pos) + self._panel.update_preedit_string (text, attrs, cursor_pos, show) - def _aux_string_changed_cb (self, client, text, attrs): + def _update_aux_string_cb (self, client, text, attrs, show): assert self._focused_client == client - self._panel.set_aux_string (text, attrs) + self._panel.update_aux_string (text, attrs, show) - def _update_lookup_table_cb (self, client, lookup_table): + def _update_lookup_table_cb (self, client, lookup_table, show): assert self._focused_client == client - self._panel.update_lookup_table (lookup_table) + self._panel.update_lookup_table (lookup_table, show) def _show_lookup_table_cb (self, client, lookup_table): assert self._focused_client == client diff --git a/ibusdaemon/client.py b/ibusdaemon/client.py index 37371fa..80c86f6 100644 --- a/ibusdaemon/client.py +++ b/ibusdaemon/client.py @@ -3,26 +3,18 @@ import ibus class Client (ibus.Object): __gsignals__ = { - "preedit-changed" : ( + "update-preedit" : ( gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, - (gobject.TYPE_STRING, gobject.TYPE_PYOBJECT, gobject.TYPE_INT)), - "aux-string-changed" : ( + (gobject.TYPE_STRING, gobject.TYPE_PYOBJECT, gobject.TYPE_INT, gobject.TYPE_BOOLEAN)), + "update-aux-string" : ( gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, - (gobject.TYPE_STRING, gobject.TYPE_PYOBJECT)), + (gobject.TYPE_STRING, gobject.TYPE_PYOBJECT, gobject.TYPE_BOOLEAN)), "update-lookup-table" : ( gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, - (gobject.TYPE_PYOBJECT, )), - "show-lookup-table" : ( - gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - ()), - "hide-lookup-table" : ( - gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - ()) + (gobject.TYPE_PYOBJECT, gobject.TYPE_BOOLEAN)), } def __init__ (self, name, ibusconn): @@ -113,12 +105,12 @@ class Client (ibus.Object): def commit_string (self, text): self._ibusconn.emit_dbus_signal ("CommitString", text) - def preedit_changed (self, text, attrs, cursor_pos): + def update_preedit (self, text, attrs, cursor_pos, show): if self._use_preedit: - self._ibusconn.emit_dbus_signal ("PreeditChanged", text, attrs, cursor_pos) + self._ibusconn.emit_dbus_signal ("UpdatePreedit", text, attrs, cursor_pos, show) else: # show preedit on panel - self.emit ("preedit-changed", text, attrs, cursor_pos) + self.emit ("update-preedit", text, attrs, cursor_pos, show) def set_engine (self, engine): if self._engine == engine: @@ -149,25 +141,17 @@ class Client (ibus.Object): def _commit_string_cb (self, engine, text): self.commit_string (text) - def _preedit_changed_cb (self, engine, text, attrs, cursor_pos): - self.preedit_changed (text, attrs, cursor_pos) + def _update_preedit_cb (self, engine, text, attrs, cursor_pos, show): + self.update_preedit (text, attrs, cursor_pos, show) - def _aux_string_changed_cb (self, engine, text, attrs): + def _update_aux_string_cb (self, engine, text, attrs, show): self._aux_string = text self._aux_attrs = attrs - self.emit ("aux-string-changed", text, attrs) + self.emit ("update-aux-string", text, attrs, show) - def _update_lookup_table_cb (self, engine, lookup_table): + def _update_lookup_table_cb (self, engine, lookup_table, show): self._lookup_table = lookup_table - self.emit ("update-lookup-table", lookup_table) - - def _show_lookup_table_cb (self, engine): - self._show_lookup_table = True - self.emit ("show-lookup-table") - - def _hide_lookup_table_cb (self, engine): - self._show_lookup_table = False - self.emit ("hide-lookup-table") + self.emit ("update-lookup-table", lookup_table, show) def _remove_engine_handlers (self): assert self._engine != None @@ -180,14 +164,10 @@ class Client (ibus.Object): self._engine_handler_ids.append (id) id = self._engine.connect ("commit-string", self._commit_string_cb) self._engine_handler_ids.append (id) - id = self._engine.connect ("preedit-changed", self._preedit_changed_cb) + id = self._engine.connect ("update-preedit", self._update_preedit_cb) self._engine_handler_ids.append (id) - id = self._engine.connect ("aux-string-changed", self._aux_string_changed_cb) + id = self._engine.connect ("update-aux-string", self._update_aux_string_cb) self._engine_handler_ids.append (id) id = self._engine.connect ("update-lookup-table", self._update_lookup_table_cb) self._engine_handler_ids.append (id) - id = self._engine.connect ("show-lookup-table", self._show_lookup_table_cb) - self._engine_handler_ids.append (id) - id = self._engine.connect ("hide-lookup-table", self._hide_lookup_table_cb) - self._engine_handler_ids.append (id) gobject.type_register (Client) diff --git a/ibusdaemon/engine.py b/ibusdaemon/engine.py index ad0d461..8ea060e 100644 --- a/ibusdaemon/engine.py +++ b/ibusdaemon/engine.py @@ -12,26 +12,18 @@ class Engine (ibus.Object): gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, (gobject.TYPE_UINT, gobject.TYPE_BOOLEAN, gobject.TYPE_UINT )), - "preedit-changed" : ( + "update-preedit" : ( gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, - (gobject.TYPE_STRING, gobject.TYPE_PYOBJECT, gobject.TYPE_INT)), - "aux-string-changed" : ( + (gobject.TYPE_STRING, gobject.TYPE_PYOBJECT, gobject.TYPE_INT, gobject.TYPE_BOOLEAN)), + "update-aux-string" : ( gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, - (gobject.TYPE_STRING, gobject.TYPE_PYOBJECT)), + (gobject.TYPE_STRING, gobject.TYPE_PYOBJECT, gobject.TYPE_BOOLEAN)), "update-lookup-table" : ( gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, - (gobject.TYPE_PYOBJECT, )), - "show-lookup-table" : ( - gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - ()), - "hide-lookup-table" : ( - gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - ()) + (gobject.TYPE_PYOBJECT, gobject.TYPE_BOOLEAN)), } def __init__ (self, factory, ibusconn, object_path): @@ -55,23 +47,17 @@ class Engine (ibus.Object): args = message.get_args_list () self.emit ("forward-key-event", args[0], bool (arg[1]), arg[2]) return True - elif message.is_signal (ibus.IBUS_ENGINE_IFACE, "PreeditChanged"): + elif message.is_signal (ibus.IBUS_ENGINE_IFACE, "UpdatePreedit"): args = message.get_args_list () - self.emit ("preedit-changed", args[0], args[1], args[2]) + self.emit ("update-preedit", args[0], args[1], args[2], args[3]) return True - elif message.is_signal (ibus.IBUS_ENGINE_IFACE, "AuxStringChanged"): + elif message.is_signal (ibus.IBUS_ENGINE_IFACE, "UpdateAuxString"): args = message.get_args_list () - self.emit ("aux-string-changed", args[0], args[1]) + self.emit ("update-aux-string", args[0], args[1], args[2]) return True elif message.is_signal (ibus.IBUS_ENGINE_IFACE, "UpdateLookupTable"): args = message.get_args_list () - self.emit ("update-lookup-table", args[0]) - return True - elif message.is_signal (ibus.IBUS_ENGINE_IFACE, "ShowLookupTable"): - self.emit ("show-lookup-table") - return True - elif message.is_signal (ibus.IBUS_ENGINE_IFACE, "HideLookupTable"): - self.emit ("hide-lookup-table") + self.emit ("update-lookup-table", args[0], args[1]) return True else: return False diff --git a/ibusdaemon/panel.py b/ibusdaemon/panel.py index 18a3fe1..dfca789 100644 --- a/ibusdaemon/panel.py +++ b/ibusdaemon/panel.py @@ -34,8 +34,8 @@ class Panel (ibus.Object): def set_cursor_location (self, x, y, w, h): self._panel.SetCursorLocation (x, y, w, h) - def set_preedit_string (self, text, attrs, cursor_pos): - self._panel.SetPreeditString (text, attrs, cursor_pos) + def update_preedit (self, text, attrs, cursor_pos, show): + self._panel.UpdatePreedit (text, attrs, cursor_pos, show) def show_preedit_string (self): self._panel.ShowPreeditString () @@ -43,8 +43,8 @@ class Panel (ibus.Object): def hide_preedit_string (self): slef._panel.HidePreeditString () - def set_aux_string (self, text, attrs): - self._panel.SetAuxString (text, attrs) + def update_aux_string (self, text, attrs, show): + self._panel.UpdateAuxString (text, attrs, show) def show_aux_string (self): self._panel.ShowAuxString () @@ -52,8 +52,8 @@ class Panel (ibus.Object): def hide_aux_string (self): slef._panel.HideAuxString () - def update_lookup_table (self, lookup_table): - self._panel.UpdateLookupTable (lookup_table) + def update_lookup_table (self, lookup_table, show): + self._panel.UpdateLookupTable (lookup_table, show) def show_candidate_window (self): self._panel.ShowCandidateWindow () @@ -67,6 +67,9 @@ class Panel (ibus.Object): def hide_language_bar (self): self._panel.HideLanguageBar () + def reset (self): + self._panel.Reste () + def destroy (self): if self._ibusconn != None: self._panel.Destroy () diff --git a/panel/candidatepanel.py b/panel/candidatepanel.py index 87ef552..cd254fa 100644 --- a/panel/candidatepanel.py +++ b/panel/candidatepanel.py @@ -82,7 +82,6 @@ class CandidateArea (gtk.HBox): else: self._labels[0][0].set_text ("1.") - class CandidatePanel (gtk.VBox): __gproperties__ = { 'orientation' : (gtk.Orientation, # type @@ -110,9 +109,11 @@ class CandidatePanel (gtk.VBox): self._orientation = gtk.ORIENTATION_HORIZONTAL self._orientation = gtk.ORIENTATION_VERTICAL self._show_preedit_string = False - self._preedit_string = "preedit string" + self._show_aux_string = False + self._show_lookup_table = False + self._preedit_string = "" self._preedit_attrs = pango.AttrList () - self._aux_string = "aux string" + self._aux_string = "" self._aux_attrs = pango.AttrList () self._lookup_table = None @@ -138,9 +139,15 @@ class CandidatePanel (gtk.VBox): self._aux_label.set_alignment (0.0, 0.5) self._aux_label.set_padding (8, 0) self._tooltips.set_tip (self._aux_label, "Aux string") + self._aux_label.set_no_show_all (True) + if self._show_aux_string: + self._aux_label.show () # create candidates area self._candidate_area = CandidateArea (self._orientation) + self._candidate_area.set_no_show_all (True) + if self._show_lookup_table: + self._candidate_area.show_all () # create state label self._state_label = gtk.Label () @@ -206,17 +213,47 @@ class CandidatePanel (gtk.VBox): self.hide_all () self.show_all () - def show_preedit_string (self): self._show_preedit_string = True self._preedit_label.show () + self._check_show_states () def hide_preedit_string (self): - self._hide_preedit_string = False + self._show_preedit_string = False self._preedit_label.hide () + self._check_show_states () - def set_aux_string (self, text, attrs): + def update_preedit (self, text, attrs, cursor_pos, show): attrs = PangoAttrList (attrs) + if show: + self.show_preedit_string () + else: + self.hide_preedit_string () + self._preedit_string = text + self._preedit_label.set_text (text) + if attrs == None: + attrs = pango.AttrList () + self._preedit_attrs = attrs + self._preedit_label.set_attributes (attrs) + + def show_aux_string (self): + self._show_aux_string = True + self._aux_label.show () + self._check_show_states () + + def hide_aux_string (self): + self._show_aux_string = False + self._aux_label.hide () + self._check_show_states () + + def update_aux_string (self, text, attrs, show): + attrs = PangoAttrList (attrs) + + if show: + self.show_aux_string () + else: + self.hide_aux_string () + self._aux_string = text self._aux_label.set_text (text) if attrs == None: @@ -224,21 +261,51 @@ class CandidatePanel (gtk.VBox): self._aux_attrs = attrs self._aux_label.set_attributes (attrs) - def set_preedit_string (self, text, attrs, cursor_pos): - attrs = PangoAttrList (attrs) - self._preedit_string = text - self._preedit_label.set_text (text) - if attrs == None: - attrs = pango.AttrList () - self._preedit_attrs = attrs - self._preedit_label.set_attributes (attrs) + def show_lookup_table (self): + self._show_lookup_table = True + self._candidate_area.set_no_show_all (False) + self._candidate_area.show_all () + self._check_show_states () + + def hide_lookup_table (self): + self._show_lookup_table = False + self._candidate_area.hide_all () + self._candidate_area.set_no_show_all (True) + self._check_show_states () + + def update_lookup_table (self, lookup_table, show): + if lookup_table == None: + lookup_table = ibus.LookupTable () + + if show: + self.show_lookup_table () + else: + self.hide_lookup_table () - def set_lookup_table (self, lookup_table): self._lookup_table = lookup_table candidates = self._lookup_table.get_canidates_in_current_page () candidates = map (lambda x: (x[0], PangoAttrList (x[1])), candidates) self._candidate_area.set_candidates (candidates, self._lookup_table.get_cursor_pos_in_current_page ()) + def _check_show_states (self): + if self._show_preedit_string or \ + self._show_aux_string or \ + self._show_lookup_table: + self.show_all () + self.emit ("show") + else: + self.hide_all () + self.emit ("hide") + + def reset (self): + self.hide () + self.hide_preedit_string () + self.hide_aux_string () + self.hide_lookup_table () + self.set_preedit_string ("", None, 0) + self.set_aux_string ("", None) + self.set_lookup_table (None) + def set_orientation (self, orientation): if self._orientation == orientation: return diff --git a/panel/candidatewindow.py b/panel/candidatewindow.py index d1fc086..572f45b 100644 --- a/panel/candidatewindow.py +++ b/panel/candidatewindow.py @@ -28,12 +28,13 @@ class CandidateWindow (gtk.Window): self._candidate_panel.connect ("size-request", self._size_request_cb) self._candidate_panel.connect ("cursor-up", lambda x: self.emit ("cursor-up")) self._candidate_panel.connect ("cursor-down", lambda x: self.emit ("cursor-down")) + self._candidate_panel.connect ("show", lambda x: self.show ()) + self._candidate_panel.connect ("hide", lambda x: self.hide ()) self.add (self._candidate_panel) self.move (100, 100) - self.show_all () - def set_preedit_string (self, text, attrs, cursor_pos): - self._candidate_panel.set_preedit_string (text, attrs, cursor_pos) + def update_preedit (self, text, attrs, cursor_pos, show): + self._candidate_panel.update_preedit (text, attrs, cursor_pos, show) def show_preedit_string (self, text, attrs): self._candidate_panel.show_preedit_string () @@ -41,11 +42,15 @@ class CandidateWindow (gtk.Window): def hide_preedit_string (self, text, attrs): self._candidate_panel.hide_preedit_string () - def set_aux_string (self, text, attrs): - self._candidate_panel.set_aux_string (text, attrs) + def update_aux_string (self, text, attrs, show): + self._candidate_panel.update_aux_string (text, attrs, show) - def set_lookup_table (self, lookup_table): - self._candidate_panel.set_lookup_table (lookup_table) + def update_lookup_table (self, lookup_table, show): + self._candidate_panel.update_lookup_table (lookup_table, show) + + def reset (self): + self.hide () + self._candidate_panel.reset () def _size_request_cb (self, widget, size): self.resize (1, 1) diff --git a/panel/languagebar.py b/panel/languagebar.py index cada51c..00ee54e 100644 --- a/panel/languagebar.py +++ b/panel/languagebar.py @@ -55,6 +55,9 @@ class LanguageBarWindow (gtk.Window): def _size_request_cb (self, widget, size): self.resize (size.width, size.height) + def reset (self): + pass + def do_size_allocate (self, allocation): gtk.Window.do_size_allocate (self, allocation) root = gdk.get_default_root_window () diff --git a/panel/panel.py b/panel/panel.py index 5b3aecf..2194f5c 100644 --- a/panel/panel.py +++ b/panel/panel.py @@ -18,9 +18,9 @@ class Panel (gobject.GObject): def set_cursor_location (self, x, y, w, h): self._candidate_panel.move (x + w, y + h) - - def set_preedit_string (self, text, attrs, cursor_pos): - self._candidate_panel.set_preedit_string (text, attrs, cursor_pos) + + def update_preedit (self, text, attrs, cursor_pos, show): + self._candidate_panel.update_preedit (text, attrs, cursor_pos, show) def show_preedit_string (self): self._candidate_panel.show_preedit_string () @@ -28,17 +28,17 @@ class Panel (gobject.GObject): def hide_preedit_string (self): self._candidate_panel.hide_preedit_string () - def set_aux_string (self, text, attrs): - self._candidate_panel.set_aux_string (text, attrs) + def update_aux_string (self, text, attrs, show): + self._candidate_panel.update_aux_string (text, attrs, show) def show_aux_string (self): self._candidate_panel.show_aux_string () def hide_aux_string (self): self._candidate_panel.hide_aux_string () - - def update_lookup_table (self, lookup_table): - self._candidate_panel.set_lookup_table (lookup_table) + + def update_lookup_table (self, lookup_table, show): + self._candidate_panel.update_lookup_table (lookup_table, show) def show_candidate_window (self): self._candidate_panel.show () @@ -52,6 +52,10 @@ class Panel (gobject.GObject): def hide_language_bar (self): selk._language_bar.hide () + def reset (self): + self._candidate_panel.reset () + self._language_bar.reset () + class PanelProxy (interface.IPanel): def __init__ (self, dbusconn, object_path): interface.IPanel.__init__ (self, dbusconn, object_path) @@ -60,10 +64,10 @@ class PanelProxy (interface.IPanel): def SetCursorLocation (self, x, y, w, h): self._panel.set_cursor_location (x, y, w, h) - - def SetPreeditString (self, text, attrs, cursor_pos): + + def UpdatePreedit (self, text, attrs, cursor_pos, show): attrs = ibus.attr_list_from_dbus_value (attrs) - self._panel.set_preedit_string (text, atrrs, cursor_pos) + self._panel.update_preedit (text, atrrs, cursor_pos, show) def ShowPreeditString (self): self._panel.show_preedit_string () @@ -71,9 +75,9 @@ class PanelProxy (interface.IPanel): def HidePreeditString (self): self._panel.hide_preedit_string () - def SetAuxString (self, text, attrs): + def UpdateAuxString (self, text, attrs, show): attrs = ibus.attr_list_from_dbus_value (attrs) - self._panel.set_aux_string (text, attrs) + self._panel.update_aux_string (text, attrs, show) def ShowAuxString (self): self._panel.show_aux_string () @@ -81,9 +85,9 @@ class PanelProxy (interface.IPanel): def HideAuxString (self): self._panel.hide_aux_string () - def UpdateLookupTable (self, lookup_table): + def UpdateLookupTable (self, lookup_table, show): lookup_table = ibus.lookup_table_from_dbus_value (lookup_table) - self._panel.update_lookup_table (lookup_table) + self._panel.update_lookup_table (lookup_table, show) def ShowCandidateWindow (self): self._panel.show_candidate_window () @@ -97,6 +101,9 @@ class PanelProxy (interface.IPanel): def HideLanguageBar (self): self._panel.hide_language_bar () + def Reset (self): + self._panel.reset () + def Destroy (self): self._pabel.destroy ()