commit 36740e39556fcbcda9e93a064aec684936f0b6cc Author: Damian Johnson atagar@torproject.org Date: Sun Mar 20 13:43:40 2016 -0700
Replace subwindow box() requests with draw_box()
We have a helper function for drawing boxes so using that rather than drawing directly to our subwindow...
https://docs.python.org/2/library/curses.html#curses.window.box
We want to drop all direct subwindow usage so this gets us one step closer. --- nyx/panel/__init__.py | 11 ++++++++++- nyx/panel/config.py | 4 +++- nyx/panel/log.py | 2 +- nyx/popups.py | 12 ++++++------ 4 files changed, 20 insertions(+), 9 deletions(-)
diff --git a/nyx/panel/__init__.py b/nyx/panel/__init__.py index d4c7171..70c577d 100644 --- a/nyx/panel/__init__.py +++ b/nyx/panel/__init__.py @@ -634,7 +634,7 @@ class Panel(object):
return recreate
- def draw_box(self, top, left, width, height, *attributes): + def draw_box(self, top = 0, left = 0, width = -1, height = -1, *attributes): """ Draws a box in the panel with the given bounds.
@@ -646,6 +646,15 @@ class Panel(object): attr - text attributes """
+ if width == -1 or height == -1: + panel_height, panel_width = self.get_preferred_size() + + if width == -1: + width = panel_width - left + + if height == -1: + height = panel_height - top + # draws the top and bottom
self.hline(top, left + 1, width - 2, *attributes) diff --git a/nyx/panel/config.py b/nyx/panel/config.py index 8b759c5..2ad6f8f 100644 --- a/nyx/panel/config.py +++ b/nyx/panel/config.py @@ -209,7 +209,7 @@ class ConfigPanel(nyx.panel.Panel): x = popup.addstr(height - 2, x, option, BOLD, HIGHLIGHT if i == selection else NORMAL) x = popup.addstr(height - 2, x, '] ')
- popup.win.box() + popup.draw_box() popup.addstr(0, 0, 'Torrc to save:', HIGHLIGHT) popup.win.refresh()
@@ -231,6 +231,8 @@ class ConfigPanel(nyx.panel.Panel): elif key.match('esc'): break # esc - cancel
+ self.redraw(True) + def handle_key(self, key): if key.is_scroll(): page_height = self.get_preferred_size()[0] - DETAILS_HEIGHT diff --git a/nyx/panel/log.py b/nyx/panel/log.py index 498651b..094ad06 100644 --- a/nyx/panel/log.py +++ b/nyx/panel/log.py @@ -144,7 +144,7 @@ class LogPanel(nyx.panel.Panel, threading.Thread): if popup: # displays the available flags
- popup.win.box() + popup.draw_box() popup.addstr(0, 0, 'Event Types:', HIGHLIGHT) event_lines = CONFIG['msg.misc.event_types'].split('\n')
diff --git a/nyx/popups.py b/nyx/popups.py index de83e7c..bf40e4c 100644 --- a/nyx/popups.py +++ b/nyx/popups.py @@ -141,7 +141,7 @@ def show_help_popup():
# test doing afterward in case of overwriting
- popup.win.box() + popup.draw_box() popup.addstr(0, 0, 'Page %i Commands:' % (control.get_page() + 1), HIGHLIGHT)
for i in range(len(help_options)): @@ -192,7 +192,7 @@ def show_about_popup():
with popup_window(9, 80) as (popup, _, height): if popup: - popup.win.box() + popup.draw_box() popup.addstr(0, 0, 'About:', HIGHLIGHT) popup.addstr(1, 2, 'nyx, version %s (released %s)' % (__version__, __release_date__), BOLD) popup.addstr(2, 4, 'Written by Damian Johnson (atagar@torproject.org)') @@ -244,7 +244,7 @@ def show_count_dialog(title, counts):
popup.addstr(height - 2, 2, 'Press any key...')
- popup.win.box() + popup.draw_box() popup.addstr(0, 0, title, HIGHLIGHT) popup.win.refresh()
@@ -281,7 +281,7 @@ def show_sort_dialog(title, options, old_selection, option_colors):
while len(new_selections) < len(old_selection): popup.win.erase() - popup.win.box() + popup.draw_box() popup.addstr(0, 0, title, HIGHLIGHT)
_draw_sort_selection(popup, 1, 2, 'Current Order: ', old_selection, option_colors) @@ -387,7 +387,7 @@ def show_menu(title, options, old_selection):
while True: popup.win.erase() - popup.win.box() + popup.draw_box() popup.addstr(0, 0, title, HIGHLIGHT)
for i in range(len(options)): @@ -548,6 +548,6 @@ def _draw(popup, title, lines, entry_color, scroll, show_line_numbers): if y > height: break
- popup.win.box() + popup.draw_box() popup.addstr(0, 0, title, HIGHLIGHT) popup.win.refresh()