Add some minor code cleanup

This commit is contained in:
Veronica Berglyd Olsen
2024-12-30 16:55:54 +01:00
parent 6448f05557
commit 4a6511b39f
3 changed files with 19 additions and 23 deletions
+18 -18
View File
@@ -371,11 +371,11 @@ class _StatusPage(NFixedPage):
self.dnButton.clicked.connect(qtLambda(self._moveItem, 1)) self.dnButton.clicked.connect(qtLambda(self._moveItem, 1))
# Edit Form # Edit Form
self.editName = QLineEdit(self) self.labelText = QLineEdit(self)
self.editName.setMaxLength(40) self.labelText.setMaxLength(40)
self.editName.setPlaceholderText(self.tr("Select item to edit")) self.labelText.setPlaceholderText(self.tr("Select item to edit"))
self.editName.setEnabled(False) self.labelText.setEnabled(False)
self.editName.textEdited.connect(self._onNameEdit) self.labelText.textEdited.connect(self._onNameEdit)
buttonStyle = ( buttonStyle = (
f"QToolButton {{padding: 0 {bPd}px;}} " f"QToolButton {{padding: 0 {bPd}px;}} "
@@ -418,7 +418,7 @@ class _StatusPage(NFixedPage):
self.listControls.addStretch(1) self.listControls.addStretch(1)
self.editBox = QHBoxLayout() self.editBox = QHBoxLayout()
self.editBox.addWidget(self.editName, 1) self.editBox.addWidget(self.labelText, 1)
self.editBox.addWidget(self.colorButton, 0) self.editBox.addWidget(self.colorButton, 0)
self.editBox.addWidget(self.shapeButton, 0) self.editBox.addWidget(self.shapeButton, 0)
@@ -522,20 +522,20 @@ class _StatusPage(NFixedPage):
self._shape = entry.shape self._shape = entry.shape
self._setButtonIcons() self._setButtonIcons()
self.editName.setText(entry.name) self.labelText.setText(entry.name)
self.editName.selectAll() self.labelText.selectAll()
self.editName.setFocus() self.labelText.setFocus()
self.editName.setEnabled(True) self.labelText.setEnabled(True)
self.colorButton.setEnabled(True) self.colorButton.setEnabled(True)
self.shapeButton.setEnabled(True) self.shapeButton.setEnabled(True)
else: else:
self._color = QColor(100, 100, 100) self._color = QColor(100, 100, 100)
self._shape = nwStatusShape.SQUARE self._shape = nwStatusShape.SQUARE
self._setButtonIcons() self._setButtonIcons()
self.editName.setText("") self.labelText.setText("")
self.editName.setEnabled(False) self.labelText.setEnabled(False)
self.colorButton.setEnabled(False) self.colorButton.setEnabled(False)
self.shapeButton.setEnabled(False) self.shapeButton.setEnabled(False)
return return
@@ -639,7 +639,7 @@ class _ReplacePage(NFixedPage):
self.listBox.setIndentation(0) self.listBox.setIndentation(0)
self.listBox.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows) self.listBox.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows)
self.listBox.setSelectionMode(QAbstractItemView.SelectionMode.SingleSelection) self.listBox.setSelectionMode(QAbstractItemView.SelectionMode.SingleSelection)
self.listBox.itemSelectionChanged.connect(self._selectionChanged) self.listBox.itemSelectionChanged.connect(self._onSelectionChanged)
for aKey, aVal in SHARED.project.data.autoReplace.items(): for aKey, aVal in SHARED.project.data.autoReplace.items():
newItem = QTreeWidgetItem(["<%s>" % aKey, aVal]) newItem = QTreeWidgetItem(["<%s>" % aKey, aVal])
@@ -650,10 +650,10 @@ class _ReplacePage(NFixedPage):
# List Controls # List Controls
self.addButton = NIconToolButton(self, iSz, "add") self.addButton = NIconToolButton(self, iSz, "add")
self.addButton.clicked.connect(self._addEntry) self.addButton.clicked.connect(self._onEntryCreated)
self.delButton = NIconToolButton(self, iSz, "remove") self.delButton = NIconToolButton(self, iSz, "remove")
self.delButton.clicked.connect(self._delEntry) self.delButton.clicked.connect(self._onEntryDeleted)
# Edit Form # Edit Form
self.editKey = QLineEdit(self) self.editKey = QLineEdit(self)
@@ -736,7 +736,7 @@ class _ReplacePage(NFixedPage):
return return
@pyqtSlot() @pyqtSlot()
def _selectionChanged(self) -> None: def _onSelectionChanged(self) -> None:
"""Extract the details from the selected item and populate the """Extract the details from the selected item and populate the
edit form. edit form.
""" """
@@ -755,14 +755,14 @@ class _ReplacePage(NFixedPage):
return return
@pyqtSlot() @pyqtSlot()
def _addEntry(self) -> None: def _onEntryCreated(self) -> None:
"""Add a new list entry.""" """Add a new list entry."""
key = f"<keyword{self.listBox.topLevelItemCount() + 1:d}>" key = f"<keyword{self.listBox.topLevelItemCount() + 1:d}>"
self.listBox.addTopLevelItem(QTreeWidgetItem([key, ""])) self.listBox.addTopLevelItem(QTreeWidgetItem([key, ""]))
return return
@pyqtSlot() @pyqtSlot()
def _delEntry(self) -> None: def _onEntryDeleted(self) -> None:
"""Delete the selected entry.""" """Delete the selected entry."""
if item := self._getSelectedItem(): if item := self._getSelectedItem():
self.listBox.takeTopLevelItem(self.listBox.indexOfTopLevelItem(item)) self.listBox.takeTopLevelItem(self.listBox.indexOfTopLevelItem(item))
-4
View File
@@ -957,12 +957,8 @@ class GuiMain(QMainWindow):
docEditor = True docEditor = True
elif self.docViewer.isAncestorOf(new): elif self.docViewer.isAncestorOf(new):
docViewer = True docViewer = True
self.docEditor.changeFocusState(docEditor) self.docEditor.changeFocusState(docEditor)
self.docViewer.changeFocusState(docViewer) self.docViewer.changeFocusState(docViewer)
logger.debug("Main focus switched to: %s", type(new).__name__)
return return
@pyqtSlot(bool) @pyqtSlot(bool)
@@ -349,7 +349,7 @@ def testDlgProjSettings_Replace(qtbot, monkeypatch, nwGUI, projPath, mockRnd):
# Nothing to save or delete # Nothing to save or delete
replace.listBox.clearSelection() replace.listBox.clearSelection()
replace._delEntry() replace._onEntryDeleted()
assert replace.listBox.topLevelItemCount() == 2 assert replace.listBox.topLevelItemCount() == 2
# Create a new entry # Create a new entry