From a55783887e757f02078143c2d12031a33c9e9223 Mon Sep 17 00:00:00 2001 From: bnauwelaerts Date: Sat, 2 Feb 2013 13:03:48 +0100 Subject: [PATCH 2/5] Add auto_select functionality to select the first phrase when typing. Useful for Cyrillic transliteration. --- engine/table.py | 26 +++++++++++++++++++++++--- engine/tabsqlitedb.py | 1 + tables/template.txt | 3 +++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/engine/table.py b/engine/table.py index c106a0a..4a10636 100644 --- a/engine/table.py +++ b/engine/table.py @@ -228,6 +228,13 @@ class editor(object): "ChineseMode")) if self._chinese_mode == None: self._chinese_mode = self.get_chinese_mode() + + self._auto_select = variant_to_value(self._config.get_value( + self._config_section, + "AutoSelect")) + if self._auto_select == None: + self._auto_select = self.db.get_ime_property('auto_select').lower() == u'true' + def init_select_keys(self): # __select_keys: lookup table select keys/labels @@ -728,7 +735,9 @@ class editor(object): if ascii.ispunct (self._chars[0][-1].encode('ascii')) \ or len (self._chars[0][:-1]) \ in self.db.pkeylens \ - or only_one_last: + or only_one_last \ + or self._auto_select: + # because we use [!@#$%] to denote [12345] # in py_mode, so we need to distinguish them ## old manner: @@ -750,7 +759,7 @@ class editor(object): self._lookup_table.clear() self._lookup_table.set_cursor_visible(True) return False - else: + else: # this is not a punct or not a valid phrase # last time self._chars[1].append( self._chars[0].pop() ) @@ -1142,11 +1151,19 @@ class tabengine (IBus.Engine): self._full_width_punct[1] = self.db.get_ime_property('def_full_width_punct').lower() == u'true' # some properties we will involved, Property is taken from scim. #self._setup_property = Property ("setup", _("Setup")) + self._auto_commit = variant_to_value(self._config.get_value( self._config_section, "AutoCommit")) if self._auto_commit == None: self._auto_commit = self.db.get_ime_property('auto_commit').lower() == u'true' + + self._auto_select = variant_to_value(self._config.get_value( + self._config_section, + "AutoSelect")) + if self._auto_select == None: + self._auto_select = self.db.get_ime_property('auto_select').lower() == u'true' + # the commit phrases length self._len_list = [0] # connect to SpeedMeter @@ -1736,7 +1753,10 @@ class tabengine (IBus.Engine): sp_res = self._editor.space () #return (KeyProcessResult,whethercommit,commitstring) if sp_res[0]: - self.commit_string (sp_res[1]) + if self._auto_select: + self.commit_string ("%s " %sp_res[1]) + else: + self.commit_string (sp_res[1]) #self.add_string_len(sp_res[1]) self.db.check_phrase (sp_res[1], sp_res[2]) else: diff --git a/engine/tabsqlitedb.py b/engine/tabsqlitedb.py index 78fa85d..fa56053 100644 --- a/engine/tabsqlitedb.py +++ b/engine/tabsqlitedb.py @@ -99,6 +99,7 @@ class tabsqlitedb: 'user_can_define_phrase':'FALSE', 'pinyin_mode':'FALSE', 'dynamic_adjust':'FALSE', + 'auto_select':'false', 'auto_commit':'false', #'no_check_chars':u'', 'description':'A IME under IBus Table', diff --git a/tables/template.txt b/tables/template.txt index 40bc915..f51cdf8 100644 --- a/tables/template.txt +++ b/tables/template.txt @@ -63,6 +63,9 @@ MAX_KEY_LENGTH = 4 ### Use auto_commit mode as default AUTO_COMMIT = FALSE +### Automatically selects the first phrase when typing +AUTO_SELECT = FALSE + ### Use full width punctuation by default DEF_FULL_WIDTH_PUNCT = TRUE ### Not use full width letter by default -- 1.7.11.7