Make some improvements to the config layout class
This commit is contained in:
@@ -58,8 +58,7 @@ class NConfigLayout(QGridLayout):
|
|||||||
##
|
##
|
||||||
|
|
||||||
def setHelpTextStyle(self, color: QColor | list | tuple, fontScale: float = FONT_SCALE):
|
def setHelpTextStyle(self, color: QColor | list | tuple, fontScale: float = FONT_SCALE):
|
||||||
"""Set the text color for the help text.
|
"""Set the text color for the help text."""
|
||||||
"""
|
|
||||||
if isinstance(color, QColor):
|
if isinstance(color, QColor):
|
||||||
self._helpCol = color
|
self._helpCol = color
|
||||||
else:
|
else:
|
||||||
@@ -68,8 +67,7 @@ class NConfigLayout(QGridLayout):
|
|||||||
return
|
return
|
||||||
|
|
||||||
def setHelpText(self, row: int, text: str):
|
def setHelpText(self, row: int, text: str):
|
||||||
"""Set the text for the help label.
|
"""Set the text for the help label."""
|
||||||
"""
|
|
||||||
if row in self._itemMap:
|
if row in self._itemMap:
|
||||||
qHelp = self._itemMap[row][1]
|
qHelp = self._itemMap[row][1]
|
||||||
if isinstance(qHelp, NHelpLabel):
|
if isinstance(qHelp, NHelpLabel):
|
||||||
@@ -77,8 +75,7 @@ class NConfigLayout(QGridLayout):
|
|||||||
return
|
return
|
||||||
|
|
||||||
def setLabelText(self, row: int, text: str):
|
def setLabelText(self, row: int, text: str):
|
||||||
"""Set the text for the main label.
|
"""Set the text for the main label."""
|
||||||
"""
|
|
||||||
if row in self._itemMap:
|
if row in self._itemMap:
|
||||||
self._itemMap[row](0).setText(text)
|
self._itemMap[row](0).setText(text)
|
||||||
return
|
return
|
||||||
@@ -88,8 +85,7 @@ class NConfigLayout(QGridLayout):
|
|||||||
##
|
##
|
||||||
|
|
||||||
def addGroupLabel(self, label: str):
|
def addGroupLabel(self, label: str):
|
||||||
"""Adds a text label to separate groups of settings.
|
"""Add a text label to separate groups of settings."""
|
||||||
"""
|
|
||||||
hM = CONFIG.pxInt(4)
|
hM = CONFIG.pxInt(4)
|
||||||
qLabel = QLabel("<b>%s</b>" % label)
|
qLabel = QLabel("<b>%s</b>" % label)
|
||||||
qLabel.setContentsMargins(0, hM, 0, hM)
|
qLabel.setContentsMargins(0, hM, 0, hM)
|
||||||
@@ -103,44 +99,35 @@ class NConfigLayout(QGridLayout):
|
|||||||
self, label: str, widget: QWidget, helpText: str | None = None,
|
self, label: str, widget: QWidget, helpText: str | None = None,
|
||||||
unit: str | None = None, button: QWidget | None = None
|
unit: str | None = None, button: QWidget | None = None
|
||||||
) -> int:
|
) -> int:
|
||||||
"""Add a label and a widget as a new row of the grid.
|
"""Add a label and a widget as a new row of the grid."""
|
||||||
"""
|
|
||||||
if isinstance(widget, QWidget):
|
|
||||||
qWidget = widget
|
|
||||||
else:
|
|
||||||
qWidget = None
|
|
||||||
raise ValueError("The widget must be a QWidget")
|
|
||||||
|
|
||||||
wSp = CONFIG.pxInt(8)
|
wSp = CONFIG.pxInt(8)
|
||||||
qLabel = QLabel(label)
|
qLabel = QLabel(label)
|
||||||
qLabel.setIndent(wSp)
|
qLabel.setIndent(wSp)
|
||||||
|
qLabel.setBuddy(widget)
|
||||||
|
|
||||||
qHelp = None
|
qHelp = None
|
||||||
if helpText is not None:
|
if helpText is not None:
|
||||||
qHelp = NHelpLabel(str(helpText), self._helpCol, self._fontScale)
|
qHelp = NHelpLabel(str(helpText), self._helpCol, self._fontScale)
|
||||||
qHelp.setIndent(wSp)
|
qHelp.setIndent(wSp)
|
||||||
|
|
||||||
labelBox = QVBoxLayout()
|
labelBox = QVBoxLayout()
|
||||||
labelBox.addWidget(qLabel)
|
labelBox.addWidget(qLabel)
|
||||||
labelBox.addWidget(qHelp)
|
labelBox.addWidget(qHelp)
|
||||||
labelBox.setSpacing(0)
|
labelBox.setSpacing(0)
|
||||||
labelBox.addStretch(1)
|
labelBox.addStretch(1)
|
||||||
|
|
||||||
self.addLayout(labelBox, self._nextRow, 0, 1, 1, Qt.AlignLeft | Qt.AlignTop)
|
self.addLayout(labelBox, self._nextRow, 0, 1, 1, Qt.AlignLeft | Qt.AlignTop)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self.addWidget(qLabel, self._nextRow, 0, 1, 1, Qt.AlignLeft | Qt.AlignTop)
|
self.addWidget(qLabel, self._nextRow, 0, 1, 1, Qt.AlignLeft | Qt.AlignTop)
|
||||||
|
|
||||||
if isinstance(unit, str):
|
if isinstance(unit, str):
|
||||||
controlBox = QHBoxLayout()
|
controlBox = QHBoxLayout()
|
||||||
controlBox.addWidget(qWidget, 0, Qt.AlignVCenter)
|
controlBox.addWidget(widget, 0, Qt.AlignVCenter)
|
||||||
controlBox.addWidget(QLabel(unit), 0, Qt.AlignVCenter)
|
controlBox.addWidget(QLabel(unit), 0, Qt.AlignVCenter)
|
||||||
controlBox.setSpacing(wSp)
|
controlBox.setSpacing(wSp)
|
||||||
self.addLayout(controlBox, self._nextRow, 1, 1, 1, Qt.AlignRight | Qt.AlignTop)
|
self.addLayout(controlBox, self._nextRow, 1, 1, 1, Qt.AlignRight | Qt.AlignTop)
|
||||||
|
|
||||||
elif isinstance(button, QAbstractButton):
|
elif isinstance(button, QAbstractButton):
|
||||||
controlBox = QHBoxLayout()
|
controlBox = QHBoxLayout()
|
||||||
controlBox.addWidget(qWidget, 0, Qt.AlignVCenter)
|
controlBox.addWidget(widget, 0, Qt.AlignVCenter)
|
||||||
controlBox.addWidget(button, 0, Qt.AlignVCenter)
|
controlBox.addWidget(button, 0, Qt.AlignVCenter)
|
||||||
controlBox.setSpacing(wSp)
|
controlBox.setSpacing(wSp)
|
||||||
self.addLayout(controlBox, self._nextRow, 1, 1, 1, Qt.AlignRight | Qt.AlignTop)
|
self.addLayout(controlBox, self._nextRow, 1, 1, 1, Qt.AlignRight | Qt.AlignTop)
|
||||||
@@ -151,14 +138,12 @@ class NConfigLayout(QGridLayout):
|
|||||||
qLayout.addWidget(widget)
|
qLayout.addWidget(widget)
|
||||||
self.addLayout(qLayout, self._nextRow, 1, 1, 1, Qt.AlignRight | Qt.AlignTop)
|
self.addLayout(qLayout, self._nextRow, 1, 1, 1, Qt.AlignRight | Qt.AlignTop)
|
||||||
else:
|
else:
|
||||||
self.addWidget(qWidget, self._nextRow, 1, 1, 1, Qt.AlignRight | Qt.AlignTop)
|
self.addWidget(widget, self._nextRow, 1, 1, 1, Qt.AlignRight | Qt.AlignTop)
|
||||||
|
|
||||||
qLabel.setBuddy(qWidget)
|
|
||||||
|
|
||||||
self.setRowStretch(self._nextRow, 0)
|
self.setRowStretch(self._nextRow, 0)
|
||||||
self.setRowStretch(self._nextRow+1, 1)
|
self.setRowStretch(self._nextRow+1, 1)
|
||||||
|
|
||||||
self._itemMap[self._nextRow] = (qLabel, qHelp, qWidget)
|
self._itemMap[self._nextRow] = (qLabel, qHelp, widget)
|
||||||
self._nextRow += 1
|
self._nextRow += 1
|
||||||
|
|
||||||
return self._nextRow - 1
|
return self._nextRow - 1
|
||||||
@@ -187,8 +172,7 @@ class NSimpleLayout(QGridLayout):
|
|||||||
##
|
##
|
||||||
|
|
||||||
def addGroupLabel(self, label: str):
|
def addGroupLabel(self, label: str):
|
||||||
"""Adds a text label to separate groups of settings.
|
"""Add a text label to separate groups of settings."""
|
||||||
"""
|
|
||||||
hM = CONFIG.pxInt(4)
|
hM = CONFIG.pxInt(4)
|
||||||
qLabel = QLabel("<b>%s</b>" % label)
|
qLabel = QLabel("<b>%s</b>" % label)
|
||||||
qLabel.setContentsMargins(0, hM, 0, hM)
|
qLabel.setContentsMargins(0, hM, 0, hM)
|
||||||
@@ -199,14 +183,7 @@ class NSimpleLayout(QGridLayout):
|
|||||||
return
|
return
|
||||||
|
|
||||||
def addRow(self, label: str, widget: QWidget):
|
def addRow(self, label: str, widget: QWidget):
|
||||||
"""Add a label and a widget as a new row of the grid.
|
"""Add a label and a widget as a new row of the grid."""
|
||||||
"""
|
|
||||||
if isinstance(widget, QWidget):
|
|
||||||
qWidget = widget
|
|
||||||
else:
|
|
||||||
qWidget = None
|
|
||||||
raise ValueError("The widget must be a QWidget")
|
|
||||||
|
|
||||||
wSp = CONFIG.pxInt(8)
|
wSp = CONFIG.pxInt(8)
|
||||||
qLabel = QLabel(label)
|
qLabel = QLabel(label)
|
||||||
qLabel.setIndent(wSp)
|
qLabel.setIndent(wSp)
|
||||||
@@ -217,9 +194,9 @@ class NSimpleLayout(QGridLayout):
|
|||||||
qLayout.addWidget(widget)
|
qLayout.addWidget(widget)
|
||||||
self.addLayout(qLayout, self._nextRow, 1, 1, 1, Qt.AlignRight | Qt.AlignTop)
|
self.addLayout(qLayout, self._nextRow, 1, 1, 1, Qt.AlignRight | Qt.AlignTop)
|
||||||
else:
|
else:
|
||||||
self.addWidget(qWidget, self._nextRow, 1, 1, 1, Qt.AlignRight | Qt.AlignTop)
|
self.addWidget(widget, self._nextRow, 1, 1, 1, Qt.AlignRight | Qt.AlignTop)
|
||||||
|
|
||||||
qLabel.setBuddy(qWidget)
|
qLabel.setBuddy(widget)
|
||||||
|
|
||||||
self.setRowStretch(self._nextRow, 0)
|
self.setRowStretch(self._nextRow, 0)
|
||||||
self.setRowStretch(self._nextRow+1, 1)
|
self.setRowStretch(self._nextRow+1, 1)
|
||||||
|
|||||||
Reference in New Issue
Block a user