forked from openlp/openlp
Fix Database defaults
Add Topic Dialog and add functionality Add Topic code to Song window
This commit is contained in:
parent
b365090544
commit
5b58f7137f
@ -53,7 +53,7 @@ class SlideData(QtCore.QAbstractListModel):
|
||||
self.beginInsertRows(QtCore.QModelIndex(), row, row)
|
||||
log.info(u'insert row %d' % row)
|
||||
# create a preview image
|
||||
frame1 = frame.scaled(QtCore.QSize(300, 225), QtCore.Qt.KeepAspectRatio,
|
||||
frame1 = frame.scaled(QtCore.QSize(280, 210), QtCore.Qt.KeepAspectRatio,
|
||||
QtCore.Qt.SmoothTransformation)
|
||||
self.items.insert(row, (frame1, framenumber))
|
||||
log.info(u'Items: %s' % self.items)
|
||||
@ -196,7 +196,7 @@ class SlideController(QtGui.QWidget):
|
||||
sizePolicy.setHeightForWidth(
|
||||
self.SlidePreview.sizePolicy().hasHeightForWidth())
|
||||
self.SlidePreview.setSizePolicy(sizePolicy)
|
||||
self.SlidePreview.setMinimumSize(QtCore.QSize(250, 190))
|
||||
self.SlidePreview.setMinimumSize(QtCore.QSize(280, 210))
|
||||
self.SlidePreview.setFrameShape(QtGui.QFrame.Box)
|
||||
self.SlidePreview.setFrameShadow(QtGui.QFrame.Plain)
|
||||
self.SlidePreview.setLineWidth(1)
|
||||
|
@ -38,7 +38,7 @@ class BibleDBImpl(BibleCommon):
|
||||
self.config = config
|
||||
self.biblefile = os.path.join(biblepath, biblename+u'.sqlite')
|
||||
log.debug( "Load bible %s on path %s", biblename, self.biblefile)
|
||||
db_type = self.config.get_config(u'db type')
|
||||
db_type = self.config.get_config(u'db type', u'sqlite')
|
||||
if db_type == u'sqlite':
|
||||
self.db = create_engine("sqlite:///" + self.biblefile)
|
||||
else:
|
||||
|
@ -19,14 +19,6 @@ class Ui_AuthorsDialog(object):
|
||||
self.DialogLayout.setMargin(8)
|
||||
self.DialogLayout.setObjectName("DialogLayout")
|
||||
|
||||
|
||||
# self.AuthorListView = QtGui.QTableWidget(AuthorsDialog)
|
||||
# self.AuthorListView.setDragEnabled(True)
|
||||
# self.AuthorListView.setAlternatingRowColors(True)
|
||||
# self.AuthorListView.setColumnCount(0)
|
||||
# self.AuthorListView.setObjectName("AuthorListView")
|
||||
# self.AuthorListView.setColumnCount(0)
|
||||
# self.AuthorListView.setRowCount(0)
|
||||
self.AuthorListView = QtGui.QListView()
|
||||
self.AuthorListView.setAlternatingRowColors(True)
|
||||
self.AuthorListData = TextListData()
|
||||
@ -115,7 +107,7 @@ class Ui_AuthorsDialog(object):
|
||||
self.FirstNameLabel.setText(QtGui.QApplication.translate("AuthorsDialog", "First Name:", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.LastNameLabel.setText(QtGui.QApplication.translate("AuthorsDialog", "Last Name:", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.ClearButton.setToolTip(QtGui.QApplication.translate("AuthorsDialog", "Clear Selection", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.ClearButton.setText(QtGui.QApplication.translate("AuthorsDialog", "New", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.ClearButton.setText(QtGui.QApplication.translate("AuthorsDialog", "Clear", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.AddUpdateButton.setToolTip(QtGui.QApplication.translate("AuthorsDialog", "Add Update Author", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.AddUpdateButton.setText(QtGui.QApplication.translate("AuthorsDialog", "Save", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.DeleteButton.setToolTip(QtGui.QApplication.translate("AuthorsDialog", "Delete Author", None, QtGui.QApplication.UnicodeUTF8))
|
||||
|
@ -42,7 +42,7 @@ class AuthorsForm(QtGui.QDialog, Ui_AuthorsDialog):
|
||||
QtCore.QObject.connect(self.AddUpdateButton,
|
||||
QtCore.SIGNAL('pressed()'), self.onAddUpdateButtonClick)
|
||||
QtCore.QObject.connect(self.DisplayEdit,
|
||||
QtCore.SIGNAL('pressed()'), self.onDisplayEditLostFocus)
|
||||
QtCore.SIGNAL('lostFocus()'), self.onDisplayEditLostFocus)
|
||||
QtCore.QObject.connect(self.AuthorListView,
|
||||
QtCore.SIGNAL(u'clicked(QModelIndex)'), self.onAuthorListViewItemClicked)
|
||||
|
||||
@ -61,7 +61,8 @@ class AuthorsForm(QtGui.QDialog, Ui_AuthorsDialog):
|
||||
self.currentRow = row_count
|
||||
row = self.AuthorListData.createIndex(self.currentRow, 0)
|
||||
if row.isValid():
|
||||
self.AuthorListView.selectionModel().setCurrentIndex(row, QtGui.QItemSelectionModel.SelectCurrent)
|
||||
self.AuthorListView.selectionModel().setCurrentIndex(row,
|
||||
QtGui.QItemSelectionModel.SelectCurrent)
|
||||
self._validate_form()
|
||||
|
||||
def onDeleteButtonClick(self):
|
||||
@ -69,7 +70,6 @@ class AuthorsForm(QtGui.QDialog, Ui_AuthorsDialog):
|
||||
Delete the author is the Author is not attached to any songs
|
||||
"""
|
||||
self.songmanager.delete_author(self.author.id)
|
||||
self.onClearButtonClick()
|
||||
self.load_form()
|
||||
|
||||
def onDisplayEditLostFocus(self):
|
||||
@ -87,7 +87,6 @@ class AuthorsForm(QtGui.QDialog, Ui_AuthorsDialog):
|
||||
self.songmanager.save_author(self.author)
|
||||
self.onClearButtonClick()
|
||||
self.load_form()
|
||||
self._validate_form()
|
||||
|
||||
def onClearButtonClick(self):
|
||||
"""
|
||||
|
@ -61,6 +61,7 @@ class Ui_EditSongDialog(object):
|
||||
self.VerseEditLayout.setObjectName("VerseEditLayout")
|
||||
self.VerseListWidget = QtGui.QListWidget(self.VerseEditWidget)
|
||||
self.VerseListWidget.setObjectName("VerseListWidget")
|
||||
self.VerseListWidget.setAlternatingRowColors(True)
|
||||
self.VerseEditLayout.addWidget(self.VerseListWidget)
|
||||
self.VerseButtonWidget = QtGui.QWidget(self.VerseEditWidget)
|
||||
self.VerseButtonWidget.setObjectName("VerseButtonWidget")
|
||||
@ -234,12 +235,12 @@ class Ui_EditSongDialog(object):
|
||||
self.AddTopicsToSongButton.setObjectName("AddTopicsToSongButton")
|
||||
self.TopicAddLayout.addWidget(self.AddTopicsToSongButton)
|
||||
self.TopicLayout.addWidget(self.TopicAddWidget)
|
||||
self.ToticsListView = QtGui.QTableWidget(self.TopicGroupBox)
|
||||
self.ToticsListView.setAlternatingRowColors(True)
|
||||
self.ToticsListView.setObjectName("ToticsListView")
|
||||
self.ToticsListView.setColumnCount(0)
|
||||
self.ToticsListView.setRowCount(0)
|
||||
self.TopicLayout.addWidget(self.ToticsListView)
|
||||
self.TopicsListView = QtGui.QTableWidget(self.TopicGroupBox)
|
||||
self.TopicsListView.setAlternatingRowColors(True)
|
||||
self.TopicsListView.setObjectName("TopicsListView")
|
||||
self.TopicsListView.setColumnCount(0)
|
||||
self.TopicsListView.setRowCount(0)
|
||||
self.TopicLayout.addWidget(self.TopicsListView)
|
||||
self.TopicRemoveWidget = QtGui.QWidget(self.TopicGroupBox)
|
||||
self.TopicRemoveWidget.setObjectName("TopicRemoveWidget")
|
||||
self.TopicRemoveLayout = QtGui.QHBoxLayout(self.TopicRemoveWidget)
|
||||
@ -311,8 +312,8 @@ class Ui_EditSongDialog(object):
|
||||
EditSongDialog.setTabOrder(self.AuthorRemoveItem, self.SongbookCombo)
|
||||
EditSongDialog.setTabOrder(self.SongbookCombo, self.AddSongBookButton)
|
||||
EditSongDialog.setTabOrder(self.AddSongBookButton, self.SongTopicCombo)
|
||||
EditSongDialog.setTabOrder(self.SongTopicCombo, self.ToticsListView)
|
||||
EditSongDialog.setTabOrder(self.ToticsListView, self.pushButton)
|
||||
EditSongDialog.setTabOrder(self.SongTopicCombo, self.TopicsListView)
|
||||
EditSongDialog.setTabOrder(self.TopicsListView, self.pushButton)
|
||||
EditSongDialog.setTabOrder(self.pushButton, self.CopyrightEditItem)
|
||||
EditSongDialog.setTabOrder(self.CopyrightEditItem, self.CopyrightInsertItem)
|
||||
EditSongDialog.setTabOrder(self.CopyrightInsertItem, self.CCLNumberEdit)
|
||||
|
@ -69,6 +69,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
|
||||
|
||||
def initialise(self):
|
||||
self.loadAuthors()
|
||||
self.loadTopics()
|
||||
|
||||
def loadAuthors(self):
|
||||
authors = self.songmanager.get_authors()
|
||||
@ -76,6 +77,12 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
|
||||
for author in authors:
|
||||
self.AuthorsSelectionComboItem.addItem(author.display_name)
|
||||
|
||||
def loadTopics(self):
|
||||
topics= self.songmanager.get_topics()
|
||||
self.SongTopicCombo.clear()
|
||||
for topic in topics:
|
||||
self.SongTopicCombo.addItem(topic.name)
|
||||
|
||||
def loadSong(self, id):
|
||||
self.song = self.songmanager.get_song(id)
|
||||
self.TitleEditItem.setText(self.song.title)
|
||||
@ -111,6 +118,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
|
||||
"""
|
||||
self.topics_form.load_form()
|
||||
self.topics_form.exec_()
|
||||
self.loadTopics()
|
||||
|
||||
def onAddSongBookButtonClicked(self):
|
||||
"""
|
||||
|
@ -42,10 +42,10 @@ 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.DisplayEdit,
|
||||
# QtCore.SIGNAL('pressed()'), self.onDisplayEditLostFocus)
|
||||
# QtCore.QObject.connect(self.SongBookListView,
|
||||
# QtCore.SIGNAL(u'clicked(QModelIndex)'), self.onSongBookListViewItemClicked)
|
||||
|
||||
def load_form(self):
|
||||
"""
|
||||
|
@ -36,13 +36,13 @@ class Ui_TopicsDialog(object):
|
||||
self.gridLayout.addWidget(self.DeleteButton, 1, 3, 1, 1)
|
||||
self.AddUpdateButton = QtGui.QPushButton(self.TopicGroupBox)
|
||||
icon1 = QtGui.QIcon()
|
||||
icon1.addPixmap(QtGui.QPixmap(":/system/system_settings.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
||||
icon1.addPixmap(QtGui.QPixmap(":/services/service_save.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
||||
self.AddUpdateButton.setIcon(icon1)
|
||||
self.AddUpdateButton.setObjectName("AddUpdateButton")
|
||||
self.gridLayout.addWidget(self.AddUpdateButton, 1, 4, 1, 1)
|
||||
self.ClearButton = QtGui.QPushButton(self.TopicGroupBox)
|
||||
icon2 = QtGui.QIcon()
|
||||
icon2.addPixmap(QtGui.QPixmap(":/songs/song_edit.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
||||
icon2.addPixmap(QtGui.QPixmap(":/services/service_new.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
||||
self.ClearButton.setIcon(icon2)
|
||||
self.ClearButton.setObjectName("ClearButton")
|
||||
self.gridLayout.addWidget(self.ClearButton, 1, 2, 1, 1)
|
||||
@ -51,11 +51,6 @@ class Ui_TopicsDialog(object):
|
||||
self.MessageLabel.setObjectName("MessageLabel")
|
||||
self.gridLayout_2.addWidget(self.MessageLabel, 3, 0, 1, 1)
|
||||
|
||||
# self.TopicsListView = QtGui.QTableWidget(TopicsDialog)
|
||||
# self.TopicsListView.setObjectName("TopicsListView")
|
||||
# self.TopicsListView.setColumnCount(0)
|
||||
# self.TopicsListView.setRowCount(0)
|
||||
|
||||
self.TopicsListView = QtGui.QListView()
|
||||
self.TopicsListView.setAlternatingRowColors(True)
|
||||
self.TopicsListData = TextListData()
|
||||
@ -77,8 +72,11 @@ class Ui_TopicsDialog(object):
|
||||
TopicsDialog.setWindowTitle(QtGui.QApplication.translate("TopicsDialog", "Topic Maintenance", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.TopicGroupBox.setTitle(QtGui.QApplication.translate("TopicsDialog", "Topic", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.TopicNameLabel.setText(QtGui.QApplication.translate("TopicsDialog", "Topic Name:", None, QtGui.QApplication.UnicodeUTF8))
|
||||
|
||||
self.DeleteButton.setToolTip(QtGui.QApplication.translate("TopicsDialog", "Delete Author", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.DeleteButton.setText(QtGui.QApplication.translate("AuthorsDialog", "Delete", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.AddUpdateButton.setToolTip(QtGui.QApplication.translate("TopicsDialog", "Add Update Author", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.AddUpdateButton.setText(QtGui.QApplication.translate("AuthorsDialog", "Save", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.ClearButton.setToolTip(QtGui.QApplication.translate("TopicsDialog", "Clear Selection", None, QtGui.QApplication.UnicodeUTF8))
|
||||
|
||||
self.ClearButton.setText(QtGui.QApplication.translate("TopicsDialog", "Clear", None, QtGui.QApplication.UnicodeUTF8))
|
||||
|
||||
|
@ -18,12 +18,12 @@ Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
"""
|
||||
|
||||
from PyQt4 import QtGui, QtCore
|
||||
from PyQt4.QtGui import QDialog
|
||||
from PyQt4.QtCore import pyqtSignature
|
||||
from openlp.plugins.songs.lib import TextListData
|
||||
|
||||
from topicsdialog import Ui_TopicsDialog
|
||||
from openlp.plugins.songs.forms.topicsdialog import Ui_TopicsDialog
|
||||
from openlp.plugins.songs.lib.classes import Topic
|
||||
|
||||
class TopicsForm(QDialog, Ui_TopicsDialog):
|
||||
class TopicsForm(QtGui.QDialog, Ui_TopicsDialog):
|
||||
"""
|
||||
Class documentation goes here.
|
||||
"""
|
||||
@ -31,7 +31,7 @@ class TopicsForm(QDialog, Ui_TopicsDialog):
|
||||
"""
|
||||
Constructor
|
||||
"""
|
||||
QDialog.__init__(self, parent)
|
||||
QtGui.QDialog.__init__(self, parent)
|
||||
self.setupUi(self)
|
||||
self.songmanager = songmanager
|
||||
self.currentRow = 0
|
||||
@ -43,38 +43,38 @@ class TopicsForm(QDialog, Ui_TopicsDialog):
|
||||
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.TopicListView,
|
||||
QtCore.SIGNAL(u'clicked(QModelIndex)'), self.onTopicListViewItemClicked)
|
||||
QtCore.QObject.connect(self.TopicNameEdit,
|
||||
QtCore.SIGNAL('lostFocus()'), self.onTopicNameEditLostFocus)
|
||||
QtCore.QObject.connect(self.TopicsListView,
|
||||
QtCore.SIGNAL(u'clicked(QModelIndex)'), self.onTopicsListViewItemClicked)
|
||||
|
||||
def load_form(self):
|
||||
"""
|
||||
Refresh the screen and rest fields
|
||||
"""
|
||||
self.TopicListData.resetStore()
|
||||
self.TopicsListData.resetStore()
|
||||
self.onClearButtonClick() # tidy up screen
|
||||
Topics = self.songmanager.get_Topics()
|
||||
Topics = self.songmanager.get_topics()
|
||||
for Topic in Topics:
|
||||
self.TopicListData.addRow(Topic.id,Topic.display_name)
|
||||
row_count = self.TopicListData.rowCount(None)
|
||||
self.TopicsListData.addRow(Topic.id,Topic.name)
|
||||
row_count = self.TopicsListData.rowCount(None)
|
||||
if self.currentRow > row_count:
|
||||
# in case we have delete the last row of the table
|
||||
self.currentRow = row_count
|
||||
row = self.TopicListData.createIndex(self.currentRow, 0)
|
||||
row = self.TopicsListData.createIndex(self.currentRow, 0)
|
||||
if row.isValid():
|
||||
self.TopicListView.selectionModel().setCurrentIndex(row, QtGui.QItemSelectionModel.SelectCurrent)
|
||||
self.TopicsListView.selectionModel().setCurrentIndex(row,
|
||||
QtGui.QItemSelectionModel.SelectCurrent)
|
||||
self._validate_form()
|
||||
|
||||
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.songmanager.delete_topic(self.Topic.id)
|
||||
self.load_form()
|
||||
|
||||
def onDisplayEditLostFocus(self):
|
||||
def onTopicNameEditLostFocus(self):
|
||||
self._validate_form()
|
||||
|
||||
def onAddUpdateButtonClick(self):
|
||||
@ -83,32 +83,32 @@ class TopicsForm(QDialog, Ui_TopicsDialog):
|
||||
"""
|
||||
if self.Topic == None:
|
||||
self.Topic = Topic()
|
||||
self.Topic.display_name = unicode(self.DisplayEdit.displayText())
|
||||
self.songmanager.save_Topic(self.Topic)
|
||||
self.Topic.name = unicode(self.TopicNameEdit.displayText())
|
||||
self.songmanager.save_topic(self.Topic)
|
||||
self.onClearButtonClick()
|
||||
self.load_form()
|
||||
self._validate_form()
|
||||
|
||||
def onClearButtonClick(self):
|
||||
"""
|
||||
Tidy up screen if clear button pressed
|
||||
"""
|
||||
self.DisplayEdit.setText(u'')
|
||||
self.TopicNameEdit.setText(u'')
|
||||
self.MessageLabel.setText(u'')
|
||||
self.DeleteButton.setEnabled(False)
|
||||
self.AddUpdateButton.setEnabled(True)
|
||||
self.Topic = None
|
||||
self._validate_form()
|
||||
|
||||
def onTopicListViewItemClicked(self, index):
|
||||
def onTopicsListViewItemClicked(self, index):
|
||||
"""
|
||||
An Topic has been selected display it
|
||||
If the Topic is attached to a Song prevent delete
|
||||
"""
|
||||
self.currentRow = index.row()
|
||||
id = int(self.TopicListData.getId(index))
|
||||
self.Topic = self.songmanager.get_Topic(id)
|
||||
id = int(self.TopicsListData.getId(index))
|
||||
self.Topic = self.songmanager.get_topic(id)
|
||||
|
||||
self.DisplayEdit.setText(self.Topic.display_name)
|
||||
self.TopicNameEdit.setText(self.Topic.name)
|
||||
if len(self.Topic.songs) > 0:
|
||||
self.MessageLabel.setText("Topic in use 'Delete' is disabled")
|
||||
self.DeleteButton.setEnabled(False)
|
||||
@ -118,7 +118,7 @@ class TopicsForm(QDialog, Ui_TopicsDialog):
|
||||
self._validate_form()
|
||||
|
||||
def _validate_form(self):
|
||||
if len(self.DisplayEdit.displayText()) == 0: # We need at lease a display name
|
||||
if len(self.TopicNameEdit.displayText()) == 0: # We need at lease a display name
|
||||
self.AddUpdateButton.setEnabled(False)
|
||||
else:
|
||||
self.AddUpdateButton.setEnabled(True)
|
||||
|
@ -45,7 +45,7 @@ class SongManager():
|
||||
self.config = config
|
||||
log.debug('Song Initialising')
|
||||
self.db_url = u''
|
||||
db_type = self.config.get_config(u'db type')
|
||||
db_type = self.config.get_config(u'db type', u'sqlite')
|
||||
if db_type == u'sqlite':
|
||||
self.db_url = u'sqlite:///' + self.config.get_data_path() + \
|
||||
u'/songs.sqlite'
|
||||
@ -145,3 +145,40 @@ class SongManager():
|
||||
log.error("Errow thrown %s", sys.exc_info()[1])
|
||||
print "Errow thrown ", sys.exc_info()[1]
|
||||
return False
|
||||
|
||||
def get_topics(self):
|
||||
"""
|
||||
Returns a list of all the topics
|
||||
"""
|
||||
return self.session.query(Topic).order_by(Topic.name).all()
|
||||
|
||||
def get_topic(self, id):
|
||||
"""
|
||||
Details of the Topic
|
||||
"""
|
||||
return self.session.query(Topic).get(id)
|
||||
|
||||
def save_topic(self, topic):
|
||||
"""
|
||||
Save the Topic
|
||||
"""
|
||||
try:
|
||||
self.session.add(topic)
|
||||
self.session.commit()
|
||||
return True
|
||||
except:
|
||||
return False
|
||||
|
||||
def delete_topic(self, topicid):
|
||||
"""
|
||||
Delete the topic
|
||||
"""
|
||||
topic = self.get_topic(topicid)
|
||||
try:
|
||||
self.session.delete(topic)
|
||||
self.session.commit()
|
||||
return True
|
||||
except:
|
||||
log.error("Errow thrown %s", sys.exc_info()[1])
|
||||
print "Errow thrown ", sys.exc_info()[1]
|
||||
return False
|
||||
|
Loading…
Reference in New Issue
Block a user