-
Notifications
You must be signed in to change notification settings - Fork 5
/
ui.py
93 lines (61 loc) · 2.24 KB
/
ui.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
80
81
82
83
84
85
86
87
88
89
90
91
import curses
import time
import threading, Queue
import curses.textpad as textpad
class UIThread(threading.Thread):
def __init__(self, inputChannel, sigChannel = None):
super(UIThread, self).__init__()
self.stoprequest = threading.Event()
self.myscreen = curses.initscr()
curses.start_color()
self.myscreen.border(0)
self.myscreen.timeout(0)
curses.noecho()
# curses.cbreak()
# self.myscreen.keypad(1);
self.textbox = textpad.Textbox(self.myscreen)
self.Lastinfo = []
curses.init_pair(1, curses.COLOR_BLUE, curses.COLOR_CYAN)
self.inp_q = inputChannel
self.sig_q = sigChannel
def getTextString(self):
win = curses.newwin(5, 60, 5, 40)
tb = textpad.Textbox(win)
strng = tb.edit()
return strng
def run(self):
# As long as we weren't asked to stop, try to take new tasks from the
# queue. The tasks are taken with a blocking 'get', so no CPU
# cycles are wasted while waiting.
# Also, 'get' is given a timeout, so stoprequest is always checked,
# even if there's nothing in the queue.
while not self.stoprequest.isSet():
try:
info = self.inp_q.get(True, 0.05)
self.updateInfo(info)
except Queue.Empty:
ch = self.myscreen.getch()
if ch == -1 :
continue
self.sig_q.put(ch)
if ch == ord('q'):
self.exitSelf()
def updateInfo(self, info):
self.curYPos = 2
if info.keys() != self.Lastinfo :
self.myscreen.clear()
for k in info :
strPrnt = "%s: %s"%(k, info[k])
self.myscreen.addstr(self.curYPos, 5, strPrnt )
self.curYPos += 2
self.myscreen.refresh()
self.LastInfo = info.keys()
def exitSelf(self):
self.stoprequest.set()
# curses.nocbreak()
# self.myscreen.keypad(0)
curses.echo()
curses.endwin()
def join(self, timeout=None):
super(UIThread, self).join(timeout)
self.exitSelf()