diff --git a/alternative_wmiircs/python/pygmi/event.py b/alternative_wmiircs/python/pygmi/event.py index 6e0263e4..c56460af 100644 --- a/alternative_wmiircs/python/pygmi/event.py +++ b/alternative_wmiircs/python/pygmi/event.py @@ -108,7 +108,7 @@ class Events(): def loop(self): """ - Enters teh event loop, reading lines from wmii's '/event' + Enters the event loop, reading lines from wmii's '/event' and dispatching them, via #dispatch, to event handlers. Continues so long as #alive is True. """ diff --git a/alternative_wmiircs/python/pygmi/menu.py b/alternative_wmiircs/python/pygmi/menu.py index 07395cbb..47115762 100644 --- a/alternative_wmiircs/python/pygmi/menu.py +++ b/alternative_wmiircs/python/pygmi/menu.py @@ -1,16 +1,13 @@ +from threading import Thread from pygmi.util import call __all__ = 'Menu', 'ClickMenu' -def inthread(fn, action): - def run(): - res = fn() - if action: - return action(res) - return res - return run() - # Bug. - t = Thread(target=run) +def inthread(args, action, **kwargs): + fn = lambda: call(*args, **kwargs) + if not action: + return fn() + t = Thread(target=lambda: action(fn())) t.daemon = True t.start() @@ -27,14 +24,12 @@ class Menu(object): choices = self.choices if callable(choices): choices = choices() - def act(): - args = ['wimenu'] - if self.histfile: - args += ['-h', self.histfile] - if self.nhist: - args += ['-n', self.nhist] - return call(*map(str, args), input='\n'.join(choices)) - return inthread(act, self.action) + args = ['wimenu'] + if self.histfile: + args += ['-h', self.histfile] + if self.nhist: + args += ['-n', self.nhist] + return inthread(map(str, args), self.action, input='\n'.join(choices)) call = __call__ class ClickMenu(object): @@ -49,13 +44,11 @@ class ClickMenu(object): choices = self.choices if callable(choices): choices = choices() - def act(): - args = ['wmii9menu'] - if self.prev: - args += ['-i', self.prev] - args += ['--'] + list(choices) - return call(*map(str, args)).replace('\n', '') - return inthread(act, self.action) + args = ['wmii9menu'] + if self.prev: + args += ['-i', self.prev] + args += ['--'] + list(choices) + return inthread(map(str, args), self.action) call = __call__ # vim:se sts=4 sw=4 et: diff --git a/alternative_wmiircs/python/wmiirc b/alternative_wmiircs/python/wmiirc index ee40f8df..75a148ac 100755 --- a/alternative_wmiircs/python/wmiirc +++ b/alternative_wmiircs/python/wmiirc @@ -5,5 +5,8 @@ for p in os.environ.get("WMII_CONFPATH", "").split(':'): path += [p, p + '/python'] sys.path = path + sys.path -import pygmi +from pygmi import events import wmiirc + +events.loop() + diff --git a/alternative_wmiircs/python/wmiirc.py b/alternative_wmiircs/python/wmiirc.py index 35c4dc61..1a4c2627 100644 --- a/alternative_wmiircs/python/wmiirc.py +++ b/alternative_wmiircs/python/wmiirc.py @@ -304,6 +304,4 @@ for f in ['wmiirc_local'] + ['plugins.%s' % file[:-3] for file in files]: except Exception, e: traceback.print_exc(sys.stdout) -events.loop() - # vim:se sts=4 sw=4 et: