[tor-commits] [nyx/master] Drop name attribute of panels

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


commit a35433758b5e2f8e1e3ad3600f685d359b21cb6f
Author: Damian Johnson <atagar at torproject.org>
Date:   Thu Jul 14 08:38:06 2016 -0700

    Drop name attribute of panels
    
    Now that we're only using this a couple spots in the menu we can finally drop
    this attribute.
---
 nyx/menu.py             | 16 ++++++++++------
 nyx/panel/__init__.py   | 15 +++------------
 nyx/panel/config.py     |  2 +-
 nyx/panel/connection.py |  2 +-
 nyx/panel/graph.py      |  2 +-
 nyx/panel/header.py     |  2 +-
 nyx/panel/log.py        |  2 +-
 nyx/panel/torrc.py      |  2 +-
 8 files changed, 19 insertions(+), 24 deletions(-)

diff --git a/nyx/menu.py b/nyx/menu.py
index 697dfac..fef66d3 100644
--- a/nyx/menu.py
+++ b/nyx/menu.py
@@ -10,7 +10,11 @@ import functools
 import nyx.controller
 import nyx.curses
 import nyx.popups
+import nyx.panel.config
+import nyx.panel.connection
 import nyx.panel.graph
+import nyx.panel.log
+import nyx.panel.torrc
 import nyx.controller
 import nyx.tracker
 
@@ -38,15 +42,15 @@ def make_menu():
   control = nyx.controller.get_controller()
 
   for page_panel in control.get_display_panels():
-    if page_panel.get_name() == 'graph':
+    if isinstance(page_panel, nyx.panel.graph.GraphPanel):
       base_menu.add(make_graph_menu(page_panel))
-    elif page_panel.get_name() == 'log':
+    elif isinstance(page_panel, nyx.panel.log.LogPanel):
       base_menu.add(make_log_menu(page_panel))
-    elif page_panel.get_name() == 'connections':
+    elif isinstance(page_panel, nyx.panel.connection.ConnectionPanel):
       base_menu.add(make_connections_menu(page_panel))
-    elif page_panel.get_name() == 'configuration':
+    elif isinstance(page_panel, nyx.panel.config.ConfigPanel):
       base_menu.add(make_configuration_menu(page_panel))
-    elif page_panel.get_name() == 'torrc':
+    elif isinstance(page_panel, nyx.panel.torrc.TorrcPanel):
       base_menu.add(make_torrc_menu(page_panel))
 
   base_menu.add(make_help_menu())
@@ -100,7 +104,7 @@ def make_view_menu():
 
     for i in range(control.get_page_count()):
       page_panels = control.get_display_panels(page_number = i)
-      label = ' / '.join([str_tools._to_camel_case(panel.get_name()) for panel in page_panels])
+      label = ' / '.join([type(panel).__name__.replace('Panel', '') for panel in page_panels])
 
       view_menu.add(SelectionMenuItem(label, page_group, i))
 
diff --git a/nyx/panel/__init__.py b/nyx/panel/__init__.py
index fdd1480..c4d9222 100644
--- a/nyx/panel/__init__.py
+++ b/nyx/panel/__init__.py
@@ -77,12 +77,11 @@ class Panel(object):
   redraw().
   """
 
-  def __init__(self, name):
+  def __init__(self):
     """
     Creates a durable wrapper for a curses subwindow in the given parent.
 
     Arguments:
-      name   - identifier for the panel
       top    - positioning of top within parent
       left   - positioning of the left edge within the parent
       height - maximum height of panel (uses all available space if -1)
@@ -93,7 +92,6 @@ class Panel(object):
     # implementations aren't entirely deterministic (for instance panels
     # might chose their height based on its parent's current width).
 
-    self.panel_name = name
     self.visible = False
 
     self.paused = False
@@ -106,13 +104,6 @@ class Panel(object):
 
     self.max_y, self.max_x = -1, -1  # subwindow dimensions when last redrawn
 
-  def get_name(self):
-    """
-    Provides panel's identifier.
-    """
-
-    return self.panel_name
-
   def set_visible(self, is_visible):
     """
     Toggles if the panel is visible or not.
@@ -243,8 +234,8 @@ class Panel(object):
 
 
 class DaemonPanel(Panel, threading.Thread):
-  def __init__(self, name, update_rate):
-    Panel.__init__(self, name)
+  def __init__(self, update_rate):
+    Panel.__init__(self)
     threading.Thread.__init__(self)
     self.setDaemon(True)
 
diff --git a/nyx/panel/config.py b/nyx/panel/config.py
index 14e73ac..cbbaa92 100644
--- a/nyx/panel/config.py
+++ b/nyx/panel/config.py
@@ -122,7 +122,7 @@ class ConfigPanel(nyx.panel.Panel):
   """
 
   def __init__(self):
-    nyx.panel.Panel.__init__(self, 'configuration')
+    nyx.panel.Panel.__init__(self)
 
     self._contents = []
     self._scroller = nyx.curses.CursorScroller()
diff --git a/nyx/panel/connection.py b/nyx/panel/connection.py
index 2facd55..8e032e6 100644
--- a/nyx/panel/connection.py
+++ b/nyx/panel/connection.py
@@ -262,7 +262,7 @@ class ConnectionPanel(nyx.panel.DaemonPanel):
   """
 
   def __init__(self):
-    nyx.panel.DaemonPanel.__init__(self, 'connections', UPDATE_RATE)
+    nyx.panel.DaemonPanel.__init__(self, UPDATE_RATE)
 
     self._scroller = nyx.curses.CursorScroller()
     self._entries = []            # last fetched display entries
diff --git a/nyx/panel/graph.py b/nyx/panel/graph.py
index 5869dff..9cf1d71 100644
--- a/nyx/panel/graph.py
+++ b/nyx/panel/graph.py
@@ -409,7 +409,7 @@ class GraphPanel(nyx.panel.Panel):
   """
 
   def __init__(self):
-    nyx.panel.Panel.__init__(self, 'graph')
+    nyx.panel.Panel.__init__(self)
 
     self._displayed_stat = None if CONFIG['features.graph.type'] == 'none' else CONFIG['features.graph.type']
     self._update_interval = CONFIG['features.graph.interval']
diff --git a/nyx/panel/header.py b/nyx/panel/header.py
index 231ff1b..a2a5ae7 100644
--- a/nyx/panel/header.py
+++ b/nyx/panel/header.py
@@ -44,7 +44,7 @@ class HeaderPanel(nyx.panel.DaemonPanel):
   """
 
   def __init__(self):
-    nyx.panel.DaemonPanel.__init__(self, 'header', UPDATE_RATE)
+    nyx.panel.DaemonPanel.__init__(self, UPDATE_RATE)
     self._vals = Sampling.create()
 
     self._last_width = nyx.curses.screen_size().width
diff --git a/nyx/panel/log.py b/nyx/panel/log.py
index 355e52c..81b7a64 100644
--- a/nyx/panel/log.py
+++ b/nyx/panel/log.py
@@ -66,7 +66,7 @@ class LogPanel(nyx.panel.DaemonPanel):
   """
 
   def __init__(self):
-    nyx.panel.DaemonPanel.__init__(self, 'log', UPDATE_RATE)
+    nyx.panel.DaemonPanel.__init__(self, UPDATE_RATE)
 
     logged_events = CONFIG['startup.events'].split(',')
     tor_events = tor_controller().get_info('events/names', '').split()
diff --git a/nyx/panel/torrc.py b/nyx/panel/torrc.py
index e9f4ee2..6927e0c 100644
--- a/nyx/panel/torrc.py
+++ b/nyx/panel/torrc.py
@@ -35,7 +35,7 @@ class TorrcPanel(panel.Panel):
   """
 
   def __init__(self):
-    panel.Panel.__init__(self, 'torrc')
+    panel.Panel.__init__(self)
 
     self._scroller = nyx.curses.Scroller()
     self._show_line_numbers = True  # shows left aligned line numbers





More information about the tor-commits mailing list