[gedit-plugins/translate] Use callback for languages names
- From: Jordi Mas <jmas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit-plugins/translate] Use callback for languages names
- Date: Mon, 24 Jul 2017 17:54:07 +0000 (UTC)
commit cb054e9a23a1134ccc304fb14cd8adec70b10651
Author: Jordi Mas <jmas softcatala org>
Date: Mon Jul 24 19:53:52 2017 +0200
Use callback for languages names
...rg.gnome.gedit.plugins.translate.gschema.xml.in | 2 +-
plugins/translate/translate/__init__.py | 11 ++++-
plugins/translate/translate/preferences.py | 44 +++++++++++---------
3 files changed, 34 insertions(+), 23 deletions(-)
---
diff --git a/plugins/translate/org.gnome.gedit.plugins.translate.gschema.xml.in
b/plugins/translate/org.gnome.gedit.plugins.translate.gschema.xml.in
index 29b7068..f53dea4 100644
--- a/plugins/translate/org.gnome.gedit.plugins.translate.gschema.xml.in
+++ b/plugins/translate/org.gnome.gedit.plugins.translate.gschema.xml.in
@@ -21,7 +21,7 @@
API key for remote web service
</description>
</key>
- <key type="i" name="service">
+ <key type="u" name="service">
<default>0</default>
<summary>Remote web service to use</summary>
<description>
diff --git a/plugins/translate/translate/__init__.py b/plugins/translate/translate/__init__.py
index 8fbb4ae..dfeac47 100644
--- a/plugins/translate/translate/__init__.py
+++ b/plugins/translate/translate/__init__.py
@@ -83,12 +83,19 @@ class TranslateWindowActivatable(GObject.Object, Gedit.WindowActivatable, PeasGt
self.window.lookup_action('translate').set_enabled(sensitive)
+
+ def get_languages_names_codes(self, service_id):
+ print("get_languages_names_codes. service_id: " + str(service_id))
+ settings = Settings()
+ service_id = settings.get_service()
+ service = Services.get(service_id)
+ return service.get_language_names(), service.get_language_codes()
+
def do_create_configure_widget(self):
print("called do_create_configure_widget")
apertium = Apertium()
config_widget = Preferences(self.plugin_info.get_data_dir(),
- apertium.get_language_names(),
- apertium.get_language_codes())
+ self.get_languages_names_codes)
widget = config_widget.configure_widget()
print("called do_create_configure_widget return:" + str(type(widget)))
return widget
diff --git a/plugins/translate/translate/preferences.py b/plugins/translate/translate/preferences.py
index 6287e25..891735c 100644
--- a/plugins/translate/translate/preferences.py
+++ b/plugins/translate/translate/preferences.py
@@ -30,12 +30,13 @@ class Preferences(object):
LANG_NAME = 0
LANG_CODE = 1
- def __init__(self, datadir, language_names, language_codes):
+ def __init__(self, datadir, get_languages_names_codes):
object.__init__(self)
- self._language_codes = language_codes
- self._language_names = language_names
+ self._get_languages_names_codes = get_languages_names_codes
self._settings = Settings()
+ self._service_id = self._settings.get_service()
+
self._ui_path = os.path.join(datadir, 'ui', 'preferences.ui')
self._ui = Gtk.Builder()
self._ui.set_translation_domain(GETTEXT_PACKAGE)
@@ -46,10 +47,16 @@ class Preferences(object):
self._init_combobox_services()
self._init_api_entry()
- def _init_api_entry(self):
+ def _populate_languages(self):
+ self._language_names, self._language_codes = self._get_languages_names_codes(self._service_id)
+ self._model = self._get_languages_stored_model()
+ self._languages.set_model(self._model)
+ selected = self._settings.get_language_pair()
+ index = self._get_index(selected)
+ self._languages.set_active(index)
- service_id = self._settings.get_service()
- service = Services.get(service_id)
+ def _init_api_entry(self):
+ service = Services.get(self._service_id)
if service.has_api_key() is True:
self._update_api_key_ui(True)
return
@@ -60,7 +67,6 @@ class Preferences(object):
def _update_api_key_ui(self, show):
apibox = self._ui.get_object('api_box')
- print("_update_api_key_ui show:" + str(show))
if show is True:
self._apilabel = Gtk.Label("API Key")
self._apikey= Gtk.Entry(expand=True)
@@ -112,15 +118,9 @@ class Preferences(object):
cell = Gtk.CellRendererText()
self._languages.pack_start(cell, 1)
self._languages.add_attribute(cell, 'text', 0)
-
- self._model = self._get_languages_stored_model()
- self._languages.set_model(self._model)
+ self._populate_languages()
self._languages.connect('changed', self._changed_lang_pair)
- selected = self._settings.get_language_pair()
- index = self._get_index(selected)
- self._languages.set_active(index)
-
def _get_languages_stored_model(self):
sorted_language_names = set()
@@ -152,12 +152,16 @@ class Preferences(object):
def _changed_services(self, combobox):
model = combobox.get_model()
index = combobox.get_active()
- if index > -1:
- item = model[index]
- service_id = item[1]
- self._settings.set_service(service_id)
- service = Services.get(service_id)
- self._update_api_key_ui(service.has_api_key())
+ if index == -1:
+ return
+
+ item = model[index]
+ self._service_id = item[1]
+ self._settings.set_service(self._service_id)
+ service = Services.get(self._service_id)
+ self._update_api_key_ui(service.has_api_key())
+ self._populate_languages()
+
def _changed_apikey(self, text_entry):
text = text_entry.get_text()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]