[kupfer] darkstyle: Use GTK+ styles to theme the main window



commit b0b5e5637b31b17f8778b4a8ec63210d8915b71b
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Sat Mar 19 14:27:29 2011 +0100

    darkstyle: Use GTK+ styles to theme the main window

 kupfer/plugin/darkstyle.py |   81 ++++++++++++++++++++++++++++++++++++-------
 1 files changed, 67 insertions(+), 14 deletions(-)
---
diff --git a/kupfer/plugin/darkstyle.py b/kupfer/plugin/darkstyle.py
index 7c4a888..f9d1dbe 100644
--- a/kupfer/plugin/darkstyle.py
+++ b/kupfer/plugin/darkstyle.py
@@ -1,25 +1,78 @@
-__kupfer_name__ = _("Darkstyle")
+__kupfer_name__ = _("Dark Theme")
 __kupfer_sources__ = ()
-__description__ = _("Use a dark color theme in Kupfer")
+__description__ = _("Use a dark color theme")
 __version__ = ""
 __author__ = ""
 
+import os
 import gtk
 
+from kupfer import config
+
+DARK_STYLE = """
+style "dark"
+{
+	## bg: background color
+	bg[NORMAL] = "#333"
+	bg[SELECTED] = "#000"
+	bg[ACTIVE] = "#222"
+	bg[PRELIGHT] = "#222"
+	bg[INSENSITIVE] = "#333"
+
+	## fg: foreground text color
+	fg[NORMAL] = "#DDD"
+	fg[SELECTED] = "#EEE"
+	fg[ACTIVE] = "#EEE"
+	fg[PRELIGHT] = "#EEE"
+	fg[INSENSITIVE] = "#DDD"
+
+	## text: text color in input widget and treeview
+	text[NORMAL] = "#EEE"
+	text[SELECTED] = "#EEE"
+	text[ACTIVE] = "#EEE"
+
+	## base: background color in input widget and treeview
+	base[NORMAL] = "#777"
+	base[SELECTED] = "#100"
+	base[ACTIVE] = "#112"
+}
+
+## The main window is kupfer
+widget "kupfer" style "dark"
+widget "kupfer.*" style "dark"
+
+## The result list is kupfer-list
+widget "kupfer-list.*" style "dark"
+
+## The context menu is GtkWindow.kupfer-menu
+## widget "*.kupfer-menu" style "dark"
+"""
+
+def cache_filename():
+	return os.path.join(config.get_cache_home(), __name__)
+
 def initialize_plugin(name):
+	"""
+	Theme changes are only reversible if we add
+	and remove gtkrc files.
+	"""
+	filename = cache_filename()
+	with open(filename, "wb") as rcfile:
+		rcfile.write(DARK_STYLE)
+	gtk.rc_add_default_file(filename)
+	## force re-read theme
 	settings = gtk.settings_get_default()
-	settings.set_property("gtk-color-scheme", DARK_COLORS)
+	gtk.rc_reparse_all_for_settings(settings, True)
 
 def finalize_plugin(name):
+	filename = cache_filename()
+	gtk.rc_set_default_files([f for f in gtk.rc_get_default_files()
+	                          if f != filename])
+	## force re-read theme
 	settings = gtk.settings_get_default()
-	settings.set_property("gtk-color-scheme", "")
-
-## Based upon darklooks but with Gray, not blue text
-DARK_COLORS = ("fg_color:#E6E6E6\n"
-               "bg_color:#555753\n"
-               "base_color:#2E3436\n"
-               "text_color:#D3D7CF\n"
-               "selected_bg_color:#3F403D\n"
-               "selected_fg_color:#CCCCCC\n"
-               "tooltip_bg_color:#EDDE5C\n"
-               "tooltip_fg_color:#000000")
+	gtk.rc_reparse_all_for_settings(settings, True)
+	assert ("kupfer" in filename)
+	try:
+		os.unlink(filename)
+	except OSError:
+		pass



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]