diff options
author | hut <hut@lavabit.com> | 2009-11-29 23:11:26 +0100 |
---|---|---|
committer | hut <hut@lavabit.com> | 2009-11-29 23:11:26 +0100 |
commit | ae943ecbc21969937b13ac70ab71facc61271a6f (patch) | |
tree | 3fa65ed9aaf656c1d5b7ad8e6ce6bd007578c7d9 /ranger | |
parent | 5805deca6306eb888ebdad64c14119995521c6b8 (diff) | |
download | ranger-ae943ecbc21969937b13ac70ab71facc61271a6f.tar.gz |
mouse support
Diffstat (limited to 'ranger')
-rw-r--r-- | ranger/conf/keys.py | 14 | ||||
-rw-r--r-- | ranger/fm.py | 3 | ||||
-rw-r--r-- | ranger/fsobject.py | 3 | ||||
-rw-r--r-- | ranger/gui/colorscheme.py | 6 | ||||
-rw-r--r-- | ranger/gui/ui.py | 46 | ||||
-rw-r--r-- | ranger/gui/wdisplay.py | 26 | ||||
-rw-r--r-- | ranger/gui/widget.py | 2 | ||||
-rw-r--r-- | ranger/gui/wtitlebar.py | 7 |
8 files changed, 91 insertions, 16 deletions
diff --git a/ranger/conf/keys.py b/ranger/conf/keys.py index 54e2ba0d..3d5fa856 100644 --- a/ranger/conf/keys.py +++ b/ranger/conf/keys.py @@ -7,7 +7,7 @@ def initialize_commands(cl): # fnc is a function which is called with the FM instance, # keys are one or more key-combinations which are either: # * a string - # * an integer which represents an ascii value + # * an integer which represents an ascii code # * a tuple of integers def move(relative = 0, absolute = None): @@ -33,7 +33,10 @@ def initialize_commands(cl): cl.bind(move( absolute = -1 ), 'G') cl.bind(FM.edit_file, 'E') + # toggle options cl.bind(toggle_option('show_hidden'), 'th') + cl.bind(toggle_option('preview_files'), 'tp') + cl.bind(toggle_option('directories_first'), 'td') # key combinations which change the current directory cl.bind(cd("~"), 'gh') @@ -46,10 +49,11 @@ def initialize_commands(cl): cl.bind(cd("/srv"), 'gs') # system functions - cl.bind(FM.exit, ctrl('D'), 'q', 'ZZ') - cl.bind(FM.reset, ctrl('R')) - cl.bind(FM.redraw, ctrl('L')) - cl.bind(FM.resize, curses.KEY_RESIZE) + cl.bind(FM.exit, ctrl('D'), 'q', 'ZZ') + cl.bind(FM.reset, ctrl('R')) + cl.bind(FM.redraw, ctrl('L')) + cl.bind(FM.resize, curses.KEY_RESIZE) + cl.bind(FM.handle_mouse, curses.KEY_MOUSE) cl.rebuild_paths() diff --git a/ranger/fm.py b/ranger/fm.py index b8df319c..02cf1300 100644 --- a/ranger/fm.py +++ b/ranger/fm.py @@ -42,6 +42,9 @@ class FM(): self.execute_file(path) except AttributeError: pass + + def handle_mouse(self): + self.ui.handle_mouse(self) def execute_file(self, path): from subprocess import Popen diff --git a/ranger/fsobject.py b/ranger/fsobject.py index 081c22be..485f5165 100644 --- a/ranger/fsobject.py +++ b/ranger/fsobject.py @@ -14,10 +14,11 @@ class FileSystemObject(object): if type(self) == FileSystemObject: raise TypeError("FileSystemObject is an abstract class and cannot be initialized.") - from os.path import basename + from os.path import basename, dirname self.path = path self.basename = basename(path) + self.dirname = dirname(path) self.exists = False self.accessible = False self.marked = False 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: |