implemented Bar object
This commit is contained in:
parent
03e19af3c7
commit
ae7679866a
5 changed files with 38 additions and 25 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
|||
data/testing_config.yml
|
||||
__pycache__
|
||||
easyconf-lemonbar/__pycache__
|
||||
pyrightconfig.json
|
||||
|
|
27
easyconf-lemonbar/Bar.py
Normal file
27
easyconf-lemonbar/Bar.py
Normal 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)
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
{
|
||||
"venv": "easyconf-lemonbar-yKjthnqC-py3.10",
|
||||
"venvPath": "/home/noah/.cache/pypoetry/virtualenvs"
|
||||
}
|
Loading…
Reference in a new issue