[tor-commits] [nyx/master] Combine get_height() and get_preferred_size()

atagar at torproject.org atagar at torproject.org
Fri Jul 15 17:33:39 UTC 2016


commit f777422689c02f289b65a2bfd8629fed5d09cbb4
Author: Damian Johnson <atagar at torproject.org>
Date:   Fri Jul 15 09:59:35 2016 -0700

    Combine get_height() and get_preferred_size()
    
    Our get_height() provided our maximum height while get_preferred_size()
    provided our actual dimensions. On reflection both of these were dumb...
    
      * We never care about our maximum height except to calculate our real
        dimensions.
    
      * We never care about our width so get_preferred_size() was really just
        providing our height.
    
    So combining these into a single get_height() method that provides our actual
    height. Much simpler.
---
 nyx/panel/__init__.py   | 26 ++------------------------
 nyx/panel/config.py     |  2 +-
 nyx/panel/connection.py |  2 +-
 nyx/panel/graph.py      |  4 +++-
 nyx/panel/header.py     |  6 ++++--
 nyx/panel/log.py        |  2 +-
 nyx/panel/torrc.py      |  2 +-
 7 files changed, 13 insertions(+), 31 deletions(-)

diff --git a/nyx/panel/__init__.py b/nyx/panel/__init__.py
index bfc4e6c..85d1b78 100644
--- a/nyx/panel/__init__.py
+++ b/nyx/panel/__init__.py
@@ -22,7 +22,6 @@ Panels consisting the nyx interface.
     |
     |- set_visible - toggles panel visiblity
     |- key_handlers - keyboard input accepted by the panel
-    |- get_preferred_size - dimensions when rendered
     +- redraw - renders the panel content
 """
 
@@ -113,10 +112,10 @@ class Panel(object):
     """
     Provides the height occupied by this panel.
 
-    :returns: **int** for the height of the panel or **None** if unlimited
+    :returns: **int** for the height of the panel
     """
 
-    return None
+    return max(0, nyx.curses.screen_size().height - self._top)
 
   def set_visible(self, is_visible):
     """
@@ -136,27 +135,6 @@ class Panel(object):
 
     return ()
 
-  def get_preferred_size(self):
-    """
-    Provides the dimensions the subwindow would use when next redrawn if none
-    of its properties change.
-
-    :returns: **tuple** of the form **(height, width)**
-    """
-
-    with nyx.curses.raw_screen() as stdscr:
-      new_height, new_width = stdscr.getmaxyx()
-
-    new_height = max(0, new_height - self._top)
-    new_width = max(0, new_width)
-
-    set_height = self.get_height()
-
-    if set_height is not None:
-      new_height = min(new_height, set_height)
-
-    return (new_height, new_width)
-
   def redraw(self):
     """
     Renders our panel's content to the screen.
diff --git a/nyx/panel/config.py b/nyx/panel/config.py
index f5d9dd9..7640b99 100644
--- a/nyx/panel/config.py
+++ b/nyx/panel/config.py
@@ -200,7 +200,7 @@ class ConfigPanel(nyx.panel.Panel):
 
   def key_handlers(self):
     def _scroll(key):
-      page_height = self.get_preferred_size()[0] - DETAILS_HEIGHT
+      page_height = self.get_height() - DETAILS_HEIGHT
       is_changed = self._scroller.handle_key(key, self._get_config_options(), page_height)
 
       if is_changed:
diff --git a/nyx/panel/connection.py b/nyx/panel/connection.py
index 497df5c..cac6490 100644
--- a/nyx/panel/connection.py
+++ b/nyx/panel/connection.py
@@ -314,7 +314,7 @@ class ConnectionPanel(nyx.panel.DaemonPanel):
 
   def key_handlers(self):
     def _scroll(key):
-      page_height = self.get_preferred_size()[0] - 1
+      page_height = self.get_height() - 1
 
       if self._show_details:
         page_height -= (DETAILS_HEIGHT + 1)
diff --git a/nyx/panel/graph.py b/nyx/panel/graph.py
index 4a4e125..9dd3244 100644
--- a/nyx/panel/graph.py
+++ b/nyx/panel/graph.py
@@ -478,6 +478,8 @@ class GraphPanel(nyx.panel.Panel):
     Provides the height of the content.
     """
 
+    max_height = nyx.panel.Panel.get_height(self)
+
     if not self.displayed_stat:
       return 0
 
@@ -488,7 +490,7 @@ class GraphPanel(nyx.panel.Panel):
     if self.displayed_stat == GraphStat.BANDWIDTH and accounting_stats:
       height += 3
 
-    return height
+    return min(max_height, height)
 
   def set_graph_height(self, new_graph_height):
     self._graph_height = max(1, new_graph_height)
diff --git a/nyx/panel/header.py b/nyx/panel/header.py
index 31f9970..f08afd7 100644
--- a/nyx/panel/header.py
+++ b/nyx/panel/header.py
@@ -90,10 +90,12 @@ class HeaderPanel(nyx.panel.DaemonPanel):
     panel's maximum width.
     """
 
+    max_height = nyx.panel.DaemonPanel.get_height(self)
+
     if self._vals.is_relay:
-      return 5 if self.is_wide() else 7
+      return min(max_height, 5 if self.is_wide() else 7)
     else:
-      return 4 if self.is_wide() else 5
+      return min(max_height, 4 if self.is_wide() else 5)
 
   def send_newnym(self):
     """
diff --git a/nyx/panel/log.py b/nyx/panel/log.py
index 2eac0b5..0437e0f 100644
--- a/nyx/panel/log.py
+++ b/nyx/panel/log.py
@@ -207,7 +207,7 @@ class LogPanel(nyx.panel.DaemonPanel):
 
   def key_handlers(self):
     def _scroll(key):
-      page_height = self.get_preferred_size()[0] - 1
+      page_height = self.get_height() - 1
       is_changed = self._scroller.handle_key(key, self._last_content_height, page_height)
 
       if is_changed:
diff --git a/nyx/panel/torrc.py b/nyx/panel/torrc.py
index dfe331d..3682f7f 100644
--- a/nyx/panel/torrc.py
+++ b/nyx/panel/torrc.py
@@ -90,7 +90,7 @@ class TorrcPanel(panel.Panel):
 
   def key_handlers(self):
     def _scroll(key):
-      page_height = self.get_preferred_size()[0] - 1
+      page_height = self.get_height() - 1
       is_changed = self._scroller.handle_key(key, self._last_content_height, page_height)
 
       if is_changed:





More information about the tor-commits mailing list