diff options
| author | Jan T <keppinakki@gmail.com> | 2015-06-10 14:49:41 +0300 |
|---|---|---|
| committer | Jan T <keppinakki@gmail.com> | 2015-06-10 14:49:41 +0300 |
| commit | 06f8ed3d9f63c171fdda0205eef5e8d9ee4247f7 (patch) | |
| tree | c89c4f04ee7a5e5ea9c4912a526f8fb4a983c891 | |
| parent | 503f2eb95ef73109949a227795a03fee2fad8f72 (diff) | |
Fixed regexes.
Added note about forcing py3status update.
| -rw-r--r-- | py3status/modules/volume_status.py | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/py3status/modules/volume_status.py b/py3status/modules/volume_status.py index 90c81a8..f61e7df 100644 --- a/py3status/modules/volume_status.py +++ b/py3status/modules/volume_status.py @@ -1,6 +1,11 @@ """ Display current sound volume using amixer. Expands on the standard i3status volume module by adding color and percentage threshold settings. + +NOTE: If you want to refresh the module quicker than the i3status interval, + send a USR1 signal to py3status in the keybinding. + Example: killall -s USR1 py3status + Configuration parameters: - format : format the output, available variables: {percentage} - format_mute : format the output when the volume is muted @@ -60,15 +65,32 @@ class Py3status: # return the current channel volume value as a string def _get_percentage(self, output): - prog = re.compile(r"\[\d{1,3}%\]") - text = prog.findall(output)[0][1:-2] - return text + + # attempt to find a percentage value in square brackets + p = re.compile(r"(?<=\[)\d{1,3}(?=%\])") + text = p.search(output).group() + + # check if the parsed value is sane by checking if it's an integer + try: + int(text) + return text + + # if not, show an error message in output + except ValueError: + return "Error: Can't parse amixer output." # returns True if the channel is muted def _get_muted(self, output): - prog = re.compile(r"\[\w{2,3}\]") - text = prog.findall(output)[0][1:-1] - return text == "off" + p = re.compile(r"(?<=\[)\w{2,3}(?=\])") + text = p.search(output).group() + + # check if the parsed string is either "off" or "on" + if text in ["on", "off"]: + return text == "off" + + # if not, return False + else: + return False # this method is ran by py3status # returns a response dict |
