diff options
Diffstat (limited to 'py3status')
| -rwxr-xr-x | py3status/__init__.py | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/py3status/__init__.py b/py3status/__init__.py index bd8072a..cb24d39 100755 --- a/py3status/__init__.py +++ b/py3status/__init__.py @@ -34,8 +34,8 @@ def print_line(line): """ Print given line to stdout (i3bar). """ - sys.stdout.write('{}\n'.format(line)) - sys.stdout.flush() + sys.__stdout__.write('{}\n'.format(line)) + sys.__stdout__.flush() class IOPoller: @@ -252,6 +252,22 @@ class Events(Thread): if self.config['debug']: syslog(LOG_INFO, 'dispatching default event {}'.format(event)) + def i3bar_click_events_module(self): + """ + Detect the presence of the special i3bar_click_events.py module. + + When py3status detects a module named 'i3bar_click_events.py', + it will dispatch i3status click events to this module so you can catch + them and trigger any function call based on the event. + """ + for module in self.modules: + if not module.click_events: + continue + if module.module_name == 'i3bar_click_events.py': + return module + else: + return False + def run(self): """ Wait for an i3bar JSON event, then find the right module to dispatch @@ -276,6 +292,7 @@ class Events(Thread): # setup default action on button 2 press default_event = False + dispatched = False if 'button' in event and event['button'] == 2: default_event = True @@ -291,10 +308,23 @@ class Events(Thread): if 'instance' in event: if event['instance'] == obj['instance']: self.dispatch(module, obj, event) + dispatched = True break else: self.dispatch(module, obj, event) + dispatched = True break + + # fall back to i3bar_click_events.py module if present + if not dispatched: + module = self.i3bar_click_events_module() + if module: + if self.config['debug']: + syslog( + LOG_INFO, + 'dispatching event to i3bar_click_events' + ) + self.dispatch(module, obj, event) except Exception: err = sys.exc_info()[1] syslog(LOG_WARNING, 'event failed ({})'.format(err)) @@ -320,6 +350,7 @@ class Module(Thread): self.lock = lock self.methods = {} self.module_class = None + self.module_name = f_name # self.load_methods(include_path, f_name) @@ -389,7 +420,7 @@ class Module(Thread): syslog( LOG_INFO, 'module {} click_events={} has_kill={} methods={}'.format( - f_name, + self.module_name, self.click_events, self.has_kill, self.methods.keys() @@ -601,6 +632,10 @@ class Py3statusWrapper(): if self.config['debug']: syslog(LOG_INFO, 'events thread started') + # suppress modules' ouput wrt issue #20 + sys.stdout = open('/dev/null', 'w') + sys.stderr = open('/dev/null', 'w') + # load and spawn modules threads for include_path, f_name in self.list_modules(): try: |
