commit af4562df66c5c6d3dc633cedf4368c88f463e8d0 Author: Damian Johnson atagar@torproject.org Date: Tue Sep 13 10:25:19 2016 -0700
Move panel methods
Pretty direct cut-and-paste with the exception of renaming get_display_panels(). --- nyx/__init__.py | 45 +++++++++++++++++++++++++++++++++++++++++++-- nyx/controller.py | 44 +++----------------------------------------- nyx/menu.py | 4 ++-- nyx/popups.py | 2 +- test/popups.py | 2 +- 5 files changed, 50 insertions(+), 47 deletions(-)
diff --git a/nyx/__init__.py b/nyx/__init__.py index c7a9b47..2ca58fe 100644 --- a/nyx/__init__.py +++ b/nyx/__init__.py @@ -19,6 +19,10 @@ Tor curses monitoring application. |- set_page - sets the page we're showing |- page_count - pages within our interface | + |- get_panels - provides all panels + |- get_page_panels - provides panels on a page + |- get_daemon_panels - provides daemon panels + | |- is_paused - checks if the interface is paused +- set_paused - sets paused state """ @@ -260,6 +264,41 @@ class Interface(object):
return len(self._page_panels)
+ def get_panels(self): + """ + Provides all panels in the interface. + + :returns: **list** with panels in the interface + """ + + all_panels = [self._header_panel] + + for page in self._page_panels: + all_panels += list(page) + + return all_panels + + def get_page_panels(self, page_number = None): + """ + Provides panels belonging to a page, ordered top to bottom. + + :param int page_number: page to provide the panels of, current page if + **None** + + :returns: **list** of panels on that page + """ + + return list(self._page_panels[self._page if page_number is None else page_number]) + + def get_daemon_panels(self): + """ + Provides panels that are daemons. + + :returns: **list** of DaemonPanel in the interface + """ + + return [panel for panel in self.get_panels() if isinstance(panel, nyx.panel.DaemonPanel)] + def is_paused(self): """ Checks if the interface is configured to be paused. @@ -280,8 +319,10 @@ class Interface(object): if is_pause != self._paused: self._paused = is_pause
- for panel_impl in self.get_all_panels(): + for panel_impl in self.get_panels(): panel_impl.set_paused(is_pause)
- for panel_impl in self.get_display_panels(): + for panel_impl in self.get_page_panels(): panel_impl.redraw() + +import nyx.panel diff --git a/nyx/controller.py b/nyx/controller.py index 8e1f6f3..63aa13c 100644 --- a/nyx/controller.py +++ b/nyx/controller.py @@ -139,44 +139,6 @@ class Controller(Interface): def header_panel(self): return self._header_panel
- def get_display_panels(self, page_number = None): - """ - Provides all panels belonging to a page and sticky content above it. This - is ordered they way they are presented (top to bottom) on the page. - - Arguments: - page_number - page number of the panels to be returned, the current - page if None - """ - - return_page = self._page if page_number is None else page_number - return list(self._page_panels[return_page]) if self._page_panels else [] - - def get_daemon_panels(self): - """ - Provides thread panels. - """ - - thread_panels = [] - - for panel_impl in self.get_all_panels(): - if isinstance(panel_impl, threading.Thread): - thread_panels.append(panel_impl) - - return thread_panels - - def get_all_panels(self): - """ - Provides all panels in the interface. - """ - - all_panels = [self._header_panel] - - for page in self._page_panels: - all_panels += list(page) - - return all_panels - def redraw(self, force = True): """ Redraws the displayed panel content. @@ -195,7 +157,7 @@ class Controller(Interface): if self._last_drawn + CONFIG['features.refreshRate'] <= current_time: force = True
- display_panels = [self.header_panel()] + self.get_display_panels() + display_panels = [self.header_panel()] + self.get_page_panels()
occupied_content = 0
@@ -274,11 +236,11 @@ def start_nyx(): override_key = None # uses this rather than waiting on user input
while not interface.quit_signal: - display_panels = [interface.header_panel()] + interface.get_display_panels() + display_panels = [interface.header_panel()] + interface.get_page_panels()
# sets panel visability
- for panel_impl in interface.get_all_panels(): + for panel_impl in interface.get_panels(): panel_impl.set_visible(panel_impl in display_panels)
interface.redraw() diff --git a/nyx/menu.py b/nyx/menu.py index 8ebaf4d..ebb8305 100644 --- a/nyx/menu.py +++ b/nyx/menu.py @@ -240,7 +240,7 @@ def _make_menu():
root_menu.add(_view_menu())
- for panel in interface.get_display_panels(): + for panel in interface.get_page_panels(): submenu = panel.submenu()
if submenu: @@ -270,7 +270,7 @@ def _view_menu(): page_group = RadioGroup(interface.set_page, interface.get_page())
for i in range(interface.page_count()): - page_panels = interface.get_display_panels(page_number = i) + page_panels = interface.get_page_panels(page_number = i) label = ' / '.join([type(panel).__name__.replace('Panel', '') for panel in page_panels]) view_menu.add(RadioMenuItem(label, page_group, i))
diff --git a/nyx/popups.py b/nyx/popups.py index 5dd7c05..b52d95d 100644 --- a/nyx/popups.py +++ b/nyx/popups.py @@ -59,7 +59,7 @@ def show_help(): interface = nyx_interface() handlers = []
- for panel in reversed(interface.get_display_panels()): + for panel in reversed(interface.get_page_panels()): handlers += [handler for handler in panel.key_handlers() if handler.description]
def _render(subwindow): diff --git a/test/popups.py b/test/popups.py index 4b12f33..361d15b 100644 --- a/test/popups.py +++ b/test/popups.py @@ -275,7 +275,7 @@ class TestPopups(unittest.TestCase): nyx.panel.KeyHandler('c', 'clear event log'), )
- nyx_interface_mock().get_display_panels.return_value = [header_panel, graph_panel, log_panel] + nyx_interface_mock().get_page_panels.return_value = [header_panel, graph_panel, log_panel]
rendered = test.render(nyx.popups.show_help) self.assertEqual(EXPECTED_HELP_POPUP, rendered.content)
tor-commits@lists.torproject.org