summary refs log tree commit diff stats
path: root/ranger/gui
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2009-11-29 23:11:26 +0100
committerhut <hut@lavabit.com>2009-11-29 23:11:26 +0100
commitae943ecbc21969937b13ac70ab71facc61271a6f (patch)
tree3fa65ed9aaf656c1d5b7ad8e6ce6bd007578c7d9 /ranger/gui
parent5805deca6306eb888ebdad64c14119995521c6b8 (diff)
downloadranger-ae943ecbc21969937b13ac70ab71facc61271a6f.tar.gz
mouse support
Diffstat (limited to 'ranger/gui')
-rw-r--r--ranger/gui/colorscheme.py6
-rw-r--r--ranger/gui/ui.py46
-rw-r--r--ranger/gui/wdisplay.py26
-rw-r--r--ranger/gui/widget.py2
-rw-r--r--ranger/gui/wtitlebar.py7
5 files changed, 77 insertions, 10 deletions
diff --git a/ranger/gui/colorscheme.py b/ranger/gui/colorscheme.py
index e69e9d7e..d6bf5cce 100644
--- a/ranger/gui/colorscheme.py
+++ b/ranger/gui/colorscheme.py
@@ -1,4 +1,8 @@
-CONTEXT_KEYS = ['reset', 'in_display', 'in_statusbar', 'in_titlebar', 'in_console', 'directory', 'file', 'maindisplay', 'executable', 'media', 'link', 'broken', 'selected', 'empty', 'currentfile', 'hostname']
+CONTEXT_KEYS = [ 'reset',
+		'in_display', 'in_statusbar', 'in_titlebar', 'in_console',
+		'directory', 'file', 'hostname',
+		'executable', 'media', 'link',
+		'broken', 'selected', 'empty', 'maindisplay']
 
 class ColorSchemeContext():
 	pass
diff --git a/ranger/gui/ui.py b/ranger/gui/ui.py
index a54003dc..77f88080 100644
--- a/ranger/gui/ui.py
+++ b/ranger/gui/ui.py
@@ -1,5 +1,5 @@
 import curses
-from ranger.api import log
+
 class UI():
 	def __init__(self, env, commandlist, colorscheme):
 		self.env = env
@@ -7,8 +7,6 @@ class UI():
 		self.colorscheme = colorscheme
 
 		self.widgets = []
-		self.win = curses.initscr()
-		self.win.leaveok(1)
 
 		self.initialize()
 
@@ -16,11 +14,31 @@ class UI():
 		self.resize()
 
 	def initialize(self):
+		self.win = curses.initscr()
+		self.win.leaveok(1)
+		self.win.keypad(1)
+
 		curses.noecho()
 		curses.halfdelay(20)
 		curses.curs_set(0)
 		curses.start_color()
 		curses.use_default_colors()
+		curses.mouseinterval(0)
+		mask = curses.ALL_MOUSE_EVENTS | curses.REPORT_MOUSE_POSITION
+		avail, old = curses.mousemask(mask)
+		curses.mousemask(avail)
+
+	def handle_mouse(self, fm):
+		try:
+			event = MouseEvent(curses.getmouse())
+		except:
+			return
+
+		if event.pressed(1) or event.pressed(3):
+			for widg in self.widgets:
+				if widg.contains_point(event.y, event.x):
+					widg.click(event, fm)
+					break
 
 	def setup(self):
 		pass
@@ -41,7 +59,9 @@ class UI():
 
 	def press(self, key, fm):
 		self.env.key_append(key)
-		log(self.env.keybuffer)
+
+#		from ranger.api import log
+#		log(self.env.keybuffer)
 
 		try:
 			cmd = self.commandlist.paths[self.env.keybuffer]
@@ -66,10 +86,26 @@ class UI():
 			widg.feed_env(self.env)
 			widg.draw()
 		self.win.refresh()
-#		log(self.env.cf)
 
 	def get_next_key(self):
 		key = self.win.getch()
 		curses.flushinp()
 		return key
 
+
+class MouseEvent():
+	import curses
+	PRESSED = [ 0,
+			curses.BUTTON1_PRESSED,
+			curses.BUTTON2_PRESSED,
+			curses.BUTTON3_PRESSED,
+			curses.BUTTON4_PRESSED ]
+
+	def __init__(self, getmouse):
+		_, self.x, self.y, _, self.bstate = getmouse
+	
+	def pressed(self, n):
+		try:
+			return (self.bstate & MouseEvent.PRESSED[n]) != 0
+		except:
+			return False
diff --git a/ranger/gui/wdisplay.py b/ranger/gui/wdisplay.py
index 00f73a93..2aba3a61 100644
--- a/ranger/gui/wdisplay.py
+++ b/ranger/gui/wdisplay.py
@@ -14,6 +14,32 @@ class WDisplay(SuperClass):
 		self.scroll_offset = env.opt['scroll_offset']
 		self.directories_first = env.opt['directories_first']
 		self.preview_files = env.opt['preview_files']
+		
+	def click(self, event, fm):
+		from ranger.fsobject import T_DIRECTORY
+
+		if self.target is None:
+			pass
+
+		elif self.target.type is T_DIRECTORY:
+			index = self.scroll_begin + event.y - self.y
+
+			if event.pressed(1):
+				if not self.main_display:
+					fm.enter_dir(self.target.path)
+
+				if index < len(self.target):
+					fm.move_pointer(absolute = index)
+			elif event.pressed(3):
+				try:
+					clicked_file = self.target[index]
+					fm.enter_dir(clicked_file.path)
+				except:
+					pass
+
+		else:
+			if self.level > 0:
+				fm.move_right()
 
 	def draw(self):
 		from ranger.file import File
diff --git a/ranger/gui/widget.py b/ranger/gui/widget.py
index cb78062b..f9a0651f 100644
--- a/ranger/gui/widget.py
+++ b/ranger/gui/widget.py
@@ -55,7 +55,7 @@ class Widget():
 	def feed(self):
 		pass
 
-	def click(self):
+	def click(self, event, fm):
 		pass
 	
 	def draw(self):
diff --git a/ranger/gui/wtitlebar.py b/ranger/gui/wtitlebar.py
index b95311dd..af8ab0d7 100644
--- a/ranger/gui/wtitlebar.py
+++ b/ranger/gui/wtitlebar.py
@@ -1,19 +1,20 @@
-import curses, socket
 from ranger.gui.widget import Widget as SuperClass
 
-
 class WTitleBar(SuperClass):
 	def feed_env(self, env):
 		self.pathway = env.pathway
 		self.cf = env.cf
 
 	def draw(self):
+		import curses, socket, os
 		self.win.move(self.y, self.x)
 
 		try:
 			self.color('in_titlebar', 'hostname')
-			self.win.addnstr(socket.gethostname(), self.wid)
+			string = os.getenv('LOGNAME') + '@' + socket.gethostname()
+			self.win.addnstr(string, self.wid)
 		except:
+			raise
 			pass
 
 		for path in self.pathway: