[tor-commits] [nyx/master] Move quit and halt methods

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


commit 6a30efb8f330305ca8c354c36483e9b5b1bfe77d
Author: Damian Johnson <atagar at torproject.org>
Date:   Tue Sep 13 10:45:38 2016 -0700

    Move quit and halt methods
    
    Simply moving a couple of our methods used to terminate the application.
---
 nyx/__init__.py   | 33 ++++++++++++++++++++++++++++++++-
 nyx/controller.py | 24 ++----------------------
 2 files changed, 34 insertions(+), 23 deletions(-)

diff --git a/nyx/__init__.py b/nyx/__init__.py
index 2ca58fe..c5e24c1 100644
--- a/nyx/__init__.py
+++ b/nyx/__init__.py
@@ -24,12 +24,16 @@ Tor curses monitoring application.
     |- get_daemon_panels - provides daemon panels
     |
     |- is_paused - checks if the interface is paused
-    +- set_paused - sets paused state
+    |- set_paused - sets paused state
+    |
+    |- quit - quits our application
+    +- halt - stops daemon panels
 """
 
 import distutils.spawn
 import os
 import sys
+import threading
 
 import stem.connection
 import stem.control
@@ -228,6 +232,7 @@ class Interface(object):
   def __init__(self):
     self._page = 0
     self._paused = False
+    self._quit = False
 
   def get_page(self):
     """
@@ -325,4 +330,30 @@ class Interface(object):
       for panel_impl in self.get_page_panels():
         panel_impl.redraw()
 
+  def quit(self):
+    """
+    Quits our application.
+    """
+
+    self._quit = True
+
+  def halt(self):
+    """
+    Stops curses panels in our interface.
+
+    :returns: **threading.Thread** terminating daemons
+    """
+
+    def halt_panels():
+      for panel_impl in self.get_daemon_panels():
+        panel_impl.stop()
+
+      for panel_impl in self.get_daemon_panels():
+        panel_impl.join()
+
+    halt_thread = threading.Thread(target = halt_panels)
+    halt_thread.start()
+    return halt_thread
+
+
 import nyx.panel
diff --git a/nyx/controller.py b/nyx/controller.py
index a50f2d4..7358383 100644
--- a/nyx/controller.py
+++ b/nyx/controller.py
@@ -7,7 +7,6 @@ user input to the proper panels.
 """
 
 import time
-import threading
 
 import nyx.curses
 import nyx.menu
@@ -106,13 +105,13 @@ class Controller(Interface):
 
     self._page_panels = []
     self._header_panel = None
-    self.quit_signal = False
     self._force_redraw = False
     self._last_drawn = 0
 
     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())
@@ -181,25 +180,6 @@ class Controller(Interface):
     if force:
       self._last_drawn = current_time
 
-  def quit(self):
-    self.quit_signal = True
-
-  def halt(self):
-    """
-    Halts curses panels, providing back the thread doing so.
-    """
-
-    def halt_panels():
-      for panel_impl in self.get_daemon_panels():
-        panel_impl.stop()
-
-      for panel_impl in self.get_daemon_panels():
-        panel_impl.join()
-
-    halt_thread = threading.Thread(target = halt_panels)
-    halt_thread.start()
-    return halt_thread
-
 
 def start_nyx():
   """
@@ -230,7 +210,7 @@ def start_nyx():
 
   override_key = None      # uses this rather than waiting on user input
 
-  while not interface.quit_signal:
+  while not interface._quit:
     display_panels = [interface.header_panel()] + interface.get_page_panels()
 
     # sets panel visability





More information about the tor-commits mailing list