From 1f4c26e466a1e4c19a7f700b012831120f712be0 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Thu, 3 Feb 2011 20:11:27 +0100 Subject: [PATCH] --- openlp/plugins/alerts/forms/alertdialog.py | 3 ++ openlp/plugins/alerts/forms/alertform.py | 44 +++++++++++++++------- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/openlp/plugins/alerts/forms/alertdialog.py b/openlp/plugins/alerts/forms/alertdialog.py index 272a96f3d..2e7e19176 100644 --- a/openlp/plugins/alerts/forms/alertdialog.py +++ b/openlp/plugins/alerts/forms/alertdialog.py @@ -66,6 +66,7 @@ class Ui_AlertDialog(object): self.saveButton.setObjectName(u'saveButton') self.manageButtonLayout.addWidget(self.saveButton) self.deleteButton = QtGui.QPushButton(alertDialog) + self.deleteButton.setEnabled(False) self.deleteButton.setIcon(build_icon(u':/general/general_delete.png')) self.deleteButton.setObjectName(u'deleteButton') self.manageButtonLayout.addWidget(self.deleteButton) @@ -75,11 +76,13 @@ class Ui_AlertDialog(object): self.buttonBox.addButton(QtGui.QDialogButtonBox.Close) displayIcon = build_icon(u':/general/general_live.png') self.displayButton = QtGui.QPushButton(alertDialog) + self.displayButton.setEnabled(False) self.displayButton.setIcon(displayIcon) self.displayButton.setObjectName(u'displayButton') self.buttonBox.addButton(self.displayButton, QtGui.QDialogButtonBox.ActionRole) self.displayCloseButton = QtGui.QPushButton(alertDialog) + self.displayCloseButton.setEnabled(False) self.displayCloseButton.setIcon(displayIcon) self.displayCloseButton.setObjectName(u'displayCloseButton') self.buttonBox.addButton(self.displayCloseButton, diff --git a/openlp/plugins/alerts/forms/alertform.py b/openlp/plugins/alerts/forms/alertform.py index f1a0f7fea..1d10b99a9 100644 --- a/openlp/plugins/alerts/forms/alertform.py +++ b/openlp/plugins/alerts/forms/alertform.py @@ -44,22 +44,24 @@ class AlertForm(QtGui.QDialog, Ui_AlertDialog): self.item_id = None QtGui.QDialog.__init__(self, plugin.formparent) self.setupUi(self) - QtCore.QObject.connect(self.displayButton, QtCore.SIGNAL(u'clicked()'), - self.onDisplayClicked) + QtCore.QObject.connect(self.displayButton, + QtCore.SIGNAL(u'clicked()'), self.onDisplayClicked) QtCore.QObject.connect(self.displayCloseButton, QtCore.SIGNAL(u'clicked()'), self.onDisplayCloseClicked) QtCore.QObject.connect(self.alertTextEdit, QtCore.SIGNAL(u'textChanged(const QString&)'), self.onTextChanged) - QtCore.QObject.connect(self.newButton, QtCore.SIGNAL(u'clicked()'), - self.onNewClick) - QtCore.QObject.connect(self.deleteButton, QtCore.SIGNAL(u'clicked()'), - self.onDeleteClick) - QtCore.QObject.connect(self.saveButton, QtCore.SIGNAL(u'clicked()'), - self.onSaveClick) + QtCore.QObject.connect(self.newButton, + QtCore.SIGNAL(u'clicked()'), self.onNewClick) + QtCore.QObject.connect(self.deleteButton, + QtCore.SIGNAL(u'clicked()'), self.onDeleteClick) + QtCore.QObject.connect(self.saveButton, + QtCore.SIGNAL(u'clicked()'), self.onSaveClick) QtCore.QObject.connect(self.alertListWidget, QtCore.SIGNAL(u'doubleClicked(QModelIndex)'), self.onDoubleClick) QtCore.QObject.connect(self.alertListWidget, QtCore.SIGNAL(u'clicked(QModelIndex)'), self.onSingleClick) + QtCore.QObject.connect(self.alertListWidget, + QtCore.SIGNAL(u'currentRowChanged(int)'), self.onCurrentRowChanged) def loadList(self): """ @@ -72,8 +74,6 @@ class AlertForm(QtGui.QDialog, Ui_AlertDialog): 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) def onDisplayClicked(self): if self.triggerAlert(unicode(self.alertTextEdit.text())): @@ -95,8 +95,6 @@ class AlertForm(QtGui.QDialog, Ui_AlertDialog): 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: @@ -142,7 +140,6 @@ class AlertForm(QtGui.QDialog, Ui_AlertDialog): self.alertTextEdit.setText(unicode(bitem.text())) self.item_id = (bitem.data(QtCore.Qt.UserRole)).toInt()[0] self.saveButton.setEnabled(False) - self.deleteButton.setEnabled(True) def onSingleClick(self): """ @@ -158,7 +155,6 @@ class AlertForm(QtGui.QDialog, Ui_AlertDialog): if unicode(self.alertTextEdit.text()).find(u'<>') == -1: self.parameterEdit.setText(u'') self.saveButton.setEnabled(False) - self.deleteButton.setEnabled(True) def triggerAlert(self, text): """ @@ -194,3 +190,23 @@ class AlertForm(QtGui.QDialog, Ui_AlertDialog): self.parent.alertsmanager.displayAlert(text) 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".