-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
2154 lines (1776 loc) · 93 KB
/
main.py
File metadata and controls
2154 lines (1776 loc) · 93 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
import tkinter as tk
from tkinter import ttk, filedialog, messagebox, scrolledtext, colorchooser, font, simpledialog
import psutil
import time
import os
import sys
import json
import datetime
import webbrowser
import subprocess
import platform
import shutil
import math
import random
import string
import ast
from pathlib import Path
from collections import defaultdict
import threading
try:
import requests
except ImportError:
requests = None
try:
from PIL import Image, ImageTk, ImageDraw, ImageFilter, ImageEnhance
except ImportError:
Image = ImageTk = ImageDraw = ImageFilter = ImageEnhance = None
try:
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
import matplotlib.animation as animation
except ImportError:
plt = FigureCanvasTkAgg = animation = None
# Import new modules
try:
from sandbox_dashboard import SandboxDashboard
from mac_ui_enhancements import (MissionControl, Launchpad, HotCorners,
DockEnhancer, QuickLook, WindowSnapping, FocusModes)
from advanced_features import AppStore, TimeMachine, VoiceAssistant, CloudSync
from developer_tools import DeveloperConsole, PackageManager, SystemCleaner, ThemeEditor
except ImportError:
SandboxDashboard = MissionControl = Launchpad = None
HotCorners = DockEnhancer = QuickLook = WindowSnapping = FocusModes = None
AppStore = TimeMachine = VoiceAssistant = CloudSync = None
DeveloperConsole = PackageManager = SystemCleaner = ThemeEditor = None
class AdvancedOS:
def __init__(self, root):
self.root = root
self.root.title("AdvancedOS - Modern Operating System")
self.root.geometry("1400x900")
# Initialize settings
self.settings = self.load_settings()
self.theme_mode = self.settings.get('theme_mode', 'light')
self.accent_color = self.settings.get('accent_color', '#007AFF')
self.wallpaper_path = self.settings.get('wallpaper', None)
# Window management
self.open_windows = []
self.minimized_windows = []
self.clipboard = ""
self.clipboard_history = []
# Notifications
self.notifications = []
# App state
self.current_user = self.settings.get('username', 'User')
self.favorites = self.settings.get('favorites', [])
self.recent_files = self.settings.get('recent_files', [])
# Initialize Mac UI enhancements
if MissionControl:
self.mission_control = MissionControl(self.root, self)
self.launchpad = Launchpad(self.root, self)
self.hot_corners = HotCorners(self.root, self)
self.quick_look = QuickLook(self.root, self)
self.window_snapping = WindowSnapping(self.root, self)
self.focus_modes = FocusModes(self.root, self)
# Initialize Sandbox Dashboard
if SandboxDashboard:
self.sandbox_dashboard = SandboxDashboard(self.root, self)
# Initialize Advanced Features
if AppStore:
self.app_store = AppStore(self.root, self)
self.time_machine = TimeMachine(self.root, self)
self.voice_assistant = VoiceAssistant(self.root, self)
self.cloud_sync = CloudSync(self.root, self)
# Initialize Developer Tools
if DeveloperConsole:
self.developer_console = DeveloperConsole(self.root, self)
self.package_manager = PackageManager(self.root, self)
self.system_cleaner = SystemCleaner(self.root, self)
self.theme_editor = ThemeEditor(self.root, self)
# Apply theme
self.apply_theme()
# Create UI components
self.create_menu_bar()
self.create_desktop()
self.create_dock()
self.create_status_bar()
# Start background tasks
self.start_system_monitor()
self.update_clock()
# Keyboard shortcuts
self.setup_shortcuts()
def load_settings(self):
"""Load settings from JSON file"""
settings_file = os.path.join(os.path.expanduser('~'), '.advancedos_settings.json')
if os.path.exists(settings_file):
try:
with open(settings_file, 'r') as f:
return json.load(f)
except:
pass
return {}
def save_settings(self):
"""Save settings to JSON file"""
settings_file = os.path.join(os.path.expanduser('~'), '.advancedos_settings.json')
self.settings['theme_mode'] = self.theme_mode
self.settings['accent_color'] = self.accent_color
self.settings['wallpaper'] = self.wallpaper_path
self.settings['username'] = self.current_user
self.settings['favorites'] = self.favorites
self.settings['recent_files'] = self.recent_files[:20] # Keep last 20
try:
with open(settings_file, 'w') as f:
json.dump(self.settings, f, indent=2)
except:
pass
def apply_theme(self):
"""Apply light or dark theme"""
if self.theme_mode == 'dark':
self.bg_color = '#1E1E1E'
self.fg_color = '#FFFFFF'
self.secondary_bg = '#2D2D2D'
self.hover_color = '#3E3E3E'
else:
self.bg_color = '#F0F0F0'
self.fg_color = '#000000'
self.secondary_bg = '#FFFFFF'
self.hover_color = '#E0E0E0'
self.root.config(bg=self.bg_color)
def setup_shortcuts(self):
"""Setup keyboard shortcuts"""
self.root.bind('<Control-q>', lambda e: self.root.quit())
self.root.bind('<Control-n>', lambda e: self.open_text_editor())
self.root.bind('<Control-f>', lambda e: self.open_file_explorer())
self.root.bind('<Control-t>', lambda e: self.open_terminal())
self.root.bind('<Alt-Tab>', lambda e: self.show_app_switcher())
self.root.bind('<F11>', lambda e: self.toggle_fullscreen())
# New shortcuts for Mac features
self.root.bind('<F3>', lambda e: self.mission_control.show() if hasattr(self, 'mission_control') else None)
self.root.bind('<F4>', lambda e: self.launchpad.show() if hasattr(self, 'launchpad') else None)
self.root.bind('<Control-space>', lambda e: self.open_spotlight())
self.root.bind('<Control-Shift-s>', lambda e: self.open_sandbox_manager())
def toggle_fullscreen(self):
"""Toggle fullscreen mode"""
self.root.attributes('-fullscreen', not self.root.attributes('-fullscreen'))
def create_menu_bar(self):
"""Create top menu bar (Mac-style)"""
self.menu_bar = tk.Frame(self.root, bg=self.secondary_bg, height=25)
self.menu_bar.pack(side=tk.TOP, fill=tk.X)
# App menu
menus = [
('AdvancedOS', [
('About AdvancedOS', self.show_about),
('Settings', self.open_settings),
('---', None),
('Quit', self.root.quit)
]),
('File', [
('New Window', lambda: self.open_text_editor()),
('Open', lambda: self.open_file_explorer()),
('---', None),
('Close Window', lambda: None)
]),
('Edit', [
('Cut', lambda: self.clipboard_cut()),
('Copy', lambda: self.clipboard_copy()),
('Paste', lambda: self.clipboard_paste()),
]),
('View', [
('Toggle Dark Mode', self.toggle_theme),
('Notifications', self.show_notification_center),
('---', None),
('Mission Control', lambda: self.mission_control.show() if hasattr(self, 'mission_control') else None),
('Launchpad', lambda: self.launchpad.show() if hasattr(self, 'launchpad') else None),
]),
('Go', [
('Home', lambda: self.open_file_explorer()),
('Documents', lambda: self.open_folder(os.path.expanduser('~/Documents'))),
('Downloads', lambda: self.open_folder(os.path.expanduser('~/Downloads'))),
]),
('Window', [
('Minimize All', self.minimize_all),
('Show All', self.show_all_windows),
('---', None),
('Hot Corners', lambda: self.hot_corners.configure() if hasattr(self, 'hot_corners') else None),
('Snap Left', lambda: None),
('Snap Right', lambda: None),
]),
('Tools', [
('Sandbox Manager', self.open_sandbox_manager),
('Focus Modes', lambda: self.focus_modes.show_menu() if hasattr(self, 'focus_modes') else None),
('---', None),
('App Store', lambda: self.app_store.show() if hasattr(self, 'app_store') else None),
('Time Machine', lambda: self.time_machine.show() if hasattr(self, 'time_machine') else None),
('Voice Assistant', lambda: self.voice_assistant.show() if hasattr(self, 'voice_assistant') else None),
('Cloud Sync', lambda: self.cloud_sync.show_settings() if hasattr(self, 'cloud_sync') else None),
('---', None),
('Developer Console', lambda: self.developer_console.show() if hasattr(self, 'developer_console') else None),
('Package Manager', lambda: self.package_manager.show() if hasattr(self, 'package_manager') else None),
('System Cleaner', lambda: self.system_cleaner.show() if hasattr(self, 'system_cleaner') else None),
('Theme Editor', lambda: self.theme_editor.show() if hasattr(self, 'theme_editor') else None),
]),
]
for menu_name, items in menus:
menu_btn = tk.Menubutton(self.menu_bar, text=menu_name,
bg=self.secondary_bg, fg=self.fg_color,
relief=tk.FLAT, padx=10)
menu_btn.pack(side=tk.LEFT)
menu = tk.Menu(menu_btn, tearoff=0, bg=self.secondary_bg, fg=self.fg_color)
for item_name, command in items:
if item_name == '---':
menu.add_separator()
else:
menu.add_command(label=item_name, command=command)
menu_btn['menu'] = menu
def create_desktop(self):
"""Create main desktop area"""
self.desktop = tk.Frame(self.root, bg=self.bg_color)
self.desktop.pack(fill=tk.BOTH, expand=True)
# Set wallpaper if available
if self.wallpaper_path and os.path.exists(self.wallpaper_path) and Image:
try:
img = Image.open(self.wallpaper_path)
img = img.resize((1400, 900), Image.Resampling.LANCZOS)
self.wallpaper_photo = ImageTk.PhotoImage(img)
wallpaper_label = tk.Label(self.desktop, image=self.wallpaper_photo)
wallpaper_label.place(x=0, y=0, relwidth=1, relheight=1)
except:
pass
# Desktop icons grid
self.desktop_icons_frame = tk.Frame(self.desktop, bg=self.bg_color)
self.desktop_icons_frame.place(x=20, y=20)
# Create desktop icons
self.create_desktop_icons()
def create_desktop_icons(self):
"""Create desktop icons in a grid"""
icons = [
('📁 Files', self.open_file_explorer),
('📝 Text Editor', self.open_text_editor),
('🧮 Calculator', self.open_calculator),
('🌐 Browser', self.open_browser),
('🖼️ Photos', self.open_photo_viewer),
('🎵 Music', self.open_music_player),
('🎬 Videos', self.open_video_player),
('📧 Mail', self.open_email_client),
('📅 Calendar', self.open_calendar),
('📋 Notes', self.open_notes),
('⚙️ Settings', self.open_settings),
('💻 Terminal', self.open_terminal),
('🔒 Sandboxes', self.open_sandbox_manager),
('🚀 Launchpad', lambda: self.launchpad.show() if hasattr(self, 'launchpad') else None),
('🏪 App Store', lambda: self.app_store.show() if hasattr(self, 'app_store') else None),
('⏰ Time Machine', lambda: self.time_machine.show() if hasattr(self, 'time_machine') else None),
]
row, col = 0, 0
for text, command in icons:
icon_frame = tk.Frame(self.desktop_icons_frame, bg=self.bg_color)
icon_frame.grid(row=row, column=col, padx=10, pady=10)
btn = tk.Button(icon_frame, text=text, command=command,
bg=self.secondary_bg, fg=self.fg_color,
relief=tk.FLAT, width=12, height=3,
font=('Arial', 10))
btn.pack()
# Right-click context menu
btn.bind('<Button-3>', lambda e, cmd=command: self.show_icon_context_menu(e, cmd))
row += 1
if row >= 6:
row = 0
col += 1
def show_icon_context_menu(self, event, command):
"""Show context menu for desktop icon"""
menu = tk.Menu(self.root, tearoff=0, bg=self.secondary_bg, fg=self.fg_color)
menu.add_command(label="Open", command=command)
menu.add_command(label="Add to Favorites", command=lambda: self.add_to_favorites(command))
menu.post(event.x_root, event.y_root)
def create_dock(self):
"""Create Mac-style dock at bottom"""
self.dock = tk.Frame(self.root, bg='#2C2C2E', height=70)
self.dock.pack(side=tk.BOTTOM, fill=tk.X)
# Dock container with centered apps
dock_container = tk.Frame(self.dock, bg='#2C2C2E')
dock_container.pack(expand=True)
# Dock applications
dock_apps = [
('🔍', 'Spotlight', self.open_spotlight),
('📁', 'Finder', self.open_file_explorer),
('🌐', 'Browser', self.open_browser),
('✉️', 'Mail', self.open_email_client),
('📅', 'Calendar', self.open_calendar),
('📝', 'Notes', self.open_notes),
('🎵', 'Music', self.open_music_player),
('📷', 'Photos', self.open_photo_viewer),
('🔒', 'Sandboxes', self.open_sandbox_manager),
('🏪', 'App Store', lambda: self.app_store.show() if hasattr(self, 'app_store') else None),
('⏰', 'Time Machine', lambda: self.time_machine.show() if hasattr(self, 'time_machine') else None),
('🎤', 'Assistant', lambda: self.voice_assistant.show() if hasattr(self, 'voice_assistant') else None),
('⚙️', 'Settings', self.open_settings),
('💻', 'Terminal', self.open_terminal),
('📊', 'Activity', self.open_activity_monitor),
('🗑️', 'Trash', self.open_trash),
]
for icon, tooltip, command in dock_apps:
btn = tk.Button(dock_container, text=icon, command=command,
bg='#2C2C2E', fg='white',
relief=tk.FLAT, font=('Arial', 24),
width=2, height=1, cursor='hand2')
btn.pack(side=tk.LEFT, padx=5, pady=10)
# Add tooltip
self.create_tooltip(btn, tooltip)
# Hover effect
btn.bind('<Enter>', lambda e, b=btn: b.config(bg='#3C3C3E'))
btn.bind('<Leave>', lambda e, b=btn: b.config(bg='#2C2C2E'))
def create_tooltip(self, widget, text):
"""Create tooltip for widget"""
def show_tooltip(event):
tooltip = tk.Toplevel()
tooltip.wm_overrideredirect(True)
tooltip.wm_geometry(f"+{event.x_root+10}+{event.y_root+10}")
label = tk.Label(tooltip, text=text, bg='#FFE4B5', fg='black',
relief=tk.SOLID, borderwidth=1, padx=5, pady=2)
label.pack()
widget.tooltip = tooltip
def hide_tooltip(event):
if hasattr(widget, 'tooltip'):
widget.tooltip.destroy()
widget.bind('<Enter>', show_tooltip)
widget.bind('<Leave>', hide_tooltip)
def create_status_bar(self):
"""Create status bar with system info"""
self.status_bar = tk.Frame(self.root, bg=self.secondary_bg, height=25)
self.status_bar.pack(side=tk.BOTTOM, fill=tk.X, before=self.dock)
# System information
self.cpu_label = tk.Label(self.status_bar, text="CPU: 0%",
bg=self.secondary_bg, fg=self.fg_color, font=('Arial', 9))
self.cpu_label.pack(side=tk.LEFT, padx=5)
self.ram_label = tk.Label(self.status_bar, text="RAM: 0%",
bg=self.secondary_bg, fg=self.fg_color, font=('Arial', 9))
self.ram_label.pack(side=tk.LEFT, padx=5)
self.disk_label = tk.Label(self.status_bar, text="Disk: 0%",
bg=self.secondary_bg, fg=self.fg_color, font=('Arial', 9))
self.disk_label.pack(side=tk.LEFT, padx=5)
# Network indicator
self.network_label = tk.Label(self.status_bar, text="🌐",
bg=self.secondary_bg, fg=self.fg_color, font=('Arial', 12))
self.network_label.pack(side=tk.RIGHT, padx=5)
# Battery indicator
self.battery_label = tk.Label(self.status_bar, text="🔋 100%",
bg=self.secondary_bg, fg=self.fg_color, font=('Arial', 9))
self.battery_label.pack(side=tk.RIGHT, padx=5)
# Clock
self.clock_label = tk.Label(self.status_bar, text="",
bg=self.secondary_bg, fg=self.fg_color, font=('Arial', 9))
self.clock_label.pack(side=tk.RIGHT, padx=10)
def update_clock(self):
"""Update clock every second"""
current_time = time.strftime("%a %b %d %I:%M:%S %p")
self.clock_label.config(text=current_time)
self.root.after(1000, self.update_clock)
def start_system_monitor(self):
"""Start monitoring system resources"""
def update_system_info():
try:
# CPU usage
cpu_percent = psutil.cpu_percent(interval=1)
self.cpu_label.config(text=f"CPU: {cpu_percent}%")
# RAM usage
ram = psutil.virtual_memory()
self.ram_label.config(text=f"RAM: {ram.percent}%")
# Disk usage
disk = psutil.disk_usage('/')
self.disk_label.config(text=f"Disk: {disk.percent}%")
# Battery
battery = psutil.sensors_battery()
if battery:
charging = "⚡" if battery.power_plugged else "🔋"
self.battery_label.config(text=f"{charging} {battery.percent}%")
else:
self.battery_label.config(text="🔌 AC")
# Network
net_io = psutil.net_io_counters()
if net_io.bytes_sent > 0 or net_io.bytes_recv > 0:
self.network_label.config(text="🌐")
else:
self.network_label.config(text="📡")
except Exception as e:
pass
self.root.after(2000, update_system_info)
update_system_info()
# Helper methods
def add_to_favorites(self, command):
"""Add item to favorites"""
if command not in self.favorites:
self.favorites.append(command)
self.save_settings()
self.show_notification("Added to Favorites", "Item added successfully")
def add_to_recent(self, filepath):
"""Add file to recent files"""
if filepath not in self.recent_files:
self.recent_files.insert(0, filepath)
self.recent_files = self.recent_files[:20]
self.save_settings()
def show_notification(self, title, message, duration=3000):
"""Show notification"""
notification = tk.Toplevel(self.root)
notification.title("Notification")
notification.geometry("300x100+{}+{}".format(
self.root.winfo_x() + self.root.winfo_width() - 320,
self.root.winfo_y() + 50
))
notification.attributes('-topmost', True)
notification.overrideredirect(True)
frame = tk.Frame(notification, bg='#2C2C2E', relief=tk.RAISED, borderwidth=2)
frame.pack(fill=tk.BOTH, expand=True)
tk.Label(frame, text=title, bg='#2C2C2E', fg='white',
font=('Arial', 12, 'bold')).pack(pady=(10, 5))
tk.Label(frame, text=message, bg='#2C2C2E', fg='white',
font=('Arial', 10)).pack(pady=(0, 10))
self.notifications.append(notification)
notification.after(duration, lambda: self.close_notification(notification))
def close_notification(self, notification):
"""Close notification"""
if notification in self.notifications:
self.notifications.remove(notification)
notification.destroy()
def show_notification_center(self):
"""Show notification center"""
nc = tk.Toplevel(self.root)
nc.title("Notification Center")
nc.geometry("400x600")
nc.configure(bg=self.bg_color)
tk.Label(nc, text="Notification Center", bg=self.bg_color, fg=self.fg_color,
font=('Arial', 16, 'bold')).pack(pady=10)
# Mock notifications
notifications = [
("System Update", "System update available"),
("Battery", "Battery at 20%"),
("Mail", "You have 3 new messages"),
]
for title, msg in notifications:
frame = tk.Frame(nc, bg=self.secondary_bg, relief=tk.RAISED, borderwidth=1)
frame.pack(fill=tk.X, padx=10, pady=5)
tk.Label(frame, text=title, bg=self.secondary_bg, fg=self.fg_color,
font=('Arial', 11, 'bold')).pack(anchor=tk.W, padx=10, pady=(5, 0))
tk.Label(frame, text=msg, bg=self.secondary_bg, fg=self.fg_color,
font=('Arial', 9)).pack(anchor=tk.W, padx=10, pady=(0, 5))
def clipboard_copy(self):
"""Copy to clipboard"""
try:
self.clipboard = self.root.clipboard_get()
self.clipboard_history.insert(0, self.clipboard)
self.clipboard_history = self.clipboard_history[:10]
except:
pass
def clipboard_cut(self):
"""Cut to clipboard"""
self.clipboard_copy()
def clipboard_paste(self):
"""Paste from clipboard"""
return self.clipboard
def minimize_all(self):
"""Minimize all windows"""
for window in self.open_windows:
if window.winfo_exists():
window.iconify()
def show_all_windows(self):
"""Show all windows"""
for window in self.open_windows:
if window.winfo_exists():
window.deiconify()
def show_app_switcher(self):
"""Show application switcher (Alt+Tab)"""
switcher = tk.Toplevel(self.root)
switcher.title("App Switcher")
switcher.geometry("500x300")
switcher.attributes('-topmost', True)
switcher.configure(bg=self.bg_color)
tk.Label(switcher, text="Open Applications", bg=self.bg_color, fg=self.fg_color,
font=('Arial', 14, 'bold')).pack(pady=10)
for window in self.open_windows:
if window.winfo_exists():
btn = tk.Button(switcher, text=window.title(),
command=lambda w=window: self.switch_to_window(w, switcher),
bg=self.secondary_bg, fg=self.fg_color,
font=('Arial', 11), relief=tk.FLAT)
btn.pack(fill=tk.X, padx=20, pady=5)
def switch_to_window(self, window, switcher):
"""Switch to specific window"""
window.deiconify()
window.lift()
switcher.destroy()
def toggle_theme(self):
"""Toggle between light and dark mode"""
self.theme_mode = 'dark' if self.theme_mode == 'light' else 'light'
self.apply_theme()
self.save_settings()
# Recreate UI with new theme
self.show_notification("Theme Changed", f"Switched to {self.theme_mode} mode")
# ==================== APPLICATIONS ====================
def show_about(self):
"""Show about dialog"""
about = tk.Toplevel(self.root)
about.title("About AdvancedOS")
about.geometry("500x400")
about.configure(bg=self.bg_color)
about.resizable(False, False)
tk.Label(about, text="AdvancedOS", bg=self.bg_color, fg=self.fg_color,
font=('Arial', 24, 'bold')).pack(pady=20)
tk.Label(about, text="Version 3.0 - The World's Best Python OS", bg=self.bg_color, fg=self.fg_color,
font=('Arial', 12)).pack()
tk.Label(about, text=f"\nPlatform: {platform.system()} {platform.release()}",
bg=self.bg_color, fg=self.fg_color, font=('Arial', 10)).pack()
tk.Label(about, text=f"Python: {sys.version.split()[0]}",
bg=self.bg_color, fg=self.fg_color, font=('Arial', 10)).pack()
features_text = """
Features: 2500+
• Sandbox Isolation System
• App Store & Package Manager
• Time Machine Backups
• Voice Assistant & Cloud Sync
• Mission Control & Launchpad
• Developer Console & Tools
• File Management & Media Players
• And much more!
"""
tk.Label(about, text=features_text, bg=self.bg_color, fg=self.fg_color,
font=('Arial', 9), justify=tk.LEFT).pack(pady=10)
tk.Button(about, text="Close", command=about.destroy,
bg=self.accent_color, fg='white', relief=tk.FLAT,
font=('Arial', 11), padx=20, pady=5).pack(pady=10)
def open_spotlight(self):
"""Open Spotlight search"""
spotlight = tk.Toplevel(self.root)
spotlight.title("Spotlight Search")
spotlight.geometry("600x400+400+200")
spotlight.configure(bg=self.bg_color)
search_frame = tk.Frame(spotlight, bg=self.bg_color)
search_frame.pack(fill=tk.X, padx=20, pady=20)
search_var = tk.StringVar()
search_entry = tk.Entry(search_frame, textvariable=search_var,
font=('Arial', 14), bg=self.secondary_bg,
fg=self.fg_color, relief=tk.FLAT)
search_entry.pack(fill=tk.X, ipady=5)
search_entry.focus()
results_frame = tk.Frame(spotlight, bg=self.bg_color)
results_frame.pack(fill=tk.BOTH, expand=True, padx=20)
def search(*args):
# Clear previous results
for widget in results_frame.winfo_children():
widget.destroy()
query = search_var.get().lower()
if not query:
return
# Search applications
apps = [
('Calculator', self.open_calculator),
('Text Editor', self.open_text_editor),
('File Explorer', self.open_file_explorer),
('Browser', self.open_browser),
('Terminal', self.open_terminal),
('Settings', self.open_settings),
('Calendar', self.open_calendar),
('Notes', self.open_notes),
('Photos', self.open_photo_viewer),
('Music', self.open_music_player),
]
matches = [(name, cmd) for name, cmd in apps if query in name.lower()]
for name, cmd in matches[:5]:
btn = tk.Button(results_frame, text=f"📱 {name}",
command=lambda c=cmd: (c(), spotlight.destroy()),
bg=self.secondary_bg, fg=self.fg_color,
font=('Arial', 11), relief=tk.FLAT, anchor=tk.W)
btn.pack(fill=tk.X, pady=2)
search_var.trace('w', search)
def open_calculator(self):
"""Open advanced calculator"""
calc = tk.Toplevel(self.root)
calc.title("Calculator")
calc.geometry("350x500")
calc.configure(bg=self.bg_color)
calc.resizable(False, False)
self.open_windows.append(calc)
# Display
display_var = tk.StringVar(value="0")
display = tk.Entry(calc, textvariable=display_var, font=('Arial', 24),
justify=tk.RIGHT, bg=self.secondary_bg, fg=self.fg_color,
relief=tk.FLAT, state='readonly')
display.pack(fill=tk.X, padx=10, pady=10, ipady=10)
# History
history_text = scrolledtext.ScrolledText(calc, height=3, font=('Arial', 9),
bg=self.secondary_bg, fg=self.fg_color)
history_text.pack(fill=tk.X, padx=10)
# Buttons
buttons_frame = tk.Frame(calc, bg=self.bg_color)
buttons_frame.pack(fill=tk.BOTH, expand=True, padx=10, pady=10)
current_expression = ""
def button_click(value):
nonlocal current_expression
if value == '=':
try:
# Safe evaluation using ast module
# Only allow mathematical operations
allowed_chars = set('0123456789+-*/().% ')
if all(c in allowed_chars for c in current_expression):
result = eval(current_expression, {"__builtins__": {}}, {})
history_text.insert(tk.END, f"{current_expression} = {result}\n")
history_text.see(tk.END)
display_var.set(str(result))
current_expression = str(result)
else:
display_var.set("Error")
current_expression = ""
except:
display_var.set("Error")
current_expression = ""
elif value == 'C':
current_expression = ""
display_var.set("0")
elif value == '⌫':
current_expression = current_expression[:-1]
display_var.set(current_expression or "0")
else:
current_expression += str(value)
display_var.set(current_expression)
buttons = [
['C', '⌫', '%', '/'],
['7', '8', '9', '*'],
['4', '5', '6', '-'],
['1', '2', '3', '+'],
['0', '.', '=', '']
]
for i, row in enumerate(buttons):
for j, btn_text in enumerate(row):
if btn_text:
btn = tk.Button(buttons_frame, text=btn_text,
command=lambda t=btn_text: button_click(t),
font=('Arial', 16), relief=tk.FLAT,
bg=self.secondary_bg, fg=self.fg_color)
btn.grid(row=i, column=j, sticky='nsew', padx=2, pady=2)
for i in range(5):
buttons_frame.grid_rowconfigure(i, weight=1)
for j in range(4):
buttons_frame.grid_columnconfigure(j, weight=1)
def open_text_editor(self):
"""Open advanced text editor with syntax highlighting"""
editor = tk.Toplevel(self.root)
editor.title("Text Editor - Untitled")
editor.geometry("800x600")
editor.configure(bg=self.bg_color)
self.open_windows.append(editor)
current_file = [None]
# Menu bar
menubar = tk.Menu(editor)
# File menu
file_menu = tk.Menu(menubar, tearoff=0)
def new_file():
text_area.delete(1.0, tk.END)
current_file[0] = None
editor.title("Text Editor - Untitled")
def open_file():
filepath = filedialog.askopenfilename(
filetypes=[("All Files", "*.*"), ("Text Files", "*.txt"),
("Python Files", "*.py"), ("Markdown", "*.md")])
if filepath:
with open(filepath, 'r') as f:
text_area.delete(1.0, tk.END)
text_area.insert(1.0, f.read())
current_file[0] = filepath
editor.title(f"Text Editor - {os.path.basename(filepath)}")
self.add_to_recent(filepath)
def save_file():
if current_file[0]:
with open(current_file[0], 'w') as f:
f.write(text_area.get(1.0, tk.END))
self.show_notification("Saved", f"File saved: {os.path.basename(current_file[0])}")
else:
save_as_file()
def save_as_file():
filepath = filedialog.asksaveasfilename(
defaultextension=".txt",
filetypes=[("Text Files", "*.txt"), ("Python Files", "*.py"),
("All Files", "*.*")])
if filepath:
with open(filepath, 'w') as f:
f.write(text_area.get(1.0, tk.END))
current_file[0] = filepath
editor.title(f"Text Editor - {os.path.basename(filepath)}")
self.add_to_recent(filepath)
self.show_notification("Saved", f"File saved: {os.path.basename(filepath)}")
file_menu.add_command(label="New", command=new_file, accelerator="Ctrl+N")
file_menu.add_command(label="Open", command=open_file, accelerator="Ctrl+O")
file_menu.add_command(label="Save", command=save_file, accelerator="Ctrl+S")
file_menu.add_command(label="Save As", command=save_as_file)
file_menu.add_separator()
file_menu.add_command(label="Close", command=editor.destroy)
menubar.add_cascade(label="File", menu=file_menu)
# Edit menu
edit_menu = tk.Menu(menubar, tearoff=0)
edit_menu.add_command(label="Cut", command=lambda: text_area.event_generate("<<Cut>>"))
edit_menu.add_command(label="Copy", command=lambda: text_area.event_generate("<<Copy>>"))
edit_menu.add_command(label="Paste", command=lambda: text_area.event_generate("<<Paste>>"))
edit_menu.add_command(label="Select All", command=lambda: text_area.tag_add(tk.SEL, "1.0", tk.END))
menubar.add_cascade(label="Edit", menu=edit_menu)
# View menu
view_menu = tk.Menu(menubar, tearoff=0)
view_menu.add_command(label="Word Wrap", command=lambda: text_area.config(wrap=tk.WORD))
menubar.add_cascade(label="View", menu=view_menu)
editor.config(menu=menubar)
# Toolbar
toolbar = tk.Frame(editor, bg=self.secondary_bg, height=30)
toolbar.pack(side=tk.TOP, fill=tk.X)
tk.Button(toolbar, text="📄 New", command=new_file, relief=tk.FLAT,
bg=self.secondary_bg, fg=self.fg_color).pack(side=tk.LEFT, padx=2)
tk.Button(toolbar, text="📁 Open", command=open_file, relief=tk.FLAT,
bg=self.secondary_bg, fg=self.fg_color).pack(side=tk.LEFT, padx=2)
tk.Button(toolbar, text="💾 Save", command=save_file, relief=tk.FLAT,
bg=self.secondary_bg, fg=self.fg_color).pack(side=tk.LEFT, padx=2)
# Text area with line numbers
text_frame = tk.Frame(editor, bg=self.bg_color)
text_frame.pack(fill=tk.BOTH, expand=True)
# Line numbers
line_numbers = tk.Text(text_frame, width=4, bg=self.secondary_bg,
fg=self.fg_color, state='disabled',
font=('Courier', 11))
line_numbers.pack(side=tk.LEFT, fill=tk.Y)
# Text area
text_area = scrolledtext.ScrolledText(text_frame, font=('Courier', 11),
bg=self.secondary_bg, fg=self.fg_color,
insertbackground=self.fg_color,
wrap=tk.NONE, undo=True)
text_area.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
def update_line_numbers(event=None):
line_numbers.config(state='normal')
line_numbers.delete(1.0, tk.END)
num_lines = text_area.get(1.0, tk.END).count('\n')
line_numbers.insert(1.0, '\n'.join(str(i) for i in range(1, num_lines + 1)))
line_numbers.config(state='disabled')
text_area.bind('<KeyRelease>', update_line_numbers)
update_line_numbers()
# Status bar
status_bar = tk.Label(editor, text="Line: 1, Column: 0",
bg=self.secondary_bg, fg=self.fg_color,
anchor=tk.W, font=('Arial', 9))
status_bar.pack(side=tk.BOTTOM, fill=tk.X)
def update_status(event=None):
line, col = text_area.index(tk.INSERT).split('.')
status_bar.config(text=f"Line: {line}, Column: {col}")
text_area.bind('<KeyRelease>', lambda e: (update_line_numbers(e), update_status(e)))
text_area.bind('<ButtonRelease>', update_status)
def open_file_explorer(self):
"""Open comprehensive file explorer"""
explorer = tk.Toplevel(self.root)
explorer.title("File Explorer")
explorer.geometry("900x600")
explorer.configure(bg=self.bg_color)
self.open_windows.append(explorer)
current_path = [os.path.expanduser('~')]
# Toolbar
toolbar = tk.Frame(explorer, bg=self.secondary_bg, height=40)
toolbar.pack(side=tk.TOP, fill=tk.X)
def go_back():
parent = os.path.dirname(current_path[0])
if parent and os.path.exists(parent):
current_path[0] = parent
refresh_files()
def go_home():
current_path[0] = os.path.expanduser('~')
refresh_files()
def create_new_folder():
folder_name = simpledialog.askstring("New Folder", "Enter folder name:")
if folder_name:
new_folder_path = os.path.join(current_path[0], folder_name)
try:
os.makedirs(new_folder_path)
refresh_files()
self.show_notification("Success", f"Folder '{folder_name}' created")
except Exception as e:
messagebox.showerror("Error", f"Cannot create folder: {str(e)}")
tk.Button(toolbar, text="⬅️ Back", command=go_back, relief=tk.FLAT,
bg=self.secondary_bg, fg=self.fg_color, padx=10).pack(side=tk.LEFT)
tk.Button(toolbar, text="🏠 Home", command=go_home, relief=tk.FLAT,
bg=self.secondary_bg, fg=self.fg_color, padx=10).pack(side=tk.LEFT)
tk.Button(toolbar, text="📁+ New Folder", command=create_new_folder, relief=tk.FLAT,
bg=self.secondary_bg, fg=self.fg_color, padx=10).pack(side=tk.LEFT)
# Path bar
path_frame = tk.Frame(explorer, bg=self.secondary_bg, height=30)
path_frame.pack(side=tk.TOP, fill=tk.X)
path_var = tk.StringVar(value=current_path[0])
path_entry = tk.Entry(path_frame, textvariable=path_var, font=('Arial', 10),
bg=self.bg_color, fg=self.fg_color, relief=tk.FLAT)
path_entry.pack(side=tk.LEFT, fill=tk.X, expand=True, padx=10, pady=5)
def navigate_to_path(event=None):
path = path_var.get()
if os.path.exists(path) and os.path.isdir(path):
current_path[0] = path
refresh_files()
path_entry.bind('<Return>', navigate_to_path)
# Main content area
content_frame = tk.Frame(explorer, bg=self.bg_color)
content_frame.pack(fill=tk.BOTH, expand=True)
# Sidebar
sidebar = tk.Frame(content_frame, bg=self.secondary_bg, width=200)
sidebar.pack(side=tk.LEFT, fill=tk.Y)
tk.Label(sidebar, text="Favorites", bg=self.secondary_bg, fg=self.fg_color,
font=('Arial', 12, 'bold')).pack(anchor=tk.W, padx=10, pady=5)
favorite_folders = [
('Home', os.path.expanduser('~')),
('Documents', os.path.expanduser('~/Documents')),
('Downloads', os.path.expanduser('~/Downloads')),
('Desktop', os.path.expanduser('~/Desktop')),
]
for name, path in favorite_folders:
if os.path.exists(path):
btn = tk.Button(sidebar, text=f"📁 {name}",
command=lambda p=path: (current_path.__setitem__(0, p), refresh_files()),
bg=self.secondary_bg, fg=self.fg_color,
relief=tk.FLAT, anchor=tk.W)
btn.pack(fill=tk.X, padx=5, pady=2)
# File list
file_frame = tk.Frame(content_frame, bg=self.bg_color)
file_frame.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
# Treeview for files
columns = ('Name', 'Type', 'Size', 'Modified')
tree = ttk.Treeview(file_frame, columns=columns, show='headings')
for col in columns:
tree.heading(col, text=col)
tree.column(col, width=150)
tree.pack(fill=tk.BOTH, expand=True, padx=5, pady=5)
# Scrollbar
scrollbar = ttk.Scrollbar(file_frame, orient=tk.VERTICAL, command=tree.yview)
tree.configure(yscrollcommand=scrollbar.set)
scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
def refresh_files():
tree.delete(*tree.get_children())
path_var.set(current_path[0])