easyconf-lemonbar/easyconf_lemonbar/Bar.py

43 lines
1.5 KiB
Python
Raw Normal View History

2023-03-11 23:52:47 +00:00
class Bar:
2023-03-12 00:36:22 +00:00
def __init__(self, seperator, margin):
self.monitors = {}
2023-03-12 00:36:22 +00:00
self.seperator = seperator
self.margin = margin
def add_monitor(self, monitor):
self.monitors[monitor] = { "left": [], "center": [], "right": [] }
def add_module(self, monitor, module):
2023-03-11 23:52:47 +00:00
match module.alignment:
case "left":
self.monitors[monitor]["left"].append(module)
2023-03-11 23:52:47 +00:00
case "center":
self.monitors[monitor]["center"].append(module)
2023-03-11 23:52:47 +00:00
case "right":
self.monitors[monitor]["right"].append(module)
2023-03-11 23:52:47 +00:00
2023-03-12 00:36:22 +00:00
def __print_alignment_group(self, alignment_group):
for index, module in enumerate(alignment_group):
2023-03-11 23:52:47 +00:00
print(module.text, end='')
2023-03-12 00:36:22 +00:00
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"])
2023-03-12 00:36:22 +00:00
print("%{r}", end='')
self.__print_alignment_group(self.monitors[monitor]["right"])
2023-03-12 00:36:22 +00:00
print(self.margin, end='')
2023-03-11 23:52:47 +00:00
print(flush=True)