-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard.py
More file actions
2013 lines (1734 loc) · 83.7 KB
/
dashboard.py
File metadata and controls
2013 lines (1734 loc) · 83.7 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
#!/usr/bin/env python3
"""
Linux Gaming Center - Dashboard Screen
"""
import tkinter as tk
from tkinter import Menu
from pathlib import Path
import json
import os
from path_helper import get_user_account_dir, get_config_file_path, get_data_base_path
# Try to import PIL for image handling (optional)
try:
from PIL import Image, ImageTk
PIL_AVAILABLE = True
except ImportError:
PIL_AVAILABLE = False
class DashboardScreen:
def __init__(self, parent, on_logout, on_exit, theme, scaler):
self.parent = parent
self.on_logout = on_logout
self.on_exit = on_exit
self.theme = theme
self.scaler = scaler
self.username = None
self.previous_username = None # Track previous username to detect user change
self.profile_image_path = None
self.menu_bar_frame = None
self.profile_menu = None
self.admin_menu = None
self.admin_button = None
self.power_menu = None
bg_color = self.theme.get_color("background", "#1A1A2E")
text_color = self.theme.get_color("text_primary", "#FFFFFF")
self.frame = tk.Frame(parent, bg=bg_color)
self.frame.pack(fill=tk.BOTH, expand=True)
# Menu bar frame (larger, scaled)
menu_bar_color = self.theme.get_color("menu_bar", "#34495E")
menu_bar_height = self.scaler.scale_dimension(70)
self.menu_bar_frame = tk.Frame(self.frame, bg=menu_bar_color, height=menu_bar_height)
self.menu_bar_frame.pack(fill=tk.X, side=tk.TOP)
self.menu_bar_frame.pack_propagate(False)
# Home button on the left (will be created, initially hidden on dashboard)
self.home_button = None
# Right side container for profile and power button (stored for reuse)
self.right_container = tk.Frame(self.menu_bar_frame, bg=menu_bar_color)
self.right_container.pack(side=tk.RIGHT, padx=self.scaler.scale_padding(15), pady=self.scaler.scale_padding(15))
# Power button (will be created)
self.power_button = None
# Store button (will be created)
self.store_button = None
# Profile section (will be created when username is set)
self.profile_container = None
# Create scrollable content area
# Create a canvas for scrolling (no visible scrollbar)
self.scroll_canvas = tk.Canvas(self.frame, bg=bg_color, highlightthickness=0)
self.scroll_canvas.pack(fill=tk.BOTH, expand=True)
# Content area for library buttons and frames (inside canvas)
self.content_area = tk.Frame(self.scroll_canvas, bg=bg_color)
self.scroll_canvas_window = self.scroll_canvas.create_window((0, 0), window=self.content_area, anchor="nw")
# Configure scroll region
def configure_scroll_region(event=None):
self.scroll_canvas.update_idletasks()
# Always set canvas window to full canvas size
canvas_width = event.width if event else self.scroll_canvas.winfo_width()
canvas_height = event.height if event else self.scroll_canvas.winfo_height()
if canvas_width > 1 and canvas_height > 1:
self.scroll_canvas.itemconfig(self.scroll_canvas_window, width=canvas_width, height=canvas_height)
# For scroll region, check if we have a frame that needs scrolling or should fill
bbox = self.scroll_canvas.bbox("all")
if bbox:
# If control panel is active, use full canvas size, otherwise use content bbox
if hasattr(self, 'current_frame') and self.current_frame and hasattr(self.current_frame, '__class__'):
frame_class_name = self.current_frame.__class__.__name__
if frame_class_name == "ControlPanelFrame":
# Control panel: use full canvas size (no scrolling)
self.scroll_canvas.configure(scrollregion=(0, 0, canvas_width, canvas_height))
else:
# Other frames: use content bbox (allow scrolling)
self.scroll_canvas.configure(scrollregion=bbox)
else:
# Default: use content bbox
self.scroll_canvas.configure(scrollregion=bbox)
self.content_area.bind("<Configure>", configure_scroll_region)
self.scroll_canvas.bind("<Configure>", configure_scroll_region)
# Mouse wheel scrolling
def on_mousewheel(event):
# Windows and Mac
if event.delta:
scroll_amount = int(-1 * (event.delta / 40))
self.scroll_canvas.yview_scroll(scroll_amount, "units")
return "break"
# Linux mousewheel support
def scroll_up(e):
if self.scroll_canvas.yview()[0] > 0.0:
self.scroll_canvas.yview_scroll(-3, "units")
def scroll_down(e):
if self.scroll_canvas.yview()[1] < 1.0:
self.scroll_canvas.yview_scroll(3, "units")
# Bind mousewheel events
self.scroll_canvas.bind("<MouseWheel>", on_mousewheel)
self.content_area.bind("<MouseWheel>", on_mousewheel)
self.scroll_canvas.bind("<Button-4>", scroll_up)
self.scroll_canvas.bind("<Button-5>", scroll_down)
self.content_area.bind("<Button-4>", scroll_up)
self.content_area.bind("<Button-5>", scroll_down)
# Arrow key scrolling
def on_arrow_key(event):
if event.keysym == "Up":
if self.scroll_canvas.yview()[0] > 0.0:
self.scroll_canvas.yview_scroll(-3, "units")
elif event.keysym == "Down":
if self.scroll_canvas.yview()[1] < 1.0:
self.scroll_canvas.yview_scroll(3, "units")
elif event.keysym == "Page_Up":
self.scroll_canvas.yview_scroll(-1, "page")
elif event.keysym == "Page_Down":
self.scroll_canvas.yview_scroll(1, "page")
elif event.keysym == "Home":
self.scroll_canvas.yview_moveto(0)
elif event.keysym == "End":
self.scroll_canvas.yview_moveto(1)
return "break"
# Bind arrow keys to the frame and canvas
self.frame.bind("<KeyPress>", on_arrow_key)
self.scroll_canvas.bind("<KeyPress>", on_arrow_key)
self.content_area.bind("<KeyPress>", on_arrow_key)
# Make sure the frame can receive focus for keyboard events
self.frame.focus_set()
self.scroll_canvas.focus_set()
# Store reference to on_arrow_key for use in show/hide methods
self.on_arrow_key = on_arrow_key
# Library buttons container (initially visible)
self.library_buttons_frame = tk.Frame(self.content_area, bg=bg_color)
self.library_buttons_frame.pack(pady=self.scaler.scale_padding(30))
# Create recently used sections in configured order
self.create_recently_used_sections_in_order()
# Frame container (where frame content will be displayed, initially hidden)
self.frame_container = tk.Frame(self.content_area, bg=bg_color)
# Don't pack initially - will be shown when a frame is loaded
# Store frame container padding for reuse
self.frame_padding = self.scaler.scale_padding(20)
# Current frame instance
self.current_frame = None
# Create library buttons
self.create_library_buttons()
def create_home_button(self):
"""Create home button on the left side of menu bar"""
if self.home_button:
return # Already created
menu_bar_color = self.theme.get_color("menu_bar", "#34495E")
text_color = self.theme.get_color("text_primary", "#FFFFFF")
# Get app root and load home icon
from theme_manager import get_app_root
app_root = get_app_root()
home_image_path = app_root / "data" / "themes" / "cosmic-twilight" / "images" / "home.png"
if home_image_path.exists() and PIL_AVAILABLE:
try:
image = Image.open(home_image_path)
# Resize to fit menu bar (larger, scaled)
icon_size = self.scaler.scale_dimension(40)
image = image.resize((icon_size, icon_size), Image.Resampling.LANCZOS)
photo = ImageTk.PhotoImage(image)
self.home_button = tk.Button(
self.menu_bar_frame,
image=photo,
command=self.go_home,
bg=menu_bar_color,
cursor="hand2",
relief=tk.FLAT,
borderwidth=0,
highlightthickness=0,
activebackground=self.theme.get_color("background_secondary", "#1A1A1A")
)
self.home_button.image = photo # Keep reference
# Don't pack initially - will be shown when needed
except Exception as e:
print(f"Error loading home icon: {e}")
# Fallback to text button
home_font = self.scaler.get_font("Arial", 14)
self.home_button = tk.Button(
self.menu_bar_frame,
text="Home",
command=self.go_home,
bg=menu_bar_color,
fg=text_color,
cursor="hand2",
relief=tk.FLAT,
borderwidth=0,
highlightthickness=0,
font=home_font
)
else:
# Fallback to text button if image not available
home_font = self.scaler.get_font("Arial", 14)
self.home_button = tk.Button(
self.menu_bar_frame,
text="Home",
command=self.go_home,
bg=menu_bar_color,
fg=text_color,
cursor="hand2",
relief=tk.FLAT,
borderwidth=0,
highlightthickness=0,
font=home_font
)
def show_home_button(self):
"""Show the home button"""
if self.home_button:
self.home_button.pack(side=tk.LEFT, padx=self.scaler.scale_padding(20), pady=self.scaler.scale_padding(15))
def hide_home_button(self):
"""Hide the home button"""
if self.home_button:
self.home_button.pack_forget()
def create_profile_section(self):
"""Create profile image and name dropdown on the right side"""
if not self.username:
return
menu_bar_color = self.theme.get_color("menu_bar", "#34495E")
text_color = self.theme.get_color("text_primary", "#FFFFFF")
button_small_font = self.theme.get_font("button_small", scaler=self.scaler)
# Remove existing profile container if it exists
if self.profile_container:
self.profile_container.destroy()
# Profile container
self.profile_container = tk.Frame(self.right_container, bg=menu_bar_color)
self.profile_container.pack(side=tk.LEFT, padx=(0, 10))
# Profile image (larger, for menu bar, scaled)
profile_image_label = None
if self.profile_image_path and os.path.exists(self.profile_image_path) and PIL_AVAILABLE:
try:
image = Image.open(self.profile_image_path)
# Resize to larger size for menu bar (scaled)
profile_icon_size = self.scaler.scale_dimension(40)
image = image.resize((profile_icon_size, profile_icon_size), Image.Resampling.LANCZOS)
photo = ImageTk.PhotoImage(image)
profile_image_label = tk.Label(
self.profile_container,
image=photo,
bg=menu_bar_color,
cursor="hand2"
)
profile_image_label.image = photo # Keep reference
profile_image_label.bind("<Button-1>", lambda e: self.show_profile_menu())
profile_image_label.pack(side=tk.LEFT, padx=(0, self.scaler.scale_padding(8)))
except Exception as e:
print(f"Error loading profile image for menu: {e}")
# Profile name button (acts as dropdown trigger)
profile_name_button = tk.Button(
self.profile_container,
text=self.username,
font=button_small_font,
bg=menu_bar_color,
fg=text_color,
cursor="hand2",
relief=tk.FLAT,
borderwidth=0,
highlightthickness=0,
activebackground=self.theme.get_color("background_secondary", "#1A1A1A"),
command=self.show_profile_menu
)
profile_name_button.pack(side=tk.LEFT)
# Create profile dropdown menu
self.profile_menu = Menu(
self.parent,
tearoff=0,
bg=self.theme.get_color("background_secondary", "#1A1A1A"),
fg=text_color,
activebackground=self.theme.get_color("primary", "#9D4EDD"),
activeforeground=text_color,
borderwidth=0,
relief=tk.FLAT
)
self.profile_menu.add_command(label="Account settings", command=self.account_settings)
# Create store button
self.create_store_button()
def create_store_button(self):
"""Create the store button in the menu bar"""
menu_bar_color = self.theme.get_color("menu_bar", "#34495E")
# Remove existing store button if it exists
if self.store_button:
self.store_button.destroy()
# Store button container
self.store_button = tk.Frame(self.right_container, bg=menu_bar_color)
self.store_button.pack(side=tk.LEFT, padx=(0, self.scaler.scale_padding(15)))
# Try to load store icon
store_icon_size = self.scaler.scale_dimension(32)
store_icon_loaded = False
from theme_manager import get_app_root
app_root = get_app_root()
store_icon_path = app_root / "data" / "themes" / "cosmic-twilight" / "images" / "appstore.png"
if store_icon_path.exists() and PIL_AVAILABLE:
try:
image = Image.open(store_icon_path)
image = image.resize((store_icon_size, store_icon_size), Image.Resampling.LANCZOS)
photo = ImageTk.PhotoImage(image)
store_icon_label = tk.Label(
self.store_button,
image=photo,
bg=menu_bar_color,
cursor="hand2"
)
store_icon_label.image = photo # Keep reference
store_icon_label.bind("<Button-1>", lambda e: self.open_store())
store_icon_label.pack(side=tk.LEFT)
store_icon_loaded = True
except Exception as e:
print(f"Error loading store icon: {e}")
# Fallback to text button if icon not loaded
if not store_icon_loaded:
text_color = self.theme.get_color("text_primary", "#FFFFFF")
button_small_font = self.theme.get_font("button_small", scaler=self.scaler)
store_text_btn = tk.Button(
self.store_button,
text="Store",
font=button_small_font,
bg=menu_bar_color,
fg=text_color,
cursor="hand2",
relief=tk.FLAT,
borderwidth=0,
command=self.open_store
)
store_text_btn.pack(side=tk.LEFT)
def open_store(self):
"""Open the store frame"""
# Show home button (we're leaving dashboard)
self.create_home_button()
self.show_home_button()
# Hide library buttons
self.library_buttons_frame.pack_forget()
# Hide recently used apps section
if hasattr(self, 'recently_used_container'):
self.recently_used_container.pack_forget()
# Hide recently used open source games section
if hasattr(self, 'recently_used_osg_container'):
self.recently_used_osg_container.pack_forget()
# Hide recently used Windows/Steam games section
if hasattr(self, 'recently_used_ws_container'):
self.recently_used_ws_container.pack_forget()
# Hide current frame if exists
if self.current_frame:
self.current_frame.hide()
self.current_frame = None
# Clear the frame container
for widget in self.frame_container.winfo_children():
widget.destroy()
# Show frame container
self.frame_container.pack(fill=tk.BOTH, expand=True, padx=self.frame_padding, pady=self.frame_padding)
try:
# Import and create store frame
from theme_manager import get_app_root
import sys
app_root = get_app_root()
frames_dir = app_root / "data" / "frames"
if str(frames_dir) not in sys.path:
sys.path.insert(0, str(frames_dir))
from store import StoreFrame
self.current_frame = StoreFrame(
self.frame_container,
self.theme,
self.scaler,
self.username
)
except Exception as e:
print(f"Error loading store: {e}")
import traceback
traceback.print_exc()
from tkinter import messagebox
messagebox.showerror("Error", f"Failed to load Store:\n{str(e)}")
def is_admin(self):
"""Check if current user is an administrator"""
if not self.username:
return False
account_dir = get_user_account_dir(self.username)
account_file = account_dir / "account.json"
if account_file.exists():
try:
with open(account_file, 'r') as f:
account_data = json.load(f)
account_type = account_data.get("account_type", "basic")
return account_type == "administrator"
except Exception as e:
print(f"Error checking admin status: {e}")
return False
return False
def create_admin_button(self):
"""Create Admin button with dropdown menu (only for admin users)"""
if not self.is_admin():
# Remove admin button if it exists and user is not admin
if self.admin_button:
self.admin_button.destroy()
self.admin_button = None
self.admin_menu = None
return
menu_bar_color = self.theme.get_color("menu_bar", "#34495E")
text_color = self.theme.get_color("text_primary", "#FFFFFF")
button_small_font = self.theme.get_font("button_small", scaler=self.scaler)
# Remove existing admin button if it exists
if self.admin_button:
self.admin_button.destroy()
# Admin button
self.admin_button = tk.Button(
self.right_container,
text="Admin",
font=button_small_font,
bg=menu_bar_color,
fg=text_color,
cursor="hand2",
relief=tk.FLAT,
borderwidth=0,
highlightthickness=0,
activebackground=self.theme.get_color("background_secondary", "#1A1A1A"),
command=self.show_admin_menu
)
# Pack between profile and power button (before power button)
self.admin_button.pack(side=tk.RIGHT, padx=(0, self.scaler.scale_padding(10)))
# Create admin dropdown menu
menu_font = self.scaler.get_font("Arial", 12)
self.admin_menu = Menu(
self.parent,
tearoff=0,
bg=self.theme.get_color("background_secondary", "#1A1A1A"),
fg=text_color,
activebackground=self.theme.get_color("primary", "#9D4EDD"),
activeforeground=text_color,
borderwidth=0,
relief=tk.FLAT,
font=menu_font
)
self.admin_menu.add_command(label="Control Panel", command=self.open_control_panel)
def show_admin_menu(self):
"""Show admin dropdown menu"""
if self.admin_menu and self.admin_button:
try:
x = self.admin_button.winfo_rootx()
y = self.admin_button.winfo_rooty() + self.admin_button.winfo_height()
self.admin_menu.tk_popup(x, y)
except Exception as e:
print(f"Error showing admin menu: {e}")
def open_control_panel(self):
"""Open the Control Panel frame"""
# Hide library buttons and recently used sections
self.library_buttons_frame.pack_forget()
if hasattr(self, 'recently_used_container'):
self.recently_used_container.pack_forget()
if hasattr(self, 'recently_used_osg_container'):
self.recently_used_osg_container.pack_forget()
if hasattr(self, 'recently_used_ws_container'):
self.recently_used_ws_container.pack_forget()
# Show home button
self.create_home_button()
if self.home_button:
self.home_button.pack(side=tk.LEFT, padx=self.scaler.scale_padding(15), pady=self.scaler.scale_padding(15))
# Load control panel frame
try:
# Hide current frame if exists
if self.current_frame:
self.current_frame.hide()
# Clear frame container to remove any lingering widgets
for widget in self.frame_container.winfo_children():
widget.destroy()
# Add frames directory to path for imports
import sys
from theme_manager import get_app_root
app_root = get_app_root()
frames_dir = app_root / "data" / "frames"
if str(frames_dir) not in sys.path:
sys.path.insert(0, str(frames_dir))
# Import and create control panel frame
from controlpanel import ControlPanelFrame
self.current_frame = ControlPanelFrame(self.frame_container, self.theme, self.scaler)
self.current_frame.show()
# Show frame container (no padding for control panel to fill entire window)
self.frame_container.pack(fill=tk.BOTH, expand=True, padx=0, pady=0)
# Force canvas window to fill full canvas height/width for control panel
def update_canvas_for_control_panel():
self.scroll_canvas.update_idletasks()
canvas_width = self.scroll_canvas.winfo_width()
canvas_height = self.scroll_canvas.winfo_height()
if canvas_width > 1 and canvas_height > 1:
# Set canvas window to full canvas size
self.scroll_canvas.itemconfig(self.scroll_canvas_window, width=canvas_width, height=canvas_height)
# Set scroll region to match (no scrolling needed for control panel)
self.scroll_canvas.configure(scrollregion=(0, 0, canvas_width, canvas_height))
# Update immediately and after a short delay
update_canvas_for_control_panel()
self.parent.after(100, update_canvas_for_control_panel)
self.parent.after(300, update_canvas_for_control_panel)
except Exception as e:
print(f"Error loading control panel: {e}")
from tkinter import messagebox
messagebox.showerror("Error", f"Failed to load Control Panel:\n{str(e)}")
def create_power_button(self):
"""Create power button with dropdown menu"""
menu_bar_color = self.theme.get_color("menu_bar", "#34495E")
text_color = self.theme.get_color("text_primary", "#FFFFFF")
# Remove existing power button if it exists
if self.power_button:
self.power_button.destroy()
# Get app root and load power icon
from theme_manager import get_app_root
app_root = get_app_root()
power_image_path = app_root / "data" / "themes" / "cosmic-twilight" / "images" / "power.png"
# Power button
if power_image_path.exists() and PIL_AVAILABLE:
try:
image = Image.open(power_image_path)
# Resize to fit menu bar (larger, scaled)
icon_size = self.scaler.scale_dimension(40)
image = image.resize((icon_size, icon_size), Image.Resampling.LANCZOS)
photo = ImageTk.PhotoImage(image)
self.power_button = tk.Button(
self.right_container,
image=photo,
command=self.show_power_menu,
bg=menu_bar_color,
cursor="hand2",
relief=tk.FLAT,
borderwidth=0,
highlightthickness=0,
activebackground=self.theme.get_color("background_secondary", "#1A1A1A")
)
self.power_button.image = photo # Keep reference
self.power_button.pack(side=tk.RIGHT)
except Exception as e:
print(f"Error loading power icon: {e}")
# Fallback to text button
power_font = self.scaler.get_font("Arial", 18)
self.power_button = tk.Button(
self.right_container,
text="⚡",
font=power_font,
bg=menu_bar_color,
fg=text_color,
cursor="hand2",
relief=tk.FLAT,
borderwidth=0,
highlightthickness=0,
activebackground=self.theme.get_color("background_secondary", "#1A1A1A"),
command=self.show_power_menu
)
self.power_button.pack(side=tk.RIGHT)
else:
# Fallback to text button if image not available
power_font = self.scaler.get_font("Arial", 18)
self.power_button = tk.Button(
self.right_container,
text="⚡",
font=power_font,
bg=menu_bar_color,
fg=text_color,
cursor="hand2",
relief=tk.FLAT,
borderwidth=0,
highlightthickness=0,
activebackground=self.theme.get_color("background_secondary", "#1A1A1A"),
command=self.show_power_menu
)
self.power_button.pack(side=tk.RIGHT)
# Create power dropdown menu
menu_font = self.scaler.get_font("Arial", 12)
self.power_menu = Menu(
self.parent,
tearoff=0,
bg=self.theme.get_color("background_secondary", "#1A1A1A"),
fg=text_color,
activebackground=self.theme.get_color("primary", "#9D4EDD"),
activeforeground=text_color,
borderwidth=0,
relief=tk.FLAT,
font=menu_font
)
self.power_menu.add_command(label="Logout", command=self.logout)
self.power_menu.add_separator()
self.power_menu.add_command(label="Exit app", command=self.exit_app)
def show_profile_menu(self):
"""Show profile dropdown menu"""
if self.profile_menu and self.profile_container:
try:
# Get position of profile container
x = self.profile_container.winfo_rootx()
y = self.profile_container.winfo_rooty() + self.profile_container.winfo_height()
self.profile_menu.tk_popup(x, y)
except Exception as e:
print(f"Error showing profile menu: {e}")
def show_power_menu(self):
"""Show power dropdown menu"""
if self.power_menu and self.power_button:
try:
x = self.power_button.winfo_rootx()
y = self.power_button.winfo_rooty() + self.power_button.winfo_height()
self.power_menu.tk_popup(x, y)
except Exception as e:
print(f"Error showing power menu: {e}")
def create_library_buttons(self):
"""Create library buttons in a grid row"""
from theme_manager import get_app_root
app_root = get_app_root()
images_dir = app_root / "data" / "themes" / "cosmic-twilight" / "images"
menu_bar_color = self.theme.get_color("menu_bar", "#2D2D2D")
text_color = self.theme.get_color("text_primary", "#FFFFFF")
# Library button configurations
libraries = [
{
"name": "Apps",
"image": "apps.jpg",
"frame": "apps"
},
{
"name": "Emulators",
"image": "emulators.jpg",
"frame": "emulators"
},
{
"name": "Open Source Gaming",
"image": "opensourcegaming.jpg",
"frame": "opensourcegaming"
},
{
"name": "Windows/Steam",
"image": "windowssteam.jpg",
"frame": "windowssteam"
}
]
for i, lib in enumerate(libraries):
image_path = images_dir / lib["image"]
# Create button frame
button_frame = tk.Frame(self.library_buttons_frame, bg=menu_bar_color)
button_frame.grid(row=0, column=i, padx=15, pady=10)
# Load and display image (larger buttons)
button = None
if image_path.exists() and PIL_AVAILABLE:
try:
image = Image.open(image_path)
# Resize to larger size (250x200 - wider)
image = image.resize((350, 200), Image.Resampling.LANCZOS)
photo = ImageTk.PhotoImage(image)
button = tk.Button(
button_frame,
image=photo,
command=lambda f=lib["frame"]: self.load_frame(f),
bg=menu_bar_color,
cursor="hand2",
relief=tk.FLAT,
borderwidth=0,
highlightthickness=0,
activebackground=self.theme.get_color("background_secondary", "#1A1A1A")
)
button.image = photo # Keep reference
button.pack()
except Exception as e:
print(f"Error loading {lib['name']} image: {e}")
# Fallback to text button
button_font = self.theme.get_font("button_small", scaler=self.scaler)
button = tk.Button(
button_frame,
text=lib["name"],
command=lambda f=lib["frame"]: self.load_frame(f),
bg=menu_bar_color,
fg=text_color,
cursor="hand2",
relief=tk.FLAT,
borderwidth=0,
highlightthickness=0,
font=button_font,
padx=self.scaler.scale_padding(20),
pady=self.scaler.scale_padding(10)
)
button.pack()
else:
# Fallback to text button
button_font = self.theme.get_font("button_small", scaler=self.scaler)
button = tk.Button(
button_frame,
text=lib["name"],
command=lambda f=lib["frame"]: self.load_frame(f),
bg=menu_bar_color,
fg=text_color,
cursor="hand2",
relief=tk.FLAT,
borderwidth=0,
highlightthickness=0,
font=button_font,
padx=self.scaler.scale_padding(20),
pady=self.scaler.scale_padding(10)
)
button.pack()
def create_recently_used_sections_in_order(self):
"""Create recently used sections in the configured order"""
# Load order from config
config_file = get_config_file_path("dashboard_config.json")
order = ["apps", "opensourcegaming", "windowssteam"] # Default order
if config_file.exists():
try:
with open(config_file, 'r') as f:
config = json.load(f)
order = config.get("recently_used_order", order)
except:
pass
# Create sections in the specified order
for section_key in order:
if section_key == "apps":
self.create_recently_used_section()
elif section_key == "opensourcegaming":
self.create_recently_used_opensourcegaming_section()
elif section_key == "windowssteam":
self.create_recently_used_windowssteam_section()
def create_recently_used_section(self):
"""Create the Recently Used Apps section"""
bg_color = self.theme.get_color("background", "#000000")
text_color = self.theme.get_color("text_primary", "#FFFFFF")
# Section container
recently_used_container = tk.Frame(self.content_area, bg=bg_color)
recently_used_container.pack(fill=tk.X, padx=self.scaler.scale_padding(20), pady=(self.scaler.scale_padding(20), 0))
# Title
heading_font = self.theme.get_font("heading", scaler=self.scaler)
title_label = tk.Label(
recently_used_container,
text="Recently Used Apps",
font=heading_font,
bg=bg_color,
fg=text_color,
anchor="w"
)
title_label.pack(fill=tk.X, pady=(0, self.scaler.scale_padding(15)))
# Scrollable frame with left/right buttons
scroll_container = tk.Frame(recently_used_container, bg=bg_color)
scroll_container.pack(fill=tk.X)
# Left scroll button
button_font = self.theme.get_font("button", scaler=self.scaler)
primary_color = self.theme.get_color("primary", "#9D4EDD")
left_button = tk.Button(
scroll_container,
text="◀",
font=button_font,
command=self.scroll_recently_used_left,
bg=primary_color,
fg=text_color,
cursor="hand2",
relief=tk.FLAT,
borderwidth=0,
width=self.scaler.scale_dimension(3),
height=self.scaler.scale_dimension(2)
)
left_button.pack(side=tk.LEFT, padx=(0, self.scaler.scale_padding(10)))
# Canvas for horizontal scrolling
self.recently_used_canvas = tk.Canvas(
scroll_container,
bg=bg_color,
highlightthickness=0,
height=self.scaler.scale_dimension(180)
)
self.recently_used_canvas.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
# Scrollable frame inside canvas
self.recently_used_frame = tk.Frame(self.recently_used_canvas, bg=bg_color)
self.recently_used_canvas_window = self.recently_used_canvas.create_window(
(0, 0), window=self.recently_used_frame, anchor="nw"
)
# Right scroll button
right_button = tk.Button(
scroll_container,
text="▶",
font=button_font,
command=self.scroll_recently_used_right,
bg=primary_color,
fg=text_color,
cursor="hand2",
relief=tk.FLAT,
borderwidth=0,
width=self.scaler.scale_dimension(3),
height=self.scaler.scale_dimension(2)
)
right_button.pack(side=tk.LEFT, padx=(self.scaler.scale_padding(10), 0))
# Configure canvas scroll region
def configure_recent_canvas(event=None):
self.recently_used_canvas.update_idletasks()
bbox = self.recently_used_canvas.bbox("all")
if bbox:
# Set scrollregion for horizontal scrolling
self.recently_used_canvas.configure(scrollregion=bbox)
# Don't constrain width - let content determine width for horizontal scrolling
# The canvas window should match content width, not canvas width
self.recently_used_frame.bind("<Configure>", configure_recent_canvas)
self.recently_used_canvas.bind("<Configure>", configure_recent_canvas)
# Store reference
self.recently_used_container = recently_used_container
def scroll_recently_used_left(self):
"""Scroll recently used apps left"""
self.recently_used_canvas.xview_scroll(-3, "units")
def scroll_recently_used_right(self):
"""Scroll recently used apps right"""
self.recently_used_canvas.xview_scroll(3, "units")
def scroll_recently_used_osg_left(self):
"""Scroll recently used open source games left"""
self.recently_used_osg_canvas.xview_scroll(-3, "units")
def scroll_recently_used_osg_right(self):
"""Scroll recently used open source games right"""
self.recently_used_osg_canvas.xview_scroll(3, "units")
def create_recently_used_opensourcegaming_section(self):
"""Create the Recently Used Open Source Games section"""
bg_color = self.theme.get_color("background", "#000000")
text_color = self.theme.get_color("text_primary", "#FFFFFF")
# Section container
recently_used_osg_container = tk.Frame(self.content_area, bg=bg_color)
recently_used_osg_container.pack(fill=tk.X, padx=self.scaler.scale_padding(20), pady=(self.scaler.scale_padding(20), 0))
# Title
heading_font = self.theme.get_font("heading", scaler=self.scaler)
title_label = tk.Label(
recently_used_osg_container,
text="Recently Used Open Source Games",
font=heading_font,
bg=bg_color,
fg=text_color,
anchor="w"
)
title_label.pack(fill=tk.X, pady=(0, self.scaler.scale_padding(15)))
# Scrollable frame with left/right buttons
scroll_container = tk.Frame(recently_used_osg_container, bg=bg_color)
scroll_container.pack(fill=tk.X)
# Left scroll button
button_font = self.theme.get_font("button", scaler=self.scaler)
primary_color = self.theme.get_color("primary", "#9D4EDD")
left_button = tk.Button(
scroll_container,
text="◀",
font=button_font,
command=self.scroll_recently_used_osg_left,
bg=primary_color,
fg=text_color,
cursor="hand2",
relief=tk.FLAT,
borderwidth=0,
width=self.scaler.scale_dimension(3),
height=self.scaler.scale_dimension(2)
)
left_button.pack(side=tk.LEFT, padx=(0, self.scaler.scale_padding(10)))
# Canvas for horizontal scrolling
self.recently_used_osg_canvas = tk.Canvas(
scroll_container,
bg=bg_color,
highlightthickness=0,
height=self.scaler.scale_dimension(180)
)
self.recently_used_osg_canvas.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
# Scrollable frame inside canvas
self.recently_used_osg_frame = tk.Frame(self.recently_used_osg_canvas, bg=bg_color)
self.recently_used_osg_canvas_window = self.recently_used_osg_canvas.create_window(
(0, 0), window=self.recently_used_osg_frame, anchor="nw"
)
# Right scroll button
right_button = tk.Button(
scroll_container,
text="▶",
font=button_font,
command=self.scroll_recently_used_osg_right,
bg=primary_color,
fg=text_color,
cursor="hand2",
relief=tk.FLAT,
borderwidth=0,
width=self.scaler.scale_dimension(3),
height=self.scaler.scale_dimension(2)
)
right_button.pack(side=tk.LEFT, padx=(self.scaler.scale_padding(10), 0))
# Configure canvas scroll region
def configure_recent_osg_canvas(event=None):
self.recently_used_osg_canvas.update_idletasks()
bbox = self.recently_used_osg_canvas.bbox("all")
if bbox:
# Set scrollregion for horizontal scrolling
self.recently_used_osg_canvas.configure(scrollregion=bbox)