Mercurial > getan > getan
annotate getan/config.py @ 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 | fcbdecb0f9e0 |
children | 527168c08ae4 |
rev | line source |
---|---|
23
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
3 # |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
4 # (c) 2010 by Ingo Weinzierl <ingo.weinzierl@intevation.de> |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
5 # |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
6 # This is Free Software licensed under the terms of GPLv3 or later. |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
7 # For details see LICENSE coming with the source of 'getan'. |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
8 # |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
9 |
36
e6f81aa329b1
Introduced i18n support; german and english translation available.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
23
diff
changeset
|
10 import locale |
23
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
11 import logging |
36
e6f81aa329b1
Introduced i18n support; german and english translation available.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
23
diff
changeset
|
12 import os |
23
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
13 |
148
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
14 from ConfigParser import SafeConfigParser, NoSectionError, NoOptionError |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
15 |
23
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
16 logger = None |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
17 |
305
fcbdecb0f9e0
Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents:
176
diff
changeset
|
18 |
66
13e3ec26dc36
Make the logging configurable for filename and level
Björn Ricks <bjoern.ricks@intevation.de>
parents:
39
diff
changeset
|
19 def initialize(level=logging.INFO, filename="getan.log"): |
13e3ec26dc36
Make the logging configurable for filename and level
Björn Ricks <bjoern.ricks@intevation.de>
parents:
39
diff
changeset
|
20 setup_logging(level, filename) |
36
e6f81aa329b1
Introduced i18n support; german and english translation available.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
23
diff
changeset
|
21 setup_locale() |
e6f81aa329b1
Introduced i18n support; german and english translation available.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
23
diff
changeset
|
22 |
e6f81aa329b1
Introduced i18n support; german and english translation available.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
23
diff
changeset
|
23 |
66
13e3ec26dc36
Make the logging configurable for filename and level
Björn Ricks <bjoern.ricks@intevation.de>
parents:
39
diff
changeset
|
24 def setup_logging(level, filename): |
39
d4ce02a33acd
Minor fixes (logging, states)
Sascha L. Teichmann <teichmann@intevation.de>
parents:
36
diff
changeset
|
25 global logger |
66
13e3ec26dc36
Make the logging configurable for filename and level
Björn Ricks <bjoern.ricks@intevation.de>
parents:
39
diff
changeset
|
26 logging.basicConfig(level=level, |
23
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
27 format='%(asctime)s %(levelname)s %(message)s', |
66
13e3ec26dc36
Make the logging configurable for filename and level
Björn Ricks <bjoern.ricks@intevation.de>
parents:
39
diff
changeset
|
28 filename=filename, |
23
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
29 filemode='w') |
9c4e8ba3c4fa
Added a new implementation of 'getan' based on urwid, a python console user interface library.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
diff
changeset
|
30 logger = logging.getLogger() |
36
e6f81aa329b1
Introduced i18n support; german and english translation available.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
23
diff
changeset
|
31 |
e6f81aa329b1
Introduced i18n support; german and english translation available.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
23
diff
changeset
|
32 |
e6f81aa329b1
Introduced i18n support; german and english translation available.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
23
diff
changeset
|
33 def setup_locale(): |
e6f81aa329b1
Introduced i18n support; german and english translation available.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
23
diff
changeset
|
34 for var in ('LANGUAGE', 'LC_ALL', 'LC_MESSAGES', 'LANG'): |
e6f81aa329b1
Introduced i18n support; german and english translation available.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
23
diff
changeset
|
35 if var in os.environ: |
e6f81aa329b1
Introduced i18n support; german and english translation available.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
23
diff
changeset
|
36 break |
e6f81aa329b1
Introduced i18n support; german and english translation available.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
23
diff
changeset
|
37 else: |
e6f81aa329b1
Introduced i18n support; german and english translation available.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
23
diff
changeset
|
38 default_locale = locale.getdefaultlocale() |
e6f81aa329b1
Introduced i18n support; german and english translation available.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
23
diff
changeset
|
39 # The default is normally a tuple of two strings. It may |
e6f81aa329b1
Introduced i18n support; german and english translation available.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
23
diff
changeset
|
40 # contain None, objects under some circumstances, though. |
e6f81aa329b1
Introduced i18n support; german and english translation available.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
23
diff
changeset
|
41 if len(default_locale) > 1: |
e6f81aa329b1
Introduced i18n support; german and english translation available.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
23
diff
changeset
|
42 lang = default_locale[0] |
e6f81aa329b1
Introduced i18n support; german and english translation available.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
23
diff
changeset
|
43 if isinstance(lang, str): |
e6f81aa329b1
Introduced i18n support; german and english translation available.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
23
diff
changeset
|
44 os.environ["LANG"] = lang |
e6f81aa329b1
Introduced i18n support; german and english translation available.
Ingo Weinzierl <ingo_weinzierl@web.de>
parents:
23
diff
changeset
|
45 |
148
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
46 |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
47 class Config(object): |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
48 |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
49 def __init__(self): |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
50 self.config = self.load([os.path.expanduser("~/.getan/getanrc"), |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
51 "/etc/getanrc"]) |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
52 self.keybinding = Keybinding(self) |
319
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
53 self.theme = Theme(self) |
148
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
54 |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
55 def load(self, filenames): |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
56 configparser = SafeConfigParser() |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
57 configparser.read(filenames) |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
58 return configparser |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
59 |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
60 def get(self, section, key): |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
61 return self.config.get(section, key) |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
62 |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
63 def items(self, section): |
164
90abd423fc0c
Fix: Return empty list if section is not found
Björn Ricks <bjoern.ricks@intevation.de>
parents:
148
diff
changeset
|
64 try: |
90abd423fc0c
Fix: Return empty list if section is not found
Björn Ricks <bjoern.ricks@intevation.de>
parents:
148
diff
changeset
|
65 return self.config.items(section) |
90abd423fc0c
Fix: Return empty list if section is not found
Björn Ricks <bjoern.ricks@intevation.de>
parents:
148
diff
changeset
|
66 except NoSectionError: |
90abd423fc0c
Fix: Return empty list if section is not found
Björn Ricks <bjoern.ricks@intevation.de>
parents:
148
diff
changeset
|
67 return [] |
148
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
68 |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
69 def get_keybinding(self): |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
70 return self.keybinding |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
71 |
319
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
72 def get_theme(self): |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
73 return self.theme |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
74 |
148
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
75 |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
76 class Keybinding(object): |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
77 |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
78 KEYBINDINGS = "keybindings" |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
79 |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
80 KEY_SWITCH_TIME_MODE = "switch_time_mode" |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
81 KEY_SWITCH_PROJECT_ORDER = "switch_project_order" |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
82 KEY_SWITCH_LISTS = "switch_lists" |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
83 KEY_ENTER = "enter" |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
84 KEY_INSERT = "insert" |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
85 KEY_DELETE = "delete" |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
86 KEY_ESCAPE = "escape" |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
87 KEY_ENTRY_DELETE = "entry_delete" |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
88 KEY_ENTRY_UP = "entry_up" |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
89 KEY_ENTRY_DOWN = "entry_down" |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
90 KEY_ENTRY_MOVE = "entry_move" |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
91 KEY_ENTRY_EDIT = "entry_edit" |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
92 KEY_ADD_TIME = "add_time" |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
93 KEY_SUBTRACT_TIME = "subtract_time" |
171
a34693c5905f
Use common name scheme for keybinding key names
Björn Ricks <bjoern.ricks@intevation.de>
parents:
164
diff
changeset
|
94 KEY_PROJECT_PAUSE = "project_pause" |
176
6e8b23f1ee94
Add new key for editing a project
Björn Ricks <bjoern.ricks@intevation.de>
parents:
171
diff
changeset
|
95 KEY_PROJECT_EDIT = "project_edit" |
148
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
96 |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
97 DEFAULT_KEYBINDINGS = { |
305
fcbdecb0f9e0
Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents:
176
diff
changeset
|
98 KEY_SWITCH_TIME_MODE: "f1", |
fcbdecb0f9e0
Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents:
176
diff
changeset
|
99 KEY_SWITCH_PROJECT_ORDER: "f2", |
fcbdecb0f9e0
Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents:
176
diff
changeset
|
100 KEY_SWITCH_LISTS: "tab", |
fcbdecb0f9e0
Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents:
176
diff
changeset
|
101 KEY_ENTER: "enter", |
fcbdecb0f9e0
Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents:
176
diff
changeset
|
102 KEY_INSERT: "insert", |
fcbdecb0f9e0
Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents:
176
diff
changeset
|
103 KEY_DELETE: "delete", |
fcbdecb0f9e0
Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents:
176
diff
changeset
|
104 KEY_ESCAPE: "esc", |
fcbdecb0f9e0
Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents:
176
diff
changeset
|
105 KEY_ENTRY_UP: "up", |
fcbdecb0f9e0
Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents:
176
diff
changeset
|
106 KEY_ENTRY_DOWN: "down", |
fcbdecb0f9e0
Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents:
176
diff
changeset
|
107 KEY_ENTRY_DELETE: "d", |
fcbdecb0f9e0
Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents:
176
diff
changeset
|
108 KEY_ENTRY_MOVE: "m", |
fcbdecb0f9e0
Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents:
176
diff
changeset
|
109 KEY_ENTRY_EDIT: "e", |
fcbdecb0f9e0
Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents:
176
diff
changeset
|
110 KEY_ADD_TIME: "+", |
fcbdecb0f9e0
Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents:
176
diff
changeset
|
111 KEY_SUBTRACT_TIME: "-", |
fcbdecb0f9e0
Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents:
176
diff
changeset
|
112 KEY_PROJECT_PAUSE: " ", |
fcbdecb0f9e0
Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents:
176
diff
changeset
|
113 KEY_PROJECT_EDIT: "backspace", |
fcbdecb0f9e0
Update codingstyle for pep8
Björn Ricks <bjoern.ricks@intevation.de>
parents:
176
diff
changeset
|
114 } |
148
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
115 |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
116 def __init__(self, config): |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
117 logger.debug("Keybindings are: %r" % config.items(self.KEYBINDINGS)) |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
118 self.config = config |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
119 |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
120 def get_binding(self, key): |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
121 value = None |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
122 try: |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
123 value = self.config.get(self.KEYBINDINGS, key) |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
124 except (NoSectionError, NoOptionError): |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
125 pass |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
126 |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
127 if not value: |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
128 value = self.DEFAULT_KEYBINDINGS[key] |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
129 return value |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
130 |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
131 def get_switch_time_mode(self): |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
132 return self.get_binding(self.KEY_SWITCH_TIME_MODE) |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
133 |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
134 def get_switch_project_order(self): |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
135 return self.get_binding(self.KEY_SWITCH_PROJECT_ORDER) |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
136 |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
137 def get_switch_lists(self): |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
138 return self.get_binding(self.KEY_SWITCH_LISTS) |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
139 |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
140 def get_enter(self): |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
141 return self.get_binding(self.KEY_ENTER) |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
142 |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
143 def get_insert(self): |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
144 return self.get_binding(self.KEY_INSERT) |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
145 |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
146 def get_delete(self): |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
147 return self.get_binding(self.KEY_DELETE) |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
148 |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
149 def get_escape(self): |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
150 return self.get_binding(self.KEY_ESCAPE) |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
151 |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
152 def get_entry_delete(self): |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
153 return self.get_binding(self.KEY_ENTRY_DELETE) |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
154 |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
155 def get_entry_move(self): |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
156 return self.get_binding(self.KEY_ENTRY_MOVE) |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
157 |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
158 def get_entry_edit(self): |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
159 return self.get_binding(self.KEY_ENTRY_EDIT) |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
160 |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
161 def get_entry_up(self): |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
162 return self.get_binding(self.KEY_ENTRY_UP) |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
163 |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
164 def get_entry_down(self): |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
165 return self.get_binding(self.KEY_ENTRY_DOWN) |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
166 |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
167 def get_add_time(self): |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
168 return self.get_binding(self.KEY_ADD_TIME) |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
169 |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
170 def get_subtract_time(self): |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
171 return self.get_binding(self.KEY_SUBTRACT_TIME) |
f0a2beb17f9b
Add config classes to provide keybindings
Björn Ricks <bjoern.ricks@intevation.de>
parents:
66
diff
changeset
|
172 |
171
a34693c5905f
Use common name scheme for keybinding key names
Björn Ricks <bjoern.ricks@intevation.de>
parents:
164
diff
changeset
|
173 def get_project_pause(self): |
a34693c5905f
Use common name scheme for keybinding key names
Björn Ricks <bjoern.ricks@intevation.de>
parents:
164
diff
changeset
|
174 return self.get_binding(self.KEY_PROJECT_PAUSE) |
176
6e8b23f1ee94
Add new key for editing a project
Björn Ricks <bjoern.ricks@intevation.de>
parents:
171
diff
changeset
|
175 |
6e8b23f1ee94
Add new key for editing a project
Björn Ricks <bjoern.ricks@intevation.de>
parents:
171
diff
changeset
|
176 def get_project_edit(self): |
6e8b23f1ee94
Add new key for editing a project
Björn Ricks <bjoern.ricks@intevation.de>
parents:
171
diff
changeset
|
177 return self.get_binding(self.KEY_PROJECT_EDIT) |
319
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
178 |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
179 |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
180 class Theme(object): |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
181 |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
182 THEME = "theme" |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
183 |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
184 # TODO remove unused names |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
185 KEY_HEADER = "header" |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
186 KEY_BODY = "body" |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
187 KEY_FOOTER = "footer" |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
188 KEY_PROJECT_FOOTER = "project_footer" |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
189 KEY_ENTRY_FOOTER = "entry_footer" |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
190 KEY_PROJECT_KEY = "project_key" |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
191 KEY_ENTRY = "entry" |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
192 KEY_FOCUSED_ENTRY = "focus_entry" |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
193 KEY_SELECTED_ENTRY = "selected_entry" |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
194 KEY_SELECTED_FOCUS_ENTRY = "selected_focus_entry" |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
195 KEY_INFO = "info" |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
196 KEY_QUESTION = "question" |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
197 KEY_RUNNING = "running" |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
198 KEY_PAUSED_RUNNING = "paused_running" |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
199 |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
200 DEFAULT_THEME = { |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
201 KEY_HEADER: "white, dark blue", |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
202 KEY_FOOTER: "yellow,dark blue", |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
203 KEY_ENTRY_FOOTER: "white, dark blue", |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
204 KEY_PROJECT_FOOTER: "white, dark blue", |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
205 KEY_PROJECT_KEY: "black, dark cyan", |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
206 KEY_BODY: "white, black", |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
207 KEY_ENTRY: "white, dark blue", |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
208 KEY_FOCUSED_ENTRY: "white, dark cyan", |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
209 KEY_SELECTED_ENTRY: "yellow, light cyan", |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
210 KEY_SELECTED_FOCUS_ENTRY: "yellow, dark cyan", |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
211 KEY_INFO: "white, dark red", |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
212 KEY_QUESTION: "white, dark red", |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
213 KEY_RUNNING: "yellow, dark green", |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
214 KEY_PAUSED_RUNNING: "white, dark red", |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
215 } |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
216 |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
217 def __init__(self, config): |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
218 self.config = config |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
219 |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
220 def get_colors(self, key): |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
221 value = None |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
222 try: |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
223 value = self.config.get(self.THEME, key) |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
224 except (NoSectionError, NoOptionError): |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
225 pass |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
226 |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
227 if not value: |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
228 value = self.DEFAULT_THEME[key] |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
229 return [val.strip() for val in value.split(",")] |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
230 |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
231 def get_palette(self): |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
232 palette = [] |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
233 for key in self.DEFAULT_THEME.keys(): |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
234 colors = self.get_colors(key) |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
235 line = [key] |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
236 line.extend(colors) |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
237 palette.append(line) |
ec84b522c94b
Implement loading a palette theme from the getan config
Björn Ricks <bjoern.ricks@intevation.de>
parents:
305
diff
changeset
|
238 return palette |