From 6354752eab5e5505e36cdd2a9c6e7618703ece5b Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Thu, 29 Jul 2021 21:33:28 -0700 Subject: [PATCH] Fix up the editor to show the margins nicely, add loading of files --- src/ukatali/app.py | 19 ++++++++++++++----- src/ukatali/mainwindow.py | 31 +++++++++++++++++++++++++++++-- 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/src/ukatali/app.py b/src/ukatali/app.py index af34e6a..1cb85a7 100644 --- a/src/ukatali/app.py +++ b/src/ukatali/app.py @@ -1,8 +1,17 @@ from PyQt5 import QtWidgets -from mainwindow import MainWindow +from ukatali.mainwindow import MainWindow -app = QtWidgets.QApplication([]) -window = MainWindow() -window.show() -app.exec() +def run_ukutali(): + app = QtWidgets.QApplication([]) + app.setApplicationDisplayName('Ukatali') + app.setApplicationName('Ukatali') + app.setOrganizationDomain('info.snyman') + app.setOrganizationName('Snyman') + window = MainWindow() + window.show() + app.exec() + + +if __name__ == '__main__': + run_ukutali() diff --git a/src/ukatali/mainwindow.py b/src/ukatali/mainwindow.py index 0653c07..02e23b7 100644 --- a/src/ukatali/mainwindow.py +++ b/src/ukatali/mainwindow.py @@ -1,6 +1,9 @@ # -*- coding: utf-8 -*- +from pathlib import Path from PyQt5 import QtCore, QtGui, QtWidgets, QtWebEngineWidgets, Qsci +OPEN_COUNT = 0 + class MainWindow(QtWidgets.QMainWindow): def __init__(self, parent=None): @@ -17,8 +20,14 @@ class MainWindow(QtWidgets.QMainWindow): self.editorLayout.setSpacing(0) self.editorLayout.setObjectName("editorLayout") self.fileEditor = Qsci.QsciScintilla(self.editorWidget) - self.fileEditor.setColor(QtWidgets.QApplication.palette().windowText().color()) self.fileEditor.setFont(QtGui.QFont("monospace")) + self.fileEditor.setColor(QtWidgets.QApplication.palette().windowText().color()) + self.fileEditor.setCaretWidth(2) + self.fileEditor.setCaretForegroundColor(QtWidgets.QApplication.palette().windowText().color()) + self.fileEditor.setMarginsBackgroundColor(QtWidgets.QApplication.palette().window().color()) + self.fileEditor.setMarginsForegroundColor(QtWidgets.QApplication.palette().windowText().color()) + self.fileEditor.setMarginLineNumbers(1, True) + self.fileEditor.setMarginWidth(1, "000") self.fileEditor.setObjectName("fileEditor") self.editorLayout.addWidget(self.fileEditor) self.setCentralWidget(self.editorWidget) @@ -154,7 +163,8 @@ class MainWindow(QtWidgets.QMainWindow): self.cutAction.triggered.connect(self.fileEditor.cut) self.copyAction.triggered.connect(self.fileEditor.copy) self.pasteAction.triggered.connect(self.fileEditor.paste) - QtCore.QMetaObject.connectSlotsByName(self) + # QtCore.QMetaObject.connectSlotsByName(self) + self.openAction.triggered.connect(self.on_open_clicked) def retranslate_ui(self): _translate = QtCore.QCoreApplication.translate @@ -205,3 +215,20 @@ class MainWindow(QtWidgets.QMainWindow): self.exitAction.setText(_translate("MainWindow", "E&xit")) self.exitAction.setToolTip(_translate("MainWindow", "Quit Ukatali")) self.exitAction.setShortcut(_translate("MainWindow", "Alt+F4")) + + def on_open_clicked(self): + """Open the file""" + if QtCore.QSettings().value('files/last-directory'): + last_directory = QtCore.QSettings().value('files/last-directory') + else: + last_directory = '' + filename = QtWidgets.QFileDialog.getOpenFileName(self, "Open file", last_directory, + filter="All files *") + if isinstance(filename, tuple): + filename = filename[0] + if not filename: + return + file_path = Path(filename) + if file_path.exists(): + QtCore.QSettings().setValue('files/last-directory', str(file_path.parent)) + self.fileEditor.setText(file_path.open().read())