[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [nyx/master] Separate panel from descriptor dialog
commit 34be51ee6ea48f8d8e1c124063a7c6a02f890a79
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Sat Jun 27 13:41:20 2015 -0700
Separate panel from descriptor dialog
Abstracting the connection panel from the function for showing a descriptor
dialog. This essentially moves the outer loop which handled connection panel
navigation where it belongs.
---
nyx/connections/conn_panel.py | 25 ++++++++-
nyx/connections/descriptor_popup.py | 96 ++++++++++++++---------------------
2 files changed, 61 insertions(+), 60 deletions(-)
diff --git a/nyx/connections/conn_panel.py b/nyx/connections/conn_panel.py
index fe41507..c555a38 100644
--- a/nyx/connections/conn_panel.py
+++ b/nyx/connections/conn_panel.py
@@ -311,8 +311,29 @@ class ConnectionPanel(panel.Panel, threading.Thread):
if selection != -1:
self.set_listing_type(options[selection])
elif key.match('d'):
- # presents popup for raw consensus data
- descriptor_popup.show_descriptor_popup(self)
+ self.set_title_visible(False)
+ self.redraw(True)
+
+ while True:
+ selection = self.get_selection()
+
+ if not selection:
+ break
+
+ color = nyx.connections.conn_entry.CATEGORY_COLOR[selection.get_type()]
+ fingerprint = None if selection.foreign.get_fingerprint() == 'UNKNOWN' else selection.foreign.get_fingerprint()
+ is_close_key = lambda key: key.is_selection() or key.match('d') or key.match('left') or key.match('right')
+ key = descriptor_popup.show_descriptor_popup(fingerprint, color, self.max_x, is_close_key)
+
+ if not key or key.is_selection() or key.match('d'):
+ break # closes popup
+ elif key.match('left'):
+ self.handle_key(panel.KeyInput(curses.KEY_UP))
+ elif key.match('right'):
+ self.handle_key(panel.KeyInput(curses.KEY_DOWN))
+
+ self.set_title_visible(True)
+ self.redraw(True)
elif key.match('c') and self.is_clients_allowed():
count_popup.showCountDialog(count_popup.CountType.CLIENT_LOCALE, self._client_locale_usage)
elif key.match('e') and self.is_exits_allowed():
diff --git a/nyx/connections/descriptor_popup.py b/nyx/connections/descriptor_popup.py
index 1d155c3..358784c 100644
--- a/nyx/connections/descriptor_popup.py
+++ b/nyx/connections/descriptor_popup.py
@@ -6,9 +6,8 @@ import math
import curses
import nyx.popups
-import nyx.connections.conn_entry
-from nyx.util import panel, tor_controller, ui_tools
+from nyx.util import tor_controller, ui_tools
from stem.util import str_tools
@@ -22,70 +21,51 @@ UNRESOLVED_MSG = 'No consensus data available'
ERROR_MSG = 'Unable to retrieve data'
-def show_descriptor_popup(conn_panel):
+def show_descriptor_popup(fingerprint, color, max_width, is_close_key):
"""
- Presents consensus descriptor in popup window with the following controls:
- Up, Down, Page Up, Page Down - scroll descriptor
- Right, Left - next / previous connection
- Enter, Space, d, D - close popup
+ Provides a dialog showing the descriptors for a given relay.
- Arguments:
- conn_panel - connection panel providing the dialog
+ :param str fingerprint: fingerprint of the relay to be shown
+ :param str color: text color of the dialog
+ :param int max_width: maximum width of the dialog
+ :param function is_close_key: method to indicate if a key should close the
+ dialog or not
+
+ :returns: :class:`~nyx.util.panel.KeyInput` for the keyboard input that
+ closed the dialog
"""
- # hides the title of the connection panel
+ if fingerprint:
+ title = 'Consensus Descriptor:'
+ lines = _display_text(fingerprint)
+ show_line_numbers = True
+ else:
+ title = 'Consensus Descriptor (%s):' % fingerprint
+ lines = [UNRESOLVED_MSG]
+ show_line_numbers = False
+
+ popup_height, popup_width = _preferred_size(lines, max_width, show_line_numbers)
- conn_panel.set_title_visible(False)
- conn_panel.redraw(True)
+ with nyx.popups.popup_window(popup_height, popup_width) as (popup, _, height):
+ if not popup:
+ return None
- control = nyx.controller.get_controller()
+ scroll, redraw = 0, True
- with panel.CURSES_LOCK:
while True:
- selection = conn_panel.get_selection()
-
- if not selection:
- break
-
- fingerprint = selection.foreign.get_fingerprint()
-
- if fingerprint == 'UNKNOWN':
- title = 'Consensus Descriptor (%s):' % fingerprint
- lines = [UNRESOLVED_MSG]
- show_line_numbers = False
- else:
- title = 'Consensus Descriptor:'
- lines = _display_text(fingerprint)
- show_line_numbers = True
-
- color = nyx.connections.conn_entry.CATEGORY_COLOR[selection.get_type()]
- popup_height, popup_width = _preferred_size(lines, conn_panel.max_x, show_line_numbers)
-
- with nyx.popups.popup_window(popup_height, popup_width) as (popup, _, height):
- if popup:
- scroll = 0
- _draw(popup, title, lines, color, scroll, show_line_numbers)
-
- while True:
- key = control.key_input()
-
- if key.is_scroll():
- new_scroll = ui_tools.get_scroll_position(key, scroll, height - 2, len(lines))
-
- if scroll != new_scroll:
- scroll = new_scroll
- _draw(popup, title, lines, color, scroll, show_line_numbers)
- elif key.is_selection() or key.match('d'):
- return # closes popup
- elif key.match('left'):
- conn_panel.handle_key(panel.KeyInput(curses.KEY_UP))
- break
- elif key.match('right'):
- conn_panel.handle_key(panel.KeyInput(curses.KEY_DOWN))
- break
-
- conn_panel.set_title_visible(True)
- conn_panel.redraw(True)
+ if redraw:
+ _draw(popup, title, lines, color, scroll, show_line_numbers)
+ redraw = False
+
+ key = nyx.controller.get_controller().key_input()
+
+ if key.is_scroll():
+ new_scroll = ui_tools.get_scroll_position(key, scroll, height - 2, len(lines))
+
+ if scroll != new_scroll:
+ scroll, redraw = new_scroll, True
+ elif is_close_key(key):
+ return key
def _display_text(fingerprint):
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits