summary refs log tree commit diff stats
path: root/ranger/gui
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2009-11-29 15:19:45 +0100
committerhut <hut@lavabit.com>2009-11-29 15:19:45 +0100
commit9dc6fe07975ef2d489e5071f4e6d7223a33cb3b3 (patch)
tree9f7c72916c67d7a94846313bf7bed7b43f939831 /ranger/gui
parent3d566884280b1db24cb9fa13adde3985f0e7c5a2 (diff)
downloadranger-9dc6fe07975ef2d489e5071f4e6d7223a33cb3b3.tar.gz
started to implement colorschemes
Diffstat (limited to 'ranger/gui')
-rw-r--r--ranger/gui/color.py26
-rw-r--r--ranger/gui/colorscheme.py54
-rw-r--r--ranger/gui/defaultui.py10
-rw-r--r--ranger/gui/ui.py3
-rw-r--r--ranger/gui/wdisplay.py5
-rw-r--r--ranger/gui/widget.py17
6 files changed, 67 insertions, 48 deletions
diff --git a/ranger/gui/color.py b/ranger/gui/color.py
deleted file mode 100644
index 5701c0ee..00000000
--- a/ranger/gui/color.py
+++ /dev/null
@@ -1,26 +0,0 @@
-#import curses
-
-color_pairs = {10: 0}
-
-
-#class ColorScheme():
-#	def isdir
-
-
-#def get_color(fg, bg):
-#	c = bg+2 + 9*(fg + 2)
-#	try:
-#		return color_pairs[c]
-#	except KeyError:
-#		size = len(color_pairs)
-#		curses.init_pair(size, curses.COLOR_RED, curses.COLOR_WHITE)
-#		color_pairs[c] = size
-#		return color_pairs[c]
-#
-#def color(fg = -1, bg = -1, attribute = 0):
-#	pass
-##	prin
-#	curses.attrset(attribute | curses.color_pair(get_color(fg, bg)))
-
-#color(-1, -1)
-#print(color_pairs)
diff --git a/ranger/gui/colorscheme.py b/ranger/gui/colorscheme.py
new file mode 100644
index 00000000..f410983f
--- /dev/null
+++ b/ranger/gui/colorscheme.py
@@ -0,0 +1,54 @@
+
+TUPLE_KEYS = ['wdisplay', 'wstatusbar', 'wtitlebar', 'wconsole', 'folder', 'executable', 'media', 'link', 'broken', 'selected']
+
+COLOR_PAIRS = {10: 0}
+
+def get_color(fg, bg):
+	import curses
+
+	c = bg+2 + 9*(fg + 2)
+
+	if c not in COLOR_PAIRS:
+		size = len(COLOR_PAIRS)
+		curses.init_pair(size, fg, bg)
+		COLOR_PAIRS[c] = size
+
+	return COLOR_PAIRS[c]
+
+
+class ColorSchemeContext(object):
+	def __init__(self, dictionary):
+		object.__init__(self)
+
+		self.__tuple__ = None
+		for key in TUPLE_KEYS:
+			if key in dictionary:
+				self.__dict__[key] = dictionary[key]
+			else:
+				self.__dict__[key] = False
+
+	def to_tuple(self):
+		d = self.__dict__
+
+		if '__tuple__' is None:
+			self.__tuple__ = tuple(d[key] for key in TUPLE_KEYS)
+
+		return self.__tuple__
+
+class ColorScheme():
+	def __init__(self):
+		self.cache = {}
+
+	def get(self, **keywords):
+		con = ColorSchemeContext(keywords)
+		tup = con.to_tuple()
+		try:
+			return self.cache[tup]
+		except KeyError:
+			color = self.use(con)
+			self.cache[tup] = color
+			return color
+	
+	def use(self, context):
+		return -1, -1, 0
+		
diff --git a/ranger/gui/defaultui.py b/ranger/gui/defaultui.py
index 4d4f6d44..419d8a4f 100644
--- a/ranger/gui/defaultui.py
+++ b/ranger/gui/defaultui.py
@@ -6,14 +6,14 @@ RATIO = ( 0.15, 0.15, 0.4, 0.3 )
 
 class DefaultUI(SuperClass):
 	def setup(self):
-		self.titlebar = WTitleBar(self.win)
+		self.titlebar = WTitleBar(self.win, self.colorscheme)
 		self.add_widget(self.titlebar)
 
 		self.displays = [
-				WDisplay(self.win, -2),
-				WDisplay(self.win, -1),
-				WDisplay(self.win, 0),
-				WDisplay(self.win, 1) ]
+				WDisplay(self.win, self.colorscheme, -2),
+				WDisplay(self.win, self.colorscheme, -1),
+				WDisplay(self.win, self.colorscheme, 0),
+				WDisplay(self.win, self.colorscheme, 1) ]
 		self.displays[2].display_infostring = True
 		self.displays[2].main_display = True
 		for disp in self.displays:
diff --git a/ranger/gui/ui.py b/ranger/gui/ui.py
index 2abf8939..6bcfc7fe 100644
--- a/ranger/gui/ui.py
+++ b/ranger/gui/ui.py
@@ -1,9 +1,10 @@
 import curses
 from ranger.api import log
 class UI():
-	def __init__(self, env, commandlist):
+	def __init__(self, env, commandlist, colorscheme):
 		self.env = env
 		self.commandlist = commandlist
+		self.colorscheme = colorscheme
 
 		self.widgets = []
 		self.win = curses.initscr()
diff --git a/ranger/gui/wdisplay.py b/ranger/gui/wdisplay.py
index 95014d51..d8d70bf3 100644
--- a/ranger/gui/wdisplay.py
+++ b/ranger/gui/wdisplay.py
@@ -1,11 +1,10 @@
 from ranger.gui.color import color_pairs
 from ranger.gui.widget import Widget as SuperClass
 import curses
-#from ranger.color import color
 
 class WDisplay(SuperClass):
-	def __init__(self, win, level):
-		SuperClass.__init__(self,win)
+	def __init__(self, win, colorscheme, level):
+		SuperClass.__init__(self, win, colorscheme)
 		self.level = level
 		self.main_display = False
 		self.display_infostring = False
diff --git a/ranger/gui/widget.py b/ranger/gui/widget.py
index cb5fdc1f..9c64cc1a 100644
--- a/ranger/gui/widget.py
+++ b/ranger/gui/widget.py
@@ -1,25 +1,16 @@
 import curses
-from ranger.gui.color import color_pairs
+from ranger.gui.colorscheme import get_color
 
 class OutOfBoundsException(Exception): pass
 
 class Widget():
-	def __init__(self, win):
+	def __init__(self, win, colorscheme):
 		self.win = win
+		self.colorscheme = colorscheme
 		self.setdim(0, 0, 0, 0)
 
-	def get_color(self, fg, bg):
-		c = bg+2 + 9*(fg + 2)
-		try:
-			return color_pairs[c]
-		except KeyError:
-			size = len(color_pairs)
-			curses.init_pair(size, fg, bg)
-			color_pairs[c] = size
-			return color_pairs[c]
-
 	def color(self, fg = -1, bg = -1, attr = 0):
-		self.win.attrset(attr | curses.color_pair(self.get_color(fg, bg)))
+		self.win.attrset(attr | curses.color_pair(get_color(fg, bg)))
 
 	def setdim(self, y, x, hei=None, wid=None):
 		maxy, maxx = self.win.getmaxyx()