def post_config_hook(self): if i3pystatus is None: raise Exception('i3pystatus is not installed') if self.py3.is_python_2(): raise Exception('Python 2 not supported by i3pystatus :(') if not self.module: raise Exception('No module selected') settings = {} for attribute in dir(self): if attribute.startswith('__') or attribute in SKIP_ATTRS: continue settings[attribute] = getattr(self, attribute) # backends backend_type = None if 'backend' in settings: backend_type = 'backend' elif 'backends' in settings: backend_type = 'backends' if backend_type: backends = settings[backend_type] backends_initiated = [] for key, value in backends.items(): mod_info = key.split('.') backend_module = import_module(get_backends().get(mod_info[0])) try: backend = getattr(backend_module, mod_info[1])(**value) except i3pystatus.core.exceptions.ConfigMissingError as e: msg = e.message msg = ('i3pystatus module `{}` backend `{}`' 'missing configuration options {}').format( self.module, key, msg[msg.index('{'):]) self.py3.notify_user(msg) raise Exception('Missing configuration options') backends_initiated.append(backend) if backend_type == 'backend': settings['backend'] = backends_initiated[0] else: settings['backends'] = backends_initiated # i3pystatus.Status can only exist once # so create it and share global status if status is None: status = i3pystatus.Status() # create the module and register it finder = status.modules.finder try: module = finder.instanciate_class_from_module( self.module, **settings) except i3pystatus.core.exceptions.ConfigMissingError as e: msg = e.message msg = 'i3pystatus module `{}` missing configuration options {}'.format( self.module, msg[msg.index('{'):]) self.py3.notify_user(msg) raise Exception('Missing configuration options') status.register(module) self.module = module self.is_interval_module = isinstance(module, i3pystatus.IntervalModule) # modules update their output independently so we need to periodically # check if it has been updated. For modules with long intervals it is # important to do this output check much more regularly thank the # interval. self._cache_timeout = min( getattr(module, 'interval', MIN_CHECK_INTERVAL), MIN_CHECK_INTERVAL) # get callbacks available, useful for deciding if double clicks exist callbacks = [] for i in range(len(CLICK_EVENTS)): click = getattr(module, CLICK_EVENTS[i], None) dbclick = getattr(module, DBL_CLICK_EVENTS[i], None) callbacks.append((click, dbclick)) self._click_timer = ClickTimer(self, callbacks) self._last_content = None self._timeout = 1
def post_config_hook(self): if not i3pystatus: raise Exception(STRING_NOT_INSTALLED) elif not self.module: raise Exception(STRING_MISSING_MODULE) settings = {} for attribute in dir(self): if attribute.startswith("__") or attribute in SKIP_ATTRS: continue settings[attribute] = getattr(self, attribute) # backends backend_type = None if "backend" in settings: backend_type = "backend" elif "backends" in settings: backend_type = "backends" if backend_type: backends = settings[backend_type] backends_initiated = [] for key, value in backends.items(): mod_info = key.split(".") backend_module = import_module(get_backends().get(mod_info[0])) try: backend = getattr(backend_module, mod_info[1])(**value) except i3pystatus.core.exceptions.ConfigMissingError as e: msg = e.message msg = ("i3pystatus module `{}` backend `{}`" "missing configuration options {}").format( self.module, key, msg[msg.index("{"):]) self.py3.notify_user(msg) raise Exception("Missing configuration options") backends_initiated.append(backend) if backend_type == "backend": settings["backend"] = backends_initiated[0] else: settings["backends"] = backends_initiated # i3pystatus.Status can only exist once # so create it and share global status if status is None: status = i3pystatus.Status(standalone=False) # create the module and register it finder = status.modules.finder try: module = finder.instanciate_class_from_module( self.module, **settings) except i3pystatus.core.exceptions.ConfigMissingError as e: msg = e.message msg = "i3pystatus module `{}` missing configuration options {}".format( self.module, msg[msg.index("{"):]) self.py3.notify_user(msg) raise Exception("Missing configuration options") status.register(module) self.module = module self.is_interval_module = isinstance(module, i3pystatus.IntervalModule) # modules update their output independently so we need to periodically # check if it has been updated. For modules with long intervals it is # important to do output check much more regularly than the interval. self._cache_timeout = min( getattr(module, "interval", MIN_CHECK_INTERVAL), MIN_CHECK_INTERVAL) # get callbacks available, useful for deciding if double clicks exist callbacks = [] for click_event, dbl_click_event in zip(CLICK_EVENTS, DBL_CLICK_EVENTS): click = getattr(module, click_event, None) dbclick = getattr(module, dbl_click_event, None) callbacks.append((click, dbclick)) self._click_timer = ClickTimer(self, callbacks) self._last_content = {} self._timeout = 1
import i3pystatus status = i3pystatus.Status() # Displays clock like this: # Tue 30 Jul 11:59:46 PM KW31 # ^-- calendar week status.register( "clock", format="%a %-d %b %X KW%V", ) # Shows the average load of the last minute and the last 5 minutes # (the default value for format is used) status.register("load") # Shows your CPU temperature, if you have a Intel CPU status.register( "temp", format="{temp:.0f}°C", ) # The battery monitor has many formatting options, see README for details # This would look like this, when discharging (or charging) # ↓14.22W 56.15% [77.81%] 2h:41m # And like this if full: # =14.22W 100.0% [91.21%] # # This would also display a desktop notification (via D-Bus) if the percentage # goes below 5 percent while discharging. The block will also color RED.