-
Notifications
You must be signed in to change notification settings - Fork 0
/
gui.py
663 lines (546 loc) · 34.1 KB
/
gui.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
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
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
import datetime as dt
import tkinter as tk
from tkinter import ttk
import webbrowser
import os
import helpers.config as config
from helpers.style import Style
import helpers.gui as gh
from helpers.logger import Logger
from helpers.changelog import Changelog
s = Style.Get()
class GUI:
def __init__(self, configurator):
self.Configurator = configurator
self.log = Logger("pyLaunch.GUI", "gui.log")
class Storage:
pass
def Launch(self):
self.Initialize()
self.Runtime()
return self.Completed
def Reset(self):
self.ws = tk.Tk()
self.Completed = False
self.Configuring = False
self.data = self.Storage()
self.Frames = self.Storage()
self.Menus = self.Storage()
def SetTheme(self, theme: str):
s.Set(theme)
self.ws.destroy()
self.Initialize()
def Initialize(self):
self.Reset()
self.ws.title(f"pyLaunch Configurator {config.VERSION}")
self.ws.geometry("700x400")
self.ws.resizable(width=False, height=False)
self.Icon = tk.PhotoImage(f"{config.PATH_ROOT}/pyLaunch.ico")
self.ws.iconbitmap(self.Icon)
# Menu
self.Menus.Main = tk.Menu(self.ws)
self.ws.config(menu=self.Menus.Main)
# View
self.Menus.View = tk.Menu(self.Menus.Main, tearoff=0, background=s.FRAME_BG_ALT, foreground=s.LABEL_FG)
self.Menus.Main.add_cascade(label="View", menu=self.Menus.View)
self.Menus.View_Themes = tk.Menu(self.Menus.View, tearoff=0, background=s.FRAME_BG_ALT, foreground=s.LABEL_FG)
self.Menus.View.add_cascade(label="Themes", menu=self.Menus.View_Themes)
for theme in s.GetThemes():
self.Menus.View_Themes.add_command(label=theme, command=lambda theme=theme: self.SetTheme(theme))
#self.Menus.View.add_command(label="Dark mode", command=self.DarkMode)
#self.Menus.View.add_command(label="Light mode", command=self.LightMode)
# Help
self.Menus.Help = tk.Menu(self.Menus.Main, tearoff=0, background=s.FRAME_BG_ALT, foreground=s.LABEL_FG)
self.Menus.Main.add_cascade(label="Help", menu=self.Menus.Help)
self.Menus.Help.add_command(label="What's this?", command=self.PopupStartup)
self.Menus.Help.add_separator()
self.Menus.Help.add_command(label="About", command=self.PopupAbout)
self.Menus.Help.add_command(label="Documentation", command=lambda: webbrowser.open(config.LINK_DOCUMENTATION))
self.Menus.Help.add_command(label="Release Notes", command=self.PopupChangelog)
self.Menus.Help.add_separator()
self.Menus.Help.add_command(label="Configuration", command=self.PopupConfiguration)
self.Menus.Help.add_command(label="Updater", command=self.PopupUpdater)
self.Menus.Help.add_command(label="Setup", command=self.PopupSetup)
self.Menus.Help.add_command(label="Launcher", command=self.PopupLauncher)
######## Frames
# Configuration
self.Frames.Configuration = tk.Frame(self.ws, width=200, height=400, borderwidth=10, background=s.FRAME_BG)
self.Frames.Configuration.grid_propagate(0)
self.Frames.Configuration.pack(fill='both', side='left', expand='True')
self.Frames.Configuration_Title = tk.Frame(self.Frames.Configuration, background=s.FRAME_BG)
self.Frames.Configuration_Title.pack_propagate(0)
self.Frames.Configuration_Title.pack(fill='both', side='top', expand='False')
gh.Title(self.Frames.Configuration_Title, text="Configurations", bg=0).grid(column=0, row=0)
self.Frames.Configuration_Body = tk.Frame(self.Frames.Configuration, background=s.FRAME_BG)
self.Frames.Configuration_Body.pack_propagate(0)
self.Frames.Configuration_Body.pack(fill='both', side='top', expand='False')
self.ConfigurationStatus = dict(
Updater =dict(
Callback = self.ConfigureUpdater,
Complete = False,
Label = None
),
Setup = dict(
Callback = self.ConfigureSetup,
Complete = False,
Label = None
),
Launcher = dict(
Callback = self.ConfigureLauncher,
Complete = False,
Label = None
),
)
row = 1
for key, value in self.ConfigurationStatus.items():
gh.Button(self.Frames.Configuration_Body, text=key, command=value['Callback'], width=8, bg=0).grid(column=0, row=row, padx=5, pady=5)
value['Label'] = gh.SmallLabel(self.Frames.Configuration_Body, text="Incomplete", bg=0)
value['Label'].grid(column=1, row=row)
row += 1
self.ConfigurationComplete = gh.Label(self.Frames.Configuration_Body, text="", bg=0)
self.ConfigurationComplete.grid(column=0, row=row)
gh.Button(self.Frames.Configuration_Body, text="Finish", command=self.FinishConfiguration, bg=0).grid(column=0, row=row + 1)
# Configurator
self.Frames.Configurator = tk.Frame(self.ws, width=500, height=400, borderwidth=10, background=s.FRAME_BG_ALT)
self.Frames.Configurator.grid_propagate(0)
self.Frames.Configurator.pack(fill='both', side='right', expand='True')
self.fr_cfr_title = gh.Title(self.Frames.Configurator, text="Select a configuration on the left", bg=1)
self.fr_cfr_title.grid(column=0, row=0)
self.fr_cfr_popup_btn = gh.Button(self.Frames.Configurator, text="What's this?", command=self.PopupStartup, bg=1)
self.fr_cfr_popup_btn.grid(sticky="e", column=1, row=0, padx=50)
self.Frames.CGR = tk.Frame(self.Frames.Configurator, width=500, height=325, borderwidth=10, background=s.FRAME_BG)
self.Frames.CGR.grid_propagate(0)
self.Frames.CGR.pack(fill='both', side='bottom', expand='False')
def FocusNextWidget(event):
event.widget.tk_focusNext().focus()
return("break")
def PopupStartup(self):
popup = tk.Toplevel(self.ws, borderwidth=10, background=s.FRAME_BG_ALT)
popup.geometry("350x270")
popup.title("No valid configuration")
popup.resizable(width=False, height=False)
popup.iconbitmap(self.Icon)
gh.Title(popup, text="This project has no configuration", bg=1).pack()
gh.Label(popup, text="If you're not the developer of this program,\nlet them know: 'pyLaunch has no configuration'\nTo use this program otherwise, launch it directly.", justify='left', bg=0).pack()
gh.LargeLabel(popup, text="Developers:", justify='left', bg=1).pack(anchor='w', padx=5, pady=5)
gh.Label(popup, text="Please set up each configuration on the left", bg=1).pack(anchor='w', padx=s.PAD_BODY)
gh.Label(popup, text="then press finish to save it.", bg=1).pack(anchor='w', padx=s.PAD_BODY)
gh.Label(popup, text="If you need any assistance, please check our docs page,\nthe 'help' menu or check our GitHub page").pack()
Startup_Buttons = tk.Frame(popup, background=s.FRAME_BG_ALT)
Startup_Buttons.pack(pady=5)
gh.Button(Startup_Buttons, text="GitHub Page", command=lambda: webbrowser.open(config.LINK_GITHUB), bg=1).grid(column=0, row=0, padx=20)
gh.Button(Startup_Buttons, text="Docs", command=lambda: webbrowser.open(config.LINK_DOCUMENTATION), width=6, bg=1).grid(sticky='w', column=1, row=0)
gh.Button(Startup_Buttons, text="Close", command=popup.destroy, bg=1).grid(column=2, row=0, padx=20)
def PopupAbout(self):
popup = tk.Toplevel(self.ws, borderwidth=10, background=s.FRAME_BG_ALT)
popup.geometry("350x300")
popup.title("About")
popup.resizable(width=False, height=False)
popup.iconbitmap(self.Icon)
About_Title = tk.Frame(popup, background=s.FRAME_BG_ALT)
About_Title.pack(anchor='w', pady=2)
gh.Title(About_Title, text=f"pyLaunch {config.VERSION}", justify='left', bg=1).grid(sticky='s', column=0, row=0)
gh.SmallLabel(About_Title, text=f"©2022 DAAV, LLC", justify='left', bg=1).grid(sticky='s', column=1, row=0)
gh.Label(popup, text=f"Python project setup, updater, and launcher", bg=1).pack(anchor='w', padx=s.PAD_BODY)
About_Source = tk.Frame(popup, borderwidth=10, background=s.FRAME_BG_ALT)
About_Source.pack(anchor='w')
gh.Label(About_Source, text=f"License: MIT", justify='left', bg=1).grid(sticky='w', column=0, row=0)
gh.Button(About_Source, text="Source Code", command=lambda: webbrowser.open(config.LINK_GITHUB), bg=1).grid(sticky='w', column=1, row=0, padx=10)
gh.Label(About_Source, text=f"Documentation: ", justify='left', bg=1).grid(sticky='w', column=0, row=1)
gh.Button(About_Source, text="docs.daav.us", command=lambda: webbrowser.open(config.LINK_DOCUMENTATION), bg=1).grid(sticky='w', column=1, row=1, padx=10)
gh.FillHorizontalSeparator(popup, pady=5)
gh.Label(popup, text=f"GUI v{config.VERSION_CONFIGURATOR_GUI}", bg=1).pack(anchor='w', padx=5)
gh.Label(popup, text=f"Configurator v{config.VERSION_CONFIGURATOR}", bg=1).pack(anchor='w', padx=5)
gh.Label(popup, text=f"Configuration v{config.VERSION_CONFIGURATOR}", bg=1).pack(anchor='w', padx=5)
gh.Label(popup, text=f"Updater v{config.VERSION_UPDATE}", bg=1).pack(anchor='w', padx=5)
gh.Label(popup, text=f"Setup v{config.VERSION_SETUP}", bg=1).pack(anchor='w', padx=5)
gh.Label(popup, text=f"Launcher v{config.VERSION_LAUNCH}", bg=1).pack(anchor='w', padx=5)
def PopupChangelog(self):
popup = tk.Toplevel(self.ws, background=s.FRAME_BG_ALT)
popup.geometry("500x600")
popup.title("Help - Release notes")
popup.resizable(width=False, height=True)
popup.iconbitmap(self.Icon)
gh.Title(popup, text="Release notes", bg=1).pack(pady=5)
container = tk.Frame(popup, background=s.FRAME_BG_ALT)
canvas = tk.Canvas(container, borderwidth=0, highlightthickness=0, background=s.FRAME_BG)
scrollbar = tk.Scrollbar(container, orient='vertical', command=canvas.yview)
frame = tk.Frame(canvas, background=s.FRAME_BG)
frame.bind(
"<Configure>",
lambda e: canvas.configure(
scrollregion = canvas.bbox("all")
)
)
canvas.create_window((0, 0), window=frame, anchor="nw")
canvas.configure(yscrollcommand=scrollbar.set)
cl = Changelog(config.GIT_ORG, config.GIT_REPO)
changelog = cl.Get()
for item in changelog:
date = dt.datetime.fromisoformat(item['date'])
gh.LargeLabel(frame, text=f"{date.strftime('%Y-%m-%d %H:%M:%S')}", bg=0).pack(anchor='w')
gh.Label(frame, text=f"Author: {item['author']['name']} - {item['author']['email']}", justify='left', wraplength=550, bg=0).pack(anchor='w')
gh.Label(frame, text=item['message'], justify='left', wraplength=550, bg=0).pack(anchor='w')
gh.Button(frame, text="View on GitHub", command=lambda sha=item['sha']: webbrowser.open(f"https://github.com/{config.GIT_ORG}/{config.GIT_REPO}/commit/{sha}"), bg=0).pack()
if not item == changelog[-1]:
gh.FillHorizontalSeparator(frame, pady=5)
container.pack(side='left', fill='both', expand=True)
canvas.pack(padx=5, pady=5, side='left', fill='both', expand=True)
scrollbar.pack(side="right", fill="y")
def PopupConfiguration(self):
popup = tk.Toplevel(self.ws, borderwidth=10, background=s.FRAME_BG_ALT)
popup.geometry("350x200")
popup.title("Help - Configuration")
popup.resizable(width=False, height=False)
popup.iconbitmap(self.Icon)
gh.LargeLabel(popup, text="Configuration is broken into 3 parts:", bg=1).pack(pady=5)
Config_Details = tk.Frame(popup, background=s.FRAME_BG_ALT)
Config_Details.pack(pady=5)
gh.Button(Config_Details, text="Updater", command=self.PopupUpdater, width=8, bg=1).grid(sticky='w', column=0, row=0)
gh.Label(Config_Details, text="GitHub details for update checking/downloading", bg=1).grid(sticky='w', column=1, row=0, pady=5)
gh.Button(Config_Details, text="Setup", command=self.PopupSetup, width=8, bg=1).grid(sticky='w', column=0, row=1)
gh.Label(Config_Details, text="Dependancy installation", bg=1).grid(sticky='w', column=1, row=1, pady=5)
gh.Button(Config_Details, text="Launcher", command=self.PopupLauncher, width=8, bg=1).grid(sticky='w', column=0, row=2)
gh.Label(Config_Details, text="Error catching, and Python reloading", bg=1).grid(sticky='w', column=1, row=2, pady=5)
Configuration_Buttons = tk.Frame(popup, background=s.FRAME_BG_ALT)
Configuration_Buttons.pack(pady=5)
gh.Label(Configuration_Buttons, text="More documentation is available at", bg=1).grid(sticky='w', column=0, row=0, pady=5)
gh.Button(Configuration_Buttons, text="docs.daav.us", command=lambda: webbrowser.open(config.LINK_DOCUMENTATION), bg=1).grid(sticky='w', column=1, row=0)
def PopupUpdater(self):
popup = tk.Toplevel(self.ws, borderwidth=10, background=s.FRAME_BG_ALT)
popup.geometry("400x355")
popup.title("Help - Updater")
popup.resizable(width=False, height=False)
popup.iconbitmap(self.Icon)
gh.Label(popup, text="Check installed version vs most recent version on GitHub", bg=1).pack()
gh.FillHorizontalSeparator(popup, pady=5)
gh.LargeLabel(popup, text="Organization:", bg=1).pack(anchor='w', padx=s.PAD_HEADERX)
gh.Label(popup, text="Your GitHub username (ex: daavofficial)", bg=1).pack(anchor='w', padx=s.PAD_BODY)
gh.LargeLabel(popup, text="Repository:", bg=1).pack(anchor='w', padx=s.PAD_HEADERX)
gh.Label(popup, text="Your GitHub repository's name (ex: pyLaunch)", bg=1).pack(anchor='w', padx=s.PAD_BODY)
gh.LargeLabel(popup, text="Branch:", bg=1).pack(anchor='w', padx=s.PAD_HEADERX)
gh.Label(popup, text="Branch to check (ex: main)", bg=1).pack(anchor='w', padx=s.PAD_BODY)
gh.LargeLabel(popup, text="Version Path:", bg=1).pack(anchor='w', padx=s.PAD_HEADERX)
gh.Label(popup, text="Repository path to the file that contains the version", bg=1).pack(anchor='w', padx=s.PAD_BODY)
gh.Label(popup, text="(ex: /src/config.py)", bg=1).pack(anchor='w', padx=s.PAD_BODY)
gh.LargeLabel(popup, text="Find:", bg=1).pack(anchor='w', padx=s.PAD_HEADERX)
gh.Label(popup, text="The string to look for to find the version (ex: VERSION = )", bg=1).pack(anchor='w', padx=s.PAD_BODY)
gh.LargeLabel(popup, text="Token:", bg=1).pack(anchor='w', padx=s.PAD_HEADERX)
gh.Label(popup, text="Only needed for accessing private repositores", bg=1).pack(anchor='w', padx=s.PAD_BODY)
def PopupSetup(self):
popup = tk.Toplevel(self.ws, borderwidth=10, background=s.FRAME_BG_ALT)
popup.geometry("420x320")
popup.title("Help - Setup")
popup.resizable(width=False, height=False)
popup.iconbitmap(self.Icon)
gh.Label(popup, text="Setup simplifies installation by running python", bg=1).pack()
gh.Label(popup, text="using your project's required version,", bg=1).pack()
gh.Label(popup, text="and installing required packages automatically", bg=1).pack()
gh.FillHorizontalSeparator(popup, pady=5)
gh.LargeLabel(popup, text="Setup requires two things:", bg=1).pack(anchor='w', padx=s.PAD_HEADERX)
gh.Label(popup, text="The version of python your project uses", bg=1).pack(anchor='w', padx=s.PAD_BODY)
gh.Label(popup, text="The packages your project depends on", bg=1).pack(anchor='w', padx=s.PAD_BODY)
gh.LargeLabel(popup, text="Python Version", bg=1).pack(anchor='w', padx=s.PAD_HEADERX)
gh.Label(popup, text="Provide the required python version (ex: 3.10)", bg=1).pack(anchor='w', padx=s.PAD_BODY)
gh.LargeLabel(popup, text="Required packages:", bg=1).pack(anchor='w', padx=s.PAD_HEADERX)
gh.Label(popup, text="Provide the pip install name, and the import name", bg=1).pack(anchor='w', padx=s.PAD_BODY)
gh.Label(popup, text="If they are the same, just type the package name (ex: numpy)", bg=1).pack(anchor='w', padx=s.PAD_BODY)
gh.Label(popup, text="If they are different, delimit them with a colon (ex: pyyaml:yaml)", bg=1).pack(anchor='w', padx=s.PAD_BODY)
def PopupLauncher(self):
popup = tk.Toplevel(self.ws, borderwidth=10, background=s.FRAME_BG_ALT)
popup.geometry("420x270")
popup.title("Help - Launcher")
popup.resizable(width=False, height=False)
popup.iconbitmap(self.Icon)
gh.Label(popup, text="Launch project and check error codes", bg=1).pack()
gh.FillHorizontalSeparator(popup, pady=5)
gh.LargeLabel(popup, text="Project Root:", bg=1).pack(anchor='w', padx=s.PAD_HEADERX)
gh.Label(popup, text="Relative path from pyLaunch to your Project's root folder (ex: ..)", bg=1).pack(anchor='w', padx=s.PAD_BODY)
gh.LargeLabel(popup, text="Project Main:", bg=1).pack(anchor='w', padx=s.PAD_HEADERX)
gh.Label(popup, text="Repository path to your project's main file (ex: /start.py)", bg=1).pack(anchor='w', padx=s.PAD_BODY)
gh.LargeLabel(popup, text="Error Codes:", bg=1).pack(anchor='w', padx=s.PAD_HEADERX)
gh.Label(popup, text="Provide the error code and addional arguments", bg=1).pack(anchor='w', padx=s.PAD_BODY)
gh.Label(popup, text="Error codes are formated as follows: 'code:args' (ex: -2:-UI GUI)", bg=1).pack(anchor='w', padx=s.PAD_BODY)
gh.Label(popup, text="If you provide and error code with no arguments,", bg=1).pack(anchor='w', padx=s.PAD_BODY)
gh.Label(popup, text="it will reload python (ex: -1:)", bg=1).pack(anchor='w', padx=s.PAD_BODY)
def Runtime(self):
self.ws.mainloop()
def FinishConfiguration(self):
if not( all(complete == True for complete in [value['Complete'] for value in self.ConfigurationStatus.values()]) ):
self.ConfigurationComplete.config(text="Incomplete")
else:
self.ConfigurationComplete.config(text="Done!")
self.Configurator.Save()
self.Completed = True
self.ws.destroy()
return True
def UpdateStatus(self):
for key in self.ConfigurationStatus.keys():
if self.ConfigurationStatus[key]['Complete']:
self.ConfigurationStatus[key]['Label'].config(text="Done")
else:
self.ConfigurationStatus[key]['Label'].config(text="Incomplete")
def ClearConfigure(self):
self.data = self.Storage()
self.fr_cfr_title.config(text="Select a configuration on the left")
for item in self.Frames.CGR.winfo_children():
item.destroy()
if self.fr_cfr_popup_btn is not None:
self.fr_cfr_popup_btn.destroy()
self.fr_cfr_popup_btn = None
##########################################################################################
#
# UPDATER
#
##########################################################################################
def ConfigureUpdater(self):
self.ClearConfigure()
self.Configuring = True
self.fr_cfr_title.config(text="Updater Configuration")
self.data.Update = {'SkipCheck' : tk.BooleanVar(value=self.Configurator.Configuration.data['Update']['SkipCheck'])}
gh.Checkbutton(self.Frames.CGR, text="Skip update checking", variable=self.data.Update['SkipCheck'], command=self.SkipUpdate).grid(sticky='w', column=0, row=0)
row = 1
for text in ['Organization', 'Repository', 'Branch', 'Version Path', 'Find', 'Token']:
gh.Label(self.Frames.CGR, justify="left", text=text + ":", bg=0).grid(sticky='w', column=0, row=row)
key = text.replace(" ", "")
self.data.Update[key] = gh.TabableInput(self.Frames.CGR, width=40)
value = self.Configurator.Configuration.data['Update'][key]
if value is not None:
self.data.Update[key].insert("1.0", value)
self.data.Update[key].grid(sticky='w', column=1, row=row, pady=5)
row += 1
self.Frames.CGR_UpdateButtons = tk.Frame(self.Frames.CGR, background=s.FRAME_BG)
self.Frames.CGR_UpdateButtons.grid(sticky='w', column=0, row=row, pady=5)
self.StatusLabel = gh.LargeLabel(self.Frames.CGR_UpdateButtons, text="", bg=0)
self.StatusLabel.grid(column=0, row=0, sticky='s')
gh.Button(self.Frames.CGR_UpdateButtons, text="Finish", command=self.SetUpdate, bg=1).grid(column=0, row=1, sticky='s', pady=20)
def SkipUpdate(self):
self.Configurator.Update.SetSkipCheck(self.data.Update['SkipCheck'].get())
def SetUpdate(self):
self.StatusLabel.config(text="Verifiying information with GitHub...")
Organization = self.data.Update['Organization'].get("1.0", "end-1c")
Repository = self.data.Update['Repository'].get("1.0", "end-1c")
Branch = self.data.Update['Branch'].get("1.0", "end-1c")
VersionPath = self.data.Update['VersionPath'].get("1.0", "end-1c")
Find = self.data.Update['Find'].get("1.0", "end-1c")
Token = self.data.Update['Token'].get("1.0", "end-1c")
if not type(self.data.Update['SkipCheck']) == bool:
self.data.Update['SkipCheck'] = False
status = self.Configurator.Update.Set(Organization, Repository, Branch, VersionPath, Find, Token, self.data.Update['SkipCheck'])
if not type(status) == list:
self.StatusLabel.config(text="Unable to connect to the internet, config saved.")
self.ConfigurationStatus['Updater']['Complete'] = True
self.UpdateStatus()
elif all(element == None for element in status):
self.SaveUpdate()
else:
for stat in status:
if stat is not None:
self.StatusLabel.config(text=stat)
gh.Button(self.Frames.CGR_UpdateButtons, text="Save anyway", command=self.SaveUpdate, bg=1).grid(column=1, row=1)
break
self.log.info(f"Update configuration issues: {str(status)}")
def SaveUpdate(self):
self.ConfigurationStatus['Updater']['Complete'] = True
self.UpdateStatus()
self.StatusLabel.config(text="Done!")
self.ClearConfigure()
self.log.info(f"Stored Update: {self.Configurator.Configuration.data['Update']}")
##########################################################################################
#
# SETUP
#
##########################################################################################
def ConfigureSetup(self):
self.ClearConfigure()
self.Configuring = True
self.data.packages = {}
self.data.tk_items = []
self.fr_cfr_title.config(text="Setup Configuration", background=s.FRAME_BG_ALT, foreground=s.LABEL_FG)
self.Frames.CGR_PythonVersion = tk.Frame(self.Frames.CGR, background=s.FRAME_BG)
self.Frames.CGR_PythonVersion.grid(sticky='w', column=0, row=0, pady=5)
gh.Label(self.Frames.CGR_PythonVersion, justify="left", text="Python Version:", bg=0).grid(sticky='w', column=0, row=0)
self.data.PythonVersion = gh.TabableInput(self.Frames.CGR_PythonVersion, width=5, bg=0)
value = self.Configurator.Configuration.data['Setup']['PythonVersion']
if value is not None:
self.data.PythonVersion.insert("1.0", value)
self.data.PythonVersion.grid(sticky='w', column=1, row=0, padx=5, pady=5)
self.Frames.CGR_MinimumPythonVersion = tk.Frame(self.Frames.CGR, background=s.FRAME_BG)
self.Frames.CGR_MinimumPythonVersion.grid(sticky='w', column=0, row=1, pady=5)
gh.Label(self.Frames.CGR_MinimumPythonVersion, justify="left", text="Minimum Python Version:", bg=0).grid(sticky='w', column=0, row=0)
self.data.MinimumPythonVersion = gh.TabableInput(self.Frames.CGR_MinimumPythonVersion, width=5, bg=0)
value = self.Configurator.Configuration.data['Setup']['MinimumPythonVersion']
if value is not None:
self.data.MinimumPythonVersion.insert("1.0", value)
self.data.MinimumPythonVersion.grid(sticky='w', column=1, row=0, padx=5, pady=5)
self.Frames.CGR_Packages = tk.Frame(self.Frames.CGR, background=s.FRAME_BG)
self.Frames.CGR_Packages.grid(sticky='w', column=0, row=2, pady=5)
self.Frames.CGR_Package_Input = tk.Frame(self.Frames.CGR_Packages, background=s.FRAME_BG)
self.Frames.CGR_Package_Input.grid(sticky='n', column=0, row=0, padx=5)
gh.Label(self.Frames.CGR_Package_Input, justify="left", text="Packages:", bg=0).grid(sticky='w', column=0, row=0)
self.data.PackageName = gh.TabableInput(self.Frames.CGR_Package_Input, width=20, bg=0)
self.data.PackageName.grid(sticky='w', column=0, row=1, padx=5, pady=5)
gh.Button(self.Frames.CGR_Package_Input, text="Add", command=self.AddPackage, bg=0).grid(column=1, row=1, pady=5)
self.Frames.CGR_Table = tk.Frame(self.Frames.CGR_Packages, background=s.FRAME_BG)
self.Frames.CGR_Table.grid(sticky='n', column=1, row=0)
gh.Label(self.Frames.CGR_Table, justify="left", width=10, text="pypiName", bg=1).grid(column=0, row=0)
gh.Label(self.Frames.CGR_Table, justify="left", width=10, text="importName", bg=1).grid(column=1, row=0)
self.StatusLabel = gh.Label(self.Frames.CGR_Package_Input, text="", width=20, wraplength=200, bg=0)
self.StatusLabel.grid(sticky='s')
gh.Button(self.Frames.CGR_Package_Input, text="Finish", command=self.SetSetup, bg=1).grid(sticky='s', pady=20)
if not self.Configurator.Configuration.data['Setup']['Packages'] == {}:
for key, value in self.Configurator.Configuration.data['Setup']['Packages'].items():
self.data.packages[key] = value
self.DrawPackageList()
def DrawPackageList(self):
for row in self.data.tk_items:
for item in row:
item.destroy()
self.data.tk_items = []
index = 0
for py, imp in self.data.packages.items():
bg = 0
if index % 2:
bg = 1
pyNameLabel = gh.Label(self.Frames.CGR_Table, text=py, justify="left", bg=bg)
pyNameLabel.grid(sticky='w', column=0, row=index + 1)
importNameLabel = gh.Label(self.Frames.CGR_Table, text=imp, justify="left", bg=bg)
importNameLabel.grid(sticky='w', column=1, row=index + 1)
removeButton = gh.Button(self.Frames.CGR_Table, text="Remove", command=lambda key=py, index=index: self.RemovePackage(index, key), bg=0)
removeButton.grid(column=2, row=index + 1, padx=5, pady=1)
self.data.tk_items.append([pyNameLabel, importNameLabel, removeButton])
index += 1
def AddPackage(self):
package = self.data.PackageName.get("1.0", "end-1c")
if ":" in package:
if self.data.packages.get(package[0], None) is None:
package = package.split(":")
self.data.packages[package[0]] = package[1]
else:
if self.data.packages.get(package, None) is None:
self.data.packages[package] = package
self.DrawPackageList()
def RemovePackage(self, index:int, key: str):
del self.data.packages[key]
for item in self.data.tk_items.pop(index):
item.destroy()
self.DrawPackageList()
def SetSetup(self):
status = self.Configurator.Setup.Set(self.data.PythonVersion.get("1.0", "end-1c"),
self.data.MinimumPythonVersion.get("1.0", "end-1c"), self.data.packages)
if all(element == None for element in status):
self.ConfigurationStatus['Setup']['Complete'] = True
self.UpdateStatus()
self.StatusLabel.config(text="Done!")
self.ClearConfigure()
self.log.info(f"Stored Setup: {self.Configurator.Configuration.data['Setup']}")
else:
for stat in status:
if stat is not None:
self.StatusLabel.config(text=stat)
break
self.log.info(f"Setup configuration issues: {str(status)}")
##########################################################################################
#
# LAUNCH
#
##########################################################################################
def ConfigureLauncher(self):
self.ClearConfigure()
self.Configuring = True
self.fr_cfr_title.config(text="Launcher Configuration")
self.data.codes = {}
self.data.tk_items = []
self.data.LaunchSkipCheck = tk.BooleanVar(value=self.Configurator.Configuration.data['Launch']['SkipCheck'])
gh.Checkbutton(self.Frames.CGR, text="Skip update checking", variable=self.data.LaunchSkipCheck, command=self.SkipLaunchErrors).grid(sticky='w', column=0, row=0)
self.Frames.CGR_ProjectPath = tk.Frame(self.Frames.CGR, background=s.FRAME_BG_ALT)
self.Frames.CGR_ProjectPath.grid(sticky='w', column=0, row=1, pady=5)
gh.Label(self.Frames.CGR_ProjectPath, justify="left", text="Project Root:", bg=0).grid(sticky='w', column=0, row=0)
self.data.ProjectPath = gh.TabableInput(self.Frames.CGR_ProjectPath, width=30)
value = self.Configurator.Configuration.data['Launch']['ProjectRoot']
if value is not None:
self.data.ProjectPath.insert("1.0", value)
self.data.ProjectPath.grid(sticky='w', column=1, row=0)
self.Frames.CGR_ProjectMain = tk.Frame(self.Frames.CGR, background=s.FRAME_BG_ALT)
self.Frames.CGR_ProjectMain.grid(sticky='w', column=0, row=2, pady=5)
gh.Label(self.Frames.CGR_ProjectMain, justify="left", text="Project Main:", bg=0).grid(sticky='w', column=0, row=0)
self.data.ProjectMain = gh.TabableInput(self.Frames.CGR_ProjectMain, width=30)
value = self.Configurator.Configuration.data['Launch']['ProjectMain']
if value is not None:
self.data.ProjectMain.insert("1.0", value)
self.data.ProjectMain.grid(sticky='w', column=1, row=0)
self.Frames.CGR_ErrorCodes = tk.Frame(self.Frames.CGR, background=s.FRAME_BG)
self.Frames.CGR_ErrorCodes.grid(sticky='w', column=0, row=3)
self.Frames.CGR_ErrorCodes_Input = tk.Frame(self.Frames.CGR_ErrorCodes, background=s.FRAME_BG)
self.Frames.CGR_ErrorCodes_Input.grid(sticky='n', column=0, row=0)
gh.Label(self.Frames.CGR_ErrorCodes_Input, justify="left", text="Error Codes:", bg=0).grid(sticky='w', column=0, row=0)
self.data.ErrorCode = gh.TabableInput(self.Frames.CGR_ErrorCodes_Input, width=20, bg=0)
self.data.ErrorCode.grid(sticky='w', column=0, row=1, padx=5)
gh.Button(self.Frames.CGR_ErrorCodes_Input, text="Add", command=self.AddCode, bg=1).grid(column=1, row=1, padx=5, pady=5)
self.Frames.CGR_ErrorCodes_Table = tk.Frame(self.Frames.CGR_ErrorCodes, background=s.FRAME_BG)
self.Frames.CGR_ErrorCodes_Table.grid(sticky='n', column=1, row=0)
gh.Label(self.Frames.CGR_ErrorCodes_Table, justify="left", width=10, text="Code", bg=1).grid(column=0, row=0)
gh.Label(self.Frames.CGR_ErrorCodes_Table, justify="left", width=10, text="Arguments", bg=1).grid(column=1, row=0)
self.StatusLabel = gh.Label(self.Frames.CGR_ErrorCodes_Input, text="", width=20, wraplength=200, bg=0)
self.StatusLabel.grid(sticky='s')
gh.Button(self.Frames.CGR_ErrorCodes_Input, text="Finish", command=self.SetLaunch, bg=1).grid(sticky='s', pady=20)
if not self.Configurator.Configuration.data['Launch']['ErrorCodes'] == {}:
for key, value in self.Configurator.Configuration.data['Launch']['ErrorCodes'].items():
self.data.codes[key] = value
self.DrawCodeList()
def SkipLaunchErrors(self):
self.Configurator.Launch.SetSkipCheck(self.data.LaunchSkipCheck.get())
def DrawCodeList(self):
for row in self.data.tk_items:
for item in row:
item.destroy()
self.data.tk_items = []
index = 0
for code, arg in self.data.codes.items():
bg = 0
if index % 2:
bg = 1
pyNameLabel = gh.Label(self.Frames.CGR_ErrorCodes_Table, text=code, justify="left", bg=bg)
pyNameLabel.grid(sticky='w', column=0, row=index + 1)
importNameLabel = gh.Label(self.Frames.CGR_ErrorCodes_Table, text=arg, justify="left", bg=bg)
importNameLabel.grid(sticky='w', column=1, row=index + 1)
removeButton = gh.Button(self.Frames.CGR_ErrorCodes_Table, text="Remove", command=lambda key=code, index=index: self.RemoveCode(index, key), bg=0)
removeButton.grid(column=2, row=index + 1, padx=5, pady=1)
self.data.tk_items.append([pyNameLabel, importNameLabel, removeButton])
index += 1
def AddCode(self):
code = self.data.ErrorCode.get("1.0", "end-1c")
if not ":" in code:
return
code = code.split(":")
if len(code) > 2:
return
try:
errorCode = int(code[0])
except ValueError:
return
self.data.codes[code[0]] = code[1]
self.DrawCodeList()
def RemoveCode(self, index: int, key: str):
del self.data.codes[key]
for item in self.data.tk_items.pop(index):
item.destroy()
self.DrawCodeList()
def SetLaunch(self):
ProjectRoot = self.data.ProjectPath.get("1.0", "end-1c")
ProjectMain = self.data.ProjectMain.get("1.0", "end-1c")
SkipCheck = self.data.LaunchSkipCheck.get()
status = self.Configurator.Launch.Set(ProjectRoot, ProjectMain, self.data.codes, SkipCheck)
if all(element == None for element in status):
self.data = self.Storage()
self.ConfigurationStatus['Launcher']['Complete'] = True
self.UpdateStatus()
self.StatusLabel.config(text="Done!")
self.ClearConfigure()
self.log.info(f"Stored Update: {self.Configurator.Configuration.data['Launch']}")
else:
for stat in status:
if stat is not None:
self.StatusLabel.config(text=stat)
break
self.log.info(f"Launch configuration issues: {str(status)}")