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):
return False
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_combobox = self.xml.get_object('emoticons_combobox')
emoticons_list = os.listdir(os.path.join(app.DATA_DIR, 'emoticons'))
# user themes
if os.path.isdir(app.MY_EMOTS_PATH):
emoticons_list += os.listdir(app.MY_EMOTS_PATH)
emoticons_list.sort()
renderer_text = Gtk.CellRendererText()
emoticons_combobox.pack_start(renderer_text, True)
emoticons_combobox.add_attribute(renderer_text, 'text', 0)
model = Gtk.ListStore(str)
emoticons_combobox.set_model(model)
l = [_('Disabled')]
for dir_ in emoticons_list:
if not os.path.isdir(os.path.join(app.DATA_DIR, 'emoticons', dir_)) \
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)
emoticon_themes = helpers.get_available_emoticon_themes()
emoticons_combobox.append_text(_('Disabled'))
for theme in emoticon_themes:
emoticons_combobox.append_text(theme)
config_theme = app.config.get('emoticons_theme')
if config_theme not in emoticon_themes:
# Fallback theme
config_theme = 'font-emoticons'
app.config.set('emoticons_theme', 'font-emoticons')
emoticons_combobox.set_id_column(0)
emoticons_combobox.set_active_id(config_theme)
# Set default for single window type
choices = c_config.opt_one_window_types

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.20.0 -->
<!-- Generated with glade 3.20.2 -->
<interface>
<requires lib="gtk+" version="3.12"/>
<object class="GtkAdjustment" id="adjustment1">
@ -515,17 +515,6 @@
<property name="top_attach">1</property>
</packing>
</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>
<object class="GtkCheckButton" id="show_avatar_in_tabs_checkbutton">
<property name="label" translatable="yes">Show avatar in chat tabs</property>
@ -542,6 +531,17 @@
<property name="width">2</property>
</packing>
</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>
</child>
<child type="label">
@ -2888,5 +2888,8 @@ to discover one from server.</property>
</child>
</object>
</child>
<child type="titlebar">
<placeholder/>
</child>
</object>
</interface>