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
1=== modified file 'openlp/core/__init__.py'
2--- openlp/core/__init__.py 2009-04-06 18:45:45 +0000
3+++ openlp/core/__init__.py 2009-04-07 19:03:36 +0000
4@@ -29,8 +29,5 @@
5 return QtGui.QApplication.translate(context, text, None, QtGui.QApplication.UnicodeUTF8)
6
7 def fileToXML(xmlfile):
8- file=open(xmlfile)
9- xml =''.join(file.readlines()) # read the file and change list to a string
10- file.close()
11- return xml
12+ return open(xmlfile).read()
13
14
15=== modified file 'openlp/core/lib/__init__.py'
16--- openlp/core/lib/__init__.py 2009-03-28 20:12:22 +0000
17+++ openlp/core/lib/__init__.py 2009-04-07 19:45:21 +0000
18@@ -31,9 +31,8 @@
19 from toolbar import OpenLPToolbar
20 from songxmlhandler import SongXMLBuilder
21 from songxmlhandler import SongXMLParser
22-from themexmlhandler import ThemeXMLBuilder
23-from themexmlhandler import ThemeXMLParser
24+from themexmlhandler import ThemeXML
25
26 __all__ = ['PluginConfig', 'Plugin', 'SettingsTab', 'MediaManagerItem', 'Event', 'EventType'
27 'XmlRootClass', 'ServiceItem', 'Receiver', 'OpenLPToolbar', 'SongXMLBuilder',
28- 'SongXMLParser', 'EventManager', 'ThemeXMLBuilder', 'ThemeXMLParser']
29+ 'SongXMLParser', 'EventManager', 'ThemeXML']
30
31=== modified file 'openlp/core/lib/themexmlhandler.py'
32--- openlp/core/lib/themexmlhandler.py 2009-04-06 18:45:45 +0000
33+++ openlp/core/lib/themexmlhandler.py 2009-04-07 19:45:21 +0000
34@@ -24,7 +24,7 @@
35 from xml.dom.minidom import Document
36 from xml.etree.ElementTree import ElementTree, XML, dump
37
38-class ThemeXMLBuilder():
39+class ThemeXML():
40 def __init__(self):
41 # Create the minidom document
42 self.theme_xml = Document()
43@@ -154,8 +154,7 @@
44 # Print our newly created XML
45 return self.theme_xml.toxml()
46
47-class ThemeXMLParser():
48- def __init__(self, xml):
49+ def parse(self, xml):
50 theme_xml = ElementTree(element=XML(xml))
51 iter=theme_xml.getiterator()
52 master = u''
53
54=== modified file 'openlp/core/ui/thememanager.py'
55--- openlp/core/ui/thememanager.py 2009-04-06 18:45:45 +0000
56+++ openlp/core/ui/thememanager.py 2009-04-07 19:45:21 +0000
57@@ -37,8 +37,7 @@
58 from openlp.core.lib import EventType
59 from openlp.core.lib import EventManager
60 from openlp.core.lib import OpenLPToolbar
61-from openlp.core.lib import ThemeXMLBuilder
62-from openlp.core.lib import ThemeXMLParser
63+from openlp.core.lib import ThemeXML
64 from openlp.core.utils import ConfigHelper
65
66
67@@ -52,6 +51,7 @@
68 """
69 global log
70 log=logging.getLogger(u'ThemeData')
71+
72 def __init__(self):
73 QAbstractItemModel.__init__(self)
74 self.items=[]
75@@ -132,9 +132,13 @@
76 log.info(u'Get Item:%d -> %s' %(row, str(self.items)))
77 return self.items[row]
78
79+ def getList(self):
80+ filelist = [item[3] for item in self.items];
81+ return filelist
82+
83 class ThemeManager(QWidget):
84 """
85- Manages the orders of Theme. C
86+ Manages the orders of Theme.
87 """
88 global log
89 log=logging.getLogger(u'ThemeManager')
90@@ -178,6 +182,7 @@
91 self.eventManager = eventManager
92
93 def onAddTheme(self):
94+ self.amendThemeForm.loadTheme(None)
95 self.amendThemeForm.exec_()
96
97 def onEditTheme(self):
98@@ -213,7 +218,7 @@
99 self.eventManager.post_event(Event(EventType.ThemeListChanged))
100
101 def getThemes(self):
102- return self.themelist
103+ return self.Theme_data.getList()
104
105 def checkThemesExists(self, dir):
106 log.debug(u'check themes')
107@@ -232,7 +237,7 @@
108 fullpath = os.path.join(dir, file)
109 names = file.split(u'/')
110 xml_data = zip.read(file)
111- if file.endswith(u'.xml'):
112+ if os.path.splitext (file) [1].lower () in [u'.xml']:
113 if self.checkVersion1(xml_data):
114 filexml = self.migrateVersion122(filename, fullpath, xml_data)
115 outfile = open(fullpath, 'w')
116@@ -240,7 +245,7 @@
117 outfile.close()
118 self.generateImage(dir,names[0], filexml)
119 else:
120- if file.endswith(u'.bmp'):
121+ if os.path.splitext (file) [1].lower () in [u'.bmp']:
122 if fullpath is not os.path.join(dir, file):
123 outfile = open(fullpath, 'w')
124 outfile.write(zip.read(file))
125@@ -259,7 +264,7 @@
126 log.debug(u'migrateVersion122 %s %s', filename , fullpath)
127 t=Theme(xml_data)
128
129- newtheme = ThemeXMLBuilder()
130+ newtheme = ThemeXML()
131 newtheme.new_document(t.Name)
132 if t.BackgroundType == 0:
133 newtheme.add_background_solid(str(t.BackgroundParameter1.name()))
134@@ -285,7 +290,8 @@
135
136 def generateImage(self, dir, name, theme_xml):
137 log.debug(u'generateImage %s %s ', dir, theme_xml)
138- theme = ThemeXMLParser(theme_xml)
139+ theme = ThemeXML()
140+ theme.parse(theme_xml)
141 #print theme
142 size=QtCore.QSize(800,600)
143 frame=TstFrame(size)
144
145=== modified file 'openlp/plugins/custom/customplugin.py'
146--- openlp/plugins/custom/customplugin.py 2009-03-25 20:30:48 +0000
147+++ openlp/plugins/custom/customplugin.py 2009-04-07 19:03:36 +0000
148@@ -23,15 +23,17 @@
149
150 from openlp.core.resources import *
151 from openlp.core.lib import Plugin, Event
152+from openlp.core.lib import EventType
153 from forms import EditCustomForm
154 from openlp.plugins.custom.lib import CustomManager, CustomTab, CustomMediaItem, CustomServiceItem
155
156+
157 class CustomPlugin(Plugin):
158
159 global log
160 log=logging.getLogger(u'CustomPlugin')
161 log.info(u'Custom Plugin loaded')
162-
163+
164 def __init__(self, plugin_helpers):
165 # Call the parent constructor
166 Plugin.__init__(self, u'Custom', u'1.9.0', plugin_helpers)
167@@ -49,9 +51,12 @@
168 # Create the CustomManagerItem object
169 self.media_item = CustomMediaItem(self, self.icon, u'Custom Slides')
170 return self.media_item
171-
172+
173 def handle_event(self, event):
174 """
175 Handle the event contained in the event object.
176 """
177- log.debug(u'Handle event called with event %s' %event.get_type())
178+ log.debug(u'Handle event called with event %s' %event.event_type)
179+ if event.event_type == EventType.ThemeListChanged:
180+ log.debug(u'New Theme request received')
181+ self.edit_custom_form.loadThemes(self.theme_manager.getThemes())
182
183=== modified file 'openlp/plugins/custom/forms/editcustomform.py'
184--- openlp/plugins/custom/forms/editcustomform.py 2009-03-25 20:30:48 +0000
185+++ openlp/plugins/custom/forms/editcustomform.py 2009-04-07 19:03:36 +0000
186@@ -32,7 +32,7 @@
187 Constructor
188 """
189 QtGui.QDialog.__init__(self, parent)
190- #self.parent = parent
191+ #self.parent = parent
192 self.setupUi(self)
193 # Connecting signals and slots
194 QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("rejected()"), self.rejected)
195@@ -43,18 +43,18 @@
196 QtCore.QObject.connect(self.DeleteButton, QtCore.SIGNAL("pressed()"), self.onDeleteButtonPressed)
197 QtCore.QObject.connect(self.ClearButton, QtCore.SIGNAL("pressed()"), self.onClearButtonPressed)
198 QtCore.QObject.connect(self.UpButton, QtCore.SIGNAL("pressed()"), self.onUpButtonPressed)
199- QtCore.QObject.connect(self.DownButton, QtCore.SIGNAL("pressed()"), self.onDownButtonPressed)
200- QtCore.QObject.connect(self.TitleEdit, QtCore.SIGNAL("lostFocus()"), self.validate)
201+ QtCore.QObject.connect(self.DownButton, QtCore.SIGNAL("pressed()"), self.onDownButtonPressed)
202+ QtCore.QObject.connect(self.TitleEdit, QtCore.SIGNAL("lostFocus()"), self.validate)
203
204- QtCore.QObject.connect(self.VerseListView,
205+ QtCore.QObject.connect(self.VerseListView,
206 QtCore.SIGNAL("itemDoubleClicked(QListWidgetItem*)"), self.onVerseListViewSelected)
207- QtCore.QObject.connect(self.VerseListView,
208+ QtCore.QObject.connect(self.VerseListView,
209 QtCore.SIGNAL("itemClicked(QListWidgetItem*)"), self.onVerseListViewPressed)
210 # Create other objects and forms
211 self.custommanager = custommanager
212 self.initialise()
213- self.VerseListView.setAlternatingRowColors(True)
214-
215+ self.VerseListView.setAlternatingRowColors(True)
216+
217 def initialise(self):
218 self.valid = True
219 self.DeleteButton.setEnabled(False)
220@@ -64,10 +64,15 @@
221 self.CreditEdit.setText('')
222 self.VerseTextEdit.clear()
223 self.VerseListView.clear()
224- #make sure we have a new item
225+ #make sure we have a new item
226 self.customSlide = CustomSlide()
227 self.ThemecomboBox.addItem(u'')
228- #self.theme_manager.getThemes()
229+
230+ def loadThemes(self, themelist):
231+ self.ThemecomboBox.clear()
232+ self.ThemecomboBox.addItem(u'')
233+ for themename in themelist:
234+ self.ThemecomboBox.addItem(themename)
235
236 def loadCustom(self, id):
237 self.customSlide = CustomSlide()
238@@ -76,12 +81,19 @@
239 self.customSlide = self.custommanager.get_custom(id)
240 self.TitleEdit.setText(self.customSlide.title)
241 self.CreditEdit.setText(self.customSlide.title)
242-
243+
244 songXML=SongXMLParser(self.customSlide.text)
245 verseList = songXML.get_verses()
246 for verse in verseList:
247 self.VerseListView.addItem(verse[1])
248+ theme = str(self.customSlide.theme_name)
249+ id = self.ThemecomboBox.findText(theme, QtCore.Qt.MatchExactly)
250+ if id == -1:
251+ id = 0 # Not Found
252+ self.ThemecomboBox.setCurrentIndex(id)
253 self.validate()
254+ else:
255+ self.ThemecomboBox.setCurrentIndex(0)
256
257 def accept(self):
258 self.validate()
259@@ -96,6 +108,7 @@
260 self.customSlide.title = unicode(self.TitleEdit.displayText())
261 self.customSlide.text = unicode(sxml.extract_xml())
262 self.customSlide.credits = unicode(self.CreditEdit.displayText())
263+ self.customSlide.theme_name = unicode(self.ThemecomboBox.currentText())
264 self.custommanager.save_slide(self.customSlide)
265 self.close()
266
267@@ -114,7 +127,7 @@
268 if selectedRow != self.VerseListView.count() - 1: # zero base arrays
269 qw = self.VerseListView.takeItem(selectedRow)
270 self.VerseListView.insertItem(selectedRow + 1, qw)
271- self.VerseListView.setCurrentRow(selectedRow + 1)
272+ self.VerseListView.setCurrentRow(selectedRow + 1)
273
274 def onClearButtonPressed(self):
275 self.VerseTextEdit.clear()
276@@ -122,7 +135,7 @@
277 def onVerseListViewPressed(self, item):
278 self.DeleteButton.setEnabled(True)
279 self.EditButton.setEnabled(True)
280-
281+
282 def onVerseListViewSelected(self, item):
283 self.VerseTextEdit.setPlainText(item.text())
284 self.DeleteButton.setEnabled(False)