diff options
author | hut <hut@lavabit.com> | 2011-09-29 03:51:20 +0200 |
---|---|---|
committer | hut <hut@lavabit.com> | 2011-09-29 03:51:20 +0200 |
commit | 7b6fab79ff289aa8f11a974d9eea421fa1910ca7 (patch) | |
tree | 616574ffb17357655f8d23fb4d027c7d2534a568 | |
parent | 0f30fdab1baac5ab45a8fafd398f581e463819bb (diff) | |
download | ranger-7b6fab79ff289aa8f11a974d9eea421fa1910ca7.tar.gz |
Merge gui.defaultui into gui.ui
-rw-r--r-- | ranger/core/fm.py | 4 | ||||
-rw-r--r-- | ranger/gui/defaultui.py | 136 | ||||
-rw-r--r-- | ranger/gui/ui.py | 123 |
3 files changed, 117 insertions, 146 deletions
diff --git a/ranger/core/fm.py b/ranger/core/fm.py index fa972b50..341ab4c7 100644 --- a/ranger/core/fm.py +++ b/ranger/core/fm.py @@ -27,7 +27,7 @@ import sys import ranger from ranger.core.actions import Actions from ranger.container.tags import Tags -from ranger.gui.defaultui import DefaultUI +from ranger.gui.ui import UI from ranger.container import Bookmarks from ranger.core.runner import Runner from ranger.ext.get_executables import get_executables @@ -90,7 +90,7 @@ class FM(Actions, SignalDispatcher): self.tags = Tags(self.confpath('tagged')) if self.ui is None: - self.ui = DefaultUI() + self.ui = UI() self.ui.initialize() def mylogfunc(text): diff --git a/ranger/gui/defaultui.py b/ranger/gui/defaultui.py deleted file mode 100644 index 933b56f7..00000000 --- a/ranger/gui/defaultui.py +++ /dev/null @@ -1,136 +0,0 @@ -# Copyright (C) 2009, 2010 Roman Zimbelmann <romanz@lavabit.com> -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. - -from ranger.gui.ui import UI -from ranger.gui.widgets.browserview import BrowserView -from ranger.gui.widgets.titlebar import TitleBar -from ranger.gui.widgets.console import Console -from ranger.gui.widgets.statusbar import StatusBar -from ranger.gui.widgets.taskview import TaskView -from ranger.gui.widgets.pager import Pager - -class DefaultUI(UI): - def setup(self): - """Build up the UI by initializing widgets.""" - # Create a title bar - self.titlebar = TitleBar(self.win) - self.add_child(self.titlebar) - - # Create the browser view - self.browser = BrowserView(self.win, self.settings.column_ratios) - self.settings.signal_bind('setopt.column_ratios', - self.browser.change_ratios) - self.add_child(self.browser) - - # Create the process manager - self.taskview = TaskView(self.win) - self.taskview.visible = False - self.add_child(self.taskview) - - # Create the status bar - self.status = StatusBar(self.win, self.browser.main_column) - self.add_child(self.status) - - # Create the console - self.console = Console(self.win) - self.add_child(self.console) - self.console.visible = False - - # Create the pager - self.pager = Pager(self.win) - self.pager.visible = False - self.add_child(self.pager) - - def update_size(self): - """resize all widgets""" - UI.update_size(self) - y, x = self.env.termsize - - self.browser.resize(1, 0, y - 2, x) - self.taskview.resize(1, 0, y - 2, x) - self.pager.resize(1, 0, y - 2, x) - self.titlebar.resize(0, 0, 1, x) - self.status.resize(y - 1, 0, 1, x) - self.console.resize(y - 1, 0, 1, x) - - def notify(self, *a, **k): - return self.status.notify(*a, **k) - - def close_pager(self): - if self.console.visible: - self.console.focused = True - self.pager.close() - self.pager.visible = False - self.pager.focused = False - self.browser.visible = True - - def open_pager(self): - if self.console.focused: - self.console.focused = False - self.pager.open() - self.pager.visible = True - self.pager.focused = True - self.browser.visible = False - return self.pager - - def open_embedded_pager(self): - self.browser.open_pager() - return self.browser.pager - - def close_embedded_pager(self): - self.browser.close_pager() - - def open_console(self, string='', prompt=None, position=None): - if self.console.open(string, prompt=prompt, position=position): - self.status.msg = None - self.console.on_close = self.close_console - self.console.visible = True - self.status.visible = False - - def close_console(self): - self.console.visible = False - self.status.visible = True - self.close_pager() - - def open_taskview(self): - self.pager.close() - self.pager.visible = False - self.pager.focused = False - self.console.visible = False - self.browser.visible = False - self.taskview.visible = True - self.taskview.focused = True - self.fm.hint('*tasks:* *dd*:remove *J*:move_down *H*:move_up') - - def redraw_main_column(self): - self.browser.main_column.need_redraw = True - - def close_taskview(self): - self.taskview.visible = False - self.browser.visible = True - self.taskview.focused = False - - def scroll(self, relative): - if self.browser and self.browser.main_column: - self.browser.main_column.scroll(relative) - - def throbber(self, string='.', remove=False): - if remove: - self.titlebar.throbber = type(self.titlebar).throbber - else: - self.titlebar.throbber = string - - def hint(self, text=None): - self.status.hint = text diff --git a/ranger/gui/ui.py b/ranger/gui/ui.py index cc2871af..2ace09a3 100644 --- a/ranger/gui/ui.py +++ b/ranger/gui/ui.py @@ -209,11 +209,46 @@ class UI(DisplayableContainer): if not self.fm.input_is_blocked(): self.handle_key(key) + def notify(self, *a, **k): + return self.status.notify(*a, **k) + def setup(self): - """ - Called after an initialize() call. - Override this! - """ + """Build up the UI by initializing widgets.""" + from ranger.gui.widgets.browserview import BrowserView + from ranger.gui.widgets.titlebar import TitleBar + from ranger.gui.widgets.console import Console + from ranger.gui.widgets.statusbar import StatusBar + from ranger.gui.widgets.taskview import TaskView + from ranger.gui.widgets.pager import Pager + + # Create a title bar + self.titlebar = TitleBar(self.win) + self.add_child(self.titlebar) + + # Create the browser view + self.browser = BrowserView(self.win, self.settings.column_ratios) + self.settings.signal_bind('setopt.column_ratios', + self.browser.change_ratios) + self.add_child(self.browser) + + # Create the process manager + self.taskview = TaskView(self.win) + self.taskview.visible = False + self.add_child(self.taskview) + + # Create the status bar + self.status = StatusBar(self.win, self.browser.main_column) + self.add_child(self.status) + + # Create the console + self.console = Console(self.win) + self.add_child(self.console) + self.console.visible = False + + # Create the pager + self.pager = Pager(self.win) + self.pager.visible = False + self.add_child(self.pager) def redraw(self): """Redraw all widgets""" @@ -230,11 +265,16 @@ class UI(DisplayableContainer): self.need_redraw = True def update_size(self): - """ - Update self.env.termsize. - Extend this method to resize all widgets! - """ + """resize all widgets""" self.env.termsize = self.win.getmaxyx() + y, x = self.env.termsize + + self.browser.resize(1, 0, y - 2, x) + self.taskview.resize(1, 0, y - 2, x) + self.pager.resize(1, 0, y - 2, x) + self.titlebar.resize(0, 0, 1, x) + self.status.resize(y - 1, 0, 1, x) + self.console.resize(y - 1, 0, 1, x) def draw(self): """Draw all objects in the container""" @@ -258,3 +298,70 @@ class UI(DisplayableContainer): """Finalize every object in container and refresh the window""" DisplayableContainer.finalize(self) self.win.refresh() + + def close_pager(self): + if self.console.visible: + self.console.focused = True + self.pager.close() + self.pager.visible = False + self.pager.focused = False + self.browser.visible = True + + def open_pager(self): + if self.console.focused: + self.console.focused = False + self.pager.open() + self.pager.visible = True + self.pager.focused = True + self.browser.visible = False + return self.pager + + def open_embedded_pager(self): + self.browser.open_pager() + return self.browser.pager + + def close_embedded_pager(self): + self.browser.close_pager() + + def open_console(self, string='', prompt=None, position=None): + if self.console.open(string, prompt=prompt, position=position): + self.status.msg = None + self.console.on_close = self.close_console + self.console.visible = True + self.status.visible = False + + def close_console(self): + self.console.visible = False + self.status.visible = True + self.close_pager() + + def open_taskview(self): + self.pager.close() + self.pager.visible = False + self.pager.focused = False + self.console.visible = False + self.browser.visible = False + self.taskview.visible = True + self.taskview.focused = True + self.fm.hint('*tasks:* *dd*:remove *J*:move_down *H*:move_up') + + def redraw_main_column(self): + self.browser.main_column.need_redraw = True + + def close_taskview(self): + self.taskview.visible = False + self.browser.visible = True + self.taskview.focused = False + + def scroll(self, relative): + if self.browser and self.browser.main_column: + self.browser.main_column.scroll(relative) + + def throbber(self, string='.', remove=False): + if remove: + self.titlebar.throbber = type(self.titlebar).throbber + else: + self.titlebar.throbber = string + + def hint(self, text=None): + self.status.hint = text |