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

[tor-commits] [nyx/master] Drop legacy draw method



commit 0f7339404ba391a26047ddc3fe0272812e84a3cf
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Wed Jul 13 09:04:15 2016 -0700

    Drop legacy draw method
    
    Now that all our panels use the new draw() function the other condition is dead
    code. This in turns means we can drop the force flag since it's unused.
---
 nyx/controller.py       |  6 ++---
 nyx/panel/__init__.py   | 59 ++++++-------------------------------------------
 nyx/panel/config.py     |  8 +++----
 nyx/panel/connection.py |  8 +++----
 nyx/panel/graph.py      |  8 +++----
 nyx/panel/header.py     |  4 ++--
 nyx/panel/log.py        | 12 +++++-----
 nyx/panel/torrc.py      |  8 +++----
 8 files changed, 34 insertions(+), 79 deletions(-)

diff --git a/nyx/controller.py b/nyx/controller.py
index 1957770..964e27d 100644
--- a/nyx/controller.py
+++ b/nyx/controller.py
@@ -153,7 +153,7 @@ class Controller(object):
     if page_number != self._page:
       self._page = page_number
       self._force_redraw = True
-      self.header_panel().redraw(True)
+      self.header_panel().redraw()
 
   def next_page(self):
     """
@@ -184,7 +184,7 @@ class Controller(object):
     if is_pause != self._is_paused:
       self._is_paused = is_pause
       self._force_redraw = True
-      self.header_panel().redraw(True)
+      self.header_panel().redraw()
 
       for panel_impl in self.get_all_panels():
         panel_impl.set_paused(is_pause)
@@ -265,7 +265,7 @@ class Controller(object):
         stdscr.clear()
 
     for panel_impl in display_panels:
-      panel_impl.redraw(force)
+      panel_impl.redraw()
 
     if force:
       self._last_drawn = current_time
diff --git a/nyx/panel/__init__.py b/nyx/panel/__init__.py
index 313f264..06af3e1 100644
--- a/nyx/panel/__init__.py
+++ b/nyx/panel/__init__.py
@@ -172,7 +172,7 @@ class Panel(object):
         self.pause_time = time.time()
 
       self.paused = is_pause
-      self.redraw(True)
+      self.redraw()
 
   def get_pause_time(self):
     """
@@ -238,7 +238,7 @@ class Panel(object):
 
     return ()
 
-  def draw(self, width, height):
+  def draw(self, subwindow):
     """
     Draws display's content. This is meant to be overwritten by
     implementations and not called directly (use redraw() instead). The
@@ -246,19 +246,15 @@ class Panel(object):
     a column less than the actual space.
 
     Arguments:
-      width  - horizontal space available for content
-      height - vertical space available for content
+      subwindow - window content is drawn into
     """
 
     pass
 
-  def redraw(self, force_redraw=False):
+  def redraw(self):
     """
     Clears display and redraws its content. This can skip redrawing content if
     able (ie, the subwindow's unchanged), instead just refreshing the display.
-
-    Arguments:
-      force_redraw - forces the content to be cleared and redrawn if true
     """
 
     # skipped if not currently visible or activity has been halted
@@ -266,51 +262,10 @@ class Panel(object):
     if not self.visible or HALT_ACTIVITY:
       return
 
-    if self.panel_name in ('header', 'graph', 'log', 'connections', 'configuration', 'torrc'):
-      height = self.get_height() if self.get_height() != -1 else None
-      width = self.get_width() if self.get_width() != -1 else None
-
-      nyx.curses.draw(self.draw, top = self.top, width = width, height = height)
-      return
-
-    # if the panel's completely outside its parent then this is a no-op
-
-    new_height, new_width = self.get_preferred_size()
-
-    if new_height == 0 or new_width == 0:
-      self.win = None
-      return
-
-    # recreates the subwindow if necessary
-
-    is_new_window = self._reset_subwindow()
-
-    if not self.win:
-      return
-
-    # The reset argument is disregarded in a couple of situations:
-    # - The subwindow's been recreated (obviously it then doesn't have the old
-    #   content to refresh).
-    # - The subwindow's dimensions have changed since last drawn (this will
-    #   likely change the content's layout)
-
-    subwin_max_y, subwin_max_x = self.win.getmaxyx()
-
-    if is_new_window or subwin_max_y != self.max_y or subwin_max_x != self.max_x:
-      force_redraw = True
-
-    self.max_y, self.max_x = subwin_max_y, subwin_max_x
-
-    if not nyx.curses.CURSES_LOCK.acquire(False):
-      return
+    height = self.get_height() if self.get_height() != -1 else None
+    width = self.get_width() if self.get_width() != -1 else None
 
-    try:
-      if force_redraw:
-        self.win.erase()  # clears any old contents
-        self.draw(self.max_x, self.max_y)
-      self.win.refresh()
-    finally:
-      nyx.curses.CURSES_LOCK.release()
+    nyx.curses.draw(self.draw, top = self.top, width = width, height = height)
 
   def hline(self, y, x, length, *attributes):
     """
diff --git a/nyx/panel/config.py b/nyx/panel/config.py
index f3e747a..14e73ac 100644
--- a/nyx/panel/config.py
+++ b/nyx/panel/config.py
@@ -196,7 +196,7 @@ class ConfigPanel(nyx.panel.Panel):
       except IOError as exc:
         nyx.controller.show_message('Unable to save configuration (%s)' % exc.strerror, HIGHLIGHT, max_wait = 2)
 
-    self.redraw(True)
+    self.redraw()
 
   def key_handlers(self):
     def _scroll(key):
@@ -204,7 +204,7 @@ class ConfigPanel(nyx.panel.Panel):
       is_changed = self._scroller.handle_key(key, self._get_config_options(), page_height)
 
       if is_changed:
-        self.redraw(True)
+        self.redraw()
 
     def _edit_selected_value():
       selected = self._scroller.selection(self._get_config_options())
@@ -224,13 +224,13 @@ class ConfigPanel(nyx.panel.Panel):
             new_value = new_value.split(',')  # set_conf accepts list inputs
 
           tor_controller().set_conf(selected.name, new_value)
-          self.redraw(True)
+          self.redraw()
         except Exception as exc:
           nyx.controller.show_message('%s (press any key)' % exc, HIGHLIGHT, max_wait = 30)
 
     def _toggle_show_all():
       self._show_all = not self._show_all
-      self.redraw(True)
+      self.redraw()
 
     return (
       nyx.panel.KeyHandler('arrows', 'scroll up and down', _scroll, key_func = lambda key: key.is_scroll()),
diff --git a/nyx/panel/connection.py b/nyx/panel/connection.py
index 3163b5d..2facd55 100644
--- a/nyx/panel/connection.py
+++ b/nyx/panel/connection.py
@@ -322,11 +322,11 @@ class ConnectionPanel(nyx.panel.DaemonPanel):
       is_changed = self._scroller.handle_key(key, lines, page_height)
 
       if is_changed:
-        self.redraw(True)
+        self.redraw()
 
     def _show_details():
       self._show_details = not self._show_details
-      self.redraw(True)
+      self.redraw()
 
     def _show_descriptor():
       entries = self._entries
@@ -351,7 +351,7 @@ class ConnectionPanel(nyx.panel.DaemonPanel):
         elif key.match('right'):
           _scroll(nyx.curses.KeyInput(curses.KEY_DOWN))
 
-      self.redraw(True)
+      self.redraw()
 
     def _pick_connection_resolver():
       connection_tracker = nyx.tracker.get_connection_tracker()
@@ -361,7 +361,7 @@ class ConnectionPanel(nyx.panel.DaemonPanel):
       selected = nyx.popups.select_from_list('Connection Resolver:', options, resolver if resolver else 'auto')
       connection_tracker.set_custom_resolver(None if selected == 'auto' else selected)
 
-      self.redraw(True)
+      self.redraw()
 
     def _show_client_locales():
       nyx.popups.show_counts('Client Locales', self._client_locale_usage)
diff --git a/nyx/panel/graph.py b/nyx/panel/graph.py
index 1043339..5869dff 100644
--- a/nyx/panel/graph.py
+++ b/nyx/panel/graph.py
@@ -435,7 +435,7 @@ class GraphPanel(nyx.panel.Panel):
     controller = tor_controller()
     controller.add_event_listener(self._update_accounting, EventType.BW)
     controller.add_event_listener(self._update_stats, EventType.BW)
-    controller.add_status_listener(lambda *args: self.redraw(True))
+    controller.add_status_listener(lambda *args: self.redraw())
 
   @property
   def displayed_stat(self):
@@ -538,11 +538,11 @@ class GraphPanel(nyx.panel.Panel):
 
     def _next_bounds():
       self.bounds_type = Bounds.next(self.bounds_type)
-      self.redraw(True)
+      self.redraw()
 
     def _pick_interval():
       self.update_interval = nyx.popups.select_from_list('Update Interval:', list(Interval), self.update_interval)
-      self.redraw(True)
+      self.redraw()
 
     return (
       nyx.panel.KeyHandler('g', 'resize graph', self.resize_graph),
@@ -605,7 +605,7 @@ class GraphPanel(nyx.panel.Panel):
       update_rate = INTERVAL_SECONDS[self.update_interval]
 
       if param.primary.tick % update_rate == 0:
-        self.redraw(True)
+        self.redraw()
 
 
 def _draw_subgraph(subwindow, data, x, width, height, bounds_type, interval, color, fill_char = ' '):
diff --git a/nyx/panel/header.py b/nyx/panel/header.py
index d470ba1..231ff1b 100644
--- a/nyx/panel/header.py
+++ b/nyx/panel/header.py
@@ -70,7 +70,7 @@ class HeaderPanel(nyx.panel.DaemonPanel):
 
     self._message = message
     self._message_attr = attr
-    self.redraw(True)
+    self.redraw()
 
     if 'max_wait' in kwargs:
       user_input = nyx.curses.key_input(kwargs['max_wait'])
@@ -205,7 +205,7 @@ class HeaderPanel(nyx.panel.DaemonPanel):
         self._reported_inactive = False
         log.notice('Relay resumed')
 
-    self.redraw(True)
+    self.redraw()
 
 
 class Sampling(object):
diff --git a/nyx/panel/log.py b/nyx/panel/log.py
index 5d4c36e..355e52c 100644
--- a/nyx/panel/log.py
+++ b/nyx/panel/log.py
@@ -148,7 +148,7 @@ class LogPanel(nyx.panel.DaemonPanel):
 
     if event_types and event_types != self._event_types:
       self._event_types = nyx.log.listen_for_events(self._register_tor_event, event_types)
-      self.redraw(True)
+      self.redraw()
 
   def show_snapshot_prompt(self):
     """
@@ -170,7 +170,7 @@ class LogPanel(nyx.panel.DaemonPanel):
     """
 
     self._event_log = nyx.log.LogGroup(CONFIG['cache.log_panel.size'], group_by_day = True)
-    self.redraw(True)
+    self.redraw()
 
   def save_snapshot(self, path):
     """
@@ -211,7 +211,7 @@ class LogPanel(nyx.panel.DaemonPanel):
       is_changed = self._scroller.handle_key(key, self._last_content_height, page_height)
 
       if is_changed:
-        self.redraw(True)
+        self.redraw()
 
     def _pick_filter():
       with nyx.curses.CURSES_LOCK:
@@ -228,7 +228,7 @@ class LogPanel(nyx.panel.DaemonPanel):
 
     def _toggle_deduplication():
       self.set_duplicate_visability(not self._show_duplicates)
-      self.redraw(True)
+      self.redraw()
 
     def _clear_log():
       msg = 'This will clear the log. Are you sure (c again to confirm)?'
@@ -300,7 +300,7 @@ class LogPanel(nyx.panel.DaemonPanel):
 
     if force_redraw:
       log.debug('redrawing the log panel with the corrected content height (%s)' % force_redraw_reason)
-      self.redraw(True)
+      self.redraw()
 
   def _update(self):
     """
@@ -313,7 +313,7 @@ class LogPanel(nyx.panel.DaemonPanel):
 
     if self._has_new_event or self._last_day != current_day:
       self._last_day = current_day
-      self.redraw(True)
+      self.redraw()
 
   def _register_tor_event(self, event):
     msg = ' '.join(str(event).split(' ')[1:])
diff --git a/nyx/panel/torrc.py b/nyx/panel/torrc.py
index 868e546..e9f4ee2 100644
--- a/nyx/panel/torrc.py
+++ b/nyx/panel/torrc.py
@@ -76,7 +76,7 @@ class TorrcPanel(panel.Panel):
     """
 
     self._show_comments = is_visible
-    self.redraw(True)
+    self.redraw()
 
   def set_line_number_visible(self, is_visible):
     """
@@ -86,7 +86,7 @@ class TorrcPanel(panel.Panel):
     """
 
     self._show_line_numbers = is_visible
-    self.redraw(True)
+    self.redraw()
 
   def key_handlers(self):
     def _scroll(key):
@@ -94,7 +94,7 @@ class TorrcPanel(panel.Panel):
       is_changed = self._scroller.handle_key(key, self._last_content_height, page_height)
 
       if is_changed:
-        self.redraw(True)
+        self.redraw()
 
     def _toggle_comment_stripping():
       self.set_comments_visible(not self._show_comments)
@@ -175,4 +175,4 @@ class TorrcPanel(panel.Panel):
 
     if self._last_content_height != new_content_height:
       self._last_content_height = new_content_height
-      self.draw(subwindow)
+      self.redraw()



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