Using global enum class instead of constants in classes.
This commit is contained in:
+16
-16
@@ -18,7 +18,7 @@ from PyQt5.QtGui import QIcon
|
||||
from PyQt5.QtCore import Qt, QSize
|
||||
from PyQt5.QtWidgets import QTreeWidget, QTreeWidgetItem, QTreeWidgetItemIterator, QAbstractItemView
|
||||
|
||||
from nw.project.item import NWItem
|
||||
from nw.enum import nwItemType, nwItemClass
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -60,31 +60,31 @@ class GuiDocTree(QTreeWidget):
|
||||
|
||||
# Figure out where to put the new item
|
||||
if rHandle is None:
|
||||
nwType = NWItem.TYPE_ROOT
|
||||
nwType = nwItemType.ROOT
|
||||
pHandle = None
|
||||
else:
|
||||
rItem = self.theProject.projTree[rHandle]
|
||||
if rItem.itemType == NWItem.TYPE_FILE:
|
||||
if rItem.itemType == nwItemType.FILE:
|
||||
pHandle = rItem.parHandle
|
||||
else:
|
||||
pHandle = rHandle
|
||||
|
||||
# Create the new item
|
||||
if itemType == NWItem.TYPE_FILE:
|
||||
tHandle = self.theProject.newFile("New File", NWItem.CLASS_NONE, pHandle)
|
||||
elif itemType == NWItem.TYPE_FOLDER:
|
||||
if itemType == nwItemType.FILE:
|
||||
tHandle = self.theProject.newFile("New File", nwItemClass.NONE, pHandle)
|
||||
elif itemType == nwItemType.FOLDER:
|
||||
if pHandle is None:
|
||||
logger.error("Failed to add new item.")
|
||||
return
|
||||
pItem = self.theProject.projTree[rHandle]
|
||||
if pItem.itemClass == NWItem.CLASS_NOVEL:
|
||||
tHandle = self.theProject.newFolder("New Chapter", NWItem.CLASS_CHAPTER, pHandle)
|
||||
elif pItem.itemClass == NWItem.CLASS_CHAPTER:
|
||||
tHandle = self.theProject.newFolder("New Chapter", NWItem.CLASS_CHAPTER, pItem.parHandle)
|
||||
if pItem.itemClass == nwItemClass.NOVEL:
|
||||
tHandle = self.theProject.newFolder("New Chapter", nwItemClass.CHAPTER, pHandle)
|
||||
elif pItem.itemClass == nwItemClass.CHAPTER:
|
||||
tHandle = self.theProject.newFolder("New Chapter", nwItemClass.CHAPTER, pItem.parHandle)
|
||||
else:
|
||||
tHandle = self.theProject.newFolder("New Folder", NWItem.CLASS_NONE, pHandle)
|
||||
elif itemType == NWItem.TYPE_ROOT:
|
||||
tHandle = self.theProject.newRoot("Root Folder", NWItem.CLASS_NONE)
|
||||
tHandle = self.theProject.newFolder("New Folder", nwItemClass.NONE, pHandle)
|
||||
elif itemType == nwItemType.ROOT:
|
||||
tHandle = self.theProject.newRoot("Root Folder", nwItemClass.NONE)
|
||||
else:
|
||||
logger.error("Failed to add new item.")
|
||||
return
|
||||
@@ -132,11 +132,11 @@ class GuiDocTree(QTreeWidget):
|
||||
else:
|
||||
self.theMap[pHandle].addChild(newItem)
|
||||
newItem.setExpanded(nwItem.isExpanded)
|
||||
if nwItem.itemType == NWItem.TYPE_ROOT:
|
||||
if nwItem.itemType == nwItemType.ROOT:
|
||||
newItem.setIcon(0, QIcon.fromTheme("drive-harddisk"))
|
||||
elif nwItem.itemType == NWItem.TYPE_FOLDER:
|
||||
elif nwItem.itemType == nwItemType.FOLDER:
|
||||
newItem.setIcon(0, QIcon.fromTheme("folder"))
|
||||
elif nwItem.itemType == NWItem.TYPE_FILE:
|
||||
elif nwItem.itemType == nwItemType.FILE:
|
||||
newItem.setIcon(0, QIcon.fromTheme("x-office-document"))
|
||||
return True
|
||||
|
||||
|
||||
+5
-5
@@ -18,11 +18,11 @@ from PyQt5.QtWidgets import qApp, QWidget, QMainWindow, QHBoxLayout, QVBoxL
|
||||
from PyQt5.QtCore import Qt, QSize
|
||||
from PyQt5.QtGui import QIcon, QStandardItemModel
|
||||
|
||||
from nw.enum import nwItemType
|
||||
from nw.gui.doctree import GuiDocTree
|
||||
from nw.gui.doceditor import GuiDocEditor
|
||||
from nw.gui.projecteditor import GuiProjectEditor
|
||||
from nw.project.project import NWProject
|
||||
from nw.project.item import NWItem
|
||||
from nw.project.document import NWDoc
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -149,7 +149,7 @@ class GuiMain(QMainWindow):
|
||||
tHandle = tItem.text(3)
|
||||
logger.verbose("User double clicked tree item with handle %s" % tHandle)
|
||||
nwItem = self.theProject.getItem(tHandle)
|
||||
if nwItem.itemType == NWItem.TYPE_FILE:
|
||||
if nwItem.itemType == nwItemType.FILE:
|
||||
logger.verbose("Requested item %s is a file" % tHandle)
|
||||
self.openDocument(tHandle)
|
||||
else:
|
||||
@@ -396,21 +396,21 @@ class GuiMain(QMainWindow):
|
||||
tbRootNew = QAction(QIcon.fromTheme("folder-new"), "New Root Folder (Ctrl+Alt+N)", toolBar)
|
||||
tbRootNew.setShortcut("Ctrl+Alt+N")
|
||||
tbRootNew.setStatusTip("Create New Root Folder")
|
||||
tbRootNew.triggered.connect(lambda: self.treeView.newTreeItem(NWItem.TYPE_ROOT))
|
||||
tbRootNew.triggered.connect(lambda: self.treeView.newTreeItem(nwItemType.ROOT))
|
||||
toolBar.addAction(tbRootNew)
|
||||
|
||||
# Folder > New
|
||||
tbFolderNew = QAction(QIcon.fromTheme("folder-new"), "New Folder (Ctrl+Shift+N)", toolBar)
|
||||
tbFolderNew.setShortcut("Ctrl+Shift+N")
|
||||
tbFolderNew.setStatusTip("Create New Chapter or Folder")
|
||||
tbFolderNew.triggered.connect(lambda: self.treeView.newTreeItem(NWItem.TYPE_FOLDER))
|
||||
tbFolderNew.triggered.connect(lambda: self.treeView.newTreeItem(nwItemType.FOLDER))
|
||||
toolBar.addAction(tbFolderNew)
|
||||
|
||||
# Document > New
|
||||
tbDocNew = QAction(QIcon.fromTheme("document-new"), "New Document (Ctrl+N)", toolBar)
|
||||
tbDocNew.setShortcut("Ctrl+N")
|
||||
tbDocNew.setStatusTip("Create New Document")
|
||||
tbDocNew.triggered.connect(lambda: self.treeView.newTreeItem(NWItem.TYPE_FILE))
|
||||
tbDocNew.triggered.connect(lambda: self.treeView.newTreeItem(nwItemType.FILE))
|
||||
toolBar.addAction(tbDocNew)
|
||||
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user