From e01ea6523445c49fe440ebceeaeed1293f268b5f Mon Sep 17 00:00:00 2001 From: hut Date: Thu, 8 Apr 2010 17:40:51 +0200 Subject: added option 'mouse_enabled' --- ranger/defaults/options.py | 3 +++ ranger/gui/ui.py | 33 +++++++++++++++++++++------------ ranger/shared/settings.py | 1 + 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/ranger/defaults/options.py b/ranger/defaults/options.py index 6b2a0dc9..d96955b7 100644 --- a/ranger/defaults/options.py +++ b/ranger/defaults/options.py @@ -61,6 +61,9 @@ draw_bookmark_borders = True # How many columns are there, and what are their relative widths? column_ratios = (1, 1, 4, 3) +# Enable the mouse support? +mouse_enabled = True + # Display the file size in the main column or status bar? display_size_in_main_column = True display_size_in_status_bar = False diff --git a/ranger/gui/ui.py b/ranger/gui/ui.py index 68285718..cdaf6cde 100644 --- a/ranger/gui/ui.py +++ b/ranger/gui/ui.py @@ -27,9 +27,25 @@ TERMINALS_WITH_TITLE = ("xterm", "xterm-256color", "rxvt", "rxvt-256color", "rxvt-unicode", "aterm", "Eterm", "screen", "screen-256color") +MOUSEMASK = curses.ALL_MOUSE_EVENTS | curses.REPORT_MOUSE_POSITION + +def _setup_mouse(signal): + if signal['value']: + curses.mousemask(MOUSEMASK) + curses.mouseinterval(0) + + ## this line solves this problem: + ## If an action, following a mouse click, includes the + ## suspension and re-initializion of the ui (e.g. running a + ## file by clicking on its preview) and the next key is another + ## mouse click, the bstate of this mouse event will be invalid. + ## (atm, invalid bstates are recognized as scroll-down) + curses.ungetmouse(0,0,0,0,0) + else: + curses.mousemask(0) + class UI(DisplayableContainer): is_set_up = False - mousemask = curses.ALL_MOUSE_EVENTS | curses.REPORT_MOUSE_POSITION load_mode = False def __init__(self, commandlist=None, env=None, fm=None): self._draw_title = os.environ["TERM"] in TERMINALS_WITH_TITLE @@ -66,16 +82,8 @@ class UI(DisplayableContainer): curses.start_color() curses.use_default_colors() - curses.mousemask(self.mousemask) - curses.mouseinterval(0) - - ## this line solves this problem: - ## If an action, following a mouse click, includes the - ## suspension and re-initializion of the ui (e.g. running a - ## file by clicking on its preview) and the next key is another - ## mouse click, the bstate of this mouse event will be invalid. - ## (atm, invalid bstates are recognized as scroll-down) - curses.ungetmouse(0,0,0,0,0) + self.settings.signal_bind('setopt.mouse_enabled', _setup_mouse) + _setup_mouse(dict(value=self.settings.mouse_enabled)) if not self.is_set_up: self.is_set_up = True @@ -91,7 +99,8 @@ class UI(DisplayableContainer): curses.curs_set(1) except: pass - curses.mousemask(0) + if self.settings.mouse_enabled: + _setup_mouse(dict(value=False)) curses.endwin() def set_load_mode(self, boolean): diff --git a/ranger/shared/settings.py b/ranger/shared/settings.py index a4a58e6e..6933957a 100644 --- a/ranger/shared/settings.py +++ b/ranger/shared/settings.py @@ -39,6 +39,7 @@ ALLOWED_SETTINGS = { 'scroll_offset': int, 'preview_files': bool, 'preview_directories': bool, + 'mouse_enabled': bool, 'flushinput': bool, 'colorscheme': str, 'colorscheme_overlay': (type(None), type(lambda:0)), -- cgit 1.4.1-2-gfad0 From e4e9ef4a93eb8d95f29848b2447968c6b9eef129 Mon Sep 17 00:00:00 2001 From: hut Date: Thu, 8 Apr 2010 18:09:56 +0200 Subject: Fixed multiple signal bindings of the same function --- ranger/shared/settings.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ranger/shared/settings.py b/ranger/shared/settings.py index 6933957a..c533205b 100644 --- a/ranger/shared/settings.py +++ b/ranger/shared/settings.py @@ -58,6 +58,9 @@ class SettingObject(SignalDispatcher): SignalDispatcher.__init__(self) self.__dict__['_settings'] = dict() self.__dict__['_setting_sources'] = list() + for name in ALLOWED_SETTINGS: + self.signal_bind('setopt.'+name, + self._raw_set_with_signal, priority=0.2) def __setattr__(self, name, value): if name[0] == '_': @@ -67,8 +70,6 @@ class SettingObject(SignalDispatcher): assert self._check_type(name, value) kws = dict(setting=name, value=value, previous=self._settings[name]) - self.signal_bind('setopt.'+name, - self._raw_set_with_signal, priority=0.2) self.signal_emit('setopt', **kws) self.signal_emit('setopt.'+name, **kws) -- cgit 1.4.1-2-gfad0 From 1c09037cb7484bdd101c07f8373e2ea6fc9f91fd Mon Sep 17 00:00:00 2001 From: hut Date: Thu, 8 Apr 2010 18:10:33 +0200 Subject: shared.settings: allow to iterate over settings --- ranger/shared/settings.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ranger/shared/settings.py b/ranger/shared/settings.py index c533205b..9a8a0000 100644 --- a/ranger/shared/settings.py +++ b/ranger/shared/settings.py @@ -91,6 +91,10 @@ class SettingObject(SignalDispatcher): self.__setattr__(name, value) return self._settings[name] + def __iter__(self): + for x in self._settings: + yield x + def _check_type(self, name, value): from inspect import isfunction typ = ALLOWED_SETTINGS[name] -- cgit 1.4.1-2-gfad0 From e8faa101b6e59239e5bea2d52eba7b1d2ed707b0 Mon Sep 17 00:00:00 2001 From: hut Date: Thu, 8 Apr 2010 18:49:34 +0200 Subject: added :set = command --- ranger/defaults/commands.py | 33 +++++++++++++++++++++++++++++++++ ranger/ext/command_parser.py | 16 ++++++++++++++++ ranger/shared/settings.py | 12 ++++++++++++ 3 files changed, 61 insertions(+) diff --git a/ranger/defaults/commands.py b/ranger/defaults/commands.py index c0e1ccf1..c364fda0 100644 --- a/ranger/defaults/commands.py +++ b/ranger/defaults/commands.py @@ -236,6 +236,39 @@ class find(Command): return self.count == 1 +class set(Command): + """ + :set