summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--ranger/gui/curses_shortcuts.py54
-rw-r--r--ranger/gui/displayable.py64
2 files changed, 64 insertions, 54 deletions
diff --git a/ranger/gui/curses_shortcuts.py b/ranger/gui/curses_shortcuts.py
new file mode 100644
index 00000000..3d85f697
--- /dev/null
+++ b/ranger/gui/curses_shortcuts.py
@@ -0,0 +1,54 @@
+from ranger.shared import SettingsAware
+import _curses
+
+class CursesShortcuts(SettingsAware):
+
+	"""
+	This class defines shortcuts to faciliate operations with curses.
+	color(*keys) -- sets the color associated with the keys from
+		the current colorscheme.
+	color_at(y, x, wid, *keys) -- sets the color at the given position
+	color_reset() -- resets the color to the default
+	addstr(*args) -- failsafe version of self.win.addstr(*args)
+	"""
+
+	colorscheme = None
+
+	def addstr(self, *args):
+		try:
+			self.win.addstr(*args)
+		except _curses.error:
+			pass
+
+	def color(self, keylist = None, *keys):
+		"""Change the colors from now on."""
+		keys = combine(keylist, keys)
+		attr = self.settings.colorscheme.get_attr(*keys)
+		try:
+			self.win.attrset(attr)
+		except _curses.error:
+			pass
+
+	def color_at(self, y, x, wid, keylist = None, *keys):
+		"""Change the colors at the specified position"""
+		keys = combine(keylist, keys)
+		attr = self.settings.colorscheme.get_attr(*keys)
+		try:
+			self.win.chgat(y, x, wid, attr)
+		except _curses.error:
+			pass
+	
+	def color_reset(self):
+		"""Change the colors to the default colors"""
+		CursesShortcuts.color(self, 'reset')
+
+def combine(seq, tup):
+	"""Add seq and tup. Ensures that the result is a tuple."""
+	try:
+		if isinstance(seq, str): raise TypeError
+		return tuple(tuple(seq) + tup)
+	except TypeError:
+		try:
+			return tuple((seq, ) + tup)
+		except:
+			return ()
diff --git a/ranger/gui/displayable.py b/ranger/gui/displayable.py
index 1929c4e2..8ec8e10e 100644
--- a/ranger/gui/displayable.py
+++ b/ranger/gui/displayable.py
@@ -1,17 +1,19 @@
-from ranger.shared import FileManagerAware, EnvironmentAware, SettingsAware
+from ranger.shared import FileManagerAware, EnvironmentAware
+from ranger.gui.curses_shortcuts import CursesShortcuts
 from ranger import log
 import _curses
 
 
-class Displayable(EnvironmentAware, FileManagerAware, SettingsAware):
+class Displayable(EnvironmentAware, FileManagerAware, CursesShortcuts):
+
 	"""
 	Displayables are objects which are displayed on the screen.
 
 	This is just the abstract class, defining basic operations
 	such as resizing, printing, changing colors.
-	Subclasses of displayable should implement this interface:
+	Subclasses of displayable can extend these methods:
 
-	draw() -- draw the object here. Is only called if visible.
+	draw() -- draw the object. Is only called if visible.
 	poke() -- is called just before draw(), even if not visible.
 	finalize() -- called after all objects finished drawing.
 	click(event) -- called with a MouseEvent. This is called on all
@@ -19,13 +21,8 @@ class Displayable(EnvironmentAware, FileManagerAware, SettingsAware):
 	press(key) -- called after a key press on focused objects.
 	destroy() -- called before destroying the displayable object
 
-	This abstract class defines the following (helper) methods:
+	Additionally, there are these methods:
 
-	color(*keys) -- sets the color associated with the keys from
-		the current colorscheme.
-	color_at(y, x, wid, *keys) -- sets the color at the given position
-	color_reset() -- resets the color to the default
-	addstr(*args) -- failsafe version of self.win.addstr(*args)
 	__contains__(item) -- is the item (y, x) inside the widget?
 	
 	These attributes are set:
@@ -36,6 +33,7 @@ class Displayable(EnvironmentAware, FileManagerAware, SettingsAware):
 		need_redraw -- Should the widget be redrawn? This variable may
 			be set at various places in the script and should eventually be
 			handled (and unset) in the draw() method.
+		colorscheme -- The colorscheme object.
 	
 	Read-Only: (i.e. reccomended not to change manually)
 		win -- the own curses window object
@@ -89,34 +87,6 @@ class Displayable(EnvironmentAware, FileManagerAware, SettingsAware):
 		
 		return self.contains_point(y, x)
 
-	def addstr(self, *args):
-		try:
-			self.win.addstr(*args)
-		except _curses.error:
-			pass
-	
-	def color(self, keylist = None, *keys):
-		"""Change the colors from now on."""
-		keys = combine(keylist, keys)
-		attr = self.settings.colorscheme.get_attr(*keys)
-		try:
-			self.win.attrset(attr)
-		except _curses.error:
-			pass
-
-	def color_at(self, y, x, wid, keylist = None, *keys):
-		"""Change the colors at the specified position"""
-		keys = combine(keylist, keys)
-		attr = self.settings.colorscheme.get_attr(*keys)
-		try:
-			self.win.chgat(y, x, wid, attr)
-		except _curses.error:
-			pass
-	
-	def color_reset(self):
-		"""Change the colors to the default colors"""
-		Displayable.color(self, 'reset')
-
 	def draw(self):
 		"""
 		Draw the object. Called on every main iteration if visible.
@@ -238,7 +208,7 @@ class DisplayableContainer(Displayable):
 	DisplayableContainers are Displayables which contain other Displayables.
 
 	This is also an abstract class. The methods draw, poke, finalize,
-	click, press and destroy are overridden here and will recursively
+	click, press and destroy are extended here and will recursively
 	call the function on all contained objects.
 
 	New methods:
@@ -263,7 +233,7 @@ class DisplayableContainer(Displayable):
 
 		Displayable.__init__(self, win)
 	
-	# ----------------------------------------------- overrides
+	# ------------------------------------ extended or overidden methods
 
 	def poke(self):
 		"""Recursively called on objects in container"""
@@ -345,17 +315,3 @@ class DisplayableContainer(Displayable):
 				if obj is not None:
 					return obj
 		return None
-
-class OutOfBoundsException(Exception):
-	pass
-
-def combine(seq, tup):
-	"""Add seq and tup. Ensures that the result is a tuple."""
-	try:
-		if isinstance(seq, str): raise TypeError
-		return tuple(tuple(seq) + tup)
-	except TypeError:
-		try:
-			return tuple((seq, ) + tup)
-		except:
-			return ()
8e60380e ^



84393683 ^

7a84094a ^
84393683 ^
d63cddea ^
84393683 ^









eb45abde ^
093b45e7 ^

eb45abde ^
093b45e7 ^
eb45abde ^
b75d9d45 ^
093b45e7 ^

eb45abde ^
093b45e7 ^

eb45abde ^
093b45e7 ^


b75d9d45 ^
093b45e7 ^

78c50205 ^
093b45e7 ^
b0bf5321 ^
eb45abde ^
21fc6180 ^



78c50205 ^
21fc6180 ^

eb45abde ^
093b45e7 ^

b75d9d45 ^





78c50205 ^
b75d9d45 ^






093b45e7 ^




dad3bedd ^
21fc6180 ^

eb45abde ^
21fc6180 ^
78c50205 ^
21fc6180 ^



















3473c63a ^
af023b32 ^

d57bf669 ^
af023b32 ^
d57bf669 ^

3473c63a ^
8e60380e ^
af023b32 ^
8e60380e ^

b75d9d45 ^



7a84094a ^
864cbf9d ^


d52406cc ^
b75d9d45 ^

dad3bedd ^


dad3bedd ^


7a84094a ^

dad3bedd ^
d63cddea ^
dad3bedd ^




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172