changeset 319:ec84b522c94b

Implement loading a palette theme from the getan config This allows to override the default palette theme for getan. For details about the possible colors see http://excess.org/urwid/docs/manual/displayattributes.html#foreground-and-background-settings Example for a ~/.getan/getanrc [theme] focus_entry=dark red, white This will change the font color to dark red and the background to white for all focused entries (in both lists).
author Björn Ricks <bjoern.ricks@intevation.de>
date Fri, 11 Oct 2013 14:25:36 +0200
parents 27fc5f43a69b
children 922935ebfdd5
files getan/config.py
diffstat 1 files changed, 65 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/getan/config.py	Fri Oct 11 14:12:03 2013 +0200
+++ b/getan/config.py	Fri Oct 11 14:25:36 2013 +0200
@@ -50,6 +50,7 @@
         self.config = self.load([os.path.expanduser("~/.getan/getanrc"),
                                  "/etc/getanrc"])
         self.keybinding = Keybinding(self)
+        self.theme = Theme(self)
 
     def load(self, filenames):
         configparser = SafeConfigParser()
@@ -68,6 +69,9 @@
     def get_keybinding(self):
         return self.keybinding
 
+    def get_theme(self):
+        return self.theme
+
 
 class Keybinding(object):
 
@@ -171,3 +175,64 @@
 
     def get_project_edit(self):
         return self.get_binding(self.KEY_PROJECT_EDIT)
+
+
+class Theme(object):
+
+    THEME = "theme"
+
+    # TODO remove unused names
+    KEY_HEADER = "header"
+    KEY_BODY = "body"
+    KEY_FOOTER = "footer"
+    KEY_PROJECT_FOOTER = "project_footer"
+    KEY_ENTRY_FOOTER = "entry_footer"
+    KEY_PROJECT_KEY = "project_key"
+    KEY_ENTRY = "entry"
+    KEY_FOCUSED_ENTRY = "focus_entry"
+    KEY_SELECTED_ENTRY = "selected_entry"
+    KEY_SELECTED_FOCUS_ENTRY = "selected_focus_entry"
+    KEY_INFO = "info"
+    KEY_QUESTION = "question"
+    KEY_RUNNING = "running"
+    KEY_PAUSED_RUNNING = "paused_running"
+
+    DEFAULT_THEME = {
+        KEY_HEADER: "white, dark blue",
+        KEY_FOOTER: "yellow,dark blue",
+        KEY_ENTRY_FOOTER: "white, dark blue",
+        KEY_PROJECT_FOOTER: "white, dark blue",
+        KEY_PROJECT_KEY: "black, dark cyan",
+        KEY_BODY: "white, black",
+        KEY_ENTRY: "white, dark blue",
+        KEY_FOCUSED_ENTRY: "white, dark cyan",
+        KEY_SELECTED_ENTRY: "yellow, light cyan",
+        KEY_SELECTED_FOCUS_ENTRY: "yellow, dark cyan",
+        KEY_INFO: "white, dark red",
+        KEY_QUESTION: "white, dark red",
+        KEY_RUNNING: "yellow, dark green",
+        KEY_PAUSED_RUNNING: "white, dark red",
+    }
+
+    def __init__(self, config):
+        self.config = config
+
+    def get_colors(self, key):
+        value = None
+        try:
+            value = self.config.get(self.THEME, key)
+        except (NoSectionError, NoOptionError):
+            pass
+
+        if not value:
+            value = self.DEFAULT_THEME[key]
+        return [val.strip() for val in value.split(",")]
+
+    def get_palette(self):
+        palette = []
+        for key in self.DEFAULT_THEME.keys():
+            colors = self.get_colors(key)
+            line = [key]
+            line.extend(colors)
+            palette.append(line)
+        return palette
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)