-
Notifications
You must be signed in to change notification settings - Fork 0
/
ModStatusText.py
61 lines (50 loc) · 1.38 KB
/
ModStatusText.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
import TermUI as tui
class StatusText(tui.GenElement):
def __init__(self):
self.text=tui.Text("")
self.vanishing=""
self.lingering=""
self.counter=0
def _updateText(self):
if self.lingering and self.vanishing:
self.text.text=self.lingering+", "+self.vanishing
else:
self.text.text=self.lingering+self.vanishing
def queueText(self,text,frames,seconds=3):
self.counter+=1
self.vanishing=text
self._updateText()
frames.schedule(0,tui.sched.framesLater)
counter=self.counter
def conditionalClear(frames):
nonlocal self,counter
if self.counter==counter:
self.vanishing=""
self._updateText()
else:
return tui.NoFrame
frames.schedule(seconds,tui.sched.secondsLater,callback=conditionalClear)
def setLingering(self,text,frames):
self.lingering=text
self._updateText()
frames.schedule(0,tui.sched.framesLater)
def clear(self,frames):
self.vanishing=""
self._updateText()
def size(self):
return self.text.size()
def render(self,cnv,x,y,ph,pw):
self.text.render(cnv,x,y,ph,pw)
def setLingering(text):
statusText.setLingering(text,frames)
def clear():
statusText.clear(frames)
def queueText(text,seconds=3):
statusText.queueText(text,frames,seconds=seconds)
statusText=StatusText()
shown=statusText.align(alignV="bottom")
frames=None
def modInit(modules,config,lock):
modules.ui.addElem(shown)
global frames
frames=modules.ui.root.frames