Andreas Preikschat has proposed merging lp:~googol-hush/openlp/alerts into lp:openlp.
Requested reviews: OpenLP Core (openlp-core) - camelCase for Qt Classes - "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. - docs -- https://code.launchpad.net/~googol-hush/openlp/alerts/+merge/43433 Your team OpenLP Core is requested to review the proposed merge of lp:~googol-hush/openlp/alerts into lp:openlp.
=== modified file 'openlp/plugins/alerts/forms/alertdialog.py' --- openlp/plugins/alerts/forms/alertdialog.py 2010-12-09 17:44:18 +0000 +++ openlp/plugins/alerts/forms/alertdialog.py 2010-12-11 20:32:53 +0000 @@ -29,115 +29,112 @@ from openlp.core.lib import build_icon, translate class Ui_AlertDialog(object): - def setupUi(self, AlertDialog): - AlertDialog.setObjectName(u'AlertDialog') - AlertDialog.resize(567, 440) - AlertDialog.setWindowIcon(build_icon(u':/icon/openlp.org-icon-32.bmp')) - self.AlertDialogLayout = QtGui.QVBoxLayout(AlertDialog) - self.AlertDialogLayout.setSpacing(8) - self.AlertDialogLayout.setMargin(8) - self.AlertDialogLayout.setObjectName(u'AlertDialogLayout') - self.AlertTextLayout = QtGui.QFormLayout() - self.AlertTextLayout.setContentsMargins(0, 0, -1, -1) - self.AlertTextLayout.setSpacing(8) - self.AlertTextLayout.setObjectName(u'AlertTextLayout') - self.AlertEntryLabel = QtGui.QLabel(AlertDialog) + def setupUi(self, alertDialog): + alertDialog.setObjectName(u'alertDialog') + alertDialog.resize(567, 440) + alertDialog.setWindowIcon(build_icon(u':/icon/openlp.org-icon-32.bmp')) + self.alertDialogLayout = QtGui.QVBoxLayout(alertDialog) + self.alertDialogLayout.setSpacing(8) + self.alertDialogLayout.setMargin(8) + self.alertDialogLayout.setObjectName(u'alertDialogLayout') + self.alertTextLayout = QtGui.QFormLayout() + self.alertTextLayout.setContentsMargins(0, 0, -1, -1) + self.alertTextLayout.setSpacing(8) + self.alertTextLayout.setObjectName(u'AlertTextLayout') + self.alertEntryLabel = QtGui.QLabel(alertDialog) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( - self.AlertEntryLabel.sizePolicy().hasHeightForWidth()) - self.AlertEntryLabel.setSizePolicy(sizePolicy) - self.AlertEntryLabel.setObjectName(u'AlertEntryLabel') - self.AlertTextLayout.setWidget(0, QtGui.QFormLayout.LabelRole, - self.AlertEntryLabel) - self.AlertParameter = QtGui.QLabel(AlertDialog) - self.AlertParameter.setObjectName(u'AlertParameter') - self.AlertTextLayout.setWidget(1, QtGui.QFormLayout.LabelRole, - self.AlertParameter) - self.ParameterEdit = QtGui.QLineEdit(AlertDialog) - self.ParameterEdit.setObjectName(u'ParameterEdit') - self.AlertTextLayout.setWidget(1, QtGui.QFormLayout.FieldRole, - self.ParameterEdit) - self.AlertTextEdit = QtGui.QLineEdit(AlertDialog) - self.AlertTextEdit.setObjectName(u'AlertTextEdit') - self.AlertTextLayout.setWidget(0, QtGui.QFormLayout.FieldRole, - self.AlertTextEdit) - self.AlertDialogLayout.addLayout(self.AlertTextLayout) - self.ManagementLayout = QtGui.QHBoxLayout() - self.ManagementLayout.setSpacing(8) - self.ManagementLayout.setContentsMargins(-1, -1, -1, 0) - self.ManagementLayout.setObjectName(u'ManagementLayout') - self.AlertListWidget = QtGui.QListWidget(AlertDialog) - self.AlertListWidget.setAlternatingRowColors(True) - self.AlertListWidget.setObjectName(u'AlertListWidget') - self.ManagementLayout.addWidget(self.AlertListWidget) - self.ManageButtonLayout = QtGui.QVBoxLayout() - self.ManageButtonLayout.setSpacing(8) - self.ManageButtonLayout.setObjectName(u'ManageButtonLayout') - self.NewButton = QtGui.QPushButton(AlertDialog) - self.NewButton.setIcon(build_icon(u':/general/general_new.png')) - self.NewButton.setObjectName(u'NewButton') - self.ManageButtonLayout.addWidget(self.NewButton) - self.SaveButton = QtGui.QPushButton(AlertDialog) - self.SaveButton.setEnabled(False) - self.SaveButton.setIcon(build_icon(u':/general/general_save.png')) - self.SaveButton.setObjectName(u'SaveButton') - self.ManageButtonLayout.addWidget(self.SaveButton) - self.DeleteButton = QtGui.QPushButton(AlertDialog) - self.DeleteButton.setIcon(build_icon(u':/general/general_delete.png')) - self.DeleteButton.setObjectName(u'DeleteButton') - self.ManageButtonLayout.addWidget(self.DeleteButton) + self.alertEntryLabel.sizePolicy().hasHeightForWidth()) + self.alertEntryLabel.setSizePolicy(sizePolicy) + self.alertEntryLabel.setObjectName(u'AlertEntryLabel') + self.alertTextLayout.setWidget(0, QtGui.QFormLayout.LabelRole, + self.alertEntryLabel) + self.alertParameter = QtGui.QLabel(alertDialog) + self.alertParameter.setObjectName(u'AlertParameter') + self.alertTextLayout.setWidget(1, QtGui.QFormLayout.LabelRole, + self.alertParameter) + self.parameterEdit = QtGui.QLineEdit(alertDialog) + self.parameterEdit.setObjectName(u'ParameterEdit') + self.alertTextLayout.setWidget(1, QtGui.QFormLayout.FieldRole, + self.parameterEdit) + self.alertTextEdit = QtGui.QLineEdit(alertDialog) + self.alertTextEdit.setObjectName(u'AlertTextEdit') + self.alertTextLayout.setWidget(0, QtGui.QFormLayout.FieldRole, + self.alertTextEdit) + self.alertDialogLayout.addLayout(self.alertTextLayout) + self.managementLayout = QtGui.QHBoxLayout() + self.managementLayout.setSpacing(8) + self.managementLayout.setContentsMargins(-1, -1, -1, 0) + self.managementLayout.setObjectName(u'ManagementLayout') + self.alertListWidget = QtGui.QListWidget(alertDialog) + self.alertListWidget.setAlternatingRowColors(True) + self.alertListWidget.setObjectName(u'AlertListWidget') + self.managementLayout.addWidget(self.alertListWidget) + self.manageButtonLayout = QtGui.QVBoxLayout() + self.manageButtonLayout.setSpacing(8) + self.manageButtonLayout.setObjectName(u'ManageButtonLayout') + self.newButton = QtGui.QPushButton(alertDialog) + self.newButton.setIcon(build_icon(u':/general/general_new.png')) + self.newButton.setObjectName(u'NewButton') + self.manageButtonLayout.addWidget(self.newButton) + self.saveButton = QtGui.QPushButton(alertDialog) + self.saveButton.setEnabled(False) + self.saveButton.setIcon(build_icon(u':/general/general_save.png')) + self.saveButton.setObjectName(u'SaveButton') + self.manageButtonLayout.addWidget(self.saveButton) + self.deleteButton = QtGui.QPushButton(alertDialog) + self.deleteButton.setIcon(build_icon(u':/general/general_delete.png')) + self.deleteButton.setObjectName(u'DeleteButton') + self.manageButtonLayout.addWidget(self.deleteButton) spacerItem = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) - self.ManageButtonLayout.addItem(spacerItem) - self.ManagementLayout.addLayout(self.ManageButtonLayout) - self.AlertDialogLayout.addLayout(self.ManagementLayout) - self.AlertButtonLayout = QtGui.QHBoxLayout() - self.AlertButtonLayout.setSpacing(8) - self.AlertButtonLayout.setObjectName(u'AlertButtonLayout') + self.manageButtonLayout.addItem(spacerItem) + self.managementLayout.addLayout(self.manageButtonLayout) + self.alertDialogLayout.addLayout(self.managementLayout) + self.alertButtonLayout = QtGui.QHBoxLayout() + self.alertButtonLayout.setSpacing(8) + self.alertButtonLayout.setObjectName(u'AlertButtonLayout') spacerItem1 = QtGui.QSpacerItem(181, 0, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) - self.AlertButtonLayout.addItem(spacerItem1) + self.alertButtonLayout.addItem(spacerItem1) displayIcon = build_icon(u':/general/general_live.png') - self.DisplayButton = QtGui.QPushButton(AlertDialog) - self.DisplayButton.setIcon(displayIcon) - self.DisplayButton.setObjectName(u'DisplayButton') - self.AlertButtonLayout.addWidget(self.DisplayButton) - self.DisplayCloseButton = QtGui.QPushButton(AlertDialog) - self.DisplayCloseButton.setIcon(displayIcon) - self.DisplayCloseButton.setObjectName(u'DisplayCloseButton') - self.AlertButtonLayout.addWidget(self.DisplayCloseButton) - self.CloseButton = QtGui.QPushButton(AlertDialog) - self.CloseButton.setIcon(build_icon(u':/system/system_close.png')) - self.CloseButton.setObjectName(u'CloseButton') - self.AlertButtonLayout.addWidget(self.CloseButton) - self.AlertDialogLayout.addLayout(self.AlertButtonLayout) - self.AlertEntryLabel.setBuddy(self.AlertTextEdit) - self.AlertParameter.setBuddy(self.ParameterEdit) - - self.retranslateUi(AlertDialog) - QtCore.QObject.connect(self.CloseButton, QtCore.SIGNAL(u'clicked()'), - AlertDialog.close) - QtCore.QMetaObject.connectSlotsByName(AlertDialog) - - def retranslateUi(self, AlertDialog): - AlertDialog.setWindowTitle( + self.displayButton = QtGui.QPushButton(alertDialog) + self.displayButton.setIcon(displayIcon) + self.displayButton.setObjectName(u'DisplayButton') + self.alertButtonLayout.addWidget(self.displayButton) + self.displayCloseButton = QtGui.QPushButton(alertDialog) + self.displayCloseButton.setIcon(displayIcon) + self.displayCloseButton.setObjectName(u'DisplayCloseButton') + self.alertButtonLayout.addWidget(self.displayCloseButton) + self.closeButton = QtGui.QPushButton(alertDialog) + self.closeButton.setIcon(build_icon(u':/system/system_close.png')) + self.closeButton.setObjectName(u'CloseButton') + self.alertButtonLayout.addWidget(self.closeButton) + self.alertDialogLayout.addLayout(self.alertButtonLayout) + self.alertEntryLabel.setBuddy(self.alertTextEdit) + self.alertParameter.setBuddy(self.parameterEdit) + + self.retranslateUi(alertDialog) + QtCore.QObject.connect(self.closeButton, QtCore.SIGNAL(u'clicked()'), + alertDialog.close) + QtCore.QMetaObject.connectSlotsByName(alertDialog) + + def retranslateUi(self, alertDialog): + alertDialog.setWindowTitle( translate('AlertsPlugin.AlertForm', 'Alert Message')) - self.AlertEntryLabel.setText( + self.alertEntryLabel.setText( translate('AlertsPlugin.AlertForm', 'Alert &text:')) - self.AlertParameter.setText( + self.alertParameter.setText( translate('AlertsPlugin.AlertForm', '&Parameter:')) - self.NewButton.setText( - translate('AlertsPlugin.AlertForm', '&New')) - self.SaveButton.setText( - translate('AlertsPlugin.AlertForm', '&Save')) - self.DeleteButton.setText( + self.newButton.setText(translate('AlertsPlugin.AlertForm', '&New')) + self.saveButton.setText(translate('AlertsPlugin.AlertForm', '&Save')) + self.deleteButton.setText( translate('AlertsPlugin.AlertForm', '&Delete')) - self.DisplayButton.setText( + self.displayButton.setText( translate('AlertsPlugin.AlertForm', 'Displ&ay')) - self.DisplayCloseButton.setText( + self.displayCloseButton.setText( translate('AlertsPlugin.AlertForm', 'Display && Cl&ose')) - self.CloseButton.setText( - translate('AlertsPlugin.AlertForm', '&Close')) + self.closeButton.setText(translate('AlertsPlugin.AlertForm', '&Close')) === 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-11 20:32:53 +0000 @@ -44,115 +44,157 @@ self.item_id = None QtGui.QDialog.__init__(self, plugin.formparent) self.setupUi(self) - QtCore.QObject.connect(self.DisplayButton, QtCore.SIGNAL(u'clicked()'), + QtCore.QObject.connect(self.displayButton, QtCore.SIGNAL(u'clicked()'), self.onDisplayClicked) - QtCore.QObject.connect(self.DisplayCloseButton, + QtCore.QObject.connect(self.displayCloseButton, 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.QObject.connect(self.NewButton, QtCore.SIGNAL(u'clicked()'), + QtCore.QObject.connect(self.newButton, QtCore.SIGNAL(u'clicked()'), self.onNewClick) - QtCore.QObject.connect(self.DeleteButton, QtCore.SIGNAL(u'clicked()'), + QtCore.QObject.connect(self.deleteButton, QtCore.SIGNAL(u'clicked()'), self.onDeleteClick) - QtCore.QObject.connect(self.SaveButton, QtCore.SIGNAL(u'clicked()'), + QtCore.QObject.connect(self.saveButton, QtCore.SIGNAL(u'clicked()'), self.onSaveClick) - QtCore.QObject.connect(self.AlertListWidget, + QtCore.QObject.connect(self.alertListWidget, QtCore.SIGNAL(u'doubleClicked(QModelIndex)'), self.onDoubleClick) - QtCore.QObject.connect(self.AlertListWidget, + QtCore.QObject.connect(self.alertListWidget, QtCore.SIGNAL(u'clicked(QModelIndex)'), self.onSingleClick) def loadList(self): - self.AlertListWidget.clear() + """ + Loads the list with alerts. + """ + self.alertListWidget.clear() alerts = self.manager.get_all_objects(AlertItem, order_by_ref=AlertItem.text) for alert in alerts: item_name = QtGui.QListWidgetItem(alert.text) item_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(alert.id)) - self.AlertListWidget.addItem(item_name) - self.SaveButton.setEnabled(False) - self.DeleteButton.setEnabled(False) + self.alertListWidget.addItem(item_name) + self.saveButton.setEnabled(False) + self.deleteButton.setEnabled(False) def onDisplayClicked(self): - if self.triggerAlert(unicode(self.AlertTextEdit.text())): + if self.triggerAlert(unicode(self.alertTextEdit.text())): self.loadList() def onDisplayCloseClicked(self): - if self.triggerAlert(unicode(self.AlertTextEdit.text())): + if self.triggerAlert(unicode(self.alertTextEdit.text())): self.close() def onDeleteClick(self): - item = self.AlertListWidget.currentItem() + """ + 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.AlertTextEdit.setText(u'') - self.SaveButton.setEnabled(False) - self.DeleteButton.setEnabled(False) + 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) def onNewClick(self): - if len(self.AlertTextEdit.text()) == 0: + """ + Creates a new alert. + """ + if len(self.alertTextEdit.text()) == 0: 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()) + alert.text = unicode(self.alertTextEdit.text()) self.manager.save_object(alert) - self.AlertTextEdit.setText(u'') + self.alertTextEdit.setText(u'') self.loadList() 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) - alert.text = unicode(self.AlertTextEdit.text()) + alert.text = unicode(self.alertTextEdit.text()) 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 + 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): """ - List item has been double clicked to display it + List item has been double clicked to display it. """ - items = self.AlertListWidget.selectedIndexes() + items = self.alertListWidget.selectedIndexes() for item in items: - bitem = self.AlertListWidget.item(item.row()) - self.triggerAlert(bitem.text()) - self.AlertTextEdit.setText(bitem.text()) + bitem = self.alertListWidget.item(item.row()) + 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) + self.saveButton.setEnabled(False) + self.deleteButton.setEnabled(True) def onSingleClick(self): """ - List item has been single clicked to add it to - the edit field so it can be changed. + List item has been single clicked to add it to the edit field so it can + be changed. """ - items = self.AlertListWidget.selectedIndexes() + items = self.alertListWidget.selectedIndexes() for item in items: - bitem = self.AlertListWidget.item(item.row()) - self.AlertTextEdit.setText(bitem.text()) + bitem = self.alertListWidget.item(item.row()) + self.alertTextEdit.setText(unicode(bitem.text())) self.item_id = (bitem.data(QtCore.Qt.UserRole)).toInt()[0] - self.SaveButton.setEnabled(False) - self.DeleteButton.setEnabled(True) + # 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: - text = text.replace(u'<>', unicode(self.ParameterEdit.text())) + # The parameterEdit field is not empty, but we have not found '<>' + # in the alert text. + 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 + # We found '<>' in the alert text, but the parameterEdit field it + # empty. + 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.alertTextEdit.setFocus() + return False + text = text.replace(u'<>', unicode(self.parameterEdit.text())) self.parent.alertsmanager.displayAlert(text) return True return False === 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-11 20:32:53 +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