[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [nyx/master] Move redraw method



commit 66e34c28ca1c02a526c4a427e37955d25a3487cc
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Thu Sep 15 10:10:28 2016 -0700

    Move redraw method
    
    Moving our redraw() method to the Interface with a couple simplifications...
    
    * The only time we ever call a panel's set_height() is for rendering, so that
      might as well just be a render() argument.
    
    * Since we started doing forced rendering by default 'features.refreshRate'
      and self._force_redraw are no longer doing anything. We may go back to this
      in the future but for now might as well just drop them it.
---
 nyx/__init__.py       | 22 +++++++++++++++++++++-
 nyx/controller.py     | 48 ------------------------------------------------
 nyx/panel/__init__.py | 16 +++++-----------
 nyxrc.sample          |  5 -----
 4 files changed, 26 insertions(+), 65 deletions(-)

diff --git a/nyx/__init__.py b/nyx/__init__.py
index c5e24c1..91225b8 100644
--- a/nyx/__init__.py
+++ b/nyx/__init__.py
@@ -26,6 +26,7 @@ Tor curses monitoring application.
     |- is_paused - checks if the interface is paused
     |- set_paused - sets paused state
     |
+    |- redraw - renders our content
     |- quit - quits our application
     +- halt - stops daemon panels
 """
@@ -257,7 +258,6 @@ class Interface(object):
 
     if page_number != self._page:
       self._page = page_number
-      self._force_redraw = True
       self.header_panel().redraw()
 
   def page_count(self):
@@ -330,6 +330,26 @@ class Interface(object):
       for panel_impl in self.get_page_panels():
         panel_impl.redraw()
 
+  def redraw(self, force = True):
+    """
+    Renders our displayed content.
+
+    :param bool force: if **False** only redraws content if resized
+    """
+
+    # Curses may overly cache content without clearing here...
+    # https://trac.torproject.org/projects/tor/ticket/2830#comment:9
+
+    if force:
+      with nyx.curses.raw_screen() as stdscr:
+        stdscr.clear()
+
+    occupied = 0
+
+    for panel in [self.header_panel()] + self.get_page_panels():
+      panel.redraw(force = force, top = occupied)
+      occupied += panel.get_height()
+
   def quit(self):
     """
     Quits our application.
diff --git a/nyx/controller.py b/nyx/controller.py
index 7358383..6dd1b09 100644
--- a/nyx/controller.py
+++ b/nyx/controller.py
@@ -35,8 +35,6 @@ NYX_CONTROLLER = None
 def conf_handler(key, value):
   if key == 'features.redrawRate':
     return max(1, value)
-  elif key == 'features.refreshRate':
-    return max(0, value)
 
 
 CONFIG = conf.config_dict('nyx', {
@@ -48,7 +46,6 @@ CONFIG = conf.config_dict('nyx', {
   'features.panels.show.torrc': True,
   'features.panels.show.interpreter': True,
   'features.redrawRate': 5,
-  'features.refreshRate': 5,
   'features.confirmQuit': True,
   'start_time': 0,
 }, conf_handler)
@@ -105,8 +102,6 @@ class Controller(Interface):
 
     self._page_panels = []
     self._header_panel = None
-    self._force_redraw = False
-    self._last_drawn = 0
 
     NYX_CONTROLLER = self
 
@@ -137,49 +132,6 @@ class Controller(Interface):
   def header_panel(self):
     return self._header_panel
 
-  def redraw(self, force = True):
-    """
-    Redraws the displayed panel content.
-
-    Arguments:
-      force - redraws regardless of if it's needed if true, otherwise ignores
-              the request when there aren't changes to be displayed
-    """
-
-    force |= self._force_redraw
-    self._force_redraw = False
-
-    current_time = time.time()
-
-    if CONFIG['features.refreshRate'] != 0:
-      if self._last_drawn + CONFIG['features.refreshRate'] <= current_time:
-        force = True
-
-    display_panels = [self.header_panel()] + self.get_page_panels()
-
-    occupied_content = 0
-
-    for panel_impl in display_panels:
-      panel_impl.set_top(occupied_content)
-      height = panel_impl.get_height()
-
-      if height:
-        occupied_content += height
-
-    # apparently curses may cache display contents unless we explicitely
-    # request a redraw here...
-    # https://trac.torproject.org/projects/tor/ticket/2830#comment:9
-
-    if force:
-      with nyx.curses.raw_screen() as stdscr:
-        stdscr.clear()
-
-    for panel_impl in display_panels:
-      panel_impl.redraw(force = force)
-
-    if force:
-      self._last_drawn = current_time
-
 
 def start_nyx():
   """
diff --git a/nyx/panel/__init__.py b/nyx/panel/__init__.py
index 49c7e22..24ffadf 100644
--- a/nyx/panel/__init__.py
+++ b/nyx/panel/__init__.py
@@ -17,7 +17,6 @@ Panels consisting the nyx interface.
     |  +- stop - stops triggering daemon actions
     |
     |- get_top - top position we're rendered into on the screen
-    |- set_top - sets top position within the screen
     |- get_height - height occupied by the panel
     |
     |- set_visible - toggles panel visiblity
@@ -107,15 +106,6 @@ class Panel(object):
 
     return self._top
 
-  def set_top(self, top):
-    """
-    Changes the position where we're rendered in the screen.
-
-    :param int top: top position within the sceen
-    """
-
-    self._top = top
-
   def get_height(self):
     """
     Provides the height occupied by this panel.
@@ -162,14 +152,18 @@ class Panel(object):
 
     return None
 
-  def redraw(self, force = True):
+  def redraw(self, force = True, top = None):
     """
     Renders our panel's content to the screen.
 
     :param bool force: if **False** only redraws content if the panel's
       dimensions have changed
+    :param int top: position to render relative to the top of the screen
     """
 
+    if top:
+      self._top = top
+
     if not self._visible:
       return  # not currently visible
 
diff --git a/nyxrc.sample b/nyxrc.sample
index 7bb300c..c9ff604 100644
--- a/nyxrc.sample
+++ b/nyxrc.sample
@@ -45,11 +45,6 @@ features.logFile
 # Seconds to wait on user input before refreshing content
 features.redrawRate 5
 
-# Rate (seconds) to periodically redraw the screen, disabled if zero. This
-# shouldn't be necessary, but can correct issues if the terminal gets into a
-# funky state.
-features.refreshRate 5
-
 # Confirms promt to confirm when quiting if true
 features.confirmQuit true
 



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits