forked from Openlights/firesim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
firesimgui.py
200 lines (151 loc) · 7.04 KB
/
firesimgui.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
import logging as log
import os.path
from PySide import QtCore, QtGui, QtDeclarative, QtDeclarative
from ui.canvaswidget import CanvasWidget
from ui.fixturewidget import FixtureWidget
from util.config import Config
from models.scene import Scene
from controllers.scenecontroller import SceneController
from controllers.netcontroller import NetController
class FireSimGUI(QtCore.QObject):
def __init__(self, args=None):
QtCore.QObject.__init__(self)
self.app = QtGui.QApplication(["FireSim"])
self.args = args
self.config = Config("data/config.json")
self._selected_fixture_strand = 0
self._selected_fixture_address = 0
self._selected_fixture_pixels = 0
self.selected_fixture = None
self.scene = Scene(os.path.join(self.config.get("scene_root"), self.args.scene) + ".json")
self.scenecontroller = SceneController(app=self, scene=self.scene)
QtDeclarative.qmlRegisterType(CanvasWidget, "FireSim", 1, 0, "SimCanvas")
QtDeclarative.qmlRegisterType(FixtureWidget, "FireSim", 1, 0, "Fixture")
self.view = QtDeclarative.QDeclarativeView()
self.view.setWindowTitle("FireSim")
self.view.setResizeMode(QtDeclarative.QDeclarativeView.SizeRootObjectToView)
self.view.closeEvent = self.on_close
self.context = self.view.rootContext()
self.context.setContextProperty('main', self)
self.fixture_info_list = []
self.context.setContextProperty('fixtureInfoModel', self.fixture_info_list)
self.view.setSource(QtCore.QUrl('ui/qml/FireSimGUI.qml'))
self.root = self.view.rootObject()
self.item_frame = self.root.findChild(QtDeclarative.QDeclarativeItem)
self.canvas = self.root.findChild(CanvasWidget)
self.scenecontroller.set_canvas(self.canvas)
cw, ch = self.scenecontroller.scene.get("extents")
self.canvas.setWidth(cw)
self.canvas.setHeight(ch)
self.root.backdrop_showhide_callback.connect(self.on_btn_backdrop_showhide)
self.root.labels_showhide_callback.connect(self.on_btn_labels_showhide)
self.root.lock_callback.connect(self.on_btn_lock)
self.netcontroller = NetController(self)
self.canvas_timer = QtCore.QTimer(self)
self.canvas_timer.timeout.connect(self.on_canvas_timer)
self.view.setFixedSize(max(640, cw + 130), max(480, ch))
log.info("FireSimGUI Ready.")
self.view.show()
self.canvas_timer.start(300)
def run(self):
return self.app.exec_()
def on_close(self, e):
pass
@QtCore.Slot()
def on_canvas_timer(self):
self.canvas.stat_ups = self.netcontroller.get_ups()
self.canvas.update()
@QtCore.Slot(result=bool)
def is_backdrop_enabled(self):
return self.scenecontroller.scene.get("backdrop_enable", False)
@QtCore.Slot(result=bool)
def are_labels_enabled(self):
return self.scenecontroller.scene.get("labels_enable", False)
@QtCore.Slot(result=bool)
def is_locked(self):
return self.scenecontroller.scene.get("locked", False)
@QtCore.Slot()
def on_btn_add_fixture(self):
self.scenecontroller.add_fixture()
@QtCore.Slot()
def on_btn_clear(self):
self.scenecontroller.clear_fixtures()
@QtCore.Slot()
def on_btn_save(self):
self.scenecontroller.save_scene()
@QtCore.Slot(result=bool)
def on_btn_backdrop_showhide(self, obj):
enabled = self.scenecontroller.toggle_background_enable()
if enabled:
obj.setProperty("text", "Hide Backdrop")
else:
obj.setProperty("text", "Show Backdrop")
return enabled
@QtCore.Slot(result=bool)
def on_btn_labels_showhide(self, obj):
enabled = self.scenecontroller.toggle_labels_enable()
if enabled:
obj.setProperty("text", "Hide Labels")
else:
obj.setProperty("text", "Show Labels")
return enabled
@QtCore.Slot(result=bool)
def on_btn_lock(self, obj):
locked = self.scenecontroller.toggle_locked()
if locked:
obj.setProperty("text", "Unlock Scene")
else:
obj.setProperty("text", "Lock Scene")
return locked
def widget_selected(self, selected, fixture, multi):
self.selected_fixture = None
if multi:
pass
else:
if selected:
self.selected_fixture_strand = fixture.strand
self.selected_fixture_address = fixture.address
self.selected_fixture_pixels = fixture.pixels
else:
self.selected_fixture_strand = 0
self.selected_fixture_address = 0
self.selected_fixture_pixels = 0
if selected:
self.selected_fixture = fixture
self.update_selected_fixture_properties()
def update_selected_fixture_properties(self):
if self.selected_fixture is not None:
self.selected_fixture.strand = int(self.selected_fixture_strand)
self.selected_fixture.address = int(self.selected_fixture_address)
self.selected_fixture.pixels = int(self.selected_fixture_pixels)
self.selected_fixture.widget.update()
def _get_selected_fixture_strand(self):
return self._selected_fixture_strand
def _set_selected_fixture_strand(self, strand):
if self._selected_fixture_strand == strand:
return
self._selected_fixture_strand = strand
self.update_selected_fixture_properties()
self.on_selected_fixture_strand.emit()
def _get_selected_fixture_address(self):
return self._selected_fixture_address
def _set_selected_fixture_address(self, address):
if self._selected_fixture_address == address:
return
self._selected_fixture_address = address
self.update_selected_fixture_properties()
self.on_selected_fixture_address.emit()
def _get_selected_fixture_pixels(self):
return self._selected_fixture_pixels
def _set_selected_fixture_pixels(self, pixels):
if self._selected_fixture_pixels == pixels:
return
self._selected_fixture_pixels = pixels
self.update_selected_fixture_properties()
self.on_selected_fixture_pixels.emit()
on_selected_fixture_strand = QtCore.Signal()
on_selected_fixture_address = QtCore.Signal()
on_selected_fixture_pixels = QtCore.Signal()
selected_fixture_strand = QtCore.Property(int, _get_selected_fixture_strand, _set_selected_fixture_strand, notify=on_selected_fixture_strand)
selected_fixture_address = QtCore.Property(int, _get_selected_fixture_address, _set_selected_fixture_address, notify=on_selected_fixture_address)
selected_fixture_pixels = QtCore.Property(int, _get_selected_fixture_pixels, _set_selected_fixture_pixels, notify=on_selected_fixture_pixels)