new config schema is now readable, bar prints properly
This commit is contained in:
parent
90bbfcd7fe
commit
841218a6b7
4 changed files with 42 additions and 36 deletions
|
@ -1,20 +1,20 @@
|
|||
class Bar:
|
||||
def __init__(self, seperator, margin):
|
||||
self.left = []
|
||||
self.center = []
|
||||
self.right = []
|
||||
|
||||
self.monitors = {}
|
||||
self.seperator = seperator
|
||||
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:
|
||||
case "left":
|
||||
self.left.append(module)
|
||||
self.monitors[monitor]["left"].append(module)
|
||||
case "center":
|
||||
self.center.append(module)
|
||||
self.monitors[monitor]["center"].append(module)
|
||||
case "right":
|
||||
self.right.append(module)
|
||||
self.monitors[monitor]["right"].append(module)
|
||||
|
||||
def __print_alignment_group(self, alignment_group):
|
||||
for index, module in enumerate(alignment_group):
|
||||
|
@ -26,13 +26,17 @@ class Bar:
|
|||
break
|
||||
|
||||
def print(self):
|
||||
for monitor in self.monitors:
|
||||
print("%{S" + str(monitor) + "}", end='')
|
||||
print("%{l}" + self.margin, end='')
|
||||
self.__print_alignment_group(self.left)
|
||||
self.__print_alignment_group(self.monitors[monitor]["left"])
|
||||
|
||||
print("%{c}", end='')
|
||||
self.__print_alignment_group(self.center)
|
||||
self.__print_alignment_group(self.monitors[monitor]["center"])
|
||||
|
||||
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)
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
from parse_config_file import get_bar_config_and_module_config_list
|
||||
from os import getenv
|
||||
from os.path import exists
|
||||
|
||||
from easyconf_lemonbar.parse_config_file import get_bar_config_and_monitor_list
|
||||
|
||||
def generate_flags(bar_config):
|
||||
flags = ""
|
||||
for option in bar_config:
|
||||
|
@ -33,6 +34,6 @@ if exists("./data/testing_config.yml"):
|
|||
else:
|
||||
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))
|
||||
|
|
|
@ -5,7 +5,7 @@ from os.path import exists
|
|||
from SignalRouter import SignalRouter
|
||||
from Bar import Bar
|
||||
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):
|
||||
delete_pidfile(pidfile_name())
|
||||
|
@ -17,26 +17,28 @@ def main():
|
|||
else:
|
||||
config_file = str(getenv("HOME")) + "/.config/easyconf-lemonbar.yml"
|
||||
|
||||
#bar_config, module_config_list = get_bar_config_and_module_config_list(config_file)
|
||||
get_bar_config_and_module_config_list(config_file)
|
||||
#padding = bar_config["padding"]
|
||||
#seperator = bar_config["seperator"]
|
||||
#margin = bar_config["margin"]
|
||||
bar_config, monitor_list = get_bar_config_and_monitor_list(config_file)
|
||||
padding = bar_config["padding"]
|
||||
seperator = bar_config["seperator"]
|
||||
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:
|
||||
# module = Module(module_config, padding, bar)
|
||||
# bar.add_module(module)
|
||||
# module.start_thread()
|
||||
# if module.signal != 0:
|
||||
# signal_router.register_signal_thread(module.signal, module.ident)
|
||||
for monitor in monitor_list:
|
||||
bar.add_monitor(monitor)
|
||||
module_config_list = monitor_list[monitor]["modules"]
|
||||
for module_config in module_config_list.values():
|
||||
module = Module(module_config, padding, bar)
|
||||
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__":
|
||||
main()
|
||||
|
|
|
@ -2,7 +2,7 @@ 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):
|
||||
def get_bar_config_and_monitor_list(filename):
|
||||
config_schema = Schema({
|
||||
"bar": {
|
||||
Optional("config"): {
|
||||
|
@ -57,7 +57,6 @@ def get_bar_config_and_module_config_list(filename):
|
|||
|
||||
try:
|
||||
validated_config = config_schema.validate(config_file)
|
||||
return validated_config
|
||||
#return validated_config["bar"]["config"], validated_config["bar"]["modules"]
|
||||
return validated_config["bar"]["config"], validated_config["bar"]["monitor"]
|
||||
except SchemaError as se:
|
||||
raise se
|
||||
|
|
Loading…
Reference in a new issue