[core] Add a decorator for never updating a module
This commit is contained in:
parent
06ca5024dc
commit
94ef496ee6
3 changed files with 23 additions and 12 deletions
|
@ -1,5 +1,12 @@
|
||||||
import util.format
|
import util.format
|
||||||
|
|
||||||
|
def never(init):
|
||||||
|
def call_init(obj, *args, **kwargs):
|
||||||
|
init(obj, *args, **kwargs)
|
||||||
|
if obj.parameter('interval') is None:
|
||||||
|
obj.set('interval', 'never')
|
||||||
|
return call_init
|
||||||
|
|
||||||
def every(hours=0, minutes=0, seconds=0):
|
def every(hours=0, minutes=0, seconds=0):
|
||||||
def decorator_init(init):
|
def decorator_init(init):
|
||||||
def call_init(obj, *args, **kwargs):
|
def call_init(obj, *args, **kwargs):
|
||||||
|
|
|
@ -172,10 +172,13 @@ class i3(object):
|
||||||
if affected_modules and not module.id in affected_modules:
|
if affected_modules and not module.id in affected_modules:
|
||||||
continue
|
continue
|
||||||
if not affected_modules and module.next_update:
|
if not affected_modules and module.next_update:
|
||||||
|
if module.parameter('interval', '') == 'never':
|
||||||
|
continue
|
||||||
if now < module.next_update:
|
if now < module.next_update:
|
||||||
continue
|
continue
|
||||||
if not redraw_only:
|
if not redraw_only:
|
||||||
module.update_wrapper()
|
module.update_wrapper()
|
||||||
|
if module.parameter('interval', '') != 'never':
|
||||||
module.next_update = now + float(module.parameter('interval', self.__config.interval()))
|
module.next_update = now + float(module.parameter('interval', self.__config.interval()))
|
||||||
for widget in module.widgets():
|
for widget in module.widgets():
|
||||||
self.__content[widget] = widget.full_text()
|
self.__content[widget] = widget.full_text()
|
||||||
|
|
|
@ -2,16 +2,17 @@
|
||||||
|
|
||||||
"""Opens a random xkcd comic in the browser."""
|
"""Opens a random xkcd comic in the browser."""
|
||||||
|
|
||||||
import bumblebee.input
|
import core.module
|
||||||
import bumblebee.output
|
import core.widget
|
||||||
import bumblebee.engine
|
import core.input
|
||||||
|
import core.decorators
|
||||||
|
|
||||||
|
class Module(core.module.Module):
|
||||||
class Module(bumblebee.engine.Module):
|
@core.decorators.never
|
||||||
def __init__(self, engine, config):
|
def __init__(self, config):
|
||||||
super(Module, self).__init__(engine, config,
|
super().__init__(config, core.widget.Widget('xkcd'))
|
||||||
bumblebee.output.Widget(full_text="xkcd")
|
core.input.register(self, button=core.input.LEFT_MOUSE,
|
||||||
)
|
|
||||||
engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE,
|
|
||||||
cmd="xdg-open https://c.xkcd.com/random/comic/"
|
cmd="xdg-open https://c.xkcd.com/random/comic/"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||||
|
|
Loading…
Reference in a new issue