commit 31aa289c444da1f06dcef12ce83cbf5e5d72c9d1 Author: Damian Johnson atagar@torproject.org Date: Sun Apr 19 12:26:28 2015 -0700
Standardize on allowing multiple styling attributes
We changed addstr() to allow multiple styling attributes. Changing our other draw methods as well since we now expect it from them...
Traceback (most recent call last): File "./run_nyx", line 60, in <module> main() File "./run_nyx", line 17, in main nyx.starter.main() File "/home/atagar/Desktop/nyx/stem/util/conf.py", line 288, in wrapped return func(*args, config = config, **kwargs) File "/home/atagar/Desktop/nyx/nyx/starter.py", line 91, in main curses.wrapper(nyx.controller.start_nyx) File "/usr/lib/python2.7/curses/wrapper.py", line 43, in wrapper return func(stdscr, *args, **kwds) File "/home/atagar/Desktop/nyx/nyx/controller.py", line 570, in start_nyx control.redraw(False) File "/home/atagar/Desktop/nyx/nyx/controller.py", line 401, in redraw panel_impl.redraw(force) File "/home/atagar/Desktop/nyx/nyx/log_panel.py", line 828, in redraw panel.Panel.redraw(self, force_redraw, block) File "/home/atagar/Desktop/nyx/nyx/util/panel.py", line 433, in redraw self.draw(self.max_x, self.max_y) File "/home/atagar/Desktop/nyx/nyx/log_panel.py", line 727, in draw self.addch(line_count, divider_indent, curses.ACS_ULCORNER, *divider_attr) TypeError: addch() takes at most 5 arguments (6 given) --- nyx/util/panel.py | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-)
diff --git a/nyx/util/panel.py b/nyx/util/panel.py index 2841fe3..6dc3d0e 100644 --- a/nyx/util/panel.py +++ b/nyx/util/panel.py @@ -435,7 +435,7 @@ class Panel(object): finally: CURSES_LOCK.release()
- def hline(self, y, x, length, attr=curses.A_NORMAL): + def hline(self, y, x, length, *attributes): """ Draws a horizontal line. This should only be called from the context of a panel's draw method. @@ -447,15 +447,23 @@ class Panel(object): attr - text attributes """
+ format_attr = curses.A_NORMAL + + for attr in attributes: + if isinstance(attr, str): + format_attr |= ui_tools.get_color(attr) + else: + format_attr |= attr + if self.win and self.max_x > x and self.max_y > y: try: draw_length = min(length, self.max_x - x) - self.win.hline(y, x, curses.ACS_HLINE | attr, draw_length) + self.win.hline(y, x, curses.ACS_HLINE | format_attr, draw_length) except: # in edge cases drawing could cause a _curses.error pass
- def vline(self, y, x, length, attr=curses.A_NORMAL): + def vline(self, y, x, length, *attributes): """ Draws a vertical line. This should only be called from the context of a panel's draw method. @@ -467,15 +475,23 @@ class Panel(object): attr - text attributes """
+ format_attr = curses.A_NORMAL + + for attr in attributes: + if isinstance(attr, str): + format_attr |= ui_tools.get_color(attr) + else: + format_attr |= attr + if self.win and self.max_x > x and self.max_y > y: try: draw_length = min(length, self.max_y - y) - self.win.vline(y, x, curses.ACS_VLINE | attr, draw_length) + self.win.vline(y, x, curses.ACS_VLINE | format_attr, draw_length) except: # in edge cases drawing could cause a _curses.error pass
- def addch(self, y, x, char, attr=curses.A_NORMAL): + def addch(self, y, x, char, *attributes): """ Draws a single character. This should only be called from the context of a panel's draw method. @@ -487,9 +503,17 @@ class Panel(object): attr - text attributes """
+ format_attr = curses.A_NORMAL + + for attr in attributes: + if isinstance(attr, str): + format_attr |= ui_tools.get_color(attr) + else: + format_attr |= attr + if self.win and self.max_x > x and self.max_y > y: try: - self.win.addch(y, x, char, attr) + self.win.addch(y, x, char, format_attr) except: # in edge cases drawing could cause a _curses.error pass
tor-commits@lists.torproject.org