-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathui.py
More file actions
1154 lines (950 loc) · 47.2 KB
/
ui.py
File metadata and controls
1154 lines (950 loc) · 47.2 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
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
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""
User Interface components for OpenChamp Admin Tool
"""
import tkinter as tk
from tkinter import ttk, messagebox, filedialog
import threading
import queue
from datetime import datetime
from pathlib import Path
from typing import Optional, Dict, List, Tuple, Any
from config import ConfigManager
from service_manager import ServiceManager
from resource_monitor import ResourceMonitor
class AdminToolUI:
"""Main UI for the Admin Tool"""
def __init__(self, root: tk.Tk) -> None:
self.root = root
self.config_manager = ConfigManager()
self.service_manager = ServiceManager(self.config_manager)
self.resource_monitor = ResourceMonitor(self.service_manager)
# Check if first-time setup is needed
if not self.config_manager.config_file.exists():
# Hide main window during setup
self.root.withdraw()
self.show_initialization_window()
# Show main window after setup
self.root.deiconify()
self.monitor = ResourceMonitor(self.service_manager)
self.update_queue: queue.Queue[Tuple[str, Any]] = queue.Queue()
self.monitoring = False
self.setup_ui()
self.start_monitoring()
def show_initialization_window(self):
"""Show an initialization window during first-time setup"""
# Window Configuration
init_window = tk.Toplevel(self.root)
init_window.title("OpenChamp Admin Tool - Setup")
init_window.geometry("600x500")
init_window.configure(bg=self.config_manager.colors['bg'])
init_window.resizable(False, False)
# Placement
init_window.update_idletasks()
x = (init_window.winfo_screenwidth() // 2) - (init_window.winfo_width() // 2)
y = (init_window.winfo_screenheight() // 2) - (init_window.winfo_height() // 2)
init_window.geometry(f"+{x}+{y}")
init_window.attributes('-topmost', True) # type: ignore
# Variables
setup_completed = [False]
selected_dir = tk.StringVar(value=str(self.config_manager.install_dir))
# ===== STAGE 1: Directory Selection =====
stage1_frame = tk.Frame(init_window, bg=self.config_manager.colors['bg'])
stage1_frame.pack(fill=tk.BOTH, expand=True, padx=20, pady=20)
# Title
title_label = tk.Label(
stage1_frame, text="Installation Directory",
bg=self.config_manager.colors['bg'], fg=self.config_manager.colors['accent_light'],
font=('Arial', 14, 'bold'), pady=10
)
title_label.pack(fill=tk.X)
# Description
desc_label = tk.Label(
stage1_frame, text="Where should OpenChamp be installed?",
bg=self.config_manager.colors['bg'], fg=self.config_manager.colors['fg'],
font=('Arial', 10), pady=5
)
desc_label.pack(fill=tk.X)
# Directory display panel
dir_panel = tk.Frame(stage1_frame, bg=self.config_manager.colors['panel_bg'], relief=tk.SUNKEN, borderwidth=1)
dir_panel.pack(fill=tk.X, pady=10)
dir_label = tk.Label(
dir_panel, textvariable=selected_dir,
bg=self.config_manager.colors['panel_bg'], fg=self.config_manager.colors['fg'],
font=('Courier', 9), wraplength=520, justify=tk.LEFT, padx=10, pady=10
)
dir_label.pack(fill=tk.BOTH, expand=True)
# Buttons for directory selection
button_frame = tk.Frame(stage1_frame, bg=self.config_manager.colors['bg'])
button_frame.pack(fill=tk.X, pady=10)
def browse_directory():
chosen = filedialog.askdirectory(
title="Select Installation Directory",
initialdir=str(self.config_manager.install_dir)
)
if chosen:
selected_dir.set(chosen)
change_button = tk.Button(
button_frame, text="Change Directory",
bg=self.config_manager.colors['accent_light'], fg=self.config_manager.colors['fg'],
font=('Arial', 10, 'bold'), padx=15, pady=8,
cursor='hand2', command=browse_directory
)
change_button.pack(side=tk.LEFT, padx=5)
# Next button (bottom right)
next_button = tk.Button(
button_frame, text="Next →",
bg=self.config_manager.colors['success'], fg=self.config_manager.colors['fg'],
font=('Arial', 10, 'bold'), padx=20, pady=8,
cursor='hand2'
)
next_button.pack(side=tk.RIGHT, padx=5)
# ===== STAGE 2: Installation Progress =====
stage2_frame = tk.Frame(init_window, bg=self.config_manager.colors['bg'])
# Don't pack yet - will be shown after Next is clicked
# Title for stage 2
title2_label = tk.Label(
stage2_frame, text="Installing...",
bg=self.config_manager.colors['bg'], fg=self.config_manager.colors['accent_light'],
font=('Arial', 14, 'bold'), pady=10
)
title2_label.pack(fill=tk.X)
# Status label
status_label = tk.Label(
stage2_frame, text="Downloading and installing repositories...",
bg=self.config_manager.colors['bg'], fg=self.config_manager.colors['fg'],
font=('Arial', 10), pady=5
)
status_label.pack(fill=tk.X)
# Progress text widget
progress_frame = tk.Frame(stage2_frame, bg=self.config_manager.colors['panel_bg'], relief=tk.SUNKEN, borderwidth=1)
progress_frame.pack(fill=tk.BOTH, expand=True, pady=10)
output_text = tk.Text(
progress_frame, bg=self.config_manager.colors['panel_bg'], fg=self.config_manager.colors['fg'],
font=('Courier', 9), height=15, width=70, state=tk.DISABLED
)
output_text.pack(fill=tk.BOTH, expand=True, padx=5, pady=5)
# Close button for stage 2
close_button = tk.Button(
stage2_frame, text="Close",
bg=self.config_manager.colors['success'], fg=self.config_manager.colors['fg'],
font=('Arial', 10, 'bold'), padx=20, pady=8,
cursor='hand2', state=tk.DISABLED
)
close_button.pack(pady=10)
def start_installation():
# Hide stage 1, show stage 2
stage1_frame.pack_forget()
stage2_frame.pack(fill=tk.BOTH, expand=True, padx=20, pady=20)
init_window.update_idletasks()
# Update install directory
self.config_manager.install_dir = Path(selected_dir.get())
self.service_manager.install_dir = Path(selected_dir.get())
# Queue for thread-safe communication
setup_queue = queue.Queue()
# Flag to track if setup is complete
setup_complete = [False]
# Run setup in a separate thread
def run_setup():
self.service_manager.first_time_setup(progress_queue=setup_queue)
setup_queue.put(('complete', None, None))
setup_complete[0] = True
# Process queue updates
def process_setup_queue():
try:
while True:
msg_type, *args = setup_queue.get_nowait()
if msg_type == 'message':
# Update the text widget with output
message = args[0] if args else ""
output_text.config(state=tk.NORMAL)
output_text.insert(tk.END, message)
output_text.see(tk.END)
output_text.config(state=tk.DISABLED)
elif msg_type == 'complete':
# Setup is done, enable close button
status_label.config(text="✓ Installation complete!", fg=COLORS['success'])
close_button.config(state=tk.NORMAL)
setup_completed[0] = True
init_window.lift() # Bring window back to front
except queue.Empty:
pass
# Check again in 50ms if window still exists
if init_window.winfo_exists():
init_window.after(50, process_setup_queue)
# Start setup thread
setup_thread = threading.Thread(target=run_setup, daemon=True)
setup_thread.start()
# Start queue processor
process_setup_queue()
def close_setup():
# If setup wasn't completed, quit the app
if not setup_completed[0]:
import os
os._exit(0)
else:
init_window.destroy()
next_button.config(command=start_installation)
close_button.config(command=close_setup)
# Handle window close button
def on_window_close():
close_setup()
init_window.protocol("WM_DELETE_WINDOW", on_window_close)
# Wait for setup to complete
self.root.wait_window(init_window)
def setup_ui(self):
"""Setup the user interface"""
self.root.title("OpenChamp Admin Tool")
self.root.geometry(f"{self.config_manager.ui_dimensions['window_width']}x{self.config_manager.ui_dimensions['window_height']}")
self.root.configure(bg=self.config_manager.colors['bg'])
# Configure styles
self.setup_styles()
# Header
header_frame = tk.Frame(self.root, bg=self.config_manager.colors['accent'], height=60)
header_frame.pack(fill=tk.X, padx=0, pady=0)
header_frame.pack_propagate(False)
header_label = tk.Label(
header_frame, text="OpenChamp Admin Tool",
bg=self.config_manager.colors['accent'], fg=self.config_manager.colors['fg'],
font=('Arial', 18, 'bold'), pady=15
)
header_label.pack(side=tk.LEFT, padx=20)
# Create main layout
main_frame = ttk.Frame(self.root, style='Dark.TFrame')
main_frame.pack(fill=tk.BOTH, expand=True, padx=10, pady=10)
# Left panel - Controls
left_panel = ttk.Frame(main_frame, style='Dark.TFrame')
left_panel.pack(side=tk.LEFT, fill=tk.BOTH, padx=(0, 10))
self.create_control_panel(left_panel)
# Right panel - Monitoring
right_panel = ttk.Frame(main_frame, style='Dark.TFrame')
right_panel.pack(side=tk.RIGHT, fill=tk.BOTH, expand=True)
self.create_monitoring_panel(right_panel)
def setup_styles(self):
"""Setup ttk styles for dark theme"""
style = ttk.Style()
style.theme_use('clam')
# Configure colors
style.configure('Dark.TFrame', background=self.config_manager.colors['bg'])
style.configure('Panel.TFrame', background=self.config_manager.colors['panel_bg'], relief='solid', borderwidth=1)
style.configure('Panel.TLabelframe', background=self.config_manager.colors['panel_bg'],
foreground=self.config_manager.colors['fg'], relief='solid', borderwidth=1)
style.configure('Panel.TLabelframe.Label', background=self.config_manager.colors['panel_bg'],
foreground=self.config_manager.colors['fg'])
style.configure('Title.TLabel', background=self.config_manager.colors['bg'],
foreground=self.config_manager.colors['accent_light'], font=('Arial', 14, 'bold'))
style.configure('Heading.TLabel', background=self.config_manager.colors['panel_bg'],
foreground=self.config_manager.colors['fg'], font=('Arial', 11, 'bold'))
style.configure('Info.TLabel', background=self.config_manager.colors['panel_bg'],
foreground=self.config_manager.colors['fg'], font=('Arial', 9))
# Button styles
style.configure('Primary.TButton', font=('Arial', 10, 'bold'))
style.map('Primary.TButton',
background=[('pressed', self.config_manager.colors['accent']),
('active', self.config_manager.colors['accent_light'])],
foreground=[('pressed', self.config_manager.colors['fg']),
('active', self.config_manager.colors['fg'])])
# Treeview style
style.configure('Treeview', background=self.config_manager.colors['panel_bg'],
foreground=self.config_manager.colors['fg'], fieldbackground=self.config_manager.colors['panel_bg'],
borderwidth=1, relief='solid')
style.configure('Treeview.Heading', background=self.config_manager.colors['accent'],
foreground=self.config_manager.colors['fg'], relief='solid')
style.map('Treeview', background=[('selected', self.config_manager.colors['accent'])])
# Container status tags
style.configure('Running.Treeview', background=self.config_manager.colors['success'])
style.map('Running.Treeview', background=[('selected', self.config_manager.colors['accent'])])
style.configure('Stopped.Treeview', background=self.config_manager.colors['error'])
style.map('Stopped.Treeview', background=[('selected', self.config_manager.colors['accent'])])
def create_control_panel(self, parent):
"""Create the control panel with buttons"""
# Title
title = ttk.Label(parent, text="Services", style='Title.TLabel')
title.pack(pady=(0, 15))
# Database Container Group
db_frame = ttk.LabelFrame(parent, text="Database Container", style='Panel.TLabelframe')
db_frame.pack(fill=tk.X, pady=5)
# Database header with status indicator
db_header = tk.Frame(db_frame, bg=self.config_manager.colors['panel_bg'])
db_header.pack(fill=tk.X, padx=10, pady=(10, 5))
# Status circle for DB
self.db_status_canvas = tk.Canvas(
db_header, width=16, height=16, bg=self.config_manager.colors['panel_bg'],
highlightthickness=0
)
self.db_status_canvas.pack(side=tk.LEFT, padx=(0, 8))
self.db_status_circle_db = self.db_status_canvas.create_oval(
2, 2, 14, 14, fill=self.config_manager.colors['error'], outline=self.config_manager.colors['border']
)
# Toggle button for DB
self.btn_toggle_db = tk.Button(
db_header, text="Start/Stop", command=self.toggle_database,
bg=self.config_manager.colors['accent_light'], fg=self.config_manager.colors['fg'],
font=('Arial', 10, 'bold'), padx=20, pady=6, cursor='hand2',
activebackground=self.config_manager.colors['accent']
)
self.btn_toggle_db.pack(side=tk.LEFT)
# Matchmaking Server Group
mm_frame = ttk.LabelFrame(parent, text="Matchmaking Server", style='Panel.TLabelframe')
mm_frame.pack(fill=tk.X, pady=5)
# Matchmaking header with status indicator
mm_header = tk.Frame(mm_frame, bg=self.config_manager.colors['panel_bg'])
mm_header.pack(fill=tk.X, padx=10, pady=(10, 5))
# Status circle for MM
self.mm_status_canvas = tk.Canvas(
mm_header, width=16, height=16, bg=self.config_manager.colors['panel_bg'],
highlightthickness=0
)
self.mm_status_canvas.pack(side=tk.LEFT, padx=(0, 8))
self.mm_status_circle_mm = self.mm_status_canvas.create_oval(
2, 2, 14, 14, fill=self.config_manager.colors['error'], outline=self.config_manager.colors['border']
)
# Toggle button for MM
self.btn_toggle_mm = tk.Button(
mm_header, text="Start/Stop", command=self.toggle_matchmaking,
bg=self.config_manager.colors['accent_light'], fg=self.config_manager.colors['fg'],
font=('Arial', 10, 'bold'), padx=20, pady=6, cursor='hand2',
activebackground=self.config_manager.colors['accent']
)
self.btn_toggle_mm.pack(side=tk.LEFT)
# Utility Group
util_frame = ttk.LabelFrame(parent, text="Utilities", style='Panel.TLabelframe')
util_frame.pack(fill=tk.X, pady=5)
btn_frame = ttk.Frame(util_frame, style='Panel.TFrame')
btn_frame.pack(fill=tk.X, padx=10, pady=10)
self.btn_pull = tk.Button(
btn_frame, text="Pull Latest", command=self.pull_latest,
bg=self.config_manager.colors['accent_light'], fg=self.config_manager.colors['fg'], font=('Arial', 10, 'bold'),
padx=15, pady=8, cursor='hand2', activebackground=self.config_manager.colors['accent']
)
self.btn_pull.pack(fill=tk.X, pady=5)
self.btn_install_dir = tk.Button(
btn_frame, text="Change Install Dir", command=self.change_install_dir,
bg=self.config_manager.colors['accent_light'], fg=self.config_manager.colors['fg'], font=('Arial', 10, 'bold'),
padx=15, pady=8, cursor='hand2', activebackground=self.config_manager.colors['accent']
)
self.btn_install_dir.pack(fill=tk.X, pady=5)
self.btn_settings = tk.Button(
btn_frame, text="Settings", command=self.open_settings,
bg=self.config_manager.colors['accent_light'], fg=self.config_manager.colors['fg'], font=('Arial', 10, 'bold'),
padx=15, pady=8, cursor='hand2', activebackground=self.config_manager.colors['accent']
)
self.btn_settings.pack(fill=tk.X, pady=5)
# Info display
self.info_label = ttk.Label(parent, text="", style='Info.TLabel', justify=tk.LEFT)
self.info_label.pack(fill=tk.X, pady=(15, 0), expand=True)
# Initialize status tracking
self.db_running = False
self.mm_running = False
def create_monitoring_panel(self, parent):
"""Create the monitoring panel"""
# Title
title = ttk.Label(parent, text="Resource Monitoring", style='Title.TLabel')
title.pack(pady=(0, 15))
# Containers monitoring
container_frame = ttk.LabelFrame(parent, text="Running Containers", style='Panel.TLabelframe')
container_frame.pack(fill=tk.BOTH, expand=True, pady=5)
# Treeview for containers
columns = ('Name', 'Status', 'CPU', 'Memory', 'Uptime')
self.container_tree = ttk.Treeview(
container_frame, columns=columns, height=8, show='headings'
)
self.container_tree.column('Name', width=150, anchor=tk.W)
self.container_tree.column('Status', width=100, anchor=tk.CENTER)
self.container_tree.column('CPU', width=80, anchor=tk.CENTER)
self.container_tree.column('Memory', width=100, anchor=tk.CENTER)
self.container_tree.column('Uptime', width=150, anchor=tk.W)
for col in columns:
self.container_tree.heading(col, text=col)
# Configure row tags for color coding
self.container_tree.tag_configure('Running', background=COLORS['success'], foreground='#000000')
self.container_tree.tag_configure('Stopped', background=COLORS['error'], foreground='#ffffff')
self.container_tree.pack(fill=tk.BOTH, expand=True, padx=5, pady=5)
# Scrollbar for treeview
scrollbar = ttk.Scrollbar(container_frame, orient=tk.VERTICAL, command=self.container_tree.yview)
scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
self.container_tree.configure(yscroll=scrollbar.set)
# Matchmaking server info
mm_frame = ttk.LabelFrame(parent, text="Matchmaking Server", style='Panel.TLabelframe')
mm_frame.pack(fill=tk.X, pady=5)
self.mm_info_label = tk.Label(
mm_frame, text="Status: Not Running", bg=COLORS['panel_bg'],
fg=COLORS['fg'], font=('Arial', 10), justify=tk.LEFT, padx=10, pady=10
)
self.mm_info_label.pack(fill=tk.X)
# Status bar
status_frame = ttk.Frame(parent, style='Dark.TFrame')
status_frame.pack(fill=tk.X, pady=(10, 0))
self.status_label = ttk.Label(parent, text="Ready", style='Info.TLabel')
self.status_label.pack(fill=tk.X, pady=5)
def start_monitoring(self):
"""Start the monitoring thread"""
self.monitoring = True
thread = threading.Thread(target=self.monitoring_thread, daemon=True)
thread.start()
# Start processing queue on main thread
self.process_queue()
def monitoring_thread(self):
"""Background thread for monitoring"""
while self.monitoring:
try:
# Get container info
containers = self.monitor.get_container_info()
# Get matchmaking info
mm_info = self.monitor.get_matchmaking_info()
self.update_queue.put(('containers', containers))
self.update_queue.put(('matchmaking', mm_info))
threading.Event().wait(2) # Update every 2 seconds
except Exception as e:
print(f"Monitoring error: {e}")
def process_queue(self):
"""Process updates from the monitoring thread"""
try:
while True:
msg_type, data = self.update_queue.get_nowait()
if msg_type == 'containers':
self.update_containers_display(data)
elif msg_type == 'matchmaking':
self.update_matchmaking_display(data)
except queue.Empty:
pass
self.root.after(500, self.process_queue)
def update_containers_display(self, containers):
"""Update the containers treeview"""
# Clear existing items
for item in self.container_tree.get_children():
self.container_tree.delete(item)
# Check if openchamp-db is running
db_found = False
for container in containers:
if 'openchamp-db' in container['name'].lower():
db_found = True
self.db_running = True
self._update_db_status_circle()
break
if not db_found:
self.db_running = False
self._update_db_status_circle()
# Add container info with color coding
for container in containers:
values = (
container['name'],
container['status'],
container['cpu'],
container['memory'],
container['up_time']
)
# Determine if container is running based on state field
is_running = container['state'] == 'running'
tag = 'Running' if is_running else 'Stopped'
self.container_tree.insert('', tk.END, values=values, tags=(tag,))
def update_matchmaking_display(self, info):
"""Update the matchmaking info display"""
if info:
text = (f"Status: Running (PID: {info['pid']})\n"
f"CPU: {info['cpu_percent']:.1f}%\n"
f"Memory: {info['memory_mb']:.1f} MB")
self.mm_running = True
self._update_mm_status_circle()
else:
text = "Status: Not Running"
self.mm_running = False
self._update_mm_status_circle()
self.mm_info_label.config(text=text)
def toggle_database(self):
"""Toggle database container state"""
if self.db_running:
self.stop_database()
else:
self.start_database()
def start_database(self):
"""Start database container"""
self.set_status("Starting database...")
thread = threading.Thread(target=self._start_database_thread, daemon=True)
thread.start()
def _start_database_thread(self):
"""Thread for starting database"""
success, message = self.service_manager.start_database_container()
color = COLORS['success'] if success else COLORS['error']
self.update_info(message, color)
self.set_status(message)
if success:
self.db_running = True
self._update_db_status_circle()
def stop_database(self):
"""Stop database container"""
self.set_status("Stopping database...")
thread = threading.Thread(target=self._stop_database_thread, daemon=True)
thread.start()
def _stop_database_thread(self):
"""Thread for stopping database"""
success, message = self.service_manager.stop_database_container()
color = COLORS['success'] if success else COLORS['error']
self.update_info(message, color)
self.set_status(message)
if success:
self.db_running = False
self._update_db_status_circle()
def _update_db_status_circle(self):
"""Update the database status circle color"""
color = COLORS['success'] if self.db_running else COLORS['error']
self.db_status_canvas.itemconfig(self.db_status_circle_db, fill=color)
def toggle_matchmaking(self):
"""Toggle matchmaking server state"""
if self.mm_running:
self.stop_matchmaking()
else:
self.start_matchmaking()
def start_matchmaking(self):
"""Start matchmaking server"""
self.set_status("Starting matchmaking server...")
thread = threading.Thread(target=self._start_matchmaking_thread, daemon=True)
thread.start()
def _start_matchmaking_thread(self):
"""Thread for starting matchmaking"""
success, message = self.service_manager.start_matchmaking_server()
color = COLORS['success'] if success else COLORS['error']
self.update_info(message, color)
self.set_status(message)
if success:
self.mm_running = True
self._update_mm_status_circle()
# Open output window and start reading process output
self.open_matchmaking_output_window()
# Start thread to read output
output_thread = threading.Thread(target=self.service_manager.read_matchmaking_output, daemon=True)
output_thread.start()
def stop_matchmaking(self):
"""Stop matchmaking server"""
self.set_status("Stopping matchmaking server...")
thread = threading.Thread(target=self._stop_matchmaking_thread, daemon=True)
thread.start()
def _stop_matchmaking_thread(self):
"""Thread for stopping matchmaking"""
success, message = self.service_manager.stop_matchmaking_server()
color = COLORS['success'] if success else COLORS['error']
self.update_info(message, color)
self.set_status(message)
if success:
self.mm_running = False
self._update_mm_status_circle()
# Close output window if it exists
if hasattr(self, 'mm_output_window') and self.mm_output_window and self.mm_output_window.winfo_exists():
self.mm_output_window.destroy()
def _update_mm_status_circle(self):
"""Update the matchmaking status circle color"""
color = COLORS['success'] if self.mm_running else COLORS['error']
self.mm_status_canvas.itemconfig(self.mm_status_circle_mm, fill=color)
def open_matchmaking_output_window(self):
"""Open a window to display matchmaking server output"""
# Close existing window if it exists
if hasattr(self, 'mm_output_window') and self.mm_output_window and self.mm_output_window.winfo_exists():
self.mm_output_window.destroy()
# Create new output window
self.mm_output_window = tk.Toplevel(self.root)
self.mm_output_window.title("Matchmaking Server - Output")
self.mm_output_window.geometry("800x500")
self.mm_output_window.configure(bg=COLORS['bg'])
# Header
header_frame = tk.Frame(self.mm_output_window, bg=COLORS['accent'], height=50)
header_frame.pack(fill=tk.X, padx=0, pady=0)
header_frame.pack_propagate(False)
header_label = tk.Label(
header_frame, text="Matchmaking Server Output",
bg=COLORS['accent'], fg=COLORS['fg'],
font=('Arial', 12, 'bold'), pady=10
)
header_label.pack(side=tk.LEFT, padx=20)
# Output text widget with scrollbar
text_frame = tk.Frame(self.mm_output_window, bg=COLORS['bg'])
text_frame.pack(fill=tk.BOTH, expand=True, padx=10, pady=10)
scrollbar = tk.Scrollbar(text_frame)
scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
self.mm_output_text = tk.Text(
text_frame,
bg=COLORS['panel_bg'],
fg=COLORS['fg'],
font=('Courier', 9),
state=tk.DISABLED,
yscrollcommand=scrollbar.set
)
self.mm_output_text.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
scrollbar.config(command=self.mm_output_text.yview)
# Button frame
button_frame = tk.Frame(self.mm_output_window, bg=COLORS['bg'])
button_frame.pack(fill=tk.X, padx=10, pady=10)
clear_button = tk.Button(
button_frame, text="Clear Output", command=self.clear_matchmaking_output,
bg=COLORS['accent_light'], fg=COLORS['fg'],
font=('Arial', 9, 'bold'), padx=15, pady=6,
cursor='hand2', activebackground=COLORS['accent']
)
clear_button.pack(side=tk.LEFT, padx=5)
# Start processing output
self.process_matchmaking_output()
def append_matchmaking_output(self, text: str):
"""Append text to matchmaking output window"""
if hasattr(self, 'mm_output_text'):
self.mm_output_text.config(state=tk.NORMAL)
self.mm_output_text.insert(tk.END, text + '\n')
self.mm_output_text.see(tk.END)
self.mm_output_text.config(state=tk.DISABLED)
def clear_matchmaking_output(self):
"""Clear the matchmaking output window"""
if hasattr(self, 'mm_output_text'):
self.mm_output_text.config(state=tk.NORMAL)
self.mm_output_text.delete(1.0, tk.END)
self.mm_output_text.config(state=tk.DISABLED)
def process_matchmaking_output(self):
"""Process output from matchmaking server queue"""
if 'matchmaking' not in self.service_manager.process_output_queues:
return
output_queue = self.service_manager.process_output_queues['matchmaking']
try:
while True:
msg_type, data = output_queue.get_nowait()
if msg_type == 'output':
self.append_matchmaking_output(data)
elif msg_type == 'error':
self.append_matchmaking_output(f"[ERROR] {data}")
elif msg_type == 'end':
self.append_matchmaking_output("[Process ended]")
return
except queue.Empty:
pass
# Check again in 100ms if window still exists
if hasattr(self, 'mm_output_window') and self.mm_output_window and self.mm_output_window.winfo_exists():
self.mm_output_window.after(100, self.process_matchmaking_output)
def pull_latest(self):
"""Pull latest versions with progress window"""
self.set_status("Pulling latest versions...")
# Create progress window
progress_window = tk.Toplevel(self.root)
progress_window.title("Pull Latest - Progress")
progress_window.geometry("700x500")
progress_window.configure(bg=COLORS['bg'])
progress_window.resizable(True, True)
# Center the window
progress_window.update_idletasks()
x = (progress_window.winfo_screenwidth() // 2) - (progress_window.winfo_width() // 2)
y = (progress_window.winfo_screenheight() // 2) - (progress_window.winfo_height() // 2)
progress_window.geometry(f"+{x}+{y}")
# Title
title_label = tk.Label(
progress_window, text="Updating OpenChamp...",
bg=COLORS['bg'], fg=COLORS['accent_light'],
font=('Arial', 12, 'bold'), pady=10
)
title_label.pack(fill=tk.X, padx=10)
# Progress text widget
progress_frame = tk.Frame(progress_window, bg=COLORS['panel_bg'], relief=tk.SUNKEN, borderwidth=1)
progress_frame.pack(fill=tk.BOTH, expand=True, padx=10, pady=10)
output_text = tk.Text(
progress_frame, bg=COLORS['panel_bg'], fg=COLORS['fg'],
font=('Courier', 9), state=tk.DISABLED, wrap=tk.WORD
)
output_text.pack(fill=tk.BOTH, expand=True, padx=5, pady=5)
# Scrollbar
scrollbar = tk.Scrollbar(output_text, command=output_text.yview)
scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
output_text.config(yscrollcommand=scrollbar.set)
# Close button
close_button = tk.Button(
progress_window, text="Close", command=progress_window.destroy,
bg=COLORS['success'], fg=COLORS['fg'],
font=('Arial', 10, 'bold'), padx=20, pady=8,
cursor='hand2', state=tk.DISABLED
)
close_button.pack(pady=10)
# Queue for progress updates
progress_queue = queue.Queue()
def run_pull():
"""Run pull in background thread"""
success, message = self.service_manager.pull_latest_versions(progress_queue=progress_queue)
progress_queue.put(('complete', success, message))
def process_progress():
"""Process progress queue updates"""
try:
while True:
msg_type, *args = progress_queue.get_nowait()
if msg_type == 'update':
# Update the text widget with output
message = args[0] if args else ""
output_text.config(state=tk.NORMAL)
output_text.insert(tk.END, message)
output_text.see(tk.END)
output_text.config(state=tk.DISABLED)
progress_window.update_idletasks()
elif msg_type == 'complete':
# Pull is done
success = args[0] if args else False
message = args[1] if len(args) > 1 else ""
color = COLORS['success'] if success else COLORS['warning']
title_label.config(text="✓ Update Complete!" if success else "⚠ Update Complete with Warnings",
fg=color)
close_button.config(state=tk.NORMAL)
self.update_info(message, color)
self.set_status("Pull complete" if success else "Pull completed with warnings")
progress_window.lift() # Bring window to front
return
except queue.Empty:
pass
# Check again in 100ms if window still exists
if progress_window.winfo_exists():
progress_window.after(100, process_progress)
# Start pull thread
pull_thread = threading.Thread(target=run_pull, daemon=True)
pull_thread.start()
# Start queue processor
process_progress()
def open_settings(self):
"""Open the database settings window"""
settings_window = tk.Toplevel(self.root)
settings_window.title("Database Settings")
settings_window.geometry("600x650")
settings_window.configure(bg=COLORS['bg'])
settings_window.resizable(False, False)
# Center the window
settings_window.update_idletasks()
x = (settings_window.winfo_screenwidth() // 2) - (settings_window.winfo_width() // 2)
y = (settings_window.winfo_screenheight() // 2) - (settings_window.winfo_height() // 2)
settings_window.geometry(f"+{x}+{y}")
# Make it stay on top
settings_window.attributes('-topmost', True)
# Header
header_frame = tk.Frame(settings_window, bg=COLORS['accent'], height=50)
header_frame.pack(fill=tk.X, padx=0, pady=0)
header_frame.pack_propagate(False)
header_label = tk.Label(
header_frame, text="Database Container Settings",
bg=COLORS['accent'], fg=COLORS['fg'],
font=('Arial', 14, 'bold'), pady=10
)
header_label.pack(side=tk.LEFT, padx=20)
# Main scrollable frame
canvas_frame = tk.Frame(settings_window, bg=COLORS['bg'])
canvas_frame.pack(fill=tk.BOTH, expand=True, padx=10, pady=10)
# Create scrollable canvas
canvas = tk.Canvas(canvas_frame, bg=COLORS['bg'], highlightthickness=0)
scrollbar = tk.Scrollbar(canvas_frame, orient=tk.VERTICAL, command=canvas.yview)
scrollable_frame = tk.Frame(canvas, bg=COLORS['bg'])
scrollable_frame.bind(
"<Configure>",
lambda e: canvas.configure(scrollregion=canvas.bbox("all"))
)
canvas.create_window((0, 0), window=scrollable_frame, anchor="nw")
canvas.configure(yscrollcommand=scrollbar.set)
canvas.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
# Storage for entry widgets
entries = {}
checkboxes = {}
# Container Information Section
section_frame = tk.Frame(scrollable_frame, bg=COLORS['panel_bg'], relief=tk.SUNKEN, borderwidth=1)
section_frame.pack(fill=tk.X, pady=10, padx=5)
section_label = tk.Label(
section_frame, text="Container Information",
bg=COLORS['panel_bg'], fg=COLORS['accent_light'],
font=('Arial', 11, 'bold'), padx=10, pady=8
)
section_label.pack(fill=tk.X)
# Container Name
name_frame = tk.Frame(section_frame, bg=COLORS['panel_bg'])
name_frame.pack(fill=tk.X, padx=10, pady=5)
tk.Label(
name_frame, text="Container Name:", bg=COLORS['panel_bg'],
fg=COLORS['fg'], font=('Arial', 10), width=20, anchor='w'
).pack(side=tk.LEFT)
entries['container_name'] = tk.Entry(
name_frame, bg=COLORS['accent'], fg=COLORS['fg'],
font=('Arial', 10), width=30
)
entries['container_name'].insert(0, self.service_manager.db_settings['container_name'])
entries['container_name'].pack(side=tk.LEFT, padx=5)
# Database Configuration Section
section_frame2 = tk.Frame(scrollable_frame, bg=COLORS['panel_bg'], relief=tk.SUNKEN, borderwidth=1)
section_frame2.pack(fill=tk.X, pady=10, padx=5)
section_label2 = tk.Label(
section_frame2, text="Database Configuration",
bg=COLORS['panel_bg'], fg=COLORS['accent_light'],
font=('Arial', 11, 'bold'), padx=10, pady=8
)
section_label2.pack(fill=tk.X)
# Database Name
db_name_frame = tk.Frame(section_frame2, bg=COLORS['panel_bg'])
db_name_frame.pack(fill=tk.X, padx=10, pady=5)
tk.Label(
db_name_frame, text="Database Name:", bg=COLORS['panel_bg'],
fg=COLORS['fg'], font=('Arial', 10), width=20, anchor='w'
).pack(side=tk.LEFT)
entries['database_name'] = tk.Entry(
db_name_frame, bg=COLORS['accent'], fg=COLORS['fg'],
font=('Arial', 10), width=30
)
entries['database_name'].insert(0, self.service_manager.db_settings['database_name'])
entries['database_name'].pack(side=tk.LEFT, padx=5)
# Database User
db_user_frame = tk.Frame(section_frame2, bg=COLORS['panel_bg'])
db_user_frame.pack(fill=tk.X, padx=10, pady=5)
tk.Label(
db_user_frame, text="Database User:", bg=COLORS['panel_bg'],
fg=COLORS['fg'], font=('Arial', 10), width=20, anchor='w'
).pack(side=tk.LEFT)
entries['database_user'] = tk.Entry(
db_user_frame, bg=COLORS['accent'], fg=COLORS['fg'],
font=('Arial', 10), width=30
)
entries['database_user'].insert(0, self.service_manager.db_settings['database_user'])
entries['database_user'].pack(side=tk.LEFT, padx=5)
# Database Password
db_pass_frame = tk.Frame(section_frame2, bg=COLORS['panel_bg'])
db_pass_frame.pack(fill=tk.X, padx=10, pady=5)
tk.Label(
db_pass_frame, text="Database Password:", bg=COLORS['panel_bg'],
fg=COLORS['fg'], font=('Arial', 10), width=20, anchor='w'
).pack(side=tk.LEFT)
entries['database_password'] = tk.Entry(
db_pass_frame, bg=COLORS['accent'], fg=COLORS['fg'],
font=('Arial', 10), width=30, show='*'
)
entries['database_password'].insert(0, self.service_manager.db_settings['database_password'])
entries['database_password'].pack(side=tk.LEFT, padx=5)
# Database Port
db_port_frame = tk.Frame(section_frame2, bg=COLORS['panel_bg'])
db_port_frame.pack(fill=tk.X, padx=10, pady=5)
tk.Label(
db_port_frame, text="Database Port:", bg=COLORS['panel_bg'],
fg=COLORS['fg'], font=('Arial', 10), width=20, anchor='w'
).pack(side=tk.LEFT)
entries['database_port'] = tk.Entry(
db_port_frame, bg=COLORS['accent'], fg=COLORS['fg'],
font=('Arial', 10), width=30
)
entries['database_port'].insert(0, self.service_manager.db_settings['database_port'])
entries['database_port'].pack(side=tk.LEFT, padx=5)