From b851547fe10ab112dbfbc303dd893f9f23d01d97 Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Fri, 10 Aug 2012 13:08:25 +0800 Subject: update setup code --- setup/dicttreeview.py | 6 ++++-- setup/main2.py | 31 ++++++++++--------------------- 2 files changed, 14 insertions(+), 23 deletions(-) (limited to 'setup') diff --git a/setup/dicttreeview.py b/setup/dicttreeview.py index 29b7f2f..b35f8b9 100644 --- a/setup/dicttreeview.py +++ b/setup/dicttreeview.py @@ -100,8 +100,9 @@ class DictionaryTreeView(Gtk.TreeView): # save value model.set(iter, COLUMN_ACTIVE, active) - # mark changed + # notify changed self.__changed = True + self.__emit_changed() def __emit_changed(self, *args): if self.__changed: @@ -114,7 +115,8 @@ class DictionaryTreeView(Gtk.TreeView): if (not row[COLUMN_SENSITIVE]): continue; if (row[COLUMN_ACTIVE]): - dicts.append(row[COLUMN_PHRASE_INDEX]) + dicts.append(str(row[COLUMN_PHRASE_INDEX])) + return ';'.join(dicts) def set_dictionaries(self, dicts): diff --git a/setup/main2.py b/setup/main2.py index 5bb52b5..fb5b0b7 100644 --- a/setup/main2.py +++ b/setup/main2.py @@ -32,6 +32,7 @@ from gi.repository import IBus from xdg import BaseDirectory import version +from dicttreeview import DictionaryTreeView _ = lambda x : gettext.gettext(x) @@ -56,7 +57,7 @@ class PreferencesDialog: self.__init_general() self.__init_pinyin() self.__init_fuzzy() - #self.__init_dictionary() + self.__init_dictionary() self.__init_about() elif engine == "bopomofo": self.__config_namespace = "engine/Bopomofo" @@ -329,28 +330,16 @@ class PreferencesDialog: # page Dictionary self.__page_dictionary.show() - # dictionary - self.__special_phrases = self.__builder.get_object("SpecialPhrases") - self.__edit_special_phrases = self.__builder.get_object("EditSpecialPhrases") + # dictionary tree view + self.__dict_treeview = self.__builder.get_object("Dictionaries") + self.__dict_treeview.show() + self.__dict_treeview.set_dictionaries(self.__get_value("Dictionaries", "2")) - # read values - self.__special_phrases.set_active(self.__get_value("SpecialPhrases", True)) - - def __edit_special_phrases_clicked_cb(widget): - from xdg import BaseDirectory - import shutil - path = os.path.join(BaseDirectory.xdg_config_home, "ibus", "pinyin") - os.path.exists(path) or os.makedirs(path) - path = os.path.join(path, "phrases.txt") - if not os.path.exists(path): - datadir = os.getenv("IBUS_DATAROOTDIR") or "/usr/share" - src = os.path.join(datadir, "ibus-libpinyin", "phrases.txt") - shutil.copyfile(src, path) - os.system("xdg-open %s" % path) + def __notified_dicts_cb(self, param, dialog): + dialog.__set_value("Dictionaries", self.get_dictionaries()) - # connect signals - self.__special_phrases.connect("toggled", self.__toggled_cb, "SpecialPhrases") - self.__edit_special_phrases.connect("clicked", __edit_special_phrases_clicked_cb) + # connect notify signal + self.__dict_treeview.connect("notify::dictionaries", __notified_dicts_cb, self) def __init_about(self): # page About -- cgit