labels
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from PySide6.QtWidgets import (
|
||||
QDialog,
|
||||
QDialogButtonBox,
|
||||
QCheckBox,
|
||||
QFormLayout,
|
||||
QLineEdit,
|
||||
QMessageBox,
|
||||
@@ -11,7 +12,15 @@ from PySide6.QtWidgets import (
|
||||
class ItemOptionsDialog(QDialog):
|
||||
"""Small, extensible options dialog shared by ports and connections."""
|
||||
|
||||
def __init__(self, title: str, name: str, parent=None, *, name_required: bool = True) -> None:
|
||||
def __init__(
|
||||
self,
|
||||
title: str,
|
||||
name: str,
|
||||
parent=None,
|
||||
*,
|
||||
name_required: bool = True,
|
||||
show_name: bool | None = None,
|
||||
) -> None:
|
||||
super().__init__(parent)
|
||||
self.name_required = name_required
|
||||
self.setWindowTitle(title)
|
||||
@@ -21,6 +30,11 @@ class ItemOptionsDialog(QDialog):
|
||||
self.form = QFormLayout()
|
||||
self.name_edit = QLineEdit(name, self)
|
||||
self.form.addRow("Name:", self.name_edit)
|
||||
self.show_name_check = None
|
||||
if show_name is not None:
|
||||
self.show_name_check = QCheckBox("Show name below connection", self)
|
||||
self.show_name_check.setChecked(show_name)
|
||||
self.form.addRow("", self.show_name_check)
|
||||
layout.addLayout(self.form)
|
||||
|
||||
buttons = QDialogButtonBox(
|
||||
@@ -35,6 +49,10 @@ class ItemOptionsDialog(QDialog):
|
||||
def name(self) -> str:
|
||||
return self.name_edit.text().strip()
|
||||
|
||||
@property
|
||||
def show_name(self) -> bool:
|
||||
return bool(self.show_name_check and self.show_name_check.isChecked())
|
||||
|
||||
def accept(self) -> None:
|
||||
if self.name_required and not self.name:
|
||||
QMessageBox.warning(self, "Invalid name", "The name cannot be empty.")
|
||||
|
||||
Reference in New Issue
Block a user