-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSimpleWeb.py
More file actions
1373 lines (1259 loc) · 55.4 KB
/
SimpleWeb.py
File metadata and controls
1373 lines (1259 loc) · 55.4 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
# Copyright (c) 2026 tudify
#
# This file may be used under the terms of the GNU General Public License
# version 3.0 as published by the Free Software Foundation and appearing in
# the file LICENSE included in the packaging of this file. The requirements
# of the GNU General Public License version 3.0 can be found here:
# http://www.gnu.org/copyleft/gpl.html.
#
# This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
# WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
import sys, os, platform, urllib.parse, json, psutil, subprocess, updater, inspect, simplewebex, darkdetect
from PyQt6.QtWidgets import (QApplication, QMainWindow, QMenuBar,QMenu, QHBoxLayout, QWidget, QMessageBox,QVBoxLayout, QLineEdit, QTabWidget, QFileDialog, QDialog, QLabel, QDialogButtonBox, QComboBox, QCheckBox, QColorDialog, QPushButton)
from PyQt6.QtCore import QUrl, Qt, QSettings, QEvent, QObject, pyqtSlot, QEventLoop
from PyQt6.QtGui import QKeySequence, QAction, QShortcut
from PyQt6.QtWebEngineWidgets import QWebEngineView
from PyQt6.QtWebEngineCore import QWebEngineSettings, QWebEngineProfile, QWebEnginePage, QWebEngineDownloadRequest, QWebEngineFullScreenRequest, QWebEnginePermission, QWebEngineFileSystemAccessRequest
from PyQt6.QtWebChannel import QWebChannel
from pathlib import Path
from simplewebex import SimpleWeb # this file's ln count needs saving.
script_dir = os.path.dirname(os.path.abspath(__file__))
exe_path = os.path.join(script_dir, "simpleweblib")
result = subprocess.run([exe_path], capture_output=True, text=True)
print(result.stdout)
#MARK: GetWebPage
class getwebpage(QWebEnginePage):
"""Load a URL and return the rendered HTML source code."""
def __init__(self):
self.app = QApplication.instance() or QApplication(sys.argv)
super().__init__()
self.html = None
self.loadFinished.connect(self._on_load_finished)
def fetch(self, url: str) -> str:
self.html = None
self._loop = QEventLoop()
self.load(QUrl(url))
print("Loading URL:", url)
self._loop.exec_()
return self.html
def _on_load_finished(self, ok: bool):
if not ok:
self.html = ""
self._loop.quit()
return
self.toHtml(self._store_html)
def _store_html(self, html: str):
self.html = html
self._loop.quit()
#MARK: ExtensionsWindow
class ExtensionsWindow(QDialog):
def __init__(self, parent=None):
super().__init__(parent)
self.setWindowTitle("Extensions - SimpleWeb")
self.setGeometry(100, 100, 400, 300)
layout = QVBoxLayout()
self.heading_label = QLabel("Extensions")
self.heading_label.setObjectName("heading")
layout.addWidget(self.heading_label, alignment=Qt.AlignmentFlag.AlignLeft)
self.new_current_label = QLabel("Currently Available:")
layout.addWidget(self.new_current_label)
self.extension_checkboxes = {}
self.load_extensions(layout)
layout.addSpacing(20)
button_box = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel)
button_box.accepted.connect(self.save_settings)
button_box.rejected.connect(self.reject)
layout.addWidget(button_box)
self.setLayout(layout)
def load_extensions(self, layout):
base_dir = Path(__file__).resolve().parent
extensions_file = base_dir / "extensions.json"
if extensions_file.exists():
try:
with extensions_file.open("r", encoding="utf-8") as f:
extensions = json.load(f)
except Exception as e:
print(f"Failed to read {extensions_file.name}: {e}")
msg = QMessageBox()
msg.setText("Fatal Error\n\nSimpleWeb could not read from its internal files. \n extensions.json not readable (3)")
msg.exec()
raise TypeError(f"simplewebex is malformed or corrupted. {e}")
else:
msg = QMessageBox()
msg.setText("Fatal Error\n\nSimpleWeb could not read from its internal files. \n extensions.json not found (0)")
msg.exec()
raise FileNotFoundError("extensions.json is missing.")
extop = QSettings("Tudify", "SimpleWeb-Extensions")
for name, default_state in extensions.items():
state = extop.value(name, default_state, type=bool)
checkbox = QCheckBox(name)
checkbox.setChecked(state)
layout.addWidget(checkbox)
self.extension_checkboxes[name] = checkbox
def save_settings(self):
extop = QSettings("Tudify", "SimpleWeb-Extensions")
for name, checkbox in self.extension_checkboxes.items():
extop.setValue(name, checkbox.isChecked())
if self.parent() is not None and hasattr(self.parent(), "apply_chromium_spoofer"):
try:
self.parent().apply_chromium_spoofer()
except Exception as e:
msg = QMessageBox()
msg.setText(f"Fatal Error\n\nCould not save settings to simpleweb-extensions \n {e} (2)")
raise TypeError(f"info.json is malformed or corrupted. {e}")
self.accept()
#MARK: SimpleWebEngine About
class AboutSWE(QDialog):
def __init__(self, parent=None):
super().__init__(parent)
self.setWindowTitle("About SimpleWebEngine")
self.setGeometry(100, 100, 467, 120)
layout = QVBoxLayout()
versions = EngineVer
self.heading_label = QLabel(f"This Program Uses SimpleWebEngine {versions}")
layout.addWidget(self.heading_label, alignment=Qt.AlignmentFlag.AlignCenter)
self.new_current_label = QLabel(f"An open-source project by tudify & its users. \n SimpleWebEngine is liscenced under the GPL v3 Lisence.\n Uses Qt and Chromium.")
layout.addWidget(self.new_current_label, alignment=Qt.AlignmentFlag.AlignCenter)
self.setLayout(layout)
#MARK: SimpleWeb About
class About(QDialog):
def __init__(self, parent=None):
super().__init__(parent)
self.setWindowTitle("About SimpleWeb")
self.setGeometry(100, 100, 200, 100)
self.setWindowFlags(
Qt.WindowType.Window |
Qt.WindowType.CustomizeWindowHint |
Qt.WindowType.WindowTitleHint |
Qt.WindowType.WindowCloseButtonHint
)
layout = QVBoxLayout()
versions = EngineVer
print(versions)
self.heading_label = QLabel("SimpleWeb")
self.heading_label.setObjectName("heading")
layout.addWidget(self.heading_label, alignment=Qt.AlignmentFlag.AlignCenter)
self.new_current_label = QLabel(f"An open-source project by tudify. \n")
layout.addWidget(self.new_current_label, alignment=Qt.AlignmentFlag.AlignCenter)
self.verlabel = QLabel(f"version: {versions}")
layout.addWidget(self.verlabel, alignment=Qt.AlignmentFlag.AlignCenter)
self.setLayout(layout)
#MARK: SimpleWebAPI
class SimpleWebAPI(QObject):
def __init__(self, parent=None):
super().__init__(parent)
self.windows = []
self.main_window = parent # main browser window reference
@pyqtSlot(str, int, int)
def openwindow(self, url, width=800, height=600):
window = QMainWindow()
window.setWindowTitle("SimpleWeb Window")
window.setGeometry(100, 100, width, height)
# Web view setup
central_widget = QWidget()
layout = QVBoxLayout()
central_widget.setLayout(layout)
browser = QWebEngineView()
browser.setUrl(QUrl(url))
layout.addWidget(browser)
window.setCentralWidget(central_widget)
window.show()
self.windows.append(window)
@pyqtSlot(result=str)
def getDeviceInfo(self):
return f"{cpuname}, {arch[0]}, {os_namereport}"
@pyqtSlot(result=str)
def reportAPIver(self):
return APIver
@pyqtSlot(result=str)
def getSearchEngine(self):
settings = QSettings("Tudify", "SimpleWeb")
return settings.value("search_engine", "Google")
@pyqtSlot(result=str)
def getRamAmount(self):
return str(mem) + " GB"
@pyqtSlot(result=str)
def getUserAgent(self):
return UserAgent
@pyqtSlot(result=str)
def getOS(self):
return os_name
@pyqtSlot(result=str)
def getUserTheme(self):
settings = QSettings("Tudify", "SimpleWeb")
theme = settings.value("theme", "dark")
if theme.lower() == "auto":
if current_theme.lower() == "dark":
return "dark"
else:
return "light"
else:
return theme
@pyqtSlot(result=str)
def GetUserTheme(self):
return self.getUserTheme()
@pyqtSlot(result=str)
def macVersion(self):
if os_namereport == "macOS":
return macver
else:
return "null"
@pyqtSlot(str)
def print(self, text):
print(text)
@pyqtSlot(str)
def setWindowTitle(self, title):
"""Sets title for the main browser window (if linked)."""
if self.main_window:
self.main_window.setWindowTitle(title)
else:
if self.windows:
self.windows[-1].setWindowTitle(title)
#MARK: SettingsWindow
class SettingsWindow(QDialog):
def __init__(self, parent=None):
super().__init__(parent)
self.setWindowTitle("Settings")
self.setGeometry(100, 100, 400, 300)
layout = QVBoxLayout()
self.heading_label = QLabel("Settings")
self.heading_label.setObjectName("heading")
layout.addWidget(self.heading_label, alignment=Qt.AlignmentFlag.AlignLeft)
self.new_tab_url_label = QLabel("New Tab URL:")
layout.addWidget(self.new_tab_url_label)
self.new_tab_url_edit = QLineEdit()
layout.addWidget(self.new_tab_url_edit)
self.default_new_tab_checkbox = QCheckBox("Open new tabs with default URL")
layout.addWidget(self.default_new_tab_checkbox)
self.theme_label = QLabel("Choose your theme:")
layout.addWidget(self.theme_label)
self.theme_combo = QComboBox()
self.theme_combo.addItems(["Auto", "Dark", "Light"])
layout.addWidget(self.theme_combo)
self.selabel = QLabel("Choose your search engine:")
layout.addWidget(self.selabel)
self.search_engine_combo = QComboBox()
self.search_engine_combo.addItems(["Google", "DuckDuckGo", "Bing"])
layout.addWidget(self.search_engine_combo)
self.ailabel = QLabel("Choose your AI service:")
layout.addWidget(self.ailabel)
self.AI_combo = QComboBox()
self.AI_combo.addItems(["Nora AI", "Claude", "Amanda AI 2", "ChatGPT", "Gemini"])
layout.addWidget(self.AI_combo)
self.musictitle = QLabel("Choose your Music service:")
layout.addWidget(self.musictitle)
self.music_combo = QComboBox()
self.music_combo.addItems(["Spotify", "Apple Music", "Amazon Music", "YouTube Music", "Tidal"])
layout.addWidget(self.music_combo)
self.accent_label = QLabel("Accent Colour (Hex):")
layout.addWidget(self.accent_label)
accent_layout = QHBoxLayout()
self.accent_edit = QLineEdit()
self.accent_edit.setPlaceholderText("#0a6cff")
self.accent_btn = QPushButton("Pick Colour")
self.accent_btn.clicked.connect(self.pick_accent_colour)
accent_layout.addWidget(self.accent_edit)
accent_layout.addWidget(self.accent_btn)
layout.addLayout(accent_layout)
self.accent_note = QLabel("NOTE: \n All settings changes \n will require a restart to apply.")
layout.addWidget(self.accent_note)
self.load_settings()
layout.addSpacing(20)
button_box = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok |
QDialogButtonBox.StandardButton.Cancel |
QDialogButtonBox.StandardButton.Reset)
button_box.accepted.connect(self.save_settings)
button_box.accepted.connect(self.accept)
button_box.rejected.connect(self.reject)
reset_button = button_box.button(QDialogButtonBox.StandardButton.Reset)
reset_button.clicked.connect(self.reset_settings)
layout.addWidget(button_box)
self.setLayout(layout)
def pick_accent_colour(self):
colour = QColorDialog.getColor()
if colour.isValid():
self.accent_edit.setText(colour.name())
def load_settings(self):
settings = QSettings("Tudify", "SimpleWeb")
self.new_tab_url_edit.setText(settings.value("new_tab_url", "https://tudify.co.uk/simpleweb/newtab.htm"))
self.theme_combo.setCurrentText(settings.value("theme", "auto"))
self.search_engine_combo.setCurrentText(settings.value("search_engine", "Google"))
self.AI_combo.setCurrentText(settings.value("AI_service", "Nora AI"))
self.music_combo.setCurrentText(settings.value("music_service", "Spotify"))
default_new_tab_checked = settings.value("default_new_tab_checked", False, type=bool)
self.default_new_tab_checkbox.setChecked(default_new_tab_checked)
self.accent_colour = str(settings.value("accent_colour", "#0a6cff"))
self.accent_edit.setText(self.accent_colour)
def reset_settings(self):
settings = QSettings("Tudify", "SimpleWeb")
settings.setValue("new_tab_url", "https://tudify.co.uk/simpleweb/newtab.htm")
settings.setValue("theme", "auto")
settings.setValue("search_engine","Google")
settings.setValue("AI_service", "Nora AI")
settings.setValue("default_new_tab_checked", True)
settings.setValue("accent_colour", "#0a6cff")
settings.setValue("music_service", "Spotify")
settings.setValue("initialsetup", "True")
print("DEBUG: Reset Settings.")
settings.sync()
QMessageBox.information(self, "Settings Reset", "SimpleWeb Will now restart to apply default settings.")
sys.exit(69)
def save_settings(self):
settings = QSettings("Tudify", "SimpleWeb")
settings.setValue("new_tab_url", self.new_tab_url_edit.text())
settings.setValue("theme", self.theme_combo.currentText())
settings.setValue("search_engine", self.search_engine_combo.currentText())
settings.setValue("AI_service", self.AI_combo.currentText())
settings.setValue("default_new_tab_checked", self.default_new_tab_checkbox.isChecked())
settings.setValue("accent_colour", self.accent_edit.text())
settings.setValue("music_service", self.music_combo.currentText())
print("DEBUG: Saved accent colour:", self.accent_edit.text())
#MARK: Debug Window
class DebugWindow(QDialog):
def __init__(self, parent=None):
super().__init__(parent)
self.setWindowTitle("DebugWindow")
self.setGeometry(100, 100, 400, 300)
self.json_path = os.path.join(os.path.dirname(__file__), "info.json")
self.info = self.load_json()
chromium_spoofer = None
if parent is not None and hasattr(parent, "chromium_spoofer"):
chromium_spoofer = parent.chromium_spoofer
else:
try:
chromium_spoofer = SimpleWeb.ChromiumSpoofer(parent or self)
except Exception:
chromium_spoofer = None
try:
currentchromiumstate = chromium_spoofer.chromium_spoofer_enabled() if chromium_spoofer else False
except Exception:
currentchromiumstate = False
if currentchromiumstate:
CurrentUA = ChromiumUserAgent
else:
CurrentUA = UserAgent
layout = QVBoxLayout()
self.heading_label = QLabel("Debug Flags")
self.heading_label.setObjectName("heading")
layout.addWidget(self.heading_label, alignment=Qt.AlignmentFlag.AlignLeft)
self.ostitle = QLabel("Versioning")
layout.addWidget(self.ostitle)
self.osdisplay = QLabel(f"SimpleWeb {EngineVer} on {os_namereport} ({cpunamefinal})")
layout.addWidget(self.osdisplay)
self.cbn = QLabel("Set a Custom Browser Name:")
layout.addWidget(self.cbn)
self.CustomBrowserName = QLineEdit()
self.CustomBrowserName.setText(self.info.get("name", ""))
layout.addWidget(self.CustomBrowserName)
self.ua_label = QLabel("Edit UserAgent:")
layout.addWidget(self.ua_label)
self.ua_edit = QLineEdit()
self.ua_edit.setText(CurrentUA)
layout.addWidget(self.ua_edit)
self.font_label = QLabel("Set Custom Font Name:")
layout.addWidget(self.font_label)
self.font_edit = QLineEdit()
self.font_edit.setText(self.info.get("font", "Hack"))
layout.addWidget(self.font_edit)
layout.addSpacing(20)
button_box = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok)
button_box.accepted.connect(self.save_and_close)
layout.addWidget(button_box)
self.setLayout(layout)
def load_json(self):
if not os.path.exists(self.json_path):
raise FileNotFoundError("info.json must be in the same directory!")
try:
with open(self.json_path, "r", encoding="utf-8") as f:
return json.load(f)
except Exception:
raise FileNotFoundError("info.json must be in the same directory!")
def save_json(self):
with open(self.json_path, "w", encoding="utf-8") as f:
json.dump(self.info, f, indent=4)
def save_and_close(self):
global UserAgent
self.info["name"] = self.CustomBrowserName.text().strip()
self.info["font"] = self.font_edit.text().strip() # save the font
UserAgent = self.ua_edit.text().strip()
self.save_json()
self.accept()
#MARK: InitialWelcome
class InitialWelcome(QDialog):
def __init__(self, parent=None):
super().__init__(parent)
self.setWindowTitle("Welcome to SimpleWeb!")
self.setGeometry(100, 100, 400, 300)
layout = QVBoxLayout()
self.heading_label = QLabel("Hello. It's good to see you.")
self.heading_label.setObjectName("heading")
layout.addWidget(self.heading_label, alignment=Qt.AlignmentFlag.AlignCenter)
self.swwelcme = QLabel("Welcome to SimpleWeb! Here's the basics so you can get going right away.")
self.swwelcme.setObjectName("welcome")
layout.addWidget(self.swwelcme)
self.cntrls = QLabel("""
<b>Keyboard Shortcuts:</b><br><br>
• <b>Ctrl + U</b> — Quick Bar<br>
• <b>Ctrl + ,</b> — Settings<br>
• <b>extensions:// (type inside of Quick Bar)</b> — Extensions Panel<br>
• <b>Ctrl + Z</b> — Back<br>
• <b>Ctrl + R</b> — Refresh
""")
layout.addWidget(self.cntrls)
layout.addSpacing(20)
self.settings_btn = QPushButton("Open Settings")
self.settings_btn.clicked.connect(self.openSettings)
layout.addWidget(self.settings_btn, alignment=Qt.AlignmentFlag.AlignLeft)
self.setLayout(layout)
def openSettings(self):
BrowserWindow.settings_window = SettingsWindow(self)
BrowserWindow.settings_window.show()
def closeEvent(self, event):
settings = QSettings("Tudify", "SimpleWeb")
settings.setValue("initialsetup", "False")
settings.sync()
super().closeEvent(event)
#MARK: Main - BrowserWindow
class BrowserWindow(QMainWindow):
def __init__(self):
super().__init__()
self.load_settings()
self.checkwintitle()
self.setWindowTitle(name)
self.setGeometry(225, 150, 1270, 760)
print(f"SimpleWebAPI v{APIver}")
self.refresh_shortcut = QShortcut(QKeySequence("Ctrl+R"), self)
self.refresh_shortcut.activated.connect(self.refresh_page)
self.shortcut_close_tab = QShortcut(QKeySequence("Ctrl+W"), self)
self.shortcut_close_tab.activated.connect(self.close_current_tab)
self.shortcut_settings = QShortcut(QKeySequence("Ctrl+,"), self)
self.shortcut_settings.activated.connect(self.open_settings_window)
self.shortcut_new_tab = QShortcut(QKeySequence("Ctrl+T"), self)
self.shortcut_new_tab.activated.connect(self.open_default_new_tab)
self.shortcut_toggle_tabbar = QShortcut(QKeySequence("F11"), self)
self.shortcut_toggle_tabbar.activated.connect(self.toggle_tab_bar)
self.shortcut_url_popup = QShortcut(QKeySequence("Ctrl+U"), self)
self.shortcut_url_popup.activated.connect(self.toggle_url_popup)
self.shortcut_find_popup = QShortcut(QKeySequence("Ctrl+F"), self)
self.shortcut_find_popup.activated.connect(self.toggle_find_popup)
self.shortcut_goback = QShortcut(QKeySequence("Ctrl+Z"), self)
self.shortcut_goback.activated.connect(self.go_back)
self.set_stylesheet(self.theme)
menubar(self)
self.central_widget = QWidget()
self.setCentralWidget(self.central_widget)
self.central_layout = QVBoxLayout(self.central_widget)
self.create_tab_widget()
self.url_popup = QLineEdit(self)
self.url_popup.setPlaceholderText("Enter URL or search...")
self.url_popup.hide()
self.url_popup.returnPressed.connect(self.handle_quick_url)
self.url_popup.installEventFilter(self)
self.find_popup = QLineEdit(self)
self.find_popup.setPlaceholderText("Search this Webpage...")
self.find_popup.hide()
self.find_popup.installEventFilter(self)
self.popups_width = 400
self.popups_height = 40
self.update_url_popup_position()
self.update_find_pos()
self.onboardingcheck()
self.extension_instances = {}
self.auto_register_shortcuts(simplewebex.SimpleWeb)
self.debugwin = DebugWindow(self)
self.versioncheck()
# MARK: Support Check
def versioncheck(self):
if os_namereport.startswith("Windows"):
if winver in ["XP", "Vista", "7", "8", "8.1"]:
self.supportissuewindow()
print("version check failed!")
else:
print("version check passed: Windows 10/11")
if os_namereport.startswith("macOS"):
if not macver.startswith("26_"):
self.supportissuewindow()
print("version check failed!")
else:
print("version check passed: macOS 26")
#if you imagine it supports linux, it supports linux!
def supportissuewindow(self):
msg = QMessageBox()
msg.setWindowTitle("Insecure Operating System")
msg.setText(
f"""You are using an older version of {os_namereport}, which is no longer supported
and is insecure. Please consider upgrading to a newer version of {os_namereport}.
tudify and the SimpleWeb team accept zero liability for any damage caused
by using this software on an insecure OS.""")
msg.setStandardButtons(QMessageBox.StandardButton.Ok)
msg.exec()
def checkwintitle(self):
if name == "null":
winnullmsg = QMessageBox()
winnullmsg.setText("Fatal Error \n Window title cannot be null. \n null_err (1)")
winnullmsg.exec()
def initial_hello(self):
self.initialsetup = InitialWelcome(self)
self.initialsetup.show()
def onboardingcheck(self):
if self.initial_launch == "True":
self.initial_hello()
def findonpage(self, browser: QWebEngineView, text: str):
current_browser = self.tabs.currentWidget()
if not text:
current_browser.page().findText("", QWebEnginePage.FindFlag(0))
return
current_browser.page().findText(text, QWebEnginePage.FindFlag(0),
lambda result: print(f"Found {result.numberOfMatches()} matches, active match {result.activeMatch()}"))
def toggle_find_popup(self):
if self.find_popup.isVisible():
self.find_popup.clear()
self.find_popup.hide()
else:
self.find_popup.show()
self.find_popup.raise_()
self.find_popup.setFocus()
def toggle_tab_bar(self):
tabbar = self.tabs.tabBar()
if tabbar.isVisible():
tabbar.hide()
else:
tabbar.show()
# MARK: Shortcut handler
def auto_register_shortcuts(self, module):
for name, cls in inspect.getmembers(module, inspect.isclass):
if not hasattr(cls, '__module__'):
continue
shortcut_value = getattr(cls, "Shortcut", None)
if not shortcut_value or str(shortcut_value).lower() == "none":
continue
instance = None
try:
if name == "AIsidebar":
instance = cls(self, ai_service=self.AI_service)
else:
instance = cls(self)
except TypeError as e:
continue
if instance is None:
continue
self.extension_instances[name] = instance
toggle_method = None
toggle_method_name = None
for attr_name in dir(instance):
if attr_name.startswith("toggle"):
attr = getattr(instance, attr_name, None)
if callable(attr):
toggle_method = attr
toggle_method_name = attr_name
break
if not toggle_method:
continue
try:
shortcut = QShortcut(QKeySequence(shortcut_value), self)
shortcut.activated.connect(toggle_method)
except Exception as e:
extmsg = QMessageBox()
extmsg.setWindowTitle("Non-Fatal Error")
extmsg.setText(
"Non-Fatal Error\nSimpleWeb failed to initialise extensions."
"SimpleWeb will continue."
"simplewebex_not_found (4)")
extmsg.exec()
# MARK: Settings Checker
def TrackMeNot_enabled(self):
settings = QSettings("Tudify", "SimpleWeb-Extensions")
return settings.value("TrackMeNot", False, type=bool)
def load_settings(self):
settings = QSettings("Tudify", "SimpleWeb")
self.new_tab_url = settings.value("new_tab_url", "https://tudify.co.uk/simpleweb/newtab.htm")
self.accent_colour = str(settings.value("accent_colour", "#0a6cff"))
self.theme = settings.value("theme", "auto")
self.default_new_tab_enabled = settings.value("default_new_tab_checked", False, type=bool)
self.search_engine = settings.value("search_engine", "Google")
self.AI_service = settings.value("AI_service", "Nora AI")
self.music_service = settings.value("music_service", "Spotify")
self.initial_launch = settings.value("initialsetup")
print(f"DEBUG: Loaded accent colour: {self.accent_colour}")
self.chromium_spoofer = SimpleWeb.ChromiumSpoofer(self)
self.chromium_spoofer.apply_chromium_spoofer()
def save_settings(self):
settings = QSettings("Tudify", "SimpleWeb")
settings.setValue("new_tab_url", self.new_tab_url)
settings.setValue("theme", self.theme)
settings.setValue("default_new_tab_checked", self.default_new_tab_enabled)
settings.setValue("search_engine", self.search_engine)
settings.setValue("AI_service", self.AI_service)
settings.setValue("music_service", self.music_service)
self.music_sidebar = simplewebex.SimpleWeb.MusicSidebar(self)
self.music_sidebar.refresh_page()
settings.setValue("accent_colour", self.accent_colour)
# MARK: Default New Tab
def open_default_new_tab(self):
if self.default_new_tab_enabled:
self.add_new_tab(QUrl(self.new_tab_url))
else:
self.add_new_tab(QUrl("https://tudify.co.uk/simpleweb/newtab.htm"))
def toggle_url_popup(self):
if self.url_popup.isVisible():
self.url_popup.clear()
self.url_popup.hide()
else:
self.url_popup.show()
self.url_popup.raise_()
self.url_popup.setFocus()
def eventFilter(self, source, event):
if source is self.url_popup and event.type() == QEvent.Type.KeyPress:
if event.key() == Qt.Key.Key_Escape:
self.url_popup.clear()
self.url_popup.hide()
return True
elif source is self.find_popup and event.type() == QEvent.Type.KeyPress:
if event.key() in (Qt.Key.Key_Return, Qt.Key.Key_Enter):
self.findonpage(self.tabs.currentWidget(), self.find_popup.text())
return True
return False
return super().eventFilter(source, event)
# MARK: URL handler
def handle_quick_url(self):
text = self.url_popup.text().strip()
if not text:
self.url_popup.hide()
return
url_to_load = None
# Handle Tudify commands
if text.startswith(('tudify://', 'debug://', 'extensions://', '/weather')):
if text in ('tudify://settings', 'tudify://setup', 'tudify://set', 'tudify://config'):
self.open_settings_window()
self.url_popup.clear()
self.url_popup.hide()
return
elif text in ('debug://flags', 'debug://devflags'):
self.debugwin = DebugWindow(self)
self.debugwin.show()
self.url_popup.clear()
self.url_popup.hide()
return
elif text.startswith('/weather'):
self.url_popup.clear()
url_to_load = 'http://tudify.co.uk/weather'
elif text.startswith('extensions://'):
if text == 'extensions://store':
url_to_load = 'http://tudify.co.uk/simpleweb/extensions/store/'
elif text == 'extensions://':
self.extensions_window = ExtensionsWindow(self)
self.extensions_window.show()
self.url_popup.clear()
self.url_popup.hide()
else:
print("Error")
elif text == 'tudify://newtab':
url_to_load = 'https://tudify.co.uk/simpleweb/newtab.htm'
else:
print("Unknown tudify command:", text)
url_to_load = 'https://tudify.co.uk/simpleweb/404/'
elif text.startswith("file://"):
url_to_load = text
elif not text.startswith(('http://', 'https://')):
search_eng = self.search_engine.lower()
if '.' not in text: # assume search
if search_eng == "google":
url_to_load = f"https://www.google.com/search?q={urllib.parse.quote_plus(text)}"
elif search_eng == "duckduckgo":
url_to_load = f"https://duckduckgo.com/?q={urllib.parse.quote_plus(text)}"
elif search_eng == "bing":
url_to_load = f"https://www.bing.com/search?q={urllib.parse.quote_plus(text)}"
else:
url_to_load = 'https://' + text
else:
url_to_load = text # already has https/http
current_browser = self.tabs.currentWidget()
if current_browser:
current_browser.setUrl(QUrl(url_to_load))
else:
self.add_new_tab(QUrl(url_to_load))
self.url_popup.clear()
self.url_popup.hide()
def resizeEvent(self, event):
super().resizeEvent(event)
self.update_url_popup_position()
self.update_find_pos()
def update_find_pos(self):
x = (self.width() - self.popups_width) // 2
y = 20 # distance from top
self.find_popup.setGeometry(x, y, self.popups_width, self.popups_height)
def update_url_popup_position(self):
x = (self.width() - self.popups_width) // 2
y = 20 # distance from top
self.url_popup.setGeometry(x, y, self.popups_width, self.popups_height)
# MARK: Stylesheet
def set_stylesheet(self, theme):
accent = self.accent_colour
print(f"DEBUG: Applying {theme} Theme with accent: {accent}")
self.setAttribute(Qt.WidgetAttribute.WA_StyledBackground, True)
style_dark = f"""
*{{font-family:{font_name}, hack, arial;}}
QMainWindow {{
background-color: #202326;
color: #ffffff;
border: none;
}}
QLabel#heading {{
font-size: 22px;
font-weight: bold;
margin-bottom: 7px;
}}
QLabel#welcome {{
font-size: 16px;
font-weight: bold;
margin-bottom: 7px;
}}
QWebEngineView {{
border: none;
outline: none;
background: transparent;
}}
QMenu {{
background-color: #2b2b2b;
color: white;
border-radius: 8px;
border: 1px solid #444;
padding: 6px;
}}
QTabWidget::pane {{
border: none;
background: transparent;
}}
QMenu::item {{
padding: 6px 20px;
background-color: transparent;
border-radius: 4px;
}}
QMenu::item:selected {{
background-color: #3c3c3c;
border-radius: 4px;
}}
QComboBox{{
background-color: #292c30;
color: #ffffff;
padding: 10px 16px;
border-radius: 6px;
border: 1px solid #414346;
padding: 10px 16px 10px 16px;
}}
QComboBox:focus {{
background-color: #292c30;
border: 1px solid {accent};
}}
QDialog{{
background-color: #202326;
color: #ffffff;
}}
QPushButton {{
background-color: #292c30;
color: #ffffff;
padding: 10px 16px;
border-radius: 6px;
border: 1px solid #414346;
}}
QPushButton:hover {{
background-color: #292c30;
border: 1px solid #414346;
}}
QLineEdit {{
background-color: #292c30;
color: #ffffff;
padding: 10px 16px;
border-radius: 6px;
border: 1px solid {accent};
}}
QLineEdit:focus {{
background-color: #292c30;
border: 1px solid {accent};
}}
QTabBar::tab {{
background-color: #292c30;
color: #ffffff;
padding: 10px 16px;
border-radius: 6px;
border: 1px solid #414346;
}}
QTabBar::tab:selected {{
background-color: #292c30;
border: 1px solid {accent};
}}
"""
style_light = f"""
*{{font-family:{font_name}, hack, arial;}}
QMainWindow {{
background-color: #f5f5f5;
}}
QDialog {{
background-color: #f5f5f5;
text-color: #000000;
}}
QWebEngineView {{
border: none;
outline: none;
background: transparent;
}}
QLabel#heading {{
font-size: 22px;
font-weight: bold;
margin-bottom: 7px;
}}
QLabel#welcome {{
font-size: 16px;
font-weight: bold;
margin-bottom: 7px;
}}
QMenu {{
background-color: #e3e3e3;
color: black;
border-radius: 8px;
border: 1px solid #ccc;
padding: 6px;
}}
QTabWidget::pane {{
border: none;
background: transparent;
}}
QMenu::item {{
padding: 6px 20px;
background-color: transparent;
border-radius: 4px;
}}
QMenu::item:selected {{
background-color: #ffffff;
border-radius: 4px;
}}
QPushButton {{
background-color: #e0e0e0;
color: #000000;
padding: 10px 16px;
border-radius: 6px;
border: 1px solid #cccccc;
}}
QPushButton:hover {{
border: 1px solid {accent};
}}
QLineEdit {{
background-color: #ffffff;
color: #000000;
border: 1px solid #cccccc;
padding: 10px;
border-radius: 6px;
}}
QLineEdit:focus {{
border: 1px solid {accent};
}}
QTabBar::tab {{
background-color: #e0e0e0;
color: #000000;
padding: 8px 20px;
border-radius: 6px;
margin-right: 4px;
}}
QTabBar::tab:selected {{
border: 1px solid {accent};
}}
"""
if theme.lower() == "dark":
self.setStyleSheet(style_dark)
elif theme.lower() == "light":
self.setStyleSheet(style_light)
elif theme.lower() == "auto":
if os_namereport != "Linux":
if current_theme.lower() == "dark":
self.setStyleSheet(style_dark)
else:
self.setStyleSheet(style_light)
else:
self.setStyleSheet(style_dark)
else:
thmemsg = QMessageBox()
thmemsg.setWindowTitle("Settings Error")
thmemsg.setText(
"Settings Error\nSimpleWeb failed to initialise due"
"to an unknown setting."
"themenotfound error (5)"
)
thmemsg.exec()
sys.exit()
# MARK: Browsing Experiences
def docs(self, url):
current_browser = self.tabs.currentWidget()
if current_browser is not None:
current_browser.setUrl(QUrl(url))
def create_tab_widget(self):
self.tabs = QTabWidget()
self.tabs.tabCloseRequested.connect(lambda index: self.tabs.removeTab(index))
self.tabs.setTabPosition(QTabWidget.TabPosition.South)
tabbar = self.tabs.tabBar()
tabbar.setExpanding(False)
tabbar.setLayoutDirection(Qt.LayoutDirection.LeftToRight)
tabbar.setStyleSheet("QTabBar { qproperty-drawBase: 0;} QTabBar::tab { margin-right: 5px; }")
self.central_layout.addWidget(self.tabs)
self.add_new_tab(QUrl('https://tudify.co.uk/simpleweb/newtab.htm'))
def sw_context_menu(self, pos):
self.find_popup.hide()
self.url_popup.hide()
browser = self.sender()
page = browser.page()
menu = QMenu(self)
act_copy = page.action(QWebEnginePage.WebAction.Copy)
act_copy.setText("⧉ Copy")
act_cut = page.action(QWebEnginePage.WebAction.Cut)
act_cut.setText("✂ Cut")
act_paste = page.action(QWebEnginePage.WebAction.Paste)
act_paste.setText("| Paste")
menu.addAction(act_copy)
menu.addAction(act_paste)
menu.addAction(act_cut)
menu.addSeparator()
back_action = menu.addAction("← Back")
find_action = menu.addAction("⌕ Find")
reload_action = menu.addAction("↻ Reload")
selected = menu.exec(browser.mapToGlobal(pos))
if selected == back_action: