Fix Problems from last merge review

Get Custom Plugin theme combo working following event post from ThemeManager
This commit is contained in:
Tim Bentley 2009-04-07 20:03:36 +01:00
parent 0e7dfb9fc4
commit 0dfe60ef9f
4 changed files with 44 additions and 23 deletions

View File

@ -29,8 +29,5 @@ def translate(context, text):
return QtGui.QApplication.translate(context, text, None, QtGui.QApplication.UnicodeUTF8)
def fileToXML(xmlfile):
file=open(xmlfile)
xml =''.join(file.readlines()) # read the file and change list to a string
file.close()
return xml
return open(xmlfile).read()

View File

@ -52,6 +52,7 @@ class ThemeData(QAbstractItemModel):
"""
global log
log=logging.getLogger(u'ThemeData')
def __init__(self):
QAbstractItemModel.__init__(self)
self.items=[]
@ -132,9 +133,13 @@ class ThemeData(QAbstractItemModel):
log.info(u'Get Item:%d -> %s' %(row, str(self.items)))
return self.items[row]
def getList(self):
filelist = [item[3] for item in self.items];
return filelist
class ThemeManager(QWidget):
"""
Manages the orders of Theme. C
Manages the orders of Theme.
"""
global log
log=logging.getLogger(u'ThemeManager')
@ -178,6 +183,7 @@ class ThemeManager(QWidget):
self.eventManager = eventManager
def onAddTheme(self):
self.amendThemeForm.loadTheme(None)
self.amendThemeForm.exec_()
def onEditTheme(self):
@ -213,7 +219,7 @@ class ThemeManager(QWidget):
self.eventManager.post_event(Event(EventType.ThemeListChanged))
def getThemes(self):
return self.themelist
return self.Theme_data.getList()
def checkThemesExists(self, dir):
log.debug(u'check themes')
@ -232,7 +238,7 @@ class ThemeManager(QWidget):
fullpath = os.path.join(dir, file)
names = file.split(u'/')
xml_data = zip.read(file)
if file.endswith(u'.xml'):
if os.path.splitext (file) [1].lower () in [u'.xml']:
if self.checkVersion1(xml_data):
filexml = self.migrateVersion122(filename, fullpath, xml_data)
outfile = open(fullpath, 'w')
@ -240,7 +246,7 @@ class ThemeManager(QWidget):
outfile.close()
self.generateImage(dir,names[0], filexml)
else:
if file.endswith(u'.bmp'):
if os.path.splitext (file) [1].lower () in [u'.bmp']:
if fullpath is not os.path.join(dir, file):
outfile = open(fullpath, 'w')
outfile.write(zip.read(file))

View File

@ -23,9 +23,11 @@ from PyQt4 import QtCore, QtGui
from openlp.core.resources import *
from openlp.core.lib import Plugin, Event
from openlp.core.lib import EventType
from forms import EditCustomForm
from openlp.plugins.custom.lib import CustomManager, CustomTab, CustomMediaItem, CustomServiceItem
class CustomPlugin(Plugin):
global log
@ -54,4 +56,7 @@ class CustomPlugin(Plugin):
"""
Handle the event contained in the event object.
"""
log.debug(u'Handle event called with event %s' %event.get_type())
log.debug(u'Handle event called with event %s' %event.event_type)
if event.event_type == EventType.ThemeListChanged:
log.debug(u'New Theme request received')
self.edit_custom_form.loadThemes(self.theme_manager.getThemes())

View File

@ -67,7 +67,12 @@ class EditCustomForm(QtGui.QDialog, Ui_customEditDialog):
#make sure we have a new item
self.customSlide = CustomSlide()
self.ThemecomboBox.addItem(u'')
#self.theme_manager.getThemes()
def loadThemes(self, themelist):
self.ThemecomboBox.clear()
self.ThemecomboBox.addItem(u'')
for themename in themelist:
self.ThemecomboBox.addItem(themename)
def loadCustom(self, id):
self.customSlide = CustomSlide()
@ -81,7 +86,14 @@ class EditCustomForm(QtGui.QDialog, Ui_customEditDialog):
verseList = songXML.get_verses()
for verse in verseList:
self.VerseListView.addItem(verse[1])
theme = str(self.customSlide.theme_name)
id = self.ThemecomboBox.findText(theme, QtCore.Qt.MatchExactly)
if id == -1:
id = 0 # Not Found
self.ThemecomboBox.setCurrentIndex(id)
self.validate()
else:
self.ThemecomboBox.setCurrentIndex(0)
def accept(self):
self.validate()
@ -96,6 +108,7 @@ class EditCustomForm(QtGui.QDialog, Ui_customEditDialog):
self.customSlide.title = unicode(self.TitleEdit.displayText())
self.customSlide.text = unicode(sxml.extract_xml())
self.customSlide.credits = unicode(self.CreditEdit.displayText())
self.customSlide.theme_name = unicode(self.ThemecomboBox.currentText())
self.custommanager.save_slide(self.customSlide)
self.close()