diff options
author | fujiwarat <takao.fujiwara1@gmail.com> | 2010-03-11 19:35:03 +0900 |
---|---|---|
committer | fujiwarat <takao.fujiwara1@gmail.com> | 2010-03-11 22:31:48 +0900 |
commit | 0b8a908719588d202bd83c85dc2052f5144bb691 (patch) | |
tree | dfc3b0145062b2d75363b227f2d67290711a1dcd | |
parent | f8c60a9844df6da08cc0327b62dec6917961dfc4 (diff) | |
download | ibus-anthy-0b8a908719588d202bd83c85dc2052f5144bb691.tar.gz |
Fix Segment convertion mode. #147
-rw-r--r-- | engine/engine.py | 94 | ||||
-rw-r--r-- | setup/anthyprefs.py | 1 | ||||
-rw-r--r-- | setup/main.py | 16 | ||||
-rw-r--r-- | setup/setup.glade | 60 |
4 files changed, 149 insertions, 22 deletions
diff --git a/engine/engine.py b/engine/engine.py index 6b95ab8..ab9a406 100644 --- a/engine/engine.py +++ b/engine/engine.py @@ -72,6 +72,10 @@ CONV_MODE_WIDE_LATIN_2, \ CONV_MODE_WIDE_LATIN_3, \ CONV_MODE_PREDICTION = range(14) +SEGMENT_DEFAULT = 0 +SEGMENT_SINGLE = 1 << 0 +SEGMENT_IMMEDIATE = 1 << 1 + CLIPBOARD_RECONVERT = range(1) LINK_DICT_EMBEDDED, \ @@ -117,6 +121,7 @@ class Engine(ibus.EngineBase): # init state self.__idle_id = 0 self.__input_mode = INPUT_MODE_HIRAGANA + self.__segment_mode = SEGMENT_DEFAULT self.__dict_mode = 0 self.__prop_dict = {} self.__is_utf8 = (getpreferredencoding().lower() == "utf-8") @@ -135,6 +140,11 @@ class Engine(ibus.EngineBase): mode = 'TypingMode.' + ['Romaji', 'Kana', 'ThumbShift'][mode] self.__typing_mode_activate(mode, ibus.PROP_STATE_CHECKED) + mode = self.__prefs.get_value('common', 'conversion_segment_mode') + mode = 'SegmentMode.' + ['Multi', 'Single', + 'ImmediateMulti', 'ImmediateSingle'][mode] + self.__segment_mode_activate(mode, ibus.PROP_STATE_CHECKED) + # use reset to init values self.__reset() @@ -216,6 +226,7 @@ class Engine(ibus.EngineBase): typing_mode_prop.set_sub_props(props) anthy_props.append(typing_mode_prop) + self.__set_segment_mode_props(anthy_props) self.__set_dict_mode_props(anthy_props) self.__set_dict_config_props(anthy_props) anthy_props.append(ibus.Property(key=u"setup", @@ -235,6 +246,34 @@ class Engine(ibus.EngineBase): signal.signal(signum, signal.SIG_DFL) os.kill(os.getpid(), signum) + def __set_segment_mode_props(self, anthy_props): + segment_mode_prop = ibus.Property(key=u"SegmentMode", + type=ibus.PROP_TYPE_MENU, + label=u"連", + tooltip=UN(_("Switch conversion mode"))) + self.__prop_dict[u"SegmentMode"] = segment_mode_prop + + props = ibus.PropList() + props.append(ibus.Property(key=u"SegmentMode.Multi", + type=ibus.PROP_TYPE_RADIO, + label=UN(_("Multiple segment")))) + props.append(ibus.Property(key=u"SegmentMode.Single", + type=ibus.PROP_TYPE_RADIO, + label=UN(_("Single segment")))) + props.append(ibus.Property(key=u"SegmentMode.ImmediateMulti", + type=ibus.PROP_TYPE_RADIO, + label=UN(_("Immediate conversion (Multiple segment)")))) + props.append(ibus.Property(key=u"SegmentMode.ImmediateSingle", + type=ibus.PROP_TYPE_RADIO, + label=UN(_("Immediate conversion (Single segment)")))) + props[self.__segment_mode].set_state(ibus.PROP_STATE_CHECKED) + + for prop in props: + self.__prop_dict[prop.key] = prop + + segment_mode_prop.set_sub_props(props) + anthy_props.append(segment_mode_prop) + def __set_dict_mode_props(self, anthy_props): short_label = self.__prefs.get_value('dict/file/embedded', 'short_label') @@ -522,6 +561,9 @@ class Engine(ibus.EngineBase): elif prop_name.startswith(u"TypingMode."): self.__typing_mode_activate(prop_name, state) return + elif prop_name.startswith(u"SegmentMode."): + self.__segment_mode_activate(prop_name, state) + return elif prop_name.startswith(u"DictMode."): self.__dict_mode_activate(prop_name, state) return @@ -609,6 +651,31 @@ class Engine(ibus.EngineBase): prop.label = label self.update_property(prop) + def __segment_mode_activate(self, prop_name, state): + segment_modes = { + u"SegmentMode.Multi" : (SEGMENT_DEFAULT, u"連"), + u"SegmentMode.Single" : (SEGMENT_SINGLE, u"単"), + u"SegmentMode.ImmediateMulti" : (SEGMENT_IMMEDIATE, u"逐|連"), + u"SegmentMode.ImmediateSingle" : + (SEGMENT_IMMEDIATE | SEGMENT_SINGLE, u"逐|単"), + } + + if prop_name not in segment_modes: + print >> sys.stderr, "Unknow prop_name = %s" % prop_name + return + self.__prop_dict[prop_name].set_state(state) + self.update_property(self.__prop_dict[prop_name]) + + mode, label = segment_modes[prop_name] + + self.__segment_mode = mode + prop = self.__prop_dict[u"SegmentMode"] + prop.label = label + self.update_property(prop) + + self.__reset() + self.__invalidate() + def __dict_mode_get_prop_name(self, mode): if mode == 0: id = 'embedded' @@ -681,8 +748,21 @@ class Engine(ibus.EngineBase): self.__remove_dict_files() super(Engine,self).do_destroy() + def __join_all_segments(self): + while True: + conv_stat = anthy.anthy_conv_stat() + self.__context.get_stat(conv_stat) + seg = conv_stat.nr_segment - self.__cursor_pos + + if seg > 1: + self.__context.resize_segment(self.__cursor_pos, 1) + else: + break + # begine convert def __begin_anthy_convert(self): + if self.__segment_mode & SEGMENT_IMMEDIATE: + self.__end_anthy_convert() if self.__convert_mode == CONV_MODE_ANTHY: return self.__convert_mode = CONV_MODE_ANTHY @@ -691,6 +771,8 @@ class Engine(ibus.EngineBase): text, cursor = self.__preedit_ja_string.get_hiragana(True) self.__context.set_string(text.encode("utf8")) + if self.__segment_mode & SEGMENT_SINGLE: + self.__join_all_segments() conv_stat = anthy.anthy_conv_stat() self.__context.get_stat(conv_stat) @@ -699,7 +781,10 @@ class Engine(ibus.EngineBase): text = unicode(buf, "utf-8") self.__segments.append((0, text)) - self.__cursor_pos = 0 + if self.__segment_mode & SEGMENT_IMMEDIATE: + self.__cursor_pos = conv_stat.nr_segment - 1 + else: + self.__cursor_pos = 0 self.__fill_lookup_table() self.__lookup_table_visible = False @@ -1177,7 +1262,10 @@ class Engine(ibus.EngineBase): return True # Input Japanese - if self.__convert_mode == CONV_MODE_ANTHY: + if self.__segment_mode & SEGMENT_IMMEDIATE: + # Commit nothing + pass + elif self.__convert_mode == CONV_MODE_ANTHY: for i, (seg_index, text) in enumerate(self.__segments): self.__context.commit_segment(i, seg_index) self.__commit_string(self.__convert_chars) @@ -1192,6 +1280,8 @@ class Engine(ibus.EngineBase): shift = False self.__preedit_ja_string.set_shift(shift) self.__preedit_ja_string.insert(unichr(keyval)) + if self.__segment_mode & SEGMENT_IMMEDIATE: + self.__begin_anthy_convert() self.__invalidate() return True diff --git a/setup/anthyprefs.py b/setup/anthyprefs.py index 2f66a3d..d46fcb8 100644 --- a/setup/anthyprefs.py +++ b/setup/anthyprefs.py @@ -156,6 +156,7 @@ _config = { 'common': { 'input_mode': 0, 'typing_method': 0, + 'conversion_segment_mode': 0, 'period_style': 0, 'symbol_style': 1, diff --git a/setup/main.py b/setup/main.py index a05d421..78a7755 100644 --- a/setup/main.py +++ b/setup/main.py @@ -64,7 +64,7 @@ class AnthySetup(object): if path.exists(icon_path): xml.get_widget('main').set_icon_from_file(icon_path) - for name in ['input_mode', 'typing_method', + for name in ['input_mode', 'typing_method', 'conversion_segment_mode', 'period_style', 'symbol_style', 'ten_key_mode', 'behavior_on_focus_out', 'behavior_on_period', 'half_width_symbol', 'half_width_number', 'half_width_space', @@ -298,19 +298,19 @@ class AnthySetup(object): if new: if file in files: - self.__run_message_dialog(_("Your choosed file has already been added."), + self.__run_message_dialog(_("Your choosed file has already been added: ") + file, gtk.MESSAGE_ERROR) return if not path.exists(file): - self.__run_message_dialog(_("Your choosed file does not exist."), + self.__run_message_dialog(_("Your choosed file does not exist: ") + file, gtk.MESSAGE_ERROR) return if path.isdir(file): - self.__run_message_dialog(_("Your choosed file is a directory."), + self.__run_message_dialog(_("Your choosed file is a directory: " + file), gtk.MESSAGE_ERROR) return if file.startswith(self.__get_userhome() + "/.anthy"): - self.__run_message_dialog(_("You cannot add dictionaries in the anthy private directory."), + self.__run_message_dialog(_("You cannot add dictionaries in the anthy private directory: " + file), gtk.MESSAGE_ERROR) return @@ -593,6 +593,10 @@ class AnthySetup(object): else: return command = self.prefs.get_value('common', key) + if not path.exists(command[0]): + self.__run_message_dialog(_("Your file does not exist: ") + command[0], + gtk.MESSAGE_ERROR) + return os.spawnl(os.P_NOWAIT, *command) def on_btn_dict_add_clicked(self, widget): @@ -676,7 +680,7 @@ class AnthySetup(object): gtk.MESSAGE_ERROR) return if not path.exists(dict_file): - self.__run_message_dialog(_("Your file does not exist."), + self.__run_message_dialog(_("Your file does not exist: ") + dict_file, gtk.MESSAGE_ERROR) return diff --git a/setup/setup.glade b/setup/setup.glade index d44d7fb..7130411 100644 --- a/setup/setup.glade +++ b/setup/setup.glade @@ -33,7 +33,7 @@ <child> <widget class="GtkTable" id="table1"> <property name="visible">True</property> - <property name="n_rows">2</property> + <property name="n_rows">3</property> <property name="n_columns">2</property> <property name="column_spacing">8</property> <property name="row_spacing">4</property> @@ -51,6 +51,22 @@ </packing> </child> <child> + <widget class="GtkComboBox" id="input_mode"> + <property name="visible">True</property> + <property name="items" translatable="yes">Hiragana +Katakana +Half Width Katakana +Latin +Wide Latin</property> + <signal name="changed" handler="on_cb_changed"/> + </widget> + <packing> + <property name="left_attach">1</property> + <property name="right_attach">2</property> + <property name="y_options"></property> + </packing> + </child> + <child> <widget class="GtkLabel" id="label21"> <property name="visible">True</property> <property name="xalign">0</property> @@ -66,34 +82,50 @@ </packing> </child> <child> - <widget class="GtkComboBox" id="input_mode"> + <widget class="GtkComboBox" id="typing_method"> <property name="visible">True</property> - <property name="items" translatable="yes">Hiragana -Katakana -Half Width Katakana -Latin -Wide Latin</property> + <property name="items" translatable="yes">Romaji +Kana +Thumb shift</property> <signal name="changed" handler="on_cb_changed"/> </widget> <packing> <property name="left_attach">1</property> <property name="right_attach">2</property> + <property name="top_attach">1</property> + <property name="bottom_attach">2</property> <property name="y_options"></property> </packing> </child> <child> - <widget class="GtkComboBox" id="typing_method"> + <widget class="GtkLabel" id="label10"> <property name="visible">True</property> - <property name="items" translatable="yes">Romaji -Kana -Thumb shift</property> + <property name="xalign">0</property> + <property name="label" translatable="yes">Conversion _Mode:</property> + <property name="use_underline">True</property> + <property name="mnemonic_widget">conversion_segment_mode</property> + </widget> + <packing> + <property name="top_attach">2</property> + <property name="bottom_attach">3</property> + <property name="x_options">GTK_FILL</property> + <property name="y_options"></property> + </packing> + </child> + <child> + <widget class="GtkComboBox" id="conversion_segment_mode"> + <property name="visible">True</property> + <property name="items" translatable="yes">Multiple segment +Single segment +Immediate conversion (Multiple segment) +Immediate conversion (Single segment)</property> <signal name="changed" handler="on_cb_changed"/> </widget> <packing> <property name="left_attach">1</property> <property name="right_attach">2</property> - <property name="top_attach">1</property> - <property name="bottom_attach">2</property> + <property name="top_attach">2</property> + <property name="bottom_attach">3</property> <property name="y_options"></property> </packing> </child> @@ -153,7 +185,7 @@ Thumb shift</property> <widget class="GtkLabel" id="label13"> <property name="visible">True</property> <property name="xalign">0</property> - <property name="label" translatable="yes">Sy_mbol Style:</property> + <property name="label" translatable="yes">Symbo_l Style:</property> <property name="use_underline">True</property> <property name="mnemonic_widget">symbol_style</property> </widget> |