Repository navigation
Expand file tree
/
Copy pathController.py
More file actions
309 lines (233 loc) · 11.9 KB
/
Copy pathController.py
File metadata and controls
309 lines (233 loc) · 11.9 KB
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
import bin.View as View
from bin.Model import Model
from lib.LXFunctions import *
class Controller:
def __init__(self):
self.view = View
self.model = Model()
def core(self):
# Open main menu by default
self.openMainMenu()
# --------------- Event Handlers ---------------
#
# View's callback function, in order to
# proccess users interactions/events
#
def menuEventHandler(self, event, data):
if event == None: # Exit on window close
self.currentWindow.close()
else: # Open requested window using the event name as the class name to instantiate
# Save menu selection and remove white space from event name, thus now matching the class in the view
menuSelection = event.replace(" ", "")
self.currentWindow.close()
eval(f"self.open{menuSelection}()")
def dmxCalculatorEventHandler(self, event, data):
# Exit on user exit
# TODO DMX Calc Functionality
if event == None:
self.currentWindow.close()
if event == "Close":
self.currentWindow.close()
self.openMainMenu()
def wvaCalculatorEventHandler(self, event, data):
# Exit on user exit
if event == None:
self.currentWindow.close()
if event == "Close":
self.currentWindow.close()
self.openMainMenu()
# Calculate Button
if event == "Calculate":
# If at least one field is blank
if data['w'] == '' or data['v'] == '' or data['a'] == '':
# Not all fields can be blank
if not (data['w'] == '' and data['v'] == '' and data['a'] == ''):
# Two fields can not be blank
total: float = data['w'] + data['v'] + data['a']
if not (total == data['w'] or total == data['v'] or total == data['a']):
# If all checks are met, run calculation
result, solvedFor = powerCalculator(w=data['w'], v=data['v'], a=data['a'])
# And Display to the user in the appropriate input field
self.currentWindow.window[solvedFor].update(result)
# Error cases will popup to user
else:
self.view.gui.popup_error("Only one field can be left blank!", title='Error')
else:
self.view.gui.popup_error("Fill out the formula first!", title='Error')
else:
self.view.gui.popup_error("At least one field must be blank!", title='Error')
def roscoViewerEventHandler(self, event, data):
# Exit on user exit
if event == None:
self.currentWindow.close()
if event == "Close":
self.currentWindow.close()
self.openMainMenu()
# Load image per input upon button press
if event == 'Lookup':
fileName = f"{data['gel']}.jpg"
bio = io.BytesIO()
# Check if file is already downloaded
if not os.path.exists(fileName):
# If image downloads successfuly
if downloadImage(f"https://us.rosco.com/sites/default/files/content/filters//{data['gel_type'][0]}/{data['gel']}.jpg"):
imageToMemory(fileName, 600, 600, bio)
# Update image view with image downloaded
self.currentWindow.window['img'].update(data=bio.getvalue())
# Error if not success
else:
self.view.gui.popup_error("Please try another gel, that one didn't work!", title='Error')
else:
imageToMemory(fileName, 600, 600, bio)
# Update image view with image downloaded
self.currentWindow.window['img'].update(data=bio.getvalue())
def fixtureLibraryEventHandler(self, event, data):
# TODO Add new fixture functionality
# Model key
mKey = 'FIXTURE_LIBRARY'
# Saves fixture data regardless of data being updated
def saveFixture():
for key in data.keys():
# Extract selected fixture from data
if key == 'selected_fixture':
selectedFixture = data['selected_fixture'][0]
elif key == 'name':
# If the name was changed, update it
if not data[key] == data['selected_fixture'][0]:
self.model.rename(data[key], mKey, selectedFixture)
# Get updated model and determin the fixture to select upon update
selectedFixture = data['name']
fixtureData = self.model.get('FIXTURE_LIBRARY').keys()
updatedIndex = len(fixtureData) - 1
# Refresh fixture list
self.currentWindow.window['selected_fixture'].update(values=fixtureData, set_to_index=updatedIndex)
# Update model with data to save
else:
# Handle t/f Listboxes
if isinstance(data[key], list):
if data[key][0] == 'True':
self.model.set(True, mKey, selectedFixture, key)
else:
self.model.set(False, mKey, selectedFixture, key)
else:
self.model.set(data[key], mKey, selectedFixture, key)
# Fixture model
fixtureData = self.model.get(mKey)
# Exit on user exit, without saving
if event == None:
self.currentWindow.close()
# Save and return to the menu
if event == "Save and Close":
self.currentWindow.close()
saveFixture()
self.openMainMenu()
# Save only
if event == "Save":
saveFixture()
# User selected a fixture from the list
if event == "selected_fixture":
selectedFixture = data['selected_fixture'][0]
# If the dataColumn is hidden, unhide it
if not self.currentWindow.window['dataColumn'].visible:
self.currentWindow.window['dataColumn'].update(visible=True)
# Set data in the dataColumn
# TODO Add name update functionality
self.currentWindow.window['name'].update(selectedFixture)
self.currentWindow.window['lamp_type'].update(fixtureData[selectedFixture]['lamp_type'])
self.currentWindow.window['fixture_type'].update(fixtureData[selectedFixture]['fixture_type'])
self.currentWindow.window['degree_min'].update(fixtureData[selectedFixture]['degree_min'])
self.currentWindow.window['degree_max'].update(fixtureData[selectedFixture]['degree_max'])
self.currentWindow.window['wattage'].update(fixtureData[selectedFixture]['wattage'])
self.currentWindow.window['volts'].update(fixtureData[selectedFixture]['volts'])
self.currentWindow.window['amperage'].update(fixtureData[selectedFixture]['amperage'])
self.currentWindow.window['addresses'].update(fixtureData[selectedFixture]['addresses'])
# Handle bool values in data set
if fixtureData[selectedFixture]['3-pin-data']:
self.currentWindow.window['3-pin-data'].update(set_to_index=0)
else:
self.currentWindow.window['3-pin-data'].update(set_to_index=1)
if fixtureData[selectedFixture]['5-pin-data']:
self.currentWindow.window['5-pin-data'].update(set_to_index=0)
else:
self.currentWindow.window['5-pin-data'].update(set_to_index=1)
def settingsEventHandler(self, event, data):
# Model key
mKey = 'SETTINGS'
# Exit on user exit, without saving
if event == None:
self.currentWindow.close()
# Save and return to the menu
if event == "Save and Close":
self.currentWindow.close()
self.model.set(data['mode'], mKey, 'mode')
self.openMainMenu()
def dmxCalculatorEventHandler(self, event, data):
# Exit on user exit, without saving
if event == None:
self.currentWindow.close()
if event == "Close":
self.currentWindow.close()
self.openMainMenu()
# Returns a popup with calculation completed
if event == "Calculate":
# Check if fields were filled out correctly
if data['numberFixtures'] == '':
self.view.gui.popup_ok("You must enter the number of fixtures you would to calculate for.")
# Check if a fixture was not selected from the listbox
elif data['selected_fixture'] == []:
self.view.gui.popup_ok("You must select the fixture you would to calculate for.")
else:
# Model key
mKey = 'FIXTURE_LIBRARY'
# Checking if a starting address was passed
if not data['startingAddress'] == '':
startingAddress = int(data['startingAddress'])
else:
startingAddress = None
# Get the number of addresses a fixture uses from the model
fixtureAddresses = int(self.model.get(mKey, data['selected_fixture'][0], 'addresses'))
# Handle optional starting address
if startingAddress == None:
dmxAddresses = addressCalculator(int(fixtureAddresses), int(data['numberFixtures']))
else:
dmxAddresses = addressCalculator(fixtureAddresses, int(data['numberFixtures']), startingAddress)
# Display the result in an OK popup window
self.view.gui.popup_ok(str(dmxAddresses), title='Result')
# ------------------------------------------------
def openMainMenu(self):
# Open the window and pass in menu options from model
menuOptions = self.model.get('MENU_OPTIONS')
self.currentWindow = self.view.MainMenu(self, menuOptions)
self.currentWindow.open()
def openSettings(self):
# Opens the settings window with settings from the model
settingsData = self.model.get('SETTINGS')
self.currentWindow = self.view.Settings(self, settingsData)
self.currentWindow.open()
def openWVACalculator(self):
# Opens the WVA Calculator window
self.currentWindow = self.view.WVACalculator(self, None)
self.currentWindow.open()
def openFixtureLibrary(self):
# Opens the fixture library window with the fixture library from the model
# Only passes in the fixture names for list creation
fixtureData = self.model.get('FIXTURE_LIBRARY').keys()
self.currentWindow = self.view.FixtureLibrary(self, fixtureData)
self.currentWindow.open()
def openRoscoGelDataSheetViewer(self):
# Opens the rosco data sheet veiwer window
# Passes in supported gel types
supportedGels = self.model.get('SUPPORTED_GELS')
self.currentWindow = self.view.RoscoGelDataSheetViewer(self, supportedGels)
self.currentWindow.open()
def openDMXAddressCalculator(self):
# TODO Check if passing keys() already returns a list, and if it needs to be redefined in the view
# Opens the DMX ddress Calculator window
# Only passes in the fixture names for list creation
fixtureData = self.model.get('FIXTURE_LIBRARY').keys()
self.currentWindow = self.view.DMXAddressCalculator(self, fixtureData)
self.currentWindow.open()
# Start the program
if __name__ == '__main__':
lxtoolkit = Controller()
lxtoolkit.core()