commit 84cae714f5b6d386109147aaad007ac5b0f2635e
Author: Damian Johnson <atagar(a)torproject.org>
Date: Sun Mar 20 12:15:37 2016 -0700
Drop 'title_visible' methods from the Panel
I never liked these. They're a hack needed by a couple popups to hide the title
of the panel below them. I couldn't think of an elegant method for doing this,
but did come up with a more localized hack. We now make an extra subwindow that
covers the panel title and erase that.
---
nyx/panel/__init__.py | 16 -----------
nyx/panel/config.py | 5 ++--
nyx/panel/connection.py | 6 +---
nyx/panel/graph.py | 3 +-
nyx/panel/log.py | 3 +-
nyx/panel/torrc.py | 7 ++---
nyx/popups.py | 74 ++++++++++++++++++++++++-------------------------
7 files changed, 44 insertions(+), 70 deletions(-)
diff --git a/nyx/panel/__init__.py b/nyx/panel/__init__.py
index 62ae709..30b8b99 100644
--- a/nyx/panel/__init__.py
+++ b/nyx/panel/__init__.py
@@ -139,7 +139,6 @@ class Panel(object):
self.panel_name = name
self.visible = False
- self.title_visible = True
self.paused = False
self.pause_time = -1
@@ -168,21 +167,6 @@ class Panel(object):
return self.panel_name
- def is_title_visible(self):
- """
- True if the title is configured to be visible, False otherwise.
- """
-
- return self.title_visible
-
- def set_title_visible(self, is_visible):
- """
- Configures the panel's title to be visible or not when it's next redrawn.
- This is not guarenteed to be respected (not all panels have a title).
- """
-
- self.title_visible = is_visible
-
def set_visible(self, is_visible):
"""
Toggles if the panel is visible or not.
diff --git a/nyx/panel/config.py b/nyx/panel/config.py
index 765345a..8b759c5 100644
--- a/nyx/panel/config.py
+++ b/nyx/panel/config.py
@@ -291,9 +291,8 @@ class ConfigPanel(nyx.panel.Panel):
if selected is not None:
self._draw_selection_details(selected, width)
- if self.is_title_visible():
- hidden_msg = "press 'a' to hide most options" if self._show_all else "press 'a' to show all options"
- self.addstr(0, 0, 'Tor Configuration (%s):' % hidden_msg, HIGHLIGHT)
+ hidden_msg = "press 'a' to hide most options" if self._show_all else "press 'a' to show all options"
+ self.addstr(0, 0, 'Tor Configuration (%s):' % hidden_msg, HIGHLIGHT)
scroll_offset = 1
diff --git a/nyx/panel/connection.py b/nyx/panel/connection.py
index 3d571ec..952148f 100644
--- a/nyx/panel/connection.py
+++ b/nyx/panel/connection.py
@@ -344,8 +344,6 @@ class ConnectionPanel(nyx.panel.Panel, threading.Thread):
if selected != -1:
connection_tracker.set_custom_resolver(None if selected == 0 else options[selected])
elif key.match('d'):
- self.set_title_visible(False)
- self.redraw(True)
entries = self._entries
while True:
@@ -368,7 +366,6 @@ class ConnectionPanel(nyx.panel.Panel, threading.Thread):
elif key.match('right'):
self.handle_key(nyx.curses.KeyInput(curses.KEY_DOWN))
- self.set_title_visible(True)
self.redraw(True)
elif key.match('c') and user_traffic_allowed.inbound:
nyx.popups.show_count_dialog('Client Locales', self._client_locale_usage)
@@ -451,8 +448,7 @@ class ConnectionPanel(nyx.panel.Panel, threading.Thread):
is_scrollbar_visible = len(lines) > height - details_offset - 1
scroll_offset = 2 if is_scrollbar_visible else 0
- if self.is_title_visible():
- self._draw_title(entries, self._show_details)
+ self._draw_title(entries, self._show_details)
if is_showing_details:
self._draw_details(selected, width, is_scrollbar_visible)
diff --git a/nyx/panel/graph.py b/nyx/panel/graph.py
index b325dd1..7315bea 100644
--- a/nyx/panel/graph.py
+++ b/nyx/panel/graph.py
@@ -573,8 +573,7 @@ class GraphPanel(nyx.panel.Panel):
right_to_left = CONFIG['features.graph.right_to_left'],
)
- if self.is_title_visible():
- self.addstr(0, 0, attr.stat.title(width), HIGHLIGHT)
+ self.addstr(0, 0, attr.stat.title(width), HIGHLIGHT)
self._draw_subgraph(attr, attr.stat.primary, 0, PRIMARY_COLOR)
self._draw_subgraph(attr, attr.stat.secondary, attr.subgraph_width, SECONDARY_COLOR)
diff --git a/nyx/panel/log.py b/nyx/panel/log.py
index 159469a..498651b 100644
--- a/nyx/panel/log.py
+++ b/nyx/panel/log.py
@@ -322,8 +322,7 @@ class LogPanel(nyx.panel.Panel, threading.Thread):
# drawing the title after the content, so we'll clear content from the top line
- if self.is_title_visible():
- self._draw_title(width, event_types, event_filter)
+ self._draw_title(width, event_types, event_filter)
# redraw the display if...
# - last_content_height was off by too much
diff --git a/nyx/panel/torrc.py b/nyx/panel/torrc.py
index f52b6fb..39318f5 100644
--- a/nyx/panel/torrc.py
+++ b/nyx/panel/torrc.py
@@ -168,10 +168,9 @@ class TorrcPanel(panel.Panel):
new_content_height = y + scroll - 1
- if self.is_title_visible():
- self.addstr(0, 0, ' ' * width) # clear line
- location = ' (%s)' % self._torrc_location if self._torrc_location else ''
- self.addstr(0, 0, 'Tor Configuration File%s:' % location, HIGHLIGHT)
+ self.addstr(0, 0, ' ' * width) # clear line
+ location = ' (%s)' % self._torrc_location if self._torrc_location else ''
+ self.addstr(0, 0, 'Tor Configuration File%s:' % location, HIGHLIGHT)
if self._last_content_height != new_content_height:
self._last_content_height = new_content_height
diff --git a/nyx/popups.py b/nyx/popups.py
index 6190a09..de83e7c 100644
--- a/nyx/popups.py
+++ b/nyx/popups.py
@@ -382,40 +382,35 @@ def show_menu(title, options, old_selection):
selection = old_selection if old_selection != -1 else 0
- # hides the title of the first panel on the page
+ with popup_window(1, -1) as (title_erase, _, _):
+ title_erase.addstr(0, 0, ' ' * 500) # hide title of the panel below us
- control = nyx.controller.get_controller()
- top_panel = control.get_display_panels(include_sticky = False)[0]
- top_panel.set_title_visible(False)
- top_panel.redraw(True)
-
- while True:
- popup.win.erase()
- popup.win.box()
- popup.addstr(0, 0, title, HIGHLIGHT)
+ while True:
+ popup.win.erase()
+ popup.win.box()
+ popup.addstr(0, 0, title, HIGHLIGHT)
- for i in range(len(options)):
- label = options[i]
- format = HIGHLIGHT if i == selection else NORMAL
- tab = '> ' if i == old_selection else ' '
- popup.addstr(i + 1, 2, tab)
- popup.addstr(i + 1, 4, ' %s ' % label, format)
+ for i in range(len(options)):
+ label = options[i]
+ format = HIGHLIGHT if i == selection else NORMAL
+ tab = '> ' if i == old_selection else ' '
+ popup.addstr(i + 1, 2, tab)
+ popup.addstr(i + 1, 4, ' %s ' % label, format)
- popup.win.refresh()
+ popup.win.refresh()
- key = nyx.curses.key_input()
+ key = nyx.curses.key_input()
- if key.match('up'):
- selection = max(0, selection - 1)
- elif key.match('down'):
- selection = min(len(options) - 1, selection + 1)
- elif key.is_selection():
- break
- elif key.match('esc'):
- selection = -1
- break
+ if key.match('up'):
+ selection = max(0, selection - 1)
+ elif key.match('down'):
+ selection = min(len(options) - 1, selection + 1)
+ elif key.is_selection():
+ break
+ elif key.match('esc'):
+ selection = -1
+ break
- top_panel.set_title_visible(True)
return selection
@@ -448,19 +443,22 @@ def show_descriptor_popup(fingerprint, color, max_width, is_close_key):
if not popup:
return None
- scroller, redraw = nyx.curses.Scroller(), True
+ with popup_window(1, -1) as (title_erase, _, _):
+ title_erase.addstr(0, 0, ' ' * 500) # hide title of the panel below us
- while True:
- if redraw:
- _draw(popup, title, lines, color, scroller.location(), show_line_numbers)
- redraw = False
+ scroller, redraw = nyx.curses.Scroller(), True
- key = nyx.curses.key_input()
+ while True:
+ if redraw:
+ _draw(popup, title, lines, color, scroller.location(), show_line_numbers)
+ redraw = False
+
+ key = nyx.curses.key_input()
- if key.is_scroll():
- redraw = scroller.handle_key(key, len(lines), height - 2)
- elif is_close_key(key):
- return key
+ if key.is_scroll():
+ redraw = scroller.handle_key(key, len(lines), height - 2)
+ elif is_close_key(key):
+ return key
def _display_text(fingerprint):