Merge branch 'Kymon-disk_remaining&fix'
This commit is contained in:
commit
ce7870c5bf
2 changed files with 35 additions and 5 deletions
|
@ -74,6 +74,10 @@ class Module(object):
|
||||||
def update_all(self):
|
def update_all(self):
|
||||||
self.update(self._widgets)
|
self.update(self._widgets)
|
||||||
|
|
||||||
|
def has_parameter(self, name):
|
||||||
|
v = self.parameter(name)
|
||||||
|
return v is not None
|
||||||
|
|
||||||
def parameter(self, name, default=None):
|
def parameter(self, name, default=None):
|
||||||
"""Return the config parameter 'name' for this module"""
|
"""Return the config parameter 'name' for this module"""
|
||||||
name = "{}.{}".format(self.name, name)
|
name = "{}.{}".format(self.name, name)
|
||||||
|
|
|
@ -8,6 +8,9 @@ Parameters:
|
||||||
* disk.path: Path to calculate disk usage from (defaults to /)
|
* disk.path: Path to calculate disk usage from (defaults to /)
|
||||||
* disk.open: Which application / file manager to launch (default xdg-open)
|
* disk.open: Which application / file manager to launch (default xdg-open)
|
||||||
* disk.format: Format string, tags {path}, {used}, {left}, {size} and {percent} (defaults to "{path} {used}/{size} ({percent:05.02f}%)")
|
* disk.format: Format string, tags {path}, {used}, {left}, {size} and {percent} (defaults to "{path} {used}/{size} ({percent:05.02f}%)")
|
||||||
|
* (deprecated) disk.showUsed: Show used space (defaults to yes)
|
||||||
|
* (deprecated) disk.showSize: Show total size (defaults to yes)
|
||||||
|
* (deprecated) disk.showPercent: Show usage percentage (defaults to yes)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
@ -42,11 +45,34 @@ class Module(bumblebee.engine.Module):
|
||||||
left_str = bumblebee.util.bytefmt(self._left)
|
left_str = bumblebee.util.bytefmt(self._left)
|
||||||
percent_str = self._percent
|
percent_str = self._percent
|
||||||
|
|
||||||
|
sused = self.has_parameter("showUsed")
|
||||||
|
ssize = self.has_parameter("showSize")
|
||||||
|
spercent = self.has_parameter("showPercent")
|
||||||
|
|
||||||
|
if all(not param for param in (sused, ssize, spercent)):
|
||||||
return self._format.format(path = self._path,
|
return self._format.format(path = self._path,
|
||||||
used = used_str,
|
used = used_str,
|
||||||
left = left_str,
|
left = left_str,
|
||||||
size = size_str,
|
size = size_str,
|
||||||
percent = percent_str)
|
percent = percent_str)
|
||||||
|
else:
|
||||||
|
rv = ""
|
||||||
|
sused = bumblebee.util.asbool(self.parameter("showUsed", True))
|
||||||
|
ssize = bumblebee.util.asbool(self.parameter("showSize", True))
|
||||||
|
spercent = bumblebee.util.asbool(self.parameter("showPercent", True))
|
||||||
|
|
||||||
|
if sused:
|
||||||
|
rv = "{}{}".format(rv, used_str)
|
||||||
|
if sused and ssize:
|
||||||
|
rv = "{}/".format(rv)
|
||||||
|
if ssize:
|
||||||
|
rv = "{}{}".format(rv, size_str)
|
||||||
|
if spercent:
|
||||||
|
if not sused and not ssize:
|
||||||
|
rv = "{:05.02f}%".format(percent_str)
|
||||||
|
else:
|
||||||
|
rv = "{} ({:05.02f}%)".format(rv, percent_str)
|
||||||
|
return rv
|
||||||
|
|
||||||
|
|
||||||
def update(self, widgets):
|
def update(self, widgets):
|
||||||
|
|
Loading…
Reference in a new issue