[Getan-commits] [PATCH 24 of 32] Implement loading a palette theme from the getan config

Wald Commits scm-commit at wald.intevation.org
Fri Oct 11 14:34:08 CEST 2013


# HG changeset patch
# User Björn Ricks <bjoern.ricks at intevation.de>
# Date 1381494336 -7200
# Node ID ec84b522c94b057a9a393c560abb23658743447a
# Parent  27fc5f43a69ba9ceae35239c6c3589101c399376
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).

diff -r 27fc5f43a69b -r ec84b522c94b getan/config.py
--- 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


More information about the Getan-commits mailing list