[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [nyx/master] Notify all panels of pausing/unpausing
commit f271985f7647e56b6737be689ceeb5329b1d492c
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Mon Sep 12 10:33:36 2016 -0700
Notify all panels of pausing/unpausing
Initially I thought a listener pattern would make more sense, but just about
all the panels need to be notified when we're paused or unpaused. As such
adding a notification hook to the panel.
This lets us drop get_pause_time() from the Interface since the two panels that
care about this can now track it for themselves.
---
nyx/__init__.py | 24 +-----------------------
nyx/panel/__init__.py | 10 ++++++++++
nyx/panel/connection.py | 7 ++++++-
nyx/panel/graph.py | 10 +++++-----
nyx/panel/header.py | 10 +++++++---
nyx/panel/log.py | 8 ++++----
6 files changed, 33 insertions(+), 36 deletions(-)
diff --git a/nyx/__init__.py b/nyx/__init__.py
index 268c4ba..4a031c7 100644
--- a/nyx/__init__.py
+++ b/nyx/__init__.py
@@ -16,14 +16,12 @@ Tor curses monitoring application.
Interface - overall nyx interface
|- is_paused - checks if the interface is paused
- |- pause_time - time when the interface was paused
+- set_paused - sets paused state
"""
import distutils.spawn
import os
import sys
-import time
import stem.connection
import stem.control
@@ -221,7 +219,6 @@ class Interface(object):
def __init__(self):
self._paused = False
- self._pause_time = None
def is_paused(self):
"""
@@ -232,16 +229,6 @@ class Interface(object):
return self._paused
- def get_pause_time(self):
- """
- Provides the time that we were last paused.
-
- :returns: **float** with the unix timestamp for when we were last paused,
- **None** if not paused
- """
-
- return self._pause_time
-
def set_paused(self, is_pause):
"""
Pauses or unpauses the interface.
@@ -252,18 +239,9 @@ class Interface(object):
if is_pause != self._paused:
self._paused = is_pause
- self._pause_time = time.time() if is_pause else None
-
- # Couple panels have their own pausing behavior. I'll later change this to
- # a listener approach or someting else that's less hacky.
for panel_impl in self.get_all_panels():
- if isinstance(panel_impl, nyx.panel.graph.GraphPanel) or isinstance(panel_impl, nyx.panel.log.LogPanel):
- panel_impl.set_paused(is_pause)
+ panel_impl.set_paused(is_pause)
for panel_impl in self.get_display_panels():
panel_impl.redraw()
-
-
-import nyx.panel.graph
-import nyx.panel.log
diff --git a/nyx/panel/__init__.py b/nyx/panel/__init__.py
index 5714db4..49c7e22 100644
--- a/nyx/panel/__init__.py
+++ b/nyx/panel/__init__.py
@@ -21,6 +21,7 @@ Panels consisting the nyx interface.
|- get_height - height occupied by the panel
|
|- set_visible - toggles panel visiblity
+ |- set_paused - notified when interface pauses or unpauses
|- key_handlers - keyboard input accepted by the panel
|- submenu - submenu for the panel
+- redraw - renders the panel content
@@ -133,6 +134,15 @@ class Panel(object):
self._visible = is_visible
+ def set_paused(self, is_pause):
+ """
+ Notified when the interface pauses or unpauses.
+
+ :param bool is_pause: suspended if **True**, resumed otherwise
+ """
+
+ pass
+
def key_handlers(self):
"""
Provides keyboard input this panel supports.
diff --git a/nyx/panel/connection.py b/nyx/panel/connection.py
index f8c3a7d..cabba2d 100644
--- a/nyx/panel/connection.py
+++ b/nyx/panel/connection.py
@@ -265,6 +265,7 @@ class ConnectionPanel(nyx.panel.DaemonPanel):
self._entries = [] # last fetched display entries
self._show_details = False # presents the details panel if true
self._sort_order = CONFIG['features.connection.order']
+ self._pause_time = 0
self._last_resource_fetch = -1 # timestamp of the last ConnectionResolver results used
@@ -308,6 +309,10 @@ class ConnectionPanel(nyx.panel.DaemonPanel):
self._sort_order = results
self._entries = sorted(self._entries, key = lambda entry: [entry.sort_value(attr) for attr in self._sort_order])
+ def set_paused(self, is_pause):
+ if is_pause:
+ self._pause_time = time.time()
+
def key_handlers(self):
def _scroll(key):
page_height = self.get_height() - 1
@@ -426,7 +431,7 @@ class ConnectionPanel(nyx.panel.DaemonPanel):
selected, scroll = self._scroller.selection(lines, subwindow.height - details_offset - 1)
if interface.is_paused():
- current_time = interface.get_pause_time()
+ current_time = self._pause_time()
elif not controller.is_alive():
current_time = controller.connection_time()
else:
diff --git a/nyx/panel/graph.py b/nyx/panel/graph.py
index 76d4bfa..5266e3f 100644
--- a/nyx/panel/graph.py
+++ b/nyx/panel/graph.py
@@ -498,6 +498,11 @@ class GraphPanel(nyx.panel.Panel):
finally:
nyx.controller.show_message()
+ def set_paused(self, is_pause):
+ if is_pause:
+ self._accounting_stats_paused = copy.copy(self._accounting_stats)
+ self._stats_paused = dict([(key, type(self._stats[key])(self._stats[key])) for key in self._stats])
+
def key_handlers(self):
def _pick_stats():
available_stats = sorted(self.stat_options())
@@ -546,11 +551,6 @@ class GraphPanel(nyx.panel.Panel):
Submenu('Bounds', [RadioMenuItem(opt, bounds_group, opt) for opt in Bounds]),
])
- def set_paused(self, is_pause):
- if is_pause:
- self._accounting_stats_paused = copy.copy(self._accounting_stats)
- self._stats_paused = dict([(key, type(self._stats[key])(self._stats[key])) for key in self._stats])
-
def _draw(self, subwindow):
if not self._displayed_stat:
return
diff --git a/nyx/panel/header.py b/nyx/panel/header.py
index 2165c3a..8b270b3 100644
--- a/nyx/panel/header.py
+++ b/nyx/panel/header.py
@@ -49,6 +49,7 @@ class HeaderPanel(nyx.panel.DaemonPanel):
self._last_width = nyx.curses.screen_size().width
self._reported_inactive = False
+ self._pause_time = 0
self._message = None
self._message_attr = []
@@ -115,6 +116,10 @@ class HeaderPanel(nyx.panel.DaemonPanel):
if not self.is_wide():
self.show_message('Requesting a new identity', HIGHLIGHT, max_wait = 1)
+ def set_paused(self, is_pause):
+ if is_pause:
+ self._pause_time = time.time()
+
def key_handlers(self):
def _reconnect():
if self._vals.is_connected:
@@ -153,7 +158,6 @@ class HeaderPanel(nyx.panel.DaemonPanel):
interface = nyx_interface()
left_width = max(subwindow.width / 2, 77) if is_wide else subwindow.width
right_width = subwindow.width - left_width
- pause_time = interface.get_pause_time() if interface.is_paused() else None
_draw_platform_section(subwindow, 0, 0, left_width, vals)
@@ -163,7 +167,7 @@ class HeaderPanel(nyx.panel.DaemonPanel):
_draw_disconnected(subwindow, 0, 1, vals.last_heartbeat)
if is_wide:
- _draw_resource_usage(subwindow, left_width, 0, right_width, vals, pause_time)
+ _draw_resource_usage(subwindow, left_width, 0, right_width, vals, self._pause_time)
if vals.is_relay:
_draw_fingerprint_and_fd_usage(subwindow, left_width, 1, right_width, vals)
@@ -172,7 +176,7 @@ class HeaderPanel(nyx.panel.DaemonPanel):
elif vals.is_connected:
_draw_newnym_option(subwindow, left_width, 1, vals.newnym_wait)
else:
- _draw_resource_usage(subwindow, 0, 2, left_width, vals, pause_time)
+ _draw_resource_usage(subwindow, 0, 2, left_width, vals, self._pause_time)
if vals.is_relay:
_draw_fingerprint_and_fd_usage(subwindow, 0, 3, left_width, vals)
diff --git a/nyx/panel/log.py b/nyx/panel/log.py
index ca331ab..2cc41c7 100644
--- a/nyx/panel/log.py
+++ b/nyx/panel/log.py
@@ -189,6 +189,10 @@ class LogPanel(nyx.panel.DaemonPanel):
except Exception as exc:
raise IOError("unable to write to '%s': %s" % (path, exc))
+ def set_paused(self, is_pause):
+ if is_pause:
+ self._event_log_paused = self._event_log.clone()
+
def key_handlers(self):
def _scroll(key):
page_height = self.get_height() - 1
@@ -256,10 +260,6 @@ class LogPanel(nyx.panel.DaemonPanel):
]),
])
- def set_paused(self, is_pause):
- if is_pause:
- self._event_log_paused = self._event_log.clone()
-
def _draw(self, subwindow):
scroll = self._scroller.location(self._last_content_height, subwindow.height - 1)
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits