diff --git a/main.py b/main.py
index 8a4c87d..11d7f49 100644
--- a/main.py
+++ b/main.py
@@ -1,10 +1,13 @@
import sys
import os
import json
-from PyQt5.QtWidgets import QApplication, QMainWindow, QFileDialog, QListWidgetItem, QLabel, QDesktopWidget
-from PyQt5.QtCore import QDir, QFileSystemWatcher
+from PyQt6.QtWidgets import QApplication, QMainWindow, QFileDialog, QListWidgetItem, QLabel
+from PyQt6.QtCore import QDir, QFileSystemWatcher, Qt
+from PyQt6.QtGui import QGuiApplication
from startWindow import Ui_startWindow as Ui_StartWindow
from mainWindow import Ui_MainWindow as Ui_MainWindow2
+from qt_markdown.qt_markdown import QtMarkDown
+
CONFIG_FILE = "catalogs.json"
@@ -23,10 +26,11 @@ class StartWindow(QMainWindow):
self.load_catalogs()
def window_center(self):
- qr = self.frameGeometry()
- cp = QDesktopWidget().availableGeometry().center()
- qr.moveCenter(cp)
- self.move(qr.topLeft())
+ screen = QGuiApplication.primaryScreen()
+ screen_geometry = screen.geometry()
+ window_geometry = self.frameGeometry()
+ window_geometry.moveCenter(screen_geometry.center())
+ self.move(window_geometry.topLeft())
def create_catalog(self):
folder_path = QFileDialog.getSaveFileName(self, "Create New Catalog", "", "All Files (*);;Directory")[0]
@@ -88,6 +92,7 @@ class MainWindow(QMainWindow):
self.create_file()
self.ui.noteTitleEdit.textChanged.connect(self.save_note_title)
self.ui.noteEdit.textChanged.connect(self.save_note_content)
+ self.show_note_edit_and_toolbar()
else:
self.show_default_label()
@@ -97,6 +102,9 @@ class MainWindow(QMainWindow):
self.file_watcher.addPath(self.folder_path)
self.file_watcher.directoryChanged.connect(self.show_directory_files)
+ self.qt_markdown = QtMarkDown(self.ui.noteEdit)
+
+
def load_selected_note(self, item):
note_name = item.text()
self.default_note_path = os.path.join(self.folder_path, note_name)
@@ -104,9 +112,23 @@ class MainWindow(QMainWindow):
self.ui.noteTitleEdit.setPlainText(note_name)
self.ui.noteTitleEdit.show()
self.ui.noteEdit.show()
+ self.show_note_edit_and_toolbar()
+
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 show_note_edit_and_toolbar(self):
+ if not hasattr(self, 'toolbar'):
+ self.qt_markdown = QtMarkDown(self.ui.noteEdit)
+ self.toolbar = self.qt_markdown.get_toolbar()
+
+ self.ui.noteEdit.show()
+ self.ui.verticalLayout.insertWidget(0, self.toolbar)
+
def create_file(self):
base_name = "Без_Имени"
extension = ".md"
@@ -152,7 +174,7 @@ class MainWindow(QMainWindow):
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)
+ dir_content = QDir(self.folder_path).entryList(QDir.Filter.Files)
for file_name in dir_content:
item = QListWidgetItem(file_name)
self.ui.mainList.addItem(item)
@@ -160,6 +182,8 @@ class MainWindow(QMainWindow):
def show_default_label(self):
self.ui.noteTitleEdit.hide()
self.ui.noteEdit.hide()
+ if hasattr(self, 'toolbar'):
+ self.toolbar.hide()
if not hasattr(self, 'static_label'):
self.static_label = QLabel("Выберите файл из списка или создайте новый")
@@ -176,4 +200,4 @@ if __name__ == "__main__":
app = QApplication(sys.argv)
start_window = StartWindow()
start_window.show()
- sys.exit(app.exec_())
+ sys.exit(app.exec())
diff --git a/mainWindow.py b/mainWindow.py
index 76495d2..f771822 100644
--- a/mainWindow.py
+++ b/mainWindow.py
@@ -1,30 +1,28 @@
-# -*- coding: utf-8 -*-
-
-# Form implementation generated from reading ui file '/home/merelden/Документы/NoteQt/mainWindow.ui'
+# Form implementation generated from reading ui file '/home/evgeniy/Документы/Note_Qt/mainWindow.ui'
#
-# Created by: PyQt5 UI code generator 5.15.10
+# Created by: PyQt6 UI code generator 6.7.0
#
-# WARNING: Any manual changes made to this file will be lost when pyuic5 is
+# WARNING: Any manual changes made to this file will be lost when pyuic6 is
# run again. Do not edit this file unless you know what you are doing.
-from PyQt5 import QtCore, QtGui, QtWidgets
+from PyQt6 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 = QtWidgets.QWidget(parent=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 = QtWidgets.QPushButton(parent=self.centralwidget)
self.back.setObjectName("back")
self.horizontalLayout.addWidget(self.back)
- self.createFile = QtWidgets.QPushButton(self.centralwidget)
+ self.createFile = QtWidgets.QPushButton(parent=self.centralwidget)
font = QtGui.QFont()
font.setPointSize(10)
self.createFile.setFont(font)
@@ -33,17 +31,17 @@ class Ui_MainWindow(object):
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 = QtWidgets.QListWidget(parent=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 = QtWidgets.QTextEdit(parent=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 = QtWidgets.QTextEdit(parent=self.centralwidget)
self.noteEdit.setObjectName("noteEdit")
self.verticalLayout.addWidget(self.noteEdit)
self.horizontalLayout_2.addLayout(self.verticalLayout)
diff --git a/qt_markdown/__init__.py b/qt_markdown/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/qt_markdown/__pycache__/__init__.cpython-39.pyc b/qt_markdown/__pycache__/__init__.cpython-39.pyc
new file mode 100644
index 0000000..ae3daea
Binary files /dev/null and b/qt_markdown/__pycache__/__init__.cpython-39.pyc differ
diff --git a/qt_markdown/__pycache__/qt_markdown.cpython-39.pyc b/qt_markdown/__pycache__/qt_markdown.cpython-39.pyc
new file mode 100644
index 0000000..3937f79
Binary files /dev/null and b/qt_markdown/__pycache__/qt_markdown.cpython-39.pyc differ
diff --git a/qt_markdown/qt_markdown.py b/qt_markdown/qt_markdown.py
new file mode 100644
index 0000000..4a7a594
--- /dev/null
+++ b/qt_markdown/qt_markdown.py
@@ -0,0 +1,10 @@
+from .text_formatter.text_formatter import TextFormatter
+from .toolbar.toolbar import FormattingToolbar
+
+class QtMarkDown:
+ def __init__(self, text_edit):
+ self.text_formatter = TextFormatter(text_edit)
+ self.toolbar = FormattingToolbar(self.text_formatter)
+
+ def get_toolbar(self):
+ return self.toolbar
\ No newline at end of file
diff --git a/qt_markdown/text_formatter/__init__.py b/qt_markdown/text_formatter/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/qt_markdown/text_formatter/__pycache__/__init__.cpython-39.pyc b/qt_markdown/text_formatter/__pycache__/__init__.cpython-39.pyc
new file mode 100644
index 0000000..b2499e6
Binary files /dev/null and b/qt_markdown/text_formatter/__pycache__/__init__.cpython-39.pyc differ
diff --git a/qt_markdown/text_formatter/__pycache__/header_formatter.cpython-39.pyc b/qt_markdown/text_formatter/__pycache__/header_formatter.cpython-39.pyc
new file mode 100644
index 0000000..dd7e7bb
Binary files /dev/null and b/qt_markdown/text_formatter/__pycache__/header_formatter.cpython-39.pyc differ
diff --git a/qt_markdown/text_formatter/__pycache__/text_formatter.cpython-39.pyc b/qt_markdown/text_formatter/__pycache__/text_formatter.cpython-39.pyc
new file mode 100644
index 0000000..cf117ae
Binary files /dev/null and b/qt_markdown/text_formatter/__pycache__/text_formatter.cpython-39.pyc differ
diff --git a/qt_markdown/text_formatter/__pycache__/text_style_formatter.cpython-39.pyc b/qt_markdown/text_formatter/__pycache__/text_style_formatter.cpython-39.pyc
new file mode 100644
index 0000000..71860bf
Binary files /dev/null and b/qt_markdown/text_formatter/__pycache__/text_style_formatter.cpython-39.pyc differ
diff --git a/qt_markdown/text_formatter/header_formatter.py b/qt_markdown/text_formatter/header_formatter.py
new file mode 100644
index 0000000..9642307
--- /dev/null
+++ b/qt_markdown/text_formatter/header_formatter.py
@@ -0,0 +1,45 @@
+from PyQt6.QtGui import QTextCharFormat, QFont, QTextCursor
+from PyQt6.QtCore import QRegularExpression
+
+class HeaderFormatter:
+ def __init__(self):
+ self.regex_h1 = QRegularExpression(r'^#\s(.+)$')
+ self.regex_h2 = QRegularExpression(r'^##\s(.+)$')
+ self.regex_h3 = QRegularExpression(r'^###\s(.+)$')
+ self.regex_h4 = QRegularExpression(r'^####\s(.+)$')
+ self.regex_h5 = QRegularExpression(r'^#####\s(.+)$')
+ self.regex_h6 = QRegularExpression(r'^######\s(.+)$')
+
+ def apply_header_format(self, block, font_size, font_weight):
+ cursor = QTextCursor(block)
+ char_format = QTextCharFormat()
+ char_format.setFontWeight(font_weight)
+ char_format.setFontPointSize(font_size * 16)
+ cursor.select(QTextCursor.SelectionType.BlockUnderCursor)
+ cursor.setCharFormat(char_format)
+
+ def clear_header_format(self, block):
+ cursor = QTextCursor(block)
+ char_format = QTextCharFormat()
+ cursor.select(QTextCursor.SelectionType.BlockUnderCursor)
+ cursor.setCharFormat(char_format)
+
+ def process_headers(self, text_edit):
+ block = text_edit.document().firstBlock()
+ while block.isValid():
+ text = block.text()
+ if self.regex_h1.match(text).hasMatch():
+ self.apply_header_format(block, 2.0, QFont.Weight.Bold)
+ elif self.regex_h2.match(text).hasMatch():
+ self.apply_header_format(block, 1.5, QFont.Weight.Bold)
+ elif self.regex_h3.match(text).hasMatch():
+ self.apply_header_format(block, 1.25, QFont.Weight.Bold)
+ elif self.regex_h4.match(text).hasMatch():
+ self.apply_header_format(block, 1.0, QFont.Weight.Bold)
+ elif self.regex_h5.match(text).hasMatch():
+ self.apply_header_format(block, 0.875, QFont.Weight.Bold)
+ elif self.regex_h6.match(text).hasMatch():
+ self.apply_header_format(block, 0.85, QFont.Weight.Bold)
+ else:
+ self.clear_header_format(block)
+ block = block.next()
\ No newline at end of file
diff --git a/qt_markdown/text_formatter/text_formatter.py b/qt_markdown/text_formatter/text_formatter.py
new file mode 100644
index 0000000..eb86853
--- /dev/null
+++ b/qt_markdown/text_formatter/text_formatter.py
@@ -0,0 +1,69 @@
+from PyQt6.QtWidgets import QTextEdit
+from PyQt6.QtCore import QTimer, QDir, QUrl, QVariant, Qt
+from PyQt6.QtGui import QTextCharFormat, QFont, QTextCursor, QTextImageFormat, QImage, QTextDocument, QTextBlockFormat
+from .header_formatter import HeaderFormatter
+from .text_style_formatter import TextStyleFormatter
+
+class TextFormatter:
+ def __init__(self, text_edit: QTextEdit):
+ self.text_edit = text_edit
+ self.timer = QTimer()
+ self.timer.setSingleShot(True)
+ self.timer.timeout.connect(self.process_text_changes)
+ self.text_edit.textChanged.connect(self.delay_text)
+
+ self.header_formatter = HeaderFormatter()
+ self.text_style_formatter = TextStyleFormatter()
+
+ def delay_text(self):
+ self.timer.start(500)
+
+ def process_text_changes(self):
+ cursor = self.text_edit.textCursor()
+ cursor.beginEditBlock()
+ cursor.select(QTextCursor.SelectionType.Document)
+ cursor.setCharFormat(QTextCharFormat())
+
+ self.header_formatter.process_headers(self.text_edit)
+ self.text_style_formatter.apply_text_formatting(cursor, self.text_edit.toPlainText())
+ self.process_markdown_images(cursor, self.text_edit.toPlainText())
+
+ cursor.endEditBlock()
+
+ def toggle_special_symbols(self, symbol_start, symbol_end=None):
+ cursor = self.text_edit.textCursor()
+ if cursor.hasSelection():
+ selected_text = cursor.selectedText()
+ full_text = self.text_edit.toPlainText()
+ start = cursor.selectionStart()
+ end = cursor.selectionEnd()
+ corrected_text, new_start, new_end = self._toggle_special_symbols_in_selection(full_text, start, end, symbol_start, symbol_end)
+ self.text_edit.setPlainText(corrected_text)
+ cursor.setPosition(new_start)
+ cursor.setPosition(new_end, QTextCursor.MoveMode.KeepAnchor)
+ self.text_edit.setTextCursor(cursor)
+ else:
+ cursor.select(QTextCursor.SelectionType.WordUnderCursor)
+ word = cursor.selectedText()
+ full_text = self.text_edit.toPlainText()
+ start = cursor.selectionStart()
+ end = cursor.selectionEnd()
+ corrected_text, new_start, new_end = self._toggle_special_symbols_in_selection(full_text, start, end, symbol_start, symbol_end)
+ self.text_edit.setPlainText(corrected_text)
+ cursor.setPosition(new_start)
+ cursor.setPosition(new_end, QTextCursor.MoveMode.KeepAnchor)
+ self.text_edit.setTextCursor(cursor)
+
+ def _toggle_special_symbols_in_selection(self, text, start, end, symbol_start, symbol_end=None):
+ if symbol_end is None:
+ symbol_end = symbol_start
+ if text[start - len(symbol_start):start] == symbol_start and text[end:end + len(symbol_end)] == symbol_end:
+ corrected_text = text[:start - len(symbol_start)] + text[start:end] + text[end + len(symbol_end):]
+ new_start = start - len(symbol_start)
+ new_end = end - len(symbol_start)
+ return corrected_text, new_start, new_end
+ else:
+ corrected_text = text[:start] + symbol_start + text[start:end] + symbol_end + text[end:]
+ new_start = start + len(symbol_start)
+ new_end = end + len(symbol_end)
+ return corrected_text, new_start, new_end
\ No newline at end of file
diff --git a/qt_markdown/text_formatter/text_style_formatter.py b/qt_markdown/text_formatter/text_style_formatter.py
new file mode 100644
index 0000000..a453144
--- /dev/null
+++ b/qt_markdown/text_formatter/text_style_formatter.py
@@ -0,0 +1,92 @@
+from PyQt6.QtGui import QTextCharFormat, QFont, QTextCursor
+from PyQt6.QtCore import QRegularExpression
+
+class TextStyleFormatter:
+ def __init__(self):
+ self.regex_bold_italic = QRegularExpression(r'\*{3}([^\*]+)\*{3}')
+ self.regex_bold = QRegularExpression(r'\*{2}([^\*]+?)\*{2}')
+ self.regex_italic = QRegularExpression(r'\*([^\*]+?)\*')
+ self.regex_stroke = QRegularExpression(r'~~([^\~]+?)~~')
+ self.regex_underline = QRegularExpression(r'([^<]+?)')
+
+ def apply_text_formatting(self, cursor, text):
+ # Process bold and italic text
+ pos = 0
+ bold_italic_positions = []
+ while (match := self.regex_bold_italic.match(text, pos)).hasMatch():
+ match_len = match.capturedLength()
+ start = match.capturedStart(0) + 3 # Start of text between asterisks
+ end = start + match_len - 6 # End of text between asterisks
+
+ bold_italic_positions.append((start, end))
+
+ cursor.setPosition(start)
+ cursor.movePosition(QTextCursor.MoveOperation.Right, QTextCursor.MoveMode.KeepAnchor, match_len - 6)
+
+ char_format = QTextCharFormat()
+ char_format.setFontWeight(QFont.Weight.Bold)
+ char_format.setFontItalic(True)
+ cursor.mergeCharFormat(char_format)
+
+ pos = match.capturedEnd(0)
+
+ # Process bold text
+ pos = 0
+ bold_positions = []
+ while (match := self.regex_bold.match(text, pos)).hasMatch():
+ match_len = match.capturedLength()
+ start = match.capturedStart(0) + 2 # Start of text between asterisks
+ end = start + match_len - 4 # End of text between asterisks
+
+ if not any(start < bi_end and end > bi_start for bi_start, bi_end in bold_italic_positions):
+ bold_positions.append((start, end))
+
+ cursor.setPosition(start)
+ cursor.movePosition(QTextCursor.MoveOperation.Right, QTextCursor.MoveMode.KeepAnchor, match_len - 4)
+
+ char_format = QTextCharFormat()
+ char_format.setFontWeight(QFont.Weight.Bold)
+ cursor.mergeCharFormat(char_format)
+
+ pos = match.capturedEnd(0)
+
+ # Process italic text
+ pos = 0
+ while (match := self.regex_italic.match(text, pos)).hasMatch():
+ match_len = match.capturedLength()
+ start = match.capturedStart(0) + 1 # Start of text between asterisks
+ end = start + match_len - 2 # End of text between asterisks
+
+ # Check for overlap with bold or bold and italic text
+ if not any(start < b_end and end > b_start for b_start, b_end in bold_positions) and \
+ not any(start < bi_end and end > bi_start for bi_start, bi_end in bold_italic_positions):
+ cursor.setPosition(start)
+ cursor.movePosition(QTextCursor.MoveOperation.Right, QTextCursor.MoveMode.KeepAnchor, match_len - 2)
+
+ char_format = QTextCharFormat()
+ char_format.setFontItalic(True)
+ cursor.mergeCharFormat(char_format)
+
+ pos = match.capturedEnd(0)
+
+ pos = 0
+ while (match := self.regex_stroke.match(text, pos)).hasMatch():
+ start = match.capturedStart(1)
+ end = match.capturedEnd(1)
+ cursor.setPosition(start)
+ cursor.movePosition(QTextCursor.MoveOperation.Right, QTextCursor.MoveMode.KeepAnchor, end - start)
+ char_format = QTextCharFormat()
+ char_format.setFontStrikeOut(True)
+ cursor.mergeCharFormat(char_format)
+ pos = match.capturedEnd(0)
+
+ pos = 0
+ while (match := self.regex_underline.match(text, pos)).hasMatch():
+ start = match.capturedStart(1)
+ end = match.capturedEnd(1)
+ cursor.setPosition(start)
+ cursor.movePosition(QTextCursor.MoveOperation.Right, QTextCursor.MoveMode.KeepAnchor, end - start)
+ char_format = QTextCharFormat()
+ char_format.setFontUnderline(True)
+ cursor.mergeCharFormat(char_format)
+ pos = match.capturedEnd(0)
\ No newline at end of file
diff --git a/qt_markdown/toolbar/__init__.py b/qt_markdown/toolbar/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/qt_markdown/toolbar/__pycache__/__init__.cpython-39.pyc b/qt_markdown/toolbar/__pycache__/__init__.cpython-39.pyc
new file mode 100644
index 0000000..3165a2b
Binary files /dev/null and b/qt_markdown/toolbar/__pycache__/__init__.cpython-39.pyc differ
diff --git a/qt_markdown/toolbar/__pycache__/toolbar.cpython-39.pyc b/qt_markdown/toolbar/__pycache__/toolbar.cpython-39.pyc
new file mode 100644
index 0000000..b1d9351
Binary files /dev/null and b/qt_markdown/toolbar/__pycache__/toolbar.cpython-39.pyc differ
diff --git a/qt_markdown/toolbar/toolbar.py b/qt_markdown/toolbar/toolbar.py
new file mode 100644
index 0000000..d6b3456
--- /dev/null
+++ b/qt_markdown/toolbar/toolbar.py
@@ -0,0 +1,94 @@
+from PyQt6.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QPushButton, QComboBox
+from PyQt6.QtGui import QTextCharFormat, QFont, QTextCursor
+
+class FormattingToolbar(QWidget):
+ def __init__(self, formatter):
+ super().__init__()
+ self.formatter = formatter
+ self.init_ui()
+
+ def init_ui(self):
+ layout = QVBoxLayout()
+ toolbar_layout = QHBoxLayout()
+
+ self.button_bold = QPushButton("Ж")
+ self.button_bold.setStyleSheet("font-weight: bold;")
+ self.button_bold.clicked.connect(lambda: self.formatter.toggle_special_symbols('**'))
+
+ self.button_italic = QPushButton("К")
+ self.button_italic.setStyleSheet("font-style: italic;")
+ self.button_italic.clicked.connect(lambda: self.formatter.toggle_special_symbols('*'))
+
+ self.button_strike = QPushButton("abc")
+ self.button_strike.setStyleSheet("text-decoration: line-through;")
+ self.button_strike.clicked.connect(lambda: self.formatter.toggle_special_symbols('~~'))
+
+ self.button_underline = QPushButton("Ч")
+ self.button_underline.setStyleSheet("text-decoration: underline;")
+ self.button_underline.clicked.connect(lambda: self.formatter.toggle_special_symbols('', ''))
+
+ self.button_header1 = QPushButton("H1")
+ self.button_header1.clicked.connect(self.insert_header1)
+
+ self.button_header2 = QPushButton("H2")
+ self.button_header2.clicked.connect(self.insert_header2)
+
+ self.header_drop = QComboBox()
+ self.header_drop.addItems(["H1", "H2", "H3", "H4", "H5", "H6"])
+ self.header_drop.currentIndexChanged.connect(self.handle_header_drop)
+
+
+ toolbar_layout.addWidget(self.button_bold)
+ toolbar_layout.addWidget(self.button_italic)
+ toolbar_layout.addWidget(self.button_strike)
+ toolbar_layout.addWidget(self.button_underline)
+ toolbar_layout.addWidget(self.button_header1)
+ toolbar_layout.addWidget(self.button_header2)
+ toolbar_layout.addWidget(self.header_drop)
+
+
+ layout.addLayout(toolbar_layout)
+ self.setLayout(layout)
+
+ def insert_header1(self):
+ self.insert_header('# ')
+
+ def insert_header2(self):
+ self.insert_header('## ')
+
+ def insert_header(self, header_symbol):
+ cursor = self.formatter.text_edit.textCursor()
+ cursor.beginEditBlock()
+
+ # Get selected text or word under cursor
+ cursor.select(QTextCursor.SelectionType.WordUnderCursor)
+ selected_text = cursor.selectedText()
+
+ # Check if there's already a header symbol at the beginning
+ cursor.movePosition(QTextCursor.MoveOperation.StartOfLine)
+ cursor.select(QTextCursor.SelectionType.LineUnderCursor)
+ line_text = cursor.selectedText().strip()
+
+ if line_text.startswith('#'):
+ # Remove existing header symbol and space
+ line_text = line_text.replace('#', '', 1).lstrip()
+
+ if selected_text:
+ # Replace the selected text with the header symbol + selected text
+ cursor.removeSelectedText()
+ cursor.insertText(header_symbol + selected_text)
+ else:
+ # If no word is selected, just insert the header symbol
+ cursor.insertText(header_symbol)
+
+ cursor.endEditBlock()
+
+ def handle_header_drop(self, index):
+ header_level = index + 1 # Since index starts from 0, but header levels start from 1
+ header_symbol = '#' * header_level + ' '
+
+ # Set the correct index in the headerDrop ComboBox
+ self.header_drop.setCurrentIndex(index)
+
+ # Call insert_header with the header_symbol
+ self.insert_header(header_symbol)
\ No newline at end of file
diff --git a/startWindow.py b/startWindow.py
index f240fb9..11f75b2 100644
--- a/startWindow.py
+++ b/startWindow.py
@@ -1,21 +1,19 @@
-# -*- coding: utf-8 -*-
-
-# Form implementation generated from reading ui file '/home/merelden/Документы/NoteQt/startWindow.ui'
+# Form implementation generated from reading ui file '/home/evgeniy/Документы/Note_Qt/startWindow.ui'
#
-# Created by: PyQt5 UI code generator 5.15.10
+# Created by: PyQt6 UI code generator 6.7.0
#
-# WARNING: Any manual changes made to this file will be lost when pyuic5 is
+# WARNING: Any manual changes made to this file will be lost when pyuic6 is
# run again. Do not edit this file unless you know what you are doing.
-from PyQt5 import QtCore, QtGui, QtWidgets
+from PyQt6 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 = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Fixed, QtWidgets.QSizePolicy.Policy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(startWindow.sizePolicy().hasHeightForWidth())
@@ -24,32 +22,32 @@ class Ui_startWindow(object):
startWindow.setMaximumSize(QtCore.QSize(800, 600))
startWindow.setBaseSize(QtCore.QSize(800, 600))
startWindow.setAutoFillBackground(False)
- self.centralwidget = QtWidgets.QWidget(startWindow)
+ self.centralwidget = QtWidgets.QWidget(parent=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 = QtWidgets.QListWidget(parent=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.setSizeConstraint(QtWidgets.QLayout.SizeConstraint.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 = QtWidgets.QLabel(parent=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)
+ self.createCatalog = QtWidgets.QPushButton(parent=self.centralwidget)
font = QtGui.QFont()
font.setPointSize(14)
self.createCatalog.setFont(font)
@@ -58,8 +56,8 @@ class Ui_startWindow(object):
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)
+ self.label_2 = QtWidgets.QLabel(parent=self.centralwidget)
+ sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Preferred, QtWidgets.QSizePolicy.Policy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.label_2.sizePolicy().hasHeightForWidth())
@@ -70,7 +68,7 @@ class Ui_startWindow(object):
self.label_2.setFont(font)
self.label_2.setObjectName("label_2")
self.horizontalLayout_2.addWidget(self.label_2)
- self.openCatalog = QtWidgets.QPushButton(self.centralwidget)
+ self.openCatalog = QtWidgets.QPushButton(parent=self.centralwidget)
font = QtGui.QFont()
font.setPointSize(14)
self.openCatalog.setFont(font)