[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [nyx/master] Use standard callback for radio menu items
commit cde8a21cdd5d80d7bc5093df9f9e7669233b42ea
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Mon Aug 22 09:22:45 2016 -0700
Use standard callback for radio menu items
Without the redraw there's now nothing special about RadioMenuItem compared to
its parent. We can just set the callback attribute to make this simple.
---
nyx/menu.py | 24 ++++--------------------
1 file changed, 4 insertions(+), 20 deletions(-)
diff --git a/nyx/menu.py b/nyx/menu.py
index b0764fa..f137535 100644
--- a/nyx/menu.py
+++ b/nyx/menu.py
@@ -148,33 +148,17 @@ class Submenu(MenuItem):
class RadioMenuItem(MenuItem):
"""
- Menu item with an associated group which determines the selection. This is
- for the common single argument getter/setter pattern.
+ Menu item with an associated group which determines the selection.
"""
def __init__(self, label, group, arg):
- MenuItem.__init__(self, label, None)
+ MenuItem.__init__(self, label, lambda: group.action(arg))
self._group = group
self._arg = arg
@property
def prefix(self):
- return '[X] ' if self.is_selected() else '[ ] '
-
- def is_selected(self):
- """
- True if we're the selected item, false otherwise.
- """
-
- return self._arg == self._group.selected_arg
-
- def select(self):
- """
- Performs the group's setter action with our argument.
- """
-
- if not self.is_selected():
- self._group.action(self._arg)
+ return '[X] ' if self._arg == self._group.selected_arg else '[ ] '
class RadioGroup(object):
@@ -183,7 +167,7 @@ class RadioGroup(object):
"""
def __init__(self, action, selected_arg):
- self.action = action
+ self.action = lambda arg: action(arg) if arg != self.selected_arg else None
self.selected_arg = selected_arg
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits