[tor-commits] [nyx/master] Finish merging Controller into the Interface

atagar at torproject.org atagar at torproject.org
Fri Sep 16 06:18:14 UTC 2016


commit 0a366d3c6d140d0a9f229e9decf69c3e42de7a6d
Author: Damian Johnson <atagar at torproject.org>
Date:   Thu Sep 15 12:57:55 2016 -0700

    Finish merging Controller into the Interface
    
    Last bit is moving the constructor in. This completes the shift from our old
    controller into the interface class.
---
 nyx/__init__.py   | 55 +++++++++++++++++++++++++++++++++++---
 nyx/controller.py | 79 +++----------------------------------------------------
 2 files changed, 56 insertions(+), 78 deletions(-)

diff --git a/nyx/__init__.py b/nyx/__init__.py
index 973776d..a22e9f3 100644
--- a/nyx/__init__.py
+++ b/nyx/__init__.py
@@ -1,4 +1,4 @@
-# Copyright 2010-2016, Damian Johnson and The Tor Project
+# Copyright 2009-2016, Damian Johnson and The Tor Project
 # See LICENSE for licensing information
 
 """
@@ -61,6 +61,16 @@ __all__ = [
   'tracker',
 ]
 
+CONFIG = stem.util.conf.config_dict('nyx', {
+  'features.panels.show.graph': True,
+  'features.panels.show.log': True,
+  'features.panels.show.connection': True,
+  'features.panels.show.config': True,
+  'features.panels.show.torrc': True,
+  'features.panels.show.interpreter': True,
+})
+
+NYX_INTERFACE = None
 TOR_CONTROLLER = None
 BASE_DIR = os.path.sep.join(__file__.split(os.path.sep)[:-1])
 DATA_DIR = os.path.expanduser('~/.nyx')
@@ -115,8 +125,10 @@ def nyx_interface():
   :returns: :class:`~nyx.Interface` controller
   """
 
-  import nyx.controller
-  return nyx.controller.get_controller()
+  if NYX_INTERFACE is None:
+    Interface()  # constructor sets NYX_INTERFACE
+
+  return NYX_INTERFACE
 
 
 def tor_controller():
@@ -231,10 +243,40 @@ class Interface(object):
   """
 
   def __init__(self):
+    global NYX_INTERFACE
+
     self._page = 0
+    self._page_panels = []
+    self._header_panel = None
     self._paused = False
     self._quit = False
 
+    NYX_INTERFACE = self
+
+    self._header_panel = nyx.panel.header.HeaderPanel()
+    first_page_panels = []
+
+    if CONFIG['features.panels.show.graph']:
+      first_page_panels.append(nyx.panel.graph.GraphPanel())
+
+    if CONFIG['features.panels.show.log']:
+      first_page_panels.append(nyx.panel.log.LogPanel())
+
+    if first_page_panels:
+      self._page_panels.append(first_page_panels)
+
+    if CONFIG['features.panels.show.connection']:
+      self._page_panels.append([nyx.panel.connection.ConnectionPanel()])
+
+    if CONFIG['features.panels.show.config']:
+      self._page_panels.append([nyx.panel.config.ConfigPanel()])
+
+    if CONFIG['features.panels.show.torrc']:
+      self._page_panels.append([nyx.panel.torrc.TorrcPanel()])
+
+    if CONFIG['features.panels.show.interpreter']:
+      self._page_panels.append([nyx.panel.interpreter.InterpreterPanel()])
+
   def get_page(self):
     """
     Provides the page we're showing.
@@ -379,3 +421,10 @@ class Interface(object):
 
 
 import nyx.panel
+import nyx.panel.config
+import nyx.panel.connection
+import nyx.panel.graph
+import nyx.panel.header
+import nyx.panel.interpreter
+import nyx.panel.log
+import nyx.panel.torrc
diff --git a/nyx/controller.py b/nyx/controller.py
index cb69082..85cf1fe 100644
--- a/nyx/controller.py
+++ b/nyx/controller.py
@@ -13,23 +13,13 @@ import nyx.menu
 import nyx.popups
 
 import nyx.panel
-import nyx.panel.config
-import nyx.panel.connection
-import nyx.panel.graph
-import nyx.panel.header
-import nyx.panel.interpreter
-import nyx.panel.log
-import nyx.panel.torrc
 
 import stem
 
 from stem.util import conf, log
 
 from nyx.curses import BOLD
-from nyx import Interface, tor_controller
-
-
-NYX_CONTROLLER = None
+from nyx import nyx_interface, tor_controller
 
 
 def conf_handler(key, value):
@@ -39,31 +29,14 @@ def conf_handler(key, value):
 
 CONFIG = conf.config_dict('nyx', {
   'features.acsSupport': True,
-  'features.panels.show.graph': True,
-  'features.panels.show.log': True,
-  'features.panels.show.connection': True,
-  'features.panels.show.config': True,
-  'features.panels.show.torrc': True,
-  'features.panels.show.interpreter': True,
   'features.redrawRate': 5,
   'features.confirmQuit': True,
   'start_time': 0,
 }, conf_handler)
 
 
-def get_controller():
-  """
-  Provides the nyx controller instance.
-  """
-
-  if NYX_CONTROLLER is None:
-    Controller()  # constructor sets NYX_CONTROLLER
-
-  return NYX_CONTROLLER
-
-
 def show_message(message = None, *attr, **kwargs):
-  return get_controller().header_panel().show_message(message, *attr, **kwargs)
+  return nyx_interface().header_panel().show_message(message, *attr, **kwargs)
 
 
 def input_prompt(msg, initial_value = ''):
@@ -77,7 +50,7 @@ def input_prompt(msg, initial_value = ''):
     canceled
   """
 
-  header_panel = get_controller().header_panel()
+  header_panel = nyx_interface().header_panel()
 
   header_panel.show_message(msg)
   user_input = nyx.curses.str_input(len(msg), header_panel.get_height() - 1, initial_value)
@@ -86,56 +59,12 @@ def input_prompt(msg, initial_value = ''):
   return user_input
 
 
-class Controller(Interface):
-  """
-  Tracks the global state of the interface
-  """
-
-  def __init__(self):
-    """
-    Creates a new controller instance. Panel lists are ordered as they appear,
-    top to bottom on the page.
-    """
-
-    global NYX_CONTROLLER
-    super(Controller, self).__init__()
-
-    self._page_panels = []
-    self._header_panel = None
-
-    NYX_CONTROLLER = self
-
-    self._header_panel = nyx.panel.header.HeaderPanel()
-    first_page_panels = []
-
-    if CONFIG['features.panels.show.graph']:
-      first_page_panels.append(nyx.panel.graph.GraphPanel())
-
-    if CONFIG['features.panels.show.log']:
-      first_page_panels.append(nyx.panel.log.LogPanel())
-
-    if first_page_panels:
-      self._page_panels.append(first_page_panels)
-
-    if CONFIG['features.panels.show.connection']:
-      self._page_panels.append([nyx.panel.connection.ConnectionPanel()])
-
-    if CONFIG['features.panels.show.config']:
-      self._page_panels.append([nyx.panel.config.ConfigPanel()])
-
-    if CONFIG['features.panels.show.torrc']:
-      self._page_panels.append([nyx.panel.torrc.TorrcPanel()])
-
-    if CONFIG['features.panels.show.interpreter']:
-      self._page_panels.append([nyx.panel.interpreter.InterpreterPanel()])
-
-
 def start_nyx():
   """
   Main draw loop context.
   """
 
-  interface = get_controller()
+  interface = nyx_interface()
 
   if not CONFIG['features.acsSupport']:
     nyx.curses.disable_acs()





More information about the tor-commits mailing list