diff options
-rw-r--r-- | .idea/.gitignore | 8 | ||||
-rw-r--r-- | .idea/fedi_browser.iml | 10 | ||||
-rw-r--r-- | .idea/inspectionProfiles/Project_Default.xml | 6 | ||||
-rw-r--r-- | .idea/inspectionProfiles/profiles_settings.xml | 6 | ||||
-rw-r--r-- | .idea/misc.xml | 7 | ||||
-rw-r--r-- | .idea/modules.xml | 8 | ||||
-rw-r--r-- | .idea/vcs.xml | 6 | ||||
-rw-r--r-- | main.py | 127 |
8 files changed, 178 insertions, 0 deletions
diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/fedi_browser.iml b/.idea/fedi_browser.iml new file mode 100644 index 0000000..74d515a --- /dev/null +++ b/.idea/fedi_browser.iml @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module type="PYTHON_MODULE" version="4"> + <component name="NewModuleRootManager"> + <content url="file://$MODULE_DIR$"> + <excludeFolder url="file://$MODULE_DIR$/venv" /> + </content> + <orderEntry type="inheritedJdk" /> + <orderEntry type="sourceFolder" forTests="false" /> + </component> +</module> \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..9940ce4 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ +<component name="InspectionProjectProfileManager"> + <profile version="1.0"> + <option name="myName" value="Project Default" /> + <inspection_tool class="PyPep8Inspection" enabled="false" level="WEAK WARNING" enabled_by_default="false" /> + </profile> +</component> \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ +<component name="InspectionProjectProfileManager"> + <settings> + <option name="USE_PROJECT_PROFILE" value="false" /> + <version value="1.0" /> + </settings> +</component> \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..1daaa8b --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="MarkdownSettingsMigration"> + <option name="stateVersion" value="1" /> + </component> + <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (fedi_browser)" project-jdk-type="Python SDK" /> +</project> \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..a731ead --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="ProjectModuleManager"> + <modules> + <module fileurl="file://$PROJECT_DIR$/.idea/fedi_browser.iml" filepath="$PROJECT_DIR$/.idea/fedi_browser.iml" /> + </modules> + </component> +</project> \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="VcsDirectoryMappings"> + <mapping directory="$PROJECT_DIR$" vcs="Git" /> + </component> +</project> \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..835dd92 --- /dev/null +++ b/main.py @@ -0,0 +1,127 @@ +import os + +from PyQt5 import QtCore, QtGui +from PyQt5.QtGui import QKeySequence +from PyQt5.QtWidgets import * +from pyqt_line_number_widget import LineNumberWidget + +app = QApplication([]) + +class LineWindow(QTextBrowser): + def __init__(self, *_args): + super().__init__(*_args) + + def wheelEvent(self, e: QtGui.QWheelEvent): + pass + +class Window(QMainWindow): + def __init__(self): + super().__init__() + self.fileOpened = None + self.savedText = None + self.setWindowTitle("Text Editor") + self.setMinimumWidth(800) + self.setMinimumHeight(450) + + self.lay = QHBoxLayout() + + self.textWindow = QTextEdit(self) + self.textWindow.move(60, 20) + self.textWindow.verticalScrollBar().valueChanged.connect(self.moveLineWindow) + + self.lineWidget = LineWindow(self) + self.lineWidget.setFixedWidth(60) + self.lineWidget.move(0, 20) + self.lineWidget.setPlainText("1") + self.lineWidget.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarPolicy.ScrollBarAlwaysOff) + + self.textWindow.textChanged.connect(self.textUpdate) + + self.lay.addWidget(self.lineWidget) + self.lay.addWidget(self.textWindow) + + self.setLayout(self.lay) + self.createMenuBar() + + def resizeEvent(self, a0: QtGui.QResizeEvent): + self.resizeWidgets() + + def textUpdate(self): + if self.lineWidget: + n = int(self.textWindow.document().lineCount()) + lineString = "1" + x = 1 + while n > x: + x += 1 + lineString += f"\n{x}" + self.lineWidget.document().setPlainText(lineString) + + if self.fileOpened: + if self.savedText != self.textWindow.document().toPlainText(): + self.setWindowTitle(self.windowTitle() + "*") + else: + self.setWindowTitle(f"Text Editor - {str(os.path.basename(self.fileOpened))}") + + def moveLineWindow(self): + self.lineWidget.verticalScrollBar().setValue(self.textWindow.verticalScrollBar().value()) + + def resizeWidgets(self): + self.textWindow.setFixedWidth(self.width()-60) + self.textWindow.setFixedHeight(self.height()) + self.lineWidget.setFixedHeight(self.height()) + + def createMenuBar(self): + self.menuBar = self.menuBar() + + self.saveAction = QAction("Save", self) + self.saveAction.setShortcut(QKeySequence.Save) + self.saveAction.triggered.connect(self.saveFile) + + self.openAction = QAction("Open", self) + self.openAction.setShortcut(QKeySequence.Open) + self.openAction.triggered.connect(self.openFile) + + fileMenu = self.menuBar.addMenu("File") + fileMenu.addAction(self.saveAction) + fileMenu.addAction(self.openAction) + self.setMenuBar(self.menuBar) + + def openFile(self): + options = QFileDialog.Options() + file_name, _ = QFileDialog.getOpenFileName(self, "Open File", "", "All Files(*);;Text Files(*.txt)", + options=options) + if file_name: + f = open(file_name, "r") + self.textWindow.setPlainText(f.read()) + f.close() + self.fileOpened = file_name + self.setWindowTitle(f"Text Editor - {str(os.path.basename(self.fileOpened))}") + + def saveFile(self): + if self.fileOpened: + f = open(self.fileOpened, "w") + text = self.textWindow.document().toPlainText() + f.write(text) + f.close() + self.savedText = text + self.setWindowTitle(f"Text Editor - {str(os.path.basename(self.fileOpened))}") + else: + self.saveFileAs() + + def saveFileAs(self): + options = QFileDialog.Options() + file_name, _ = QFileDialog.getSaveFileName(self, "Save File", "", "All Files(*);;Text Files(*.txt)", + options=options) + if file_name: + f = open(file_name, "w") + text = self.textWindow.document().toPlainText() + f.write(text) + f.close() + self.savedText = text + self.fileOpened = file_name + self.setWindowTitle(f"Text Editor - {str(os.path.basename(file_name))}") + + +window = Window() +window.show() +app.exec() |