easyconf-lemonbar/easyconf_lemonbar/Bar.py

42 lines
1.5 KiB
Python

class Bar:
def __init__(self, seperator, margin):
self.monitors = {}
self.seperator = seperator
self.margin = margin
def add_monitor(self, monitor):
self.monitors[monitor] = { "left": [], "center": [], "right": [] }
def add_module(self, monitor, module):
match module.alignment:
case "left":
self.monitors[monitor]["left"].append(module)
case "center":
self.monitors[monitor]["center"].append(module)
case "right":
self.monitors[monitor]["right"].append(module)
def __print_alignment_group(self, alignment_group):
for index, module in enumerate(alignment_group):
print(module.text, end='')
if len(module.text) > 0:
for i in range(index+1, len(alignment_group)):
if len(alignment_group[i].text) > 0:
print(self.seperator, end='')
break
def print(self):
for monitor in self.monitors:
print("%{S" + str(monitor) + "}", end='')
print("%{l}" + self.margin, end='')
self.__print_alignment_group(self.monitors[monitor]["left"])
print("%{c}", end='')
self.__print_alignment_group(self.monitors[monitor]["center"])
print("%{r}", end='')
self.__print_alignment_group(self.monitors[monitor]["right"])
print(self.margin, end='')
print(flush=True)