Add Songs database layer

bzr-revno: 248
This commit is contained in:
Tim Bentley 2008-12-19 20:27:09 +00:00
parent 78d0dc34c2
commit 9e4fa53b0e
5 changed files with 41 additions and 10 deletions

View File

@ -109,8 +109,8 @@ mapper(Verse, verse_table)
class BibleDBImpl(BibleCommon): class BibleDBImpl(BibleCommon):
global log global log
log=logging.getLogger("BibleDBMgr") log=logging.getLogger("BibleDBImpl")
log.info("BibleDB manager loaded") log.info("BibleDBimpl loaded")
def __init__(self, biblepath , biblename, suffix, btype = 'sqlite'): def __init__(self, biblepath , biblename, suffix, btype = 'sqlite'):
# Connect to database # Connect to database
self.biblefile = os.path.join(biblepath, biblename+"."+suffix) self.biblefile = os.path.join(biblepath, biblename+"."+suffix)

View File

@ -22,11 +22,6 @@ import sys
import urllib2 import urllib2
import logging import logging
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
datefmt='%m-%d %H:%M',
filename='plugins.log',
filemode='w')
class BibleCommon: class BibleCommon:
global log global log

View File

@ -30,7 +30,7 @@ import logging
class BibleManager(): class BibleManager():
global log global log
log=logging.getLogger("BibleMgr") log=logging.getLogger("BibleManager")
log.info("Bible manager loaded") log.info("Bible manager loaded")
def __init__(self, config): def __init__(self, config):
""" """

View File

@ -3,7 +3,7 @@
""" """
OpenLP - Open Source Lyrics Projection OpenLP - Open Source Lyrics Projection
Copyright (c) 2008 Raoul Snyman Copyright (c) 2008 Raoul Snyman
Portions copyright (c) 2008 Martin Thompson, Tim Bentley, Portions copyright (c) 2008 Martin Thompson, Tim Bentley
This program is free software; you can redistribute it and/or modify it under 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 the terms of the GNU General Public License as published by the Free Software
@ -18,4 +18,7 @@ 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
""" """
from songxml import * from songmanager import SongManager
__all__ = ['SongManager']

View File

@ -24,6 +24,7 @@ from openlp.core.resources import *
from openlp.core.lib import Plugin, MediaManagerItem from openlp.core.lib import Plugin, MediaManagerItem
from forms import EditSongForm, OpenLPImportForm, OpenSongImportForm, \ from forms import EditSongForm, OpenLPImportForm, OpenSongImportForm, \
OpenLPExportForm, OpenSongExportForm OpenLPExportForm, OpenSongExportForm
from openlp.plugins.songs.lib import SongManager
class SongsPlugin(Plugin): class SongsPlugin(Plugin):
def __init__(self): def __init__(self):
@ -39,6 +40,8 @@ class SongsPlugin(Plugin):
self.icon = QtGui.QIcon() self.icon = QtGui.QIcon()
self.icon.addPixmap(QtGui.QPixmap(':/media/media_song.png'), self.icon.addPixmap(QtGui.QPixmap(':/media/media_song.png'),
QtGui.QIcon.Normal, QtGui.QIcon.Off) QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.songmanager = SongManager(self.config)
self.searchresults = {} # place to store the search results
def get_media_manager_item(self): def get_media_manager_item(self):
# Create the MediaManagerItem object # Create the MediaManagerItem object
@ -92,6 +95,10 @@ class SongsPlugin(Plugin):
self.SearchTextEdit = QtGui.QLineEdit(self.SongWidget) self.SearchTextEdit = QtGui.QLineEdit(self.SongWidget)
self.SearchTextEdit.setObjectName('SearchTextEdit') self.SearchTextEdit.setObjectName('SearchTextEdit')
self.SearchLayout.addWidget(self.SearchTextEdit, 2, 1, 1, 2) self.SearchLayout.addWidget(self.SearchTextEdit, 2, 1, 1, 2)
self.ClearTextButton = QtGui.QPushButton(self.SongWidget)
self.ClearTextButton.setObjectName('ClearTextButton')
self.ClearTextButton.setText('Clear')
self.SearchLayout.addWidget(self.ClearTextButton, 3, 1, 1, 1)
self.SearchTextButton = QtGui.QPushButton(self.SongWidget) self.SearchTextButton = QtGui.QPushButton(self.SongWidget)
self.SearchTextButton.setObjectName('SearchTextButton') self.SearchTextButton.setObjectName('SearchTextButton')
self.SearchTextButton.setText('Search') self.SearchTextButton.setText('Search')
@ -102,6 +109,10 @@ class SongsPlugin(Plugin):
self.SongListView.setGeometry(QtCore.QRect(10, 100, 256, 591)) self.SongListView.setGeometry(QtCore.QRect(10, 100, 256, 591))
self.SongListView.setObjectName("listView") self.SongListView.setObjectName("listView")
self.MediaManagerItem.PageLayout.addWidget(self.SongListView) self.MediaManagerItem.PageLayout.addWidget(self.SongListView)
QtCore.QObject.connect(self.SearchTextButton, QtCore.SIGNAL("pressed()"), self.onSearchTextButton)
QtCore.QObject.connect(self.ClearTextButton, QtCore.SIGNAL("pressed()"), self.onClearTextButton)
QtCore.QObject.connect(self.SearchTextEdit, QtCore.SIGNAL("textChanged(const QString&)"), self.onSearchTextEdit)
return self.MediaManagerItem return self.MediaManagerItem
def add_import_menu_item(self, import_menu): def add_import_menu_item(self, import_menu):
@ -132,6 +143,7 @@ class SongsPlugin(Plugin):
QtCore.QObject.connect(self.ImportOpenlp2Item, QtCore.SIGNAL("triggered()"), self.onImportOpenlp1ItemClick) QtCore.QObject.connect(self.ImportOpenlp2Item, QtCore.SIGNAL("triggered()"), self.onImportOpenlp1ItemClick)
QtCore.QObject.connect(self.ImportOpenSongItem, QtCore.SIGNAL("triggered()"), self.onImportOpenSongItemClick) QtCore.QObject.connect(self.ImportOpenSongItem, QtCore.SIGNAL("triggered()"), self.onImportOpenSongItemClick)
def add_export_menu_item(self, export_menu): def add_export_menu_item(self, export_menu):
self.ExportSongMenu = QtGui.QMenu(export_menu) self.ExportSongMenu = QtGui.QMenu(export_menu)
self.ExportSongMenu.setObjectName("ExportSongMenu") self.ExportSongMenu.setObjectName("ExportSongMenu")
@ -160,6 +172,21 @@ class SongsPlugin(Plugin):
self.SearchTypeComboBox.addItem("Titles") self.SearchTypeComboBox.addItem("Titles")
self.SearchTypeComboBox.addItem("Authors") self.SearchTypeComboBox.addItem("Authors")
def onClearTextButton(self):
print self.SearchTextEdit.clear()
def onSearchTextEdit(self):
if len(self.SearchTextEdit.displayText()) > 3: # only search if > 3 characters
self.onSearchTextButton()
def onSearchTextButton(self):
searchtext = str(self.SearchTextEdit.displayText() )
if str(self.SearchTypeComboBox.currentText=="Titles"):
self.searchresults = self.songmanager.get_song_from_title(searchtext)
elif str(self.SearchTypeComboBox.currentText=="Lyrics"):
self.searchresults = self.songmanager.get_song_from_lyrics(searchtext)
self._display_results()
def onSongNewClick(self): def onSongNewClick(self):
pass pass
@ -189,3 +216,9 @@ class SongsPlugin(Plugin):
def onExportOpenSongItemClicked(self): def onExportOpenSongItemClicked(self):
self.opensong_export_form.show() self.opensong_export_form.show()
def _display_results(self):
self.SongListView.clear() # clear the results
print self.searchresults
for id, txt in self.searchresults:
self.SongListView.addItem(str(txt))