From cd307b480b0e20137880245ed8ae971c9f024d6d Mon Sep 17 00:00:00 2001 From: Daiki Ueno Date: Fri, 3 Sep 2010 14:14:13 +0900 Subject: [PATCH] Support multiple sysdict. --- engine/factory.py | 5 +- engine/skk.py | 19 + setup/config.py | 4 + setup/ibus-skk-preferences.ui | 907 +++++++++++++++++----------------- setup/main.py | 108 +++- 5 files changed, 565 insertions(+), 478 deletions(-) diff --git a/engine/factory.py b/engine/factory.py index 88f991c..6eca3c2 100644 --- a/engine/factory.py +++ b/engine/factory.py @@ -61,7 +61,10 @@ def __load_sysdict(self, _config): sysdict_type = _config.get_value('sysdict_type', 'file') try: if sysdict_type == 'file': - return skk.SysDict(_config.sysdict_path) + instances = list() + for path in _config.sysdict_paths: + instances.append(skk.SysDict(path)) + return skk.MultiSysDict(instances) else: host = _config.get_value('skkserv_host', 'localhost') port = int(_config.get_value('skkserv_port', '1178')) diff --git a/engine/skk.py b/engine/skk.py index 16cef8f..e4a0bcd 100644 --- a/engine/skk.py +++ b/engine/skk.py @@ -577,6 +577,25 @@ def completer(self, midasi): except IOError: return iter(list()) +class MultiSysDict(DictBase): + def __init__(self, instances): + self.__instances = instances + + def reload(self): + for sysdict in self.__instances: + sysdict.reload() + + def lookup(self, midasi, okuri=False): + for sysdict in self.__instances: + candidate = sysdict.lookup(midasi, okuri) + if candidate: + return candidate + + def completer(self, midasi): + return reduce(lambda x, y: x + y, + [sysdict.completer(midasi) + for sysdict in self.__instances]) + class UsrDict(DictBase): PATH = '~/.skk-ibus-jisyo' HISTSIZE = 128 diff --git a/setup/config.py b/setup/config.py index b314310..79cd9cd 100644 --- a/setup/config.py +++ b/setup/config.py @@ -19,6 +19,10 @@ def __sysdict_path(self): sysdict_path = property(lambda self: self.get_value(\ 'sysdict', self.__sysdict_path())) + def sysdict_paths(self): + return self.get_value('sysdict_paths', + [self.sysdict_path] if self.sysdict_path else None) + def __usrdict_path(self): usrdict_path = os.path.expanduser(self.__usrdict_path_unexpanded) open(usrdict_path, 'a+').close() diff --git a/setup/ibus-skk-preferences.ui b/setup/ibus-skk-preferences.ui index f4a1833..3d254e7 100644 --- a/setup/ibus-skk-preferences.ui +++ b/setup/ibus-skk-preferences.ui @@ -2,6 +2,74 @@ + + + + + + + + + + 。、 + 0 + + + ., + 1 + + + 。, + 2 + + + .、 + 3 + + + + + + + + + + + + + Normal + 0 + + + KZIK + 1 + + + + + + + + + + + + + Hiragana + 1 + + + Latin + 3 + + + + + + + + + 5 Setup - IBus-SKK @@ -27,485 +95,471 @@ True vertical + 6 - + True - 0 - none True - 12 - + True - 4 - 2 - 6 - 6 - - - True - 1 - 0.5 - - - True - False - - - - - 1 - 2 - - - - - True - 1 - 0.5 - - - True - - - File - True - True - False - True - True - - - False - 0 - - - - - SKK Server - True - True - False - True - sysdict_file - - - False - 1 - - - - - - - 1 - 2 - 1 - 2 - - - - - True - 1 - 0.5 - - - True - False - - - - - 1 - 2 - 2 - 3 - - - - - True - 1 - 0 - - - True - - - True - False - True - - 16 - - - False - False - 0 - - - - - True - Port: - - - 1 - - - - - True - True - - - - 2 - - - - - - - 1 - 2 - 3 - 4 - - - - - True - 0 - _User Dictionary File: - True - - - - - True - 0 - System Dictionary _Type: - True - - - 1 - 2 - - - - - True - 0 - System Dictionary _File: - True - - - 2 - 3 - - - - - True - 0 - SKK _Server: - True - - - 3 - 4 - - + User dictionary: + + False + False + 0 + - - + + True - <b>Dictionaries</b> - True + 1 + 0.5 + + + True + + + + end + 1 + + False + False 0 - + True - 0 - none + vertical + 6 - + True - 12 + 2 + 6 + 6 - + + Use SKK server + True + True + False + 0.47999998927116394 + True + + + + True - 8 - 2 - 6 - 6 - - - True - Start conversion by some characters - 0 - _Auto-start Conversion Characters: - True - - - 1 - 2 - - - - - True - 1 - 0.5 - - - True - True - - - - - - 1 - 2 - 1 - 2 - - - - - True - 0 - _Period Style: - True - - - - - True - 1 - 0.5 - - - True - period_style_liststore - - - - - 1 - 2 - - - - - True - 0 - Candidate _Window Page Size: - True - - - 3 - 4 - - - - - True - 1 - 0.5 - - - True - True - - 4 - - - - - 1 - 2 - 3 - 4 - - - + True - 0 - Candidate Window Pa_gination Start: - True + False + True + + 24 - 4 - 5 + False + False + 0 - + True - 1 - 0.5 - - - True - True - - - + Port: - 1 - 2 - 4 - 5 + 1 - - Show Annotation + True True - False - True - - - 2 - 5 - 6 - - - - - True - - - True - 0 - Rom/Kana Conversion _Table: - True - 2 - - + - 6 - 7 + 2 + + + 1 + 2 + + + + + False + False + 0 + + + + + True + + + True + True + sysdict_liststore + False + False + + + + + 1 + + + + + True + 1 + 0.5 + + + True + 6 + True - + + Add.. True - 1 - 0.5 - - - True - rom_kana_rule_liststore - - + True + True - 1 - 2 - 6 - 7 + 0 - + + Remove True - - - True - 0 - Initial Input Mode: - - + True + True - 7 - 8 + 1 - + + Up True - 1 - 0.5 - - - True - initial_input_mode_liststore - - + True + True - 1 - 2 - 7 - 8 + 2 - + + Down True - - - Return-key doesn't insert new line on commit - True - True - False - True - - + True + True - 2 - 2 - 3 + 3 + + False + 2 + - - + + + 1 + + + + + + + + + True + Dictionary + + + False + + + + + True + 12 + 12 + 12 + 12 + + + True + 8 + 2 + 6 + 6 + + + True + 1 + 0.5 + + True - <b>Behavior</b> - True + True + - 1 + 1 + 2 + 1 + 2 + + + + + True + 0 + _Period Style: + True + + + + + True + 1 + 0.5 + + + True + period_style_liststore + + + + + 1 + 2 + + + + + True + 0 + Candidate _Window Page Size: + True + + + 3 + 4 + + + + + True + 1 + 0.5 + + + True + True + + 4 + + + + + 1 + 2 + 3 + 4 + + + + + True + 0 + Candidate Window Pa_gination Start: + True + + + 4 + 5 + + + + + True + 1 + 0.5 + + + True + True + + + + + + 1 + 2 + 4 + 5 + + + + + Show Annotation + True + True + False + True + + + 2 + 5 + 6 + + + + + True + + + True + 0 + Rom/Kana Conversion _Table: + True + 2 + + + + + 6 + 7 + + + + + True + 1 + 0.5 + + + True + rom_kana_rule_liststore + + + + + 1 + 2 + 6 + 7 + + + + + True + + + True + 0 + Initial Input Mode: + + + + + 7 + 8 + + + + + True + 1 + 0.5 + + + True + initial_input_mode_liststore + + + + + 1 + 2 + 7 + 8 + + + + + True + + + Return-key doesn't insert new line on commit + True + True + False + True + + + + + 2 + 2 + 3 + + + + + True + 0 + _Auto-start Conversion Characters: + True + + + 1 + 2 + + 1 + - + True - SKK + Behavior + 1 False @@ -579,7 +633,7 @@ - 1 + 2 @@ -588,13 +642,10 @@ About - 1 + 2 False - - - 1 @@ -631,66 +682,4 @@ buttonClose - - - - - - - - - - 。、 - 0 - - - ., - 1 - - - 。, - 2 - - - .、 - 3 - - - - - - - - - - - - - Normal - 0 - - - KZIK - 1 - - - - - - - - - - - - - Hiragana - 1 - - - Latin - 3 - - - diff --git a/setup/main.py b/setup/main.py index 701b27d..80a5723 100644 --- a/setup/main.py +++ b/setup/main.py @@ -33,9 +33,13 @@ def __init__(self): self.__dialog = self.__builder.get_object('dialog') self.__usrdict = self.__builder.get_object('usrdict') - self.__sysdict_file = self.__builder.get_object('sysdict_file') self.__sysdict = self.__builder.get_object('sysdict') - self.__sysdict_skkserv = self.__builder.get_object('sysdict_skkserv') + self.__sysdict_liststore = self.__builder.get_object('sysdict_liststore') + self.__add_sysdict = self.__builder.get_object('add_sysdict') + self.__remove_sysdict = self.__builder.get_object('remove_sysdict') + self.__up_sysdict = self.__builder.get_object('up_sysdict') + self.__down_sysdict = self.__builder.get_object('down_sysdict') + self.__use_skkserv = self.__builder.get_object('use_skkserv') self.__skkserv_host = self.__builder.get_object('skkserv_host') self.__skkserv_port = self.__builder.get_object('skkserv_port') self.__period_style = self.__builder.get_object('period_style') @@ -51,16 +55,17 @@ def __init__(self): self.__usrdict.set_filename(self.__config.usrdict_path) sysdict_type = self.__config.get_value('sysdict_type', 'file') - if sysdict_type == 'file': - self.__sysdict_file.set_active(True) - self.__sysdict_skkserv.set_active(False) - else: - self.__sysdict_file.set_active(False) - self.__sysdict_skkserv.set_active(True) + if sysdict_type == 'skkserv': + self.__use_skkserv.set_active(True) self.__set_sysdict_widgets_sensitivity(sysdict_type) - sysdict_path = self.__config.sysdict_path - if sysdict_path: - self.__sysdict.set_filename(sysdict_path) + + # sysdict treeview + renderer = gtk.CellRendererText() + column = gtk.TreeViewColumn("path", renderer, text=0) + self.__sysdict.append_column(column) + for path in self.__config.sysdict_paths(): + self.__sysdict_liststore.append((path,)) + self.__skkserv_host.set_text(\ self.__config.get_value('skkserv_host', skk.SkkServ.HOST)) self.__skkserv_port.set_numeric(True) @@ -114,9 +119,13 @@ def __init__(self): self.__config.get_value('egg_like_newline', True)) self.__usrdict.connect('file-set', self.__usrdict_file_set_cb) - self.__sysdict_file.connect('toggled', self.__sysdict_toggle_cb) - self.__sysdict_skkserv.connect('toggled', self.__sysdict_toggle_cb) - self.__sysdict.connect('file-set', self.__sysdict_file_set_cb) + self.__use_skkserv.connect('toggled', self.__use_skkserv_toggle_cb) + self.__add_sysdict.connect('clicked', self.__add_sysdict_clicked_cb) + self.__remove_sysdict.connect('clicked', self.__remove_sysdict_clicked_cb) + self.__up_sysdict.connect('clicked', self.__up_sysdict_clicked_cb) + self.__down_sysdict.connect('clicked', self.__down_sysdict_clicked_cb) + self.__sysdict.get_selection().connect_after('changed', + self.__sysdict_selection_changed_cb) self.__skkserv_host.connect('changed', self.__skkserv_host_changed_cb) self.__skkserv_port.connect('changed', self.__skkserv_port_changed_cb) self.__period_style.connect('changed', self.__period_style_changed_cb) @@ -129,23 +138,86 @@ def __init__(self): self.__initial_input_mode.connect('changed', self.__initial_input_mode_changed_cb) self.__egg_like_newline.connect('toggled', self.__egg_like_newline_changed_cb) - def __sysdict_toggle_cb(self, widget): - sysdict_type = 'file' if self.__sysdict_file.get_active() else 'skkserv' + def __use_skkserv_toggle_cb(self, widget): + sysdict_type = 'skkserv' if self.__use_skkserv.get_active() else 'file' self.__config.set_value('sysdict_type', sysdict_type) self.__set_sysdict_widgets_sensitivity(sysdict_type) def __set_sysdict_widgets_sensitivity(self, sysdict_type): if sysdict_type == 'file': self.__sysdict.set_sensitive(True) + self.__add_sysdict.set_sensitive(True) self.__skkserv_host.set_sensitive(False) self.__skkserv_port.set_sensitive(False) + self.__sysdict_entry_buttons_set_sensitivity(\ + self.__sysdict.get_selection().get_selected()[1] is not None) else: self.__sysdict.set_sensitive(False) + self.__add_sysdict.set_sensitive(False) self.__skkserv_host.set_sensitive(True) self.__skkserv_port.set_sensitive(True) + self.__sysdict_entry_buttons_set_sensitivity(False) + + def __add_sysdict_clicked_cb(self, widget): + chooser = gtk.FileChooserDialog(\ + title="Open Dictionary File", + parent=self.__dialog, + action=gtk.FILE_CHOOSER_ACTION_OPEN, + buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, + gtk.STOCK_OPEN, gtk.RESPONSE_OK)) + if chooser.run() == gtk.RESPONSE_OK: + model = self.__sysdict.get_model() + path = chooser.get_filename() + _iter = model.get_iter_root() + while _iter: + _value, = model.get(_iter, 0) + if _value == path: + break + _iter = model.iter_next(_iter) + if not _iter: + model.append((path,)) + self.__set_sysdict_from_model(model) + chooser.hide() + + def __remove_sysdict_clicked_cb(self, widget): + model, paths = self.__sysdict.get_selection().get_selected_rows() + for path in paths: + model.remove(model.get_iter(path)) + self.__set_sysdict_from_model(model) - def __sysdict_file_set_cb(self, widget): - self.__config.set_value('sysdict', widget.get_filename()) + def __up_sysdict_clicked_cb(self, widget): + model, _iter = self.__sysdict.get_selection().get_selected() + if _iter: + path = model.get_path(_iter) + if path[0] > 0: + model.move_before(_iter, model.get_iter((path[0] - 1,))) + self.__set_sysdict_from_model(model) + + def __down_sysdict_clicked_cb(self, widget): + model, _iter = self.__sysdict.get_selection().get_selected() + if _iter: + path = model.get_path(_iter) + if path[0] < len(model) - 1: + model.move_after(_iter, model.get_iter((path[0] + 1,))) + self.__set_sysdict_from_model(model) + + def __set_sysdict_from_model(self, model): + paths = list() + _iter = model.get_iter_root() + while _iter: + value, = model.get(_iter, 0) + paths.append(value) + _iter = model.iter_next(_iter) + self.__config.set_value('sysdict_paths', paths) + + def __sysdict_entry_buttons_set_sensitivity(self, sensitive): + self.__remove_sysdict.set_sensitive(sensitive) + self.__up_sysdict.set_sensitive(sensitive) + self.__down_sysdict.set_sensitive(sensitive) + + def __sysdict_selection_changed_cb(self, selection): + self.__sysdict_entry_buttons_set_sensitivity(\ + selection.get_selected()[1] is not None) def __usrdict_file_set_cb(self, widget): self.__config.set_value('usrdict', widget.get_filename())