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
pos = epos + 1 # find start 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
#remove tags of extra information

View File

@ -70,6 +70,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
def initialise(self):
self.loadAuthors()
self.loadTopics()
self.loadBooks()
def loadAuthors(self):
authors = self.songmanager.get_authors()
@ -83,6 +84,12 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
for topic in topics:
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):
self.song = self.songmanager.get_song(id)
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.exec_()
self.loadBooks()
def onAddVerseButtonClicked(self):
self.verse_form.setVerse('')

View File

@ -19,10 +19,6 @@ class Ui_SongBookDialog(object):
self.DialogLayout.setMargin(8)
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.setAlternatingRowColors(True)
self.BookSongListData = TextListData()

View File

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

View File

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

View File

@ -23,7 +23,7 @@ import sys
from sqlalchemy import asc, desc
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
@ -143,7 +143,6 @@ class SongManager():
return True
except:
log.error("Errow thrown %s", sys.exc_info()[1])
print "Errow thrown ", sys.exc_info()[1]
return False
def get_topics(self):
@ -180,5 +179,40 @@ class SongManager():
return True
except:
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