-
Notifications
You must be signed in to change notification settings - Fork 3
/
interface
126 lines (83 loc) · 2.72 KB
/
interface
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
119
120
121
122
123
124
125
126
from __future__ import print_function
from __future__ import division
import pyqtgraph as pg
from pyqtgraph.Qt import QtGui
#update = None
_app = None
_update_timer = None
_ptree = None
_params = None #
_params_target_obj = None
_window_view = None
_window_layout = None
_window_imgs = []
_window_stats_label = None
_windows = []
def screen_size():
return _app.desktop().screenGeometry()
def init_app():
global _app
print('gui | Initializing QApplication')
_app = QtGui.QApplication([])
def process_events():
if _app != None:
_app.processEvents()
def toggle_param(p):
p.setValue( not p.value() )
# reading & writing to pyqtgraph.parametertree seems to be slow,
# so going to cache in an object for direct access
def _add_image_to_layout(layout, row=None, col=None, rowspan=1, colspan=1, title=''):
i = pg.ImageItem(border='w')
i.setOpts(axisOrder='row-major')
l = layout.addLayout()
l.addLabel(title)
l.nextRow()
v = l.addViewBox(lockAspect=True, invertY=True, row=row, col=col, rowspan=rowspan, colspan=colspan)
v.addItem(i)
return {'img':i, 'view':v, 'layout':l}
def init_window(x=0, y=0, w=1280, h=720, title='NightfallProject'):
global _window_view, _window_layout, _window_imgs, _window_stats_label, _windows
view = pg.GraphicsView()
layout = pg.GraphicsLayout(border=(100,100,100))
view.setCentralItem(layout)
view.setWindowTitle(title)
view.setGeometry(x, y, w, h)
view.show()
imgs = []
imgs.append( _add_image_to_layout(layout, title='capture') )
imgs.append( _add_image_to_layout(layout, title='prediction') )
layout.nextRow()
stats_label = pg.LabelItem()
layout.addItem(stats_label, colspan=3)
_window_view = view
_window_layout = layout
_window_imgs = imgs
_window_stats_label = stats_label
_windows.append(view)
def update_image(index, img_data, enabled=True, autoLevels=False, levels=(0., 1.)):
if enabled:
_window_imgs[index]['img'].setImage(img_data, autoLevels=autoLevels, levels=levels)
else:
_window_imgs[index]['img'].clear()
def update_stats(text):
_window_stats_label.setText(text)
#
#def start(sleep_s):
# global _app, _update_timer
# print('gui.start')
# if update != None:
# print('gui | Starting Update')
# _update_timer = QtCore.QTimer()
# _update_timer.timeout.connect(update)
# _update_timer.start(sleep_s * 1000)
#
# print('gui | Starting QApplication')
# _app.exec_()
#
#
def close():
global _app, _update_timer, _windows
_update_timer = None
_app.closeAllWindows()
for w in _windows:
w.close()