diff --git a/.github/workflows/build-linux.yml b/.github/workflows/build-linux.yml index c92d9567..e109aa2e 100644 --- a/.github/workflows/build-linux.yml +++ b/.github/workflows/build-linux.yml @@ -45,7 +45,7 @@ jobs: run: python3 build.py - name: Upload ZIP - uses: actions/upload-artifact@v4.3.1 + uses: actions/upload-artifact@v7 with: name: Aura-Text path: dist diff --git a/.github/workflows/build-macos.yml b/.github/workflows/build-macos.yml index 34ed3b1a..0eedfdff 100644 --- a/.github/workflows/build-macos.yml +++ b/.github/workflows/build-macos.yml @@ -39,7 +39,7 @@ jobs: run: python3 build.py - name: Upload ZIP - uses: actions/upload-artifact@v4.3.1 + uses: actions/upload-artifact@v7 with: name: Aura-Text path: dist diff --git a/.github/workflows/build-windows.yml b/.github/workflows/build-windows.yml index 8eecb253..5cc85036 100644 --- a/.github/workflows/build-windows.yml +++ b/.github/workflows/build-windows.yml @@ -40,13 +40,13 @@ jobs: path: Aura-Text-setup-x64.iss - name: Upload ZIP - uses: actions/upload-artifact@v4.3.1 + uses: actions/upload-artifact@v7 with: name: Aura-Text path: dist - name: Upload installer - uses: actions/upload-artifact@v4.3.1 + uses: actions/upload-artifact@v7 with: name: Aura-Text-Installer-Output path: Output diff --git a/auratext/Components/About.py b/auratext/Components/About.py index cd45d18e..ad11a5e8 100644 --- a/auratext/Components/About.py +++ b/auratext/Components/About.py @@ -10,16 +10,9 @@ QVBoxLayout, QSpacerItem, QHBoxLayout, QLabel, QSizePolicy, QDialog) -if platform.system() == "Windows": - local_app_data = os.getenv('LOCALAPPDATA') -elif platform.system() == "Linux": - local_app_data = os.path.expanduser("~/.config") -elif platform.system() == "Darwin": - local_app_data = os.path.expanduser("~/Library/Application Support") -else: - print("Unsupported operating system") - sys.exit(1) -local_app_data = os.path.join(local_app_data, "AuraText") +from auratext.Misc.boilerplates import get_appdata_dirs + +local_app_data, script_dir = get_appdata_dirs() class AboutAppDialog(QDialog): def __init__(self): diff --git a/auratext/Components/DBViewer.py b/auratext/Components/DBViewer.py index 2808f9a7..58324231 100644 --- a/auratext/Components/DBViewer.py +++ b/auratext/Components/DBViewer.py @@ -20,7 +20,7 @@ def load_db(self): tables = cursor.fetchall() con.close() - db = QSqlDatabase.addDatabase("QSQLITE") + db = QSqlDatabase.addDatabase("QSQLITE", "auratext_dbviewer") db.setDatabaseName(self.db_path) if not db.open(): diff --git a/auratext/Components/GitCommit.py b/auratext/Components/GitCommit.py index 3335d193..f9ed0760 100644 --- a/auratext/Components/GitCommit.py +++ b/auratext/Components/GitCommit.py @@ -10,19 +10,11 @@ import platform from auratext.Misc.import_res import notepadequalequalComponentImportPathAppend +from auratext.Misc.boilerplates import get_appdata_dirs sys.path.append(notepadequalequalComponentImportPathAppend) from notepadequalequal.fileio import retrieve_file -if platform.system() == "Windows": - local_app_data = os.getenv('LOCALAPPDATA') -elif platform.system() == "Linux": - local_app_data = os.path.expanduser("~/.config") -elif platform.system() == "Darwin": - local_app_data = os.path.expanduser("~/Library/Application Support") -else: - print("Unsupported operating system") - sys.exit(1) -local_app_data = os.path.join(local_app_data, "AuraText") +local_app_data, script_dir = get_appdata_dirs() cpath = retrieve_file(f"{local_app_data}/data/CPath_Project.txt").strip() # Load theme diff --git a/auratext/Components/GitPush.py b/auratext/Components/GitPush.py index f72df3de..988c34ea 100644 --- a/auratext/Components/GitPush.py +++ b/auratext/Components/GitPush.py @@ -5,19 +5,11 @@ import platform from auratext.Misc.import_res import notepadequalequalComponentImportPathAppend +from auratext.Misc.boilerplates import get_appdata_dirs sys.path.append(notepadequalequalComponentImportPathAppend) from notepadequalequal.fileio import retrieve_file -if platform.system() == "Windows": - local_app_data = os.getenv('LOCALAPPDATA') -elif platform.system() == "Linux": - local_app_data = os.path.expanduser("~/.config") -elif platform.system() == "Darwin": - local_app_data = os.path.expanduser("~/Library/Application Support") -else: - print("Unsupported operating system") - sys.exit(1) -local_app_data = os.path.join(local_app_data, "AuraText") +local_app_data, script_dir = get_appdata_dirs() cpath = retrieve_file(f"{local_app_data}/data/CPath_Project.txt").strip() class GitPushDialog(QDialog): @@ -55,9 +47,11 @@ def __init__(self, parent=None): push_button = QPushButton("Push") self.main_layout.addWidget(push_button) push_button.clicked.connect(self.push) + + self.notAGitRepoError = "Not a Git repository. Please initialize a Git repository." if not self.is_git_repo(): - print(self, "Error", "Not a Git repository. Please initialize a Git repository.") + print(self, "Error", self.notAGitRepoError) self.reject() return diff --git a/auratext/Components/GitRebase.py b/auratext/Components/GitRebase.py index da61a897..241b4e12 100644 --- a/auratext/Components/GitRebase.py +++ b/auratext/Components/GitRebase.py @@ -1,7 +1,9 @@ +from PyQt6.QtCore import Qt from PyQt6.QtWidgets import QDialog, QVBoxLayout, QLabel, QLineEdit, QPushButton, QTableWidget, QTableWidgetItem, QComboBox, QHeaderView, QMessageBox import subprocess import tempfile import os +import platform class GitRebaseDialog(QDialog): def __init__(self, path): @@ -115,12 +117,19 @@ def start_rebase(self): with open(script_path, 'w') as f: f.write(rebase_script) - # For Windows, we need to create a simple batch file to act as the editor - editor_script_path = os.path.join(tempfile.gettempdir(), 'auratext-rebase-editor.bat') - with open(editor_script_path, 'w') as f: - # The batch script will be called by git with the path to the git-rebase-todo file - # We overwrite that file with our generated script. - f.write(f'copy "{script_path}" %1 > NUL') + if platform.system() == "Windows": + # For Windows, we need to create a simple batch file to act as the editor + editor_script_path = os.path.join(tempfile.gettempdir(), 'auratext-rebase-editor.bat') + with open(editor_script_path, 'w') as f: + # The batch script will be called by git with the path to the git-rebase-todo file + # We overwrite that file with our generated script. + f.write(f'copy "{script_path}" %1 > NUL') + else: + editor_script_path = os.path.join(tempfile.gettempdir(), 'auratext-rebase-editor.sh') + with open(editor_script_path, 'w') as f: + unixRScriptContents = "#!/bin/sh" + '\n' + f'cp "{script_path}" "$1"' + "\n" + f.write(unixRScriptContents) + os.chmod(editor_script_path, 0o755) env = os.environ.copy() env["GIT_SEQUENCE_EDITOR"] = f'"{editor_script_path}"' diff --git a/auratext/Components/Linter.py b/auratext/Components/Linter.py index 9379a7d9..2aec2229 100644 --- a/auratext/Components/Linter.py +++ b/auratext/Components/Linter.py @@ -18,16 +18,9 @@ from pylint.reporters.json_reporter import JSONReporter import json -if platform.system() == "Windows": - local_app_data = os.getenv('LOCALAPPDATA') -elif platform.system() == "Linux": - local_app_data = os.path.expanduser("~/.config") -elif platform.system() == "Darwin": - local_app_data = os.path.expanduser("~/Library/Application Support") -else: - print("Unsupported operating system") - sys.exit(1) -local_app_data = os.path.join(local_app_data, "AuraText") +from auratext.Misc.boilerplates import get_appdata_dirs + +local_app_data, script_dir = get_appdata_dirs() class LintMessage: diff --git a/auratext/Components/TabWidget.py b/auratext/Components/TabWidget.py index 67646a37..1b563107 100644 --- a/auratext/Components/TabWidget.py +++ b/auratext/Components/TabWidget.py @@ -1,63 +1 @@ -""" -A custom tab widget for the AuraText editor, supporting drag-and-drop reordering and a context""" - -from PyQt6.QtCore import QMimeData, QPoint -from PyQt6.QtGui import QPixmap, QRegion, QAction -from PyQt6.QtWidgets import QTabWidget, QMenu - - -class TabWidget(QTabWidget): - def __init__(self, parent=None, new=None): - super().__init__(parent) - self.setAcceptDrops(True) - self.tabBar().setMouseTracking(True) - self.setMovable(True) - self.setDocumentMode(True) - if new: - TabWidget.setup(self) - - def __setstate__(self, data): - self.__init__(new=False) - self.setParent(data["parent"]) - for widget, tabname in data["tabs"]: - self.addTab(widget, tabname) - TabWidget.setup(self) - - def __getstate__(self): - data = { - "parent": self.parent(), - "tabs": [], - } - tab_list = data["tabs"] - for k in range(self.count()): - tab_name = self.tabText(k) - widget = self.widget(k) - tab_list.append((widget, tab_name)) - return data - - def setup(self): - pass - - def mouseMoveEvent(self, e): - globalPos = self.mapToGlobal(e.pos()) - tabBar = self.tabBar() - posInTab = tabBar.mapFromGlobal(globalPos) - index = tabBar.tabAt(e.pos()) - tabRect = tabBar.tabRect(index) - - pixmap = QPixmap(tabRect.size()) - tabBar.render(pixmap, QPoint(), QRegion(tabRect)) - mimeData = QMimeData() - - def contextMenuEvent(self, event): - menu = QMenu(self) - close_alltabs = QAction("Close All Tabs", self) - - close_alltabs.triggered.connect(self.close_all_tabs) - - menu.addAction(close_alltabs) - - menu.exec(event.globalPos()) - - def close_all_tabs(self): - self.clear() +from auratext.Core.TabWidget import * diff --git a/auratext/Components/ToDo.py b/auratext/Components/ToDo.py index f81913d4..f872ac18 100644 --- a/auratext/Components/ToDo.py +++ b/auratext/Components/ToDo.py @@ -10,17 +10,9 @@ QVBoxLayout, QListWidget, QPushButton, QHBoxLayout, QMessageBox, QDialog, QLineEdit ) from notepadequalequal.fileio import retrieve_file +from auratext.Misc.boilerplates import get_appdata_dirs -if platform.system() == "Windows": - local_app_data = os.getenv('LOCALAPPDATA') -elif platform.system() == "Linux": - local_app_data = os.path.expanduser("~/.config") -elif platform.system() == "Darwin": - local_app_data = os.path.expanduser("~/Library/Application Support") -else: - print("Unsupported operating system") - sys.exit(1) -local_app_data = os.path.join(local_app_data, "AuraText") +local_app_data, script_dir = get_appdata_dirs() cpath = retrieve_file(f"{local_app_data}/data/CPath_Project.txt").strip() def check_folder_exists(folder_path): @@ -36,12 +28,12 @@ def create_folder(folder_path): pass -if check_folder_exists(f"{cpath}/Aura Text/"): +if check_folder_exists(f"{cpath}/.auratext/"): pass else: - create_folder(f"{cpath}/Aura Text") + create_folder(f"{cpath}/.auratext") # Path to the CSV file -CSV_FILE = f"{cpath}/Aura Text/todo.csv" +CSV_FILE = f"{cpath}/.auratext/todo.csv" class ToDoApp(QDialog): diff --git a/auratext/Components/statusBar.py b/auratext/Components/statusBar.py index 18de304e..d1da5947 100644 --- a/auratext/Components/statusBar.py +++ b/auratext/Components/statusBar.py @@ -14,18 +14,9 @@ from PyQt6.QtWidgets import QFrame, QHBoxLayout, QLabel, QStatusBar, QWidget, QPushButton # from ..scripts.color_scheme_loader import color_schemes -from auratext.Misc.boilerplates import get_font_for_platform - -if platform.system() == "Windows": - local_app_data = os.getenv('LOCALAPPDATA') -elif platform.system() == "Linux": - local_app_data = os.path.expanduser("~/.config") -elif platform.system() == "Darwin": - local_app_data = os.path.expanduser("~/Library/Application Support") -else: - print("Unsupported operating system") - sys.exit(1) -local_app_data = os.path.join(local_app_data, "AuraText") +from auratext.Misc.boilerplates import get_font_for_platform, get_appdata_dirs + +local_app_data, script_dir = get_appdata_dirs() with open(f"{local_app_data}/data/theme.json", "r") as themes_file: _themes = json.load(themes_file) @@ -160,7 +151,7 @@ def __init__(self, parent=None, greeting=None): self.editModeLabel.setFont(smallFont) self.editModeLabel.setStyleSheet( f""" - color: {"#FFFFFF;"}; + color: #FFFFFF; font-weight: bold; margin-bottom: 5px; """ diff --git a/auratext/Core/Lexers.py b/auratext/Core/Lexers.py index 451358c8..cb1a1129 100644 --- a/auratext/Core/Lexers.py +++ b/auratext/Core/Lexers.py @@ -381,7 +381,7 @@ def verilog(self): lexer.setDefaultColor(QColor("#FFFFFF")) self.current_editor.setLexer(lexer) lexer.setPaper(QColor(self._themes["editor_theme"])) - lexer.setColor(QColor(self._themes["editor_theme"]), lexer.Comment) + lexer.setColor(QColor("#808080"), lexer.Comment) lexer.setColor(QColor("#FFA500"), lexer.Keyword) lexer.setFont(get_font_for_platform(size=14, plain=True)) diff --git a/auratext/Core/MenuConfig.py b/auratext/Core/MenuConfig.py index a4ad23e6..2e63c89b 100644 --- a/auratext/Core/MenuConfig.py +++ b/auratext/Core/MenuConfig.py @@ -7,22 +7,15 @@ from PyQt6.QtWidgets import QMenu from PyQt6.QtGui import QAction, QIcon +from PyQt6.QtWidgets import QMessageBox + from auratext.Misc.import_res import notepadequalequalComponentImportPathAppend +from auratext.Misc.boilerplates import get_appdata_dirs sys.path.append(notepadequalequalComponentImportPathAppend) from .plugin_interface import MenuPluginInterface from notepadequalequal.fileio import retrieve_file - -if platform.system() == "Windows": - local_app_data = os.getenv('LOCALAPPDATA') -elif platform.system() == "Linux": - local_app_data = os.path.expanduser("~/.config") -elif platform.system() == "Darwin": - local_app_data = os.path.expanduser("~/Library/Application Support") -else: - print("Unsupported operating system") - sys.exit(1) -local_app_data = os.path.join(local_app_data, "AuraText") +local_app_data, script_dir = get_appdata_dirs() try: cpath = retrieve_file(f"{local_app_data}/data/CPath_Project.txt").strip() except (FileNotFoundError, OSError): @@ -249,6 +242,8 @@ def read_only(): action_py.triggered.connect(self.python) self.action_group.addAction(action_py) + action_py.setChecked(True) + action_cpp = QAction("C++", self, checkable=True) action_cpp.triggered.connect(self.cpp) self.action_group.addAction(action_cpp) @@ -264,16 +259,14 @@ def read_only(): action_js = QAction("JavaScript", self, checkable=True) action_js.triggered.connect(self.js) self.action_group.addAction(action_js) - action_py.setChecked(True) action_bash = QAction("Bash", self, checkable=True) - action_js.triggered.connect(self.bash) + action_bash.triggered.connect(self.bash) self.action_group.addAction(action_bash) action_csharp = QAction("C#", self, checkable=True) action_csharp.triggered.connect(self.csharp) self.action_group.addAction(action_csharp) - action_py.setChecked(True) action_ruby = QAction("Ruby", self, checkable=True) action_ruby.triggered.connect(self.ruby) @@ -312,33 +305,33 @@ def read_only(): self.action_group.addAction(action_css) action_batch = QAction("Batch", self, checkable=True) - action_css.triggered.connect(self.batch) + action_batch.triggered.connect(self.batch) self.action_group.addAction(action_batch) action_avs = QAction("AVS", self, checkable=True) - action_css.triggered.connect(self.avs) + action_avs.triggered.connect(self.avs) self.action_group.addAction(action_avs) action_asm = QAction("ASM", self, checkable=True) - action_css.triggered.connect(self.asm) + action_asm.triggered.connect(self.asm) self.action_group.addAction(action_asm) action_cmake = QAction("CMake", self, checkable=True) - action_css.triggered.connect(self.cmake) + action_cmake.triggered.connect(self.cmake) self.action_group.addAction(action_cmake) action_postscript = QAction("PostScript", self, checkable=True) action_postscript.setIcon(QIcon("Resources/language_icons/logo_postscript.png")) - action_css.triggered.connect(self.postscript) + action_postscript.triggered.connect(self.postscript) self.action_group.addAction(action_postscript) action_coffeescript = QAction("CoffeeScript", self, checkable=True) - action_css.triggered.connect(self.coffeescript) + action_coffeescript.triggered.connect(self.coffeescript) self.action_group.addAction(action_coffeescript) action_srec = QAction("SREC", self, checkable=True) - action_css.triggered.connect(self.coffeescript) - self.action_group.addAction(action_coffeescript) + action_srec.triggered.connect(self.srec) + self.action_group.addAction(action_srec) action_sql = QAction("SQL", self, checkable=True) action_sql.triggered.connect(self.sql) @@ -573,7 +566,17 @@ def toggle_pyconsole(): if section in sections: plugin.add_menu_items(sections[section]) except Exception as e: - print(f"Error loading plugin {plugin_module_name}: {e}") + + QMessageBox.critical( + + self, + + "Plugin Load Error", + + f"Error loading plugin '{plugin_module_name}':\n{e}" + + ) + for section, submenu in sections.items(): menubar.addMenu(submenu) diff --git a/auratext/Core/Modules.py b/auratext/Core/Modules.py index 6fed8b5c..b62f2b23 100644 --- a/auratext/Core/Modules.py +++ b/auratext/Core/Modules.py @@ -302,18 +302,18 @@ def pastebin(self): def summary(self): doc = self.current_editor.document() - # char_count = self.current_editor.split(QRegularExpression("(\\s|\\n|\\r)+").QString.SkipEmptyParts).count() + char_count = self.current_editor.split(QRegularExpression("(\\s|\\n|\\r)+").QString.SkipEmptyParts).count() line_count = str(doc.blockCount()) - # word_count = doc.wordCount() + word_count = doc.wordCount() text = ( "Total Number of Lines: " + line_count + "\n" + "Total Character Count: " - + "char_count" + + char_count + "\n" + "Total Word Count: " - + "word_count" + + word_count ) QMessageBox.information(self, "Summary", text) diff --git a/auratext/Core/PluginDownload.py b/auratext/Core/PluginDownload.py index 4326a944..19b11a5c 100644 --- a/auratext/Core/PluginDownload.py +++ b/auratext/Core/PluginDownload.py @@ -150,8 +150,8 @@ def get_file_list(self): def update_install_buttons(self): for card in self.cards: - selected_file = card.name + ".py" - local_file_path = os.path.join(self._window.local_app_data, "plugins", selected_file) + selected_file = card.name + local_file_path = os.path.join(self._window.local_app_data, "plugins", f"{selected_file}.py") if os.path.exists(local_file_path): card.install_btn.setText("Installed") card.install_btn.setDisabled(True) diff --git a/auratext/Core/TabWidget.py b/auratext/Core/TabWidget.py index b486b629..ed7eb60a 100644 --- a/auratext/Core/TabWidget.py +++ b/auratext/Core/TabWidget.py @@ -44,7 +44,11 @@ def mouseMoveEvent(self, e): pixmap = QPixmap(tabRect.size()) tabBar.render(pixmap, QPoint(), QRegion(tabRect)) - mimeData = QMimeData() + mimeData = QMimeData() + + drag = QDrag(self) + drag.setMimeData(mimeData) + drag.exec() def contextMenuEvent(self, event): menu = QMenu(self) diff --git a/auratext/Core/additional_prefs.py b/auratext/Core/additional_prefs.py index 8d4ecc44..a0999f5e 100644 --- a/auratext/Core/additional_prefs.py +++ b/auratext/Core/additional_prefs.py @@ -11,16 +11,9 @@ QMessageBox, ) -if platform.system() == "Windows": - local_app_data = os.getenv('LOCALAPPDATA') -elif platform.system() == "Linux": - local_app_data = os.path.expanduser("~/.config") -elif platform.system() == "Darwin": - local_app_data = os.path.expanduser("~/Library/Application Support") -else: - print("Unsupported operating system") - sys.exit(1) -local_app_data = os.path.join(local_app_data, "AuraText") +from auratext.Misc.boilerplates import get_appdata_dirs + +local_app_data, script_dir = get_appdata_dirs() class SettingsWindow(QDialog): @@ -43,9 +36,9 @@ def __init__(self): self.file_open_status = self._config["open_last_file"] print(self.exp_open_status) - self._config = { - "splash": "", - } + # self._config = { + # "splash": "", + # } self.init_ui() @@ -61,10 +54,6 @@ def init_ui(self): True) if self.terminaltips_status == "True" else self.ttips_checkbox.setChecked( False) - self.ttips_checkbox.setChecked( - True) if self.terminaltips_status == "True" else self.ttips_checkbox.setChecked( - False) - self.expopen_checkbox.setChecked( True) if self.exp_open_status == "True" else self.expopen_checkbox.setChecked( False) diff --git a/auratext/Core/window.py b/auratext/Core/window.py index 8aeb0560..8ffb292e 100644 --- a/auratext/Core/window.py +++ b/auratext/Core/window.py @@ -47,8 +47,7 @@ from . import ThemeDownload from . import config_page from .CommandPalette import CommandPalette -from ..Components import powershell, terminal, statusBar, ProjectManager, About, ToDo, GitGraph -from ..Components import powershell, terminal, statusBar, ProjectManager, About, ToDo, GitGraph, GitRebase, Performance, DBViewer +from ..Components import powershell, terminal, statusBar, ProjectManager, About, ToDo, GitGraph, GitRebase, Performance from ..Components.CommandPalette import CommandPalette from ..Components.NewProjectDialog import NewProjectDialog from ..Components.Linter import CodeLinter @@ -63,21 +62,9 @@ from auratext.Components.TabWidget import TabWidget from .plugin_interface import Plugin from notepadequalequal.fileio import retrieve_file -from auratext.Misc.boilerplates import get_font_for_platform, pathspec_gitignore_parse, is_under_parent_list - -if platform.system() == "Windows": - local_app_data = os.getenv('LOCALAPPDATA') -elif platform.system() == "Linux": - local_app_data = os.path.expanduser("~/.config") -elif platform.system() == "Darwin": - local_app_data = os.path.expanduser("~/Library/Application Support") -else: - print("Unsupported operating system") - sys.exit(1) - -local_app_data = os.path.join(local_app_data, "AuraText") +from auratext.Misc.boilerplates import get_font_for_platform, pathspec_gitignore_parse, is_under_parent_list, get_appdata_dirs -script_dir = os.path.dirname(os.path.abspath(__file__)) +local_app_data, script_dir = get_appdata_dirs() try: cpath = retrieve_file(f"{local_app_data}/data/CPath_Project.txt").strip() diff --git a/auratext/Misc/boilerplates.py b/auratext/Misc/boilerplates.py index b8586367..dc50cbe9 100644 --- a/auratext/Misc/boilerplates.py +++ b/auratext/Misc/boilerplates.py @@ -1,128 +1,146 @@ -import os -import platform -import sys - -from PyQt6.QtWidgets import ( - QMainWindow, - QInputDialog, - QDockWidget, - QTreeView, - QFileDialog, - QSplashScreen, - QMessageBox, - QPlainTextEdit, - QPushButton, - QWidget, - QVBoxLayout, - QStatusBar, - QListWidget, - QLabel, - QDialog) -from PyQt6.QtGui import QFont -import pathspec - -from auratext.Misc.import_res import notepadequalequalComponentImportPathAppend -sys.path.append(notepadequalequalComponentImportPathAppend) -from notepadequalequal.fileio import retrieve_file - -if platform.system() == "Windows": - local_app_data = os.getenv('LOCALAPPDATA') -elif platform.system() == "Linux": - local_app_data = os.path.expanduser("~/.config") -elif platform.system() == "Darwin": - local_app_data = os.path.expanduser("~/Library/Application Support") -else: - print("Unsupported operating system") - sys.exit(1) -local_app_data = os.path.join(local_app_data, "AuraText") - -class BoilerPlate(QDialog): - def __init__(self, current_editor): - super().__init__() - self.setWindowTitle("Boilerplates") - - self.current_editor = current_editor - - # Create a layout for the dock widget - dock_layout = QVBoxLayout() - self.setLayout(dock_layout) - # self.boilerplate_dock.setLayout(dock_layout) - - # Add a header label to the dock widget - header_label = QLabel("Boilerplates") - header_label.setStyleSheet("QLabel{font-size: 20px; font : Arial;}") - dock_layout.addWidget(header_label) - - # Create a QListWidget for displaying file names - self.boilerplate_list = QListWidget() - dock_layout.addWidget(self.boilerplate_list) - - # Populate the QListWidget with file names - directory = f"{local_app_data}/boilerplates" - if os.path.exists(directory): - try: - for file_name in os.listdir(directory): - if os.path.isfile(os.path.join(directory, file_name)): - name, extension = os.path.splitext(file_name) - self.boilerplate_list.addItem(name) - except Exception as e: - print(f"Error: {e}") - else: - print(f"The directory '{directory}' does not exist.") - - # Connect the clicked signal to a custom slot method - self.boilerplate_list.clicked.connect(self.on_item_clicked) - - def on_item_clicked(self, item): - print("Function reached") - selected_file = item.text() - - # Read the contents of the selected file - file_path = os.path.join(local_app_data, "boilerplates", f"{selected_file}.txt") - try: - file_contents = retrieve_file(file_path) - print(file_contents) - self.current_editor.append(file_contents) - except Exception as e: - print(f"Error reading file: {e}") - -def get_font_for_platform(size=12, plain=True): - system_name = platform.system() - if system_name == "Windows": - if plain == True: - return QFont("Consolas", size) - else: - return QFont("Arial", size) - elif system_name == "Darwin": - if plain: - return QFont("Menlo", size) - else: - return QFont("Helvetica", size) - else: - if plain: - return QFont("DejaVu Sans Mono", size) - else: - return QFont("Noto Sans", size) - -def pathspec_gitignore_parse(gitignore_path): - with open(gitignore_path, "r") as f: - lines = f.read().splitlines() - - spec = pathspec.PathSpec.from_lines('gitwildmatch', lines) - - return [line.strip() for line in lines if line.strip() and not line.startswith("#")] - -def is_under_parent_dir(path, parent_dir): - path = os.path.abspath(path) - parent_dir = os.path.abspath(parent_dir) - return os.path.commonpath([path, parent_dir]) == parent_dir - -def is_under_parent_list(path, parent_dirs): - n = 0 - for parent_dir in parent_dirs: - if is_under_parent_dir(path, parent_dir): - n += 1 - if n > 0: - return True - else: - return False +import os +import platform +import sys + +from PyQt6.QtWidgets import ( + QMainWindow, + QInputDialog, + QDockWidget, + QTreeView, + QFileDialog, + QSplashScreen, + QMessageBox, + QPlainTextEdit, + QPushButton, + QWidget, + QVBoxLayout, + QStatusBar, + QListWidget, + QLabel, + QDialog) +from PyQt6.QtGui import QFont +import pathspec + +from auratext.Misc.import_res import notepadequalequalComponentImportPathAppend +sys.path.append(notepadequalequalComponentImportPathAppend) +from notepadequalequal.fileio import retrieve_file + +if platform.system() == "Windows": + local_app_data = os.getenv('LOCALAPPDATA') +elif platform.system() == "Linux": + local_app_data = os.path.expanduser("~/.config") +elif platform.system() == "Darwin": + local_app_data = os.path.expanduser("~/Library/Application Support") +else: + print("Unsupported operating system") + sys.exit(1) + +local_app_data = os.path.join(local_app_data, "AuraText") +script_dir = os.path.dirname(os.path.abspath(__file__)) + +class BoilerPlate(QDialog): + def __init__(self, current_editor): + super().__init__() + self.setWindowTitle("Boilerplates") + + self.current_editor = current_editor + + # Create a layout for the dock widget + dock_layout = QVBoxLayout() + self.setLayout(dock_layout) + # self.boilerplate_dock.setLayout(dock_layout) + + # Add a header label to the dock widget + header_label = QLabel("Boilerplates") + header_label.setStyleSheet("QLabel{font-size: 20px; font : Arial;}") + dock_layout.addWidget(header_label) + + # Create a QListWidget for displaying file names + self.boilerplate_list = QListWidget() + dock_layout.addWidget(self.boilerplate_list) + + # Populate the QListWidget with file names + directory = f"{local_app_data}/boilerplates" + if os.path.exists(directory): + try: + for file_name in os.listdir(directory): + if os.path.isfile(os.path.join(directory, file_name)): + name, extension = os.path.splitext(file_name) + self.boilerplate_list.addItem(name) + except Exception as e: + print(f"Error: {e}") + else: + print(f"The directory '{directory}' does not exist.") + + # Connect the clicked signal to a custom slot method + self.boilerplate_list.clicked.connect(self.on_item_clicked) + + def on_item_clicked(self, item): + print("Function reached") + selected_file = item.text() + + # Read the contents of the selected file + file_path = os.path.join(local_app_data, "boilerplates", f"{selected_file}.txt") + try: + file_contents = retrieve_file(file_path) + print(file_contents) + self.current_editor.append(file_contents) + except Exception as e: + print(f"Error reading file: {e}") + +def get_font_for_platform(size=12, plain=True): + system_name = platform.system() + if system_name == "Windows": + if plain == True: + return QFont("Consolas", size) + else: + return QFont("Arial", size) + elif system_name == "Darwin": + if plain: + return QFont("Menlo", size) + else: + return QFont("Helvetica", size) + else: + if plain: + return QFont("DejaVu Sans Mono", size) + else: + return QFont("Noto Sans", size) + +def pathspec_gitignore_parse(gitignore_path): + with open(gitignore_path, "r") as f: + lines = f.read().splitlines() + + spec = pathspec.PathSpec.from_lines('gitwildmatch', lines) + + return [line.strip() for line in lines if line.strip() and not line.startswith("#")] + +def is_under_parent_dir(path, parent_dir): + path = os.path.abspath(path) + parent_dir = os.path.abspath(parent_dir) + return os.path.commonpath([path, parent_dir]) == parent_dir + +def is_under_parent_list(path, parent_dirs): + n = 0 + for parent_dir in parent_dirs: + if is_under_parent_dir(path, parent_dir): + n += 1 + if n > 0: + return True + else: + return False + +def get_appdata_dirs(): + if platform.system() == "Windows": + local_app_data = os.getenv('LOCALAPPDATA') + elif platform.system() == "Linux": + local_app_data = os.path.expanduser("~/.config") + elif platform.system() == "Darwin": + local_app_data = os.path.expanduser("~/Library/Application Support") + else: + print("Unsupported operating system") + sys.exit(1) + + local_app_data = os.path.join(local_app_data, "AuraText") + script_dir = os.path.dirname(os.path.abspath(__file__)) + + return local_app_data, script_dir diff --git a/auratext/Misc/get_started.py b/auratext/Misc/get_started.py index f02e9d7a..74fa3dcd 100644 --- a/auratext/Misc/get_started.py +++ b/auratext/Misc/get_started.py @@ -6,17 +6,9 @@ QStackedWidget from PyQt6.QtGui import QMovie import sys +from auratext.Misc.boilerplates import get_appdata_dirs -if platform.system() == "Windows": - local_app_data = os.getenv('LOCALAPPDATA') -elif platform.system() == "Linux": - local_app_data = os.path.expanduser("~/.config") -elif platform.system() == "Darwin": - local_app_data = os.path.expanduser("~/Library/Application Support") -else: - print("Unsupported operating system") - sys.exit(1) -local_app_data = os.path.join(local_app_data, "AuraText") +local_app_data, script_dir = get_appdata_dirs() with open(f"{local_app_data}/data/config.json", "r") as config_file: _config = json.load(config_file) diff --git a/main.py b/main.py index 761de5fe..ac6caf3b 100644 --- a/main.py +++ b/main.py @@ -3,6 +3,7 @@ import shutil import platform from auratext.Misc.quirks import copy_if_not_exists +from auratext.Misc.boilerplates import get_appdata_dirs if platform.system() == "Linux": from auratext.Misc.quirks import get_linux_productname, crosvm_quirks @@ -34,16 +35,7 @@ It will then load the config and theme files to apply the user's settings and theme preferences. """ -if platform.system() == "Windows": - local_app_data = os.getenv('LOCALAPPDATA') -elif platform.system() == "Linux": - local_app_data = os.path.expanduser("~/.config") -elif platform.system() == "Darwin": - local_app_data = os.path.expanduser("~/Library/Application Support") -else: - print("Unsupported operating system") - sys.exit(1) -local_app_data = os.path.join(local_app_data, "AuraText") +local_app_data, script_dir = get_appdata_dirs() template_app_data = os.path.join(os.path.dirname(sys.executable), "LocalAppData", "AuraText") if not os.path.exists(local_app_data):