Fix up the editor to show the margins nicely, add loading of files
This commit is contained in:
parent
696f042a7f
commit
6354752eab
@ -1,8 +1,17 @@
|
|||||||
from PyQt5 import QtWidgets
|
from PyQt5 import QtWidgets
|
||||||
from mainwindow import MainWindow
|
from ukatali.mainwindow import MainWindow
|
||||||
|
|
||||||
|
|
||||||
|
def run_ukutali():
|
||||||
app = QtWidgets.QApplication([])
|
app = QtWidgets.QApplication([])
|
||||||
|
app.setApplicationDisplayName('Ukatali')
|
||||||
|
app.setApplicationName('Ukatali')
|
||||||
|
app.setOrganizationDomain('info.snyman')
|
||||||
|
app.setOrganizationName('Snyman')
|
||||||
window = MainWindow()
|
window = MainWindow()
|
||||||
window.show()
|
window.show()
|
||||||
app.exec()
|
app.exec()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
run_ukutali()
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
from pathlib import Path
|
||||||
from PyQt5 import QtCore, QtGui, QtWidgets, QtWebEngineWidgets, Qsci
|
from PyQt5 import QtCore, QtGui, QtWidgets, QtWebEngineWidgets, Qsci
|
||||||
|
|
||||||
|
OPEN_COUNT = 0
|
||||||
|
|
||||||
|
|
||||||
class MainWindow(QtWidgets.QMainWindow):
|
class MainWindow(QtWidgets.QMainWindow):
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
@ -17,8 +20,14 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
self.editorLayout.setSpacing(0)
|
self.editorLayout.setSpacing(0)
|
||||||
self.editorLayout.setObjectName("editorLayout")
|
self.editorLayout.setObjectName("editorLayout")
|
||||||
self.fileEditor = Qsci.QsciScintilla(self.editorWidget)
|
self.fileEditor = Qsci.QsciScintilla(self.editorWidget)
|
||||||
self.fileEditor.setColor(QtWidgets.QApplication.palette().windowText().color())
|
|
||||||
self.fileEditor.setFont(QtGui.QFont("monospace"))
|
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.fileEditor.setObjectName("fileEditor")
|
||||||
self.editorLayout.addWidget(self.fileEditor)
|
self.editorLayout.addWidget(self.fileEditor)
|
||||||
self.setCentralWidget(self.editorWidget)
|
self.setCentralWidget(self.editorWidget)
|
||||||
@ -154,7 +163,8 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
self.cutAction.triggered.connect(self.fileEditor.cut)
|
self.cutAction.triggered.connect(self.fileEditor.cut)
|
||||||
self.copyAction.triggered.connect(self.fileEditor.copy)
|
self.copyAction.triggered.connect(self.fileEditor.copy)
|
||||||
self.pasteAction.triggered.connect(self.fileEditor.paste)
|
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):
|
def retranslate_ui(self):
|
||||||
_translate = QtCore.QCoreApplication.translate
|
_translate = QtCore.QCoreApplication.translate
|
||||||
@ -205,3 +215,20 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
self.exitAction.setText(_translate("MainWindow", "E&xit"))
|
self.exitAction.setText(_translate("MainWindow", "E&xit"))
|
||||||
self.exitAction.setToolTip(_translate("MainWindow", "Quit Ukatali"))
|
self.exitAction.setToolTip(_translate("MainWindow", "Quit Ukatali"))
|
||||||
self.exitAction.setShortcut(_translate("MainWindow", "Alt+F4"))
|
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())
|
||||||
|
Loading…
Reference in New Issue
Block a user