began implementing signals
This commit is contained in:
parent
379ea16bbf
commit
eff5058382
3 changed files with 21 additions and 5 deletions
3
ECLB
Executable file
3
ECLB
Executable file
|
@ -0,0 +1,3 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
poetry run python ./easyconf-lemonbar/main.py
|
|
@ -1,6 +1,7 @@
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
from subprocess import run
|
from subprocess import run
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
from signal import SIGRTMIN, sigtimedwait
|
||||||
|
|
||||||
class Module:
|
class Module:
|
||||||
# All text that the module contains. Will be re-generated every time the
|
# 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):
|
def __init__(self, module_config, padding, bar):
|
||||||
# Attributes that will be extracted from the config
|
# Attributes that will be extracted from the config
|
||||||
self.name = ""
|
self.name = ""
|
||||||
|
self.signal = 0
|
||||||
self.alignment = ""
|
self.alignment = ""
|
||||||
self.pre = ""
|
self.pre = ""
|
||||||
self.prefix = ""
|
self.prefix = ""
|
||||||
|
@ -28,9 +30,11 @@ class Module:
|
||||||
case "command":
|
case "command":
|
||||||
self.command = module_config[option]
|
self.command = module_config[option]
|
||||||
case "refresh":
|
case "refresh":
|
||||||
self.refresh = module_config[option]
|
self.refresh = module_config[option]/1000
|
||||||
case "prefix":
|
case "prefix":
|
||||||
self.prefix = module_config[option]
|
self.prefix = module_config[option]
|
||||||
|
case "signal":
|
||||||
|
self.signal = SIGRTMIN + module_config[option]
|
||||||
|
|
||||||
format_options = module_config["format"]
|
format_options = module_config["format"]
|
||||||
for option in format_options:
|
for option in format_options:
|
||||||
|
@ -81,6 +85,8 @@ class Module:
|
||||||
|
|
||||||
def generate_text(self):
|
def generate_text(self):
|
||||||
text = self.pre + self.padding + self.prefix
|
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 += run(self.command, shell=True, capture_output=True, text=True).stdout.strip()
|
||||||
text += self.padding + self.post
|
text += self.padding + self.post
|
||||||
self.text = text
|
self.text = text
|
||||||
|
@ -90,12 +96,17 @@ class Module:
|
||||||
# Generate new text
|
# Generate new text
|
||||||
self.generate_text()
|
self.generate_text()
|
||||||
# Print the entire bar
|
# Print the entire bar
|
||||||
self.bar.print()
|
#self.bar.print()
|
||||||
|
|
||||||
if self.refresh == 0:
|
print(self.text)
|
||||||
break
|
|
||||||
|
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):
|
def start_thread(self):
|
||||||
thread = Thread(target=self.thread_callback)
|
thread = Thread(target=self.thread_callback)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
from yaml import safe_load
|
from yaml import safe_load
|
||||||
from schema import And, Optional, Regex, Schema, SchemaError, Or
|
from schema import And, Optional, Regex, Schema, SchemaError, Or
|
||||||
|
from signal import SIGRTMIN, SIGRTMAX
|
||||||
|
|
||||||
def get_bar_config_and_module_config_list(filename):
|
def get_bar_config_and_module_config_list(filename):
|
||||||
config_schema = Schema({
|
config_schema = Schema({
|
||||||
|
@ -25,6 +26,7 @@ def get_bar_config_and_module_config_list(filename):
|
||||||
"command": str,
|
"command": str,
|
||||||
"refresh": And(int, lambda n : n >= 0),
|
"refresh": And(int, lambda n : n >= 0),
|
||||||
Optional("prefix"): str,
|
Optional("prefix"): str,
|
||||||
|
Optional("signal"): And(int, lambda n : SIGRTMIN <= SIGRTMIN+n <= SIGRTMAX),
|
||||||
"format": {
|
"format": {
|
||||||
"align": Or("left", "center", "right"),
|
"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}$'),
|
Optional("bg_color"): Regex(r'^#[0-9a-fA-F]{3}$|^#[0-9a-fA-F]{6}$|^#[0-9a-fA-F]{8}$'),
|
||||||
|
|
Loading…
Reference in a new issue