[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [nyx/master] Use draw() for config panel
commit 3a7bb6c69f61fd398666c7ea3654512b8345fc93
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Tue Jul 12 09:16:57 2016 -0700
Use draw() for config panel
---
nyx/panel/__init__.py | 2 +-
nyx/panel/config.py | 34 +++++++++++++++++-----------------
2 files changed, 18 insertions(+), 18 deletions(-)
diff --git a/nyx/panel/__init__.py b/nyx/panel/__init__.py
index 7a1e4f2..313f264 100644
--- a/nyx/panel/__init__.py
+++ b/nyx/panel/__init__.py
@@ -266,7 +266,7 @@ class Panel(object):
if not self.visible or HALT_ACTIVITY:
return
- if self.panel_name in ('header', 'graph', 'log', 'connections', 'torrc'):
+ if self.panel_name in ('header', 'graph', 'log', 'connections', 'configuration', 'torrc'):
height = self.get_height() if self.get_height() != -1 else None
width = self.get_width() if self.get_width() != -1 else None
diff --git a/nyx/panel/config.py b/nyx/panel/config.py
index bb432b2..3b3d83b 100644
--- a/nyx/panel/config.py
+++ b/nyx/panel/config.py
@@ -240,30 +240,30 @@ class ConfigPanel(nyx.panel.Panel):
nyx.panel.KeyHandler('s', 'sort ordering', self.show_sort_dialog),
)
- def draw(self, width, height):
+ def draw(self, subwindow):
contents = self._get_config_options()
- selected, scroll = self._scroller.selection(contents, height - DETAILS_HEIGHT)
- is_scrollbar_visible = len(contents) > height - DETAILS_HEIGHT
+ selected, scroll = self._scroller.selection(contents, subwindow.height - DETAILS_HEIGHT)
+ is_scrollbar_visible = len(contents) > subwindow.height - DETAILS_HEIGHT
if selected is not None:
- self._draw_selection_details(selected, width)
+ self._draw_selection_details(subwindow, selected)
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)
+ subwindow.addstr(0, 0, 'Tor Configuration (%s):' % hidden_msg, HIGHLIGHT)
scroll_offset = 1
if is_scrollbar_visible:
scroll_offset = 3
- self.add_scroll_bar(scroll, scroll + height - DETAILS_HEIGHT, len(contents), DETAILS_HEIGHT)
+ subwindow.scrollbar(DETAILS_HEIGHT, scroll, len(contents) - 1)
if selected is not None:
- self.addch(DETAILS_HEIGHT - 1, 1, curses.ACS_TTEE)
+ subwindow._addch(1, DETAILS_HEIGHT - 1, curses.ACS_TTEE)
# Description column can grow up to eighty characters. After that any extra
# space goes to the value.
- description_width = max(0, width - scroll_offset - NAME_WIDTH - VALUE_WIDTH - 2)
+ description_width = max(0, subwindow.width - scroll_offset - NAME_WIDTH - VALUE_WIDTH - 2)
if description_width > 80:
value_width = VALUE_WIDTH + (description_width - 80)
@@ -280,15 +280,15 @@ class ConfigPanel(nyx.panel.Panel):
value_label = str_tools.crop(entry.value(), value_width).ljust(value_width + 1)
summary_label = str_tools.crop(entry.manual.summary, description_width).ljust(description_width)
- self.addstr(DETAILS_HEIGHT + i, scroll_offset, option_label + value_label + summary_label, *attr)
+ subwindow.addstr(scroll_offset, DETAILS_HEIGHT + i, option_label + value_label + summary_label, *attr)
- if DETAILS_HEIGHT + i >= height:
+ if DETAILS_HEIGHT + i >= subwindow.height:
break
def _get_config_options(self):
return self._contents if self._show_all else filter(lambda entry: stem.manual.is_important(entry.name) or entry.is_set(), self._contents)
- def _draw_selection_details(self, selected, width):
+ def _draw_selection_details(self, subwindow, selected):
"""
Shows details of the currently selected option.
"""
@@ -296,10 +296,10 @@ class ConfigPanel(nyx.panel.Panel):
description = 'Description: %s' % (selected.manual.description)
attr = ', '.join(('custom' if selected.is_set() else 'default', selected.value_type, 'usage: %s' % selected.manual.usage))
selected_color = CONFIG['attr.config.category_color'].get(selected.manual.category, WHITE)
- self.draw_box(0, 0, width, DETAILS_HEIGHT)
+ subwindow.box(0, 0, subwindow.width, DETAILS_HEIGHT)
- self.addstr(1, 2, '%s (%s Option)' % (selected.name, selected.manual.category), selected_color, BOLD)
- self.addstr(2, 2, 'Value: %s (%s)' % (selected.value(), str_tools.crop(attr, width - len(selected.value()) - 13)), selected_color, BOLD)
+ subwindow.addstr(2, 1, '%s (%s Option)' % (selected.name, selected.manual.category), selected_color, BOLD)
+ subwindow.addstr(2, 2, 'Value: %s (%s)' % (selected.value(), str_tools.crop(attr, subwindow.width - len(selected.value()) - 13)), selected_color, BOLD)
for i in range(DETAILS_HEIGHT - 4):
if not description:
@@ -308,8 +308,8 @@ class ConfigPanel(nyx.panel.Panel):
line, description = description.split('\n', 1) if '\n' in description else (description, '')
if i < DETAILS_HEIGHT - 5:
- line, remainder = str_tools.crop(line, width - 3, 4, 4, str_tools.Ending.HYPHEN, True)
+ line, remainder = str_tools.crop(line, subwindow.width - 3, 4, 4, str_tools.Ending.HYPHEN, True)
description = ' ' + remainder.strip() + description
- self.addstr(3 + i, 2, line, selected_color, BOLD)
+ subwindow.addstr(2, 3 + i, line, selected_color, BOLD)
else:
- self.addstr(3 + i, 2, str_tools.crop(line, width - 3, 4, 4), selected_color, BOLD)
+ subwindow.addstr(2, 3 + i, str_tools.crop(line, subwindow.width - 3, 4, 4), selected_color, BOLD)
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits