began implementing signals

This commit is contained in:
Noah Swerhun 2023-03-11 20:20:00 -06:00
parent 379ea16bbf
commit eff5058382
3 changed files with 21 additions and 5 deletions

3
ECLB Executable file
View file

@ -0,0 +1,3 @@
#!/bin/sh
poetry run python ./easyconf-lemonbar/main.py

View file

@ -1,6 +1,7 @@
from threading import Thread
from subprocess import run
from time import sleep
from signal import SIGRTMIN, sigtimedwait
class Module:
# All text that the module contains. Will be re-generated every time the
@ -11,6 +12,7 @@ class Module:
def __init__(self, module_config, padding, bar):
# Attributes that will be extracted from the config
self.name = ""
self.signal = 0
self.alignment = ""
self.pre = ""
self.prefix = ""
@ -28,9 +30,11 @@ class Module:
case "command":
self.command = module_config[option]
case "refresh":
self.refresh = module_config[option]
self.refresh = module_config[option]/1000
case "prefix":
self.prefix = module_config[option]
case "signal":
self.signal = SIGRTMIN + module_config[option]
format_options = module_config["format"]
for option in format_options:
@ -81,6 +85,8 @@ class Module:
def generate_text(self):
text = self.pre + self.padding + self.prefix
if self.signal != 0:
text += "(" + str(self.signal) + ")"
text += run(self.command, shell=True, capture_output=True, text=True).stdout.strip()
text += self.padding + self.post
self.text = text
@ -90,12 +96,17 @@ class Module:
# Generate new text
self.generate_text()
# Print the entire bar
self.bar.print()
#self.bar.print()
if self.refresh == 0:
break
print(self.text)
if self.signal == 0:
if self.refresh == 0:
break
sleep(self.refresh)
else:
sigtimedwait([self.signal], self.refresh)
sleep(self.refresh/1000)
def start_thread(self):
thread = Thread(target=self.thread_callback)

View file

@ -1,5 +1,6 @@
from yaml import safe_load
from schema import And, Optional, Regex, Schema, SchemaError, Or
from signal import SIGRTMIN, SIGRTMAX
def get_bar_config_and_module_config_list(filename):
config_schema = Schema({
@ -25,6 +26,7 @@ def get_bar_config_and_module_config_list(filename):
"command": str,
"refresh": And(int, lambda n : n >= 0),
Optional("prefix"): str,
Optional("signal"): And(int, lambda n : SIGRTMIN <= SIGRTMIN+n <= SIGRTMAX),
"format": {
"align": Or("left", "center", "right"),
Optional("bg_color"): Regex(r'^#[0-9a-fA-F]{3}$|^#[0-9a-fA-F]{6}$|^#[0-9a-fA-F]{8}$'),