about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2010-02-28 19:16:30 +0100
committerhut <hut@lavabit.com>2010-02-28 19:21:33 +0100
commit7740d52513dd78d1e5b84262c076c15f0a3e42d3 (patch)
treeff9381f286e7faae705c74c40c27e8008414a215
parentd8bb27bde7952939643f2d23711bd85c401d94d1 (diff)
downloadranger-7740d52513dd78d1e5b84262c076c15f0a3e42d3.tar.gz
added a seperate Context class
-rw-r--r--ranger/gui/colorscheme.py20
-rw-r--r--ranger/gui/context.py41
2 files changed, 43 insertions, 18 deletions
diff --git a/ranger/gui/colorscheme.py b/ranger/gui/colorscheme.py
index f40e4a0d..867aec70 100644
--- a/ranger/gui/colorscheme.py
+++ b/ranger/gui/colorscheme.py
@@ -44,22 +44,7 @@ colorscheme = colorschemes.filename.classname
 from ranger.ext.openstruct import ReferencedOpenStruct
 from curses import color_pair
 from ranger.gui.color import get_color
-
-CONTEXT_KEYS = ['reset', 'error',
-		'in_browser', 'in_statusbar', 'in_titlebar', 'in_console',
-		'in_pager', 'in_taskview',
-		'directory', 'file', 'hostname',
-		'executable', 'media', 'link',
-		'video', 'audio', 'image', 'media', 'document', 'container',
-		'selected', 'empty', 'main_column', 'message', 'background',
-		'good', 'bad',
-		'space', 'permissions', 'owner', 'group', 'mtime', 'nlink',
-		'scroll', 'all', 'bot', 'top', 'percentage',
-		'marked', 'tagged', 'tag_marker',
-		'help_markup',
-		'seperator', 'key', 'special',
-		'title', 'text', 'highlight', 'bars', 'quotes',
-		'keybuffer']
+from ranger.gui.context import Context
 
 class ColorScheme(object):
 	"""
@@ -85,8 +70,7 @@ class ColorScheme(object):
 			return self.cache[keys]
 
 		except KeyError:
-			context = ReferencedOpenStruct(dict(
-				(key, key in keys) for key in CONTEXT_KEYS))
+			context = Context(keys)
 
 			# add custom error messages for broken colorschemes
 			color = self.use(context)
diff --git a/ranger/gui/context.py b/ranger/gui/context.py
new file mode 100644
index 00000000..25544932
--- /dev/null
+++ b/ranger/gui/context.py
@@ -0,0 +1,41 @@
+# Copyright (C) 2009, 2010  Roman Zimbelmann <romanz@lavabit.com>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+CONTEXT_KEYS = ['reset', 'error',
+		'in_browser', 'in_statusbar', 'in_titlebar', 'in_console',
+		'in_pager', 'in_taskview',
+		'directory', 'file', 'hostname',
+		'executable', 'media', 'link',
+		'video', 'audio', 'image', 'media', 'document', 'container',
+		'selected', 'empty', 'main_column', 'message', 'background',
+		'good', 'bad',
+		'space', 'permissions', 'owner', 'group', 'mtime', 'nlink',
+		'scroll', 'all', 'bot', 'top', 'percentage',
+		'marked', 'tagged', 'tag_marker',
+		'help_markup',
+		'seperator', 'key', 'special',
+		'title', 'text', 'highlight', 'bars', 'quotes',
+		'keybuffer']
+
+class Context(object):
+	def __init__(self, keys):
+		# set all given keys to True
+		d = self.__dict__
+		for key in keys:
+			d[key] = True
+
+# set all keys to False
+for key in CONTEXT_KEYS:
+	setattr(Context, key, False)