Merge lp:~trb143/openlp/ThemeManager2 into lp:openlp

Proposed by Tim Bentley
Status: Merged
Merged at revision: not available
Proposed branch: lp:~trb143/openlp/ThemeManager2
Merge into: lp:openlp
Diff against target: None lines
To merge this branch: bzr merge lp:~trb143/openlp/ThemeManager2
Reviewer Review Type Date Requested Status
Raoul Snyman Approve
Michael Gorven (community) Approve
Review via email: mp+5302@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Tim Bentley (trb143) wrote :

Fix issues from last merge
Add Theme handling to Custom plugin

Revision history for this message
Michael Gorven (mgorven) wrote :

+ log.debug(u'Handle event called with event %s' %event.event_type)

Pass event.event_type as a parameter.

+ if os.path.splitext (file) [1].lower () in [u'.xml']:

I'd prefer:
    if os.path.splitext(file)[1].lower() in (u'xml',):

 review approve

review: Approve
Revision history for this message
Raoul Snyman (raoul-snyman) wrote :

If you wanted to, you could make the __init__ function of ThemeXML take named parameters so that it's a little cooler, like so:

  theme = ThemeXML(parse=theme_xml)

It would cut 2 lines down to 1. Just a nice-to-have though.

review: Approve
lp:~trb143/openlp/ThemeManager2 updated
430. By Tim Bentley

Fixes from last merge

<email address hidden>

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'openlp/core/__init__.py'
--- openlp/core/__init__.py 2009-04-06 18:45:45 +0000
+++ openlp/core/__init__.py 2009-04-07 19:03:36 +0000
@@ -29,8 +29,5 @@
29 return QtGui.QApplication.translate(context, text, None, QtGui.QApplication.UnicodeUTF8)29 return QtGui.QApplication.translate(context, text, None, QtGui.QApplication.UnicodeUTF8)
3030
31def fileToXML(xmlfile):31def fileToXML(xmlfile):
32 file=open(xmlfile)32 return open(xmlfile).read()
33 xml =''.join(file.readlines()) # read the file and change list to a string
34 file.close()
35 return xml
3633
3734
=== modified file 'openlp/core/lib/__init__.py'
--- openlp/core/lib/__init__.py 2009-03-28 20:12:22 +0000
+++ openlp/core/lib/__init__.py 2009-04-07 19:45:21 +0000
@@ -31,9 +31,8 @@
31from toolbar import OpenLPToolbar31from toolbar import OpenLPToolbar
32from songxmlhandler import SongXMLBuilder32from songxmlhandler import SongXMLBuilder
33from songxmlhandler import SongXMLParser33from songxmlhandler import SongXMLParser
34from themexmlhandler import ThemeXMLBuilder34from themexmlhandler import ThemeXML
35from themexmlhandler import ThemeXMLParser
3635
37__all__ = ['PluginConfig', 'Plugin', 'SettingsTab', 'MediaManagerItem', 'Event', 'EventType'36__all__ = ['PluginConfig', 'Plugin', 'SettingsTab', 'MediaManagerItem', 'Event', 'EventType'
38 'XmlRootClass', 'ServiceItem', 'Receiver', 'OpenLPToolbar', 'SongXMLBuilder',37 'XmlRootClass', 'ServiceItem', 'Receiver', 'OpenLPToolbar', 'SongXMLBuilder',
39 'SongXMLParser', 'EventManager', 'ThemeXMLBuilder', 'ThemeXMLParser']38 'SongXMLParser', 'EventManager', 'ThemeXML']
4039
=== modified file 'openlp/core/lib/themexmlhandler.py'
--- openlp/core/lib/themexmlhandler.py 2009-04-06 18:45:45 +0000
+++ openlp/core/lib/themexmlhandler.py 2009-04-07 19:45:21 +0000
@@ -24,7 +24,7 @@
24from xml.dom.minidom import Document24from xml.dom.minidom import Document
25from xml.etree.ElementTree import ElementTree, XML, dump25from xml.etree.ElementTree import ElementTree, XML, dump
2626
27class ThemeXMLBuilder():27class ThemeXML():
28 def __init__(self):28 def __init__(self):
29 # Create the minidom document29 # Create the minidom document
30 self.theme_xml = Document()30 self.theme_xml = Document()
@@ -154,8 +154,7 @@
154 # Print our newly created XML154 # Print our newly created XML
155 return self.theme_xml.toxml()155 return self.theme_xml.toxml()
156156
157class ThemeXMLParser():157 def parse(self, xml):
158 def __init__(self, xml):
159 theme_xml = ElementTree(element=XML(xml))158 theme_xml = ElementTree(element=XML(xml))
160 iter=theme_xml.getiterator()159 iter=theme_xml.getiterator()
161 master = u''160 master = u''
162161
=== modified file 'openlp/core/ui/thememanager.py'
--- openlp/core/ui/thememanager.py 2009-04-06 18:45:45 +0000
+++ openlp/core/ui/thememanager.py 2009-04-07 19:45:21 +0000
@@ -37,8 +37,7 @@
37from openlp.core.lib import EventType37from openlp.core.lib import EventType
38from openlp.core.lib import EventManager38from openlp.core.lib import EventManager
39from openlp.core.lib import OpenLPToolbar39from openlp.core.lib import OpenLPToolbar
40from openlp.core.lib import ThemeXMLBuilder40from openlp.core.lib import ThemeXML
41from openlp.core.lib import ThemeXMLParser
42from openlp.core.utils import ConfigHelper41from openlp.core.utils import ConfigHelper
4342
4443
@@ -52,6 +51,7 @@
52 """51 """
53 global log52 global log
54 log=logging.getLogger(u'ThemeData')53 log=logging.getLogger(u'ThemeData')
54
55 def __init__(self):55 def __init__(self):
56 QAbstractItemModel.__init__(self)56 QAbstractItemModel.__init__(self)
57 self.items=[]57 self.items=[]
@@ -132,9 +132,13 @@
132 log.info(u'Get Item:%d -> %s' %(row, str(self.items)))132 log.info(u'Get Item:%d -> %s' %(row, str(self.items)))
133 return self.items[row]133 return self.items[row]
134134
135 def getList(self):
136 filelist = [item[3] for item in self.items];
137 return filelist
138
135class ThemeManager(QWidget):139class ThemeManager(QWidget):
136 """140 """
137 Manages the orders of Theme. C141 Manages the orders of Theme.
138 """142 """
139 global log143 global log
140 log=logging.getLogger(u'ThemeManager')144 log=logging.getLogger(u'ThemeManager')
@@ -178,6 +182,7 @@
178 self.eventManager = eventManager182 self.eventManager = eventManager
179183
180 def onAddTheme(self):184 def onAddTheme(self):
185 self.amendThemeForm.loadTheme(None)
181 self.amendThemeForm.exec_()186 self.amendThemeForm.exec_()
182187
183 def onEditTheme(self):188 def onEditTheme(self):
@@ -213,7 +218,7 @@
213 self.eventManager.post_event(Event(EventType.ThemeListChanged))218 self.eventManager.post_event(Event(EventType.ThemeListChanged))
214219
215 def getThemes(self):220 def getThemes(self):
216 return self.themelist221 return self.Theme_data.getList()
217222
218 def checkThemesExists(self, dir):223 def checkThemesExists(self, dir):
219 log.debug(u'check themes')224 log.debug(u'check themes')
@@ -232,7 +237,7 @@
232 fullpath = os.path.join(dir, file)237 fullpath = os.path.join(dir, file)
233 names = file.split(u'/')238 names = file.split(u'/')
234 xml_data = zip.read(file)239 xml_data = zip.read(file)
235 if file.endswith(u'.xml'):240 if os.path.splitext (file) [1].lower () in [u'.xml']:
236 if self.checkVersion1(xml_data):241 if self.checkVersion1(xml_data):
237 filexml = self.migrateVersion122(filename, fullpath, xml_data)242 filexml = self.migrateVersion122(filename, fullpath, xml_data)
238 outfile = open(fullpath, 'w')243 outfile = open(fullpath, 'w')
@@ -240,7 +245,7 @@
240 outfile.close()245 outfile.close()
241 self.generateImage(dir,names[0], filexml)246 self.generateImage(dir,names[0], filexml)
242 else:247 else:
243 if file.endswith(u'.bmp'):248 if os.path.splitext (file) [1].lower () in [u'.bmp']:
244 if fullpath is not os.path.join(dir, file):249 if fullpath is not os.path.join(dir, file):
245 outfile = open(fullpath, 'w')250 outfile = open(fullpath, 'w')
246 outfile.write(zip.read(file))251 outfile.write(zip.read(file))
@@ -259,7 +264,7 @@
259 log.debug(u'migrateVersion122 %s %s', filename , fullpath)264 log.debug(u'migrateVersion122 %s %s', filename , fullpath)
260 t=Theme(xml_data)265 t=Theme(xml_data)
261266
262 newtheme = ThemeXMLBuilder()267 newtheme = ThemeXML()
263 newtheme.new_document(t.Name)268 newtheme.new_document(t.Name)
264 if t.BackgroundType == 0:269 if t.BackgroundType == 0:
265 newtheme.add_background_solid(str(t.BackgroundParameter1.name()))270 newtheme.add_background_solid(str(t.BackgroundParameter1.name()))
@@ -285,7 +290,8 @@
285290
286 def generateImage(self, dir, name, theme_xml):291 def generateImage(self, dir, name, theme_xml):
287 log.debug(u'generateImage %s %s ', dir, theme_xml)292 log.debug(u'generateImage %s %s ', dir, theme_xml)
288 theme = ThemeXMLParser(theme_xml)293 theme = ThemeXML()
294 theme.parse(theme_xml)
289 #print theme295 #print theme
290 size=QtCore.QSize(800,600)296 size=QtCore.QSize(800,600)
291 frame=TstFrame(size)297 frame=TstFrame(size)
292298
=== modified file 'openlp/plugins/custom/customplugin.py'
--- openlp/plugins/custom/customplugin.py 2009-03-25 20:30:48 +0000
+++ openlp/plugins/custom/customplugin.py 2009-04-07 19:03:36 +0000
@@ -23,15 +23,17 @@
2323
24from openlp.core.resources import *24from openlp.core.resources import *
25from openlp.core.lib import Plugin, Event25from openlp.core.lib import Plugin, Event
26from openlp.core.lib import EventType
26from forms import EditCustomForm27from forms import EditCustomForm
27from openlp.plugins.custom.lib import CustomManager, CustomTab, CustomMediaItem, CustomServiceItem28from openlp.plugins.custom.lib import CustomManager, CustomTab, CustomMediaItem, CustomServiceItem
2829
30
29class CustomPlugin(Plugin):31class CustomPlugin(Plugin):
3032
31 global log33 global log
32 log=logging.getLogger(u'CustomPlugin')34 log=logging.getLogger(u'CustomPlugin')
33 log.info(u'Custom Plugin loaded')35 log.info(u'Custom Plugin loaded')
34 36
35 def __init__(self, plugin_helpers):37 def __init__(self, plugin_helpers):
36 # Call the parent constructor38 # Call the parent constructor
37 Plugin.__init__(self, u'Custom', u'1.9.0', plugin_helpers)39 Plugin.__init__(self, u'Custom', u'1.9.0', plugin_helpers)
@@ -49,9 +51,12 @@
49 # Create the CustomManagerItem object51 # Create the CustomManagerItem object
50 self.media_item = CustomMediaItem(self, self.icon, u'Custom Slides')52 self.media_item = CustomMediaItem(self, self.icon, u'Custom Slides')
51 return self.media_item53 return self.media_item
52 54
53 def handle_event(self, event):55 def handle_event(self, event):
54 """56 """
55 Handle the event contained in the event object.57 Handle the event contained in the event object.
56 """58 """
57 log.debug(u'Handle event called with event %s' %event.get_type())59 log.debug(u'Handle event called with event %s' %event.event_type)
60 if event.event_type == EventType.ThemeListChanged:
61 log.debug(u'New Theme request received')
62 self.edit_custom_form.loadThemes(self.theme_manager.getThemes())
5863
=== modified file 'openlp/plugins/custom/forms/editcustomform.py'
--- openlp/plugins/custom/forms/editcustomform.py 2009-03-25 20:30:48 +0000
+++ openlp/plugins/custom/forms/editcustomform.py 2009-04-07 19:03:36 +0000
@@ -32,7 +32,7 @@
32 Constructor32 Constructor
33 """33 """
34 QtGui.QDialog.__init__(self, parent)34 QtGui.QDialog.__init__(self, parent)
35 #self.parent = parent 35 #self.parent = parent
36 self.setupUi(self)36 self.setupUi(self)
37 # Connecting signals and slots37 # Connecting signals and slots
38 QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("rejected()"), self.rejected)38 QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("rejected()"), self.rejected)
@@ -43,18 +43,18 @@
43 QtCore.QObject.connect(self.DeleteButton, QtCore.SIGNAL("pressed()"), self.onDeleteButtonPressed)43 QtCore.QObject.connect(self.DeleteButton, QtCore.SIGNAL("pressed()"), self.onDeleteButtonPressed)
44 QtCore.QObject.connect(self.ClearButton, QtCore.SIGNAL("pressed()"), self.onClearButtonPressed)44 QtCore.QObject.connect(self.ClearButton, QtCore.SIGNAL("pressed()"), self.onClearButtonPressed)
45 QtCore.QObject.connect(self.UpButton, QtCore.SIGNAL("pressed()"), self.onUpButtonPressed)45 QtCore.QObject.connect(self.UpButton, QtCore.SIGNAL("pressed()"), self.onUpButtonPressed)
46 QtCore.QObject.connect(self.DownButton, QtCore.SIGNAL("pressed()"), self.onDownButtonPressed) 46 QtCore.QObject.connect(self.DownButton, QtCore.SIGNAL("pressed()"), self.onDownButtonPressed)
47 QtCore.QObject.connect(self.TitleEdit, QtCore.SIGNAL("lostFocus()"), self.validate) 47 QtCore.QObject.connect(self.TitleEdit, QtCore.SIGNAL("lostFocus()"), self.validate)
4848
49 QtCore.QObject.connect(self.VerseListView, 49 QtCore.QObject.connect(self.VerseListView,
50 QtCore.SIGNAL("itemDoubleClicked(QListWidgetItem*)"), self.onVerseListViewSelected)50 QtCore.SIGNAL("itemDoubleClicked(QListWidgetItem*)"), self.onVerseListViewSelected)
51 QtCore.QObject.connect(self.VerseListView, 51 QtCore.QObject.connect(self.VerseListView,
52 QtCore.SIGNAL("itemClicked(QListWidgetItem*)"), self.onVerseListViewPressed)52 QtCore.SIGNAL("itemClicked(QListWidgetItem*)"), self.onVerseListViewPressed)
53 # Create other objects and forms53 # Create other objects and forms
54 self.custommanager = custommanager54 self.custommanager = custommanager
55 self.initialise()55 self.initialise()
56 self.VerseListView.setAlternatingRowColors(True) 56 self.VerseListView.setAlternatingRowColors(True)
57 57
58 def initialise(self):58 def initialise(self):
59 self.valid = True59 self.valid = True
60 self.DeleteButton.setEnabled(False)60 self.DeleteButton.setEnabled(False)
@@ -64,10 +64,15 @@
64 self.CreditEdit.setText('')64 self.CreditEdit.setText('')
65 self.VerseTextEdit.clear()65 self.VerseTextEdit.clear()
66 self.VerseListView.clear()66 self.VerseListView.clear()
67 #make sure we have a new item 67 #make sure we have a new item
68 self.customSlide = CustomSlide()68 self.customSlide = CustomSlide()
69 self.ThemecomboBox.addItem(u'')69 self.ThemecomboBox.addItem(u'')
70 #self.theme_manager.getThemes()70
71 def loadThemes(self, themelist):
72 self.ThemecomboBox.clear()
73 self.ThemecomboBox.addItem(u'')
74 for themename in themelist:
75 self.ThemecomboBox.addItem(themename)
7176
72 def loadCustom(self, id):77 def loadCustom(self, id):
73 self.customSlide = CustomSlide()78 self.customSlide = CustomSlide()
@@ -76,12 +81,19 @@
76 self.customSlide = self.custommanager.get_custom(id)81 self.customSlide = self.custommanager.get_custom(id)
77 self.TitleEdit.setText(self.customSlide.title)82 self.TitleEdit.setText(self.customSlide.title)
78 self.CreditEdit.setText(self.customSlide.title)83 self.CreditEdit.setText(self.customSlide.title)
79 84
80 songXML=SongXMLParser(self.customSlide.text)85 songXML=SongXMLParser(self.customSlide.text)
81 verseList = songXML.get_verses()86 verseList = songXML.get_verses()
82 for verse in verseList:87 for verse in verseList:
83 self.VerseListView.addItem(verse[1])88 self.VerseListView.addItem(verse[1])
89 theme = str(self.customSlide.theme_name)
90 id = self.ThemecomboBox.findText(theme, QtCore.Qt.MatchExactly)
91 if id == -1:
92 id = 0 # Not Found
93 self.ThemecomboBox.setCurrentIndex(id)
84 self.validate()94 self.validate()
95 else:
96 self.ThemecomboBox.setCurrentIndex(0)
8597
86 def accept(self):98 def accept(self):
87 self.validate()99 self.validate()
@@ -96,6 +108,7 @@
96 self.customSlide.title = unicode(self.TitleEdit.displayText())108 self.customSlide.title = unicode(self.TitleEdit.displayText())
97 self.customSlide.text = unicode(sxml.extract_xml())109 self.customSlide.text = unicode(sxml.extract_xml())
98 self.customSlide.credits = unicode(self.CreditEdit.displayText())110 self.customSlide.credits = unicode(self.CreditEdit.displayText())
111 self.customSlide.theme_name = unicode(self.ThemecomboBox.currentText())
99 self.custommanager.save_slide(self.customSlide)112 self.custommanager.save_slide(self.customSlide)
100 self.close()113 self.close()
101114
@@ -114,7 +127,7 @@
114 if selectedRow != self.VerseListView.count() - 1: # zero base arrays127 if selectedRow != self.VerseListView.count() - 1: # zero base arrays
115 qw = self.VerseListView.takeItem(selectedRow)128 qw = self.VerseListView.takeItem(selectedRow)
116 self.VerseListView.insertItem(selectedRow + 1, qw)129 self.VerseListView.insertItem(selectedRow + 1, qw)
117 self.VerseListView.setCurrentRow(selectedRow + 1) 130 self.VerseListView.setCurrentRow(selectedRow + 1)
118131
119 def onClearButtonPressed(self):132 def onClearButtonPressed(self):
120 self.VerseTextEdit.clear()133 self.VerseTextEdit.clear()
@@ -122,7 +135,7 @@
122 def onVerseListViewPressed(self, item):135 def onVerseListViewPressed(self, item):
123 self.DeleteButton.setEnabled(True)136 self.DeleteButton.setEnabled(True)
124 self.EditButton.setEnabled(True)137 self.EditButton.setEnabled(True)
125 138
126 def onVerseListViewSelected(self, item):139 def onVerseListViewSelected(self, item):
127 self.VerseTextEdit.setPlainText(item.text())140 self.VerseTextEdit.setPlainText(item.text())
128 self.DeleteButton.setEnabled(False)141 self.DeleteButton.setEnabled(False)