commit 15163b606ed861e61fb0b967d0f20c5c09d988bc Author: merelden Date: Tue Jun 11 17:08:03 2024 +0500 bigbaboo 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/NoteQt.iml b/.idea/NoteQt.iml new file mode 100644 index 0000000..d0876a7 --- /dev/null +++ b/.idea/NoteQt.iml @@ -0,0 +1,8 @@ + + + + + + + + \ 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 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..812ab5a --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..e7e881b --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ 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 @@ + + + + + + \ No newline at end of file diff --git a/__pycache__/mainWindow.cpython-39.pyc b/__pycache__/mainWindow.cpython-39.pyc new file mode 100644 index 0000000..899a9e9 Binary files /dev/null and b/__pycache__/mainWindow.cpython-39.pyc differ diff --git a/__pycache__/startWindow.cpython-39.pyc b/__pycache__/startWindow.cpython-39.pyc new file mode 100644 index 0000000..a688218 Binary files /dev/null and b/__pycache__/startWindow.cpython-39.pyc differ diff --git a/catalogs.json b/catalogs.json new file mode 100644 index 0000000..ddd8fbe --- /dev/null +++ b/catalogs.json @@ -0,0 +1 @@ +["/home/merelden/\u0420\u0430\u0431\u043e\u0447\u0438\u0439 \u0441\u0442\u043e\u043b/\u0422\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u043a\u0430\u0442\u0430\u043b\u043e\u0433", "/home/merelden/\u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b/test_Qt", "/home/merelden/\u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b/\u0442\u0435\u0441\u0442", "/home/merelden/\u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b/\u043f\u043f\u043f", "/home/merelden/\u0420\u0430\u0431\u043e\u0447\u0438\u0439 \u0441\u0442\u043e\u043b/\u043e"] \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..8a4c87d --- /dev/null +++ b/main.py @@ -0,0 +1,179 @@ +import sys +import os +import json +from PyQt5.QtWidgets import QApplication, QMainWindow, QFileDialog, QListWidgetItem, QLabel, QDesktopWidget +from PyQt5.QtCore import QDir, QFileSystemWatcher +from startWindow import Ui_startWindow as Ui_StartWindow +from mainWindow import Ui_MainWindow as Ui_MainWindow2 + +CONFIG_FILE = "catalogs.json" + +class StartWindow(QMainWindow): + def __init__(self): + super().__init__() + self.ui = Ui_StartWindow() + self.ui.setupUi(self) + self.setWindowTitle("Start Window") + + self.ui.createCatalog.clicked.connect(self.create_catalog) + self.ui.openCatalog.clicked.connect(self.open_catalog) + self.ui.startWindowList.itemClicked.connect(self.open_selected_catalog) + self.window_center() + + self.load_catalogs() + + def window_center(self): + qr = self.frameGeometry() + cp = QDesktopWidget().availableGeometry().center() + qr.moveCenter(cp) + self.move(qr.topLeft()) + + def create_catalog(self): + folder_path = QFileDialog.getSaveFileName(self, "Create New Catalog", "", "All Files (*);;Directory")[0] + if folder_path: + if not os.path.exists(folder_path): + os.makedirs(folder_path) + self.update_catalogs(folder_path) + self.open_main_window("New Catalog", folder_path) + + def open_catalog(self): + folder_path = QFileDialog.getExistingDirectory(self, "Select Directory", "") + if folder_path: + self.update_catalogs(folder_path) + self.open_main_window("Existing Catalog", folder_path) + + def open_main_window(self, catalog_name, folder_path): + self.main_window = MainWindow(catalog_name, folder_path) + self.main_window.show() + self.close() + + def load_catalogs(self): + if os.path.exists(CONFIG_FILE): + with open(CONFIG_FILE, "r") as f: + catalogs = json.load(f) + for catalog in catalogs: + item = QListWidgetItem(catalog) + self.ui.startWindowList.addItem(item) + + def update_catalogs(self, folder_path): + catalogs = [] + if os.path.exists(CONFIG_FILE): + with open(CONFIG_FILE, "r") as f: + catalogs = json.load(f) + if folder_path not in catalogs: + catalogs.append(folder_path) + with open(CONFIG_FILE, "w") as f: + json.dump(catalogs, f) + + def open_selected_catalog(self, item): + folder_path = item.text() + self.open_main_window("Existing Catalog", folder_path) + +class MainWindow(QMainWindow): + def __init__(self, catalog_name, folder_path): + super().__init__() + self.ui = Ui_MainWindow2() + self.ui.setupUi(self) + self.setWindowTitle("Main Window") + self.showMaximized() + + self.folder_path = folder_path + + self.ui.createFile.clicked.connect(self.create_file) + self.ui.back.clicked.connect(self.back_to_start) + + self.ui.mainList.itemClicked.connect(self.load_selected_note) + + if catalog_name == "New Catalog": + self.create_file() + self.ui.noteTitleEdit.textChanged.connect(self.save_note_title) + self.ui.noteEdit.textChanged.connect(self.save_note_content) + else: + self.show_default_label() + + self.show_directory_files() + + self.file_watcher = QFileSystemWatcher() + self.file_watcher.addPath(self.folder_path) + self.file_watcher.directoryChanged.connect(self.show_directory_files) + + def load_selected_note(self, item): + note_name = item.text() + self.default_note_path = os.path.join(self.folder_path, note_name) + self.load_note_content() + self.ui.noteTitleEdit.setPlainText(note_name) + self.ui.noteTitleEdit.show() + self.ui.noteEdit.show() + if hasattr(self, 'static_label'): + self.static_label.hide() + + def create_file(self): + base_name = "Без_Имени" + extension = ".md" + note_title = base_name + extension + counter = 1 + while os.path.exists(os.path.join(self.folder_path, note_title)): + note_title = f"{base_name}_{counter}{extension}" + counter += 1 + + self.default_note_path = os.path.join(self.folder_path, note_title) + with open(self.default_note_path, "w") as f: + f.write("") + + self.ui.noteTitleEdit.setPlainText(note_title) + self.ui.noteEdit.setPlainText("") + self.ui.noteTitleEdit.show() + self.ui.noteEdit.show() + if hasattr(self, 'static_label'): + self.static_label.hide() + + self.ui.noteTitleEdit.textChanged.connect(self.save_note_title) + self.ui.noteEdit.textChanged.connect(self.save_note_content) + + def load_note_content(self): + if os.path.exists(self.default_note_path): + with open(self.default_note_path, "r") as f: + content = f.read() + self.ui.noteEdit.setPlainText(content) + + def save_note_content(self): + content = self.ui.noteEdit.toPlainText() + with open(self.default_note_path, "w") as f: + f.write(content) + + def save_note_title(self): + new_note_title = self.ui.noteTitleEdit.toPlainText() + new_note_path = os.path.join(self.folder_path, new_note_title) + if new_note_path != self.default_note_path: + if os.path.exists(self.default_note_path): + os.rename(self.default_note_path, new_note_path) + self.default_note_path = new_note_path + + def show_directory_files(self): + if os.path.exists(self.folder_path): + self.ui.mainList.clear() + dir_content = QDir(self.folder_path).entryList(QDir.Files) + for file_name in dir_content: + item = QListWidgetItem(file_name) + self.ui.mainList.addItem(item) + + def show_default_label(self): + self.ui.noteTitleEdit.hide() + self.ui.noteEdit.hide() + + if not hasattr(self, 'static_label'): + self.static_label = QLabel("Выберите файл из списка или создайте новый") + self.ui.verticalLayout.addWidget(self.static_label) + else: + self.static_label.show() + + def back_to_start(self): + self.start_window = StartWindow() + self.start_window.show() + self.close() + +if __name__ == "__main__": + app = QApplication(sys.argv) + start_window = StartWindow() + start_window.show() + sys.exit(app.exec_()) diff --git a/mainWindow.py b/mainWindow.py new file mode 100644 index 0000000..76495d2 --- /dev/null +++ b/mainWindow.py @@ -0,0 +1,60 @@ +# -*- coding: utf-8 -*- + +# Form implementation generated from reading ui file '/home/merelden/Документы/NoteQt/mainWindow.ui' +# +# Created by: PyQt5 UI code generator 5.15.10 +# +# WARNING: Any manual changes made to this file will be lost when pyuic5 is +# run again. Do not edit this file unless you know what you are doing. + + +from PyQt5 import QtCore, QtGui, QtWidgets + + +class Ui_MainWindow(object): + def setupUi(self, MainWindow): + MainWindow.setObjectName("MainWindow") + MainWindow.resize(800, 600) + self.centralwidget = QtWidgets.QWidget(MainWindow) + self.centralwidget.setObjectName("centralwidget") + self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.centralwidget) + self.verticalLayout_2.setObjectName("verticalLayout_2") + self.horizontalLayout = QtWidgets.QHBoxLayout() + self.horizontalLayout.setObjectName("horizontalLayout") + self.back = QtWidgets.QPushButton(self.centralwidget) + self.back.setObjectName("back") + self.horizontalLayout.addWidget(self.back) + self.createFile = QtWidgets.QPushButton(self.centralwidget) + font = QtGui.QFont() + font.setPointSize(10) + self.createFile.setFont(font) + self.createFile.setObjectName("createFile") + self.horizontalLayout.addWidget(self.createFile) + self.verticalLayout_2.addLayout(self.horizontalLayout) + self.horizontalLayout_2 = QtWidgets.QHBoxLayout() + self.horizontalLayout_2.setObjectName("horizontalLayout_2") + self.mainList = QtWidgets.QListWidget(self.centralwidget) + self.mainList.setMaximumSize(QtCore.QSize(150, 16777215)) + self.mainList.setObjectName("mainList") + self.horizontalLayout_2.addWidget(self.mainList) + self.verticalLayout = QtWidgets.QVBoxLayout() + self.verticalLayout.setObjectName("verticalLayout") + self.noteTitleEdit = QtWidgets.QTextEdit(self.centralwidget) + self.noteTitleEdit.setMaximumSize(QtCore.QSize(16777215, 30)) + self.noteTitleEdit.setObjectName("noteTitleEdit") + self.verticalLayout.addWidget(self.noteTitleEdit) + self.noteEdit = QtWidgets.QTextEdit(self.centralwidget) + self.noteEdit.setObjectName("noteEdit") + self.verticalLayout.addWidget(self.noteEdit) + self.horizontalLayout_2.addLayout(self.verticalLayout) + self.verticalLayout_2.addLayout(self.horizontalLayout_2) + MainWindow.setCentralWidget(self.centralwidget) + + self.retranslateUi(MainWindow) + QtCore.QMetaObject.connectSlotsByName(MainWindow) + + def retranslateUi(self, MainWindow): + _translate = QtCore.QCoreApplication.translate + MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow")) + self.back.setText(_translate("MainWindow", "Назад")) + self.createFile.setText(_translate("MainWindow", "Новая заметка")) diff --git a/mainWindow.ui b/mainWindow.ui new file mode 100644 index 0000000..ea4919e --- /dev/null +++ b/mainWindow.ui @@ -0,0 +1,77 @@ + + + MainWindow + + + + 0 + 0 + 800 + 600 + + + + MainWindow + + + + + + + + + Назад + + + + + + + + 10 + + + + Новая заметка + + + + + + + + + + + + 150 + 16777215 + + + + + + + + + + + 16777215 + 30 + + + + + + + + + + + + + + + + + diff --git a/startWindow.py b/startWindow.py new file mode 100644 index 0000000..f240fb9 --- /dev/null +++ b/startWindow.py @@ -0,0 +1,93 @@ +# -*- coding: utf-8 -*- + +# Form implementation generated from reading ui file '/home/merelden/Документы/NoteQt/startWindow.ui' +# +# Created by: PyQt5 UI code generator 5.15.10 +# +# WARNING: Any manual changes made to this file will be lost when pyuic5 is +# run again. Do not edit this file unless you know what you are doing. + + +from PyQt5 import QtCore, QtGui, QtWidgets + + +class Ui_startWindow(object): + def setupUi(self, startWindow): + startWindow.setObjectName("startWindow") + startWindow.resize(800, 600) + sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(startWindow.sizePolicy().hasHeightForWidth()) + startWindow.setSizePolicy(sizePolicy) + startWindow.setMinimumSize(QtCore.QSize(800, 600)) + startWindow.setMaximumSize(QtCore.QSize(800, 600)) + startWindow.setBaseSize(QtCore.QSize(800, 600)) + startWindow.setAutoFillBackground(False) + self.centralwidget = QtWidgets.QWidget(startWindow) + self.centralwidget.setObjectName("centralwidget") + self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.centralwidget) + self.verticalLayout_2.setObjectName("verticalLayout_2") + self.horizontalLayout_3 = QtWidgets.QHBoxLayout() + self.horizontalLayout_3.setObjectName("horizontalLayout_3") + self.startWindowList = QtWidgets.QListWidget(self.centralwidget) + self.startWindowList.setMinimumSize(QtCore.QSize(250, 0)) + self.startWindowList.setMaximumSize(QtCore.QSize(252, 16777215)) + self.startWindowList.setStyleSheet("max-width: 250") + self.startWindowList.setObjectName("startWindowList") + self.horizontalLayout_3.addWidget(self.startWindowList) + self.verticalLayout = QtWidgets.QVBoxLayout() + self.verticalLayout.setSizeConstraint(QtWidgets.QLayout.SetMinimumSize) + self.verticalLayout.setSpacing(0) + self.verticalLayout.setObjectName("verticalLayout") + self.horizontalLayout = QtWidgets.QHBoxLayout() + self.horizontalLayout.setObjectName("horizontalLayout") + self.label = QtWidgets.QLabel(self.centralwidget) + self.label.setMaximumSize(QtCore.QSize(16777215, 16777215)) + font = QtGui.QFont() + font.setPointSize(14) + self.label.setFont(font) + self.label.setObjectName("label") + self.horizontalLayout.addWidget(self.label) + self.createCatalog = QtWidgets.QPushButton(self.centralwidget) + font = QtGui.QFont() + font.setPointSize(14) + self.createCatalog.setFont(font) + self.createCatalog.setObjectName("createCatalog") + self.horizontalLayout.addWidget(self.createCatalog) + self.verticalLayout.addLayout(self.horizontalLayout) + self.horizontalLayout_2 = QtWidgets.QHBoxLayout() + self.horizontalLayout_2.setObjectName("horizontalLayout_2") + self.label_2 = QtWidgets.QLabel(self.centralwidget) + sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.label_2.sizePolicy().hasHeightForWidth()) + self.label_2.setSizePolicy(sizePolicy) + self.label_2.setMaximumSize(QtCore.QSize(16777215, 16777215)) + font = QtGui.QFont() + font.setPointSize(14) + self.label_2.setFont(font) + self.label_2.setObjectName("label_2") + self.horizontalLayout_2.addWidget(self.label_2) + self.openCatalog = QtWidgets.QPushButton(self.centralwidget) + font = QtGui.QFont() + font.setPointSize(14) + self.openCatalog.setFont(font) + self.openCatalog.setObjectName("openCatalog") + self.horizontalLayout_2.addWidget(self.openCatalog) + self.verticalLayout.addLayout(self.horizontalLayout_2) + self.horizontalLayout_3.addLayout(self.verticalLayout) + self.verticalLayout_2.addLayout(self.horizontalLayout_3) + startWindow.setCentralWidget(self.centralwidget) + + self.retranslateUi(startWindow) + QtCore.QMetaObject.connectSlotsByName(startWindow) + + def retranslateUi(self, startWindow): + _translate = QtCore.QCoreApplication.translate + startWindow.setWindowTitle(_translate("startWindow", "Note - Start")) + self.label.setText(_translate("startWindow", "Создать каталог")) + self.createCatalog.setText(_translate("startWindow", "Создать")) + self.label_2.setText(_translate("startWindow", "Открыть каталог")) + self.openCatalog.setText(_translate("startWindow", "Открыть")) diff --git a/startWindow.ui b/startWindow.ui new file mode 100644 index 0000000..d320609 --- /dev/null +++ b/startWindow.ui @@ -0,0 +1,157 @@ + + + startWindow + + + + 0 + 0 + 800 + 600 + + + + + 0 + 0 + + + + + 800 + 600 + + + + + 800 + 600 + + + + + 800 + 600 + + + + Note - Start + + + false + + + + + + + + + + 250 + 0 + + + + + 252 + 16777215 + + + + max-width: 250 + + + + + + + 0 + + + QLayout::SetMinimumSize + + + + + + + + 16777215 + 16777215 + + + + + 14 + + + + Создать каталог + + + + + + + + 14 + + + + Создать + + + + + + + + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + + 14 + + + + Открыть каталог + + + + + + + + 14 + + + + Открыть + + + + + + + + + + + + + + +