Fixed merge conflicts

This commit is contained in:
Veronica K. B. Olsen
2019-11-16 12:36:29 +01:00
13 changed files with 434 additions and 325 deletions
+1
View File
@@ -23,6 +23,7 @@ sample/**/*.json
tests/temp tests/temp
.pytest_cache .pytest_cache
pytestdebug.log pytestdebug.log
prof/
# Coverage # Coverage
.coverage .coverage
+36 -3
View File
@@ -53,6 +53,7 @@ class GuiDocEditor(QTextEdit):
self.wordCount = 0 self.wordCount = 0
self.paraCount = 0 self.paraCount = 0
self.lastEdit = 0 self.lastEdit = 0
self.nonWord = "\"'"
# Typography # Typography
self.typDQOpen = self.mainConf.fmtDoubleQuotes[0] self.typDQOpen = self.mainConf.fmtDoubleQuotes[0]
@@ -137,6 +138,11 @@ class GuiDocEditor(QTextEdit):
created, and when the user changes the main editor preferences. created, and when the user changes the main editor preferences.
""" """
# Some Constants
self.nonWord = "\"'"
self.nonWord += "".join(self.mainConf.fmtDoubleQuotes)
self.nonWord += "".join(self.mainConf.fmtSingleQuotes)
# Reload spell check and dictionaries # Reload spell check and dictionaries
self._setupSpellChecking() self._setupSpellChecking()
self.setDictionaries() self.setDictionaries()
@@ -308,17 +314,41 @@ class GuiDocEditor(QTextEdit):
## ##
def setDictionaries(self): def setDictionaries(self):
"""Set the spell checker dictionary language, and update the
status bar to show the one actually loaded by the spell checker
class.
"""
self.theDict.setLanguage(self.mainConf.spellLanguage, self.theProject.projDict) self.theDict.setLanguage(self.mainConf.spellLanguage, self.theProject.projDict)
self.theParent.statusBar.setLanguage(self.mainConf.spellLanguage) self.theParent.statusBar.setLanguage(self.theDict.spellLanguage)
return True return True
def setSpellCheck(self, theMode): def setSpellCheck(self, theMode):
"""This is the master spell check setting function, and this one
should call all other setSpellCheck functions in other classes.
If the spell check mode is not defined, then toggle the current
status saved in the class.
"""
if theMode is None:
theMode = not self.spellCheck
if self.theDict.spellLanguage is None:
theMode = False
self.spellCheck = theMode self.spellCheck = theMode
self.theParent.mainMenu.setSpellCheck(theMode)
self.theProject.setSpellCheck(theMode)
self.hLight.setSpellCheck(theMode) self.hLight.setSpellCheck(theMode)
self.hLight.rehighlight() self.hLight.rehighlight()
logger.verbose("Spell check is set to %s" % str(theMode))
return True return True
def updateSpellCheck(self): def updateSpellCheck(self):
"""Rerun the highlighter to update spell checking status of the
currently loaded text.
"""
if self.spellCheck: if self.spellCheck:
self.hLight.rehighlight() self.hLight.rehighlight()
return True return True
@@ -500,9 +530,12 @@ class GuiDocEditor(QTextEdit):
theCursor = self.cursorForPosition(thePos) theCursor = self.cursorForPosition(thePos)
theCursor.select(QTextCursor.WordUnderCursor) theCursor.select(QTextCursor.WordUnderCursor)
theWord = theCursor.selectedText()
theWord = theCursor.selectedText().strip().strip(self.nonWord)
if theWord == "": if theWord == "":
return return
logger.verbose("Looking up '%s' in the dictionary" % theWord)
if self.theDict.checkWord(theWord): if self.theDict.checkWord(theWord):
return return
@@ -541,7 +574,7 @@ class GuiDocEditor(QTextEdit):
return return
def _addWord(self, theCursor): def _addWord(self, theCursor):
theWord = theCursor.selectedText().strip() theWord = theCursor.selectedText().strip().strip(self.nonWord)
logger.debug("Added '%s' to project dictionary" % theWord) logger.debug("Added '%s' to project dictionary" % theWord)
self.theDict.addWord(theWord) self.theDict.addWord(theWord)
self.hLight.setDict(self.theDict) self.hLight.setDict(self.theDict)
+290 -299
View File
@@ -68,7 +68,6 @@ class GuiMainMenu(QMenuBar):
def updateMenu(self): def updateMenu(self):
self.updateRecentProjects() self.updateRecentProjects()
self.updateSpellCheck()
return return
def updateRecentProjects(self): def updateRecentProjects(self):
@@ -91,10 +90,12 @@ class GuiMainMenu(QMenuBar):
return return
def updateSpellCheck(self): def setSpellCheck(self, theMode):
if self.theParent.hasProject: """Set the spell check check box to theMode. This is controlled
self.toolsSpellCheck.setChecked(self.theProject.spellCheck) by the document editor class, which holds the master spell check
logger.verbose("Spell check is set to %s" % str(self.theProject.spellCheck)) flag.
"""
self.aSpellCheck.setChecked(theMode)
return return
## ##
@@ -106,16 +107,15 @@ class GuiMainMenu(QMenuBar):
return return
def _toggleSpellCheck(self): def _toggleSpellCheck(self):
if self.theParent.hasProject: """Toggle spell checking. The active status of the spell check
self.theProject.setSpellCheck(self.toolsSpellCheck.isChecked()) flag is handled by the document editor class, so we make no
self.theParent.docEditor.setSpellCheck(self.toolsSpellCheck.isChecked()) decision, just pass a None to the function and let it decide.
logger.verbose("Spell check is set to %s" % str(self.theProject.spellCheck)) """
else: self.theParent.docEditor.setSpellCheck(None)
self.toolsSpellCheck.setChecked(False)
return True return True
def _toggleViewComments(self): def _toggleViewComments(self):
self.mainConf.setViewComments(self.docViewComments.isChecked()) self.mainConf.setViewComments(self.aViewDocComments.isChecked())
self.theParent.docViewer.reloadText() self.theParent.docViewer.reloadText()
return True return True
@@ -185,111 +185,111 @@ class GuiMainMenu(QMenuBar):
self.projMenu = self.addMenu("&Project") self.projMenu = self.addMenu("&Project")
# Project > New Project # Project > New Project
menuItem = QAction("New Project", self) self.aNewProject = QAction("New Project", self)
menuItem.setStatusTip("Create new project") self.aNewProject.setStatusTip("Create new project")
menuItem.triggered.connect(lambda : self.theParent.newProject(None)) self.aNewProject.triggered.connect(lambda : self.theParent.newProject(None))
self.projMenu.addAction(menuItem) self.projMenu.addAction(self.aNewProject)
# Project > Open Project # Project > Open Project
menuItem = QAction("Open Project", self) self.aOpenProject = QAction("Open Project", self)
menuItem.setStatusTip("Open project") self.aOpenProject.setStatusTip("Open project")
menuItem.setShortcut("Ctrl+Shift+O") self.aOpenProject.setShortcut("Ctrl+Shift+O")
menuItem.triggered.connect(lambda : self.theParent.openProject(None)) self.aOpenProject.triggered.connect(lambda : self.theParent.openProject(None))
self.projMenu.addAction(menuItem) self.projMenu.addAction(self.aOpenProject)
# Project > Save Project # Project > Save Project
menuItem = QAction("Save Project", self) self.aSaveProject = QAction("Save Project", self)
menuItem.setStatusTip("Save project") self.aSaveProject.setStatusTip("Save project")
menuItem.setShortcut("Ctrl+Shift+S") self.aSaveProject.setShortcut("Ctrl+Shift+S")
menuItem.triggered.connect(self.theParent.saveProject) self.aSaveProject.triggered.connect(self.theParent.saveProject)
self.projMenu.addAction(menuItem) self.projMenu.addAction(self.aSaveProject)
# Project > Close Project # Project > Close Project
menuItem = QAction("Close Project", self) self.aCloseProject = QAction("Close Project", self)
menuItem.setStatusTip("Close project") self.aCloseProject.setStatusTip("Close project")
menuItem.setShortcut("Ctrl+Shift+W") self.aCloseProject.setShortcut("Ctrl+Shift+W")
menuItem.triggered.connect(lambda : self.theParent.closeProject(False)) self.aCloseProject.triggered.connect(lambda : self.theParent.closeProject(False))
self.projMenu.addAction(menuItem) self.projMenu.addAction(self.aCloseProject)
# Project > Recent Projects # Project > Recent Projects
self.recentMenu = self.projMenu.addMenu("Recent Projects") self.recentMenu = self.projMenu.addMenu("Recent Projects")
self.updateRecentProjects() self.updateRecentProjects()
# Project > Project Settings # Project > Project Settings
menuItem = QAction("Project Settings", self) self.aProjectSettings = QAction("Project Settings", self)
menuItem.setStatusTip("Project settings") self.aProjectSettings.setStatusTip("Project settings")
menuItem.setShortcut("Ctrl+Shift+,") self.aProjectSettings.setShortcut("Ctrl+Shift+,")
menuItem.triggered.connect(self.theParent.editProjectDialog) self.aProjectSettings.triggered.connect(self.theParent.editProjectDialog)
self.projMenu.addAction(menuItem) self.projMenu.addAction(self.aProjectSettings)
# Project > Export Project # Project > Export Project
menuItem = QAction("Export Project", self) self.aExportProject = QAction("Export Project", self)
menuItem.setStatusTip("Export project") self.aExportProject.setStatusTip("Export project")
menuItem.setShortcut("F5") self.aExportProject.setShortcut("F5")
menuItem.triggered.connect(self.theParent.exportProjectDialog) self.aExportProject.triggered.connect(self.theParent.exportProjectDialog)
self.projMenu.addAction(menuItem) self.projMenu.addAction(self.aExportProject)
# Project > Session Log # Project > Session Log
menuItem = QAction("Session Log", self) self.aSessionLog = QAction("Session Log", self)
menuItem.setStatusTip("Show the session log") self.aSessionLog.setStatusTip("Show the session log")
menuItem.triggered.connect(self.theParent.showSessionLogDialog) self.aSessionLog.triggered.connect(self.theParent.showSessionLogDialog)
self.projMenu.addAction(menuItem) self.projMenu.addAction(self.aSessionLog)
# Project > Separator # Project > Separator
self.projMenu.addSeparator() self.projMenu.addSeparator()
# Project > New Root # Project > New Root
rootMenu = self.projMenu.addMenu("Create Root Folder") self.rootMenu = self.projMenu.addMenu("Create Root Folder")
self.rootItems = {} self.rootItems = {}
self.rootItems[nwItemClass.NOVEL] = QAction("Novel Root", rootMenu) self.rootItems[nwItemClass.NOVEL] = QAction("Novel Root", self.rootMenu)
self.rootItems[nwItemClass.PLOT] = QAction("Plot Root", rootMenu) self.rootItems[nwItemClass.PLOT] = QAction("Plot Root", self.rootMenu)
self.rootItems[nwItemClass.CHARACTER] = QAction("Character Root", rootMenu) self.rootItems[nwItemClass.CHARACTER] = QAction("Character Root", self.rootMenu)
self.rootItems[nwItemClass.WORLD] = QAction("Location Root", rootMenu) self.rootItems[nwItemClass.WORLD] = QAction("Location Root", self.rootMenu)
self.rootItems[nwItemClass.TIMELINE] = QAction("Timeline Root", rootMenu) self.rootItems[nwItemClass.TIMELINE] = QAction("Timeline Root", self.rootMenu)
self.rootItems[nwItemClass.OBJECT] = QAction("Object Root", rootMenu) self.rootItems[nwItemClass.OBJECT] = QAction("Object Root", self.rootMenu)
self.rootItems[nwItemClass.ENTITY] = QAction("Entity Root", rootMenu) self.rootItems[nwItemClass.ENTITY] = QAction("Entity Root", self.rootMenu)
self.rootItems[nwItemClass.CUSTOM] = QAction("Custom Root", rootMenu) self.rootItems[nwItemClass.CUSTOM] = QAction("Custom Root", self.rootMenu)
nCount = 0 nCount = 0
for itemClass in self.rootItems.keys(): for itemClass in self.rootItems.keys():
nCount += 1 # This forces the lambdas to be unique nCount += 1 # This forces the lambdas to be unique
self.rootItems[itemClass].triggered.connect( self.rootItems[itemClass].triggered.connect(
lambda nCount, itemClass=itemClass : self._newTreeItem(nwItemType.ROOT, itemClass) lambda nCount, itemClass=itemClass : self._newTreeItem(nwItemType.ROOT, itemClass)
) )
rootMenu.addActions(self.rootItems.values()) self.rootMenu.addActions(self.rootItems.values())
# Project > New Folder # Project > New Folder
menuItem = QAction("Create Folder", self) self.aCreateFolder = QAction("Create Folder", self)
menuItem.setStatusTip("Create folder") self.aCreateFolder.setStatusTip("Create folder")
menuItem.setShortcut("Ctrl+Shift+N") self.aCreateFolder.setShortcut("Ctrl+Shift+N")
menuItem.triggered.connect(lambda : self._newTreeItem(nwItemType.FOLDER, None)) self.aCreateFolder.triggered.connect(lambda : self._newTreeItem(nwItemType.FOLDER, None))
self.projMenu.addAction(menuItem) self.projMenu.addAction(self.aCreateFolder)
# Project > Separator # Project > Separator
self.projMenu.addSeparator() self.projMenu.addSeparator()
# Project > Edit # Project > Edit
menuItem = QAction("&Edit Item", self) self.aEditItem = QAction("&Edit Item", self)
menuItem.setStatusTip("Change item settings") self.aEditItem.setStatusTip("Change item settings")
menuItem.setShortcuts(["Ctrl+E", "F2"]) self.aEditItem.setShortcuts(["Ctrl+E", "F2"])
menuItem.triggered.connect(self.theParent.editItem) self.aEditItem.triggered.connect(self.theParent.editItem)
self.projMenu.addAction(menuItem) self.projMenu.addAction(self.aEditItem)
# Project > Delete # Project > Delete
menuItem = QAction("&Delete Item", self) self.aDeleteItem = QAction("&Delete Item", self)
menuItem.setStatusTip("Delete selected item") self.aDeleteItem.setStatusTip("Delete selected item")
menuItem.setShortcut("Ctrl+Del") self.aDeleteItem.setShortcut("Ctrl+Del")
menuItem.triggered.connect(lambda : self.theParent.treeView.deleteItem(None)) self.aDeleteItem.triggered.connect(lambda : self.theParent.treeView.deleteItem(None))
self.projMenu.addAction(menuItem) self.projMenu.addAction(self.aDeleteItem)
# Project > Separator # Project > Separator
self.projMenu.addSeparator() self.projMenu.addSeparator()
# Project > Exit # Project > Exit
menuItem = QAction("Exit", self) self.aExitNW = QAction("Exit", self)
menuItem.setStatusTip("Exit %s" % nw.__package__) self.aExitNW.setStatusTip("Exit %s" % nw.__package__)
menuItem.setShortcut("Ctrl+Q") self.aExitNW.setShortcut("Ctrl+Q")
menuItem.triggered.connect(self._menuExit) self.aExitNW.triggered.connect(self._menuExit)
self.projMenu.addAction(menuItem) self.projMenu.addAction(self.aExitNW)
return return
@@ -299,85 +299,75 @@ class GuiMainMenu(QMenuBar):
self.docuMenu = self.addMenu("&Document") self.docuMenu = self.addMenu("&Document")
# Document > New # Document > New
menuItem = QAction("&New Document", self) self.aNewDoc = QAction("&New Document", self)
menuItem.setStatusTip("Create new document") self.aNewDoc.setStatusTip("Create new document")
menuItem.setShortcut("Ctrl+N") self.aNewDoc.setShortcut("Ctrl+N")
menuItem.triggered.connect(lambda : self._newTreeItem(nwItemType.FILE, None)) self.aNewDoc.triggered.connect(lambda : self._newTreeItem(nwItemType.FILE, None))
self.docuMenu.addAction(menuItem) self.docuMenu.addAction(self.aNewDoc)
# Document > Open # Document > Open
menuItem = QAction("&Open Document", self) self.aOpenDoc = QAction("&Open Document", self)
menuItem.setStatusTip("Open selected document") self.aOpenDoc.setStatusTip("Open selected document")
menuItem.setShortcut("Ctrl+O") self.aOpenDoc.setShortcut("Ctrl+O")
menuItem.triggered.connect(self.theParent.openSelectedItem) self.aOpenDoc.triggered.connect(self.theParent.openSelectedItem)
self.docuMenu.addAction(menuItem) self.docuMenu.addAction(self.aOpenDoc)
# Document > Save # Document > Save
menuItem = QAction("&Save Document", self) self.aSaveDoc = QAction("&Save Document", self)
menuItem.setStatusTip("Save current document") self.aSaveDoc.setStatusTip("Save current document")
menuItem.setShortcut("Ctrl+S") self.aSaveDoc.setShortcut("Ctrl+S")
menuItem.triggered.connect(self.theParent.saveDocument) self.aSaveDoc.triggered.connect(self.theParent.saveDocument)
self.docuMenu.addAction(menuItem) self.docuMenu.addAction(self.aSaveDoc)
# Document > Close # Document > Close
menuItem = QAction("Close Document", self) self.aCloseDoc = QAction("Close Document", self)
menuItem.setStatusTip("Close current document") self.aCloseDoc.setStatusTip("Close current document")
menuItem.setShortcut("Ctrl+W") self.aCloseDoc.setShortcut("Ctrl+W")
menuItem.triggered.connect(self.theParent.closeDocEditor) self.aCloseDoc.triggered.connect(self.theParent.closeDocEditor)
self.docuMenu.addAction(menuItem) self.docuMenu.addAction(self.aCloseDoc)
# Document > Separator # Document > Separator
self.docuMenu.addSeparator() self.docuMenu.addSeparator()
# Document > Preview # Document > Preview
menuItem = QAction("View Document", self) self.aViewDoc = QAction("View Document", self)
menuItem.setStatusTip("View document as HTML") self.aViewDoc.setStatusTip("View document as HTML")
menuItem.setShortcut("Ctrl+R") self.aViewDoc.setShortcut("Ctrl+R")
menuItem.triggered.connect(lambda : self.theParent.viewDocument(None)) self.aViewDoc.triggered.connect(lambda : self.theParent.viewDocument(None))
self.docuMenu.addAction(menuItem) self.docuMenu.addAction(self.aViewDoc)
# Document > Close Preview # Document > Close Preview
menuItem = QAction("Close Document View", self) self.aCloseView = QAction("Close Document View", self)
menuItem.setStatusTip("Close document view pane") self.aCloseView.setStatusTip("Close document view pane")
menuItem.setShortcut("Ctrl+Shift+R") self.aCloseView.setShortcut("Ctrl+Shift+R")
menuItem.triggered.connect(self.theParent.closeDocViewer) self.aCloseView.triggered.connect(self.theParent.closeDocViewer)
self.docuMenu.addAction(menuItem) self.docuMenu.addAction(self.aCloseView)
# Document > Toggle View Comments # Document > Toggle View Comments
self.docViewComments = QAction("View Comments", self) self.aViewDocComments = QAction("View Comments", self)
self.docViewComments.setStatusTip("Show comments in view panel") self.aViewDocComments.setStatusTip("Show comments in view panel")
self.docViewComments.setCheckable(True) self.aViewDocComments.setCheckable(True)
self.docViewComments.setChecked(self.mainConf.viewComments) self.aViewDocComments.setChecked(self.mainConf.viewComments)
self.docViewComments.toggled.connect(self._toggleViewComments) self.aViewDocComments.toggled.connect(self._toggleViewComments)
self.docuMenu.addAction(self.docViewComments) self.docuMenu.addAction(self.aViewDocComments)
# Document > Separator # Document > Separator
self.docuMenu.addSeparator() self.docuMenu.addSeparator()
# Document > Show File Details # Document > Show File Details
menuItem = QAction("Show File Details", self) self.aFileDetails = QAction("Show File Details", self)
menuItem.setStatusTip( self.aFileDetails.setStatusTip(
"Shows a message box with the document location in the project folder" "Shows a message box with the document location in the project folder"
) )
menuItem.triggered.connect(self._showDocumentLocation) self.aFileDetails.triggered.connect(self._showDocumentLocation)
self.docuMenu.addAction(menuItem) self.docuMenu.addAction(self.aFileDetails)
# Document > Import From File # Document > Import From File
menuItem = QAction("Import from File", self) self.aImportFile = QAction("Import from File", self)
menuItem.setStatusTip("Import document from a text or markdown file") self.aImportFile.setStatusTip("Import document from a text or markdown file")
menuItem.setShortcut("Ctrl+Shift+I") self.aImportFile.setShortcut("Ctrl+Shift+I")
menuItem.triggered.connect(self.theParent.importDocument) self.aImportFile.triggered.connect(self.theParent.importDocument)
self.docuMenu.addAction(menuItem) self.docuMenu.addAction(self.aImportFile)
# # Document > Split
# menuItem = QAction("Split Document", self)
# menuItem.setStatusTip("Split Selected Document")
# self.docuMenu.addAction(menuItem)
# # Document > Merge
# menuItem = QAction("Merge Document", self)
# menuItem.setStatusTip("Merge Selected Documents")
# self.docuMenu.addAction(menuItem)
return return
@@ -387,54 +377,54 @@ class GuiMainMenu(QMenuBar):
self.viewMenu = self.addMenu("&View") self.viewMenu = self.addMenu("&View")
# View > TreeView # View > TreeView
menuItem = QAction("TreeView", self) self.aFocusTree = QAction("TreeView", self)
menuItem.setStatusTip("Move focus to project tree") self.aFocusTree.setStatusTip("Move focus to project tree")
menuItem.setShortcut("Ctrl+1") self.aFocusTree.setShortcut("Ctrl+1")
menuItem.triggered.connect(lambda : self.theParent.setFocus(1)) self.aFocusTree.triggered.connect(lambda : self.theParent.setFocus(1))
self.viewMenu.addAction(menuItem) self.viewMenu.addAction(self.aFocusTree)
# View > Document Pane 1 # View > Document Pane 1
menuItem = QAction("Left Document Pane", self) self.aFocusEditor = QAction("Left Document Pane", self)
menuItem.setStatusTip("Move focus to left document pane") self.aFocusEditor.setStatusTip("Move focus to left document pane")
menuItem.setShortcut("Ctrl+2") self.aFocusEditor.setShortcut("Ctrl+2")
menuItem.triggered.connect(lambda : self.theParent.setFocus(2)) self.aFocusEditor.triggered.connect(lambda : self.theParent.setFocus(2))
self.viewMenu.addAction(menuItem) self.viewMenu.addAction(self.aFocusEditor)
# View > Document Pane 2 # View > Document Pane 2
menuItem = QAction("Right Document Pane", self) self.aFocusView = QAction("Right Document Pane", self)
menuItem.setStatusTip("Move focus to right document pane") self.aFocusView.setStatusTip("Move focus to right document pane")
menuItem.setShortcut("Ctrl+3") self.aFocusView.setShortcut("Ctrl+3")
menuItem.triggered.connect(lambda : self.theParent.setFocus(3)) self.aFocusView.triggered.connect(lambda : self.theParent.setFocus(3))
self.viewMenu.addAction(menuItem) self.viewMenu.addAction(self.aFocusView)
# View > Separator # View > Separator
self.viewMenu.addSeparator() self.viewMenu.addSeparator()
# View > Toggle Distraction Free Mode # View > Toggle Distraction Free Mode
menuItem = QAction("Zen Mode", self) self.aZenMode = QAction("Zen Mode", self)
menuItem.setStatusTip("Toggles distraction free mode, only showing text editor") self.aZenMode.setStatusTip("Toggles distraction free mode, only showing text editor")
menuItem.setShortcut("F8") self.aZenMode.setShortcut("F8")
menuItem.setCheckable(True) self.aZenMode.setCheckable(True)
menuItem.setChecked(self.theParent.isZenMode) self.aZenMode.setChecked(self.theParent.isZenMode)
menuItem.toggled.connect(self.theParent.toggleZenMode) self.aZenMode.toggled.connect(self.theParent.toggleZenMode)
self.viewMenu.addAction(menuItem) self.viewMenu.addAction(self.aZenMode)
# View > Toggle Full Screen # View > Toggle Full Screen
menuItem = QAction("Full Screen Mode", self) self.aFullScreen = QAction("Full Screen Mode", self)
menuItem.setStatusTip("Maximises the main window") self.aFullScreen.setStatusTip("Maximises the main window")
menuItem.setShortcut("F11") self.aFullScreen.setShortcut("F11")
menuItem.triggered.connect(self.theParent.toggleFullScreenMode) self.aFullScreen.triggered.connect(self.theParent.toggleFullScreenMode)
self.viewMenu.addAction(menuItem) self.viewMenu.addAction(self.aFullScreen)
# View > Separator # View > Separator
self.viewMenu.addSeparator() self.viewMenu.addSeparator()
# View > Project Timeline # View > Project Timeline
menuItem = QAction("Show Project Timeline", self) self.aViewTimeLine = QAction("Show Project Timeline", self)
menuItem.setStatusTip("Open the project timeline window") self.aViewTimeLine.setStatusTip("Open the project timeline window")
menuItem.setShortcut("Ctrl+T") self.aViewTimeLine.setShortcut("Ctrl+T")
menuItem.triggered.connect(self.theParent.showTimeLineDialog) self.aViewTimeLine.triggered.connect(self.theParent.showTimeLineDialog)
self.viewMenu.addAction(menuItem) self.viewMenu.addAction(self.aViewTimeLine)
return return
@@ -444,106 +434,106 @@ class GuiMainMenu(QMenuBar):
self.editMenu = self.addMenu("&Edit") self.editMenu = self.addMenu("&Edit")
# Edit > Undo # Edit > Undo
menuItem = QAction("Undo", self) self.aEditUndo = QAction("Undo", self)
menuItem.setStatusTip("Undo last change") self.aEditUndo.setStatusTip("Undo last change")
menuItem.setShortcut("Ctrl+Z") self.aEditUndo.setShortcut("Ctrl+Z")
menuItem.triggered.connect(lambda: self._docAction(nwDocAction.UNDO)) self.aEditUndo.triggered.connect(lambda: self._docAction(nwDocAction.UNDO))
self.editMenu.addAction(menuItem) self.editMenu.addAction(self.aEditUndo)
# Edit > Redo # Edit > Redo
menuItem = QAction("Redo", self) self.aEditRedo = QAction("Redo", self)
menuItem.setStatusTip("Redo last change") self.aEditRedo.setStatusTip("Redo last change")
menuItem.setShortcut("Ctrl+Y") self.aEditRedo.setShortcut("Ctrl+Y")
menuItem.triggered.connect(lambda: self._docAction(nwDocAction.REDO)) self.aEditRedo.triggered.connect(lambda: self._docAction(nwDocAction.REDO))
self.editMenu.addAction(menuItem) self.editMenu.addAction(self.aEditRedo)
# Edit > Separator # Edit > Separator
self.editMenu.addSeparator() self.editMenu.addSeparator()
# Edit > Cut # Edit > Cut
menuItem = QAction("Cut", self) self.aEditCut = QAction("Cut", self)
menuItem.setStatusTip("Cut selected text") self.aEditCut.setStatusTip("Cut selected text")
menuItem.setShortcut("Ctrl+X") self.aEditCut.setShortcut("Ctrl+X")
menuItem.triggered.connect(lambda: self._docAction(nwDocAction.CUT)) self.aEditCut.triggered.connect(lambda: self._docAction(nwDocAction.CUT))
self.editMenu.addAction(menuItem) self.editMenu.addAction(self.aEditCut)
# Edit > Copy # Edit > Copy
menuItem = QAction("Copy", self) self.aEditCopy = QAction("Copy", self)
menuItem.setStatusTip("Copy selected text") self.aEditCopy.setStatusTip("Copy selected text")
menuItem.setShortcut("Ctrl+C") self.aEditCopy.setShortcut("Ctrl+C")
menuItem.triggered.connect(lambda: self._docAction(nwDocAction.COPY)) self.aEditCopy.triggered.connect(lambda: self._docAction(nwDocAction.COPY))
self.editMenu.addAction(menuItem) self.editMenu.addAction(self.aEditCopy)
# Edit > Paste # Edit > Paste
menuItem = QAction("Paste", self) self.aEditPaste = QAction("Paste", self)
menuItem.setStatusTip("Paste text from clipboard") self.aEditPaste.setStatusTip("Paste text from clipboard")
menuItem.setShortcut("Ctrl+V") self.aEditPaste.setShortcut("Ctrl+V")
menuItem.triggered.connect(lambda: self._docAction(nwDocAction.PASTE)) self.aEditPaste.triggered.connect(lambda: self._docAction(nwDocAction.PASTE))
self.editMenu.addAction(menuItem) self.editMenu.addAction(self.aEditPaste)
# Edit > Separator # Edit > Separator
self.editMenu.addSeparator() self.editMenu.addSeparator()
# Edit > Find # Edit > Find
menuItem = QAction("Find", self) self.aEditFind = QAction("Find", self)
menuItem.setStatusTip("Find text in document") self.aEditFind.setStatusTip("Find text in document")
menuItem.setShortcut("Ctrl+F") self.aEditFind.setShortcut("Ctrl+F")
menuItem.triggered.connect(lambda: self._docAction(nwDocAction.FIND)) self.aEditFind.triggered.connect(lambda: self._docAction(nwDocAction.FIND))
self.editMenu.addAction(menuItem) self.editMenu.addAction(self.aEditFind)
# Edit > Replace # Edit > Replace
menuItem = QAction("Replace", self) self.aEditReplace = QAction("Replace", self)
menuItem.setStatusTip("Replace text in document") self.aEditReplace.setStatusTip("Replace text in document")
if self.mainConf.osDarwin: if self.mainConf.osDarwin:
menuItem.setShortcut("Ctrl+=") self.aEditReplace.setShortcut("Ctrl+=")
else: else:
menuItem.setShortcut("Ctrl+H") self.aEditReplace.setShortcut("Ctrl+H")
menuItem.triggered.connect(lambda: self._docAction(nwDocAction.REPLACE)) self.aEditReplace.triggered.connect(lambda: self._docAction(nwDocAction.REPLACE))
self.editMenu.addAction(menuItem) self.editMenu.addAction(self.aEditReplace)
# Edit > Find Next # Edit > Find Next
menuItem = QAction("Find Next", self) self.aFindNext = QAction("Find Next", self)
menuItem.setStatusTip("Find next occurrence text in document") self.aFindNext.setStatusTip("Find next occurrence text in document")
if self.mainConf.osDarwin: if self.mainConf.osDarwin:
menuItem.setShortcuts(["Ctrl+G","F3"]) self.aFindNext.setShortcuts(["Ctrl+G","F3"])
else: else:
menuItem.setShortcuts(["F3","Ctrl+G"]) self.aFindNext.setShortcuts(["F3","Ctrl+G"])
menuItem.triggered.connect(lambda: self._docAction(nwDocAction.GO_NEXT)) self.aFindNext.triggered.connect(lambda: self._docAction(nwDocAction.GO_NEXT))
self.editMenu.addAction(menuItem) self.editMenu.addAction(self.aFindNext)
# Edit > Find Prev # Edit > Find Prev
menuItem = QAction("Find Previous", self) self.aFindPrev = QAction("Find Previous", self)
menuItem.setStatusTip("Find previous occurrence text in document") self.aFindPrev.setStatusTip("Find previous occurrence text in document")
if self.mainConf.osDarwin: if self.mainConf.osDarwin:
menuItem.setShortcuts(["Ctrl+Shift+G","Shift+F3"]) self.aFindPrev.setShortcuts(["Ctrl+Shift+G","Shift+F3"])
else: else:
menuItem.setShortcuts(["Shift+F3","Ctrl+Shift+G"]) self.aFindPrev.setShortcuts(["Shift+F3","Ctrl+Shift+G"])
menuItem.triggered.connect(lambda: self._docAction(nwDocAction.GO_PREV)) self.aFindPrev.triggered.connect(lambda: self._docAction(nwDocAction.GO_PREV))
self.editMenu.addAction(menuItem) self.editMenu.addAction(self.aFindPrev)
# Edit > Replace Next # Edit > Replace Next
menuItem = QAction("Replace Next", self) self.aReplaceNext = QAction("Replace Next", self)
menuItem.setStatusTip("Find and replace next occurrence text in document") self.aReplaceNext.setStatusTip("Find and replace next occurrence text in document")
menuItem.setShortcut("Ctrl+Shift+1") self.aReplaceNext.setShortcut("Ctrl+Shift+1")
menuItem.triggered.connect(lambda: self._docAction(nwDocAction.REPL_NEXT)) self.aReplaceNext.triggered.connect(lambda: self._docAction(nwDocAction.REPL_NEXT))
self.editMenu.addAction(menuItem) self.editMenu.addAction(self.aReplaceNext)
# Edit > Separator # Edit > Separator
self.editMenu.addSeparator() self.editMenu.addSeparator()
# Edit > Select All # Edit > Select All
menuItem = QAction("Select All", self) self.aSelectAll = QAction("Select All", self)
menuItem.setStatusTip("Select all text in document") self.aSelectAll.setStatusTip("Select all text in document")
menuItem.setShortcut("Ctrl+A") self.aSelectAll.setShortcut("Ctrl+A")
menuItem.triggered.connect(lambda: self._docAction(nwDocAction.SEL_ALL)) self.aSelectAll.triggered.connect(lambda: self._docAction(nwDocAction.SEL_ALL))
self.editMenu.addAction(menuItem) self.editMenu.addAction(self.aSelectAll)
# Edit > Select Paragraph # Edit > Select Paragraph
menuItem = QAction("Select Paragraph", self) self.aSelectPar = QAction("Select Paragraph", self)
menuItem.setStatusTip("Select all text in paragraph") self.aSelectPar.setStatusTip("Select all text in paragraph")
menuItem.setShortcut("Ctrl+Shift+A") self.aSelectPar.setShortcut("Ctrl+Shift+A")
menuItem.triggered.connect(lambda: self._docAction(nwDocAction.SEL_PARA)) self.aSelectPar.triggered.connect(lambda: self._docAction(nwDocAction.SEL_PARA))
self.editMenu.addAction(menuItem) self.editMenu.addAction(self.aSelectPar)
return return
@@ -553,42 +543,42 @@ class GuiMainMenu(QMenuBar):
self.fmtMenu = self.addMenu("&Format") self.fmtMenu = self.addMenu("&Format")
# Format > Bold Text # Format > Bold Text
menuItem = QAction("Bold Text", self) self.aFmtBold = QAction("Bold Text", self)
menuItem.setStatusTip("Make selected text bold") self.aFmtBold.setStatusTip("Make selected text bold")
menuItem.setShortcut("Ctrl+B") self.aFmtBold.setShortcut("Ctrl+B")
menuItem.triggered.connect(lambda: self._docAction(nwDocAction.BOLD)) self.aFmtBold.triggered.connect(lambda: self._docAction(nwDocAction.BOLD))
self.fmtMenu.addAction(menuItem) self.fmtMenu.addAction(self.aFmtBold)
# Format > Italic Text # Format > Italic Text
menuItem = QAction("Italic Text", self) self.aFmtItalic = QAction("Italic Text", self)
menuItem.setStatusTip("Make selected text italic") self.aFmtItalic.setStatusTip("Make selected text italic")
menuItem.setShortcut("Ctrl+I") self.aFmtItalic.setShortcut("Ctrl+I")
menuItem.triggered.connect(lambda: self._docAction(nwDocAction.ITALIC)) self.aFmtItalic.triggered.connect(lambda: self._docAction(nwDocAction.ITALIC))
self.fmtMenu.addAction(menuItem) self.fmtMenu.addAction(self.aFmtItalic)
# Format > Underline Text # Format > Underline Text
menuItem = QAction("Underline Text", self) self.aFmtULine = QAction("Underline Text", self)
menuItem.setStatusTip("Underline selected text") self.aFmtULine.setStatusTip("Underline selected text")
menuItem.setShortcut("Ctrl+U") self.aFmtULine.setShortcut("Ctrl+U")
menuItem.triggered.connect(lambda: self._docAction(nwDocAction.U_LINE)) self.aFmtULine.triggered.connect(lambda: self._docAction(nwDocAction.U_LINE))
self.fmtMenu.addAction(menuItem) self.fmtMenu.addAction(self.aFmtULine)
# Edit > Separator # Edit > Separator
self.fmtMenu.addSeparator() self.fmtMenu.addSeparator()
# Format > Double Quotes # Format > Double Quotes
menuItem = QAction("Wrap Double Quotes", self) self.aFmtDQuote = QAction("Wrap Double Quotes", self)
menuItem.setStatusTip("Wrap selected text in double quotes") self.aFmtDQuote.setStatusTip("Wrap selected text in double quotes")
menuItem.setShortcut("Ctrl+D") self.aFmtDQuote.setShortcut("Ctrl+D")
menuItem.triggered.connect(lambda: self._docAction(nwDocAction.D_QUOTE)) self.aFmtDQuote.triggered.connect(lambda: self._docAction(nwDocAction.D_QUOTE))
self.fmtMenu.addAction(menuItem) self.fmtMenu.addAction(self.aFmtDQuote)
# Format > Single Quotes # Format > Single Quotes
menuItem = QAction("Wrap Single Quotes", self) self.aFmtSQuote = QAction("Wrap Single Quotes", self)
menuItem.setStatusTip("Wrap selected text in single quotes") self.aFmtSQuote.setStatusTip("Wrap selected text in single quotes")
menuItem.setShortcut("Ctrl+Shift+D") self.aFmtSQuote.setShortcut("Ctrl+Shift+D")
menuItem.triggered.connect(lambda: self._docAction(nwDocAction.S_QUOTE)) self.aFmtSQuote.triggered.connect(lambda: self._docAction(nwDocAction.S_QUOTE))
self.fmtMenu.addAction(menuItem) self.fmtMenu.addAction(self.aFmtSQuote)
return return
@@ -598,60 +588,61 @@ class GuiMainMenu(QMenuBar):
self.toolsMenu = self.addMenu("&Tools") self.toolsMenu = self.addMenu("&Tools")
# Tools > Move Up # Tools > Move Up
self.toolsMoveUp = QAction("Move Tree Item Up", self) self.aMoveUp = QAction("Move Tree Item Up", self)
self.toolsMoveUp.setStatusTip("Move item up") self.aMoveUp.setStatusTip("Move item up")
self.toolsMoveUp.setShortcut("Ctrl+Shift+Up") self.aMoveUp.setShortcut("Ctrl+Shift+Up")
self.toolsMoveUp.triggered.connect(lambda : self._moveTreeItem(-1)) self.aMoveUp.triggered.connect(lambda : self._moveTreeItem(-1))
self.toolsMenu.addAction(self.toolsMoveUp) self.toolsMenu.addAction(self.aMoveUp)
# Tools > Move Down # Tools > Move Down
self.toolsMoveDown = QAction("Move Tree Item Down", self) self.aMoveDown = QAction("Move Tree Item Down", self)
self.toolsMoveDown.setStatusTip("Move item down") self.aMoveDown.setStatusTip("Move item down")
self.toolsMoveDown.setShortcut("Ctrl+Shift+Down") self.aMoveDown.setShortcut("Ctrl+Shift+Down")
self.toolsMoveDown.triggered.connect(lambda : self._moveTreeItem(1)) self.aMoveDown.triggered.connect(lambda : self._moveTreeItem(1))
self.toolsMenu.addAction(self.toolsMoveDown) self.toolsMenu.addAction(self.aMoveDown)
# Tools > Separator # Tools > Separator
self.toolsMenu.addSeparator() self.toolsMenu.addSeparator()
# Tools > Toggle Spell Check # Tools > Toggle Spell Check
self.toolsSpellCheck = QAction("Check Spelling", self) self.aSpellCheck = QAction("Check Spelling", self)
self.toolsSpellCheck.setStatusTip("Toggle check spelling") self.aSpellCheck.setStatusTip("Toggle check spelling")
self.toolsSpellCheck.setCheckable(True) self.aSpellCheck.setCheckable(True)
self.toolsSpellCheck.setChecked(self.theProject.spellCheck) self.aSpellCheck.setChecked(self.theProject.spellCheck)
self.toolsSpellCheck.toggled.connect(self._toggleSpellCheck) # Here we must used triggered, not toggled, to avoid recursion
self.toolsSpellCheck.setShortcut("Ctrl+F7") self.aSpellCheck.triggered.connect(self._toggleSpellCheck)
self.toolsMenu.addAction(self.toolsSpellCheck) self.aSpellCheck.setShortcut("Ctrl+F7")
self.toolsMenu.addAction(self.aSpellCheck)
# Tools > Update Spell Check # Tools > Update Spell Check
menuItem = QAction("Re-Run Spell Check", self) self.aReRunSpell = QAction("Re-Run Spell Check", self)
menuItem.setStatusTip("Run the spell checker on current document") self.aReRunSpell.setStatusTip("Run the spell checker on current document")
menuItem.setShortcut("F7") self.aReRunSpell.setShortcut("F7")
menuItem.triggered.connect(self.theParent.docEditor.updateSpellCheck) self.aReRunSpell.triggered.connect(self.theParent.docEditor.updateSpellCheck)
self.toolsMenu.addAction(menuItem) self.toolsMenu.addAction(self.aReRunSpell)
# Tools > Separator # Tools > Separator
self.toolsMenu.addSeparator() self.toolsMenu.addSeparator()
# Tools > Rebuild Indices # Tools > Rebuild Indices
menuItem = QAction("Rebuild Index", self) self.aRebuildIndex = QAction("Rebuild Index", self)
menuItem.setStatusTip("Rebuild the tag indices and word counts") self.aRebuildIndex.setStatusTip("Rebuild the tag indices and word counts")
menuItem.setShortcut("F9") self.aRebuildIndex.setShortcut("F9")
menuItem.triggered.connect(self.theParent.rebuildIndex) self.aRebuildIndex.triggered.connect(self.theParent.rebuildIndex)
self.toolsMenu.addAction(menuItem) self.toolsMenu.addAction(self.aRebuildIndex)
# Tools > Backup # Tools > Backup
menuItem = QAction("Backup Project", self) self.aBackupProject = QAction("Backup Project", self)
menuItem.setStatusTip("Backup Project") self.aBackupProject.setStatusTip("Backup Project")
menuItem.triggered.connect(self.theParent.backupProject) self.aBackupProject.triggered.connect(self.theParent.backupProject)
self.toolsMenu.addAction(menuItem) self.toolsMenu.addAction(self.aBackupProject)
# Tools > Settings # Tools > Settings
menuItem = QAction("Preferences", self) self.aPreferences = QAction("Preferences", self)
menuItem.setStatusTip("Preferences") self.aPreferences.setStatusTip("Preferences")
menuItem.setShortcut("Ctrl+,") self.aPreferences.setShortcut("Ctrl+,")
menuItem.triggered.connect(self.theParent.editConfigDialog) self.aPreferences.triggered.connect(self.theParent.editConfigDialog)
self.toolsMenu.addAction(menuItem) self.toolsMenu.addAction(self.aPreferences)
return return
@@ -661,26 +652,26 @@ class GuiMainMenu(QMenuBar):
self.helpMenu = self.addMenu("&Help") self.helpMenu = self.addMenu("&Help")
# Help > About # Help > About
menuItem = QAction("About %s" % nw.__package__, self) self.aAboutNW = QAction("About %s" % nw.__package__, self)
menuItem.setStatusTip("About %s" % nw.__package__) self.aAboutNW.setStatusTip("About %s" % nw.__package__)
menuItem.triggered.connect(self._showAbout) self.aAboutNW.triggered.connect(self._showAbout)
self.helpMenu.addAction(menuItem) self.helpMenu.addAction(self.aAboutNW)
# Help > About Qt5 # Help > About Qt5
menuItem = QAction("About Qt5", self) self.aAboutQt = QAction("About Qt5", self)
menuItem.setStatusTip("About Qt5") self.aAboutQt.setStatusTip("About Qt5")
menuItem.triggered.connect(self._showAboutQt) self.aAboutQt.triggered.connect(self._showAboutQt)
self.helpMenu.addAction(menuItem) self.helpMenu.addAction(self.aAboutQt)
# Help > Separator # Help > Separator
self.helpMenu.addSeparator() self.helpMenu.addSeparator()
# Document > Preview # Document > Preview
menuItem = QAction("Documentation", self) self.aHelp = QAction("Documentation", self)
menuItem.setStatusTip("View documentation") self.aHelp.setStatusTip("View documentation")
menuItem.setShortcut("F1") self.aHelp.setShortcut("F1")
menuItem.triggered.connect(self._openHelp) self.aHelp.triggered.connect(self._openHelp)
self.helpMenu.addAction(menuItem) self.helpMenu.addAction(self.aHelp)
return return
+4 -1
View File
@@ -116,7 +116,10 @@ class GuiMainStatus(QStatusBar):
return return
def setLanguage(self, theLanguage): def setLanguage(self, theLanguage):
self.langBox.setText(NWSpellCheck.expandLanguage(theLanguage)) if theLanguage is None:
self.langBox.setText("None")
else:
self.langBox.setText(NWSpellCheck.expandLanguage(theLanguage))
return return
def setProjectStatus(self, isChanged): def setProjectStatus(self, isChanged):
+23 -8
View File
@@ -18,6 +18,8 @@ from PyQt5.QtGui import (
QColor, QTextCharFormat, QFont, QSyntaxHighlighter, QBrush QColor, QTextCharFormat, QFont, QSyntaxHighlighter, QBrush
) )
from nw.constants import nwUnicode
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
class GuiDocHighlighter(QSyntaxHighlighter): class GuiDocHighlighter(QSyntaxHighlighter):
@@ -157,7 +159,7 @@ class GuiDocHighlighter(QSyntaxHighlighter):
# Non-breaking Space # Non-breaking Space
self.hRules.append(( self.hRules.append((
"[\u00a0]+", { "[%s]+" % nwUnicode.U_NBSP, {
0 : self.hStyles["nobreak"], 0 : self.hStyles["nobreak"],
} }
)) ))
@@ -208,9 +210,19 @@ class GuiDocHighlighter(QSyntaxHighlighter):
} }
)) ))
# Build a QRegExp for each pattern and for the spell checker # Build a QRegExp for each highlight pattern
self.rules = [(QRegularExpression(a),b) for (a,b) in self.hRules] self.rxRules = []
self.spellRx = QRegularExpression(r"\b[^\s]+\b") for regEx, regRules in self.hRules:
hReg = QRegularExpression(regEx)
hReg.setPatternOptions(QRegularExpression.UseUnicodePropertiesOption)
self.rxRules.append((hReg, regRules))
# Build a QRegExp for spell checker
# Include additional characters that the highlighter should
# consider to be word separators
wordSep = "_+"
wordSep += nwUnicode.U_EMDASH
self.spellRx = QRegularExpression("\\b[^\\s%s]+\\b" % wordSep)
self.spellRx.setPatternOptions(QRegularExpression.UseUnicodePropertiesOption) self.spellRx.setPatternOptions(QRegularExpression.UseUnicodePropertiesOption)
return True return True
@@ -260,9 +272,12 @@ class GuiDocHighlighter(QSyntaxHighlighter):
kwFmt.setUnderlineStyle(QTextCharFormat.SpellCheckUnderline) kwFmt.setUnderlineStyle(QTextCharFormat.SpellCheckUnderline)
self.setFormat(xPos, xLen, kwFmt) self.setFormat(xPos, xLen, kwFmt)
# We're done, no need to continue
return
else: else:
# Other text just uses regex # For other text, just use our regex rules
for rX, xFmt in self.rules: for rX, xFmt in self.rxRules:
rxItt = rX.globalMatch(theText, 0) rxItt = rX.globalMatch(theText, 0)
while rxItt.hasNext(): while rxItt.hasNext():
rxMatch = rxItt.next() rxMatch = rxItt.next()
@@ -271,10 +286,10 @@ class GuiDocHighlighter(QSyntaxHighlighter):
xLen = rxMatch.capturedLength(xM) xLen = rxMatch.capturedLength(xM)
self.setFormat(xPos, xLen, xFmt[xM]) self.setFormat(xPos, xLen, xFmt[xM])
if self.theDict is None or not self.spellCheck or theText.startswith("@"): if self.theDict is None or not self.spellCheck:
return return
rxSpell = self.spellRx.globalMatch(theText.replace("_"," "), 0) rxSpell = self.spellRx.globalMatch(theText, 0)
while rxSpell.hasNext(): while rxSpell.hasNext():
rxMatch = rxSpell.next() rxMatch = rxSpell.next()
if not self.theDict.checkWord(rxMatch.captured(0)): if not self.theDict.checkWord(rxMatch.captured(0)):
+37 -1
View File
@@ -148,7 +148,8 @@ class GuiMain(QMainWindow):
self.asDocTimer = QTimer() self.asDocTimer = QTimer()
self.asDocTimer.timeout.connect(self._autoSaveDocument) self.asDocTimer.timeout.connect(self._autoSaveDocument)
# Keyboard Shortcuts # Shortcuts and Actions
self._connectMenuActions()
QShortcut( QShortcut(
Qt.Key_Return, Qt.Key_Return,
self.treeView, self.treeView,
@@ -173,6 +174,7 @@ class GuiMain(QMainWindow):
self.asDocTimer.start() self.asDocTimer.start()
self.statusBar.clearStatus() self.statusBar.clearStatus()
self.showNormal()
if self.mainConf.isFullScreen: if self.mainConf.isFullScreen:
self.toggleFullScreenMode() self.toggleFullScreenMode()
@@ -181,6 +183,8 @@ class GuiMain(QMainWindow):
return return
def clearGUI(self): def clearGUI(self):
"""Wrapper function to clear all sub-elements of the main GUI.
"""
self.treeView.clearTree() self.treeView.clearTree()
self.docEditor.clearEditor() self.docEditor.clearEditor()
self.closeDocViewer() self.closeDocViewer()
@@ -720,6 +724,7 @@ class GuiMain(QMainWindow):
isVisible = not self.isZenMode isVisible = not self.isZenMode
self.treePane.setVisible(isVisible) self.treePane.setVisible(isVisible)
self.statusBar.setVisible(isVisible) self.statusBar.setVisible(isVisible)
self.mainMenu.setVisible(isVisible)
if self.viewPane.isVisible(): if self.viewPane.isVisible():
self.viewPane.setVisible(False) self.viewPane.setVisible(False)
@@ -752,6 +757,35 @@ class GuiMain(QMainWindow):
# Internal Functions # Internal Functions
## ##
def _connectMenuActions(self):
"""Connect to the main window all menu actions that need to be
available also when the main menu is hidden.
"""
self.addAction(self.mainMenu.aSaveProject)
self.addAction(self.mainMenu.aExitNW)
self.addAction(self.mainMenu.aSaveDoc)
self.addAction(self.mainMenu.aFileDetails)
self.addAction(self.mainMenu.aZenMode)
self.addAction(self.mainMenu.aFullScreen)
self.addAction(self.mainMenu.aViewTimeLine)
self.addAction(self.mainMenu.aEditUndo)
self.addAction(self.mainMenu.aEditRedo)
self.addAction(self.mainMenu.aEditCut)
self.addAction(self.mainMenu.aEditCopy)
self.addAction(self.mainMenu.aEditPaste)
self.addAction(self.mainMenu.aSelectAll)
self.addAction(self.mainMenu.aSelectPar)
self.addAction(self.mainMenu.aFmtBold)
self.addAction(self.mainMenu.aFmtItalic)
self.addAction(self.mainMenu.aFmtULine)
self.addAction(self.mainMenu.aFmtDQuote)
self.addAction(self.mainMenu.aFmtSQuote)
self.addAction(self.mainMenu.aSpellCheck)
self.addAction(self.mainMenu.aReRunSpell)
self.addAction(self.mainMenu.aPreferences)
self.addAction(self.mainMenu.aHelp)
return True
def _setWindowTitle(self, projName=None): def _setWindowTitle(self, projName=None):
winTitle = "%s" % nw.__package__ winTitle = "%s" % nw.__package__
if projName is not None: if projName is not None:
@@ -838,6 +872,8 @@ class GuiMain(QMainWindow):
if self.searchBar.isVisible(): if self.searchBar.isVisible():
self.searchBar.setVisible(False) self.searchBar.setVisible(False)
return return
elif self.isZenMode:
self.toggleZenMode()
return return
# END Class GuiMain # END Class GuiMain
+8 -4
View File
@@ -13,6 +13,8 @@
import logging import logging
import nw import nw
from os import path
from nw.constants import isoLanguage from nw.constants import isoLanguage
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -29,6 +31,7 @@ class NWSpellCheck():
def __init__(self): def __init__(self):
self.mainConf = nw.CONFIG self.mainConf = nw.CONFIG
self.projectDict = None self.projectDict = None
self.spellLanguage = None
return return
def setLanguage(self, theLang, projectDict=None): def setLanguage(self, theLang, projectDict=None):
@@ -45,11 +48,10 @@ class NWSpellCheck():
newWord = newWord.strip() newWord = newWord.strip()
self.PROJW.append(newWord) self.PROJW.append(newWord)
try: try:
with open(self.projectDict,mode="w+",encoding="utf-8") as outFile: with open(self.projectDict,mode="a+",encoding="utf-8") as outFile:
for pWord in self.PROJW: outFile.write("%s\n" % newWord)
outFile.write("%s\n" % pWord)
except Exception as e: except Exception as e:
logger.error("Failed to write to project word list at %s" % str(self.projectDict)) logger.error("Failed to add word to project word list %s" % str(self.projectDict))
logger.error(str(e)) logger.error(str(e))
return return
@@ -75,6 +77,8 @@ class NWSpellCheck():
self.PROJW = [] self.PROJW = []
if projectDict is not None: if projectDict is not None:
self.projectDict = projectDict self.projectDict = projectDict
if not path.isfile(projectDict):
return
try: try:
with open(projectDict,mode="r",encoding="utf-8") as wordsFile: with open(projectDict,mode="r",encoding="utf-8") as wordsFile:
for theLine in wordsFile: for theLine in wordsFile:
+2
View File
@@ -32,10 +32,12 @@ class NWSpellEnchant(NWSpellCheck):
""" """
try: try:
self.theDict = enchant.Dict(theLang) self.theDict = enchant.Dict(theLang)
self.spellLanguage = theLang
logger.debug("Enchant spell checking for language %s loaded" % theLang) logger.debug("Enchant spell checking for language %s loaded" % theLang)
except: except:
logger.error("Failed to load enchant spell checking for language %s" % theLang) logger.error("Failed to load enchant spell checking for language %s" % theLang)
self.theDict = NWSpellEnchantDummy() self.theDict = NWSpellEnchantDummy()
self.spellLanguage = None
self._readProjectDictionary(projectDict) self._readProjectDictionary(projectDict)
for pWord in self.PROJW: for pWord in self.PROJW:
+3 -1
View File
@@ -41,9 +41,11 @@ class NWSpellSimple(NWSpellCheck):
self.WORDS.append(theLine.strip().lower()) self.WORDS.append(theLine.strip().lower())
logger.debug("Spell check word list for language %s loaded" % theLang) logger.debug("Spell check word list for language %s loaded" % theLang)
logger.debug("Word list contains %d words" % len(self.WORDS)) logger.debug("Word list contains %d words" % len(self.WORDS))
self.spellLanguage = theLang
except Exception as e: except Exception as e:
logger.error("Failed to load spell check word list for language %s" % theLang) logger.error("Failed to load spell check word list for language %s" % theLang)
logger.error(str(e)) logger.error(str(e))
self.spellLanguage = None
self._readProjectDictionary(projectDict) self._readProjectDictionary(projectDict)
for pWord in self.PROJW: for pWord in self.PROJW:
@@ -104,7 +106,7 @@ class NWSpellSimple(NWSpellCheck):
if theBits[1] != ".dict": if theBits[1] != ".dict":
continue continue
spName = "%s [nternal]" % self.expandLanguage(theBits[0]) spName = "%s [Internal]" % self.expandLanguage(theBits[0])
retList.append((theBits[0], spName)) retList.append((theBits[0], spName))
return retList return retList
@@ -12,6 +12,8 @@ In addition, the editor supports automatic formatting of “quotes”, both doub
If you have the need for it, you can also add text that can be automatically replaced by other text when you generate a preview or export the project. Now, lets auto-replace this A with <A>, and this C with <C>. While <E> is just <E>. Press Ctrl+R to see what this looks like in the view pane. If you have the need for it, you can also add text that can be automatically replaced by other text when you generate a preview or export the project. Now, lets auto-replace this A with <A>, and this C with <C>. While <E> is just <E>. Press Ctrl+R to see what this looks like in the view pane.
The editor also supports non breaking spaces, and the spell checker accepts long dashes—like this—as valid word separators.
#### Some Section Here #### Some Section Here
If you need to split a scene file up into further pieces, you can do so with the level four heading, like above. This is referred to as a section. If you need to split a scene file up into further pieces, you can do so with the level four heading, like above. This is referred to as a section.
+11 -7
View File
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?> <?xml version='1.0' encoding='utf-8'?>
<novelWriterXML appVersion="0.4.1" fileVersion="1.0" timeStamp="2019-11-10 17:08:04"> <novelWriterXML appVersion="0.4.1" fileVersion="1.0" timeStamp="2019-11-16 12:31:19">
<project> <project>
<name>Sample Project</name> <name>Sample Project</name>
<title>Sample Project</title> <title>Sample Project</title>
@@ -9,9 +9,9 @@
</project> </project>
<settings> <settings>
<spellCheck>True</spellCheck> <spellCheck>True</spellCheck>
<lastEdited>6a2d6d5f4f401</lastEdited> <lastEdited>636b6aa9b697b</lastEdited>
<lastViewed>b3e74dbc1f584</lastViewed> <lastViewed>b3e74dbc1f584</lastViewed>
<lastWordCount>849</lastWordCount> <lastWordCount>875</lastWordCount>
<autoReplace> <autoReplace>
<A>B</A> <A>B</A>
<B>E</B> <B>E</B>
@@ -79,10 +79,10 @@
<status>1st Draft</status> <status>1st Draft</status>
<expanded>False</expanded> <expanded>False</expanded>
<layout>SCENE</layout> <layout>SCENE</layout>
<charCount>1076</charCount> <charCount>1199</charCount>
<wordCount>196</wordCount> <wordCount>216</wordCount>
<paraCount>6</paraCount> <paraCount>7</paraCount>
<cursorPos>59</cursorPos> <cursorPos>949</cursorPos>
</item> </item>
<item handle="bc0cbd2a407f3" order="2" parent="e7ded148d6e4a"> <item handle="bc0cbd2a407f3" order="2" parent="e7ded148d6e4a">
<name>Another Scene</name> <name>Another Scene</name>
@@ -118,7 +118,11 @@
<charCount>1692</charCount> <charCount>1692</charCount>
<wordCount>313</wordCount> <wordCount>313</wordCount>
<paraCount>6</paraCount> <paraCount>6</paraCount>
<<<<<<< HEAD
<cursorPos>144</cursorPos> <cursorPos>144</cursorPos>
=======
<cursorPos>530</cursorPos>
>>>>>>> master
</item> </item>
<item handle="88706ddc78b1b" order="5" parent="e7ded148d6e4a"> <item handle="88706ddc78b1b" order="5" parent="e7ded148d6e4a">
<name>Chapter Two</name> <name>Chapter Two</name>
+16
View File
@@ -0,0 +1,16 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import pstats
from os import path
profDir = path.abspath(path.join(path.dirname(__file__),"..","prof"))
print("")
print("Profiles directory: %s" % profDir)
print("")
profMainWindows = pstats.Stats(path.join(profDir,"testMainWindows.prof"))
profMainWindows.sort_stats("cumtime")
profMainWindows.print_stats("nw/")
+1 -1
View File
@@ -77,7 +77,7 @@ def testMainWindows(qtbot, nwTempGUI, nwRef):
assert nwGUI.treeView._getTreeItem("71ee45a3c0db9") is not None assert nwGUI.treeView._getTreeItem("71ee45a3c0db9") is not None
assert nwGUI.treeView._getTreeItem("811786ad1ae74") is not None assert nwGUI.treeView._getTreeItem("811786ad1ae74") is not None
nwGUI.mainMenu.toolsSpellCheck.setChecked(True) nwGUI.mainMenu.aSpellCheck.setChecked(True)
assert nwGUI.mainMenu._toggleSpellCheck() assert nwGUI.mainMenu._toggleSpellCheck()
# Add a Character File # Add a Character File