frobarng: Mirroring and more
This commit is contained in:
parent
7d60269b49
commit
6690f3aa0d
|
@ -102,6 +102,23 @@ class Module(ComposableText):
|
||||||
def __init__(self, parent: "Side") -> None:
|
def __init__(self, parent: "Side") -> None:
|
||||||
super().__init__(parent=parent)
|
super().__init__(parent=parent)
|
||||||
self.sections: list[Section] = []
|
self.sections: list[Section] = []
|
||||||
|
self.mirroring: Module | None = None
|
||||||
|
self.mirrors: list[Module] = list()
|
||||||
|
|
||||||
|
def mirror(self, module: "Module") -> None:
|
||||||
|
self.mirroring = module
|
||||||
|
module.mirrors.append(self)
|
||||||
|
|
||||||
|
def getSections(self) -> list[Section]:
|
||||||
|
if self.mirroring:
|
||||||
|
return self.mirroring.sections
|
||||||
|
else:
|
||||||
|
return self.sections
|
||||||
|
|
||||||
|
def updateMarkup(self) -> None:
|
||||||
|
super().updateMarkup()
|
||||||
|
for mirror in self.mirrors:
|
||||||
|
mirror.updateMarkup()
|
||||||
|
|
||||||
|
|
||||||
class Alignment(enum.Enum):
|
class Alignment(enum.Enum):
|
||||||
|
@ -122,7 +139,7 @@ class Side(ComposableText):
|
||||||
text = "%{" + self.alignment.value + "}"
|
text = "%{" + self.alignment.value + "}"
|
||||||
lastSection: Section | None = None
|
lastSection: Section | None = None
|
||||||
for module in self.modules:
|
for module in self.modules:
|
||||||
for section in module.sections:
|
for section in module.getSections():
|
||||||
if section.isHidden():
|
if section.isHidden():
|
||||||
continue
|
continue
|
||||||
if lastSection is None:
|
if lastSection is None:
|
||||||
|
@ -184,15 +201,15 @@ class Bar(ComposableText):
|
||||||
self.screens.append(screen)
|
self.screens.append(screen)
|
||||||
|
|
||||||
async def run(self) -> None:
|
async def run(self) -> None:
|
||||||
proc = await asyncio.create_subprocess_exec(
|
cmd = [
|
||||||
"lemonbar",
|
"lemonbar",
|
||||||
"-b",
|
"-b",
|
||||||
"-a",
|
"-a",
|
||||||
"64",
|
"64",
|
||||||
"-f",
|
"-f",
|
||||||
"DejaVuSansM Nerd Font:size=10",
|
"DejaVuSansM Nerd Font:size=10",
|
||||||
stdin=asyncio.subprocess.PIPE,
|
]
|
||||||
)
|
proc = await asyncio.create_subprocess_exec(*cmd, stdin=asyncio.subprocess.PIPE)
|
||||||
|
|
||||||
async def refresher() -> None:
|
async def refresher() -> None:
|
||||||
assert proc.stdin
|
assert proc.stdin
|
||||||
|
@ -214,18 +231,13 @@ class Bar(ComposableText):
|
||||||
provider: "Provider",
|
provider: "Provider",
|
||||||
alignment: Alignment = Alignment.LEFT,
|
alignment: Alignment = Alignment.LEFT,
|
||||||
screenNum: int | None = None,
|
screenNum: int | None = None,
|
||||||
screenCount: int | None = None,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
screenNum: the provider will be added on this screen if set, all otherwise
|
screenNum: the provider will be added on this screen if set, all otherwise
|
||||||
screenCount: the provider will be added if there is this many screens,
|
|
||||||
always otherwise
|
|
||||||
"""
|
"""
|
||||||
modules = list()
|
modules = list()
|
||||||
for s, screen in enumerate(self.screens):
|
for s, screen in enumerate(self.screens):
|
||||||
if (screenCount is None or len(self.screens) == screenCount) and (
|
if screenNum is None or s == screenNum:
|
||||||
screenNum is None or s == screenNum
|
|
||||||
):
|
|
||||||
side = screen.sides[alignment]
|
side = screen.sides[alignment]
|
||||||
module = Module(parent=side)
|
module = Module(parent=side)
|
||||||
side.modules.append(module)
|
side.modules.append(module)
|
||||||
|
@ -243,32 +255,77 @@ class Provider:
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
|
||||||
class TimeProvider(Provider):
|
class MirrorProvider(Provider):
|
||||||
|
def __init__(self) -> None:
|
||||||
|
super().__init__()
|
||||||
|
self.module: Module
|
||||||
|
|
||||||
async def run(self) -> None:
|
async def run(self) -> None:
|
||||||
sections = list()
|
self.module = self.modules[0]
|
||||||
for module in self.modules:
|
for module in self.modules[1:]:
|
||||||
section = Section(parent=module)
|
module.mirror(self.module)
|
||||||
module.sections.append(section)
|
|
||||||
sections.append(section)
|
|
||||||
# FIXME Allow for mirror(ed) modules so no need for updaters to handle all
|
class SingleSectionProvider(MirrorProvider):
|
||||||
|
def __init__(self) -> None:
|
||||||
|
super().__init__()
|
||||||
|
self.section: Section
|
||||||
|
|
||||||
|
async def run(self) -> None:
|
||||||
|
await super().run()
|
||||||
|
self.section = Section(parent=self.module)
|
||||||
|
self.module.sections.append(self.section)
|
||||||
|
|
||||||
|
|
||||||
|
class StaticProvider(SingleSectionProvider):
|
||||||
|
def __init__(self, text: str) -> None:
|
||||||
|
self.text = text
|
||||||
|
|
||||||
|
async def run(self) -> None:
|
||||||
|
await super().run()
|
||||||
|
self.section.setText(self.text)
|
||||||
|
|
||||||
|
|
||||||
|
class TimeProvider(SingleSectionProvider):
|
||||||
|
async def run(self) -> None:
|
||||||
|
await super().run()
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
now = datetime.datetime.now()
|
now = datetime.datetime.now()
|
||||||
for s, section in enumerate(sections):
|
|
||||||
# section.setText(now.strftime("%a %y-%m-%d %H:%M:%S.%f"))
|
# section.setText(now.strftime("%a %y-%m-%d %H:%M:%S.%f"))
|
||||||
section.setText("-" * (now.second % 10))
|
self.section.setText("-" * (now.second % 10))
|
||||||
remaining = 1 - now.microsecond / 1000000
|
remaining = 1 - now.microsecond / 1000000
|
||||||
await asyncio.sleep(remaining)
|
await asyncio.sleep(remaining)
|
||||||
|
|
||||||
|
|
||||||
async def main() -> None:
|
async def main() -> None:
|
||||||
bar = Bar()
|
bar = Bar()
|
||||||
bar.addProvider(TimeProvider())
|
dualScreen = len(bar.screens) > 1
|
||||||
bar.addProvider(TimeProvider(), screenNum=1)
|
|
||||||
bar.addProvider(TimeProvider(), alignment=Alignment.CENTER, screenCount=2)
|
bar.addProvider(StaticProvider(text="i3 workspaces"), alignment=Alignment.LEFT)
|
||||||
bar.addProvider(TimeProvider(), alignment=Alignment.CENTER)
|
if dualScreen:
|
||||||
bar.addProvider(TimeProvider(), alignment=Alignment.RIGHT)
|
bar.addProvider(
|
||||||
|
StaticProvider(text="i3 title"), screenNum=0, alignment=Alignment.CENTER
|
||||||
|
)
|
||||||
|
bar.addProvider(
|
||||||
|
StaticProvider(text="mpris"),
|
||||||
|
screenNum=1 if dualScreen else None,
|
||||||
|
alignment=Alignment.CENTER,
|
||||||
|
)
|
||||||
|
|
||||||
|
bar.addProvider(StaticProvider("C L M T B"), alignment=Alignment.RIGHT)
|
||||||
|
bar.addProvider(
|
||||||
|
StaticProvider("pulse"),
|
||||||
|
screenNum=1 if dualScreen else None,
|
||||||
|
alignment=Alignment.RIGHT,
|
||||||
|
)
|
||||||
|
bar.addProvider(
|
||||||
|
StaticProvider("network"),
|
||||||
|
screenNum=0 if dualScreen else None,
|
||||||
|
alignment=Alignment.RIGHT,
|
||||||
|
)
|
||||||
bar.addProvider(TimeProvider(), alignment=Alignment.RIGHT)
|
bar.addProvider(TimeProvider(), alignment=Alignment.RIGHT)
|
||||||
|
|
||||||
await bar.run()
|
await bar.run()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue