-
Notifications
You must be signed in to change notification settings - Fork 0
/
ModSidebar.py
79 lines (66 loc) · 1.77 KB
/
ModSidebar.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import TermUI as tui
import TermIntr as ti
import TermCanvas as tc
class Sidebar:
def __init__(self,name,visual,interactive):
self.name=name
self.visual=visual
self.intr=interactive
def addSidebar(sidebar):
index=elems.visible
intrs.addIChild(sidebar.intr)
elems.addChild(sidebar.visual)
scroller.addValue(sidebar.name)
if index is None:
selectSidebar(sidebar)
def deleteSidebar(sidebar):
index=elems.children.index(sidebar.visual)
scroller.removeIndex(index)
intrs.orphanIChild(sidebar.intr)
elems.disownChild(sidebar.visual)
def selectSidebar(sidebar):
index=elems.children.index(sidebar.visual)
selectSidebarI(index)
def selectSidebarI(index):
scroller.setPosition(index)
intrs.select(index)
elems.switchTo(index)
class SidebarPos(tui.GenElement):
def __init__(self,scroller):
self.scroller=scroller
def innards(self):
pos=self.scroller.position
if pos is not None:
return tui.Text(f"(at {self.scroller.position+1}/{len(self.scroller.values)})")
else:
return tui.Text(f"(No sidebars!)")
intrs=None
elems=None
scroller=None
def modInit(modules,config,lock):
global intrs,elems,scroller
intrs=ti.Switcher(None)
elems=tui.ElementSwitcher(visible=None)
scroller=ti.Roller([],None,"horizontal",up=config["next"],down=config["prev"])
tracker=SidebarPos(scroller)
@scroller.onChange
def scroll(pos,val):
intrs.select(pos)
elems.switchTo(pos)
modules.ui.addElem(
tui.VStack(
tui.HStack(
tui.Text("*|Sidebars|*").pad(right=1),
tracker
).align(alignH="middle"),
scroller.align(alignH="middle")
.pad(right=2,left=2),
tui.Seperator("horizontal",tui.lines.dotted.h,style="`")
.pad(left=1,right=1),
(elems
.pad(left=2,right=2)
,100)
).align(alignH="right")
)
modules.ui.addIntr(scroller)
modules.ui.addIntr(intrs)