Upgrade Songs Database to version 2

Change SQL layer to SQLALChemy
Fix the UI to use new layer
More changes to editsong dialog
Force suffix of sqlite

bzr-revno: 280
This commit is contained in:
Tim Bentley 2009-01-10 08:33:31 +00:00
parent 534ad57dc4
commit 7397c42ac4
14 changed files with 347 additions and 181 deletions

View File

@ -64,9 +64,9 @@ class PluginConfig(object):
def set_data_path(self, path): def set_data_path(self, path):
return self.set_config('data path', os.path.basename(path)) return self.set_config('data path', os.path.basename(path))
def get_files(self, default_suffixes=None): def get_files(self, suffix=None):
returnfiles = [] returnfiles = []
suffix = self.get_config("suffix name", default_suffixes) #suffix = self.get_config("suffix name", default_suffixes)
try: try:
files = os.listdir(self.get_data_path()) files = os.listdir(self.get_data_path())
except: except:

View File

@ -20,12 +20,32 @@ import logging
import sqlite3 import sqlite3
from openlp.core.lib import PluginConfig from openlp.core.lib import PluginConfig
from sqlalchemy import *
from sqlalchemy.sql import select
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker, mapper, relation, clear_mappers
from openlp.plugins.songs.lib.tables import *
from openlp.plugins.songs.lib.classes import *
clear_mappers()
mapper(Author, authors_table)
mapper(Book, song_books_table)
mapper(Song, songs_table,
properties={'authors': relation(Author, backref='songs',
secondary=authors_songs_table),
'book': relation(Book, backref='songs'),
'topics': relation(Topic, backref='songs',
secondary=songs_topics_table)})
mapper(Topic, topics_table)
class MigrateSongs(): class MigrateSongs():
def __init__(self, display): def __init__(self, display):
self.display = display self.display = display
self.config = PluginConfig("Songs") self.config = PluginConfig("Songs")
self.data_path = self.config.get_data_path() self.data_path = self.config.get_data_path()
self.database_files = self.config.get_files("olp3") self.database_files = self.config.get_files("sqlite")
print self.database_files
def process(self): def process(self):
self.display.output("Songs processing started"); self.display.output("Songs processing started");
@ -38,33 +58,29 @@ class MigrateSongs():
self._v1_9_0_authors(database) self._v1_9_0_authors(database)
self._v1_9_0_topics(database) self._v1_9_0_topics(database)
self._v1_9_0_songbook(database) self._v1_9_0_songbook(database)
self._v1_9_0_songauthors(database)
self._v1_9_0_songtopics(database)
self._v1_9_0_songs(database)
self._v1_9_0_songs_update(database)
conn = sqlite3.connect(self.data_path+os.sep+database)
conn.text_factory = str
c = conn.cursor()
c.execute("""select * from songs where songtitle like '%Come now%'""")
conn.commit()
conn.close()
self.display.output("Migration 1.9.0 Finished for " + database); self.display.output("Migration 1.9.0 Finished for " + database);
def _v1_9_0_authors(self, database): def _v1_9_0_authors(self, database):
self.display.sub_output("Authors Started for "+database); self.display.sub_output("Authors Started for "+database);
conn = sqlite3.connect(self.data_path+os.sep+database) conn = sqlite3.connect(self.data_path+os.sep+database)
conn.text_factory = str conn.execute("""alter table authors add column first_name varchar(128);""")
conn.execute("""alter table authors add column first_name varchar(40);""")
conn.commit() conn.commit()
self.display.sub_output("first name created") self.display.sub_output("first name created")
conn.execute("""alter table authors add column last_name varchar(40);""") conn.execute("""alter table authors add column last_name varchar(128);""")
conn.commit() conn.commit()
self.display.sub_output("last name created") self.display.sub_output("last name created")
conn.execute("""create index if not exists author1 on authors (authorname ASC,authorid ASC);""") conn.execute("""create index if not exists author1 on authors (display_name ASC,id ASC);""")
conn.commit() conn.commit()
self.display.sub_output("index author1 created") self.display.sub_output("index author1 created")
conn.execute("""create index if not exists author2 on authors (last_name ASC,authorid ASC);""") conn.execute("""create index if not exists author2 on authors (last_name ASC,id ASC);""")
conn.commit() conn.commit()
self.display.sub_output("index author2 created") self.display.sub_output("index author2 created")
conn.execute("""create index if not exists author3 on authors (first_name ASC,authorid ASC);""") conn.execute("""create index if not exists author3 on authors (first_name ASC,id ASC);""")
conn.commit() conn.commit()
self.display.sub_output("index author3 created") self.display.sub_output("index author3 created")
self.display.sub_output("Author Data Migration started") self.display.sub_output("Author Data Migration started")
@ -78,7 +94,7 @@ class MigrateSongs():
afn = dispname[:pos] afn = dispname[:pos]
aln = dispname[pos + 1:len(dispname)] aln = dispname[pos + 1:len(dispname)]
#txt = text[2] #txt = text[2]
s = "update authors set first_name = '" + afn + "' ,last_name = '" + aln + "' where authorid = " +str(author[0]) s = "update authors set first_name = '" + afn + "' ,last_name = '" + aln + "' where id = " +str(author[0])
text1 = c.execute(s) text1 = c.execute(s)
conn.commit() conn.commit()
@ -90,13 +106,13 @@ class MigrateSongs():
self.display.sub_output("Topics Started for "+database); self.display.sub_output("Topics Started for "+database);
conn = sqlite3.connect(self.data_path+os.sep+database) conn = sqlite3.connect(self.data_path+os.sep+database)
conn.text_factory = str conn.text_factory = str
conn.execute("""create table if not exists topics (topic_id integer Primary Key ASC AUTOINCREMENT);""") conn.execute("""create table if not exists topics (id integer Primary Key ASC AUTOINCREMENT);""")
conn.commit() conn.commit()
self.display.sub_output("Topic table created") self.display.sub_output("Topic table created")
conn.execute("""alter table topics add column topic_name varchar(40);""") conn.execute("""alter table topics add column name varchar(128);""")
conn.commit() conn.commit()
self.display.sub_output("topicname added") self.display.sub_output("topicname added")
conn.execute("""create index if not exists topic1 on topics (topic_name ASC,topic_id ASC);""") conn.execute("""create index if not exists topic1 on topics (name ASC,id ASC);""")
conn.commit() conn.commit()
conn.close() conn.close()
self.display.sub_output("index topic1 created") self.display.sub_output("index topic1 created")
@ -106,25 +122,129 @@ class MigrateSongs():
def _v1_9_0_songbook(self, database): def _v1_9_0_songbook(self, database):
self.display.sub_output("SongBook Started for "+database); self.display.sub_output("SongBook Started for "+database);
conn = sqlite3.connect(self.data_path+os.sep+database) conn = sqlite3.connect(self.data_path+os.sep+database)
conn.text_factory = str conn.execute("""create table if not exists song_books (id integer Primary Key ASC AUTOINCREMENT);""")
conn.execute("""create table if not exists songbook (songbook_id integer Primary Key ASC AUTOINCREMENT);""")
conn.commit() conn.commit()
self.display.sub_output("SongBook table created") self.display.sub_output("SongBook table created")
conn.execute("""alter table songbook add column songbook_name varchar(40);""") conn.execute("""alter table song_books add column name varchar(128);""")
conn.commit() conn.commit()
self.display.sub_output("songbook_name added") self.display.sub_output("songbook_name added")
conn.execute("""alter table songbook add column songbook_publisher varchar(40);""") conn.execute("""alter table song_books add column publisher varchar(128);""")
conn.commit() conn.commit()
self.display.sub_output("songbook_publisher added") self.display.sub_output("songbook_publisher added")
conn.execute("""create index if not exists songbook1 on songbook (songbook_name ASC,songbook_id ASC);""") conn.execute("""create index if not exists songbook1 on song_books (name ASC,id ASC);""")
conn.commit() conn.commit()
self.display.sub_output("index songbook1 created") self.display.sub_output("index songbook1 created")
conn.execute("""create index if not exists songbook2 on songbook (songbook_publisher ASC,songbook_id ASC);""") conn.execute("""create index if not exists songbook2 on song_books (publisher ASC,id ASC);""")
conn.commit() conn.commit()
conn.close() conn.close()
self.display.sub_output("index songbook2 created") self.display.sub_output("index songbook2 created")
self.display.sub_output("SongBook Completed"); self.display.sub_output("SongBook Completed");
def _v1_9_0_songtopics(self, database):
self.display.sub_output("Songtopics Started for "+database);
conn = sqlite3.connect(self.data_path+os.sep+database)
conn.execute("""create table if not exists song_topics (song_id integer Primary Key ASC );""")
conn.commit()
self.display.sub_output("Songtopics table created")
conn.execute("""alter table song_topics add column topic_id interger;""")
conn.commit()
self.display.sub_output("songtopics_topic_id added")
conn.execute("""create index if not exists songtopic1 on song_topics (topic_id ASC,song_id ASC);""")
conn.commit()
self.display.sub_output("index songbook1 created")
conn.execute("""create index if not exists songbook2 on song_topics (song_id ASC,topic_id ASC);""")
conn.commit()
conn.close()
self.display.sub_output("index songbook2 created")
self.display.sub_output("SongTopics Completed");
def _v1_9_0_songauthors(self, database):
self.display.sub_output("SongAuthors Started for "+database);
conn = sqlite3.connect(self.data_path+os.sep+database)
conn.execute("""alter table songauthors rename to authors_songs;""")
conn.commit()
conn.close()
self.display.sub_output("Table Renamed")
self.display.sub_output("SongAuthors Completed");
def _v1_9_0_songs(self, database):
self.display.sub_output("Songs Started for "+database);
conn = sqlite3.connect(self.data_path+os.sep+database)
conn.execute("""alter table songs add column song_book_id interger;""")
conn.commit()
self.display.sub_output("songs_song_book_id added")
conn.execute("""alter table songs add column verse_order varchar(128);""")
conn.commit()
self.display.sub_output("songs verse_order added")
conn.execute("""alter table songs add column comments text;""")
conn.commit()
self.display.sub_output("songs comments added")
conn.execute("""alter table songs add ccli_number varchar(64);""")
conn.commit()
self.display.sub_output("songs ccli_number added")
conn.execute("""alter table songs add song_number varchar(64);""")
conn.commit()
self.display.sub_output("songs song_number added")
conn.execute("""alter table songs add theme_name varchar(128);""")
conn.commit()
self.display.sub_output("songs theme_name added")
conn.execute("""alter table songs add search_title varchar(255);""")
conn.commit()
self.display.sub_output("songs search_title added")
conn.execute("""alter table songs add search_lyrics text;""")
conn.commit()
self.display.sub_output("songs search_lyrics added")
conn.execute("""create index if not exists songs1 on songs (search_lyrics ASC,id ASC);""")
conn.commit()
self.display.sub_output("index songs1 created")
conn.execute("""create index if not exists songs2 on songs (search_title ASC,id ASC);""")
conn.commit()
conn.close()
self.display.sub_output("index songs2 created")
self.display.sub_output("Songs Completed");
def _v1_9_0_songs_update(self, database):
self.display.sub_output("Songs Started for "+database);
self.db = create_engine("sqlite:///"+self.data_path+os.sep+database, encoding='utf-8' , convert_unicode=False, assert_unicode=False)
self.db.echo = True
metadata.bind = self.db
metadata.bind.echo = False
Session = scoped_session(sessionmaker(autoflush=True, autocommit=False))
Session.configure(bind=self.db)
#create missing table
songs_topics_table.create()
songs = Session.query(Song).all()
for song in songs:
t=song.title.replace("&", "and")
t=t.replace("'", "")
t=t.replace(",", "")
t=t.replace(";", "")
t=t.replace(":", "")
t=t.replace("(", "")
t=t.replace(")", "")
t=t.replace("{", "")
t=t.replace("}", "")
t=t.replace("?", "")
song.search_title = t
t=song.lyrics.replace("&", "and")
t=t.replace("'", "")
t=t.replace(",", "")
t=t.replace(";", "")
t=t.replace(":", "")
t=t.replace("(", "")
t=t.replace(")", "")
t=t.replace("{", "")
t=t.replace("}", "")
t=t.replace("?", "")
song.search_lyrics = t
song.song_book_id = 0
Session.save_or_update(song)
Session.commit()
def run_cmd(self, cmd): def run_cmd(self, cmd):
f_i, f_o = os.popen4(cmd) f_i, f_o = os.popen4(cmd)

View File

@ -46,10 +46,10 @@ class BibleManager():
self.bibleHTTPCache = {} # dict of bible http readers self.bibleHTTPCache = {} # dict of bible http readers
self.biblePath = self.config.get_data_path() self.biblePath = self.config.get_data_path()
self.proxyname = self.config.get_config("proxy name") #get proxy name for screen self.proxyname = self.config.get_config("proxy name") #get proxy name for screen
self.bibleSuffix = self.config.get_config("suffix name", u'bible3,sqlite') self.bibleSuffix = "sqlite"
self.dialogobject = None self.dialogobject = None
files = self.config.get_files() files = self.config.get_files(self.bibleSuffix)
log.debug("Bible Files %s", files ) log.debug("Bible Files %s", files )
for f in files: for f in files:

View File

@ -82,7 +82,7 @@ class TestBibleManager:
def testGetBibleBooks(self): def testGetBibleBooks(self):
log.debug( "\n.......testGetBibleBooks") log.debug( "\n.......testGetBibleBooks")
c = self.bm.get_bible_books_full("NIV") c = self.bm.get_bible_books("NIV")
for c1 in c: for c1 in c:
log.debug( c1) log.debug( c1)
assert(c1 in c) assert(c1 in c)

View File

@ -53,7 +53,7 @@ class TestBibleManager:
def testRegisterOSISBibleFiles(self): def testRegisterOSISBibleFiles(self):
# Register a bible from files # Register a bible from files
log.debug("\n.......testRegisterOSISBibleFiles") log.debug("\n.......testRegisterOSISBibleFiles")
self.bm.register_OSIS_file_bible("asv",'asv.osis') self.bm.register_osis_file_bible("asv",'asv.osis')
b = self.bm.get_bibles() b = self.bm.get_bibles()
for b1 in b: for b1 in b:
log.debug( b1) log.debug( b1)

View File

@ -23,76 +23,71 @@ from PyQt4.QtGui import QDialog
from PyQt4.QtCore import pyqtSignature from PyQt4.QtCore import pyqtSignature
from authorsdialog import Ui_AuthorsDialog from authorsdialog import Ui_AuthorsDialog
from openlp.plugins.songs.lib.classes import *
class AuthorsForm(QDialog, Ui_AuthorsDialog): class AuthorsForm(QDialog, Ui_AuthorsDialog):
""" """
Class documentation goes here. Class to control the Maintenance of Authors Dialog
""" """
def __init__(self, songmanager, parent = None): def __init__(self, songmanager, parent = None):
""" """
Constructor Set up the screen and common data
""" """
QDialog.__init__(self, parent) QDialog.__init__(self, parent)
self.setupUi(self) self.setupUi(self)
self.songmanager = songmanager
self.AuthorListView.setColumnCount(2) self.AuthorListView.setColumnCount(2)
self.AuthorListView.setColumnHidden(0, True) self.AuthorListView.setColumnHidden(0, True)
self.AuthorListView.setColumnWidth(1, 300) self.AuthorListView.setColumnWidth(1, 300)
self.AuthorListView.setHorizontalHeaderLabels(QtCore.QStringList([" ","Author"])) self.AuthorListView.setHorizontalHeaderLabels(QtCore.QStringList([" ","Author"]))
self.authorid = 0 # this is the selected authorid for updates and deletes
self.candelete = False self.candelete = False
self.currentrow = 0 self.currentrow = 0
self.songmanager = songmanager self.author = None
def load_form(self): def load_form(self):
list = self.songmanager.get_authors() """
Refresh the screen and rest fields
"""
self.on_ClearButton_clicked() # tidy up screen
authors = self.songmanager.get_authors()
self.AuthorListView.clear() # clear the results self.AuthorListView.clear() # clear the results
self.AuthorListView.setHorizontalHeaderLabels(QtCore.QStringList([" ","Author"])) self.AuthorListView.setHorizontalHeaderLabels(QtCore.QStringList([" ","Author"]))
self.AuthorListView.setRowCount(0) self.AuthorListView.setRowCount(0)
for id, txt in list: for author in authors:
c = self.AuthorListView.rowCount() c = self.AuthorListView.rowCount()
self.AuthorListView.setRowCount(c+1) self.AuthorListView.setRowCount(c+1)
twi = QtGui.QTableWidgetItem(str(id)) twi = QtGui.QTableWidgetItem(str(author.id))
self.AuthorListView.setItem(c , 0, twi) self.AuthorListView.setItem(c , 0, twi)
twi = QtGui.QTableWidgetItem(str(txt)) twi = QtGui.QTableWidgetItem(str(author.display_name))
#twi.setFlags(Not QtCore.Qt.ItemIsSelectable & QtCore.Qt.ItemIsEnabled)
twi.setFlags(QtCore.Qt.ItemIsSelectable) twi.setFlags(QtCore.Qt.ItemIsSelectable)
self.AuthorListView.setItem(c , 1, twi) self.AuthorListView.setItem(c , 1, twi)
self.AuthorListView.setRowHeight(c, 20) self.AuthorListView.setRowHeight(c, 20)
c = self.AuthorListView.rowCount() c = self.AuthorListView.rowCount()
if self.currentrow > c: # incase we have delete the last row of the table if self.currentrow > c: # incase we have delete the last row of the table
self.currentrow = c self.currentrow = c
self.AuthorListView.selectRow(self.currentrow) self.AuthorListView.selectRow(self.currentrow) # set selected row to previous selected row
@pyqtSignature("")
def on_buttonBox_accepted(self):
"""
Slot documentation goes here.
"""
print "bb acc"
@pyqtSignature("")
def on_buttonBox_rejected(self):
"""
Slot documentation goes here.
"""
print "bb rej"
@pyqtSignature("") @pyqtSignature("")
def on_DeleteButton_clicked(self): def on_DeleteButton_clicked(self):
""" """
Slot documentation goes here. Delete the author is the Author is not attached to any songs
""" """
if self.candelete == True: if self.candelete == True:
self.songmanager.delete_author(self.authorid) self.songmanager.delete_author(self.author.id)
self.on_ClearButton_clicked() self.on_ClearButton_clicked()
self.load_form() self.load_form()
@pyqtSignature("") @pyqtSignature("")
def on_AddUpdateButton_clicked(self): def on_AddUpdateButton_clicked(self):
""" """
Slot documentation goes here. Sent New or update details to the database
""" """
self.songmanager.save_author(str(self.DisplayEdit.displayText()),str(self.FirstNameEdit.displayText()) ,str(self.LastNameEdit.displayText()) , self.authorid) if self.author == None:
self.author = Author()
self.author.display_name = unicode(self.DisplayEdit.displayText())
self.author.first_name = unicode(self.FirstNameEdit.displayText())
self.author.last_name = unicode(self.LastNameEdit.displayText())
self.songmanager.save_author(self.author)
self.on_ClearButton_clicked() self.on_ClearButton_clicked()
self.load_form() self.load_form()
@ -100,13 +95,14 @@ class AuthorsForm(QDialog, Ui_AuthorsDialog):
@pyqtSignature("") @pyqtSignature("")
def on_ClearButton_clicked(self): def on_ClearButton_clicked(self):
""" """
Slot documentation goes here. Tidy up screen if clear button pressed
""" """
self.authorid = 0
self.DisplayEdit.setText("") self.DisplayEdit.setText("")
self.FirstNameEdit.setText("") self.FirstNameEdit.setText("")
self.LastNameEdit.setText("") self.LastNameEdit.setText("")
self.MessageLabel.setText("")
self.candelete = True self.candelete = True
self.author = None
@pyqtSignature("QTableWidgetItem*") @pyqtSignature("QTableWidgetItem*")
def on_AuthorListView_itemClicked(self, item): def on_AuthorListView_itemClicked(self, item):
@ -115,14 +111,14 @@ class AuthorsForm(QDialog, Ui_AuthorsDialog):
""" """
self.currentrow = self.AuthorListView.currentRow() self.currentrow = self.AuthorListView.currentRow()
id = int(self.AuthorListView.item(self.currentrow, 0).text()) id = int(self.AuthorListView.item(self.currentrow, 0).text())
author = self.songmanager.get_author(id) self.author = self.songmanager.get_author(id)
self.authorid = author[0]
self.DisplayEdit.setText(author[1]) self.DisplayEdit.setText(self.author.display_name)
self.FirstNameEdit.setText(author[2]) self.FirstNameEdit.setText(self.author.first_name)
self.LastNameEdit.setText(author[3]) self.LastNameEdit.setText(self.author.last_name)
songs = self.songmanager.get_song_authors_for_author(id) songs = self.songmanager.get_song_authors_for_author(id)
if len(songs) > 0: if len(songs) > 0:
self.MessageLabel.setText("Author is attached to Songs") self.MessageLabel.setText("Author in use 'Delete' is disabled")
self.candelete = False self.candelete = False
else: else:
self.MessageLabel.setText("Author is not used") self.MessageLabel.setText("Author is not used")

View File

@ -2,7 +2,7 @@
# Form implementation generated from reading ui file 'editsongdialog.ui' # Form implementation generated from reading ui file 'editsongdialog.ui'
# #
# Created: Tue Jan 6 19:54:19 2009 # Created: Fri Jan 9 18:44:05 2009
# by: PyQt4 UI code generator 4.4.3 # by: PyQt4 UI code generator 4.4.3
# #
# WARNING! All changes made in this file will be lost! # WARNING! All changes made in this file will be lost!
@ -12,7 +12,7 @@ from PyQt4 import QtCore, QtGui
class Ui_EditSongDialog(object): class Ui_EditSongDialog(object):
def setupUi(self, EditSongDialog): def setupUi(self, EditSongDialog):
EditSongDialog.setObjectName("EditSongDialog") EditSongDialog.setObjectName("EditSongDialog")
EditSongDialog.resize(734, 761) EditSongDialog.resize(734, 756)
icon = QtGui.QIcon() icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap(":/icon/openlp.org-icon-32.bmp"), QtGui.QIcon.Normal, QtGui.QIcon.Off) icon.addPixmap(QtGui.QPixmap(":/icon/openlp.org-icon-32.bmp"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
EditSongDialog.setWindowIcon(icon) EditSongDialog.setWindowIcon(icon)
@ -41,12 +41,6 @@ class Ui_EditSongDialog(object):
self.AlternativeEdit = QtGui.QLineEdit(self.TextWidget) self.AlternativeEdit = QtGui.QLineEdit(self.TextWidget)
self.AlternativeEdit.setObjectName("AlternativeEdit") self.AlternativeEdit.setObjectName("AlternativeEdit")
self.gridLayout.addWidget(self.AlternativeEdit, 3, 0, 1, 1) self.gridLayout.addWidget(self.AlternativeEdit, 3, 0, 1, 1)
self.VerseOrderLabel = QtGui.QLabel(self.TextWidget)
self.VerseOrderLabel.setObjectName("VerseOrderLabel")
self.gridLayout.addWidget(self.VerseOrderLabel, 4, 0, 1, 1)
self.VerseOrderEdit = QtGui.QLineEdit(self.TextWidget)
self.VerseOrderEdit.setObjectName("VerseOrderEdit")
self.gridLayout.addWidget(self.VerseOrderEdit, 5, 0, 1, 1)
self.LyricsLabel = QtGui.QLabel(self.TextWidget) self.LyricsLabel = QtGui.QLabel(self.TextWidget)
self.LyricsLabel.setObjectName("LyricsLabel") self.LyricsLabel.setObjectName("LyricsLabel")
self.gridLayout.addWidget(self.LyricsLabel, 6, 0, 1, 1) self.gridLayout.addWidget(self.LyricsLabel, 6, 0, 1, 1)
@ -55,6 +49,12 @@ class Ui_EditSongDialog(object):
self.LyricsTextEdit.setAcceptRichText(False) self.LyricsTextEdit.setAcceptRichText(False)
self.LyricsTextEdit.setObjectName("LyricsTextEdit") self.LyricsTextEdit.setObjectName("LyricsTextEdit")
self.gridLayout.addWidget(self.LyricsTextEdit, 7, 0, 1, 1) self.gridLayout.addWidget(self.LyricsTextEdit, 7, 0, 1, 1)
self.VerseOrderEdit = QtGui.QLineEdit(self.TextWidget)
self.VerseOrderEdit.setObjectName("VerseOrderEdit")
self.gridLayout.addWidget(self.VerseOrderEdit, 5, 0, 1, 1)
self.VerseOrderLabel = QtGui.QLabel(self.TextWidget)
self.VerseOrderLabel.setObjectName("VerseOrderLabel")
self.gridLayout.addWidget(self.VerseOrderLabel, 4, 0, 1, 1)
self.Selectedroup = QtGui.QWidget(self.TopWidget) self.Selectedroup = QtGui.QWidget(self.TopWidget)
self.Selectedroup.setGeometry(QtCore.QRect(329, 0, 381, 531)) self.Selectedroup.setGeometry(QtCore.QRect(329, 0, 381, 531))
self.Selectedroup.setObjectName("Selectedroup") self.Selectedroup.setObjectName("Selectedroup")
@ -164,7 +164,7 @@ class Ui_EditSongDialog(object):
self.CopyrightInsertItem.setObjectName("CopyrightInsertItem") self.CopyrightInsertItem.setObjectName("CopyrightInsertItem")
self.gridLayout_4.addWidget(self.CopyrightInsertItem, 0, 1, 1, 1) self.gridLayout_4.addWidget(self.CopyrightInsertItem, 0, 1, 1, 1)
self.ThemeGroupBox = QtGui.QGroupBox(self.TopWidget) self.ThemeGroupBox = QtGui.QGroupBox(self.TopWidget)
self.ThemeGroupBox.setGeometry(QtCore.QRect(0, 540, 711, 66)) self.ThemeGroupBox.setGeometry(QtCore.QRect(0, 630, 711, 66))
self.ThemeGroupBox.setObjectName("ThemeGroupBox") self.ThemeGroupBox.setObjectName("ThemeGroupBox")
self.horizontalLayout_2 = QtGui.QHBoxLayout(self.ThemeGroupBox) self.horizontalLayout_2 = QtGui.QHBoxLayout(self.ThemeGroupBox)
self.horizontalLayout_2.setObjectName("horizontalLayout_2") self.horizontalLayout_2.setObjectName("horizontalLayout_2")
@ -175,6 +175,14 @@ class Ui_EditSongDialog(object):
self.ThemeAddItem.setMaximumSize(QtCore.QSize(110, 16777215)) self.ThemeAddItem.setMaximumSize(QtCore.QSize(110, 16777215))
self.ThemeAddItem.setObjectName("ThemeAddItem") self.ThemeAddItem.setObjectName("ThemeAddItem")
self.horizontalLayout_2.addWidget(self.ThemeAddItem) self.horizontalLayout_2.addWidget(self.ThemeAddItem)
self.CommentGroup = QtGui.QGroupBox(self.TopWidget)
self.CommentGroup.setGeometry(QtCore.QRect(10, 530, 701, 111))
self.CommentGroup.setObjectName("CommentGroup")
self.gridLayout_5 = QtGui.QGridLayout(self.CommentGroup)
self.gridLayout_5.setObjectName("gridLayout_5")
self.CommentsEdit = QtGui.QTextEdit(self.CommentGroup)
self.CommentsEdit.setObjectName("CommentsEdit")
self.gridLayout_5.addWidget(self.CommentsEdit, 0, 0, 1, 1)
self.ButtonBox = QtGui.QDialogButtonBox(EditSongDialog) self.ButtonBox = QtGui.QDialogButtonBox(EditSongDialog)
self.ButtonBox.setGeometry(QtCore.QRect(570, 720, 156, 27)) self.ButtonBox.setGeometry(QtCore.QRect(570, 720, 156, 27))
self.ButtonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Save) self.ButtonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Save)
@ -189,8 +197,8 @@ class Ui_EditSongDialog(object):
EditSongDialog.setWindowTitle(QtGui.QApplication.translate("EditSongDialog", "Song Editor", None, QtGui.QApplication.UnicodeUTF8)) EditSongDialog.setWindowTitle(QtGui.QApplication.translate("EditSongDialog", "Song Editor", None, QtGui.QApplication.UnicodeUTF8))
self.TitleLabel.setText(QtGui.QApplication.translate("EditSongDialog", "Title:", None, QtGui.QApplication.UnicodeUTF8)) self.TitleLabel.setText(QtGui.QApplication.translate("EditSongDialog", "Title:", None, QtGui.QApplication.UnicodeUTF8))
self.AlternativeTitleLabel.setText(QtGui.QApplication.translate("EditSongDialog", "Alternative Title:", None, QtGui.QApplication.UnicodeUTF8)) self.AlternativeTitleLabel.setText(QtGui.QApplication.translate("EditSongDialog", "Alternative Title:", None, QtGui.QApplication.UnicodeUTF8))
self.VerseOrderLabel.setText(QtGui.QApplication.translate("EditSongDialog", "Verse Order:", None, QtGui.QApplication.UnicodeUTF8))
self.LyricsLabel.setText(QtGui.QApplication.translate("EditSongDialog", "Lyrics:", None, QtGui.QApplication.UnicodeUTF8)) self.LyricsLabel.setText(QtGui.QApplication.translate("EditSongDialog", "Lyrics:", None, QtGui.QApplication.UnicodeUTF8))
self.VerseOrderLabel.setText(QtGui.QApplication.translate("EditSongDialog", "Verse Order:", None, QtGui.QApplication.UnicodeUTF8))
self.AuthorsGroupBox.setTitle(QtGui.QApplication.translate("EditSongDialog", "Authors", None, QtGui.QApplication.UnicodeUTF8)) self.AuthorsGroupBox.setTitle(QtGui.QApplication.translate("EditSongDialog", "Authors", None, QtGui.QApplication.UnicodeUTF8))
self.AuthorAddtoSongItem.setText(QtGui.QApplication.translate("EditSongDialog", "Add to Song", None, QtGui.QApplication.UnicodeUTF8)) self.AuthorAddtoSongItem.setText(QtGui.QApplication.translate("EditSongDialog", "Add to Song", None, QtGui.QApplication.UnicodeUTF8))
self.AddAuthorsButton.setText(QtGui.QApplication.translate("EditSongDialog", "Add Authors", None, QtGui.QApplication.UnicodeUTF8)) self.AddAuthorsButton.setText(QtGui.QApplication.translate("EditSongDialog", "Add Authors", None, QtGui.QApplication.UnicodeUTF8))
@ -208,5 +216,5 @@ class Ui_EditSongDialog(object):
self.CopyrightInsertItem.setText(QtGui.QApplication.translate("EditSongDialog", "©", None, QtGui.QApplication.UnicodeUTF8)) self.CopyrightInsertItem.setText(QtGui.QApplication.translate("EditSongDialog", "©", None, QtGui.QApplication.UnicodeUTF8))
self.ThemeGroupBox.setTitle(QtGui.QApplication.translate("EditSongDialog", "Theme", None, QtGui.QApplication.UnicodeUTF8)) self.ThemeGroupBox.setTitle(QtGui.QApplication.translate("EditSongDialog", "Theme", None, QtGui.QApplication.UnicodeUTF8))
self.ThemeAddItem.setText(QtGui.QApplication.translate("EditSongDialog", "Add a Theme", None, QtGui.QApplication.UnicodeUTF8)) self.ThemeAddItem.setText(QtGui.QApplication.translate("EditSongDialog", "Add a Theme", None, QtGui.QApplication.UnicodeUTF8))
self.CommentGroup.setTitle(QtGui.QApplication.translate("EditSongDialog", "Comments", None, QtGui.QApplication.UnicodeUTF8))

View File

@ -17,7 +17,7 @@ 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 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 PyQt4 import QtCore, QtGui
from PyQt4.QtGui import QWidget from PyQt4.QtGui import QWidget
from PyQt4.QtCore import pyqtSignature from PyQt4.QtCore import pyqtSignature
@ -44,20 +44,42 @@ class EditSongForm(QWidget, Ui_EditSongDialog):
self.topics_form = TopicsForm(self.songmanager) self.topics_form = TopicsForm(self.songmanager)
self.song_book_form = SongBookForm(self.songmanager) self.song_book_form = SongBookForm(self.songmanager)
self.initialise() self.initialise()
self.AuthorsListView.setColumnCount(2)
self.AuthorsListView.setColumnHidden(0, True)
self.AuthorsListView.setColumnWidth(1, 200)
self.AuthorsListView.setShowGrid(False)
self.AuthorsListView.setSortingEnabled(False)
self.AuthorsListView.setAlternatingRowColors(True)
def initialise(self): def initialise(self):
list = self.songmanager.get_authors() list = self.songmanager.get_authors()
self.AuthorsSelectionComboItem.clear() self.AuthorsSelectionComboItem.clear()
for i in list: for i in list:
self.AuthorsSelectionComboItem.addItem( i.get_author_name()) self.AuthorsSelectionComboItem.addItem( i.display_name)
def load_song(self, songid): def load_song(self, songid):
self.songid = songid self.songid = songid
song = self.songmanager.get_song(songid) song = self.songmanager.get_song(songid)
self.TitleEditItem.setText(song.title)
self.TitleEditItem.setText(song[1]) self.LyricsTextEdit.setText(song.lyrics)
self.LyricsTextEdit.setText(song[2]) self.CopyrightEditItem.setText(song.copyright)
self.CopyrightEditItem.setText(song[3])
self.AuthorsListView.clear() # clear the results
self.AuthorsListView.setHorizontalHeaderLabels(QtCore.QStringList(["","Author"]))
self.AuthorsListView.setVerticalHeaderLabels(QtCore.QStringList([""]))
self.AuthorsListView.setRowCount(0)
for author in song.authors:
c = self.AuthorsListView.rowCount()
self.AuthorsListView.setRowCount(c+1)
twi = QtGui.QTableWidgetItem(str(author.id))
self.AuthorsListView.setItem(c , 0, twi)
twi = QtGui.QTableWidgetItem(str(author.display_name))
self.AuthorsListView.setItem(c , 1, twi)
self.AuthorsListView.setRowHeight(c, 20)
@pyqtSignature("") @pyqtSignature("")
def on_AddAuthorsButton_clicked(self): def on_AddAuthorsButton_clicked(self):

View File

@ -30,12 +30,12 @@ def init_models(url):
bind=create_engine(url))) bind=create_engine(url)))
mapper(Author, authors_table) #mapper(Author, authors_table)
mapper(Book, song_books_table) #mapper(Book, song_books_table)
mapper(Song, songs_table, #mapper(Song, songs_table,
properties={'authors': relation(Author, backref='songs', # properties={'authors': relation(Author, backref='songs',
secondary=authors_songs_table), # secondary=authors_songs_table),
'book': relation(Book, backref='songs'), # 'book': relation(Book, backref='songs'),
'topics': relation(Topic, backref='songs', # 'topics': relation(Topic, backref='songs',
secondary=songs_topics_table)}) # secondary=songs_topics_table)})
mapper(Topic, topics_table) #mapper(Topic, topics_table)

View File

@ -25,31 +25,29 @@ import string
from sqlalchemy import * from sqlalchemy import *
from sqlalchemy.sql import select from sqlalchemy.sql import select
from sqlalchemy.orm import sessionmaker, mapper from sqlalchemy import create_engine
from sqlalchemy.types import Text, Unicode from sqlalchemy.orm import scoped_session, sessionmaker, mapper, relation, clear_mappers
from openlp.plugins.songs.lib.tables import *
from openlp.plugins.songs.lib.classes import *
from openlp.core.utils import ConfigHelper from openlp.core.utils import ConfigHelper
from songtable import Author
import logging
class SongDBException(Exception): class SongDBException(Exception):
pass pass
class SongInvalidDatabaseError(Exception): class SongInvalidDatabaseError(Exception):
pass pass
metadata = MetaData() clear_mappers() # some reason we need this
mapper(Author, authors_table)
mapper(Book, song_books_table)
mapper(Song, songs_table,
properties={'authors': relation(Author, backref='songs',
secondary=authors_songs_table),
'book': relation(Book, backref='songs'),
'topics': relation(Topic, backref='songs',
secondary=songs_topics_table)})
mapper(Topic, topics_table)
author_table = Table('authors', metadata,
Column('authorid', Integer, primary_key=True),
Column('authorname', Unicode(length=40)),
Column('first_name', Unicode(length=40)),
Column('last_name',Unicode(length=40)),
)
mapper(Author,author_table)
class SongDBImpl(): class SongDBImpl():
global log global log
log=logging.getLogger("SongDBImpl") log=logging.getLogger("SongDBImpl")
@ -66,22 +64,16 @@ class SongDBImpl():
else: else:
raise SongInvalidDatabaseError("Database not mysql or sqlite") raise SongInvalidDatabaseError("Database not mysql or sqlite")
self.db.echo = True self.db.echo = True
#self.db.convert_unicode=False
metadata.bind = self.db metadata.bind = self.db
metadata.bind.echo = False metadata.bind.echo = False
self.Session = sessionmaker(autoflush=True, autocommit=False) self.Session = scoped_session(sessionmaker(autoflush=True, autocommit=False))
self.Session.configure(bind=self.db) self.Session.configure(bind=self.db)
#self.authors_table = Table('authors', metadata, autoload=True)
#self.settings = Table('settings', metadata, autoload=True)
#self.songauthors = Table('songauthors', metadata, autoload=True)
#self.songs = Table('songs', metadata, autoload=True)
def add_author(self, author_name, first_name, last_name): def save_author(self, author):
log.debug( "add_author %s,%s,%s", author_name, first_name, last_name) log.debug( "add_author %s,%s,%s", author.display_name, author.first_name, author.last_name)
metadata.bind.echo = True metadata.bind.echo = True
session = self.Session() session = self.Session()
authorsmeta = Author(authorname=author_name, first_name=first_name,last_name=last_name) session.save_or_update(author)
session.add(authorsmeta)
session.commit() session.commit()
def save_meta(self, key, value): def save_meta(self, key, value):
@ -102,27 +94,37 @@ class SongDBImpl():
def get_song(self, songid): def get_song(self, songid):
log.debug( "get_song ") log.debug( "get_song ")
metadata.bind.echo = True # metadata.bind.echo = True
s = text (""" select * FROM songs where songid = :c """) # s = text (""" select * FROM songs where songid = :c """)
return self.db.execute(s, c=songid).fetchone() # return self.db.execute(s, c=songid).fetchone()
metadata.bind.echo = False
session = self.Session()
return session.query(Song).get(songid)
def get_authors(self): def get_authors(self):
log.debug( "get_authors ") log.debug( "get_authors ")
metadata.bind.echo = False metadata.bind.echo = False
session = self.Session() session = self.Session()
return session.query(Author).order_by(Author.authorname).all() return session.query(Author).order_by(Author.display_name).all()
def get_author(self, authorid): def get_author(self, authorid):
log.debug( "get_author %s" , authorid) log.debug( "get_author %s" , authorid)
metadata.bind.echo = True # metadata.bind.echo = True
s = text (""" select * FROM authors where authorid = :i """) # s = text (""" select * FROM authors where authorid = :i """)
return self.db.execute(s, i=authorid).fetchone() # return self.db.execute(s, i=authorid).fetchone()
session = self.Session()
return session.query(Author).get(authorid)
def delete_author(self, authorid): def delete_author(self, authorid):
log.debug( "delete_author %s" , authorid) log.debug( "delete_author %s" , authorid)
metadata.bind.echo = True # metadata.bind.echo = True
s = text (""" delete FROM authors where authorid = :i """) # s = text (""" delete FROM authors where authorid = :i """)
return self.db.execute(s, i=authorid) # return self.db.execute(s, i=authorid)
session = self.Session()
author = session.query(Author).get(authorid)
session.delete(author)
session.commit()
def update_author(self, authorid, author_name, first_name, last_name): def update_author(self, authorid, author_name, first_name, last_name):
log.debug( "update_author %s,%s,%s,%s" , authorid, author_name, first_name, last_name) log.debug( "update_author %s,%s,%s,%s" , authorid, author_name, first_name, last_name)
@ -133,7 +135,7 @@ class SongDBImpl():
def get_song_authors_for_author(self, authorid): def get_song_authors_for_author(self, authorid):
log.debug( "get_song_authors for author %s ", authorid) log.debug( "get_song_authors for author %s ", authorid)
metadata.bind.echo = False metadata.bind.echo = False
s = text (""" select * FROM songauthors where authorid = :c """) s = text (""" select * FROM authors_songs where author_id = :c """)
return self.db.execute(s, c=authorid).fetchall() return self.db.execute(s, c=authorid).fetchall()
def get_song_authors_for_song(self, songid): def get_song_authors_for_song(self, songid):
@ -145,18 +147,24 @@ class SongDBImpl():
def get_song_from_lyrics(self,searchtext): def get_song_from_lyrics(self,searchtext):
log.debug( "get_song_from_lyrics %s",searchtext) log.debug( "get_song_from_lyrics %s",searchtext)
metadata.bind.echo = False metadata.bind.echo = False
searchtext = "%"+searchtext+"%" searchtext = unicode("%"+searchtext+"%")
s = text (""" SELECT s.songid AS songid, s.songtitle AS songtitle, a.authorname AS authorname FROM songs s OUTER JOIN songauthors sa ON s.songid = sa.songid OUTER JOIN authors a ON sa.authorid = a.authorid WHERE s.lyrics LIKE :t ORDER BY s.songtitle ASC """) # s = text (""" SELECT s.songid AS songid, s.songtitle AS songtitle, a.authorname AS authorname FROM songs s OUTER JOIN songauthors sa ON s.songid = sa.songid OUTER JOIN authors a ON sa.authorid = a.authorid WHERE s.lyrics LIKE :t ORDER BY s.songtitle ASC """)
log.debug("Records returned from search %s", len(self.db.execute(s, t=searchtext).fetchall())) # log.debug("Records returned from search %s", len(self.db.execute(s, t=searchtext).fetchall()))
return self.db.execute(s, t=searchtext).fetchall() # return self.db.execute(s, t=searchtext).fetchall()
metadata.bind.echo = False
session = self.Session()
return session.query(Song).filter(Song.search_lyrics.like(searchtext)).order_by(Song.title).all()
def get_song_from_title(self,searchtext): def get_song_from_title(self,searchtext):
log.debug( "get_song_from_title %s",searchtext) log.debug( "get_song_from_title %s",searchtext)
# metadata.bind.echo = False
searchtext = unicode("%"+searchtext+"%")
# s = text (""" SELECT s.songid AS songid, s.songtitle AS songtitle, a.authorname AS authorname FROM songs s OUTER JOIN songauthors sa ON s.songid = sa.songid OUTER JOIN authors a ON sa.authorid = a.authorid WHERE s.songtitle LIKE :t ORDER BY s.songtitle ASC """)
# log.debug("Records returned from search %s", len(self.db.execute(s, t=searchtext).fetchall()))
# return self.db.execute(s, t=searchtext).fetchall()
metadata.bind.echo = False metadata.bind.echo = False
searchtext = "%"+searchtext+"%" session = self.Session()
s = text (""" SELECT s.songid AS songid, s.songtitle AS songtitle, a.authorname AS authorname FROM songs s OUTER JOIN songauthors sa ON s.songid = sa.songid OUTER JOIN authors a ON sa.authorid = a.authorid WHERE s.songtitle LIKE :t ORDER BY s.songtitle ASC """) return session.query(Song).filter(Song.search_title.like(searchtext)).order_by(Song.title).all()
log.debug("Records returned from search %s", len(self.db.execute(s, t=searchtext).fetchall()))
return self.db.execute(s, t=searchtext).fetchall()
def get_song_from_author(self,searchtext): def get_song_from_author(self,searchtext):
log.debug( "get_song_from_author %s",searchtext) log.debug( "get_song_from_author %s",searchtext)

View File

@ -42,11 +42,11 @@ class SongManager():
self.songDBCache = None self.songDBCache = None
self.authorcache = None self.authorcache = None
self.songPath = self.config.get_data_path() self.songPath = self.config.get_data_path()
self.songSuffix = self.config.get_config("suffix name", u'olp3,sqlite') self.songSuffix = "sqlite"
log.debug("Song Path %s and suffix %s", self.songPath, self.songSuffix ) log.debug("Song Path %s and suffix %s", self.songPath, self.songSuffix )
self.dialogobject = None self.dialogobject = None
files = self.config.get_files() files = self.config.get_files(self.songSuffix)
if len(files) > 0: if len(files) > 0:
log.debug("Song File %s", files ) log.debug("Song File %s", files )
self.songDBCache = SongDBImpl(self.songPath,files[0], self.songSuffix) self.songDBCache = SongDBImpl(self.songPath,files[0], self.songSuffix)
@ -81,14 +81,11 @@ class SongManager():
""" """
return self.songDBCache.get_author(authorid) return self.songDBCache.get_author(authorid)
def save_author(self, author_name, first_name, last_name, id = 0): def save_author(self, author):
""" """
Save the Author and refresh the cache Save the Author and refresh the cache
""" """
if id == 0: self.songDBCache.save_author(author)
self.songDBCache.add_author(author_name, first_name, last_name)
else:
self.songDBCache.update_author(id, author_name, first_name, last_name)
self.get_authors(True) # Updates occured refresh the cache self.get_authors(True) # Updates occured refresh the cache
return True return True

View File

@ -17,7 +17,6 @@ Place, Suite 330, Boston, MA 02111-1307 USA
""" """
class Author(object): class Author(object):
def __init__(self, authorname, first_name, last_name): def __init__(self, authorname, first_name, last_name):
#self.authorid = authorid
self.authorname =authorname self.authorname =authorname
self.first_name =first_name self.first_name =first_name
self.last_name =last_name self.last_name =last_name

View File

@ -25,7 +25,8 @@ from openlp.core.resources import *
from openlp.core.lib import Plugin,PluginUtils, MediaManagerItem from openlp.core.lib import Plugin,PluginUtils, MediaManagerItem
from forms import EditSongForm, OpenLPImportForm, OpenSongImportForm, \ from forms import EditSongForm, OpenLPImportForm, OpenSongImportForm, \
OpenLPExportForm, OpenSongExportForm OpenLPExportForm, OpenSongExportForm
from openlp.plugins.songs.lib import SongManager from openlp.plugins.songs.lib import SongManager
from openlp.plugins.songs.lib.classes import *
class SongsPlugin(Plugin, PluginUtils): class SongsPlugin(Plugin, PluginUtils):
global log global log
@ -46,7 +47,6 @@ class SongsPlugin(Plugin, PluginUtils):
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.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
@ -210,18 +210,19 @@ class SongsPlugin(Plugin, PluginUtils):
def onSearchTextButton(self): def onSearchTextButton(self):
searchtext = str(self.SearchTextEdit.displayText() ) searchtext = str(self.SearchTextEdit.displayText() )
searchresults = []
ct = self.SearchTypeComboBox.currentText() ct = self.SearchTypeComboBox.currentText()
if self.SearchTypeComboBox.currentText()=="Titles": if self.SearchTypeComboBox.currentText()=="Titles":
log.debug("Titles Search") log.debug("Titles Search")
self.searchresults = self.songmanager.get_song_from_title(searchtext) searchresults = self.songmanager.get_song_from_title(searchtext)
elif self.SearchTypeComboBox.currentText()=="Lyrics": elif self.SearchTypeComboBox.currentText()=="Lyrics":
log.debug("Lyrics Search") log.debug("Lyrics Search")
self.searchresults = self.songmanager.get_song_from_lyrics(searchtext) searchresults = self.songmanager.get_song_from_lyrics(searchtext)
elif self.SearchTypeComboBox.currentText()=="Authors": elif self.SearchTypeComboBox.currentText()=="Authors":
log.debug("Authors Search") log.debug("Authors Search")
self.searchresults = self.songmanager.get_song_from_author(searchtext) searchresults = self.songmanager.get_song_from_author(searchtext)
self._display_results() self._display_results(searchresults)
def onSongSelected(self, item): def onSongSelected(self, item):
print item print item
@ -259,21 +260,22 @@ class SongsPlugin(Plugin, PluginUtils):
def onExportOpenSongItemClicked(self): def onExportOpenSongItemClicked(self):
self.opensong_export_form.show() self.opensong_export_form.show()
def _display_results(self): def _display_results(self, searchresults):
log.debug("_search results") log.debug("_search results")
self.SongListView.clear() # clear the results self.SongListView.clear() # clear the results
self.SongListView.setHorizontalHeaderLabels(QtCore.QStringList(["","Song Name","Author"])) self.SongListView.setHorizontalHeaderLabels(QtCore.QStringList(["","Song Name","Author"]))
self.SongListView.setVerticalHeaderLabels(QtCore.QStringList([""])) self.SongListView.setVerticalHeaderLabels(QtCore.QStringList([""]))
self.SongListView.setRowCount(0) self.SongListView.setRowCount(0)
log.debug("Records returned from search %s", len(self.searchresults)) log.debug("Records returned from search %s", len(searchresults))
for id, txt, name in self.searchresults: for song in searchresults:
c = self.SongListView.rowCount() for author in song.authors:
self.SongListView.setRowCount(c+1) c = self.SongListView.rowCount()
twi = QtGui.QTableWidgetItem(str(id)) self.SongListView.setRowCount(c+1)
self.SongListView.setItem(c , 0, twi) twi = QtGui.QTableWidgetItem(str(song.id))
twi = QtGui.QTableWidgetItem(str(txt)) self.SongListView.setItem(c , 0, twi)
self.SongListView.setItem(c , 1, twi) twi = QtGui.QTableWidgetItem(str(song.title))
twi = QtGui.QTableWidgetItem(str(name)) self.SongListView.setItem(c , 1, twi)
self.SongListView.setItem(c , 2, twi) twi = QtGui.QTableWidgetItem(str(author.display_name))
self.SongListView.setRowHeight(c, 20) self.SongListView.setItem(c , 2, twi)
self.SongListView.setRowHeight(c, 20)

View File

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>734</width> <width>734</width>
<height>761</height> <height>756</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -63,16 +63,6 @@
<item row="3" column="0"> <item row="3" column="0">
<widget class="QLineEdit" name="AlternativeEdit"/> <widget class="QLineEdit" name="AlternativeEdit"/>
</item> </item>
<item row="4" column="0">
<widget class="QLabel" name="VerseOrderLabel">
<property name="text">
<string>Verse Order:</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLineEdit" name="VerseOrderEdit"/>
</item>
<item row="6" column="0"> <item row="6" column="0">
<widget class="QLabel" name="LyricsLabel"> <widget class="QLabel" name="LyricsLabel">
<property name="text"> <property name="text">
@ -90,6 +80,16 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="5" column="0">
<widget class="QLineEdit" name="VerseOrderEdit"/>
</item>
<item row="4" column="0">
<widget class="QLabel" name="VerseOrderLabel">
<property name="text">
<string>Verse Order:</string>
</property>
</widget>
</item>
</layout> </layout>
<zorder>TitleLabel</zorder> <zorder>TitleLabel</zorder>
<zorder>TitleEditItem</zorder> <zorder>TitleEditItem</zorder>
@ -351,17 +351,13 @@
</widget> </widget>
</item> </item>
</layout> </layout>
<zorder>CopyrightEditItem</zorder>
<zorder>CCLLabel</zorder>
<zorder>CCLNumberEdit</zorder>
<zorder>CopyrightInsertItem</zorder>
</widget> </widget>
</widget> </widget>
<widget class="QGroupBox" name="ThemeGroupBox"> <widget class="QGroupBox" name="ThemeGroupBox">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>540</y> <y>630</y>
<width>711</width> <width>711</width>
<height>66</height> <height>66</height>
</rect> </rect>
@ -388,6 +384,24 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<widget class="QGroupBox" name="CommentGroup">
<property name="geometry">
<rect>
<x>10</x>
<y>530</y>
<width>701</width>
<height>111</height>
</rect>
</property>
<property name="title">
<string>Comments</string>
</property>
<layout class="QGridLayout" name="gridLayout_5">
<item row="0" column="0">
<widget class="QTextEdit" name="CommentsEdit"/>
</item>
</layout>
</widget>
</widget> </widget>
<widget class="QDialogButtonBox" name="ButtonBox"> <widget class="QDialogButtonBox" name="ButtonBox">
<property name="geometry"> <property name="geometry">