Fix unicode bible import error

More Song changes
This commit is contained in:
Tim Bentley 2009-06-04 21:06:32 +01:00
parent 5b58f7137f
commit 11a9d28bed
6 changed files with 116 additions and 73 deletions

View File

@ -66,7 +66,7 @@ class BibleOSISImpl():
#lets find the bible text only #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 = unicode(file[pos : epos], u'utf8')
#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

View File

@ -70,6 +70,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
def initialise(self): def initialise(self):
self.loadAuthors() self.loadAuthors()
self.loadTopics() self.loadTopics()
self.loadBooks()
def loadAuthors(self): def loadAuthors(self):
authors = self.songmanager.get_authors() authors = self.songmanager.get_authors()
@ -78,11 +79,17 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
self.AuthorsSelectionComboItem.addItem(author.display_name) self.AuthorsSelectionComboItem.addItem(author.display_name)
def loadTopics(self): def loadTopics(self):
topics= self.songmanager.get_topics() topics = self.songmanager.get_topics()
self.SongTopicCombo.clear() self.SongTopicCombo.clear()
for topic in topics: for topic in topics:
self.SongTopicCombo.addItem(topic.name) self.SongTopicCombo.addItem(topic.name)
def loadBooks(self):
books = self.songmanager.get_books()
self.SongbookCombo.clear()
for book in books:
self.SongbookCombo.addItem(book.name)
def loadSong(self, id): def loadSong(self, id):
self.song = self.songmanager.get_song(id) self.song = self.songmanager.get_song(id)
self.TitleEditItem.setText(self.song.title) self.TitleEditItem.setText(self.song.title)
@ -126,6 +133,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
""" """
self.song_book_form.load_form() self.song_book_form.load_form()
self.song_book_form.exec_() self.song_book_form.exec_()
self.loadBooks()
def onAddVerseButtonClicked(self): def onAddVerseButtonClicked(self):
self.verse_form.setVerse('') self.verse_form.setVerse('')

View File

@ -19,10 +19,6 @@ class Ui_SongBookDialog(object):
self.DialogLayout.setMargin(8) self.DialogLayout.setMargin(8)
self.DialogLayout.setObjectName("DialogLayout") self.DialogLayout.setObjectName("DialogLayout")
# self.BookSongListView = QtGui.QTableWidget(SongBookDialog)
# self.BookSongListView.setObjectName("BookSongListView")
# self.BookSongListView.setColumnCount(0)
# self.BookSongListView.setRowCount(0)
self.BookSongListView = QtGui.QListView() self.BookSongListView = QtGui.QListView()
self.BookSongListView.setAlternatingRowColors(True) self.BookSongListView.setAlternatingRowColors(True)
self.BookSongListData = TextListData() self.BookSongListData = TextListData()

View File

@ -18,19 +18,18 @@ Place, Suite 330, Boston, MA 02111-1307 USA
""" """
from PyQt4 import QtGui, QtCore from PyQt4 import QtGui, QtCore
from PyQt4.QtGui import QDialog
from PyQt4.QtCore import pyqtSignature
from songbookdialog import Ui_SongBookDialog from songbookdialog import Ui_SongBookDialog
from openlp.plugins.songs.lib.classes import Book
class SongBookForm(QDialog, Ui_SongBookDialog): class SongBookForm(QtGui.QDialog, Ui_SongBookDialog):
""" """
Class documentation goes here. Class documentation goes here.
""" """
def __init__(self,songmanager, parent = None): def __init__(self, songmanager, parent = None):
""" """
Constructor Constructor
""" """
QDialog.__init__(self, parent) QtGui.QDialog.__init__(self, parent)
self.setupUi(self) self.setupUi(self)
self.songmanager = songmanager self.songmanager = songmanager
self.currentRow = 0 self.currentRow = 0
@ -42,82 +41,85 @@ class SongBookForm(QDialog, Ui_SongBookDialog):
QtCore.SIGNAL('pressed()'), self.onClearButtonClick) QtCore.SIGNAL('pressed()'), self.onClearButtonClick)
QtCore.QObject.connect(self.AddUpdateButton, QtCore.QObject.connect(self.AddUpdateButton,
QtCore.SIGNAL('pressed()'), self.onAddUpdateButtonClick) QtCore.SIGNAL('pressed()'), self.onAddUpdateButtonClick)
# QtCore.QObject.connect(self.DisplayEdit, QtCore.QObject.connect(self.NameEdit,
# QtCore.SIGNAL('pressed()'), self.onDisplayEditLostFocus) QtCore.SIGNAL('lostFocus()'), self.onBookNameEditLostFocus)
# QtCore.QObject.connect(self.SongBookListView, QtCore.QObject.connect(self.BookSongListView,
# QtCore.SIGNAL(u'clicked(QModelIndex)'), self.onSongBookListViewItemClicked) QtCore.SIGNAL(u'clicked(QModelIndex)'), self.onBooksListViewItemClicked)
def load_form(self): def load_form(self):
""" """
Refresh the screen and rest fields Refresh the screen and rest fields
""" """
self.SongBookListData.resetStore() self.BookSongListData.resetStore()
self.onClearButtonClick() # tidy up screen self.onClearButtonClick() # tidy up screen
SongBooks = self.songmanager.get_SongBooks() Books = self.songmanager.get_books()
for SongBook in SongBooks: for Book in Books:
self.SongBookListData.addRow(SongBook.id,SongBook.display_name) self.BookSongListData.addRow(Book.id,Book.name)
row_count = self.SongBookListData.rowCount(None) row_count = self.BookSongListData.rowCount(None)
if self.currentRow > row_count: if self.currentRow > row_count:
# in case we have delete the last row of the table # in case we have delete the last row of the table
self.currentRow = row_count self.currentRow = row_count
row = self.SongBookListData.createIndex(self.currentRow, 0) row = self.BookSongListData.createIndex(self.currentRow, 0)
if row.isValid(): if row.isValid():
self.SongBookListView.selectionModel().setCurrentIndex(row, QtGui.QItemSelectionModel.SelectCurrent) self.BookSongListView.selectionModel().setCurrentIndex(row,
QtGui.QItemSelectionModel.SelectCurrent)
self._validate_form() self._validate_form()
def onDeleteButtonClick(self): def onDeleteButtonClick(self):
""" """
Delete the SongBook is the SongBook is not attached to any songs Delete the Book is the Book is not attached to any songs
""" """
self.songmanager.delete_SongBook(self.SongBook.id) self.songmanager.delete_book(self.Book.id)
self.onClearButtonClick()
self.load_form() self.load_form()
def onDisplayEditLostFocus(self): def onBookNameEditLostFocus(self):
self._validate_form() self._validate_form()
def onAddUpdateButtonClick(self): def onAddUpdateButtonClick(self):
""" """
Sent New or update details to the database Sent New or update details to the database
""" """
if self.SongBook == None: if self.Book == None:
self.SongBook = SongBook() self.Book = Book()
self.SongBook.display_name = unicode(self.DisplayEdit.displayText()) self.Book.name = unicode(self.NameEdit.displayText())
self.songmanager.save_SongBook(self.SongBook) self.Book.publisher = unicode(self.PublisherEdit.displayText())
self.songmanager.save_book(self.Book)
self.onClearButtonClick() self.onClearButtonClick()
self.load_form() self.load_form()
self._validate_form()
def onClearButtonClick(self): def onClearButtonClick(self):
""" """
Tidy up screen if clear button pressed Tidy up screen if clear button pressed
""" """
self.DisplayEdit.setText(u'') self.NameEdit.setText(u'')
self.PublisherEdit.setText(u'')
self.MessageLabel.setText(u'') self.MessageLabel.setText(u'')
self.DeleteButton.setEnabled(False) self.DeleteButton.setEnabled(False)
self.SongBook = None self.AddUpdateButton.setEnabled(True)
self.Book = None
self._validate_form() self._validate_form()
def onSongBookListViewItemClicked(self, index): def onBooksListViewItemClicked(self, index):
""" """
An SongBook has been selected display it An Book has been selected display it
If the SongBook is attached to a Song prevent delete If the Book is attached to a Song prevent delete
""" """
self.currentRow = index.row() self.currentRow = index.row()
id = int(self.SongBookListData.getId(index)) id = int(self.BookSongListData.getId(index))
self.SongBook = self.songmanager.get_SongBook(id) self.Book = self.songmanager.get_book(id)
self.DisplayEdit.setText(self.SongBook.display_name) self.NameEdit.setText(self.Book.name)
if len(self.SongBook.songs) > 0: self.PublisherEdit.setText(self.Book.publisher)
self.MessageLabel.setText("SongBook in use 'Delete' is disabled") if len(self.Book.songs) > 0:
self.MessageLabel.setText("Book in use 'Delete' is disabled")
self.DeleteButton.setEnabled(False) self.DeleteButton.setEnabled(False)
else: else:
self.MessageLabel.setText("SongBook is not used") self.MessageLabel.setText("Book is not used")
self.DeleteButton.setEnabled(True) self.DeleteButton.setEnabled(True)
self._validate_form() self._validate_form()
def _validate_form(self): def _validate_form(self):
if len(self.DisplayEdit.displayText()) == 0: # We need at lease a display name if len(self.NameEdit.displayText()) == 0: # We need at lease a display name
self.AddUpdateButton.setEnabled(False) self.AddUpdateButton.setEnabled(False)
else: else:
self.AddUpdateButton.setEnabled(True) self.AddUpdateButton.setEnabled(True)

View File

@ -52,6 +52,7 @@ class TopicsForm(QtGui.QDialog, Ui_TopicsDialog):
""" """
Refresh the screen and rest fields Refresh the screen and rest fields
""" """
print "topics load form start"
self.TopicsListData.resetStore() self.TopicsListData.resetStore()
self.onClearButtonClick() # tidy up screen self.onClearButtonClick() # tidy up screen
Topics = self.songmanager.get_topics() Topics = self.songmanager.get_topics()
@ -66,12 +67,14 @@ class TopicsForm(QtGui.QDialog, Ui_TopicsDialog):
self.TopicsListView.selectionModel().setCurrentIndex(row, self.TopicsListView.selectionModel().setCurrentIndex(row,
QtGui.QItemSelectionModel.SelectCurrent) QtGui.QItemSelectionModel.SelectCurrent)
self._validate_form() self._validate_form()
print "topics load form end"
def onDeleteButtonClick(self): def onDeleteButtonClick(self):
""" """
Delete the Topic is the Topic is not attached to any songs Delete the Topic is the Topic is not attached to any songs
""" """
self.songmanager.delete_topic(self.Topic.id) self.songmanager.delete_topic(self.Topic.id)
self.onClearButtonClick()
self.load_form() self.load_form()
def onTopicNameEditLostFocus(self): def onTopicNameEditLostFocus(self):

View File

@ -23,7 +23,7 @@ import sys
from sqlalchemy import asc, desc from sqlalchemy import asc, desc
from openlp.plugins.songs.lib.models import init_models, metadata, session, \ from openlp.plugins.songs.lib.models import init_models, metadata, session, \
engine, songs_table, Song, Author, Topic engine, songs_table, Song, Author, Topic, Book
import logging import logging
@ -143,7 +143,6 @@ class SongManager():
return True return True
except: except:
log.error("Errow thrown %s", sys.exc_info()[1]) log.error("Errow thrown %s", sys.exc_info()[1])
print "Errow thrown ", sys.exc_info()[1]
return False return False
def get_topics(self): def get_topics(self):
@ -180,5 +179,40 @@ class SongManager():
return True return True
except: except:
log.error("Errow thrown %s", sys.exc_info()[1]) log.error("Errow thrown %s", sys.exc_info()[1])
print "Errow thrown ", sys.exc_info()[1] return False
def get_books(self):
"""
Returns a list of all the Books
"""
return self.session.query(Book).order_by(Book.name).all()
def get_book(self, id):
"""
Details of the Books
"""
return self.session.query(Book).get(id)
def save_book(self, book):
"""
Save the Book
"""
try:
self.session.add(book)
self.session.commit()
return True
except:
return False
def delete_book(self, bookid):
"""
Delete the Book
"""
book = self.get_book(bookid)
try:
self.session.delete(book)
self.session.commit()
return True
except:
log.error("Errow thrown %s", sys.exc_info()[1])
return False return False