Starting a custom clock in python.
This commit is contained in:
parent
637e9b5fed
commit
7e84f7980e
@ -51,6 +51,7 @@
|
|||||||
#clock,
|
#clock,
|
||||||
#cpu,
|
#cpu,
|
||||||
#custom-keyboard-layout,
|
#custom-keyboard-layout,
|
||||||
|
#custom-clock,
|
||||||
#memory,
|
#memory,
|
||||||
#mode,
|
#mode,
|
||||||
#network,
|
#network,
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
"spacing": 10
|
"spacing": 10
|
||||||
},
|
},
|
||||||
"custom/clock": {
|
"custom/clock": {
|
||||||
"exec": "$HOME/.bin/.waybar_date",
|
"exec": "waybar_custom_clock",
|
||||||
"return-type": "json",
|
"return-type": "json",
|
||||||
"restart-interval": 30
|
"restart-interval": 30
|
||||||
}
|
}
|
||||||
|
53
ansible/roles/sway/files/waybar_custom_clock.py
Normal file
53
ansible/roles/sway/files/waybar_custom_clock.py
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
#
|
||||||
|
# Custom waybar module for clocks. Implemented because the official clock module was downloading timezone definitions on every boot.
|
||||||
|
import json
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
from dataclasses import dataclass
|
||||||
|
from typing import Final, List, Optional
|
||||||
|
|
||||||
|
INTERVAL: Final[int] = 10
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class Update:
|
||||||
|
text: Optional[str]
|
||||||
|
alt: Optional[str]
|
||||||
|
tooltip: Optional[str]
|
||||||
|
css_class: Optional[List[str]]
|
||||||
|
percentage: Optional[str]
|
||||||
|
|
||||||
|
def dump(self) -> str:
|
||||||
|
# Dump a dict because we can't name our member variable "class"
|
||||||
|
return json.dumps(
|
||||||
|
{
|
||||||
|
k: v
|
||||||
|
for k, v in {
|
||||||
|
"text": self.text,
|
||||||
|
"alt": self.alt,
|
||||||
|
"tooltip": self.tooltip,
|
||||||
|
"class": self.css_class,
|
||||||
|
"percentage": self.percentage,
|
||||||
|
}.items()
|
||||||
|
if v is not None
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
next_update = time.time()
|
||||||
|
while True:
|
||||||
|
time_before_next_update = next_update - time.time()
|
||||||
|
if time_before_next_update > 0:
|
||||||
|
time.sleep(time_before_next_update)
|
||||||
|
next_update = time.time() + INTERVAL
|
||||||
|
argv = json.dumps(sys.argv)
|
||||||
|
out = Update(
|
||||||
|
text="foo", alt=argv, tooltip=argv, css_class=["foo"], percentage="100"
|
||||||
|
)
|
||||||
|
print(out.dump(), flush=True)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
@ -1,3 +1,14 @@
|
|||||||
|
- name: Install scripts
|
||||||
|
copy:
|
||||||
|
src: "files/{{ item.src }}"
|
||||||
|
dest: "{{ item.dest }}"
|
||||||
|
mode: 0755
|
||||||
|
owner: root
|
||||||
|
group: wheel
|
||||||
|
loop:
|
||||||
|
- src: waybar_custom_clock.py
|
||||||
|
dest: /usr/local/bin/waybar_custom_clock
|
||||||
|
|
||||||
- import_tasks: tasks/freebsd.yaml
|
- import_tasks: tasks/freebsd.yaml
|
||||||
when: 'os_flavor == "freebsd"'
|
when: 'os_flavor == "freebsd"'
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user