Add distributed event handling

Added display updates when Bibles load
Try to fix the creeping progress bar.

bzr-revno: 299
This commit is contained in:
Tim Bentley 2009-02-08 15:25:00 +00:00
parent 49ed24a69b
commit 557114fd7f
11 changed files with 111 additions and 39 deletions

View File

@ -25,6 +25,7 @@ from mediamanageritem import MediaManagerItem
from event import Event from event import Event
from xmlrootclass import XmlRootClass from xmlrootclass import XmlRootClass
from serviceitem import ServiceItem from serviceitem import ServiceItem
from eventreceiver import Receiver
__all__ = ['PluginConfig', 'Plugin', 'PluginUtils', 'SettingsTab', 'MediaManagerItem', 'Event', __all__ = ['PluginConfig', 'Plugin', 'PluginUtils', 'SettingsTab', 'MediaManagerItem', 'Event',
'XmlRootClass', 'ServiceItem'] 'XmlRootClass', 'ServiceItem', "Receiver"]

View File

@ -0,0 +1,60 @@
# -*- coding: utf-8 -*-
"""
OpenLP - Open Source Lyrics Projection
Copyright (c) 2008 Raoul Snyman
Portions copyright (c) 2008 Martin Thompson, Tim Bentley,
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 PyQt4.QtCore import *
class EventReceiver(QObject):
"""
Class to allow events to be passed from different parts of the system.
This is a private class and should not be used directly but via the Receiver class
"""
def __init__(self):
QObject.__init__(self)
def send_repaint(self):
self.emit(SIGNAL("openlprepaint"), None)
def received(self, msg=None):
print msg
class Receiver():
"""
Class to allow events to be passed from different parts of the system.
This is a static wrapper arounf the EventReceiver class.
As there is only one instance of it in the systems the QT signal/slot architecture
can send messages across the system
Send message
receiver = Receiver()
receiver.send_repaint()
Receive Message
self.receiver = Receiver()
QtCore.QObject.connect(self.receiver.get_receiver(),QtCore.SIGNAL("openlprepaint"),<<ACTION>>)
"""
eventreceiver=EventReceiver()
@staticmethod
def send_repaint():
Receiver.eventreceiver.send_repaint()
@staticmethod
def receive():
Receiver.eventreceiver.receive()
@staticmethod
def get_receiver():
return Receiver.eventreceiver

View File

@ -116,12 +116,6 @@ class Plugin(object):
""" """
pass pass
def add_repaint_main_window(self, repaint_main_window):
"""
Create ability to repaint main window.
"""
self.repaint_main_window = repaint_main_window
def get_settings_tab(self): def get_settings_tab(self):
""" """
Create a menu item and add it to the "Import" menu. Create a menu item and add it to the "Import" menu.

View File

@ -114,8 +114,3 @@ class PluginManager(object):
def hook_handle_event(self, event): def hook_handle_event(self, event):
pass pass
def hook_repaint_main_window(self, repaint_main_window):
for plugin in self.plugins:
plugin.add_repaint_main_window(repaint_main_window)

View File

@ -24,4 +24,5 @@ from alertform import AlertForm
from settings import SettingsDialog from settings import SettingsDialog
from mainwindow import MainWindow from mainwindow import MainWindow
__all__ = ['SplashScreen', 'AboutForm', 'AlertForm', 'SettingsDialog', 'MainWindow'] __all__ = ['SplashScreen', 'AboutForm', 'AlertForm', 'SettingsDialog', 'MainWindow']

View File

@ -18,12 +18,14 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA Place, Suite 330, Boston, MA 02111-1307 USA
""" """
import os import os
from time import sleep from time import sleep
from PyQt4 import *
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
from openlp.core.resources import * from openlp.core.resources import *
from openlp.core.ui import AboutForm, AlertForm, SettingsDialog from openlp.core.ui import AboutForm, AlertForm, SettingsDialog
from openlp.core.lib import Plugin, MediaManagerItem, SettingsTab from openlp.core.lib import Plugin, MediaManagerItem, SettingsTab, Receiver
from openlp.core import PluginManager from openlp.core import PluginManager
class MainWindow(object): class MainWindow(object):
@ -37,9 +39,11 @@ class MainWindow(object):
pluginpath = os.path.abspath(os.path.join(pluginpath, '..', '..','plugins')) pluginpath = os.path.abspath(os.path.join(pluginpath, '..', '..','plugins'))
self.plugin_manager = PluginManager(pluginpath) self.plugin_manager = PluginManager(pluginpath)
self.setupUi() self.setupUi()
self.receiver = Receiver()
QtCore.QObject.connect(self.receiver.get_receiver(),QtCore.SIGNAL("openlprepaint"),self.repaint)
def repaint_window(self): def repaint(self):
self.main_window.update() self.main_window.repaint()
def setupUi(self): def setupUi(self):
self.main_window.setObjectName("main_window") self.main_window.setObjectName("main_window")
@ -122,8 +126,6 @@ class MainWindow(object):
self.FileExportMenu.setObjectName("FileExportMenu") self.FileExportMenu.setObjectName("FileExportMenu")
# Call the hook method to pull in export menus. # Call the hook method to pull in export menus.
self.plugin_manager.hook_import_menu(self.FileExportMenu) self.plugin_manager.hook_import_menu(self.FileExportMenu)
# Call the hook method to export refresh.
self.plugin_manager.hook_repaint_main_window(self.repaint_window)
# #
self.OptionsMenu = QtGui.QMenu(self.MenuBar) self.OptionsMenu = QtGui.QMenu(self.MenuBar)
self.OptionsMenu.setObjectName("OptionsMenu") self.OptionsMenu.setObjectName("OptionsMenu")
@ -405,6 +407,7 @@ class MainWindow(object):
QtCore.QObject.connect(self.ToolsAlertItem, QtCore.SIGNAL("triggered()"), self.onToolsAlertItemClicked) QtCore.QObject.connect(self.ToolsAlertItem, QtCore.SIGNAL("triggered()"), self.onToolsAlertItemClicked)
QtCore.QObject.connect(self.OptionsSettingsItem, QtCore.SIGNAL("triggered()"), self.onOptionsSettingsItemClicked) QtCore.QObject.connect(self.OptionsSettingsItem, QtCore.SIGNAL("triggered()"), self.onOptionsSettingsItemClicked)
def retranslateUi(self): def retranslateUi(self):
self.main_window.setWindowTitle(QtGui.QApplication.translate("main_window", "openlp.org 2.0", None, QtGui.QApplication.UnicodeUTF8)) self.main_window.setWindowTitle(QtGui.QApplication.translate("main_window", "openlp.org 2.0", None, QtGui.QApplication.UnicodeUTF8))
self.FileMenu.setTitle(QtGui.QApplication.translate("main_window", "&File", None, QtGui.QApplication.UnicodeUTF8)) self.FileMenu.setTitle(QtGui.QApplication.translate("main_window", "&File", None, QtGui.QApplication.UnicodeUTF8))

View File

@ -25,7 +25,7 @@ from PyQt4.QtCore import *
from PyQt4.QtGui import * from PyQt4.QtGui import *
from openlp.core.resources import * from openlp.core.resources import *
from openlp.core.lib import Plugin,PluginUtils, MediaManagerItem from openlp.core.lib import Plugin,PluginUtils, MediaManagerItem, Receiver
from openlp.plugins.bibles.lib import BibleManager from openlp.plugins.bibles.lib import BibleManager
from openlp.plugins.bibles.forms import BibleImportForm from openlp.plugins.bibles.forms import BibleImportForm
@ -48,6 +48,11 @@ class BiblePlugin(Plugin, PluginUtils):
#Register the bible Manager #Register the bible Manager
self.biblemanager = BibleManager(self.config) self.biblemanager = BibleManager(self.config)
self.searchresults = {} # place to store the search results self.searchresults = {} # place to store the search results
self.receiver = Receiver()
QtCore.QObject.connect(self.receiver.get_receiver(),QtCore.SIGNAL("openlprepaint"),self.repaint)
def repaint(self):
self.MediaManagerItem.repaint()
def get_media_manager_item(self): def get_media_manager_item(self):
# Create the MediaManagerItem object # Create the MediaManagerItem object
@ -251,9 +256,6 @@ class BiblePlugin(Plugin, PluginUtils):
def onBibleAddClick(self): def onBibleAddClick(self):
pass pass
def refresh(self):
self.repaint_main_window()
def reload_bibles(self): def reload_bibles(self):
self.biblemanager.reload_bibles() self.biblemanager.reload_bibles()
self._initialise_form() self._initialise_form()

View File

@ -16,7 +16,8 @@ from PyQt4.QtGui import QDialog
from PyQt4.QtCore import pyqtSignature from PyQt4.QtCore import pyqtSignature
from bibleimportdialog import Ui_BibleImportDialog from bibleimportdialog import Ui_BibleImportDialog
from openlp.core.lib import PluginUtils from openlp.core.lib import PluginUtils, Receiver
class BibleImportForm(QDialog, Ui_BibleImportDialog, PluginUtils): class BibleImportForm(QDialog, Ui_BibleImportDialog, PluginUtils):
global log global log
@ -36,10 +37,16 @@ class BibleImportForm(QDialog, Ui_BibleImportDialog, PluginUtils):
self.bibleplugin = bibleplugin self.bibleplugin = bibleplugin
self.bibletype = None self.bibletype = None
self.barmax = 0 self.barmax = 0
self.receiver = Receiver()
QtCore.QObject.connect(self.LocationComboBox, QtCore.SIGNAL("activated(int)"), self.onLocationComboBox) QtCore.QObject.connect(self.LocationComboBox, QtCore.SIGNAL("activated(int)"), self.onLocationComboBox)
QtCore.QObject.connect(self.TypeComboBox, QtCore.SIGNAL("activated(int)"), self.onTypeComboBox) QtCore.QObject.connect(self.TypeComboBox, QtCore.SIGNAL("activated(int)"), self.onTypeComboBox)
QtCore.QObject.connect(self.BibleComboBox, QtCore.SIGNAL("activated(int)"), self.onBibleComboBox) QtCore.QObject.connect(self.BibleComboBox, QtCore.SIGNAL("activated(int)"), self.onBibleComboBox)
QtCore.QObject.connect(self.ProgressBar, QtCore.SIGNAL("valueChanged(int)"), self.on_ProgressBar_changed)
QtCore.QObject.connect(self.receiver.get_receiver(),QtCore.SIGNAL("openlprepaint"),self.on_ProgressBar_changed)
def on_ProgressBar_changed(self):
self.repaint()
@pyqtSignature("") @pyqtSignature("")
def on_VersesFileButton_clicked(self): def on_VersesFileButton_clicked(self):
@ -121,6 +128,7 @@ class BibleImportForm(QDialog, Ui_BibleImportDialog, PluginUtils):
if self.biblemanager != None: if self.biblemanager != None:
if not self.bibletype == None or len(self.BibleNameEdit.displayText()) > 0: if not self.bibletype == None or len(self.BibleNameEdit.displayText()) > 0:
self.MessageLabel.setText("Import Started") self.MessageLabel.setText("Import Started")
self.ProgressBar.setMinimum(0)
self.ProgressBar.setValue(0) self.ProgressBar.setValue(0)
self.progress = 0 self.progress = 0
self.biblemanager.process_dialog(self) self.biblemanager.process_dialog(self)
@ -132,21 +140,20 @@ class BibleImportForm(QDialog, Ui_BibleImportDialog, PluginUtils):
self.close() self.close()
def setMax(self, max): def setMax(self, max):
log.debug("set Max %s", max)
self.barmax = max self.barmax = max
self.ProgressBar.setMaximum(max) self.ProgressBar.setMaximum(max)
def incrementBar(self, text = None): def incrementBar(self, text ):
print self.progress, text, self.barmax log.debug("IncrementBar %s", text)
if text != None: self.MessageLabel.setText("Import processing " + text)
self.MessageLabel.setText("Import processed " + text)
else:
self.MessageLabel.setText("Import progressing")
self.progress +=1 self.progress +=1
self.ProgressBar.setValue(self.progress) self.ProgressBar.setValue(self.progress)
#self.update() print self.ProgressBar.value()
self.bibleplugin.refresh() print text + " " + str(self.progress)
def _import_bible(self): def _import_bible(self):
log.debug("Import Bible ")
if self.bibletype == "OSIS": if self.bibletype == "OSIS":
self.biblemanager.register_osis_file_bible(str(self.BibleNameEdit.displayText()), self.OSISLocationEdit.displayText()) self.biblemanager.register_osis_file_bible(str(self.BibleNameEdit.displayText()), self.OSISLocationEdit.displayText())
elif self.bibletype == "CSV": elif self.bibletype == "CSV":

View File

@ -62,7 +62,7 @@ class BibleDBImpl(BibleCommon):
self._load_testament("Apocrypha") self._load_testament("Apocrypha")
def add_verse(self, bookid, chap, vse, text): def add_verse(self, bookid, chap, vse, text):
log.debug( "add_verse %s,%s,%s", bookid, chap, vse) #log.debug( "add_verse %s,%s,%s", bookid, chap, vse)
metadata.bind.echo = False metadata.bind.echo = False
session = self.session() session = self.session()
verse = Verse() verse = Verse()

View File

@ -17,6 +17,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA
""" """
import logging import logging
from openlp.plugins.bibles.lib.bibleDBimpl import BibleDBImpl from openlp.plugins.bibles.lib.bibleDBimpl import BibleDBImpl
from openlp.core.lib import Receiver
class BibleOSISImpl(): class BibleOSISImpl():
global log global log
@ -27,6 +28,7 @@ class BibleOSISImpl():
self.booksOfBible = {} # books of the bible linked to bibleid {osis , name} self.booksOfBible = {} # books of the bible linked to bibleid {osis , name}
self.abbrevOfBible = {} # books of the bible linked to bibleid {osis ,Abbrev } self.abbrevOfBible = {} # books of the bible linked to bibleid {osis ,Abbrev }
fbibles=open(biblepath+"/osisbooks_en.txt", 'r') fbibles=open(biblepath+"/osisbooks_en.txt", 'r')
self.receiver = Receiver()
for line in fbibles: for line in fbibles:
p = line.split(",") p = line.split(",")
self.booksOfBible[p[0]] = p[1].replace('\n', '') self.booksOfBible[p[0]] = p[1].replace('\n', '')
@ -38,6 +40,7 @@ class BibleOSISImpl():
book_ptr = None book_ptr = None
id = 0 id = 0
count = 0
verseText = "<verse osisID=" verseText = "<verse osisID="
testament = 1 testament = 1
for f in osis.readlines(): for f in osis.readlines():
@ -74,15 +77,21 @@ class BibleOSISImpl():
if book_ptr != p[0]: if book_ptr != p[0]:
if book_ptr == None: # first time through if book_ptr == None: # first time through
if p[0] == "Gen": # set the max book size depending on the first book read if p[0] == "Gen": # set the max book size depending on the first book read
dialogobject.setMax(66) dialogobject.setMax(65)
else: else:
dialogobject.setMax(27) dialogobject.setMax(27)
if p[0] == "Gen": if p[0] == "Matt": # First book of NT
testament += 1 testament += 1
book_ptr = p[0] book_ptr = p[0]
book = self.bibledb.create_book(self.booksOfBible[p[0]] , self.abbrevOfBible[p[0]], testament) book = self.bibledb.create_book(self.booksOfBible[p[0]] , self.abbrevOfBible[p[0]], testament)
dialogobject.incrementBar(self.booksOfBible[p[0]] ) dialogobject.incrementBar(self.booksOfBible[p[0]] )
self.receiver.send_repaint() # send repaint message to dialog as book changed
count = 0
self.bibledb.add_verse(book.id, p[1], p[2], t) self.bibledb.add_verse(book.id, p[1], p[2], t)
count += 1
if count % 100 == 0: #Every x verses repaint the screen
self.receiver.send_repaint() # send repaint message to dialog
count = 0