GUI: pgroup is now a combo box, or can be typed and has a completer. currently limited to user pgroups
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
from PySide6.QtWidgets import QDialog, QLineEdit, QVBoxLayout, QPushButton, QLabel
|
||||
from PySide6.QtCore import Qt
|
||||
from PySide6.QtWidgets import QDialog, QLineEdit, QVBoxLayout, QPushButton, QLabel, QComboBox, QCompleter
|
||||
|
||||
|
||||
class PGroupDialog(QDialog):
|
||||
def __init__(self, curr_pgroup: str | None = None, parent=None):
|
||||
def __init__(self, curr_pgroup: str | None = None, pgroups: list[str] | None = None, parent=None):
|
||||
super().__init__(parent)
|
||||
self.setWindowTitle("Change current p-group")
|
||||
self.setMinimumWidth(300)
|
||||
@@ -14,11 +15,21 @@ class PGroupDialog(QDialog):
|
||||
self.label = QLabel("Set p-group:", self)
|
||||
layout.addWidget(self.label)
|
||||
|
||||
# Add a text entry field
|
||||
self.text_entry = QLineEdit(self)
|
||||
if curr_pgroup is not None:
|
||||
self.text_entry.setText(curr_pgroup)
|
||||
layout.addWidget(self.text_entry)
|
||||
self.combo = QComboBox(self)
|
||||
self.combo.setEditable(True)
|
||||
items = [str(p) for p in (pgroups or []) if p is not None and str(p).strip()]
|
||||
self.combo.addItems(items)
|
||||
|
||||
completer = QCompleter(items, self)
|
||||
completer.setCaseSensitivity(Qt.CaseInsensitive)
|
||||
completer.setFilterMode(Qt.MatchFlag.MatchContains) # requires Qt import; fallback to default if not desired
|
||||
self.combo.setCompleter(completer)
|
||||
|
||||
if curr_pgroup and curr_pgroup in items:
|
||||
self.combo.setCurrentText(curr_pgroup)
|
||||
elif curr_pgroup:
|
||||
self.combo.setCurrentText(curr_pgroup)
|
||||
layout.addWidget(self.combo)
|
||||
|
||||
# Create buttons
|
||||
self.ok_button = QPushButton("OK", self)
|
||||
@@ -34,4 +45,5 @@ class PGroupDialog(QDialog):
|
||||
|
||||
def get_input(self):
|
||||
"""Return the input text when the dialog is accepted."""
|
||||
return self.text_entry.text()
|
||||
#return self.text_entry.text()
|
||||
return self.combo.currentText()
|
||||
Reference in New Issue
Block a user