changeset bc488e4cdc02 in /home/hg/repos/gajim-plugins
author: Denis Fomin fominde@gmail.com branches: details:gajim-plugins?cmd=changeset;node=bc488e4cdc02 description: Theme Switcher Plugin. Fixes #72
diffstat:
theme_switcher/__init__.py | 1 + theme_switcher/config_dialog.ui | 85 ++++++++++++++++++++++++++++++++++++++ theme_switcher/manifest.ini | 8 +++ theme_switcher/theme_switcher.png | Bin theme_switcher/theme_switcher.py | 81 ++++++++++++++++++++++++++++++++++++ 5 файлов изменено, 175 вставок(+), 0 удалений(-)
различия (193 строк):
diff -r 60595dfa0f19 -r bc488e4cdc02 theme_switcher/__init__.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/theme_switcher/__init__.py Mon Sep 16 14:23:34 2013 +0400 @@ -0,0 +1,1 @@ +from theme_switcher import ThemeSwitcherPlugin diff -r 60595dfa0f19 -r bc488e4cdc02 theme_switcher/config_dialog.ui --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/theme_switcher/config_dialog.ui Mon Sep 16 14:23:34 2013 +0400 @@ -0,0 +1,85 @@ +<?xml version="1.0"?> +<interface> + <requires lib="gtk+" version="2.16"/> + <!-- interface-naming-policy toplevel-contextual --> + <object class="GtkWindow" id="window1"> + <child> + <object class="GtkVBox" id="vbox2"> + <property name="visible">True</property> + <property name="border_width">9</property> + <property name="orientation">vertical</property> + <child> + <object class="GtkHBox" id="hbox2"> + <property name="visible">True</property> + <child> + <object class="GtkLabel" id="theme"> + <property name="visible">True</property> + <property name="xalign">0</property> + <property name="label" translatable="yes">Theme:</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="padding">7</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkComboBox" id="theme_combobox"> + <property name="visible">True</property> + <signal name="changed" handler="on_theme_combobox_changed"/> + </object> + <packing> + <property name="position">1</property> + </packing> + </child> + <child> + <object class="GtkButton" id="reset_button"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="xalign">0</property> + <signal name="clicked" handler="on_reset_theme_button_clicked"/> + <child> + <object class="GtkHBox" id="hbox3"> + <property name="visible">True</property> + <child> + <object class="GtkImage" id="image1"> + <property name="visible">True</property> + <property name="stock">gtk-revert-to-saved</property> + </object> + <packing> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="label17"> + <property name="visible">True</property> + <property name="xalign">0</property> + <property name="label" translatable="yes">Reset to default</property> + </object> + <packing> + <property name="position">1</property> + </packing> + </child> + </object> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="padding">7</property> + <property name="position">2</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">0</property> + </packing> + </child> + </object> + </child> + </object> +</interface> diff -r 60595dfa0f19 -r bc488e4cdc02 theme_switcher/manifest.ini --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/theme_switcher/manifest.ini Mon Sep 16 14:23:34 2013 +0400 @@ -0,0 +1,8 @@ +[info] +name: Theme Switcher +short_name: theme_switcher +version: 0.0.1 +description: Change the active GTK+ theme. +authors: Denis Fomin fominde@gmail.com +homepage: http://trac-plugins.gajim.org/wiki/ThemeSwitcherPlugin +max_gajim_version: 0.16.9 diff -r 60595dfa0f19 -r bc488e4cdc02 theme_switcher/theme_switcher.png Binary file theme_switcher/theme_switcher.png has changed diff -r 60595dfa0f19 -r bc488e4cdc02 theme_switcher/theme_switcher.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/theme_switcher/theme_switcher.py Mon Sep 16 14:23:34 2013 +0400 @@ -0,0 +1,81 @@ +# -*- coding: utf-8 -*- +## + +import gtk + +from plugins.gui import GajimPluginConfigDialog +from plugins import GajimPlugin +from plugins.helpers import log_calls +from common import gajim + + +class ThemeSwitcherPlugin(GajimPlugin): + @log_calls('ThemeSwitcherPlugin') + def init(self): + self.config_dialog = ThemeSwitcherPluginConfigDialog(self) + settings = gtk.settings_get_default() + default_theme = settings.get_property('gtk-theme-name') + self.config['DEFAULT_THEME'] = default_theme + self.theme = default_theme + self.config_default_values = {'THEME': (default_theme, '')} + + @log_calls('ThemeSwitcherPlugin') + def activate(self): + settings = gtk.settings_get_default() + settings.set_property('gtk-theme-name', self.config['THEME']) + + @log_calls('ThemeSwitcherPlugin') + def deactivate(self): + settings = gtk.settings_get_default() + settings.set_property('gtk-theme-name', self.config['DEFAULT_THEME']) + + +class ThemeSwitcherPluginConfigDialog(GajimPluginConfigDialog): + def init(self): + self.GTK_BUILDER_FILE_PATH = self.plugin.local_file_path( + 'config_dialog.ui') + self.xml = gtk.Builder() + self.xml.set_translation_domain('gajim_plugins') + self.xml.add_objects_from_file(self.GTK_BUILDER_FILE_PATH, + ['vbox2']) + hbox = self.xml.get_object('vbox2') + self.child.pack_start(hbox) + self.xml.connect_signals(self) + + self.preset_combo = self.xml.get_object('theme_combobox') + self.preset_liststore = gtk.ListStore(str) + self.preset_combo.set_model(self.preset_liststore) + cellrenderer = gtk.CellRendererText() + self.preset_combo.pack_start(cellrenderer, True) + self.preset_combo.add_attribute(cellrenderer, 'text', 0) + + @log_calls('ThemeSwitcherPluginConfigDialog') + def on_run(self): + from os import listdir + from os.path import join + theme_d = gtk.rc_get_theme_dir() + theme_names = [] + for theme in listdir(theme_d): + try: + if "gtk-2.0" in listdir(join(theme_d, theme)): + theme_names.append(theme) + except: + pass + + theme_names = sorted(theme_names) + for name in theme_names: + self.preset_liststore.append((name,)) + + def on_reset_theme_button_clicked(self, widget): + settings = gtk.settings_get_default() + settings.set_property('gtk-theme-name', + self.plugin.config['DEFAULT_THEME']) + self.plugin.config['THEME'] = self.plugin.config['DEFAULT_THEME'] + + def on_theme_combobox_changed(self, widget): + model = widget.get_model() + active = widget.get_active() + self.theme = model[active][0].decode('utf-8') + settings = gtk.settings_get_default() + settings.set_property('gtk-theme-name', self.theme) + self.plugin.config['THEME'] = self.theme