diff --git a/.gitignore b/.gitignore index 3191902..54c6be6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ data/testing_config.yml -__pycache__ +easyconf-lemonbar/__pycache__ +pyrightconfig.json diff --git a/easyconf-lemonbar/Bar.py b/easyconf-lemonbar/Bar.py new file mode 100644 index 0000000..b3995a7 --- /dev/null +++ b/easyconf-lemonbar/Bar.py @@ -0,0 +1,27 @@ +class Bar: + def __init__(self): + self.left = [] + self.center = [] + self.right = [] + + def add_module(self, module): + match module.alignment: + case "left": + self.left.append(module) + case "center": + self.center.append(module) + case "right": + self.right.append(module) + + def print(self): + print("%{l}", end='') + for module in self.left: + print(module.text, end='') + print("%{c}", end='') + for module in self.center: + print(module.text, end='') + print("%{r}", end='') + for module in self.right: + print(module.text, end='') + + print(flush=True) diff --git a/easyconf-lemonbar/Module.py b/easyconf-lemonbar/Module.py index ec427c0..c40d449 100644 --- a/easyconf-lemonbar/Module.py +++ b/easyconf-lemonbar/Module.py @@ -1,4 +1,3 @@ -from os import altsep from threading import Thread from subprocess import run from time import sleep @@ -9,7 +8,7 @@ class Module: text = "" # Parse the raw module configuration - def __init__(self, module_config, padding, all_modules): + def __init__(self, module_config, padding, bar): # Attributes that will be extracted from the config self.name = "" self.alignment = "" @@ -19,9 +18,8 @@ class Module: self.refresh = 0 self.post ="" self.padding = padding - # We pass in a tuple containing the lists of modules sorted by - # alignment, so we can print all of them. - self.all_modules = all_modules + # We pass in the Bar which contains the modules we can print it. + self.bar = bar for option in module_config: match option: @@ -91,8 +89,8 @@ class Module: while True: # Generate new text self.generate_text() - - print(self.text) + # Print the entire bar + self.bar.print() if self.refresh == 0: break diff --git a/easyconf-lemonbar/main.py b/easyconf-lemonbar/main.py index af59850..3c5f740 100644 --- a/easyconf-lemonbar/main.py +++ b/easyconf-lemonbar/main.py @@ -1,3 +1,4 @@ +from Bar import Bar from Module import Module from parse_config_file import get_bar_config_and_module_config_list @@ -5,21 +6,11 @@ def main(): bar_config, module_config_list = get_bar_config_and_module_config_list("/home/noah/src/easyconf-lemonbar/data/testing_config.yml") padding = bar_config["padding"] - left_modules = [] - center_modules = [] - right_modules = [] - - all_modules = (left_modules, center_modules, right_modules) + bar = Bar() for module_config in module_config_list: - module = Module(module_config, padding, all_modules) - match module.alignment: - case "left": - left_modules.append(module) - case "center": - center_modules.append(module) - case "right": - right_modules.append(module) + module = Module(module_config, padding, bar) + bar.add_module(module) module.start_thread() diff --git a/pyrightconfig.json b/pyrightconfig.json deleted file mode 100644 index 9e1c04a..0000000 --- a/pyrightconfig.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "venv": "easyconf-lemonbar-yKjthnqC-py3.10", - "venvPath": "/home/noah/.cache/pypoetry/virtualenvs" -}