From 47a61a65812069f8014fbc0f00a290ef11f6e88a Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Fri, 12 Feb 2010 18:42:09 +0000 Subject: [PATCH] Finished moving alert code to plugin structure --- openlp/core/lib/plugin.py | 3 ++- openlp/core/lib/pluginmanager.py | 2 +- openlp/core/ui/maindisplay.py | 2 -- openlp/core/ui/mainwindow.py | 1 + openlp/plugins/alerts/alertsplugin.py | 7 ++++--- openlp/plugins/alerts/forms/alertform.py | 3 ++- openlp/plugins/alerts/lib/__init__.py | 2 +- .../lib/{alertmanager.py => alertsmanager.py} | 21 ++++++++++++------- 8 files changed, 24 insertions(+), 17 deletions(-) rename openlp/plugins/alerts/lib/{alertmanager.py => alertsmanager.py} (76%) diff --git a/openlp/core/lib/plugin.py b/openlp/core/lib/plugin.py index 598c594fd..ca291d578 100644 --- a/openlp/core/lib/plugin.py +++ b/openlp/core/lib/plugin.py @@ -127,6 +127,7 @@ class Plugin(QtCore.QObject): self.service_manager = plugin_helpers[u'service'] self.settings = plugin_helpers[u'settings'] self.mediadock = plugin_helpers[u'toolbox'] + self.maindisplay = plugin_helpers[u'maindisplay'] QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'%s_add_service_item' % self.name), self.process_add_service_event) @@ -252,4 +253,4 @@ class Plugin(QtCore.QObject): if self.media_item: self.mediadock.insert_dock(self.media_item, self.icon, self.weight) if self.settings_tab: - self.settings.insertTab(self.settings_tab, self.weight) \ No newline at end of file + self.settings.insertTab(self.settings_tab, self.weight) diff --git a/openlp/core/lib/pluginmanager.py b/openlp/core/lib/pluginmanager.py index 4d4da144a..b06f23953 100644 --- a/openlp/core/lib/pluginmanager.py +++ b/openlp/core/lib/pluginmanager.py @@ -101,7 +101,7 @@ class PluginManager(object): log.debug(u'Loaded plugin %s with helpers', unicode(p)) plugin_objects.append(plugin) except TypeError: - log.error(u'loaded plugin %s has no helpers', unicode(p)) + log.exception(u'loaded plugin %s has no helpers', unicode(p)) plugins_list = sorted(plugin_objects, self.order_by_weight) for plugin in plugins_list: if plugin.check_pre_conditions(): diff --git a/openlp/core/ui/maindisplay.py b/openlp/core/ui/maindisplay.py index 43cb0d848..7846b58d5 100644 --- a/openlp/core/ui/maindisplay.py +++ b/openlp/core/ui/maindisplay.py @@ -114,11 +114,9 @@ class MainDisplay(DisplayWidget): self.displayBlank = False self.blankFrame = None self.frame = None - self.timer_id = 0 self.firstTime = True self.mediaLoaded = False self.hasTransition = False - self.alertList = [] self.mediaBackground = False QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'live_slide_hide'), self.hideDisplay) diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 2ec93ce79..df66d5e97 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -510,6 +510,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): self.plugin_helpers[u'service'] = self.ServiceManagerContents self.plugin_helpers[u'settings'] = self.settingsForm self.plugin_helpers[u'toolbox'] = self.mediaDockManager + self.plugin_helpers[u'maindisplay'] = self.mainDisplay self.plugin_manager.find_plugins(pluginpath, self.plugin_helpers) # hook methods have to happen after find_plugins. Find plugins needs # the controllers hence the hooks have moved from setupUI() to here diff --git a/openlp/plugins/alerts/alertsplugin.py b/openlp/plugins/alerts/alertsplugin.py index f18f1b9b7..1163f70ee 100644 --- a/openlp/plugins/alerts/alertsplugin.py +++ b/openlp/plugins/alerts/alertsplugin.py @@ -29,7 +29,7 @@ import logging 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 +from openlp.plugins.alerts.lib import AlertsManager from openlp.plugins.alerts.forms import AlertsTab, AlertForm #from openlp.plugins.alerts.lib.models import alertsItem @@ -42,12 +42,13 @@ class alertsPlugin(Plugin): Plugin.__init__(self, u'alerts', u'1.9.1', plugin_helpers) self.weight = -3 self.icon = build_icon(u':/media/media_image.png') - self.alertsmanager = None + self.alertsmanager = AlertsManager(self) self.alertForm = AlertForm(self) self.status = PluginStatus.Active def get_settings_tab(self): - return AlertsTab(self.name) + self.alertsTab = AlertsTab(self.name) + return self.alertsTab def add_tools_menu_item(self, tools_menu): """ diff --git a/openlp/plugins/alerts/forms/alertform.py b/openlp/plugins/alerts/forms/alertform.py index 86724c99c..68549eaee 100644 --- a/openlp/plugins/alerts/forms/alertform.py +++ b/openlp/plugins/alerts/forms/alertform.py @@ -26,6 +26,7 @@ import logging from PyQt4 import QtCore, QtGui from openlp.core.lib import build_icon +from openlp.plugins.alerts.lib import alertmanager class AlertForm(QtGui.QDialog): global log @@ -97,4 +98,4 @@ class AlertForm(QtGui.QDialog): self.CancelButton.setText(self.trUtf8('Cancel')) def onDisplayClicked(self): - self.parent.mainDisplay.displayAlert(unicode(self.AlertEntryEditItem.text())) + self.parent.alertsmanager.displayAlert(unicode(self.AlertEntryEditItem.text())) diff --git a/openlp/plugins/alerts/lib/__init__.py b/openlp/plugins/alerts/lib/__init__.py index bf7bc5074..f6fb2c0d7 100644 --- a/openlp/plugins/alerts/lib/__init__.py +++ b/openlp/plugins/alerts/lib/__init__.py @@ -22,4 +22,4 @@ # with this program; if not, write to the Free Software Foundation, Inc., 59 # # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### -from alertmanager import AlertManager +from alertsmanager import AlertsManager diff --git a/openlp/plugins/alerts/lib/alertmanager.py b/openlp/plugins/alerts/lib/alertsmanager.py similarity index 76% rename from openlp/plugins/alerts/lib/alertmanager.py rename to openlp/plugins/alerts/lib/alertsmanager.py index 34dc2622c..977614b86 100644 --- a/openlp/plugins/alerts/lib/alertmanager.py +++ b/openlp/plugins/alerts/lib/alertsmanager.py @@ -6,7 +6,7 @@ from PyQt4 import QtCore, QtGui from openlp.core.lib import str_to_bool, Receiver from openlp.core.lib import SettingsTab -class AlertManager(self): +class AlertsManager(QtCore.QObject): """ BiblesTab is the Bibles settings tab in the settings dialog. """ @@ -14,7 +14,11 @@ class AlertManager(self): log = logging.getLogger(u'AlertManager') log.info(u'Alert Manager loaded') - def __init__(self): + def __init__(self, parent): + QtCore.QObject.__init__(self) + self.parent = parent + self.timer_id = 0 + self.alertList = [] QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'alert_text'), self.displayAlert) @@ -26,9 +30,10 @@ class AlertManager(self): display text """ log.debug(u'display alert called %s' % text) - self.parent.StatusBar.showMessage(self.trUtf8(u'')) + self.screen = self.parent.maindisplay.screen + self.parent.maindisplay.parent.StatusBar.showMessage(self.trUtf8(u'')) self.alertList.append(text) - if self.timer_id != 0 or self.mediaLoaded: + if self.timer_id != 0 or self.parent.maindisplay.mediaLoaded: self.parent.StatusBar.showMessage(\ self.trUtf8(u'Alert message created and delayed')) return @@ -39,9 +44,9 @@ class AlertManager(self): if len(self.alertList) == 0: return text = self.alertList.pop(0) - alertTab = self.parent.settingsForm.AlertsTab + alertTab = self.parent.alertsTab alertframe = \ - QtGui.QPixmap(self.screen[u'size'].width(), self.alertHeight) + QtGui.QPixmap(self.screen[u'size'].width(), self.parent.maindisplay.alertHeight) alertframe.fill(QtCore.Qt.transparent) painter = QtGui.QPainter(alertframe) painter.fillRect(alertframe.rect(), QtCore.Qt.transparent) @@ -62,14 +67,14 @@ class AlertManager(self): painter.drawText( x, y + metrics.height() - metrics.descent() - 1, text) painter.end() - self.display_alert.setPixmap(alertframe) + self.parent.maindisplay.display_alert.setPixmap(alertframe) # check to see if we have a timer running if self.timer_id == 0: self.timer_id = self.startTimer(int(alertTab.timeout) * 1000) def timerEvent(self, event): if event.timerId() == self.timer_id: - self.display_alert.setPixmap(self.transparent) + self.parent.maindisplay.display_alert.setPixmap(self.parent.maindisplay.transparent) self.killTimer(self.timer_id) self.timer_id = 0 self.generateAlert()