From 491595bfbddd68c373a296713d256ee5a96a8717 Mon Sep 17 00:00:00 2001 From: hordepfo Date: Wed, 22 Jan 2014 17:51:49 +0000 Subject: [PATCH] Several theming and color fixes Restructured a bit how theming and coloring works. Now theme and color changes work on the fly. No need to restart mintMenu anymore. Note that changing theme no longer regenerates plugins, so it's faster. Fixes issue #47 --- usr/lib/linuxmint/mintMenu/mintMenu.py | 98 ++++++++++--------- .../mintMenu/plugins/applications.py | 2 +- 2 files changed, 51 insertions(+), 49 deletions(-) diff --git a/usr/lib/linuxmint/mintMenu/mintMenu.py b/usr/lib/linuxmint/mintMenu/mintMenu.py index 0a2d1a7..3112c1e 100755 --- a/usr/lib/linuxmint/mintMenu/mintMenu.py +++ b/usr/lib/linuxmint/mintMenu/mintMenu.py @@ -96,25 +96,13 @@ class MainWindow( object ): plugindir = os.path.join( os.path.expanduser( "~" ), ".linuxmint/mintMenu/plugins" ) sys.path.append( plugindir ) - - self.getSetGSettingEntries() - self.SetupMintMenuBorder() - self.tooltips = Gtk.Tooltips() - if self.globalEnableTooltips and self.enableTooltips: - self.tooltips.enable() - else: - self.tooltips.disable() - - self.PopulatePlugins(); + self.panelSettings = Gio.Settings.new("org.mate.panel") + self.panelSettings.connect( "changed::tooltips-enabled", self.toggleTooltipsEnabled ) self.settings.connect( "changed::plugins-list", self.RegenPlugins ) - self.settings.connect( "changed::start-with-favorites", self.toggleStartWithFavorites ) - globalsettings = Gio.Settings.new("org.mate.panel") - globalsettings.connect( "changed::tooltips-enabled", self.toggleTooltipsEnabled ) self.settings.connect( "changed::tooltips-enabled", self.toggleTooltipsEnabled ) - self.settings.connect( "changed::use-custom-color", self.toggleUseCustomColor ) self.settings.connect( "changed::custom-border-color", self.toggleCustomBorderColor ) self.settings.connect( "changed::custom-heading-color", self.toggleCustomHeadingColor ) @@ -122,6 +110,15 @@ class MainWindow( object ): self.settings.connect( "changed::border-width", self.toggleBorderWidth ) self.settings.connect( "changed::opacity", self.toggleOpacity ) + self.getSetGSettingEntries() + + self.tooltips = Gtk.Tooltips() + if self.globalEnableTooltips and self.enableTooltips: + self.tooltips.enable() + else: + self.tooltips.disable() + + self.PopulatePlugins(); self.firstTime = True; def on_window1_destroy (self, widget, data=None): @@ -158,9 +155,7 @@ class MainWindow( object ): def toggleUseCustomColor( self, settings, key, args = None ): self.usecustomcolor = settings.get_boolean(key) - self.SetupMintMenuBorder() - self.SetPaneColors( self.panesToColor ) - self.SetHeadingStyle( self.headingsToColor ) + self.loadTheme() def toggleCustomBorderColor( self, settings, key, args = None ): self.custombordercolor = settings.get_string(key) @@ -188,14 +183,13 @@ class MainWindow( object ): self.enableTooltips = self.settings.get_boolean( "tooltips-enabled" ) self.startWithFavorites = self.settings.get_boolean( "start-with-favorites" ) - mate_settings = Gio.Settings.new("org.mate.panel") - self.globalEnableTooltips = mate_settings.get_boolean( "tooltips-enabled" ) + self.globalEnableTooltips = self.panelSettings.get_boolean( "tooltips-enabled" ) - def SetupMintMenuBorder( self ): + def SetupMintMenuBorder( self, defaultStyle = None ): if self.usecustomcolor: self.window.modify_bg( Gtk.StateType.NORMAL, Gdk.color_parse( self.custombordercolor ) ) - # else: - # self.window.modify_bg( Gtk.StateType.NORMAL, self.window.rc_get_style().bg[ Gtk.StateType.SELECTED ] ) + elif defaultStyle is not None: + self.window.modify_bg( Gtk.StateType.NORMAL, defaultStyle.lookup_color('bg_color')[1] ) self.border.set_padding( self.borderwidth, self.borderwidth, self.borderwidth, self.borderwidth ) def SetupMintMenuOpacity( self ): @@ -226,10 +220,9 @@ class MainWindow( object ): PluginPane.show() PaneLadder = Gtk.VBox( False, 0 ) PluginPane.add( PaneLadder ) - self.SetPaneColors( [ PluginPane ] ) ImageBox = Gtk.EventBox() - self.SetPaneColors( [ ImageBox ] ) ImageBox.show() + self.panesToColor.extend( [ PluginPane, ImageBox ] ) seperatorImage = GdkPixbuf.Pixbuf.new_from_file( self.dottedfile ) @@ -283,9 +276,7 @@ class MainWindow( object ): print u"Unable to load " + plugin + " plugin :-(" - self.SetPaneColors( [MyPlugin.content_holder] ) - - + self.panesToColor.append( MyPlugin.content_holder ) MyPlugin.content_holder.show() VBox1 = Gtk.VBox( False, 0 ) @@ -294,14 +285,14 @@ class MainWindow( object ): Align1 = Gtk.Alignment.new( 0, 0, 0, 0 ) Align1.set_padding( 10, 5, 10, 0 ) Align1.add( Label1 ) - self.SetHeadingStyle( [Label1] ) + self.headingsToColor.append( Label1 ) Align1.show() Label1.show() if not hasattr( MyPlugin, 'sticky' ) or MyPlugin.sticky == True: heading = Gtk.EventBox() Align1.set_padding( 0, 0, 10, 0 ) - self.SetPaneColors( [heading] ) + heading.set_visible_window( False ) heading.set_size_request( MyPlugin.width, 30 ) else: heading = Gtk.HBox() @@ -330,7 +321,9 @@ class MainWindow( object ): if hasattr( MyPlugin, 'height' ): MyPlugin.content_holder.set_size_request( -1, MyPlugin.height ) if hasattr( MyPlugin, 'itemstocolor' ): - self.SetPaneColors( MyPlugin.itemstocolor ) + self.panesToColor.extend( MyPlugin.itemstocolor ) + if hasattr( MyPlugin, 'headingstocolor' ): + self.headingsToColor.extend( MyPlugin.headingstocolor ) except: # create traceback info = sys.exc_info() @@ -348,9 +341,8 @@ class MainWindow( object ): PluginPane = Gtk.EventBox() PaneLadder = Gtk.VBox( False, 0 ) PluginPane.add( PaneLadder ) - self.SetPaneColors( [PluginPane] ) ImageBox = Gtk.EventBox() - self.SetPaneColors( [ImageBox] ) + self.panesToColor.extend( [ PluginPane, ImageBox ] ) ImageBox.show() PluginPane.show_all() @@ -372,22 +364,30 @@ class MainWindow( object ): self.tooltips.disable() #print u"Loading", (time.time() - start), "s" - def SetPaneColors( self, items ): - for item in items: - if item not in self.panesToColor: - self.panesToColor.append( item ) + # A little hacky but works + def getDefaultStyle( self ): + widget = Gtk.EventBox() + widget.show() + return Gtk.rc_get_style(widget) + + def loadTheme( self ): + defaultStyle = self.getDefaultStyle() + self.SetPaneColors( self.panesToColor, defaultStyle ) + self.SetupMintMenuBorder( defaultStyle ) + self.SetHeadingStyle( self.headingsToColor ) + + def SetPaneColors( self, items, defaultStyle = None ): if self.usecustomcolor: for item in items: item.modify_bg( Gtk.StateType.NORMAL, Gdk.color_parse( self.customcolor ) ) - # else: - # for item in items: - # item.modify_bg( Gtk.StateType.NORMAL, self.paneholder.rc_get_style().bg[ Gtk.StateType.NORMAL ] ) + # TODO: Changing background color isn't working for pixmaps! The following does not work: + item.get_style().bg_pixmap[Gtk.StateType.NORMAL] = None + elif defaultStyle is not None: + for item in items: + item.modify_bg( Gtk.StateType.NORMAL, defaultStyle.lookup_color('bg_color')[1] ) + item.get_style().bg_pixmap[Gtk.StateType.NORMAL] = defaultStyle.bg_pixmap[Gtk.StateType.NORMAL] def SetHeadingStyle( self, items ): - for item in items: - if item not in self.headingsToColor: - self.headingsToColor.append( item ) - if self.usecustomcolor: color = self.customheadingcolor else: @@ -429,6 +429,7 @@ class MainWindow( object ): self.getSetGSettingEntries() self.PopulatePlugins() + self.loadTheme() #print NAME+u" reloaded" @@ -501,8 +502,8 @@ class MenuWin( object ): self.settings.connect( "changed::hot-key", self.hotkeyChanged ) self.loadSettings() - mate_settings = Gio.Settings.new("org.mate.interface") - mate_settings.connect( "changed::gtk-theme", self.changeTheme ) + self.mate_settings = Gio.Settings.new("org.mate.interface") + self.mate_settings.connect( "changed::gtk-theme", self.changeTheme ) self.createPanelButton() @@ -518,6 +519,8 @@ class MenuWin( object ): self.mainwin.window.connect( "size-allocate", lambda *args: self.positionMenu() ) self.mainwin.window.set_name("mintmenu") # Name used in Gtk RC files + self.applyTheme() + self.mainwin.loadTheme() if self.mainwin.icon: Gtk.Window.set_default_icon_name( self.mainwin.icon ) @@ -620,12 +623,11 @@ class MenuWin( object ): def changeTheme(self, *args): self.reloadSettings() self.applyTheme() - self.mainwin.RegenPlugins() + self.mainwin.loadTheme() def applyTheme(self): style_settings = Gtk.Settings.get_default() - mate_settings = Gio.Settings.new("org.mate.interface") - desktop_theme = mate_settings.get_string('gtk-theme') + desktop_theme = self.mate_settings.get_string('gtk-theme') if self.theme_name == "default": style_settings.set_property("gtk-theme-name", desktop_theme) else: diff --git a/usr/lib/linuxmint/mintMenu/plugins/applications.py b/usr/lib/linuxmint/mintMenu/plugins/applications.py index ee0ddd7..7a86cf5 100755 --- a/usr/lib/linuxmint/mintMenu/plugins/applications.py +++ b/usr/lib/linuxmint/mintMenu/plugins/applications.py @@ -253,7 +253,7 @@ class pluginclass( object ): self.builder.get_object("label7").set_text(_("All applications")) self.builder.get_object("label2").set_text(_("Applications")) - self.mintMenuWin.SetHeadingStyle( [self.builder.get_object("label6"),self.builder.get_object("label2")] ) + self.headingstocolor = [self.builder.get_object("label6"),self.builder.get_object("label2")] self.numApps = 0 # These properties are NECESSARY to maintain consistency