This commit is contained in:
merelden 2024-06-11 17:08:03 +05:00
commit 15163b606e
14 changed files with 610 additions and 0 deletions

8
.idea/.gitignore vendored Normal file
View File

@ -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

8
.idea/NoteQt.iml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

7
.idea/misc.xml Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Black">
<option name="sdkName" value="Python 3.9" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9" project-jdk-type="Python SDK" />
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/NoteQt.iml" filepath="$PROJECT_DIR$/.idea/NoteQt.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml Normal file
View File

@ -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>

Binary file not shown.

Binary file not shown.

1
catalogs.json Normal file
View File

@ -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"]

179
main.py Normal file
View File

@ -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_())

60
mainWindow.py Normal file
View File

@ -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", "Новая заметка"))

77
mainWindow.ui Normal file
View File

@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="back">
<property name="text">
<string>Назад</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="createFile">
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>Новая заметка</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QListWidget" name="mainList">
<property name="maximumSize">
<size>
<width>150</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTextEdit" name="noteTitleEdit">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>30</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QTextEdit" name="noteEdit"/>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
<resources/>
<connections/>
</ui>

93
startWindow.py Normal file
View File

@ -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", "Открыть"))

157
startWindow.ui Normal file
View File

@ -0,0 +1,157 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>startWindow</class>
<widget class="QMainWindow" name="startWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>800</width>
<height>600</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>800</width>
<height>600</height>
</size>
</property>
<property name="baseSize">
<size>
<width>800</width>
<height>600</height>
</size>
</property>
<property name="windowTitle">
<string>Note - Start</string>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QListWidget" name="startWindowList">
<property name="minimumSize">
<size>
<width>250</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>252</width>
<height>16777215</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">max-width: 250</string>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetMinimumSize</enum>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="font">
<font>
<pointsize>14</pointsize>
</font>
</property>
<property name="text">
<string>Создать каталог</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="createCatalog">
<property name="font">
<font>
<pointsize>14</pointsize>
</font>
</property>
<property name="text">
<string>Создать</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="font">
<font>
<pointsize>14</pointsize>
</font>
</property>
<property name="text">
<string>Открыть каталог</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="openCatalog">
<property name="font">
<font>
<pointsize>14</pointsize>
</font>
</property>
<property name="text">
<string>Открыть</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
<resources/>
<connections/>
</ui>