Fix some widgets without parent, and update template file record keeping

This commit is contained in:
Veronica Berglyd Olsen
2024-02-07 20:37:53 +01:00
parent c420d8ae38
commit bbb23b4bc9
8 changed files with 33 additions and 17 deletions
+2 -2
View File
@@ -186,7 +186,7 @@ class nwLabels:
nwItemClass.ENTITY: QT_TRANSLATE_NOOP("Constant", "Entities"),
nwItemClass.CUSTOM: QT_TRANSLATE_NOOP("Constant", "Custom"),
nwItemClass.ARCHIVE: QT_TRANSLATE_NOOP("Constant", "Archive"),
nwItemClass.TEMPLATES: QT_TRANSLATE_NOOP("Constant", "Templates"),
nwItemClass.TEMPLATE: QT_TRANSLATE_NOOP("Constant", "Templates"),
nwItemClass.TRASH: QT_TRANSLATE_NOOP("Constant", "Trash"),
}
CLASS_ICON = {
@@ -200,7 +200,7 @@ class nwLabels:
nwItemClass.ENTITY: "cls_entity",
nwItemClass.CUSTOM: "cls_custom",
nwItemClass.ARCHIVE: "cls_archive",
nwItemClass.TEMPLATES: "cls_custom",
nwItemClass.TEMPLATE: "cls_template",
nwItemClass.TRASH: "cls_trash",
}
LAYOUT_NAME = {
+7 -3
View File
@@ -337,15 +337,19 @@ class NWItem:
return self._class in (
nwItemClass.NOVEL,
nwItemClass.ARCHIVE,
nwItemClass.TEMPLATES,
nwItemClass.TEMPLATE,
)
def isTemplateFile(self) -> bool:
"""Check if the item is a template file."""
return self._type == nwItemType.FILE and self._class == nwItemClass.TEMPLATE
def documentAllowed(self) -> bool:
"""Check if the item is allowed to be of document layout."""
return self._class in (
nwItemClass.NOVEL,
nwItemClass.ARCHIVE,
nwItemClass.TEMPLATES,
nwItemClass.TEMPLATE,
nwItemClass.TRASH,
)
@@ -354,7 +358,7 @@ class NWItem:
return self._class in (
nwItemClass.NO_CLASS,
nwItemClass.ARCHIVE,
nwItemClass.TEMPLATES,
nwItemClass.TEMPLATE,
nwItemClass.TRASH,
)
+1 -1
View File
@@ -48,7 +48,7 @@ class GuiEditLabel(QDialog):
mSp = CONFIG.pxInt(12)
# Item Label
self.labelValue = QLineEdit()
self.labelValue = QLineEdit(self)
self.labelValue.setMinimumWidth(mVd)
self.labelValue.setMaxLength(200)
self.labelValue.setText(text)
+3 -3
View File
@@ -361,7 +361,7 @@ class _StatusPage(NFixedPage):
self.dnButton.clicked.connect(lambda: self._moveItem(1))
# Edit Form
self.editName = QLineEdit()
self.editName = QLineEdit(self)
self.editName.setMaxLength(40)
self.editName.setPlaceholderText(self.tr("Select item to edit"))
self.editName.setEnabled(False)
@@ -621,12 +621,12 @@ class _ReplacePage(NFixedPage):
self.delButton.clicked.connect(self._delEntry)
# Edit Form
self.editKey = QLineEdit()
self.editKey = QLineEdit(self)
self.editKey.setPlaceholderText(self.tr("Select item to edit"))
self.editKey.setEnabled(False)
self.editKey.setMaxLength(40)
self.editValue = QLineEdit()
self.editValue = QLineEdit(self)
self.editValue.setEnabled(False)
self.editValue.setMaxLength(80)
+1 -1
View File
@@ -75,7 +75,7 @@ class GuiWordList(QDialog):
self.listBox.setDragDropMode(QAbstractItemView.NoDragDrop)
self.listBox.setSortingEnabled(True)
self.newEntry = QLineEdit()
self.newEntry = QLineEdit(self)
self.addButton = QPushButton(SHARED.theme.getIcon("add"), "")
self.addButton.clicked.connect(self._doAdd)
+1 -1
View File
@@ -47,7 +47,7 @@ class nwItemClass(Enum):
ENTITY = 7
CUSTOM = 8
ARCHIVE = 9
TEMPLATES = 10
TEMPLATE = 10
TRASH = 11
# END Enum nwItemClass
+15 -3
View File
@@ -431,7 +431,7 @@ class GuiProjectToolBar(QWidget):
addClass(nwItemClass.ENTITY)
addClass(nwItemClass.CUSTOM)
self.mAddRoot.addSeparator()
addClass(nwItemClass.TEMPLATES)
addClass(nwItemClass.TEMPLATE)
return
@@ -466,6 +466,8 @@ class GuiProjectTree(QTreeWidget):
D_HANDLE = Qt.ItemDataRole.UserRole
D_WORDS = Qt.ItemDataRole.UserRole + 1
templatesUpdated = pyqtSignal(str)
def __init__(self, projView: GuiProjectView) -> None:
super().__init__(parent=projView)
@@ -476,6 +478,7 @@ class GuiProjectTree(QTreeWidget):
# Internal Variables
self._treeMap = {}
self._templateItems = set()
self._timeChanged = 0.0
self._popAlert = None
@@ -1031,6 +1034,16 @@ class GuiProjectTree(QTreeWidget):
trFont.setUnderline(hLevel == "H1")
trItem.setFont(self.C_NAME, trFont)
# Templates
if nwItem.isTemplateFile():
self._templateItems.add(tHandle)
logger.debug("Updated template '%s'", tHandle)
self.templatesUpdated.emit(tHandle)
elif tHandle in self._templateItems:
self._templateItems.discard(tHandle)
logger.debug("Removed template '%s'", tHandle)
self.templatesUpdated.emit(tHandle)
return
def propagateCount(self, tHandle: str, newCount: int, countChildren: bool = False) -> None:
@@ -1360,8 +1373,7 @@ class GuiProjectTree(QTreeWidget):
not including) a given item.
"""
if isinstance(trItem, QTreeWidgetItem):
chCount = trItem.childCount()
for i in range(chCount):
for i in range(trItem.childCount()):
chItem = trItem.child(i)
chItem.setExpanded(isExpanded)
self._recursiveSetExpanded(chItem, isExpanded)
+3 -3
View File
@@ -99,7 +99,7 @@ class GuiWelcome(QDialog):
self.tabNew.cancelNewProject.connect(self._showOpenProjectPage)
self.tabNew.openProjectRequest.connect(self._openProjectPath)
self.mainStack = QStackedWidget()
self.mainStack = QStackedWidget(self)
self.mainStack.addWidget(self.tabOpen)
self.mainStack.addWidget(self.tabNew)
@@ -524,13 +524,13 @@ class _NewProjectForm(QWidget):
# ================
# Project Name
self.projName = QLineEdit()
self.projName = QLineEdit(self)
self.projName.setMaxLength(200)
self.projName.setPlaceholderText(self.tr("Required"))
self.projName.textChanged.connect(self._updateProjPath)
# Author(s)
self.projAuthor = QLineEdit()
self.projAuthor = QLineEdit(self)
self.projAuthor.setMaxLength(200)
self.projAuthor.setPlaceholderText(self.tr("Optional"))