Use an enum for switching focus instead of hard coded numbers
This commit is contained in:
@@ -6,7 +6,7 @@ from nw.constants.constants import (
|
||||
)
|
||||
from nw.constants.enum import (
|
||||
nwAlert, nwDocAction, nwItemClass, nwItemLayout, nwItemType, nwOutline,
|
||||
nwDocInsert
|
||||
nwDocInsert, nwWidget
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
@@ -28,4 +28,5 @@ __all__ = [
|
||||
"nwItemType",
|
||||
"nwOutline",
|
||||
"nwDocInsert",
|
||||
"nwWidget",
|
||||
]
|
||||
|
||||
@@ -112,6 +112,15 @@ class nwAlert(Enum):
|
||||
|
||||
# END Enum nwAlert
|
||||
|
||||
class nwWidget(Enum):
|
||||
|
||||
TREE = 1
|
||||
EDITOR = 2
|
||||
VIEWER = 3
|
||||
OUTLINE = 4
|
||||
|
||||
# END Enum nwWidget
|
||||
|
||||
class nwOutline(Enum):
|
||||
|
||||
TITLE = 0
|
||||
|
||||
+5
-5
@@ -33,7 +33,7 @@ from PyQt5.QtWidgets import QMenuBar, QAction
|
||||
|
||||
from nw.constants import (
|
||||
nwItemType, nwItemClass, nwDocAction, nwDocInsert, nwKeyWords, nwLabels,
|
||||
nwUnicode
|
||||
nwUnicode, nwWidget
|
||||
)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -469,28 +469,28 @@ class GuiMainMenu(QMenuBar):
|
||||
self.aFocusTree = QAction("Focus Project Tree", self)
|
||||
self.aFocusTree.setStatusTip("Move focus to project tree")
|
||||
self.aFocusTree.setShortcut("Alt+1")
|
||||
self.aFocusTree.triggered.connect(lambda: self.theParent.switchFocus(1))
|
||||
self.aFocusTree.triggered.connect(lambda: self.theParent.switchFocus(nwWidget.TREE))
|
||||
self.viewMenu.addAction(self.aFocusTree)
|
||||
|
||||
# View > Document Pane 1
|
||||
self.aFocusEditor = QAction("Focus Document Editor", self)
|
||||
self.aFocusEditor.setStatusTip("Move focus to left document pane")
|
||||
self.aFocusEditor.setShortcut("Alt+2")
|
||||
self.aFocusEditor.triggered.connect(lambda: self.theParent.switchFocus(2))
|
||||
self.aFocusEditor.triggered.connect(lambda: self.theParent.switchFocus(nwWidget.EDITOR))
|
||||
self.viewMenu.addAction(self.aFocusEditor)
|
||||
|
||||
# View > Document Pane 2
|
||||
self.aFocusView = QAction("Focus Document Viewer", self)
|
||||
self.aFocusView.setStatusTip("Move focus to right document pane")
|
||||
self.aFocusView.setShortcut("Alt+3")
|
||||
self.aFocusView.triggered.connect(lambda: self.theParent.switchFocus(3))
|
||||
self.aFocusView.triggered.connect(lambda: self.theParent.switchFocus(nwWidget.VIEWER))
|
||||
self.viewMenu.addAction(self.aFocusView)
|
||||
|
||||
# View > Outline
|
||||
self.aFocusOutline = QAction("Focus Outline", self)
|
||||
self.aFocusOutline.setStatusTip("Move focus to outline")
|
||||
self.aFocusOutline.setShortcut("Alt+4")
|
||||
self.aFocusOutline.triggered.connect(lambda: self.theParent.switchFocus(4))
|
||||
self.aFocusOutline.triggered.connect(lambda: self.theParent.switchFocus(nwWidget.OUTLINE))
|
||||
self.viewMenu.addAction(self.aFocusOutline)
|
||||
|
||||
# View > Separator
|
||||
|
||||
+7
-7
@@ -46,7 +46,7 @@ from nw.gui import (
|
||||
GuiProjectTree, GuiProjectWizard, GuiTheme, GuiWordList, GuiWritingStats
|
||||
)
|
||||
from nw.core import NWProject, NWDoc, NWIndex
|
||||
from nw.constants import nwItemType, nwItemClass, nwAlert, nwLists
|
||||
from nw.constants import nwItemType, nwItemClass, nwAlert, nwLists, nwWidget
|
||||
from nw.common import getGuiItem, hexToInt
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -810,7 +810,7 @@ class GuiMain(QMainWindow):
|
||||
if tHandle is None:
|
||||
if self.docEditor.anyFocus() or self.isFocusMode:
|
||||
tHandle = self.docEditor.theHandle
|
||||
elif self.treeView.hasFocus():
|
||||
else:
|
||||
tHandle = self.treeView.getSelectedHandle()
|
||||
|
||||
if tHandle is None:
|
||||
@@ -1180,15 +1180,15 @@ class GuiMain(QMainWindow):
|
||||
def switchFocus(self, paneNo):
|
||||
"""Switch focus between main GUI views.
|
||||
"""
|
||||
if paneNo == 1:
|
||||
if paneNo == nwWidget.TREE:
|
||||
self.treeView.setFocus()
|
||||
elif paneNo == 2:
|
||||
elif paneNo == nwWidget.EDITOR:
|
||||
self.mainTabs.setCurrentWidget(self.splitDocs)
|
||||
self.docEditor.setFocus()
|
||||
elif paneNo == 3:
|
||||
elif paneNo == nwWidget.VIEWER:
|
||||
self.mainTabs.setCurrentWidget(self.splitDocs)
|
||||
self.docViewer.setFocus()
|
||||
elif paneNo == 4:
|
||||
elif paneNo == nwWidget.OUTLINE:
|
||||
self.mainTabs.setCurrentWidget(self.splitOutline)
|
||||
self.projView.setFocus()
|
||||
return
|
||||
@@ -1225,7 +1225,7 @@ class GuiMain(QMainWindow):
|
||||
if self.isFocusMode:
|
||||
logger.debug("Activating Focus Mode")
|
||||
self.mainTabs.setCurrentWidget(self.splitDocs)
|
||||
self.switchFocus(2)
|
||||
self.switchFocus(nwWidget.EDITOR)
|
||||
else:
|
||||
logger.debug("Deactivating Focus Mode")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user