Head r1264

This commit is contained in:
Jon Tibble 2011-02-03 21:49:37 +00:00
commit 293bb8ce33
2 changed files with 67 additions and 52 deletions

View File

@ -67,6 +67,7 @@ class Ui_AlertDialog(object):
self.saveButton.setObjectName(u'saveButton') self.saveButton.setObjectName(u'saveButton')
self.manageButtonLayout.addWidget(self.saveButton) self.manageButtonLayout.addWidget(self.saveButton)
self.deleteButton = delete_push_button(alertDialog) self.deleteButton = delete_push_button(alertDialog)
self.deleteButton.setEnabled(False)
self.manageButtonLayout.addWidget(self.deleteButton) self.manageButtonLayout.addWidget(self.deleteButton)
self.manageButtonLayout.addStretch() self.manageButtonLayout.addStretch()
self.alertDialogLayout.addLayout(self.manageButtonLayout, 1, 1) self.alertDialogLayout.addLayout(self.manageButtonLayout, 1, 1)
@ -74,11 +75,13 @@ class Ui_AlertDialog(object):
self.buttonBox.addButton(QtGui.QDialogButtonBox.Close) self.buttonBox.addButton(QtGui.QDialogButtonBox.Close)
displayIcon = build_icon(u':/general/general_live.png') displayIcon = build_icon(u':/general/general_live.png')
self.displayButton = QtGui.QPushButton(alertDialog) self.displayButton = QtGui.QPushButton(alertDialog)
self.displayButton.setEnabled(False)
self.displayButton.setIcon(displayIcon) self.displayButton.setIcon(displayIcon)
self.displayButton.setObjectName(u'displayButton') self.displayButton.setObjectName(u'displayButton')
self.buttonBox.addButton(self.displayButton, self.buttonBox.addButton(self.displayButton,
QtGui.QDialogButtonBox.ActionRole) QtGui.QDialogButtonBox.ActionRole)
self.displayCloseButton = QtGui.QPushButton(alertDialog) self.displayCloseButton = QtGui.QPushButton(alertDialog)
self.displayCloseButton.setEnabled(False)
self.displayCloseButton.setIcon(displayIcon) self.displayCloseButton.setIcon(displayIcon)
self.displayCloseButton.setObjectName(u'displayCloseButton') self.displayCloseButton.setObjectName(u'displayCloseButton')
self.buttonBox.addButton(self.displayCloseButton, self.buttonBox.addButton(self.displayCloseButton,

View File

@ -44,20 +44,22 @@ class AlertForm(QtGui.QDialog, Ui_AlertDialog):
self.item_id = None self.item_id = None
QtGui.QDialog.__init__(self, plugin.formparent) QtGui.QDialog.__init__(self, plugin.formparent)
self.setupUi(self) self.setupUi(self)
QtCore.QObject.connect(self.displayButton, QtCore.SIGNAL(u'clicked()'), QtCore.QObject.connect(self.displayButton,
self.onDisplayClicked) QtCore.SIGNAL(u'clicked()'), self.onDisplayClicked)
QtCore.QObject.connect(self.displayCloseButton, QtCore.QObject.connect(self.displayCloseButton,
QtCore.SIGNAL(u'clicked()'), self.onDisplayCloseClicked) QtCore.SIGNAL(u'clicked()'), self.onDisplayCloseClicked)
QtCore.QObject.connect(self.alertTextEdit, QtCore.QObject.connect(self.alertTextEdit,
QtCore.SIGNAL(u'textChanged(const QString&)'), self.onTextChanged) QtCore.SIGNAL(u'textChanged(const QString&)'), self.onTextChanged)
QtCore.QObject.connect(self.newButton, QtCore.SIGNAL(u'clicked()'), QtCore.QObject.connect(self.newButton,
self.onNewClick) QtCore.SIGNAL(u'clicked()'), self.onNewClick)
QtCore.QObject.connect(self.saveButton, QtCore.SIGNAL(u'clicked()'), QtCore.QObject.connect(self.saveButton,
self.onSaveClick) QtCore.SIGNAL(u'clicked()'), self.onSaveClick)
QtCore.QObject.connect(self.alertListWidget, QtCore.QObject.connect(self.alertListWidget,
QtCore.SIGNAL(u'doubleClicked(QModelIndex)'), self.onDoubleClick) QtCore.SIGNAL(u'doubleClicked(QModelIndex)'), self.onDoubleClick)
QtCore.QObject.connect(self.alertListWidget, QtCore.QObject.connect(self.alertListWidget,
QtCore.SIGNAL(u'clicked(QModelIndex)'), self.onSingleClick) QtCore.SIGNAL(u'clicked(QModelIndex)'), self.onSingleClick)
QtCore.QObject.connect(self.alertListWidget,
QtCore.SIGNAL(u'currentRowChanged(int)'), self.onCurrentRowChanged)
def loadList(self): def loadList(self):
""" """
@ -70,12 +72,9 @@ class AlertForm(QtGui.QDialog, Ui_AlertDialog):
item_name = QtGui.QListWidgetItem(alert.text) item_name = QtGui.QListWidgetItem(alert.text)
item_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(alert.id)) item_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(alert.id))
self.alertListWidget.addItem(item_name) self.alertListWidget.addItem(item_name)
self.saveButton.setEnabled(False)
self.deleteButton.setEnabled(False)
def onDisplayClicked(self): def onDisplayClicked(self):
if self.triggerAlert(unicode(self.alertTextEdit.text())): self.triggerAlert(unicode(self.alertTextEdit.text()))
self.loadList()
def onDisplayCloseClicked(self): def onDisplayCloseClicked(self):
if self.triggerAlert(unicode(self.alertTextEdit.text())): if self.triggerAlert(unicode(self.alertTextEdit.text())):
@ -93,8 +92,6 @@ class AlertForm(QtGui.QDialog, Ui_AlertDialog):
self.alertListWidget.takeItem(row) self.alertListWidget.takeItem(row)
self.item_id = None self.item_id = None
self.alertTextEdit.setText(u'') self.alertTextEdit.setText(u'')
self.saveButton.setEnabled(False)
self.deleteButton.setEnabled(False)
def onNewClick(self): def onNewClick(self):
if len(self.alertTextEdit.text()) == 0: if len(self.alertTextEdit.text()) == 0:
@ -133,30 +130,26 @@ class AlertForm(QtGui.QDialog, Ui_AlertDialog):
""" """
List item has been double clicked to display it List item has been double clicked to display it
""" """
items = self.alertListWidget.selectedIndexes() item = self.alertListWidget.selectedIndexes()[0]
for item in items: bitem = self.alertListWidget.item(item.row())
bitem = self.alertListWidget.item(item.row()) self.triggerAlert(unicode(bitem.text()))
self.triggerAlert(unicode(bitem.text())) self.alertTextEdit.setText(unicode(bitem.text()))
self.alertTextEdit.setText(unicode(bitem.text())) self.item_id = (bitem.data(QtCore.Qt.UserRole)).toInt()[0]
self.item_id = (bitem.data(QtCore.Qt.UserRole)).toInt()[0]
self.saveButton.setEnabled(False) self.saveButton.setEnabled(False)
self.deleteButton.setEnabled(True)
def onSingleClick(self): def onSingleClick(self):
""" """
List item has been single clicked to add it to List item has been single clicked to add it to
the edit field so it can be changed. the edit field so it can be changed.
""" """
items = self.alertListWidget.selectedIndexes() item = self.alertListWidget.selectedIndexes()[0]
for item in items: bitem = self.alertListWidget.item(item.row())
bitem = self.alertListWidget.item(item.row()) self.alertTextEdit.setText(unicode(bitem.text()))
self.alertTextEdit.setText(unicode(bitem.text())) self.item_id = (bitem.data(QtCore.Qt.UserRole)).toInt()[0]
self.item_id = (bitem.data(QtCore.Qt.UserRole)).toInt()[0]
# If the alert does not contain '<>' we clear the ParameterEdit field. # If the alert does not contain '<>' we clear the ParameterEdit field.
if unicode(self.alertTextEdit.text()).find(u'<>') == -1: if unicode(self.alertTextEdit.text()).find(u'<>') == -1:
self.parameterEdit.setText(u'') self.parameterEdit.setText(u'')
self.saveButton.setEnabled(False) self.saveButton.setEnabled(False)
self.deleteButton.setEnabled(True)
def triggerAlert(self, text): def triggerAlert(self, text):
""" """
@ -165,30 +158,49 @@ class AlertForm(QtGui.QDialog, Ui_AlertDialog):
``text`` ``text``
The alert text (unicode). The alert text (unicode).
""" """
if text: if not text:
# We found '<>' in the alert text, but the ParameterEdit field is return False
# empty. # We found '<>' in the alert text, but the ParameterEdit field is empty.
if text.find(u'<>') != -1 and not self.parameterEdit.text() and \ if text.find(u'<>') != -1 and not self.parameterEdit.text() and \
QtGui.QMessageBox.question(self, QtGui.QMessageBox.question(self,
translate('AlertPlugin.AlertForm', 'No Parameter found'), translate('AlertPlugin.AlertForm', 'No Parameter found'),
translate('AlertPlugin.AlertForm', 'You have not entered a ' translate('AlertPlugin.AlertForm', 'You have not entered a '
'parameter to be replaced.\nDo you want to continue anyway?'), 'parameter to be replaced.\nDo you want to continue anyway?'),
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.No | QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.No |
QtGui.QMessageBox.Yes)) == QtGui.QMessageBox.No: QtGui.QMessageBox.Yes)) == QtGui.QMessageBox.No:
self.parameterEdit.setFocus() self.parameterEdit.setFocus()
return False return False
# The ParameterEdit field is not empty, but we have not found '<>' # The ParameterEdit field is not empty, but we have not found '<>'
# in the alert text. # in the alert text.
elif text.find(u'<>') == -1 and self.parameterEdit.text() and \ elif text.find(u'<>') == -1 and self.parameterEdit.text() and \
QtGui.QMessageBox.question(self, QtGui.QMessageBox.question(self,
translate('AlertPlugin.AlertForm', 'No Placeholder found'), translate('AlertPlugin.AlertForm', 'No Placeholder found'),
translate('AlertPlugin.AlertForm', 'The alert text does not' translate('AlertPlugin.AlertForm', 'The alert text does not'
' contain \'<>\'.\nDo want to continue anyway?'), ' contain \'<>\'.\nDo want to continue anyway?'),
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.No | QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.No |
QtGui.QMessageBox.Yes)) == QtGui.QMessageBox.No: QtGui.QMessageBox.Yes)) == QtGui.QMessageBox.No:
self.parameterEdit.setFocus() self.parameterEdit.setFocus()
return False return False
text = text.replace(u'<>', unicode(self.parameterEdit.text())) text = text.replace(u'<>', unicode(self.parameterEdit.text()))
self.parent.alertsmanager.displayAlert(text) self.parent.alertsmanager.displayAlert(text)
return True return True
return False
def onCurrentRowChanged(self, row):
"""
Called when the *alertListWidget*'s current row has been changed. This
enables or disables buttons which require an item to act on.
``row``
The row (int). If there is no current row, the value is -1.
"""
if row == -1:
self.displayButton.setEnabled(False)
self.displayCloseButton.setEnabled(False)
self.saveButton.setEnabled(False)
self.deleteButton.setEnabled(False)
else:
self.displayButton.setEnabled(True)
self.displayCloseButton.setEnabled(True)
self.deleteButton.setEnabled(True)
# We do not need to enable the save button, as it is only enabled
# when typing text in the "alertTextEdit".