summary refs log tree commit diff stats
path: root/ranger/gui
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2009-12-13 00:45:03 +0100
committerhut <hut@lavabit.com>2009-12-13 00:45:03 +0100
commit728fb8385d3a4dca994ae652ca44b9ffe72a029d (patch)
tree34f171ecbbcc4a03060738a53de45b75c7f25b60 /ranger/gui
parente657119b4881cec409f42b738f073f5b8e43bc2a (diff)
downloadranger-728fb8385d3a4dca994ae652ca44b9ffe72a029d.tar.gz
added docstrings everywhere
Diffstat (limited to 'ranger/gui')
-rw-r--r--ranger/gui/colorscheme.py8
-rw-r--r--ranger/gui/mouse_event.py16
-rw-r--r--ranger/gui/ui.py43
-rw-r--r--ranger/gui/widgets/console.py2
-rw-r--r--ranger/gui/widgets/filelistcontainer.py5
5 files changed, 46 insertions, 28 deletions
diff --git a/ranger/gui/colorscheme.py b/ranger/gui/colorscheme.py
index 38f4ac5a..a69ed75b 100644
--- a/ranger/gui/colorscheme.py
+++ b/ranger/gui/colorscheme.py
@@ -35,6 +35,7 @@ class ColorScheme(object):
 		self.cache = {}
 
 	def get(self, *keys):
+		"""Determine the (fg, bg, attr) tuple or get it from cache"""
 		try:
 			return self.cache[keys]
 
@@ -50,6 +51,7 @@ class ColorScheme(object):
 			return color
 
 	def get_attr(self, *keys):
+		"""Returns the curses attr integer for the specified keys"""
 		from ranger.gui.color import get_color
 		import curses
 
@@ -58,5 +60,9 @@ class ColorScheme(object):
 
 
 	def use(self, context):
-		return -1, -1, 0
+		"""Use the colorscheme to determine the (fg, bg, attr) tuple.
+This is a dummy function which always returns default_colors.
+Override this in your custom colorscheme!"""
+		from ranger.gui.color import default_colors
+		return default_colors
 
diff --git a/ranger/gui/mouse_event.py b/ranger/gui/mouse_event.py
index fa25f5f0..db98e1aa 100644
--- a/ranger/gui/mouse_event.py
+++ b/ranger/gui/mouse_event.py
@@ -1,5 +1,5 @@
+import curses
 class MouseEvent(object):
-	import curses
 	PRESSED = [ 0,
 			curses.BUTTON1_PRESSED,
 			curses.BUTTON2_PRESSED,
@@ -7,10 +7,24 @@ class MouseEvent(object):
 			curses.BUTTON4_PRESSED ]
 
 	def __init__(self, getmouse):
+		"""Creates a MouseEvent object from the result of win.getmouse()"""
 		_, self.x, self.y, _, self.bstate = getmouse
 	
 	def pressed(self, n):
+		"""Returns whether the mouse key n is pressed"""
 		try:
 			return (self.bstate & MouseEvent.PRESSED[n]) != 0
 		except:
 			return False
+
+	def ctrl(self):
+		return self.bstate & curses.BUTTON_CTRL
+
+	def alt(self):
+		return self.bstate & curses.BUTTON_ALT
+
+	def shift(self):
+		return self.bstate & curses.BUTTON_SHIFT
+
+	def key_invalid(self):
+		return self.bstate > curses.ALL_MOUSE_EVENTS
diff --git a/ranger/gui/ui.py b/ranger/gui/ui.py
index 7b7230fb..eb25d9ca 100644
--- a/ranger/gui/ui.py
+++ b/ranger/gui/ui.py
@@ -48,6 +48,18 @@ class UI(DisplayableContainer):
 			self.setup()
 		self.update_size()
 
+	def destroy(self):
+		"""Destroy all widgets and turn off curses"""
+#		DisplayableContainer.destroy(self)
+		from ranger import log
+		log("exiting ui!")
+		self.win.keypad(0)
+		curses.nocbreak()
+		curses.echo()
+		curses.curs_set(1)
+		curses.mousemask(0)
+		curses.endwin()
+
 	def handle_mouse(self):
 		"""Handles mouse input"""
 		try:
@@ -55,20 +67,17 @@ class UI(DisplayableContainer):
 		except:
 			return
 
+#		from ranger import log
+#		log('{0:0>28b} ({0})'.format(event.bstate))
+
 		if DisplayableContainer.click(self, event):
 			return
 
-#		if event.pressed(1) or event.pressed(3):
-#			for displayable in self.container:
-#				if displayable.contains_point(event.y, event.x):
-#					displayable.click(event)
-#					break
-
-#		if event.pressed(4) or event.pressed(2) or event.bstate & 134217728:
+		n = event.ctrl() and 1 or 3
 		if event.pressed(4):
-			self.fm.scroll(relative = -3)
-		elif event.pressed(2):
-			self.fm.scroll(relative = 3)
+			self.fm.scroll(relative = -n)
+		elif event.pressed(2) or event.key_invalid():
+			self.fm.scroll(relative = n)
 
 	def handle_key(self, key):
 		"""Handles key input"""
@@ -78,7 +87,7 @@ class UI(DisplayableContainer):
 			return
 
 		try:
-			cmd = self.commandlist.paths[tuple(self.env.keybuffer)]
+			cmd = self.commandlist[tuple(self.env.keybuffer)]
 		except KeyError:
 			self.env.key_clear()
 			return
@@ -119,15 +128,3 @@ Extend this method to resize all widgets!"""
 		"""Finalize every object in container and refresh the window"""
 		DisplayableContainer.finalize(self)
 		self.win.refresh()
-
-	def destroy(self):
-		"""Destroy all widgets and turn off curses"""
-#		DisplayableContainer.destroy(self)
-		from ranger import log
-		log("exiting ui!")
-		self.win.keypad(0)
-		curses.nocbreak()
-		curses.echo()
-		curses.curs_set(1)
-#		curses.mousemask(0)
-		curses.endwin()
diff --git a/ranger/gui/widgets/console.py b/ranger/gui/widgets/console.py
index 17197a2e..f4b278c9 100644
--- a/ranger/gui/widgets/console.py
+++ b/ranger/gui/widgets/console.py
@@ -69,7 +69,7 @@ class Console(Widget):
 		from curses.ascii import ctrl, ESC
 
 		try:
-			cmd = self.commandlist.paths[self.env.keybuffer]
+			cmd = self.commandlist[self.env.keybuffer]
 		except KeyError:
 			self.env.key_clear()
 			return
diff --git a/ranger/gui/widgets/filelistcontainer.py b/ranger/gui/widgets/filelistcontainer.py
index ed5a36c4..9d95b389 100644
--- a/ranger/gui/widgets/filelistcontainer.py
+++ b/ranger/gui/widgets/filelistcontainer.py
@@ -19,7 +19,8 @@ class FileListContainer(Widget, DisplayableContainer):
 		if preview: offset += 1
 
 		for level in range(len(ratios)):
-			self.add_obj(FileList(win, level + offset))
+			fl = FileList(win, level + offset)
+			self.add_obj(fl)
 
 		try:
 			self.main_filelist = self.container[preview and -2 or -1]
@@ -32,7 +33,7 @@ class FileListContainer(Widget, DisplayableContainer):
 	def resize(self, y, x, hei, wid):
 		"""Resize all the filelists according to the given ratio"""
 		DisplayableContainer.resize(self, y, x, hei, wid)
-		left = self.y
+		left = self.x
 		for ratio, i in zip(self.ratios, range(len(self.ratios))):
 			wid = int(ratio * self.wid)
 			try: