From fab5833cdf7cf20e4c87352e85275088243c45e7 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Mon, 25 Jan 2021 23:05:41 +0100 Subject: [PATCH] Add degree, times and divide symbols to insert menu, and simply the editor insert function --- nw/constants/constants.py | 8 ++++- nw/constants/enum.py | 25 ++++----------- nw/gui/custom.py | 2 +- nw/gui/doceditor.py | 26 --------------- nw/gui/mainmenu.py | 50 +++++++++++++++++++++-------- nw/guimain.py | 3 ++ tests/test_gui/test_gui_mainmenu.py | 12 +++++++ 7 files changed, 65 insertions(+), 61 deletions(-) diff --git a/nw/constants/constants.py b/nw/constants/constants.py index 87ff02b7..8bafd764 100644 --- a/nw/constants/constants.py +++ b/nw/constants/constants.py @@ -287,10 +287,13 @@ class nwUnicode: ## Symbols U_CHECK = "\u2714" # Heavy check mark - U_MULT = "\u2715" # Multiplication x + U_CROSS = "\u2715" # Heavy cross mark U_BULL = "\u2022" # List bullet U_FLOWER = "\u2055" # Flower punctuation mark U_PERMIL = "\u2030" # Per mille sign + U_DEGREE = "\u00b0" # Degree symbol + U_TIMES = "\u00d7" # Multiplaction sign + U_DIVIDE = "\u00f7" # Division sign ## Arrows U_UTRI = "\u25b2" # Up-pointing triangle @@ -348,6 +351,9 @@ class nwUnicode: H_BULL = "•" H_FLOWER = "⁕" H_PERMIL = "‰" + H_DEGREE = "°" + H_TIMES = "×" + H_DIVIDE = "÷" ## Arrows H_UTRI = "▲" diff --git a/nw/constants/enum.py b/nw/constants/enum.py index 6ed97d39..3e343f14 100644 --- a/nw/constants/enum.py +++ b/nw/constants/enum.py @@ -99,25 +99,12 @@ class nwDocAction(Enum): class nwDocInsert(Enum): - NO_INSERT = 0 - HARD_BREAK = 1 - NB_SPACE = 2 - THIN_SPACE = 3 - THIN_NB_SPACE = 4 - SHORT_DASH = 5 - LONG_DASH = 6 - ELLIPSIS = 7 - QUOTE_LS = 8 - QUOTE_RS = 9 - QUOTE_LD = 10 - QUOTE_RD = 11 - MODAPOS_S = 12 - FIGURE_DASH = 13 - LIST_BULLET = 14 - PER_MILLE = 15 - SINGLE_PRIME = 16 - DOUBLE_PRIME = 17 - FLOWER_MARK = 18 + NO_INSERT = 0 + HARD_BREAK = 1 + QUOTE_LS = 2 + QUOTE_RS = 3 + QUOTE_LD = 4 + QUOTE_RD = 5 # END Enum nwDocInsert diff --git a/nw/gui/custom.py b/nw/gui/custom.py index 0f989578..303a5ae1 100644 --- a/nw/gui/custom.py +++ b/nw/gui/custom.py @@ -303,7 +303,7 @@ class QSwitch(QAbstractButton): trackBrush = qPalette.dark() thumbBrush = qPalette.light() textColor = qPalette.dark().color() - thumbText = nwUnicode.U_MULT + thumbText = nwUnicode.U_CROSS if self.isEnabled(): trackOpacity = 1.0 diff --git a/nw/gui/doceditor.py b/nw/gui/doceditor.py index 784ea5d1..b3709420 100644 --- a/nw/gui/doceditor.py +++ b/nw/gui/doceditor.py @@ -734,26 +734,6 @@ class GuiDocEditor(QTextEdit): elif isinstance(theInsert, nwDocInsert): if theInsert == nwDocInsert.HARD_BREAK: theText = " \n" - elif theInsert == nwDocInsert.NB_SPACE: - theText = nwUnicode.U_NBSP - elif theInsert == nwDocInsert.THIN_SPACE: - theText = nwUnicode.U_THSP - elif theInsert == nwDocInsert.THIN_NB_SPACE: - theText = nwUnicode.U_THNBSP - elif theInsert == nwDocInsert.SHORT_DASH: - theText = nwUnicode.U_ENDASH - elif theInsert == nwDocInsert.LONG_DASH: - theText = nwUnicode.U_EMDASH - elif theInsert == nwDocInsert.FIGURE_DASH: - theText = nwUnicode.U_FGDASH - elif theInsert == nwDocInsert.MODAPOS_S: - theText = nwUnicode.U_MAPOSS - elif theInsert == nwDocInsert.ELLIPSIS: - theText = nwUnicode.U_HELLIP - elif theInsert == nwDocInsert.SINGLE_PRIME: - theText = nwUnicode.U_PRIME - elif theInsert == nwDocInsert.DOUBLE_PRIME: - theText = nwUnicode.U_DPRIME elif theInsert == nwDocInsert.QUOTE_LS: theText = self.typSQOpen elif theInsert == nwDocInsert.QUOTE_RS: @@ -762,12 +742,6 @@ class GuiDocEditor(QTextEdit): theText = self.typDQOpen elif theInsert == nwDocInsert.QUOTE_RD: theText = self.typDQClose - elif theInsert == nwDocInsert.LIST_BULLET: - theText = nwUnicode.U_BULL - elif theInsert == nwDocInsert.FLOWER_MARK: - theText = nwUnicode.U_FLOWER - elif theInsert == nwDocInsert.PER_MILLE: - theText = nwUnicode.U_PERMIL else: return False else: diff --git a/nw/gui/mainmenu.py b/nw/gui/mainmenu.py index 8ea2ae2a..924a67a1 100644 --- a/nw/gui/mainmenu.py +++ b/nw/gui/mainmenu.py @@ -32,7 +32,8 @@ from PyQt5.QtGui import QDesktopServices from PyQt5.QtWidgets import QMenuBar, QAction from nw.constants import ( - nwItemType, nwItemClass, nwDocAction, nwDocInsert, nwKeyWords, nwLabels + nwItemType, nwItemClass, nwDocAction, nwDocInsert, nwKeyWords, nwLabels, + nwUnicode ) logger = logging.getLogger(__name__) @@ -518,21 +519,21 @@ class GuiMainMenu(QMenuBar): self.aInsENDash = QAction("Short Dash", self) self.aInsENDash.setStatusTip("Insert short dash") self.aInsENDash.setShortcut("Ctrl+K, -") - self.aInsENDash.triggered.connect(lambda: self._docInsert(nwDocInsert.SHORT_DASH)) + self.aInsENDash.triggered.connect(lambda: self._docInsert(nwUnicode.U_ENDASH)) self.mInsDashes.addAction(self.aInsENDash) # Insert > Long Dash self.aInsEMDash = QAction("Long Dash", self) self.aInsEMDash.setStatusTip("Insert long dash") self.aInsEMDash.setShortcut("Ctrl+K, _") - self.aInsEMDash.triggered.connect(lambda: self._docInsert(nwDocInsert.LONG_DASH)) + self.aInsEMDash.triggered.connect(lambda: self._docInsert(nwUnicode.U_EMDASH)) self.mInsDashes.addAction(self.aInsEMDash) # Insert > Figure Dash self.aInsFigDash = QAction("Figure Dash", self) self.aInsFigDash.setStatusTip("Insert figure dash (same width as a number character)") self.aInsFigDash.setShortcut("Ctrl+K, ~") - self.aInsFigDash.triggered.connect(lambda: self._docInsert(nwDocInsert.FIGURE_DASH)) + self.aInsFigDash.triggered.connect(lambda: self._docInsert(nwUnicode.U_FGDASH)) self.mInsDashes.addAction(self.aInsFigDash) # Insert > Quote Marks @@ -570,7 +571,7 @@ class GuiMainMenu(QMenuBar): self.aInsMSApos = QAction("Alternative Apostrophe", self) self.aInsMSApos.setStatusTip("Insert modifier letter single apostrophe") self.aInsMSApos.setShortcut("Ctrl+K, '") - self.aInsMSApos.triggered.connect(lambda: self._docInsert(nwDocInsert.MODAPOS_S)) + self.aInsMSApos.triggered.connect(lambda: self._docInsert(nwUnicode.U_MAPOSS)) self.mInsQuotes.addAction(self.aInsMSApos) # Insert > Symbols @@ -580,21 +581,21 @@ class GuiMainMenu(QMenuBar): self.aInsEllipsis = QAction("Ellipsis", self) self.aInsEllipsis.setStatusTip("Insert ellipsis") self.aInsEllipsis.setShortcut("Ctrl+K, .") - self.aInsEllipsis.triggered.connect(lambda: self._docInsert(nwDocInsert.ELLIPSIS)) + self.aInsEllipsis.triggered.connect(lambda: self._docInsert(nwUnicode.U_HELLIP)) self.mInsPunct.addAction(self.aInsEllipsis) # Insert > Prime self.aInsPrime = QAction("Prime", self) self.aInsPrime.setStatusTip("Insert a prime symbol") self.aInsPrime.setShortcut("Ctrl+K, Ctrl+'") - self.aInsPrime.triggered.connect(lambda: self._docInsert(nwDocInsert.SINGLE_PRIME)) + self.aInsPrime.triggered.connect(lambda: self._docInsert(nwUnicode.U_PRIME)) self.mInsPunct.addAction(self.aInsPrime) # Insert > Double Prime self.aInsDPrime = QAction("Double Prime", self) self.aInsDPrime.setStatusTip("Insert a double prime symbol") self.aInsDPrime.setShortcut("Ctrl+K, Ctrl+\"") - self.aInsDPrime.triggered.connect(lambda: self._docInsert(nwDocInsert.DOUBLE_PRIME)) + self.aInsDPrime.triggered.connect(lambda: self._docInsert(nwUnicode.U_DPRIME)) self.mInsPunct.addAction(self.aInsDPrime) # Insert > Breaks and Spaces @@ -611,21 +612,21 @@ class GuiMainMenu(QMenuBar): self.aInsNBSpace = QAction("Non-Breaking Space", self) self.aInsNBSpace.setStatusTip("Insert a non-breaking space") self.aInsNBSpace.setShortcut("Ctrl+K, Space") - self.aInsNBSpace.triggered.connect(lambda: self._docInsert(nwDocInsert.NB_SPACE)) + self.aInsNBSpace.triggered.connect(lambda: self._docInsert(nwUnicode.U_NBSP)) self.mInsBreaks.addAction(self.aInsNBSpace) # Insert > Thin Space self.aInsThinSpace = QAction("Thin Space", self) self.aInsThinSpace.setStatusTip("Insert a thin space") self.aInsThinSpace.setShortcut("Ctrl+K, Shift+Space") - self.aInsThinSpace.triggered.connect(lambda: self._docInsert(nwDocInsert.THIN_SPACE)) + self.aInsThinSpace.triggered.connect(lambda: self._docInsert(nwUnicode.U_THSP)) self.mInsBreaks.addAction(self.aInsThinSpace) # Insert > Thin Non-Breaking Space self.aInsThinNBSpace = QAction("Thin Non-Breaking Space", self) self.aInsThinNBSpace.setStatusTip("Insert a thin non-breaking space") self.aInsThinNBSpace.setShortcut("Ctrl+K, Ctrl+Space") - self.aInsThinNBSpace.triggered.connect(lambda: self._docInsert(nwDocInsert.THIN_NB_SPACE)) + self.aInsThinNBSpace.triggered.connect(lambda: self._docInsert(nwUnicode.U_THNBSP)) self.mInsBreaks.addAction(self.aInsThinNBSpace) # Insert > Symbols @@ -635,23 +636,44 @@ class GuiMainMenu(QMenuBar): self.aInsBullet = QAction("List Bullet", self) self.aInsBullet.setStatusTip("Insert a list bullet") self.aInsBullet.setShortcut("Ctrl+K, *") - self.aInsBullet.triggered.connect(lambda: self._docInsert(nwDocInsert.LIST_BULLET)) + self.aInsBullet.triggered.connect(lambda: self._docInsert(nwUnicode.U_BULL)) self.mInsSymbol.addAction(self.aInsBullet) # Insert > Flower Mark self.aInsFlower = QAction("Flower Mark", self) self.aInsFlower.setStatusTip("Insert a flower mark (alternative bullet)") self.aInsFlower.setShortcut("Ctrl+K, Ctrl+*") - self.aInsFlower.triggered.connect(lambda: self._docInsert(nwDocInsert.FLOWER_MARK)) + self.aInsFlower.triggered.connect(lambda: self._docInsert(nwUnicode.U_FLOWER)) self.mInsSymbol.addAction(self.aInsFlower) # Insert > Per Mille self.aInsPerMille = QAction("Per Mille", self) self.aInsPerMille.setStatusTip("Insert a per mille symbol") self.aInsPerMille.setShortcut("Ctrl+K, %") - self.aInsPerMille.triggered.connect(lambda: self._docInsert(nwDocInsert.PER_MILLE)) + self.aInsPerMille.triggered.connect(lambda: self._docInsert(nwUnicode.U_PERMIL)) self.mInsSymbol.addAction(self.aInsPerMille) + # Insert > Degree Symbol + self.aInsDegree = QAction("Degree Symbol", self) + self.aInsDegree.setStatusTip("Insert a segree symbol") + self.aInsDegree.setShortcut("Ctrl+K, 0") + self.aInsDegree.triggered.connect(lambda: self._docInsert(nwUnicode.U_DEGREE)) + self.mInsSymbol.addAction(self.aInsDegree) + + # Insert > Times Sign + self.aInsTimes = QAction("Times Sign", self) + self.aInsTimes.setStatusTip("Insert a times (multiplication) sign") + self.aInsTimes.setShortcut("Ctrl+K, Ctrl+X") + self.aInsTimes.triggered.connect(lambda: self._docInsert(nwUnicode.U_TIMES)) + self.mInsSymbol.addAction(self.aInsTimes) + + # Insert > Division + self.aInsDivide = QAction("Division Sign", self) + self.aInsDivide.setStatusTip("Insert a division sign") + self.aInsDivide.setShortcut("Ctrl+K, Ctrl+D") + self.aInsDivide.triggered.connect(lambda: self._docInsert(nwUnicode.U_DIVIDE)) + self.mInsSymbol.addAction(self.aInsDivide) + # Insert > Separator self.insertMenu.addSeparator() diff --git a/nw/guimain.py b/nw/guimain.py index 1b0c7005..30db5b32 100644 --- a/nw/guimain.py +++ b/nw/guimain.py @@ -1256,6 +1256,9 @@ class GuiMain(QMainWindow): self.addAction(self.mainMenu.aInsBullet) self.addAction(self.mainMenu.aInsFlower) self.addAction(self.mainMenu.aInsPerMille) + self.addAction(self.mainMenu.aInsDegree) + self.addAction(self.mainMenu.aInsTimes) + self.addAction(self.mainMenu.aInsDivide) for mAction, _ in self.mainMenu.mInsKWItems.values(): self.addAction(mAction) diff --git a/tests/test_gui/test_gui_mainmenu.py b/tests/test_gui/test_gui_mainmenu.py index 7d0bdb6b..0feac816 100644 --- a/tests/test_gui/test_gui_mainmenu.py +++ b/tests/test_gui/test_gui_mainmenu.py @@ -440,6 +440,18 @@ def testGuiMenu_Insert(qtbot, monkeypatch, nwGUI, fncDir, fncProj): assert nwGUI.docEditor.getText() == nwUnicode.U_PERMIL nwGUI.docEditor.clear() + nwGUI.mainMenu.aInsDegree.activate(QAction.Trigger) + assert nwGUI.docEditor.getText() == nwUnicode.U_DEGREE + nwGUI.docEditor.clear() + + nwGUI.mainMenu.aInsTimes.activate(QAction.Trigger) + assert nwGUI.docEditor.getText() == nwUnicode.U_TIMES + nwGUI.docEditor.clear() + + nwGUI.mainMenu.aInsDivide.activate(QAction.Trigger) + assert nwGUI.docEditor.getText() == nwUnicode.U_DIVIDE + nwGUI.docEditor.clear() + nwGUI.mainMenu.aInsHardBreak.activate(QAction.Trigger) assert nwGUI.docEditor.getText() == " \n" nwGUI.docEditor.clear()