Alerts editing now work - history and pre determined

This commit is contained in:
Tim Bentley 2010-02-14 20:19:57 +00:00
parent acc97f3c79
commit 2fefcef09d
12 changed files with 257 additions and 68 deletions

View File

@ -30,7 +30,7 @@ from PyQt4 import QtCore, QtGui
from openlp.core.lib import Plugin, Receiver, str_to_bool, build_icon, PluginStatus
from openlp.plugins.alerts.lib import AlertsManager, DBManager
from openlp.plugins.alerts.forms import AlertsTab, AlertForm
from openlp.plugins.alerts.forms import AlertsTab, AlertForm, AlertEditForm
class alertsPlugin(Plugin):
global log
@ -44,10 +44,11 @@ class alertsPlugin(Plugin):
self.alertsmanager = AlertsManager(self)
self.manager = DBManager(self.config)
self.alertForm = AlertForm(self.manager, self)
self.alertEditForm = AlertEditForm(self.manager, self)
self.status = PluginStatus.Active
def get_settings_tab(self):
self.alertsTab = AlertsTab(self.name)
self.alertsTab = AlertsTab(self)
return self.alertsTab
def add_tools_menu_item(self, tools_menu):
@ -90,9 +91,9 @@ class alertsPlugin(Plugin):
self.alertForm.loadList()
self.alertForm.exec_()
def onalertsReport(self):
self.alertsdetailform.initialise()
self.alertsdetailform.exec_()
def onAlertsEdit(self):
self.alertEditForm.loadList()
self.alertEditForm.exec_()
def about(self):
about_text = self.trUtf8('<b>Alerts Plugin</b><br>This plugin '

View File

@ -25,3 +25,4 @@
from alertstab import AlertsTab
from alertform import AlertForm
from alerteditform import AlertEditForm

View File

@ -43,6 +43,7 @@ class Ui_AlertDialog(object):
self.AlertEntryEditItem.setObjectName("AlertEntryEditItem")
self.verticalLayout.addWidget(self.AlertEntryEditItem)
self.AlertListWidget = QtGui.QListWidget(self.AlertEntryWidget)
self.AlertListWidget.setAlternatingRowColors(True)
self.AlertListWidget.setObjectName("AlertListWidget")
self.verticalLayout.addWidget(self.AlertListWidget)
self.verticalLayout_2.addLayout(self.verticalLayout)
@ -60,7 +61,7 @@ class Ui_AlertDialog(object):
self.AlertFormLayout.addWidget(self.AlertEntryWidget)
self.retranslateUi(AlertForm)
QtCore.QObject.connect(self.CancelButton, QtCore.SIGNAL("clicked()"), AlertForm.close)
QtCore.QObject.connect(self.CancelButton, QtCore.SIGNAL("clicked()"), self.close)
QtCore.QMetaObject.connectSlotsByName(AlertForm)
def retranslateUi(self, AlertForm):

View File

@ -2,62 +2,66 @@
# Form implementation generated from reading ui file 'alerteditdialog.ui'
#
# Created: Sat Feb 13 08:20:09 2010
# Created: Sun Feb 14 16:45:10 2010
# by: PyQt4 UI code generator 4.6.2
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
class Ui_AlertList(object):
def setupUi(self, AlertList):
AlertList.setObjectName("AlertList")
AlertList.resize(400, 300)
self.buttonBox = QtGui.QDialogButtonBox(AlertList)
class Ui_AlertEditDialog(object):
def setupUi(self, AlertEditDialog):
AlertEditDialog.setObjectName("AlertEditDialog")
AlertEditDialog.resize(400, 300)
self.buttonBox = QtGui.QDialogButtonBox(AlertEditDialog)
self.buttonBox.setGeometry(QtCore.QRect(220, 270, 173, 27))
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel)
self.buttonBox.setObjectName("buttonBox")
self.widget = QtGui.QWidget(AlertList)
self.widget.setGeometry(QtCore.QRect(20, 10, 361, 251))
self.widget.setObjectName("widget")
self.verticalLayout_2 = QtGui.QVBoxLayout(self.widget)
self.layoutWidget = QtGui.QWidget(AlertEditDialog)
self.layoutWidget.setGeometry(QtCore.QRect(20, 10, 361, 251))
self.layoutWidget.setObjectName("layoutWidget")
self.verticalLayout_2 = QtGui.QVBoxLayout(self.layoutWidget)
self.verticalLayout_2.setObjectName("verticalLayout_2")
self.horizontalLayout_2 = QtGui.QHBoxLayout()
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.lineEdit = QtGui.QLineEdit(self.widget)
self.lineEdit.setObjectName("lineEdit")
self.horizontalLayout_2.addWidget(self.lineEdit)
self.SaveButton = QtGui.QPushButton(self.widget)
self.SaveButton.setObjectName("SaveButton")
self.horizontalLayout_2.addWidget(self.SaveButton)
self.AlertLineEdit = QtGui.QLineEdit(self.layoutWidget)
self.AlertLineEdit.setObjectName("AlertLineEdit")
self.horizontalLayout_2.addWidget(self.AlertLineEdit)
self.verticalLayout_2.addLayout(self.horizontalLayout_2)
self.horizontalLayout = QtGui.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout")
self.listWidget = QtGui.QListWidget(self.widget)
self.listWidget.setAlternatingRowColors(True)
self.listWidget.setObjectName("listWidget")
self.horizontalLayout.addWidget(self.listWidget)
self.AlertListWidget = QtGui.QListWidget(self.layoutWidget)
self.AlertListWidget.setAlternatingRowColors(True)
self.AlertListWidget.setObjectName("AlertListWidget")
self.horizontalLayout.addWidget(self.AlertListWidget)
self.verticalLayout = QtGui.QVBoxLayout()
self.verticalLayout.setObjectName("verticalLayout")
self.AddButton = QtGui.QPushButton(self.widget)
self.SaveButton = QtGui.QPushButton(self.layoutWidget)
self.SaveButton.setObjectName("SaveButton")
self.verticalLayout.addWidget(self.SaveButton)
self.ClearButton = QtGui.QPushButton(self.layoutWidget)
self.ClearButton.setObjectName("ClearButton")
self.verticalLayout.addWidget(self.ClearButton)
self.AddButton = QtGui.QPushButton(self.layoutWidget)
self.AddButton.setObjectName("AddButton")
self.verticalLayout.addWidget(self.AddButton)
self.EdirButton = QtGui.QPushButton(self.widget)
self.EdirButton.setObjectName("EdirButton")
self.verticalLayout.addWidget(self.EdirButton)
self.DeleteButton = QtGui.QPushButton(self.widget)
self.EditButton = QtGui.QPushButton(self.layoutWidget)
self.EditButton.setObjectName("EditButton")
self.verticalLayout.addWidget(self.EditButton)
self.DeleteButton = QtGui.QPushButton(self.layoutWidget)
self.DeleteButton.setObjectName("DeleteButton")
self.verticalLayout.addWidget(self.DeleteButton)
self.horizontalLayout.addLayout(self.verticalLayout)
self.verticalLayout_2.addLayout(self.horizontalLayout)
self.retranslateUi(AlertList)
QtCore.QMetaObject.connectSlotsByName(AlertList)
self.retranslateUi(AlertEditDialog)
QtCore.QMetaObject.connectSlotsByName(AlertEditDialog)
def retranslateUi(self, AlertList):
AlertList.setWindowTitle(QtGui.QApplication.translate("AlertList", "Form", None, QtGui.QApplication.UnicodeUTF8))
self.SaveButton.setText(QtGui.QApplication.translate("AlertList", "Save", None, QtGui.QApplication.UnicodeUTF8))
self.AddButton.setText(QtGui.QApplication.translate("AlertList", "Add", None, QtGui.QApplication.UnicodeUTF8))
self.EdirButton.setText(QtGui.QApplication.translate("AlertList", "Edit", None, QtGui.QApplication.UnicodeUTF8))
self.DeleteButton.setText(QtGui.QApplication.translate("AlertList", "Delete", None, QtGui.QApplication.UnicodeUTF8))
def retranslateUi(self, AlertEditDialog):
AlertEditDialog.setWindowTitle(QtGui.QApplication.translate("AlertEditDialog", "Maintain Alerts", None, QtGui.QApplication.UnicodeUTF8))
self.SaveButton.setText(QtGui.QApplication.translate("AlertEditDialog", "Save", None, QtGui.QApplication.UnicodeUTF8))
self.ClearButton.setText(QtGui.QApplication.translate("AlertEditDialog", "Clear", None, QtGui.QApplication.UnicodeUTF8))
self.AddButton.setText(QtGui.QApplication.translate("AlertEditDialog", "Add", None, QtGui.QApplication.UnicodeUTF8))
self.EditButton.setText(QtGui.QApplication.translate("AlertEditDialog", "Edit", None, QtGui.QApplication.UnicodeUTF8))
self.DeleteButton.setText(QtGui.QApplication.translate("AlertEditDialog", "Delete", None, QtGui.QApplication.UnicodeUTF8))

View File

@ -0,0 +1,168 @@
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
# Copyright (c) 2008-2010 Raoul Snyman #
# Portions copyright (c) 2008-2010 Tim Bentley, Jonathan Corwin, Michael #
# Gorven, Scott Guerrieri, Maikel Stuivenberg, Martin Thompson, Jon Tibble, #
# Carsten Tinggaard #
# --------------------------------------------------------------------------- #
# This program is free software; you can redistribute it and/or modify it #
# under the terms of the GNU General Public License as published by the Free #
# Software Foundation; version 2 of the License. #
# #
# This program is distributed in the hope that it will be useful, but WITHOUT #
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
# more details. #
# #
# You should have received a copy of the GNU General Public License along #
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
from datetime import date
from PyQt4 import QtGui, QtCore
from openlp.plugins.alerts.lib.models import AlertItem
from alerteditdialog import Ui_AlertEditDialog
class AlertEditForm(QtGui.QDialog, Ui_AlertEditDialog):
"""
Class documentation goes here.
"""
def __init__(self, manager, parent):
"""
Constructor
"""
self.manager = manager
self.parent = parent
QtGui.QDialog.__init__(self, None)
self.setupUi(self)
QtCore.QObject.connect(self.DeleteButton,
QtCore.SIGNAL(u'clicked()'),
self.onDeleteClick)
QtCore.QObject.connect(self.ClearButton,
QtCore.SIGNAL(u'clicked()'),
self.onClearClick)
QtCore.QObject.connect(self.EditButton,
QtCore.SIGNAL(u'clicked()'),
self.onEditClick)
QtCore.QObject.connect(self.AddButton,
QtCore.SIGNAL(u'clicked()'),
self.onAddClick)
QtCore.QObject.connect(self.SaveButton,
QtCore.SIGNAL(u'clicked()'),
self.onSaveClick)
QtCore.QObject.connect(self.buttonBox,
QtCore.SIGNAL(u'rejected()'), self.close)
QtCore.QObject.connect(self.AlertLineEdit,
QtCore.SIGNAL(u'textChanged(const QString&)'),
self.onTextChanged)
QtCore.QObject.connect(self.AlertListWidget,
QtCore.SIGNAL(u'doubleClicked(QModelIndex)'),
self.onItemSelected)
QtCore.QObject.connect(self.AlertListWidget,
QtCore.SIGNAL(u'clicked(QModelIndex)'),
self.onItemSelected)
def loadList(self):
self.AlertListWidget.clear()
alerts = self.manager.get_all_alerts()
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.AddButton.setEnabled(True)
self.ClearButton.setEnabled(False)
self.SaveButton.setEnabled(False)
self.EditButton.setEnabled(False)
self.DeleteButton.setEnabled(False)
def onItemSelected(self):
if len(self.AlertLineEdit.text()) > 0:
QtGui.QMessageBox.information(self,
self.trUtf8('Item selected to Edit'),
self.trUtf8('Please Save or Clear seletced item'))
else:
self.EditButton.setEnabled(True)
self.DeleteButton.setEnabled(True)
def onDeleteClick(self):
item = self.AlertListWidget.currentItem()
if item:
item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0]
self.parent.manager.delete_alert(item_id)
row = self.AlertListWidget.row(item)
self.AlertListWidget.takeItem(row)
self.AddButton.setEnabled(True)
self.SaveButton.setEnabled(False)
self.DeleteButton.setEnabled(False)
self.EditButton.setEnabled(False)
def onEditClick(self):
item = self.AlertListWidget.currentItem()
if item:
self.item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0]
self.AlertLineEdit.setText(unicode(item.text()))
self.AddButton.setEnabled(True)
self.ClearButton.setEnabled(True)
self.SaveButton.setEnabled(True)
self.DeleteButton.setEnabled(True)
self.EditButton.setEnabled(False)
def onClearClick(self):
self.AlertLineEdit.setText(u'')
self.AddButton.setEnabled(False)
self.ClearButton.setEnabled(True)
self.SaveButton.setEnabled(False)
self.DeleteButton.setEnabled(False)
self.EditButton.setEnabled(False)
def onAddClick(self):
if len(self.AlertLineEdit.text()) == 0:
QtGui.QMessageBox.information(self,
self.trUtf8('Item selected to Add'),
self.trUtf8('Missing data'))
else:
alert = AlertItem()
alert.text = unicode(self.AlertLineEdit.text())
self.manager.save_alert(alert)
self.onClearClick()
self.loadList()
def onSaveClick(self):
alert = self.manager.get_alert(self.item_id)
alert.text = unicode(self.AlertLineEdit.text())
self.manager.save_alert(alert)
self.onClearClick()
self.loadList()
def onTextChanged(self):
self.AddButton.setEnabled(True)
def onDoubleClick(self):
"""
List item has been double clicked to display it
"""
items = self.AlertListWidget.selectedIndexes()
for item in items:
bitem = self.AlertListWidget.item(item.row())
self.triggerAlert(bitem.text())
def onSingleClick(self):
"""
List item has been single clicked to add it to
the edit field so it can be changed.
"""
items = self.AlertListWidget.selectedIndexes()
for item in items:
bitem = self.AlertListWidget.item(item.row())
self.AlertEntryEditItem.setText(bitem.text())
def triggerAlert(self, text):
self.parent.alertsmanager.displayAlert(text)

View File

@ -43,9 +43,6 @@ class AlertForm(QtGui.QDialog, Ui_AlertDialog):
self.history_required = True
QtGui.QDialog.__init__(self, None)
self.setupUi(self)
QtCore.QObject.connect(self.CancelButton,
QtCore.SIGNAL(u'clicked()'),
AlertForm.close)
QtCore.QObject.connect(self.DisplayButton,
QtCore.SIGNAL(u'clicked()'),
self.onDisplayClicked)

View File

@ -31,8 +31,9 @@ class AlertsTab(SettingsTab):
"""
AlertsTab is the alerts settings tab in the settings dialog.
"""
def __init__(self, title, section=None):
SettingsTab.__init__(self, title, section)
def __init__(self, parent, section=None):
self.parent = parent
SettingsTab.__init__(self, parent.name, section)
def setupUi(self):
self.setObjectName(u'AlertsTab')
@ -209,6 +210,8 @@ class AlertsTab(SettingsTab):
QtCore.SIGNAL(u'pressed()'), self.onBackgroundColorButtonClicked)
QtCore.QObject.connect(self.FontColorButton,
QtCore.SIGNAL(u'pressed()'), self.onFontColorButtonClicked)
QtCore.QObject.connect(self.HistoryEditPushButton,
QtCore.SIGNAL(u'pressed()'), self.onHistoryEditButtonClicked)
QtCore.QObject.connect(self.FontComboBox,
QtCore.SIGNAL(u'activated(int)'), self.onFontComboBoxClicked)
QtCore.QObject.connect(self.LocationComboBox,
@ -268,6 +271,9 @@ class AlertsTab(SettingsTab):
self.font_size = self.FontSizeSpinBox.value()
self.updateDisplay()
def onHistoryEditButtonClicked(self):
self.parent.onAlertsEdit()
def load(self):
self.timeout = int(self.config.get_config(u'timeout', 5))
self.font_color = unicode(

View File

@ -78,10 +78,10 @@ class DBManager():
return True
except:
self.session.rollback()
log.excertion(u'Alert save failed')
log.exception(u'Alert save failed')
return False
def get_alerts(self, id=None):
def get_alert(self, id=None):
"""
Returns the details of a Alert
"""
@ -94,15 +94,15 @@ class DBManager():
"""
Delete a Alert show
"""
if id !=0:
Alerts = self.get_Alert(id)
if id != 0:
AlertItem = self.get_alert(id)
try:
self.session.delete(AlertItem)
self.session.commit()
return True
except:
self.session.rollback()
log.excertion(u'Alert deleton failed')
log.exception(u'Alert deleton failed')
return False
else:
return True

View File

@ -78,7 +78,7 @@ class CustomManager():
return True
except:
self.session.rollback()
log.excertion(u'Custom Slide save failed')
log.exceptiontion(u'Custom Slide save failed')
return False
def get_custom(self, id=None):
@ -94,7 +94,7 @@ class CustomManager():
"""
Delete a Custom slide show
"""
if id !=0:
if id != 0:
customslide = self.get_custom(id)
try:
self.session.delete(customslide)
@ -102,7 +102,7 @@ class CustomManager():
return True
except:
self.session.rollback()
log.excertion(u'Custom Slide deleton failed')
log.exception(u'Custom Slide deleton failed')
return False
else:
return True
return True

View File

@ -96,7 +96,7 @@ class SongUsageManager():
"""
Delete a SongUsage record
"""
if id !=0:
if id != 0:
songusageitem = self.get_songusage(id)
try:
self.session.delete(songusageitem)

View File

@ -52,7 +52,11 @@
<widget class="QLineEdit" name="AlertEntryEditItem"/>
</item>
<item>
<widget class="QListWidget" name="AlertListWidget"/>
<widget class="QListWidget" name="AlertListWidget">
<property name="alternatingRowColors">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AlertList</class>
<widget class="QWidget" name="AlertList">
<class>AlertEditDialog</class>
<widget class="QWidget" name="AlertEditDialog">
<property name="geometry">
<rect>
<x>0</x>
@ -11,7 +11,7 @@
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
<string>Maintain Alerts</string>
</property>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="geometry">
@ -26,7 +26,7 @@
<set>QDialogButtonBox::Cancel</set>
</property>
</widget>
<widget class="QWidget" name="">
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>20</x>
@ -39,21 +39,14 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLineEdit" name="lineEdit"/>
</item>
<item>
<widget class="QPushButton" name="SaveButton">
<property name="text">
<string>Save</string>
</property>
</widget>
<widget class="QLineEdit" name="AlertLineEdit"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QListWidget" name="listWidget">
<widget class="QListWidget" name="AlertListWidget">
<property name="alternatingRowColors">
<bool>true</bool>
</property>
@ -61,6 +54,20 @@
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QPushButton" name="SaveButton">
<property name="text">
<string>Save</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="ClearButton">
<property name="text">
<string>Clear</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="AddButton">
<property name="text">