From 4b052140f867cef6ee9ab375e87103cba0d618db Mon Sep 17 00:00:00 2001 From: Rohan Kishore <109947257+rohankishore@users.noreply.github.com> Date: Sat, 25 Nov 2023 14:22:34 +0530 Subject: [PATCH] #48 Added "Additional Preferences" for even more control --- auratext/Core/MenuConfig.py | 2 +- auratext/Core/additional_prefs.py | 88 +++++++++++++++++++++++++++++++ auratext/Core/window.py | 73 ++++++++++++++++--------- 3 files changed, 137 insertions(+), 26 deletions(-) create mode 100644 auratext/Core/additional_prefs.py diff --git a/auratext/Core/MenuConfig.py b/auratext/Core/MenuConfig.py index 7dd678b..927b35f 100644 --- a/auratext/Core/MenuConfig.py +++ b/auratext/Core/MenuConfig.py @@ -386,7 +386,7 @@ def read_only(): # language_menu.addMenu(z_menu) prefernces_menu.addMenu(language_menu) - # prefernces_menu.addAction("Autocomplete Dictionary", ) + prefernces_menu.addAction("Additional Preferences", self.additional_prefs) menubar.addMenu(prefernces_menu) help_menu = QMenu("&?", self) diff --git a/auratext/Core/additional_prefs.py b/auratext/Core/additional_prefs.py new file mode 100644 index 0000000..c647046 --- /dev/null +++ b/auratext/Core/additional_prefs.py @@ -0,0 +1,88 @@ +import json +import os +import sys + +from PyQt6.QtWidgets import ( + QLabel, + QCheckBox, + QPushButton, + QVBoxLayout, + QDialog, + QWidget, + QMessageBox, + QComboBox, + QApplication, +) + +local_app_data = os.path.join(os.getenv("LocalAppData"), "AuraText") + + +class SettingsWindow(QDialog): + def __init__(self): + super().__init__() + + with open(f"{local_app_data}/data/config.json", "r") as json_file: + self._config = json.load(json_file) + + self.splash_status = self._config['splash'] + + self._config = { + "splash": "", + } + + self.init_ui() + + def init_ui(self): + layout = QVBoxLayout() + layout.addStretch() + layout.addSpacing(100) + + self.splash_checkbox = QCheckBox("Show Adaptive Splash Screens") + self.splash_checkbox.setChecked(True) if self.splash_status == "True" else self.splash_checkbox.setChecked( + False) + + layout.addWidget(self.splash_checkbox) + + # Save Button + save_button = QPushButton("Apply") + save_button.setStyleSheet( + "QPushButton {" + " border-radius: 10px;" + " padding: 5px;" + "background-color: #121212;" + "color: white;" + "}" + ) + save_button.clicked.connect(self.save_settings) + layout.addWidget(save_button) + + self.setLayout(layout) + self.setWindowTitle("Settings Window") + + def save_settings(self): + if self.splash_checkbox.isChecked(): + self.splash_status = "True" + else: + self.splash_status = "False" + + # Update the splash status in the existing configuration + self._config["splash"] = self.splash_status + + # Save the updated configuration back to the JSON file + with open(f"{local_app_data}/data/config.json", "w") as json_file: + json.dump(self._config, json_file, indent=4) + + print(self.splash_status) + + # self._themes["editor_theme"] = self.editor_theme_input.isChecked() + # self._themes["margin_theme"] = self.margin_theme_input.isChecked() + # self._themes["lines_theme"] = self.lines_theme_input.isChecked() + # self._themes["lines_fg"] = self.lines_fg_input.isChecked() + # self._themes["font"] = self.font_theme_combobox.currentText() + # self._themes["theme_type"] = self.theme_combobox.currentText() + + QMessageBox.information( + self, + "Settings Applied!", + "The chosen settings have been applied.", + ) diff --git a/auratext/Core/window.py b/auratext/Core/window.py index e1e4d1d..cefaa6f 100644 --- a/auratext/Core/window.py +++ b/auratext/Core/window.py @@ -11,8 +11,8 @@ import git import pyjokes import qdarktheme -from PyQt6.QtCore import Qt, QSize, pyqtSignal -from PyQt6.QtGui import QColor, QFont, QActionGroup, QFileSystemModel, QPixmap, QIcon, QFontMetrics +from PyQt6.QtCore import Qt, QSize +from PyQt6.QtGui import QColor, QFont, QActionGroup, QFileSystemModel, QPixmap, QIcon from PyQt6.QtWidgets import ( QMainWindow, QInputDialog, @@ -25,13 +25,12 @@ QPushButton, QWidget, QVBoxLayout, - QDialog, - QStatusBar, - QLabel + QStatusBar ) from . import Lexers from . import MenuConfig +from . import additional_prefs from . import Modules as ModuleFile from . import PluginDownload from . import WelcomeScreen @@ -63,8 +62,14 @@ def __init__(self): self.local_app_data = local_app_data # self._terminal_history = "" - with open(f"{local_app_data}/data/theme.json", "r") as json_file: - self._themes = json.load(json_file) + # COMMENTED OUT CODE FOR FRAMELESS WINDOW. IN DEVELOPMENT + #self.setWindowFlags(Qt.WindowType.FramelessWindowHint) + #self.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground) + + with open(f"{local_app_data}/data/theme.json", "r") as themes_file: + self._themes = json.load(themes_file) + with open(f"{local_app_data}/data/config.json", "r") as config_file: + self._config = json.load(config_file) qdarktheme.setup_theme( self._themes["theme_type"], custom_colors={"primary": self._themes["theme"]} ) @@ -73,24 +78,30 @@ def __init__(self): self._terminal_history = thfile.readlines() # self._terminal_history.split('\n') - # Splash Screen - splash_pix = "" - current_time = datetime.datetime.now().time() - sunrise_time = current_time.replace(hour=6, minute=0, second=0, microsecond=0) - sunset_time = current_time.replace(hour=18, minute=0, second=0, microsecond=0) - - # Check which time interval the current time falls into - if sunrise_time <= current_time < sunrise_time.replace(hour=12): - splash_pix = QPixmap(f"{local_app_data}/icons/splash_morning.png") - elif sunrise_time.replace(hour=12) <= current_time < sunset_time: - splash_pix = QPixmap(f"{local_app_data}/icons/splash_afternoon.png") + def splashScreen(): + # Splash Screen + splash_pix = "" + current_time = datetime.datetime.now().time() + sunrise_time = current_time.replace(hour=6, minute=0, second=0, microsecond=0) + sunset_time = current_time.replace(hour=18, minute=0, second=0, microsecond=0) + + # Check which time interval the current time falls into + if sunrise_time <= current_time < sunrise_time.replace(hour=12): + splash_pix = QPixmap(f"{local_app_data}/icons/splash_morning.png") + elif sunrise_time.replace(hour=12) <= current_time < sunset_time: + splash_pix = QPixmap(f"{local_app_data}/icons/splash_afternoon.png") + else: + splash_pix = QPixmap(f"{local_app_data}/icons/splash_night.png") + + splash = QSplashScreen(splash_pix) + splash.show() + time.sleep(1) + splash.hide() + + if self._config["splash"] == "True": + splashScreen() else: - splash_pix = QPixmap(f"{local_app_data}/icons/splash_night.png") - - splash = QSplashScreen(splash_pix) - splash.show() - time.sleep(1) - splash.hide() + pass self.tab_widget = TabWidget() self.current_editor = "" @@ -193,6 +204,14 @@ def __init__(self): self.load_plugins() self.showMaximized() + #def mousePressEvent(self, event): + # self.dragPos = event.globalPosition().toPoint() + + #def mouseMoveEvent(self, event): + #self.move(self.pos() + event.globalPosition().toPoint() - self.dragPos) + #self.dragPos = event.globalPosition().toPoint() + #event.accept() + def create_editor(self): self.text_editor = CodeEditor(self) return self.text_editor @@ -246,7 +265,7 @@ def treeview_project(self, path): tree_view.setColumnHidden(1, True) # File type column tree_view.setColumnHidden(2, True) # Size column tree_view.setColumnHidden(3, True) # Date modified column - + tree_view.doubleClicked.connect(self.open_file) def expandSidebar__Explorer(self): @@ -657,6 +676,10 @@ def open_project_as_treeview(self): project_path = dialog.selectedFiles()[0] self.treeview_project(project_path) + def additional_prefs(self): + settings = additional_prefs.SettingsWindow() + settings.exec() + def new_document(self, checked=False, title="Scratch 1"): self.current_editor = self.create_editor()