Refactor emoticon theme combobox

- Use ComboBoxText, its much simpler
- Add a dedicated method that returns all available themes
- If the configured Theme is not available fallback to font-emoticons
This commit is contained in:
Philipp Hörist 2018-02-21 23:52:23 +01:00
parent 1fbc6a2304
commit eb3a53c791
3 changed files with 45 additions and 35 deletions

View File

@ -1592,3 +1592,19 @@ def version_condition(current_version, required_version):
if V(current_version) < V(required_version): if V(current_version) < V(required_version):
return False return False
return True return True
def get_available_emoticon_themes():
emoticons_themes = []
emoticons_data_path = os.path.join(app.DATA_DIR, 'emoticons')
folders = os.listdir(emoticons_data_path)
if os.path.isdir(app.MY_EMOTS_PATH):
folders += os.listdir(app.MY_EMOTS_PATH)
for theme in folders:
theme_path = os.path.join(
emoticons_data_path, theme, 'emoticons_theme.py')
if os.path.exists(theme_path):
emoticons_themes.append(theme)
emoticons_themes.sort()
return emoticons_themes

View File

@ -143,29 +143,20 @@ class PreferencesWindow:
# emoticons # emoticons
emoticons_combobox = self.xml.get_object('emoticons_combobox') emoticons_combobox = self.xml.get_object('emoticons_combobox')
emoticons_list = os.listdir(os.path.join(app.DATA_DIR, 'emoticons')) emoticon_themes = helpers.get_available_emoticon_themes()
# user themes
if os.path.isdir(app.MY_EMOTS_PATH): emoticons_combobox.append_text(_('Disabled'))
emoticons_list += os.listdir(app.MY_EMOTS_PATH) for theme in emoticon_themes:
emoticons_list.sort() emoticons_combobox.append_text(theme)
renderer_text = Gtk.CellRendererText()
emoticons_combobox.pack_start(renderer_text, True) config_theme = app.config.get('emoticons_theme')
emoticons_combobox.add_attribute(renderer_text, 'text', 0) if config_theme not in emoticon_themes:
model = Gtk.ListStore(str) # Fallback theme
emoticons_combobox.set_model(model) config_theme = 'font-emoticons'
l = [_('Disabled')] app.config.set('emoticons_theme', 'font-emoticons')
for dir_ in emoticons_list: emoticons_combobox.set_id_column(0)
if not os.path.isdir(os.path.join(app.DATA_DIR, 'emoticons', dir_)) \ emoticons_combobox.set_active_id(config_theme)
and not os.path.isdir(os.path.join(app.MY_EMOTS_PATH, dir_)) :
continue
if dir_ != '.svn':
l.append(dir_)
for i in range(len(l)):
model.append([l[i]])
if app.config.get('emoticons_theme') == l[i]:
emoticons_combobox.set_active(i)
if not app.config.get('emoticons_theme'):
emoticons_combobox.set_active(0)
# Set default for single window type # Set default for single window type
choices = c_config.opt_one_window_types choices = c_config.opt_one_window_types

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.20.0 --> <!-- Generated with glade 3.20.2 -->
<interface> <interface>
<requires lib="gtk+" version="3.12"/> <requires lib="gtk+" version="3.12"/>
<object class="GtkAdjustment" id="adjustment1"> <object class="GtkAdjustment" id="adjustment1">
@ -515,17 +515,6 @@
<property name="top_attach">1</property> <property name="top_attach">1</property>
</packing> </packing>
</child> </child>
<child>
<object class="GtkComboBox" id="emoticons_combobox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<signal name="changed" handler="on_emoticons_combobox_changed" swapped="no"/>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
<child> <child>
<object class="GtkCheckButton" id="show_avatar_in_tabs_checkbutton"> <object class="GtkCheckButton" id="show_avatar_in_tabs_checkbutton">
<property name="label" translatable="yes">Show avatar in chat tabs</property> <property name="label" translatable="yes">Show avatar in chat tabs</property>
@ -542,6 +531,17 @@
<property name="width">2</property> <property name="width">2</property>
</packing> </packing>
</child> </child>
<child>
<object class="GtkComboBoxText" id="emoticons_combobox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<signal name="changed" handler="on_emoticons_combobox_changed" swapped="no"/>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
</object> </object>
</child> </child>
<child type="label"> <child type="label">
@ -2888,5 +2888,8 @@ to discover one from server.</property>
</child> </child>
</object> </object>
</child> </child>
<child type="titlebar">
<placeholder/>
</child>
</object> </object>
</interface> </interface>