- "Save" button now only saves the alert (if the alert has not created before the save button is disabled). -> the buttons are less confusing

- feedback:
1) If the "alert text" field does not contain "<>" but the parameter field is not empty, then a pop up opens.
2) If the "alert text" field does contain "<>" but the parameter field is empty, a pop up opens.

bzr-revno: 1145
This commit is contained in:
andreas 2010-12-12 17:08:12 +00:00 committed by Tim Bentley
commit e7a40c492f
2 changed files with 50 additions and 11 deletions

View File

@ -62,6 +62,9 @@ class AlertForm(QtGui.QDialog, Ui_AlertDialog):
QtCore.SIGNAL(u'clicked(QModelIndex)'), self.onSingleClick) QtCore.SIGNAL(u'clicked(QModelIndex)'), self.onSingleClick)
def loadList(self): def loadList(self):
"""
Loads the list with alerts.
"""
self.AlertListWidget.clear() self.AlertListWidget.clear()
alerts = self.manager.get_all_objects(AlertItem, alerts = self.manager.get_all_objects(AlertItem,
order_by_ref=AlertItem.text) order_by_ref=AlertItem.text)
@ -81,12 +84,16 @@ class AlertForm(QtGui.QDialog, Ui_AlertDialog):
self.close() self.close()
def onDeleteClick(self): def onDeleteClick(self):
"""
Deletes the selected item.
"""
item = self.AlertListWidget.currentItem() item = self.AlertListWidget.currentItem()
if item: if item:
item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0] item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0]
self.manager.delete_object(AlertItem, item_id) self.manager.delete_object(AlertItem, item_id)
row = self.AlertListWidget.row(item) row = self.AlertListWidget.row(item)
self.AlertListWidget.takeItem(row) self.AlertListWidget.takeItem(row)
self.item_id = None
self.AlertTextEdit.setText(u'') self.AlertTextEdit.setText(u'')
self.SaveButton.setEnabled(False) self.SaveButton.setEnabled(False)
self.DeleteButton.setEnabled(False) self.DeleteButton.setEnabled(False)
@ -107,7 +114,7 @@ class AlertForm(QtGui.QDialog, Ui_AlertDialog):
def onSaveClick(self): def onSaveClick(self):
""" """
Save an alert Save the alert, we are editing.
""" """
if self.item_id: if self.item_id:
alert = self.manager.get_object(AlertItem, self.item_id) alert = self.manager.get_object(AlertItem, self.item_id)
@ -115,13 +122,13 @@ class AlertForm(QtGui.QDialog, Ui_AlertDialog):
self.manager.save_object(alert) self.manager.save_object(alert)
self.item_id = None self.item_id = None
self.loadList() self.loadList()
else:
self.onNewClick()
def onTextChanged(self): def onTextChanged(self):
""" """
Enable save button when data has been changed by editing the form Enable save button when data has been changed by editing the form
""" """
# Only enable the button, if we are editing an item.
if self.item_id:
self.SaveButton.setEnabled(True) self.SaveButton.setEnabled(True)
def onDoubleClick(self): def onDoubleClick(self):
@ -131,8 +138,8 @@ class AlertForm(QtGui.QDialog, Ui_AlertDialog):
items = self.AlertListWidget.selectedIndexes() items = self.AlertListWidget.selectedIndexes()
for item in items: for item in items:
bitem = self.AlertListWidget.item(item.row()) bitem = self.AlertListWidget.item(item.row())
self.triggerAlert(bitem.text()) self.triggerAlert(unicode(bitem.text()))
self.AlertTextEdit.setText(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) self.DeleteButton.setEnabled(True)
@ -145,13 +152,45 @@ class AlertForm(QtGui.QDialog, Ui_AlertDialog):
items = self.AlertListWidget.selectedIndexes() items = self.AlertListWidget.selectedIndexes()
for item in items: for item in items:
bitem = self.AlertListWidget.item(item.row()) bitem = self.AlertListWidget.item(item.row())
self.AlertTextEdit.setText(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 unicode(self.AlertTextEdit.text()).find(u'<>') == -1:
self.ParameterEdit.setText(u'')
self.SaveButton.setEnabled(False) self.SaveButton.setEnabled(False)
self.DeleteButton.setEnabled(True) self.DeleteButton.setEnabled(True)
def triggerAlert(self, text): def triggerAlert(self, text):
"""
Prepares the alert text for displaying.
``text``
The alert text (unicode).
"""
if text: if text:
# We found '<>' in the alert text, but the ParameterEdit field is
# empty.
if text.find(u'<>') != -1 and not self.ParameterEdit.text() and \
QtGui.QMessageBox.question(self, translate(
'AlertPlugin.AlertForm', 'No Parameter found'),
translate('AlertPlugin.AlertForm', 'You have not entered a '
'parameter to be replaced.\nDo you want to continue '
'anyway?'),
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.No |
QtGui.QMessageBox.Yes)) == QtGui.QMessageBox.No:
self.ParameterEdit.setFocus()
return False
# The ParameterEdit field is not empty, but we have not found '<>'
# in the alert text.
elif text.find(u'<>') == -1 and self.ParameterEdit.text() and \
QtGui.QMessageBox.question(self, translate(
'AlertPlugin.AlertForm', 'No Placeholder found'),
translate('AlertPlugin.AlertForm', 'The alert text does not'
' contain \'<>\'.\nDo want to continue anyway?'),
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.No |
QtGui.QMessageBox.Yes)) == QtGui.QMessageBox.No:
self.ParameterEdit.setFocus()
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

View File

@ -86,7 +86,7 @@ class AlertsManager(QtCore.QObject):
text = self.alertList.pop(0) text = self.alertList.pop(0)
alertTab = self.parent.alertsTab alertTab = self.parent.alertsTab
self.parent.liveController.display.alert(text) self.parent.liveController.display.alert(text)
# check to see if we have a timer running # Check to see if we have a timer running.
if self.timer_id == 0: if self.timer_id == 0:
self.timer_id = self.startTimer(int(alertTab.timeout) * 1000) self.timer_id = self.startTimer(int(alertTab.timeout) * 1000)
@ -94,9 +94,9 @@ class AlertsManager(QtCore.QObject):
""" """
Time has finished so if our time then request the next Alert Time has finished so if our time then request the next Alert
if there is one and reset the timer. if there is one and reset the timer.
``event`` ``event``
the QT event that has been triggered. the QT event that has been triggered.
""" """
log.debug(u'timer event') log.debug(u'timer event')
if event.timerId() == self.timer_id: if event.timerId() == self.timer_id: