commit 89f8218031de2fce3863fe151c26320317ab4656 Author: Damian Johnson atagar@torproject.org Date: Mon Sep 12 09:50:32 2016 -0700
Start Interface class, moving pause methods
Starting a gradual migration of our Controller class into the Interface, rewritting this sucker as we go. Doing this as a Controller subclass so things continue to work as we move. --- nyx/__init__.py | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ nyx/controller.py | 53 ++++------------------------------------- 2 files changed, 75 insertions(+), 49 deletions(-)
diff --git a/nyx/__init__.py b/nyx/__init__.py index 1ffd4b0..268c4ba 100644 --- a/nyx/__init__.py +++ b/nyx/__init__.py @@ -3,11 +3,27 @@
""" Tor curses monitoring application. + +:: + + nyx_interface - nyx interface singleton + tor_controller - tor connection singleton + + init_controller - initializes our connection to tor + expand_path - expands path with respect to our chroot + join - joins a series of strings up to a set length + msg - string from our configuration + + Interface - overall nyx interface + |- is_paused - checks if the interface is paused + |- pause_time - time when the interface was paused + +- set_paused - sets paused state """
import distutils.spawn import os import sys +import time
import stem.connection import stem.control @@ -196,3 +212,58 @@ def msg(message, config, **attr):
stem.util.log.notice(msg) return '' + + +class Interface(object): + """ + Overall state of the nyx interface. + """ + + def __init__(self): + self._paused = False + self._pause_time = None + + def is_paused(self): + """ + Checks if the interface is configured to be paused. + + :returns: **True** if the interface is paused, **False** otherwise + """ + + return self._paused + + def get_pause_time(self): + """ + Provides the time that we were last paused. + + :returns: **float** with the unix timestamp for when we were last paused, + **None** if not paused + """ + + return self._pause_time + + def set_paused(self, is_pause): + """ + Pauses or unpauses the interface. + + :param bool is_pause: suspends the interface if **True**, resumes it + otherwise + """ + + if is_pause != self._paused: + self._paused = is_pause + self._pause_time = time.time() if is_pause else None + + # Couple panels have their own pausing behavior. I'll later change this to + # a listener approach or someting else that's less hacky. + + for panel_impl in self.get_all_panels(): + if isinstance(panel_impl, nyx.panel.graph.GraphPanel) or isinstance(panel_impl, nyx.panel.log.LogPanel): + panel_impl.set_paused(is_pause) + + for panel_impl in self.get_display_panels(): + panel_impl.redraw() + + +import nyx.panel.graph +import nyx.panel.log diff --git a/nyx/controller.py b/nyx/controller.py index 4a3825f..42553b4 100644 --- a/nyx/controller.py +++ b/nyx/controller.py @@ -27,7 +27,7 @@ import stem from stem.util import conf, log
from nyx.curses import BOLD -from nyx import tor_controller +from nyx import Interface, tor_controller
NYX_CONTROLLER = None @@ -87,7 +87,7 @@ def input_prompt(msg, initial_value = ''): return user_input
-class Controller(object): +class Controller(Interface): """ Tracks the global state of the interface """ @@ -98,12 +98,12 @@ class Controller(object): top to bottom on the page. """
+ super(Controller, self).__init__() + self._page_panels = [] self._header_panel = None self.quit_signal = False self._page = 0 - self._paused = False - self._pause_time = -1 self._force_redraw = False self._last_drawn = 0
@@ -134,8 +134,6 @@ class Controller(object):
self.quit_signal = False self._page = 0 - self._paused = False - self._pause_time = -1 self._force_redraw = False self._last_drawn = 0
@@ -184,49 +182,6 @@ class Controller(object):
self.set_page((self._page - 1) % len(self._page_panels))
- def is_paused(self): - """ - Provides if the interface is configured to be paused or not. - - :returns: **True** if the interface is paused and **False** otherwise - """ - - return self._paused - - def set_paused(self, is_pause): - """ - Pauses or unpauses the interface. - - :param bool is_pause: suspends the interface if **True**, resumes it - otherwise - """ - - if is_pause != self._paused: - if is_pause: - self._pause_time = time.time() - - # Couple panels have their own pausing behavior. I'll later change this to - # a listener approach or someting else that's less hacky. - - for panel_impl in self.get_all_panels(): - if isinstance(panel_impl, nyx.panel.graph.GraphPanel) or isinstance(panel_impl, nyx.panel.log.LogPanel): - panel_impl.set_paused(is_pause) - - self._paused = is_pause - - for panel_impl in self.get_display_panels(): - panel_impl.redraw() - - def get_pause_time(self): - """ - Provides the time that we were last paused, returning -1 if we've never - been paused. - - :returns: **float** with the unix timestamp for when we were last paused - """ - - return self._pause_time - def header_panel(self): return self._header_panel