Add SongXMLHander Class

Tidy up OSIS Bible importer
Start to move Video Plugin to mediaitem and remove PluginUtils

bzr-revno: 408
This commit is contained in:
Tim Bentley 2009-03-12 19:52:37 +00:00
parent cf2067fb61
commit 21bfa234e8
9 changed files with 61 additions and 341 deletions

View File

@ -28,6 +28,9 @@ from serviceitem import ServiceItem
from eventreceiver import Receiver from eventreceiver import Receiver
from serviceitem import ServiceItem from serviceitem import ServiceItem
from toolbar import OpenLPToolbar from toolbar import OpenLPToolbar
from songxmlhandler import SongXMLBuilder
from songxmlhandler import SongXMLParser
__all__ = ['PluginConfig', 'Plugin', 'PluginUtils', 'SettingsTab', 'MediaManagerItem', 'Event', __all__ = ['PluginConfig', 'Plugin', 'PluginUtils', 'SettingsTab', 'MediaManagerItem', 'Event',
'XmlRootClass', 'ServiceItem', 'Receiver', 'OpenLPToolbar'] 'XmlRootClass', 'ServiceItem', 'Receiver', 'OpenLPToolbar', 'SongXMLBuilder',
'SongXMLParser']

View File

@ -135,4 +135,4 @@ class PluginConfig(object):
name = 'last directory %d' % num name = 'last directory %d' % num
else: else:
name = 'last directory' name = 'last directory'
self.config.set_config(name, directory) self.set_config(name, directory)

View File

@ -53,74 +53,34 @@ class BibleOSISImpl():
verseText = "<verse osisID=" verseText = "<verse osisID="
testament = 1 testament = 1
for file in osis.readlines(): for file in osis.readlines():
if self.loadbible == False: # cancel pressed # cancel pressed on UI
if self.loadbible == False:
break break
# print file # print file
pos = file.find(verseText) pos = file.find(verseText)
if pos > -1: # we have a verse if pos > -1: # we have a verse
epos= file.find(">", pos) epos= file.find(">", pos)
ref = file[pos+15:epos-1] # Book Reference ref = file[pos+15:epos-1] # Book Reference
#lets find the bible text
#lets find the bible text only
pos = epos + 1 # find start of text pos = epos + 1 # find start of text
epos = file.find("</verse>", pos) # end of text epos = file.find("</verse>", pos) # end of text
text = file[pos : epos] text = file[pos : epos]
#print pos, e, f[pos:e] # Found Basic Text #print pos, e, f[pos:e] # Found Basic Text
#remove tags of extra information #remove tags of extra information
text = self.remove_block('<title','</title>', text)
pos = text.find("<title") text = self.remove_block('<note','</note>', text)
while pos > -1: text = self.remove_block('<divineName','</divineName>', text)
epos = text.find("</title>", pos)
if epos == -1: # TODO
#print "Y", pos, epos
pos = -1
else:
text = text[:pos] + text[epos + 8: ]
pos = text.find("<title")
pos = text.find("<divineName") text = self.remove_tag('<lb', text)
while pos > -1: text = self.remove_tag('<q', text)
epos = text.find("</divineName>", pos) text = self.remove_tag('<l', text)
if epos == -1: # TODO text = self.remove_tag('<lg', text)
#print "Y", pos, epos
pos = -1
else:
text = text[:pos] + text[epos + 13: ]
pos = text.find("<divineName")
pos = text.find("<note")
while pos > -1:
epos = text.find("</note>", pos)
if epos == -1: # TODO
#print "Y", pos, epos
pos = -1
else:
text = text[:pos] + text[epos + 7: ]
pos = text.find("<note")
pos = text.find("<lb")
while pos > -1:
epos = text.find("/>", pos)
text = text[:pos] + text[epos + 2: ]
pos = text.find("<lb")
pos = text.find("<q")
while pos > -1:
epos = text.find("/>", pos)
text = text[:pos] + text[epos + 2: ]
pos = text.find("<q")
pos = text.find("<l")
while pos > -1:
epos = text.find("/>", pos)
text = text[:pos] + text[epos + 2: ]
pos = text.find("<l")
pos = text.find("<lg")
while pos > -1:
epos = text.find("/>", pos)
text = text[:pos] + text[epos + 2: ]
pos = text.find("<lg")
# Strange tags where the end is not the same as the start
# The must be in this order as at least one bible has them
# crossing and the removal does not work.
pos = text.find("<FI>") pos = text.find("<FI>")
while pos > -1: while pos > -1:
epos = text.find("<Fi>", pos) epos = text.find("<Fi>", pos)
@ -156,10 +116,37 @@ class BibleOSISImpl():
count = 0 count = 0
self.bibledb.add_verse(book.id, p[1], p[2], text) self.bibledb.add_verse(book.id, p[1], p[2], text)
count += 1 count += 1
if count % 3 == 0: #Every x verses repaint the screen if count % 3 == 0: #Every 3 verses repaint the screen
Receiver().send_message("openlpprocessevents") Receiver().send_message("openlpprocessevents")
count = 0 count = 0
def remove_block(self, start_tag, end_tag, text):
"""
removes a block of text between two tags
<tag attrib=xvf > Some not wanted text </tag>
"""
pos = text.find(start_tag)
while pos > -1:
epos = text.find(end_tag, pos)
if epos == -1: # TODO
#print "Y", pos, epos
pos = -1
else:
text = text[:pos] + text[epos + len(end_tag): ]
pos = text.find(start_tag)
return text
def remove_tag(self, start_tag, text):
"""
removes a single tag
<tag attrib1=fajkdf attrib2=fajkdf attrib2=fajkdf />
"""
pos = text.find(start_tag)
while pos > -1:
epos = text.find('/>', pos)
text = text[:pos] + text[epos + 2: ]
pos = text.find(start_tag)
return text

View File

@ -22,11 +22,11 @@ import logging
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
from openlp.core.resources import * from openlp.core.resources import *
from openlp.core.lib import Plugin, PluginUtils, MediaManagerItem from openlp.core.lib import Plugin, MediaManagerItem
from forms import EditCustomForm from forms import EditCustomForm
from openlp.plugins.custom.lib import CustomManager, CustomTab, CustomMediaItem from openlp.plugins.custom.lib import CustomManager, CustomTab, CustomMediaItem
class CustomPlugin(Plugin, PluginUtils): class CustomPlugin(Plugin):
global log global log
log=logging.getLogger("CustomPlugin") log=logging.getLogger("CustomPlugin")

View File

@ -20,7 +20,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA
from manager import CustomManager from manager import CustomManager
from customtab import CustomTab from customtab import CustomTab
from custommediaitem import CustomMediaItem from mediaitem import CustomMediaItem
__all__ = ['CustomManager', 'CustomTab', 'CustomMediaItem'] __all__ = ['CustomManager', 'CustomTab', 'CustomMediaItem']

View File

@ -1,194 +0,0 @@
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
"""
OpenLP - Open Source Lyrics Projection
Copyright (c) 2008 Raoul Snyman
Portions copyright (c) 2008-2009 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
"""
import logging
from PyQt4 import QtCore, QtGui
from openlp.core import translate
from openlp.core.lib import MediaManagerItem
from openlp.core.resources import *
from openlp.plugins.custom.lib import CustomTab
class CustomMediaItem(MediaManagerItem):
"""
This is the custom media manager item for Custom Slides.
"""
global log
log=logging.getLogger("CustomMediaItem")
log.info("Custom Media Item loaded")
def __init__(self, parent, icon, title):
MediaManagerItem.__init__(self, parent, icon, title)
def setupUi(self):
# Add a toolbar
self.addToolbar()
# Create buttons for the toolbar
## New Custom Button ##
self.addToolbarButton('New Custom', 'Add a new Custom Item',
':/custom/custom_new.png', self.onCustomNewClick, 'CustomNewItem')
## Edit Custom Button ##
self.addToolbarButton('Edit Custom', 'Edit the selected Custom Item',
':/custom/custom_edit.png', self.onCustomEditClick, 'CustomEditItem')
## Delete Custom Button ##
self.addToolbarButton('Delete Custom', 'Delete the selected Custom Item',
':/custom/custom_delete.png', self.onCustomDeleteClick, 'CustomDeleteItem')
## Separator Line ##
self.addToolbarSeparator()
## Preview Custom Button ##
self.addToolbarButton('Preview Custom', 'Preview the selected Custom',
':/system/system_preview.png', self.onCustomPreviewClick, 'CustomPreviewItem')
## Live Custom Button ##
self.addToolbarButton('Go Live', 'Send the selected Custom live',
':/system/system_live.png', self.onCustomLiveClick, 'CustomLiveItem')
## Add Custom Button ##
self.addToolbarButton('Add Custom To Service',
'Add the selected Custom(s) to the service', ':/system/system_add.png',
self.onCustomAddClick, 'CustomAddItem')
## Add the Customlist widget ##
# Create the tab widget
self.CustomWidget = QtGui.QWidget(self)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.CustomWidget.sizePolicy().hasHeightForWidth())
self.CustomWidget.setSizePolicy(sizePolicy)
self.CustomWidget.setObjectName('CustomWidget')
self.SearchLayout = QtGui.QGridLayout(self.CustomWidget)
self.SearchLayout.setObjectName('SearchLayout')
self.SearchTextLabel = QtGui.QLabel(self.CustomWidget)
self.SearchTextLabel.setObjectName('SearchTextLabel')
self.SearchTextLabel.setText('Search Text:')
self.SearchLayout.addWidget(self.SearchTextLabel, 2, 0, 1, 1)
self.SearchTextEdit = QtGui.QLineEdit(self.CustomWidget)
self.SearchTextEdit.setObjectName('SearchTextEdit')
self.SearchLayout.addWidget(self.SearchTextEdit, 2, 1, 1, 2)
self.ClearTextButton = QtGui.QPushButton(self.CustomWidget)
self.ClearTextButton.setObjectName('ClearTextButton')
self.ClearTextButton.setText('Clear')
self.SearchLayout.addWidget(self.ClearTextButton, 3, 1, 1, 1)
self.SearchTextButton = QtGui.QPushButton(self.CustomWidget)
self.SearchTextButton.setObjectName('SearchTextButton')
self.SearchTextButton.setText('Search')
self.SearchLayout.addWidget(self.SearchTextButton, 3, 2, 1, 1)
# Add the Custom widget to the page layout
self.PageLayout.addWidget(self.CustomWidget)
self.CustomListView = QtGui.QTableWidget()
self.CustomListView.setColumnCount(2)
self.CustomListView.setColumnHidden(0, True)
self.CustomListView.setColumnWidth(1, 240)
self.CustomListView.setShowGrid(False)
self.CustomListView.setSortingEnabled(False)
self.CustomListView.setAlternatingRowColors(True)
self.CustomListView.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
self.CustomListView.horizontalHeader().setVisible(False)
self.CustomListView.verticalHeader().setVisible(False)
self.CustomListView.setGeometry(QtCore.QRect(10, 100, 256, 591))
self.CustomListView.setObjectName('listView')
self.PageLayout.addWidget(self.CustomListView)
# Signals
QtCore.QObject.connect(self.SearchTextButton,
QtCore.SIGNAL("pressed()"), self.onSearchTextButtonClick)
QtCore.QObject.connect(self.ClearTextButton,
QtCore.SIGNAL("pressed()"), self.onClearTextButtonClick)
QtCore.QObject.connect(self.SearchTextEdit,
QtCore.SIGNAL("textChanged(const QString&)"), self.onSearchTextEditChanged)
QtCore.QObject.connect(self.CustomListView,
QtCore.SIGNAL("itemPressed(QTableWidgetItem * item)"), self.onCustomSelected)
# #define and add the context menu
self.CustomListView.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu)
#
self.CustomListView.addAction(self.contextMenuAction(
self.CustomListView, ':/system/system_preview.png',
"&Preview Custom", self.onCustomPreviewClick))
self.CustomListView.addAction(self.contextMenuAction(
self.CustomListView, ':/system/system_live.png',
"&Show Live", self.onCustomLiveClick))
self.CustomListView.addAction(self.contextMenuAction(
self.CustomListView, ':/system/system_add.png',
"&Add to Service", self.onCustomEditClick))
def onClearTextButtonClick(self):
"""
Clear the search text.
"""
self.SearchTextEdit.clear()
def onSearchTextEditChanged(self, text):
if len(text) > 3: # only search if > 3 characters
self.onSearchTextButtonClick()
def onSearchTextButtonClick(self):
search_keywords = str(self.SearchTextEdit.displayText())
search_results = []
search_type = self.SearchTypeComboBox.currentText()
search_results = self.Custommanager.search_Custom_lyrics(search_keywords)
self._display_results(search_results)
def onCustomSelected(self, item):
print item
def onCustomNewClick(self):
self.parent.edit_custom_form.exec_()
def onCustomEditClick(self):
current_row = self.CustomListView.currentRow()
id = int(self.CustomListView.item(current_row, 0).text())
self.edit_Custom_form.loadCustom(id)
self.edit_Custom_form.exec_()
def onCustomDeleteClick(self):
pass
def onCustomPreviewClick(self):
pass
def onCustomLiveClick(self):
pass
def onCustomAddClick(self):
pass
def _display_results(self, searchresults):
log.debug("_search results")
self.CustomListView.clear() # clear the results
self.CustomListView.setHorizontalHeaderLabels(QtCore.QStringList(['', u'Custom Name']))
self.CustomListView.horizontalHeader().setVisible(False)
self.CustomListView.verticalHeader().setVisible(False)
self.CustomListView.setRowCount(0)
#log.debug("Records returned from search %s", len(searchresults))
for Custom in searchresults:
for author in Custom.authors:
c = self.CustomListView.rowCount()
self.CustomListView.setRowCount(c + 1)
Custom_index = QtGui.QTableWidgetItem(str(Custom.id))
self.CustomListView.setItem(c , 0, Custom_index)
Custom_detail = QtGui.QTableWidgetItem(u'%s (%s)' % (str(Custom.title), str(author.display_name)))
self.CustomListView.setItem(c , 1, Custom_detail)
#twi = QtGui.QTableWidgetItem()
#self.CustomListView.setItem(c , 2, twi)
self.CustomListView.setRowHeight(c, 20)

View File

@ -113,7 +113,7 @@ class ImageMediaItem(MediaManagerItem):
log.info("New image(s)", str(files)) log.info("New image(s)", str(files))
if len(files) > 0: if len(files) > 0:
self.loadImageList(files) self.loadImageList(files)
dir, filename = os.path.split(files[0]) dir, filename = os.path.split(str(files[0]))
self.parent.config.set_last_dir(dir) self.parent.config.set_last_dir(dir)
self.parent.config.set_list('images', self.ImageListData.getFileList()) self.parent.config.set_list('images', self.ImageListData.getFileList())

View File

@ -19,5 +19,6 @@ Place, Suite 330, Boston, MA 02111-1307 USA
""" """
from videotab import VideoTab from videotab import VideoTab
from mediaitem import VideoMediaItem
__all__ = ['VideoTab'] __all__ = ['VideoTab', 'VideoMediaItem']

View File

@ -21,10 +21,10 @@ import os
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
from openlp.core.resources import * from openlp.core.resources import *
from openlp.core.lib import Plugin, PluginUtils, MediaManagerItem, SettingsTab from openlp.core.lib import Plugin, MediaManagerItem, SettingsTab
from openlp.plugins.videos.lib import VideoTab from openlp.plugins.videos.lib import VideoTab, VideoMediaItem
class VideoPlugin(Plugin, PluginUtils): class VideoPlugin(Plugin):
def __init__(self): def __init__(self):
# Call the parent constructor # Call the parent constructor
@ -41,83 +41,6 @@ class VideoPlugin(Plugin, PluginUtils):
def get_media_manager_item(self): def get_media_manager_item(self):
# Create the MediaManagerItem object # Create the MediaManagerItem object
self.MediaManagerItem = MediaManagerItem(self, self.icon, 'Videos') self.media_item = VideoMediaItem(self, self.icon, 'Videos')
# Add a toolbar return self.media_item
self.MediaManagerItem.addToolbar()
# Create buttons for the toolbar
## New Song Button ##
self.MediaManagerItem.addToolbarButton('New Video', 'Load videos into openlp.org',
':/videos/video_load.png', self.onVideoNewClick, 'VideoNewItem')
## Delete Song Button ##
self.MediaManagerItem.addToolbarButton('Delete Video', 'Delete the selected video',
':/videos/video_delete.png', self.onVideoDeleteClick, 'VideoDeleteItem')
## Separator Line ##
self.MediaManagerItem.addToolbarSeparator()
## Preview Song Button ##
self.MediaManagerItem.addToolbarButton('Preview Video', 'Preview the selected video',
':/system/system_preview.png', self.onVideoPreviewClick, 'VideoPreviewItem')
## Live Song Button ##
self.MediaManagerItem.addToolbarButton('Go Live', 'Send the selected video live',
':/system/system_live.png', self.onVideoLiveClick, 'VideoLiveItem')
## Add Song Button ##
self.MediaManagerItem.addToolbarButton('Add Video To Service',
'Add the selected video(s) to the service', ':/system/system_add.png',
self.onVideoAddClick, 'VideoAddItem')
## Add the videolist widget ##
self.VideoListView = QtGui.QTableWidget()
self.VideoListView.setColumnCount(2)
self.VideoListView.setColumnHidden(0, True)
self.VideoListView.setColumnWidth(1, 275)
self.VideoListView.setShowGrid(False)
self.VideoListView.setSortingEnabled(False)
self.VideoListView.setAlternatingRowColors(True)
self.VideoListView.verticalHeader().setVisible(False)
self.VideoListView.horizontalHeader().setVisible(False)
self.VideoListView.setAlternatingRowColors(True)
self.VideoListView.setGeometry(QtCore.QRect(10, 100, 256, 591))
self.VideoListView.setObjectName("VideoListView")
self.MediaManagerItem.PageLayout.addWidget(self.VideoListView)
#define and add the context menu
self.VideoListView.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu)
self.VideoListView.addAction(self.add_to_context_menu(self.VideoListView, ':/system/system_preview.png', "&Preview Video", self.onVideoPreviewClick))
self.VideoListView.addAction(self.add_to_context_menu(self.VideoListView, ':/system/system_live.png', "&Show Live", self.onVideoLiveClick))
self.VideoListView.addAction(self.add_to_context_menu(self.VideoListView, ':/system/system_add.png', "&Add to Service", self.onVideoAddClick))
return self.MediaManagerItem
def initialise(self):
list = self._load_display_list()
self._load_video_list(list)
def onVideoNewClick(self):
files = QtGui.QFileDialog.getOpenFileNames(None, "Select Image(s)", self._get_last_dir(), "Images (*.avi *.mpeg)")
if len(files) > 0:
self._load_video_list(files)
self._save_last_directory(files[0])
self._save_display_list(self.VideoListView)
def _load_video_list(self, list):
for f in list:
file_path , file_name = os.path.split(str(f))
count = self.VideoListView.rowCount()
self.VideoListView.setRowCount(count+1)
row_item = QtGui.QTableWidgetItem(str(f))
self.VideoListView.setItem(count , 0, row_item)
row_item = QtGui.QTableWidgetItem(str(file_name))
self.VideoListView.setItem(count , 1, row_item)
self.VideoListView.setRowHeight(count, 20)
def onVideoDeleteClick(self):
cr = self.VideoListView.currentRow()
self.VideoListView.removeRow(int(cr))
self._save_display_list(self.VideoListView)
def onVideoPreviewClick(self):
pass
def onVideoLiveClick(self):
pass
def onVideoAddClick(self):
pass