new config schema is now readable, bar prints properly

This commit is contained in:
Noah Swerhun 2023-04-03 15:58:45 -05:00
parent 90bbfcd7fe
commit 841218a6b7
4 changed files with 42 additions and 36 deletions

View file

@ -1,20 +1,20 @@
class Bar: class Bar:
def __init__(self, seperator, margin): def __init__(self, seperator, margin):
self.left = [] self.monitors = {}
self.center = []
self.right = []
self.seperator = seperator self.seperator = seperator
self.margin = margin self.margin = margin
def add_module(self, module): def add_monitor(self, monitor):
self.monitors[monitor] = { "left": [], "center": [], "right": [] }
def add_module(self, monitor, module):
match module.alignment: match module.alignment:
case "left": case "left":
self.left.append(module) self.monitors[monitor]["left"].append(module)
case "center": case "center":
self.center.append(module) self.monitors[monitor]["center"].append(module)
case "right": case "right":
self.right.append(module) self.monitors[monitor]["right"].append(module)
def __print_alignment_group(self, alignment_group): def __print_alignment_group(self, alignment_group):
for index, module in enumerate(alignment_group): for index, module in enumerate(alignment_group):
@ -26,13 +26,17 @@ class Bar:
break break
def print(self): def print(self):
print("%{l}" + self.margin, end='') for monitor in self.monitors:
self.__print_alignment_group(self.left) print("%{S" + str(monitor) + "}", end='')
print("%{l}" + self.margin, end='')
self.__print_alignment_group(self.monitors[monitor]["left"])
print("%{c}", end='') print("%{c}", end='')
self.__print_alignment_group(self.center) self.__print_alignment_group(self.monitors[monitor]["center"])
print("%{r}", end='') print("%{r}", end='')
self.__print_alignment_group(self.right) self.__print_alignment_group(self.monitors[monitor]["right"])
print(self.margin, flush=True) print(self.margin, end='')
print(flush=True)

View file

@ -1,7 +1,8 @@
from parse_config_file import get_bar_config_and_module_config_list
from os import getenv from os import getenv
from os.path import exists from os.path import exists
from easyconf_lemonbar.parse_config_file import get_bar_config_and_monitor_list
def generate_flags(bar_config): def generate_flags(bar_config):
flags = "" flags = ""
for option in bar_config: for option in bar_config:
@ -33,6 +34,6 @@ if exists("./data/testing_config.yml"):
else: else:
config_file = str(getenv("HOME")) + "/.config/easyconf-lemonbar.yml" config_file = str(getenv("HOME")) + "/.config/easyconf-lemonbar.yml"
bar_config, module_config_list = get_bar_config_and_module_config_list(config_file) bar_config, monitor_list = get_bar_config_and_monitor_list(config_file)
print(generate_flags(bar_config)) print(generate_flags(bar_config))

View file

@ -5,7 +5,7 @@ from os.path import exists
from SignalRouter import SignalRouter from SignalRouter import SignalRouter
from Bar import Bar from Bar import Bar
from Module import Module from Module import Module
from parse_config_file import get_bar_config_and_module_config_list from parse_config_file import get_bar_config_and_monitor_list
def sigterm_handler(signal, frame): def sigterm_handler(signal, frame):
delete_pidfile(pidfile_name()) delete_pidfile(pidfile_name())
@ -17,26 +17,28 @@ def main():
else: else:
config_file = str(getenv("HOME")) + "/.config/easyconf-lemonbar.yml" config_file = str(getenv("HOME")) + "/.config/easyconf-lemonbar.yml"
#bar_config, module_config_list = get_bar_config_and_module_config_list(config_file) bar_config, monitor_list = get_bar_config_and_monitor_list(config_file)
get_bar_config_and_module_config_list(config_file) padding = bar_config["padding"]
#padding = bar_config["padding"] seperator = bar_config["seperator"]
#seperator = bar_config["seperator"] margin = bar_config["margin"]
#margin = bar_config["margin"]
#signal_router = SignalRouter() signal_router = SignalRouter()
#bar = Bar(seperator, margin) bar = Bar(seperator, margin)
#for module_config in module_config_list: for monitor in monitor_list:
# module = Module(module_config, padding, bar) bar.add_monitor(monitor)
# bar.add_module(module) module_config_list = monitor_list[monitor]["modules"]
# module.start_thread() for module_config in module_config_list.values():
# if module.signal != 0: module = Module(module_config, padding, bar)
# signal_router.register_signal_thread(module.signal, module.ident) bar.add_module(monitor, module)
module.start_thread()
if module.signal != 0:
signal_router.register_signal_thread(module.signal, module.ident)
#create_pidfile(pidfile_name()) create_pidfile(pidfile_name())
#signal(SIGTERM, sigterm_handler) signal(SIGTERM, sigterm_handler)
if __name__ == "__main__": if __name__ == "__main__":
main() main()

View file

@ -2,7 +2,7 @@ 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 from signal import SIGRTMIN, SIGRTMAX
def get_bar_config_and_module_config_list(filename): def get_bar_config_and_monitor_list(filename):
config_schema = Schema({ config_schema = Schema({
"bar": { "bar": {
Optional("config"): { Optional("config"): {
@ -57,7 +57,6 @@ def get_bar_config_and_module_config_list(filename):
try: try:
validated_config = config_schema.validate(config_file) validated_config = config_schema.validate(config_file)
return validated_config return validated_config["bar"]["config"], validated_config["bar"]["monitor"]
#return validated_config["bar"]["config"], validated_config["bar"]["modules"]
except SchemaError as se: except SchemaError as se:
raise se raise se