Browse Source

Better error message and dialog box behaviour

master
Nils 3 years ago
parent
commit
9a72de4c58
  1. 32
      qtgui/addclientprompt.py

32
qtgui/addclientprompt.py

@ -47,6 +47,8 @@ class PromptWidget(QtWidgets.QDialog):
self.comboBox = QtWidgets.QComboBox(self)
self.comboBox.setEditable(True)
self.comboBox.currentTextChanged.connect(self.check) #not called when text is changed programatically
if PromptWidget.wordlist:
completer = QtWidgets.QCompleter(PromptWidget.wordlist)
completer.setModelSorting(QtWidgets.QCompleter.CaseInsensitivelySortedModel)
@ -65,22 +67,36 @@ class PromptWidget(QtWidgets.QDialog):
layout.addWidget(self.comboBox)
errorString = QtCore.QCoreApplication.translate("PromptWidget", "Command not accepted!<br>Parameters, --switches and relative paths are not allowed.<br>Use nsm-proxy or write a starter-script instead.")
errorString = QtCore.QCoreApplication.translate("PromptWidget", "Command not found or not accepted!<br>Parameters, --switches and relative paths are not allowed.<br>Use nsm-proxy or write a starter-script instead.")
errorString = "<i>" + errorString + "</i>"
self.errorLabel = QtWidgets.QLabel(errorString)
layout.addWidget(self.errorLabel)
self.errorLabel.hide() #shown in process
self.errorLabel.hide() #shown in process or check
buttonBox = QtWidgets.QDialogButtonBox(QtWidgets.QDialogButtonBox.Ok | QtWidgets.QDialogButtonBox.Cancel)
buttonBox.accepted.connect(self.process)
buttonBox.rejected.connect(self.reject)
layout.addWidget(buttonBox)
self.buttonBox = QtWidgets.QDialogButtonBox(QtWidgets.QDialogButtonBox.Ok | QtWidgets.QDialogButtonBox.Cancel)
self.buttonBox.accepted.connect(self.process)
self.buttonBox.rejected.connect(self.reject)
layout.addWidget(self.buttonBox)
self.exec() #blocks until the dialog gets closed
def abortHandler(self):
pass
def check(self, currentText):
"""Called every keypress.
We do preliminary error and collision checking here, so the engine does not have to throw
an error """
self.errorLabel.hide() #start in good faith
ok = self.buttonBox.button(QtWidgets.QDialogButtonBox.Ok)
if currentText in PromptWidget.wordlist: #this is taken literally. Any extra char or whitespace counts as false
ok.setEnabled(True)
else:
ok.setEnabled(False)
self.errorLabel.show()
def process(self):
"""Careful! Calling this eats python errors without notice.
Make sure your objects exists and your syntax is correct"""
@ -90,8 +106,8 @@ class PromptWidget(QtWidgets.QDialog):
curText = self.comboBox.currentText()
if not curText or curText == " ": #TODO: qt weirdness. This is a case when focus is lost from a valid entry. The field is filled from a chosen value, from the list. But it says " ".
#Do not show the errorLabel. This is a qt bug or so.
return
return
if curText in PromptWidget.wordlist:
api.clientAdd(curText)
logger.info(f"Prompt accepted {curText} and will send it to clientAdd")

Loading…
Cancel
Save