Permalink
Browse files

radio menu items

  • Loading branch information...
baverman committed Jan 8, 2012
1 parent 18fc1b3 commit 29dcf82cf9b3e9b7cc3ceec08567dd96c3283bfe
Showing with 30 additions and 6 deletions.
  1. +28 −4 uxie/actions.py
  2. +2 −2 uxie/plugins.py
View
@@ -210,7 +210,7 @@ def __call__(self, _ctx_getter):
return self.callback(*self.args)
-class MultyEntry(BaseEntry):
+class MultiEntry(BaseEntry):
def __init__(self, ctx, name, generator, resolver):
BaseEntry.__init__(self, ctx, name)
self.generator = generator
@@ -227,6 +227,29 @@ def resolve(self, *args):
return DEntry(self.ctx, None, title, cb, args)
+class DRadioEntry(DEntry):
+ def get_widget(self, _ctx_getter, km):
+ widget = create_entry_widget(
+ lambda label, underline:gtk.RadioMenuItem(None, label, underline), self.title, km)
+ widget.set_active(self.is_active)
+ return widget
+
+class RadioEntry(MultiEntry):
+ def get_entries(self, ctx_getter):
+ for is_active, title, eid, cb in self.generator(*ctx_getter(self.ctx)):
+ entry = DRadioEntry(self.ctx, self.name + '/' + eid, title, *cb)
+ entry.is_active = is_active
+ yield entry
+
+ def resolve(self, *args):
+ result = self.resolver(*args)
+ if result:
+ is_active, cb, args, title = result
+ entry = DRadioEntry(self.ctx, None, title, cb, args)
+ entry.is_active = is_active
+ return entry
+
+
class MenuEntry(object):
def __init__(self):
self.entries = []
@@ -281,7 +304,7 @@ def get_entries(self, ctx_getter):
for _, e in self.entries:
entry = self.items[e]
if entry.is_match(ctx_getter):
- if isinstance(entry, MultyEntry):
+ if isinstance(entry, MultiEntry):
for dentry in entry.get_entries(ctx_getter):
yield dentry
else:
@@ -394,10 +417,11 @@ def bind_menu(self, menu_entry):
entry = self.add_menu_entry(menu_entry+'/')
return AccelBinder(self, entry.ctx, entry.name)
- def bind_dynamic(self, ctx, name, menu_entry, generator, resolver):
+ def bind_dynamic(self, ctx, name, menu_entry, generator, resolver, as_radio=False):
ctx = normalize_context(ctx)
name = '!' + name
- entry = self.actions.setdefault(ctx, {})[name] = MultyEntry(ctx, name, generator, resolver)
+ cls = RadioEntry if as_radio else MultiEntry
+ entry = self.actions.setdefault(ctx, {})[name] = cls(ctx, name, generator, resolver)
if menu_entry:
self.add_menu_entry(menu_entry, entry)
View
@@ -29,8 +29,8 @@ def bind_check(self, ctx, name, menu_entry, callback, *args):
def bind_menu(self, menu_entry):
return self.activator.bind_menu(menu_entry)
- def bind_dynamic(self, ctx, name, menu_entry, generator, resolver):
- return self.activator.bind_dynamic(ctx, name, menu_entry, generator, resolver)
+ def bind_dynamic(self, ctx, name, menu_entry, generator, resolver, as_radio=False):
+ return self.activator.bind_dynamic(ctx, name, menu_entry, generator, resolver, as_radio)
def map(self, ctx, name, accel, priority=None):
return self.activator.map(ctx, name, accel, priority)

0 comments on commit 29dcf82

Please sign in to comment.