From 48c98cddba1cd68b78dca5d1c1449301a74304ce Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby Date: Fri, 22 Mar 2024 17:07:13 +0100 Subject: [PATCH] Study: Switch rich text to markdown. --- src/View/MainWindow.py | 3 + src/View/Study/Window.py | 41 ++++++----- src/View/Tools/ASubWindow.py | 4 +- src/View/ui/NewStudy.ui | 137 +++++++---------------------------- 4 files changed, 54 insertions(+), 131 deletions(-) diff --git a/src/View/MainWindow.py b/src/View/MainWindow.py index 1b9ebddf..eb6fa68e 100644 --- a/src/View/MainWindow.py +++ b/src/View/MainWindow.py @@ -436,6 +436,9 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): if Modules.CONFIG in keys: self._do_update_config() + if Modules.STUDY in keys: + self._tab_widget_info.update() + logger.debug(f"Propagation of {keys}") for _, window in self.sub_win_list: window._propagated_update(key=keys) diff --git a/src/View/Study/Window.py b/src/View/Study/Window.py index a903caa7..fc7e83aa 100644 --- a/src/View/Study/Window.py +++ b/src/View/Study/Window.py @@ -16,6 +16,9 @@ # -*- coding: utf-8 -*- +import logging + +from Modules import Modules from Model.Study import Study from View.Tools.PamhyrWindow import PamhyrDialog @@ -27,11 +30,14 @@ from PyQt5.QtGui import ( from PyQt5.QtWidgets import ( QRadioButton, QLabel, QDateTimeEdit, - QTextEdit, QPushButton, + QTextEdit, QPlainTextEdit, QTextBrowser, + QPushButton, ) _translate = QCoreApplication.translate +logger = logging.getLogger() + class NewStudyWindow(PamhyrDialog): _pamhyr_ui = "NewStudy" @@ -56,8 +62,11 @@ class NewStudyWindow(PamhyrDialog): if self._study is not None: self.set_line_edit_text("lineEdit_name", self._study.name) + self.set_plaintext_edit_text( + "plainTextEdit_description", self._study.description + ) self.set_text_edit_text( - "textEdit_description", self._study.description + "textBrowser_description", self._study.description ) self.set_datetime_edit("dateTimeEdit_date", self._study.date) @@ -82,22 +91,14 @@ class NewStudyWindow(PamhyrDialog): time.toggled.connect(self.set_time) date.toggled.connect(self.set_date) - self._desc = self.find(QTextEdit, "textEdit_description") - self._bold = self.find(QPushButton, "pushButton_bold") - self._italic = self.find(QPushButton, "pushButton_italic") - self._underline = self.find(QPushButton, "pushButton_underline") - self._highlight = self.find(QPushButton, "pushButton_highlight") - - self._bold.clicked.connect( - lambda x: self._desc.setFontWeight( - QFont.Bold if x else QFont.Normal - ) - ) - self._italic.clicked.connect(self._desc.setFontItalic) - self._underline.clicked.connect(self._desc.setFontUnderline) - self._highlight.clicked.connect( - lambda x: self._desc.setTextBackgroundColor( - QColor("yellow") if x else QColor("white") + md_edit = self.find(QPlainTextEdit, "plainTextEdit_description") + #md_previou = self.find(QTextBrowser, "textBrowser_description") + md_edit.textChanged.connect( + lambda: self.set_text_edit_text( + "textBrowser_description", + self.get_plaintext_edit_text( + "plainTextEdit_description" + ) ) ) @@ -113,7 +114,8 @@ class NewStudyWindow(PamhyrDialog): def accept(self): name = self.get_line_edit_text("lineEdit_name") - description = self.get_text_edit_text("textEdit_description") + description = self.get_plaintext_edit_text("plainTextEdit_description") + logger.info(description) if self._study is None: study = Study.new(name, description) @@ -132,4 +134,5 @@ class NewStudyWindow(PamhyrDialog): else: self._study.use_time() + self._propagate_update(key=Modules.STUDY) self.done(True) diff --git a/src/View/Tools/ASubWindow.py b/src/View/Tools/ASubWindow.py index 234be532..7dc57b0d 100644 --- a/src/View/Tools/ASubWindow.py +++ b/src/View/Tools/ASubWindow.py @@ -218,7 +218,7 @@ class ASubWindowFeatures(object): Returns: Nothing """ - self.find(QTextEdit, name).setText(text) + self.find(QTextEdit, name).setMarkdown(text) def get_text_edit_text(self, name: str): """Get text of text edit component @@ -229,7 +229,7 @@ class ASubWindowFeatures(object): Returns: Text """ - return self.find(QTextEdit, name).toHtml() + return self.find(QTextEdit, name).toMarkdown() def set_plaintext_edit_text(self, name: str, text: str): """Set text of text edit component diff --git a/src/View/ui/NewStudy.ui b/src/View/ui/NewStudy.ui index 680e9e2b..f257dc5f 100644 --- a/src/View/ui/NewStudy.ui +++ b/src/View/ui/NewStudy.ui @@ -48,117 +48,34 @@ - - - Qt::Horizontal - - - - - - - - - - 32 - 16777215 - - - - - 75 - true - - - - B - - - true - - - - - - - - 32 - 16777215 - - - - - true - - - - I - - - true - - - - - - - - 32 - 16777215 - - - - - true - - - - U - - - true - - - - - - - Highlight - - - true - - - true - - - false - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - false - - - false + + + 0 + + + Markdown + + + + + + false + + + + + + + + Preview + + + + + + +