[core] add custom minimizer capability
Add a new set of parameters to allow modules to be customly minimized. It works like this: If a module has the parameter "minimize" set to a true value, it will *not* use the built-in minimizer, and instead look for "minimized" parameters (e.g. if date has the "format" parameter, it would look for "minimized.format" when in minimized state). This allows the user to have different parametrization for different states. Also, using the "start-minimized" parameter allows for modules to start minimized. Note: This is hinging off the *module*, not the *widget* (the current, hard-coded hiding is per-widget). This means that modules using this method will only show a single widget - the first one - when in minimized state. The module author has to account for that. see #791
This commit is contained in:
parent
dfd23a44de
commit
4b6b4b9052
3 changed files with 16 additions and 2 deletions
|
@ -95,6 +95,8 @@ class Module(core.input.Object):
|
||||||
self.alias = self.__config.get("__alias__", None)
|
self.alias = self.__config.get("__alias__", None)
|
||||||
self.id = self.alias if self.alias else self.name
|
self.id = self.alias if self.alias else self.name
|
||||||
self.next_update = None
|
self.next_update = None
|
||||||
|
self.minimized = False
|
||||||
|
self.minimized = self.parameter("start-minimized", False)
|
||||||
|
|
||||||
self.theme = theme
|
self.theme = theme
|
||||||
|
|
||||||
|
@ -126,6 +128,8 @@ class Module(core.input.Object):
|
||||||
|
|
||||||
for prefix in [self.name, self.module_name, self.alias]:
|
for prefix in [self.name, self.module_name, self.alias]:
|
||||||
value = self.__config.get("{}.{}".format(prefix, key), value)
|
value = self.__config.get("{}.{}".format(prefix, key), value)
|
||||||
|
if self.minimized:
|
||||||
|
value = self.__config.get("{}.minimized.{}".format(prefix, key), value)
|
||||||
return value
|
return value
|
||||||
|
|
||||||
"""Set a parameter for this module
|
"""Set a parameter for this module
|
||||||
|
|
|
@ -166,6 +166,12 @@ class i3(object):
|
||||||
def toggle_minimize(self, event):
|
def toggle_minimize(self, event):
|
||||||
widget_id = event["instance"]
|
widget_id = event["instance"]
|
||||||
|
|
||||||
|
for module in self.__modules:
|
||||||
|
if module.widget(widget_id=widget_id) and util.format.asbool(module.parameter("minimize", False)) == True:
|
||||||
|
# this module can customly minimize
|
||||||
|
module.minimized = not module.minimized
|
||||||
|
return
|
||||||
|
|
||||||
if widget_id in self.__content:
|
if widget_id in self.__content:
|
||||||
self.__content[widget_id]["minimized"] = not self.__content[widget_id]["minimized"]
|
self.__content[widget_id]["minimized"] = not self.__content[widget_id]["minimized"]
|
||||||
|
|
||||||
|
@ -216,6 +222,10 @@ class i3(object):
|
||||||
|
|
||||||
def blocks(self, module):
|
def blocks(self, module):
|
||||||
blocks = []
|
blocks = []
|
||||||
|
if module.minimized:
|
||||||
|
blocks.extend(self.separator_block(module, module.widgets()[0]))
|
||||||
|
blocks.append(self.__content_block(module, module.widgets()[0]))
|
||||||
|
return blocks
|
||||||
for widget in module.widgets():
|
for widget in module.widgets():
|
||||||
if widget.module and self.__config.autohide(widget.module.name):
|
if widget.module and self.__config.autohide(widget.module.name):
|
||||||
if not any(
|
if not any(
|
||||||
|
|
|
@ -21,7 +21,6 @@ class Module(core.module.Module):
|
||||||
super().__init__(config, theme, core.widget.Widget(self.full_text))
|
super().__init__(config, theme, core.widget.Widget(self.full_text))
|
||||||
|
|
||||||
core.input.register(self, button=core.input.LEFT_MOUSE, cmd="calendar")
|
core.input.register(self, button=core.input.LEFT_MOUSE, cmd="calendar")
|
||||||
self._fmt = self.parameter("format", self.default_format())
|
|
||||||
l = locale.getdefaultlocale()
|
l = locale.getdefaultlocale()
|
||||||
if not l or l == (None, None):
|
if not l or l == (None, None):
|
||||||
l = ("en_US", "UTF-8")
|
l = ("en_US", "UTF-8")
|
||||||
|
@ -36,7 +35,8 @@ class Module(core.module.Module):
|
||||||
|
|
||||||
def full_text(self, widget):
|
def full_text(self, widget):
|
||||||
enc = locale.getpreferredencoding()
|
enc = locale.getpreferredencoding()
|
||||||
retval = datetime.datetime.now().strftime(self._fmt)
|
fmt = self.parameter("format", self.default_format())
|
||||||
|
retval = datetime.datetime.now().strftime(fmt)
|
||||||
if hasattr(retval, "decode"):
|
if hasattr(retval, "decode"):
|
||||||
return retval.decode(enc)
|
return retval.decode(enc)
|
||||||
return retval
|
return retval
|
||||||
|
|
Loading…
Reference in a new issue