implemented Bar object

This commit is contained in:
Noah Swerhun 2023-03-11 17:52:47 -06:00
parent 03e19af3c7
commit ae7679866a
5 changed files with 38 additions and 25 deletions

3
.gitignore vendored
View file

@ -1,2 +1,3 @@
data/testing_config.yml data/testing_config.yml
__pycache__ easyconf-lemonbar/__pycache__
pyrightconfig.json

27
easyconf-lemonbar/Bar.py Normal file
View file

@ -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)

View file

@ -1,4 +1,3 @@
from os import altsep
from threading import Thread from threading import Thread
from subprocess import run from subprocess import run
from time import sleep from time import sleep
@ -9,7 +8,7 @@ class Module:
text = "" text = ""
# Parse the raw module configuration # 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 # Attributes that will be extracted from the config
self.name = "" self.name = ""
self.alignment = "" self.alignment = ""
@ -19,9 +18,8 @@ class Module:
self.refresh = 0 self.refresh = 0
self.post ="" self.post =""
self.padding = padding self.padding = padding
# We pass in a tuple containing the lists of modules sorted by # We pass in the Bar which contains the modules we can print it.
# alignment, so we can print all of them. self.bar = bar
self.all_modules = all_modules
for option in module_config: for option in module_config:
match option: match option:
@ -91,8 +89,8 @@ class Module:
while True: while True:
# Generate new text # Generate new text
self.generate_text() self.generate_text()
# Print the entire bar
print(self.text) self.bar.print()
if self.refresh == 0: if self.refresh == 0:
break break

View file

@ -1,3 +1,4 @@
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_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") 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"] padding = bar_config["padding"]
left_modules = [] bar = Bar()
center_modules = []
right_modules = []
all_modules = (left_modules, center_modules, right_modules)
for module_config in module_config_list: for module_config in module_config_list:
module = Module(module_config, padding, all_modules) module = Module(module_config, padding, bar)
match module.alignment: bar.add_module(module)
case "left":
left_modules.append(module)
case "center":
center_modules.append(module)
case "right":
right_modules.append(module)
module.start_thread() module.start_thread()

View file

@ -1,4 +0,0 @@
{
"venv": "easyconf-lemonbar-yKjthnqC-py3.10",
"venvPath": "/home/noah/.cache/pypoetry/virtualenvs"
}