-
Notifications
You must be signed in to change notification settings - Fork 10
/
tickerGUI.py
118 lines (93 loc) · 3.05 KB
/
tickerGUI.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import io
import logging
import time
import PySimpleGUI as sg
from btcticker.config import Config
from btcticker.ticker import Ticker
logger = logging.getLogger(__name__)
def get_display_size(epd_type="2in7_4gray"):
if epd_type == "2in7":
return 176, 264
elif epd_type == "2in7_V2":
return 176, 264
elif epd_type == "2in7_4gray":
return 176, 264
elif epd_type == "2in9_V2":
return 128, 296
elif epd_type == "7in5_V2":
return 480, 800
else:
return 528, 880
def get_img_data(img):
"""Generate image data using PIL."""
bio = io.BytesIO()
img.save(bio, format="PNG")
del img
return bio.getvalue()
config = Config("home.admin/config.ini")
w, h = get_display_size(epd_type=config.main.epd_type)
if config.main.orientation == 90:
ticker = Ticker(config, h, w)
elif config.main.orientation == 270:
ticker = Ticker(config, h, w)
else:
ticker = Ticker(config, w, h)
ticker.orientation = 0
# ticker_mode = ["fiat", "height", "satfiat", "usd", "newblock"]
mode_list = []
for mode in config.main.mode_list.split(","):
mode_list.append(mode.replace('"', "").replace(" ", ""))
ticker_ind = config.main.start_mode_ind
mode_shifting = config.main.mode_shifting
days_list = []
for d in config.main.days_list.split(","):
days_list.append(int(d.replace('"', '').replace(" ", "")))
days_ind = config.main.start_days_ind
days_shifting = config.main.days_shifting
layout_list = []
for layout in config.main.layout_list.split(","):
layout_list.append(layout.replace('"', "").replace(" ", ""))
layout_ind = config.main.start_layout_ind
layout_shifting = config.main.layout_shifting
ticker.setDaysAgo(days_list[days_ind])
ticker.refresh()
ticker.build(mirror=False, mode=mode_list[ticker_ind], layout=layout_list[layout_ind])
ticker.set_min_refresh_time(120)
image_elem = sg.Image(data=get_img_data(ticker.get_image()))
col = [[image_elem]]
layout = [[sg.Column(col)]]
window = sg.Window(
'BTC Ticker',
layout,
return_keyboard_events=True,
location=(0, 0),
use_default_focus=False,
)
# loop reading the user input and displaying image, filename
i = 0
while True:
# read the form
print("Running loop...")
event, values = window.read(timeout=3000)
# perform button and keyboard operations
if event == sg.WIN_CLOSED:
break
elif event == sg.TIMEOUT_EVENT:
ticker_ind += 1
if ticker_ind >= len(mode_list) or not mode_shifting:
ticker_ind = 0
layout_ind += 1
if layout_ind >= len(layout_list) or not layout_shifting:
layout_ind = 0
days_ind += 1
if days_ind >= len(days_list) or not days_shifting:
days_ind = 0
ticker.setDaysAgo(days_list[days_ind])
ticker.refresh()
ticker.build(
mirror=False, mode=mode_list[ticker_ind], layout=layout_list[layout_ind]
)
# update window with new image
image_elem.update(data=get_img_data(ticker.get_image()))
time.sleep(2)
window.close()