Andreas Preikschat has proposed merging lp:~googol-hush/openlp/alerts into lp:openlp.
Requested reviews: Tim Bentley (trb143) - "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. -- https://code.launchpad.net/~googol-hush/openlp/alerts/+merge/43471 Your team OpenLP Core is subscribed to branch lp:openlp.
=== modified file 'openlp/plugins/alerts/forms/alertform.py' --- openlp/plugins/alerts/forms/alertform.py 2010-10-15 14:43:42 +0000 +++ openlp/plugins/alerts/forms/alertform.py 2010-12-12 16:04:12 +0000 @@ -62,6 +62,9 @@ QtCore.SIGNAL(u'clicked(QModelIndex)'), self.onSingleClick) def loadList(self): + """ + Loads the list with alerts. + """ self.AlertListWidget.clear() alerts = self.manager.get_all_objects(AlertItem, order_by_ref=AlertItem.text) @@ -81,12 +84,16 @@ self.close() def onDeleteClick(self): + """ + Deletes the selected item. + """ item = self.AlertListWidget.currentItem() if item: item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0] self.manager.delete_object(AlertItem, item_id) row = self.AlertListWidget.row(item) self.AlertListWidget.takeItem(row) + self.item_id = None self.AlertTextEdit.setText(u'') self.SaveButton.setEnabled(False) self.DeleteButton.setEnabled(False) @@ -96,8 +103,8 @@ QtGui.QMessageBox.information(self, translate('AlertsPlugin.AlertForm', 'New Alert'), translate('AlertsPlugin.AlertForm', 'You haven\'t specified ' - 'any text for your alert. Please type in some text before ' - 'clicking New.')) + 'any text for your alert. Please type in some text before ' + 'clicking New.')) else: alert = AlertItem() alert.text = unicode(self.AlertTextEdit.text()) @@ -107,7 +114,7 @@ def onSaveClick(self): """ - Save an alert + Save the alert, we are editing. """ if self.item_id: alert = self.manager.get_object(AlertItem, self.item_id) @@ -115,14 +122,14 @@ self.manager.save_object(alert) self.item_id = None self.loadList() - else: - self.onNewClick() def onTextChanged(self): """ Enable save button when data has been changed by editing the form """ - self.SaveButton.setEnabled(True) + # Only enable the button, if we are editing an item. + if self.item_id: + self.SaveButton.setEnabled(True) def onDoubleClick(self): """ @@ -131,8 +138,8 @@ items = self.AlertListWidget.selectedIndexes() for item in items: bitem = self.AlertListWidget.item(item.row()) - self.triggerAlert(bitem.text()) - self.AlertTextEdit.setText(bitem.text()) + self.triggerAlert(unicode(bitem.text())) + self.AlertTextEdit.setText(unicode(bitem.text())) self.item_id = (bitem.data(QtCore.Qt.UserRole)).toInt()[0] self.SaveButton.setEnabled(False) self.DeleteButton.setEnabled(True) @@ -145,13 +152,45 @@ items = self.AlertListWidget.selectedIndexes() for item in items: 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] + # 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.DeleteButton.setEnabled(True) def triggerAlert(self, text): + """ + Prepares the alert text for displaying. + + ``text`` + The alert text (unicode). + """ 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())) self.parent.alertsmanager.displayAlert(text) return True === modified file 'openlp/plugins/alerts/lib/alertsmanager.py' --- openlp/plugins/alerts/lib/alertsmanager.py 2010-09-14 18:18:47 +0000 +++ openlp/plugins/alerts/lib/alertsmanager.py 2010-12-12 16:04:12 +0000 @@ -86,7 +86,7 @@ text = self.alertList.pop(0) alertTab = self.parent.alertsTab 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: self.timer_id = self.startTimer(int(alertTab.timeout) * 1000) @@ -94,9 +94,9 @@ """ Time has finished so if our time then request the next Alert if there is one and reset the timer. + ``event`` the QT event that has been triggered. - """ log.debug(u'timer event') if event.timerId() == self.timer_id:
_______________________________________________ Mailing list: https://launchpad.net/~openlp-core Post to : openlp-core@lists.launchpad.net Unsubscribe : https://launchpad.net/~openlp-core More help : https://help.launchpad.net/ListHelp