Add degree, times and divide symbols to insert menu, and simply the editor insert function

This commit is contained in:
Veronica K. B. Olsen
2021-01-25 23:05:41 +01:00
parent a011c10d4d
commit fab5833cdf
7 changed files with 65 additions and 61 deletions
+7 -1
View File
@@ -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 = "▲"
+6 -19
View File
@@ -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
+1 -1
View File
@@ -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
-26
View File
@@ -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:
+36 -14
View File
@@ -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()
+3
View File
@@ -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)
+12
View File
@@ -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()