-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoystrWheelCompanion.pyw
387 lines (366 loc) · 22.2 KB
/
coystrWheelCompanion.pyw
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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
# coystrWheel Companion v1.0.8
# Created by DuplicitousFox for [email protected]
# (c)2020, 2021 Foxtail Studios
# v.1.0: Initial Release
# v.1.0.1: Added a function that shows the text file's users and weights
# Bugfix: Corrected an issue where Weight would not update on use of "All Weight+1" in the main window
# v.1.0.2: Added a confirmation box to the Remove button.
# Bugfix: Corrected an issue where using Remove would display the wrong name.
# v.1.0.3: Bugfix: Corrected an issue where trying to use Remove on the last remaining item in the list would crash the program.
# Corrected an issue found when using Remove on the last remaining item (after the above fix) would not clear input fields.
# v.1.0.4: Added separate buttons for randomizing Background and Text color values individually.
# Changed the default BG and Text colors to black and white in the "Add New..." menu, respectively.
# Enabled "." and "'" as valid entries in the "Add New..." menu's Name input box.
# v.1.0.5: Changed where popup windows spawn. It is now based on where the main window is currently located.
# Bugfix: Corrected an issue where it was possible to add a piece to the wheel without a name, which crashed the program.
# v.1.0.6: Added a feature that checks if someone's already on the list when using "Add to Wheel", prevents the addition, and
# brings the user to that person's name in the list.
# v.1.0.7: Added a feature -- the program will now remember the RGB values of a person previously added to the wheel. The values
# update when adding a user to the wheel (and selecting "no" to if you want to import the old colors) and when using
# "Apply". If userbase.txt doesn't exist, it will generate that file for you automatically.
# v.1.0.8: Major Bugfix: Corrected an issue where trying to manually input a name in the main window dropdown box that does not exist
# would generate a program-crashing error. Added a preventative measure to disallow the "Apply" button if a name was
# manually input that does not exist. If a name is manually input into the user selection dropdown box that DOES exist,
# but the user hits Apply, the function is ignored and the user's data is populated instead.
# v.1.0.9: Code Optimization
import PySimpleGUI as sg
import random
# Variable declarations from file
file = open('wheeldata.txt', 'a+')
file.close()
file = open('userbase.txt', 'a+')
file.close()
file = open('userbase.txt')
userbase = file.readlines()
userLength = len(userbase)
userMem = []
file.close()
file = open('wheeldata.txt')
content = file.readlines()
selectLength = len(content) # sets the upper limit based on how many items are in the list.
choices = []
file.close()
win_icon = 'ftsico.ico'
separator = " "
random.seed()
#print(content) #for debug purposes only
# Parse and generate a list of names this program can use from wheeldata.txt and userbase.txt
for i in range(selectLength):
nameList = content[i].split()
choices.append(nameList[7])
for i in range(userLength):
userList = userbase[i].split()
userMem.append(userList[6])
# GUI Declarations
def newline(library):
if len(library) > 0:
prevline = library[len(library)-1]
lastchar = prevline[-1]
if lastchar != "\n":
library[len(library)-1] = library[len(library)-1] + "\n"
def rngColor(index, window): # hexidecimal color randomizer
RR, GG, BB = '-R' + str(index) + 'IN-', '-G' + str(index) + 'IN-', '-B' + str(index) + 'IN-'
colVarR = hex(int(random.randrange(0, 255, 1))).lstrip("0x").zfill(2)
colVarG = hex(int(random.randrange(0, 255, 1))).lstrip("0x").zfill(2)
colVarB = hex(int(random.randrange(0, 255, 1))).lstrip("0x").zfill(2)
valRRGGBB = "#"+str(colVarR)+str(colVarG)+str(colVarB)
window[RR].update(colVarR), window[GG].update(colVarG), window[BB].update(colVarB)
if index == 1:
window['-NAMEIN-'].update(background_color = valRRGGBB)
else:
window['-NAMEIN-'].update(text_color = valRRGGBB)
def save_file(fname, fdata):
file = open(fname,'w')
file.writelines(fdata)
file.close()
def main_win():
menu_def = [['Help', ['Help...', 'About...']], ]
title = "coystrWheel Companion"
layout = [[sg.Menu(menu_def)],
[sg.Text('Select Piece: '), sg.Text('BG Color (#RRGGBB)'), sg.Text('Text Color (#RRGGBB)'), sg.Text('Weight')],
[sg.Combo(choices, size=(15, 5), key='-selection-', enable_events=True), sg.Text('#'), sg.Input(size=(3, 1), key='-R1-', enable_events=True), sg.Input(size=(3, 1), key='-G1-', enable_events=True), sg.Input(size=(3, 1), key='-B1-', enable_events=True), sg.Text(' #'), sg.Input(size=(3, 1), key='-R2-', enable_events=True), sg.Input(size=(3, 1), key='-G2-', enable_events=True), sg.Input(size=(3, 1), key='-B2-', enable_events=True), sg.Text(' '), sg.Input(size=(3, 1), key='-WEIGHT-', enable_events=True), sg.Button('Apply')],
[sg.Button('Add New...'), sg.Button('Remove'), sg.Button('All Weight+1'), sg.Button('Show List'), sg.Button('Save')]]
return sg.Window(title, layout, icon = win_icon, finalize=True)
def addnew_win():
title = "Add New..."
layout = [[sg.Text('Name:'), sg.Input(key='-NAMEIN-', background_color='#000000', text_color='#ffffff', enable_events=True)],
[sg.Text('BG Color: #'), sg.Input(default_text="00", size=(3, 1), key='-R1IN-', enable_events=True), sg.Input(default_text="00", size=(3, 1), key='-G1IN-', enable_events=True), sg.Input(default_text="00", size=(3, 1), key='-B1IN-', enable_events=True), sg.Button('Randomize BG Color')],
[sg.Text('Name Color: #'), sg.Input(default_text="ff", size=(3, 1), key='-R2IN-', enable_events=True), sg.Input(default_text="ff", size=(3, 1), key='-G2IN-', enable_events=True),sg.Input(default_text="ff", size=(3, 1), key='-B2IN-', enable_events=True), sg.Button('Randomize Text Color')],
[sg.Checkbox('Subscriber', key='-SUBIN-'), sg.Button('Randomize Both Colors')],
[sg.Button('Add to Wheel'), sg.Button('Cancel')]]
return sg.Window(title, layout, icon = win_icon, finalize=True)
def main():
window1, window2 = main_win(), None
var8 = ' '
selectIndex = 0
while True: #event Loop
window, event, values = sg.read_all_windows()
locale_tuple = (window1.CurrentLocation()) # Set up where the windows will spawn by finding window1's location
locale = list(locale_tuple) # Tuples are immutable. Gotta store it as a list.
locale[0] = locale[0] + (window1.Size[0] / 4) # Edit x window coordinate
locale[1] = locale[1] + (window1.Size[1] / 2) # Edit y window coordinate
sg.SetOptions(window_location = locale) # All future windows will spawn here.
if window == sg.WIN_CLOSED: #if all windows were closed
break
if event == sg.WIN_CLOSED or event == 'Cancel' or event == 'Close':
window.close()
if window == window2:
window2 = None
elif window == window1:
break
elif event == 'Help...':
sg.popup('How to use coystrWheel Companion', 'Select a name from the dropdown to load and edit an existing piece. When finished editing a single piece, press the Apply button.', 'The Add New... button will pop up a new window for you to enter data and add it to the wheel. Maximum name length is 15 characters. RGB values are in Hexidecimal.', 'The Remove button will remove the currently selected piece from the wheel.', 'The All Weight+1 button adds 1 to all of the pieces weights.', 'When you are finished, click Save. Your changes will ONLY commit to file when you click Save, so do not forget to do this!', location = locale)
elif event == 'About...':
sg.popup('coystrWheel Version 1.1.1', 'coystrWheel Companion Version 1.0.9', "For my good friend, Coy. Hope all your seeds aren't trash!", location = locale)
sg.popup('Seriously, though...', 'If something breaks, hit me up on Discord.', '--Hidari', location = locale)
elif event == 'Add New...':
if not window2:
window2 = addnew_win()
elif event == 'Apply' and values['-selection-'] and (values['-selection-'] in choices) and values['-WEIGHT-'] and values['-R1-'] and values['-G1-'] and values['-B1-'] and values['-R2-'] and values['-G2-'] and values['-B2-']: # edit the current piece
content[selectIndex] = str(int(values['-WEIGHT-'], 10)) + " " + str(int(values['-R1-'], 16)) + " " + str(int(values['-G1-'], 16)) + " " + str(int(values['-B1-'], 16)) + " " + str(int(values['-R2-'], 16)) + " " + str(int(values['-G2-'], 16)) + " " + str(int(values['-B2-'], 16)) + " " + var8 + "\n"
if var8 in userMem:
i = 0
while i < len(userMem):
if var8 == userMem[i]:
userIndex = i
i += 1
newUserLine = (str(int(values['-R1-'], 16)) + ' ' + str(int(values['-G1-'], 16)) + ' ' + str(int(values['-B1-'], 16)) + ' ' + str(int(values['-R2-'], 16)) + ' ' + str(int(values['-G2-'], 16)) + ' ' + str(int(values['-B2-'], 16)) + ' ' + var8)
userbase[userIndex] = newUserLine + "\n"
save_file('userbase.txt', userbase)
else:
newline(userbase)
newUserLine = (str(int(values['-R1-'], 16)) + ' ' + str(int(values['-G1-'], 16)) + ' ' + str(int(values['-B1-'], 16)) + ' ' + str(int(values['-R2-'], 16)) + ' ' + str(int(values['-G2-'], 16)) + ' ' + str(int(values['-B2-'], 16)) + ' ' + var8)
userbase.append(newUserLine)
userMem.append(var8)
save_file('userbase.txt', userbase)
sg.popup('Changes applied successfully.', location = locale)
#print(content) # debug purposes only
elif event == 'Remove' and values['-selection-']: # remove the current piece, gotta confirm first
deletedName = choices[selectIndex]
elephant = sg.popup_yes_no('Removing ' + deletedName + ' from the wheel. Are you sure?', title='Warning: Confirmation Required!', location = locale)
if elephant == 'Yes':
content.pop(selectIndex)
choices.pop(selectIndex)
if content != []: #if there's more on the wheel...
values['-selection-'] = values['-selection-'][0]
selectIndex = 0
window['-selection-'].update(set_to_index = selectIndex, values=choices)
selectList = content[selectIndex].split()
var1, var2, var3, var4, var5, var6, var7 = [hex(int(selectList[k])).lstrip("0x").zfill(2) for k in range(7)]
var1 = int(var1, 16)
var8 = selectList[7]
window['-WEIGHT-'].update(var1)
window['-R1-'].update(var2), window['-G1-'].update(var3), window['-B1-'].update(var4)
window['-R2-'].update(var5), window['-G2-'].update(var6), window['-B2-'].update(var7)
else: #nothing else is left
values['-selection-'] = ['']
selectIndex = 0
window['-selection-'].update('', set_to_index = -1, values=choices)
window['-WEIGHT-'].update('')
window['-R1-'].update(''), window['-G1-'].update(''), window['-B1-'].update('')
window['-R2-'].update(''), window['-G2-'].update(''), window['-B2-'].update('')
sg.popup(deletedName + ' removed from the wheel successfully.', location = locale)
else:
continue
#print(content) # debug purposes only
elif event == 'All Weight+1' and len(choices) > 0: # add +1 to all pieces weight
for i in range(len(content)):
weightList = content[i].split()
weightMod = int(weightList[0], 10) + 1
weightList[0] = str(weightMod)
content[i] = separator.join(weightList) + "\n"
if values['-selection-']:
selectList = content[selectIndex].split()
var1 = int(selectList[0])
window['-WEIGHT-'].update(var1)
sg.popup('All weights increased by +1 successfully.', location = locale)
#print(content) # debug purposes only
elif event == 'Show List': # Generate a list of everything on the wheel
sg.PrintClose()
sg.Print('Number Weight Name')
for i, j in enumerate(content):
showList = content[i].split()
showWeight = showList[0]
showName = showList[7]
sg.Print(' ' + str(int(i+1)).zfill(3) + ' ' + str(showWeight).zfill(2) + ' ' + showName)
elif event == 'Save': # write to file
save_file('wheeldata.txt', content)
sg.popup('Your data has been saved.', location = locale)
elif event == '-NAMEIN-' and values['-NAMEIN-'] and values['-NAMEIN-'][-1] not in ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-'."):
window['-NAMEIN-'].update(values['-NAMEIN-'][:-1])
elif event == '-NAMEIN-' and len(values['-NAMEIN-']) > 15:
window['-NAMEIN-'].update(values['-NAMEIN-'][:-1])
elif event == '-WEIGHT-' and values['-WEIGHT-'] and values['-WEIGHT-'][-1] not in ('0123456789'):
window['-WEIGHT-'].update(values['-WEIGHT-'][:-1])
elif event == '-R1-' and values['-R1-'] and values['-R1-'][-1] not in ('0123456789abcdefABCDEF'):
window['-R1-'].update(values['-R1-'][:-1])
elif event == '-R1-' and len(values['-R1-']) > 2:
window['-R1-'].update(values['-R1-'][:-1])
elif event == '-G1-' and values['-G1-'] and values['-G1-'][-1] not in ('0123456789abcdefABCDEF'):
window['-G1-'].update(values['-G1-'][:-1])
elif event == '-G1-' and len(values['-G1-']) > 2:
window['-G1-'].update(values['-G1-'][:-1])
elif event == '-B1-' and values['-B1-'] and values['-B1-'][-1] not in ('0123456789abcdefABCDEF'):
window['-B1-'].update(values['-B1-'][:-1])
elif event == '-B1-' and len(values['-B1-']) > 2:
window['-B1-'].update(values['-B1-'][:-1])
elif event == '-R1IN-' and values['-R1IN-'] and values['-R1IN-'][-1] not in ('0123456789abcdefABCDEF'):
window['-R1IN-'].update(values['-R1IN-'][:-1])
elif event == '-R1IN-' and len(values['-R1IN-']) > 2:
window['-R1IN-'].update(values['-R1IN-'][:-1])
elif event == '-G1IN-' and values['-G1IN-'] and values['-G1IN-'][-1] not in ('0123456789abcdefABCDEF'):
window['-G1IN-'].update(values['-G1IN-'][:-1])
elif event == '-G1IN-' and len(values['-G1IN-']) > 2:
window['-G1IN-'].update(values['-G1IN-'][:-1])
elif event == '-B1IN-' and values['-B1IN-'] and values['-B1IN-'][-1] not in ('0123456789abcdefABCDEF'):
window['-B1IN-'].update(values['-B1IN-'][:-1])
elif event == '-B1IN-' and len(values['-B1IN-']) > 2:
window['-B1IN-'].update(values['-B1IN-'][:-1])
elif event == '-R2-' and values['-R2-'] and values['-R2-'][-1] not in ('0123456789abcdefABCDEF'):
window['-R2-'].update(values['-R2-'][:-1])
elif event == '-R2-' and len(values['-R2-']) > 2:
window['-R2-'].update(values['-R2-'][:-1])
elif event == '-G2-' and values['-G2-'] and values['-G2-'][-1] not in ('0123456789abcdefABCDEF'):
window['-G2-'].update(values['-G2-'][:-1])
elif event == '-G2-' and len(values['-G2-']) > 2:
window['-G2-'].update(values['-G2-'][:-1])
elif event == '-B2-' and values['-B2-'] and values['-B2-'][-1] not in ('0123456789abcdefABCDEF'):
window['-B2-'].update(values['-B2-'][:-1])
elif event == '-B2-' and len(values['-B2-']) > 2:
window['-B2-'].update(values['-B2-'][:-1])
elif event == '-R2IN-' and values['-R2IN-'] and values['-R2IN-'][-1] not in ('0123456789abcdefABCDEF'):
window['-R2IN-'].update(values['-R2IN-'][:-1])
elif event == '-R2IN-' and len(values['-R2IN-']) > 2:
window['-R2IN-'].update(values['-R2IN-'][:-1])
elif event == '-G2IN-' and values['-G2IN-'] and values['-G2IN-'][-1] not in ('0123456789abcdefABCDEF'):
window['-G2IN-'].update(values['-G2IN-'][:-1])
elif event == '-G2IN-' and len(values['-G2IN-']) > 2:
window['-G2IN-'].update(values['-G2IN-'][:-1])
elif event == '-B2IN-' and values['-B2IN-'] and values['-B2IN-'][-1] not in ('0123456789abcdefABCDEF'):
window['-B2IN-'].update(values['-B2IN-'][:-1])
elif event == '-B2IN-' and len(values['-B2IN-']) > 2:
window['-B2IN-'].update(values['-B2IN-'][:-1])
elif event == '-R1IN-' or event == '-G1IN-' or event == '-B1IN-' or event == '-R2IN-' or event == '-G2IN-' or event == '-B2IN-':
valRRGGBB1 = "#" + (values['-R1IN-']).zfill(2) + (values['-G1IN-']).zfill(2) + (values['-B1IN-']).zfill(2)
valRRGGBB2 = "#" + (values['-R2IN-']).zfill(2) + (values['-G2IN-']).zfill(2) + (values['-B2IN-']).zfill(2)
window['-NAMEIN-'].update(text_color = valRRGGBB2, background_color = valRRGGBB1)
elif event == 'Randomize BG Color':
rngColor(1, window)
elif event == 'Randomize Text Color':
rngColor(2, window)
elif event == 'Randomize Both Colors':
rngColor(1, window)
rngColor(2, window)
elif event == 'Add to Wheel' and values['-NAMEIN-']: # put all the stuff into the list as a new wheel piece
if values['-NAMEIN-'] in choices: # if someone's already on the list, notify the user
sg.popup('Error: ' + values['-NAMEIN-'] + ' is already on the wheel.')
i = 0
while i < len(choices):
if values['-NAMEIN-'] == choices[i]:
selectIndex = i
i += 1
if window == window2: # close the window and set the list to the name specified
window.close()
window2 = None
output_window = window1
if output_window:
output_window['-selection-'].update(set_to_index = selectIndex, values=choices)
selectList = content[selectIndex].split()
var1, var2, var3, var4, var5, var6, var7 = [hex(int(selectList[k])).lstrip("0x").zfill(2) for k in range(7)]
var1 = int(var1, 16)
var8 = selectList[7]
output_window['-WEIGHT-'].update(var1)
output_window['-R1-'].update(var2), output_window['-G1-'].update(var3), output_window['-B1-'].update(var4)
output_window['-R2-'].update(var5), output_window['-G2-'].update(var6), output_window['-B2-'].update(var7)
output_window = None
continue
if values['-SUBIN-']:
subweight = 5
else:
subweight = 1
if values['-NAMEIN-'] in userMem: # The user being added has been here before
i = 0
while i < len(userMem):
if values['-NAMEIN-'] == userMem[i]: # Get the index of the user so we can add their data if desired
selectIndex = i
i += 1
userList = userbase[selectIndex].split()
rr1, gg1, bb1, rr2, gg2, bb2 = [hex(int(userList[k])).lstrip("0x").zfill(2) for k in range(6)] # get all the RGBs ready
reduxRRGGBB1 = "#"+str(rr1)+str(gg1)+str(bb1)
reduxRRGGBB2 = "#"+str(rr2)+str(gg2)+str(bb2)
redux = sg.PopupYesNo(values['-NAMEIN-'] + ' has previous RGB data. Import RGB data and add?', title = "Previous User Detected", background_color = reduxRRGGBB1, text_color = reduxRRGGBB2)
if redux == 'Yes': # If desired, update the entries and leave the userbase.txt alone
window['-R1IN-'].update(rr1), window['-G1IN-'].update(gg1), window['-B1IN-'].update(bb1)
window['-R2IN-'].update(rr1), window['-G2IN-'].update(gg1), window['-B2IN-'].update(bb2)
newline(content)
addnew_user = (str(subweight) + ' ' + str(int(rr1, 16)) + ' ' + str(int(gg1, 16)) + ' ' + str(int(bb1, 16)) + ' ' + str(int(rr2, 16)) + ' ' + str(int(gg2, 16)) + ' ' + str(int(bb2, 16)) + ' ' + values['-NAMEIN-'])
content.append(addnew_user)
choices.append(values['-NAMEIN-'])
#print(content) # for debug purposes only
sg.popup(values['-NAMEIN-'] + ' added to the wheel successfully.', location = locale)
if window == window2:
window.close()
window2 = None
output_window = window1
if output_window:
selectIndex = len(choices) - 1
output_window['-selection-'].update(set_to_index = selectIndex, values=choices)
selectList = content[selectIndex].split()
var1, var2, var3, var4, var5, var6, var7 = [hex(int(selectList[k])).lstrip("0x").zfill(2) for k in range(7)]
var1 = int(var1, 16)
var8 = selectList[7]
output_window['-WEIGHT-'].update(var1)
output_window['-R1-'].update(var2), output_window['-G1-'].update(var3), output_window['-B1-'].update(var4)
output_window['-R2-'].update(var5), output_window['-G2-'].update(var6), output_window['-B2-'].update(var7)
output_window = None
continue
else: # Otherwise, leave the entries alone and update userbase.txt
newUserLine = (str(int(values['-R1IN-'], 16)) + ' ' + str(int(values['-G1IN-'], 16)) + ' ' + str(int(values['-B1IN-'], 16)) + ' ' + str(int(values['-R2IN-'], 16)) + ' ' + str(int(values['-G2IN-'], 16)) + ' ' + str(int(values['-B2IN-'], 16)) + ' ' + values['-NAMEIN-'])
userbase[selectIndex] = newUserLine + "\n"
save_file('userbase.txt', userbase)
else:
newline(userbase)
newUserLine = (str(int(values['-R1IN-'], 16)) + ' ' + str(int(values['-G1IN-'], 16)) + ' ' + str(int(values['-B1IN-'], 16)) + ' ' + str(int(values['-R2IN-'], 16)) + ' ' + str(int(values['-G2IN-'], 16)) + ' ' + str(int(values['-B2IN-'], 16)) + ' ' + values['-NAMEIN-'])
userbase.append(newUserLine)
userMem.append(values['-NAMEIN-'])
save_file('userbase.txt', userbase)
newline(content)
addnew_user = (str(subweight) + ' ' + str(int(values['-R1IN-'], 16)) + ' ' + str(int(values['-G1IN-'], 16)) + ' ' + str(int(values['-B1IN-'], 16)) + ' ' + str(int(values['-R2IN-'], 16)) + ' ' + str(int(values['-G2IN-'], 16)) + ' ' + str(int(values['-B2IN-'], 16)) + ' ' + values['-NAMEIN-'])
content.append(addnew_user)
choices.append(values['-NAMEIN-'])
#print(content) # for debug purposes only
sg.popup(values['-NAMEIN-'] + ' added to the wheel successfully.', location = locale)
if window == window2:
window.close()
window2 = None
output_window = window1
if output_window:
selectIndex = len(choices) - 1
output_window['-selection-'].update(set_to_index = selectIndex, values=choices)
selectList = content[selectIndex].split()
var1, var2, var3, var4, var5, var6, var7 = [hex(int(selectList[k])).lstrip("0x").zfill(2) for k in range(7)]
var1 = int(var1, 16)
var8 = selectList[7]
output_window['-WEIGHT-'].update(var1)
output_window['-R1-'].update(var2), output_window['-G1-'].update(var3), output_window['-B1-'].update(var4)
output_window['-R2-'].update(var5), output_window['-G2-'].update(var6), output_window['-B2-'].update(var7)
output_window = None
try:
if values['-selection-'] and values['-selection-'] != var8 and values['-selection-'] != ['']:
for i, j in enumerate(choices):
if j == values['-selection-']:
selectIndex = i
selectList = content[selectIndex].split()
var1, var2, var3, var4, var5, var6, var7 = [hex(int(selectList[k])).lstrip("0x").zfill(2) for k in range(7)]
var1 = int(var1, 16)
var8 = selectList[7]
try:
window['-WEIGHT-'].update(var1)
window['-R1-'].update(var2), window['-G1-'].update(var3), window['-B1-'].update(var4)
window['-R2-'].update(var5), window['-G2-'].update(var6), window['-B2-'].update(var7)
except UnboundLocalError:
continue
except KeyError:
continue
if __name__ == "__main__":
main()