-
Notifications
You must be signed in to change notification settings - Fork 0
/
showbikes.py
49 lines (41 loc) · 1.8 KB
/
showbikes.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
#!/usr/bin/env python3
import curses
from datetime import datetime
from curses import wrapper
from widgets import Table, rectangle, Label
class bikeswin:
def __init__(self, xpos, ypos, width, height):
self.win = curses.newwin(height, width, ypos, xpos)
self.height = height
self.width = width
self.xpos = xpos
self.ypos = ypos
self.label = Label(self.win, 0, 0, self.width, "Bikes not connected").draw()
self.table = Table(self.win,1,2,width-2,height-3,[{
"text": lambda col,row,bike,data: ("#%s" % bike["bike_number"]) if "bike_number" in bike else "",
"attributes":[curses.color_pair(0),curses.color_pair(3)],
"width": 8
},{
"text": lambda col,row,bike,data: str(bike["address"] or "") if "address" in bike else "",
"attributes":[curses.color_pair(0),curses.color_pair(3)],
"width":width-2-8-5
},{
"text": lambda col,row,bike,data: ("%dm" % bike["distance"]) if "distance" in bike else "",
"attributes":[curses.color_pair(0),curses.color_pair(3)],
"width":5
}],
{
"line_delay": 0.025
})
rectangle(self.win,0,1,self.width,self.height-1)
def update(self, data):
curses.init_pair(3, curses.COLOR_WHITE, curses.COLOR_BLUE)
try:
self.label.update_text("Bikes %s" % data['time']).draw()
bikes = data["bikes"]
bikes.sort(key=lambda bike: bike["distance"])
self.table.apply_data(bikes)
except Exception as msg:
self.win.addstr(2,2,"Something went wrong! " + str(msg), curses.color_pair(1))
def show(self):
self.win.refresh()