Merge lp:~phill-ridout/openlp/overwrite into lp:openlp

Proposed by Phill
Status: Merged
Merged at revision: 1900
Proposed branch: lp:~phill-ridout/openlp/overwrite
Merge into: lp:openlp
Diff against target: 692 lines (+204/-182)
1 file modified
openlp/core/ui/thememanager.py (+204/-182)
To merge this branch: bzr merge lp:~phill-ridout/openlp/overwrite
Reviewer Review Type Date Requested Status
Tim Bentley Approve
Jonathan Corwin (community) Approve
Raoul Snyman Pending
Review via email: mp+96901@code.launchpad.net

This proposal supersedes a proposal from 2012-03-10.

Description of the change

Tim, Line 446 returns true!

Could it be 8th time lucky? Sorry!

To post a comment you must log in.
Revision history for this message
Raoul Snyman (raoul-snyman) wrote : Posted in a previous version of this proposal

 if ret == QtGui.QMessageBox.Yes:
     return True
 elif ret == QtGui.QMessageBox.No:
     return False

Can be replaced with:

 return ret == QtGui.QMessageBox.Yes

What changed between lines 29 and 30? Please make sure you're using UNIX/Linux line endings.

There's actually no need for brackets around the returned params on line 39.

Please use words_separated_by_underscores, as per PEP8. Wordsthatarechainedtogetherarehardtoreadandunderstand.

You also don't need brackets around all the things you are returning.

review: Needs Fixing
Revision history for this message
Tim Bentley (trb143) wrote : Posted in a previous version of this proposal

unzipVersion122 returns abort_import always a false.

It would be better to not change that API.
Default abort_import to false and only set it to true if necessary.

review: Needs Fixing
Revision history for this message
Jonathan Corwin (j-corwin) wrote : Posted in a previous version of this proposal

real_theme_name rather than realtheme_name
old_theme_name rather than oldtheme_name

161: Remove the exclamation!, it's not that exciting that it already exists ;-)
164: Remove the leading "The", so it starts: Theme %s ...
287: You've got two spaces after each comma instead of one.

review: Needs Fixing
Revision history for this message
Jonathan Corwin (j-corwin) wrote : Posted in a previous version of this proposal

Gave it permission to overwrite a theme and got:

Traceback (most recent call last):
  File "C:\Users\Jonathan\Documents\projects\openlp\overwrite\openlp\core\ui\thememanager.py", line 431, in onImportTheme
    self.unzipTheme(file, self.path)
  File "C:\Users\Jonathan\Documents\projects\openlp\overwrite\openlp\core\ui\thememanager.py", line 599, in unzipTheme
    self.generateAndSaveImage(dir, theme_name, theme)
  File "C:\Users\Jonathan\Documents\projects\openlp\overwrite\openlp\core\ui\thememanager.py", line 708, in generateAndSaveImage
    frame = self.generateImage(theme)
  File "C:\Users\Jonathan\Documents\projects\openlp\overwrite\openlp\core\ui\thememanager.py", line 740, in generateImage
    return self.mainWindow.renderer.generate_preview(
AttributeError: 'ThemeManager' object has no attribute 'mainWindow'

review: Needs Fixing
Revision history for this message
Jonathan Corwin (j-corwin) wrote : Posted in a previous version of this proposal

Sorry found another:

Traceback (most recent call last):
  File "C:\Users\Jonathan\Documents\projects\openlp\overwrite\openlp\core\ui\themeform.py", line 253, in onCustom1ButtonClicked
    width = self.thememanager.mainwindow.renderer.width
AttributeError: 'ThemeManager' object has no attribute 'mainwindow'

review: Needs Fixing
Revision history for this message
Jonathan Corwin (j-corwin) :
review: Approve
Revision history for this message
Tim Bentley (trb143) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openlp/core/ui/thememanager.py'
2--- openlp/core/ui/thememanager.py 2012-03-05 22:22:36 +0000
3+++ openlp/core/ui/thememanager.py 2012-03-10 22:29:20 +0000
4@@ -140,13 +140,13 @@
5 QtCore.QObject.connect(Receiver.get_receiver(),
6 QtCore.SIGNAL(u'config_updated'), self.configUpdated)
7 # Variables
8- self.themelist = []
9+ self.theme_list = []
10 self.path = AppLocation.get_section_data_path(self.settingsSection)
11 check_directory_exists(self.path)
12- self.thumbPath = os.path.join(self.path, u'thumbnails')
13- check_directory_exists(self.thumbPath)
14+ self.thumb_path = os.path.join(self.path, u'thumbnails')
15+ check_directory_exists(self.thumb_path)
16 self.themeForm.path = self.path
17- self.oldBackgroundImage = None
18+ self.old_background_image = None
19 self.bad_v1_name_chars = re.compile(r'[%+\[\]]')
20 # Last little bits of setting up
21 self.configUpdated()
22@@ -178,10 +178,10 @@
23 """
24 if item is None:
25 return
26- realThemeName = unicode(item.data(QtCore.Qt.UserRole).toString())
27- themeName = unicode(item.text())
28+ real_theme_name = unicode(item.data(QtCore.Qt.UserRole).toString())
29+ theme_name = unicode(item.text())
30 # If default theme restrict actions
31- if realThemeName == themeName:
32+ if real_theme_name == theme_name:
33 self.deleteToolbarAction.setVisible(True)
34 else:
35 self.deleteToolbarAction.setVisible(False)
36@@ -194,35 +194,35 @@
37 item = self.themeListWidget.itemAt(point)
38 if item is None:
39 return
40- realThemeName = unicode(item.data(QtCore.Qt.UserRole).toString())
41- themeName = unicode(item.text())
42+ real_theme_name = unicode(item.data(QtCore.Qt.UserRole).toString())
43+ theme_name = unicode(item.text())
44 self.deleteAction.setVisible(False)
45 self.renameAction.setVisible(False)
46 self.globalAction.setVisible(False)
47 # If default theme restrict actions
48- if realThemeName == themeName:
49+ if real_theme_name == theme_name:
50 self.deleteAction.setVisible(True)
51 self.renameAction.setVisible(True)
52 self.globalAction.setVisible(True)
53 self.menu.exec_(self.themeListWidget.mapToGlobal(point))
54
55- def changeGlobalFromTab(self, themeName):
56+ def changeGlobalFromTab(self, theme_name):
57 """
58 Change the global theme when it is changed through the Themes settings
59 tab
60 """
61- log.debug(u'changeGlobalFromTab %s', themeName)
62+ log.debug(u'changeGlobalFromTab %s', theme_name)
63 for count in range (0, self.themeListWidget.count()):
64 # reset the old name
65 item = self.themeListWidget.item(count)
66- oldName = item.text()
67- newName = unicode(item.data(QtCore.Qt.UserRole).toString())
68- if oldName != newName:
69- self.themeListWidget.item(count).setText(newName)
70+ old_name = item.text()
71+ new_name = unicode(item.data(QtCore.Qt.UserRole).toString())
72+ if old_name != new_name:
73+ self.themeListWidget.item(count).setText(new_name)
74 # Set the new name
75- if themeName == newName:
76+ if theme_name == new_name:
77 name = unicode(translate('OpenLP.ThemeManager',
78- '%s (default)')) % newName
79+ '%s (default)')) % new_name
80 self.themeListWidget.item(count).setText(name)
81
82 def changeGlobalFromScreen(self, index=-1):
83@@ -234,9 +234,9 @@
84 selected_row = self.themeListWidget.currentRow()
85 for count in range (0, self.themeListWidget.count()):
86 item = self.themeListWidget.item(count)
87- oldName = item.text()
88+ old_name = item.text()
89 # reset the old name
90- if oldName != unicode(item.data(QtCore.Qt.UserRole).toString()):
91+ if old_name != unicode(item.data(QtCore.Qt.UserRole).toString()):
92 self.themeListWidget.item(count).setText(
93 unicode(item.data(QtCore.Qt.UserRole).toString()))
94 # Set the new name
95@@ -272,19 +272,19 @@
96 unicode(translate('OpenLP.ThemeManager', 'Rename %s theme?')),
97 False, False):
98 item = self.themeListWidget.currentItem()
99- oldThemeName = unicode(item.data(QtCore.Qt.UserRole).toString())
100- self.fileRenameForm.fileNameEdit.setText(oldThemeName)
101+ old_theme_name = unicode(item.data(QtCore.Qt.UserRole).toString())
102+ self.fileRenameForm.fileNameEdit.setText(old_theme_name)
103 if self.fileRenameForm.exec_():
104- newThemeName = unicode(self.fileRenameForm.fileNameEdit.text())
105- if oldThemeName == newThemeName:
106+ new_theme_name = unicode(self.fileRenameForm.fileNameEdit.text())
107+ if old_theme_name == new_theme_name:
108 return
109- if self.checkIfThemeExists(newThemeName):
110- oldThemeData = self.getThemeData(oldThemeName)
111- self.cloneThemeData(oldThemeData, newThemeName)
112- self.deleteTheme(oldThemeName)
113+ if self.checkIfThemeExists(new_theme_name):
114+ old_theme_data = self.getThemeData(old_theme_name)
115+ self.cloneThemeData(old_theme_data, new_theme_name)
116+ self.deleteTheme(old_theme_name)
117 for plugin in self.mainwindow.pluginManager.plugins:
118- if plugin.usesTheme(oldThemeName):
119- plugin.renameTheme(oldThemeName, newThemeName)
120+ if plugin.usesTheme(old_theme_name):
121+ plugin.renameTheme(old_theme_name, new_theme_name)
122 self.loadThemes()
123
124 def onCopyTheme(self):
125@@ -292,30 +292,30 @@
126 Copies an existing theme to a new name
127 """
128 item = self.themeListWidget.currentItem()
129- oldThemeName = unicode(item.data(QtCore.Qt.UserRole).toString())
130+ old_theme_name = unicode(item.data(QtCore.Qt.UserRole).toString())
131 self.fileRenameForm.fileNameEdit.setText(
132 unicode(translate('OpenLP.ThemeManager',
133- 'Copy of %s','Copy of <theme name>')) % oldThemeName)
134+ 'Copy of %s', 'Copy of <theme name>')) % old_theme_name)
135 if self.fileRenameForm.exec_(True):
136- newThemeName = unicode(self.fileRenameForm.fileNameEdit.text())
137- if self.checkIfThemeExists(newThemeName):
138- themeData = self.getThemeData(oldThemeName)
139- self.cloneThemeData(themeData, newThemeName)
140+ new_theme_name = unicode(self.fileRenameForm.fileNameEdit.text())
141+ if self.checkIfThemeExists(new_theme_name):
142+ theme_data = self.getThemeData(old_theme_name)
143+ self.cloneThemeData(theme_data, new_theme_name)
144
145- def cloneThemeData(self, themeData, newThemeName):
146+ def cloneThemeData(self, theme_data, new_theme_name):
147 """
148 Takes a theme and makes a new copy of it as well as saving it.
149 """
150 log.debug(u'cloneThemeData')
151- saveTo = None
152- saveFrom = None
153- if themeData.background_type == u'image':
154- saveTo = os.path.join(self.path, newThemeName,
155- os.path.split(unicode(themeData.background_filename))[1])
156- saveFrom = themeData.background_filename
157- themeData.theme_name = newThemeName
158- themeData.extend_image_filename(self.path)
159- self.saveTheme(themeData, saveFrom, saveTo)
160+ save_to = None
161+ save_from = None
162+ if theme_data.background_type == u'image':
163+ save_to = os.path.join(self.path, new_theme_name,
164+ os.path.split(unicode(theme_data.background_filename))[1])
165+ save_from = theme_data.background_filename
166+ theme_data.theme_name = new_theme_name
167+ theme_data.extend_image_filename(self.path)
168+ self.saveTheme(theme_data, save_from, save_to)
169
170 def onEditTheme(self):
171 """
172@@ -329,10 +329,10 @@
173 theme = self.getThemeData(
174 unicode(item.data(QtCore.Qt.UserRole).toString()))
175 if theme.background_type == u'image':
176- self.oldBackgroundImage = theme.background_filename
177+ self.old_background_image = theme.background_filename
178 self.themeForm.theme = theme
179 self.themeForm.exec_(True)
180- self.oldBackgroundImage = None
181+ self.old_background_image = None
182
183 def onDeleteTheme(self):
184 """
185@@ -358,10 +358,10 @@
186 ``theme``
187 The theme to delete.
188 """
189- self.themelist.remove(theme)
190+ self.theme_list.remove(theme)
191 thumb = u'%s.png' % theme
192 delete_file(os.path.join(self.path, thumb))
193- delete_file(os.path.join(self.thumbPath, thumb))
194+ delete_file(os.path.join(self.thumb_path, thumb))
195 try:
196 encoding = get_filesystem_encoding()
197 shutil.rmtree(os.path.join(self.path, theme).encode(encoding))
198@@ -386,10 +386,10 @@
199 Receiver.send_message(u'cursor_busy')
200 if path:
201 SettingsManager.set_last_dir(self.settingsSection, path, 1)
202- themePath = os.path.join(path, theme + u'.otz')
203+ theme_path = os.path.join(path, theme + u'.otz')
204 zip = None
205 try:
206- zip = zipfile.ZipFile(themePath, u'w')
207+ zip = zipfile.ZipFile(theme_path, u'w')
208 source = os.path.join(self.path, theme)
209 for files in os.walk(source):
210 for name in files[2]:
211@@ -439,9 +439,8 @@
212 The plugins will call back in to get the real list if they want it.
213 """
214 log.debug(u'Load themes from dir')
215- self.themelist = []
216+ self.theme_list = []
217 self.themeListWidget.clear()
218- dirList = os.listdir(self.path)
219 files = SettingsManager.get_files(self.settingsSection, u'.png')
220 if firstTime:
221 self.firstTime()
222@@ -458,29 +457,29 @@
223 files = SettingsManager.get_files(self.settingsSection, u'.png')
224 # Sort the themes by its name considering language specific characters.
225 # lower() is needed for windows!
226- files.sort(key=lambda filename: unicode(filename).lower(),
227+ files.sort(key=lambda file_name: unicode(file_name).lower(),
228 cmp=locale.strcoll)
229 # now process the file list of png files
230 for name in files:
231 # check to see file is in theme root directory
232 theme = os.path.join(self.path, name)
233 if os.path.exists(theme):
234- textName = os.path.splitext(name)[0]
235- if textName == self.global_theme:
236+ text_name = os.path.splitext(name)[0]
237+ if text_name == self.global_theme:
238 name = unicode(translate('OpenLP.ThemeManager',
239- '%s (default)')) % textName
240+ '%s (default)')) % text_name
241 else:
242- name = textName
243- thumb = os.path.join(self.thumbPath, u'%s.png' % textName)
244+ name = text_name
245+ thumb = os.path.join(self.thumb_path, u'%s.png' % text_name)
246 item_name = QtGui.QListWidgetItem(name)
247 if validate_thumb(theme, thumb):
248 icon = build_icon(thumb)
249 else:
250 icon = create_thumb(theme, thumb)
251 item_name.setIcon(icon)
252- item_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(textName))
253+ item_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(text_name))
254 self.themeListWidget.addItem(item_name)
255- self.themelist.append(textName)
256+ self.theme_list.append(text_name)
257 self._pushThemes()
258
259 def _pushThemes(self):
260@@ -493,50 +492,68 @@
261 """
262 Return the list of loaded themes
263 """
264- return self.themelist
265+ return self.theme_list
266
267- def getThemeData(self, themeName):
268+ def getThemeData(self, theme_name):
269 """
270 Returns a theme object from an XML file
271
272- ``themeName``
273+ ``theme_name``
274 Name of the theme to load from file
275 """
276- log.debug(u'getthemedata for theme %s', themeName)
277- xmlFile = os.path.join(self.path, unicode(themeName),
278- unicode(themeName) + u'.xml')
279- xml = get_text_file_string(xmlFile)
280+ log.debug(u'getthemedata for theme %s', theme_name)
281+ xml_file = os.path.join(self.path, unicode(theme_name),
282+ unicode(theme_name) + u'.xml')
283+ xml = get_text_file_string(xml_file)
284 if not xml:
285 log.debug("No theme data - using default theme")
286 return ThemeXML()
287 else:
288 return self._createThemeFromXml(xml, self.path)
289+
290+ def overWriteMessageBox(self, theme_name):
291+ ret = QtGui.QMessageBox.question(self,
292+ translate('OpenLP.ThemeManager', 'Theme Already Exists'),
293+ translate('OpenLP.ThemeManager',
294+ 'Theme %s already exists. Do you want to replace it?'
295+ % theme_name),
296+ QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Yes |
297+ QtGui.QMessageBox.No),
298+ QtGui.QMessageBox.No)
299+ return ret == QtGui.QMessageBox.Yes
300
301- def unzipTheme(self, filename, dir):
302+ def unzipTheme(self, file_name, dir):
303 """
304 Unzip the theme, remove the preview file if stored
305 Generate a new preview file. Check the XML theme version and upgrade if
306 necessary.
307 """
308- log.debug(u'Unzipping theme %s', filename)
309- filename = unicode(filename)
310+ log.debug(u'Unzipping theme %s', file_name)
311+ file_name = unicode(file_name)
312 zip = None
313- outfile = None
314- filexml = None
315+ out_file = None
316+ file_xml = None
317 try:
318- zip = zipfile.ZipFile(filename)
319- xmlfile = filter(lambda name:
320+ zip = zipfile.ZipFile(file_name)
321+ xml_file = filter(lambda name:
322 os.path.splitext(name)[1].lower() == u'.xml', zip.namelist())
323- if len(xmlfile) != 1:
324- log.exception(u'Theme contains "%s" XML files' % len(xmlfile))
325+ if len(xml_file) != 1:
326+ log.exception(u'Theme contains "%s" XML files' % len(xml_file))
327 raise Exception(u'validation')
328- xml_tree = ElementTree(element=XML(zip.read(xmlfile[0]))).getroot()
329+ xml_tree = ElementTree(element=XML(zip.read(xml_file[0]))).getroot()
330 v1_background = xml_tree.find(u'BackgroundType')
331 if v1_background is not None:
332- (themename, filexml, outfile) = self.unzipVersion122(dir, zip,
333- xmlfile[0], xml_tree, v1_background, outfile)
334+ theme_name, file_xml, out_file, abort_import = self.unzipVersion122(dir, zip,
335+ xml_file[0], xml_tree, v1_background, out_file)
336 else:
337- themename = xml_tree.find(u'name').text.strip()
338+ theme_name = xml_tree.find(u'name').text.strip()
339+ theme_folder = os.path.join(dir, theme_name)
340+ theme_exists = os.path.exists(theme_folder)
341+ if theme_exists and not self.overWriteMessageBox(theme_name):
342+ abort_import = True
343+ return
344+ else:
345+ abort_import = False
346 for name in zip.namelist():
347 try:
348 uname = unicode(name, u'utf-8')
349@@ -545,22 +562,22 @@
350 u' "%s"' % name.decode(u'utf-8', u'replace'))
351 raise Exception(u'validation')
352 uname = unicode(QtCore.QDir.toNativeSeparators(uname))
353- splitname = uname.split(os.path.sep)
354- if splitname[-1] == u'' or len(splitname) == 1:
355+ split_name = uname.split(os.path.sep)
356+ if split_name[-1] == u'' or len(split_name) == 1:
357 # is directory or preview file
358 continue
359- fullname = os.path.join(dir, uname)
360- check_directory_exists(os.path.dirname(fullname))
361+ full_name = os.path.join(dir, uname)
362+ check_directory_exists(os.path.dirname(full_name))
363 if os.path.splitext(uname)[1].lower() == u'.xml':
364- filexml = unicode(zip.read(name), u'utf-8')
365- outfile = open(fullname, u'w')
366- outfile.write(filexml.encode(u'utf-8'))
367+ file_xml = unicode(zip.read(name), u'utf-8')
368+ out_file = open(full_name, u'w')
369+ out_file.write(file_xml.encode(u'utf-8'))
370 else:
371- outfile = open(fullname, u'wb')
372- outfile.write(zip.read(name))
373- outfile.close()
374+ out_file = open(full_name, u'wb')
375+ out_file.write(zip.read(name))
376+ out_file.close()
377 except (IOError, zipfile.BadZipfile):
378- log.exception(u'Importing theme from zip failed %s' % filename)
379+ log.exception(u'Importing theme from zip failed %s' % file_name)
380 raise Exception(u'validation')
381 except Exception as info:
382 if unicode(info) == u'validation':
383@@ -573,60 +590,65 @@
384 # Close the files, to be able to continue creating the theme.
385 if zip:
386 zip.close()
387- if outfile:
388- outfile.close()
389- # As all files are closed, we can create the Theme.
390- if filexml:
391- theme = self._createThemeFromXml(filexml, self.path)
392- self.generateAndSaveImage(dir, themename, theme)
393- # Only show the error message, when IOError was not raised (in this
394- # case the error message has already been shown).
395- elif zip is not None:
396- critical_error_message_box(
397- translate('OpenLP.ThemeManager', 'Validation Error'),
398- translate('OpenLP.ThemeManager',
399- 'File is not a valid theme.'))
400- log.exception(u'Theme file does not contain XML data %s' %
401- filename)
402+ if out_file:
403+ out_file.close()
404+ if not abort_import:
405+ # As all files are closed, we can create the Theme.
406+ if file_xml:
407+ theme = self._createThemeFromXml(file_xml, self.path)
408+ self.generateAndSaveImage(dir, theme_name, theme)
409+ # Only show the error message, when IOError was not raised (in this
410+ # case the error message has already been shown).
411+ elif zip is not None:
412+ critical_error_message_box(
413+ translate('OpenLP.ThemeManager', 'Validation Error'),
414+ translate('OpenLP.ThemeManager',
415+ 'File is not a valid theme.'))
416+ log.exception(u'Theme file does not contain XML data %s' %
417+ file_name)
418
419- def unzipVersion122(self, dir, zip, xmlfile, xml_tree, background, outfile):
420+ def unzipVersion122(self, dir, zip, xml_file, xml_tree, background, out_file):
421 """
422 Unzip openlp.org 1.2x theme file and upgrade the theme xml. When calling
423 this method, please keep in mind, that some parameters are redundant.
424 """
425- themename = xml_tree.find(u'Name').text.strip()
426- themename = self.bad_v1_name_chars.sub(u'', themename)
427- themedir = os.path.join(dir, themename)
428+ theme_name = xml_tree.find(u'Name').text.strip()
429+ theme_name = self.bad_v1_name_chars.sub(u'', theme_name)
430+ theme_folder = os.path.join(dir, theme_name)
431+ theme_exists = os.path.exists(theme_folder)
432+ if theme_exists and not self.overWriteMessageBox(theme_name):
433+ return '', '', '', True
434+ themedir = os.path.join(dir, theme_name)
435 check_directory_exists(themedir)
436- filexml = unicode(zip.read(xmlfile), u'utf-8')
437- filexml = self._migrateVersion122(filexml)
438- outfile = open(os.path.join(themedir, themename + u'.xml'), u'w')
439- outfile.write(filexml.encode(u'utf-8'))
440- outfile.close()
441+ file_xml = unicode(zip.read(xml_file), u'utf-8')
442+ file_xml = self._migrateVersion122(file_xml)
443+ out_file = open(os.path.join(themedir, theme_name + u'.xml'), u'w')
444+ out_file.write(file_xml.encode(u'utf-8'))
445+ out_file.close()
446 if background.text.strip() == u'2':
447- imagename = xml_tree.find(u'BackgroundParameter1').text.strip()
448+ image_name = xml_tree.find(u'BackgroundParameter1').text.strip()
449 # image file has same extension and is in subfolder
450 imagefile = filter(lambda name: os.path.splitext(name)[1].lower()
451- == os.path.splitext(imagename)[1].lower() and name.find(r'/'),
452+ == os.path.splitext(image_name)[1].lower() and name.find(r'/'),
453 zip.namelist())
454 if len(imagefile) >= 1:
455- outfile = open(os.path.join(themedir, imagename), u'wb')
456- outfile.write(zip.read(imagefile[0]))
457- outfile.close()
458+ out_file = open(os.path.join(themedir, image_name), u'wb')
459+ out_file.write(zip.read(imagefile[0]))
460+ out_file.close()
461 else:
462 log.exception(u'Theme file does not contain image file "%s"' %
463- imagename.decode(u'utf-8', u'replace'))
464+ image_name.decode(u'utf-8', u'replace'))
465 raise Exception(u'validation')
466- return (themename, filexml, outfile)
467+ return theme_name, file_xml, out_file, False
468
469- def checkIfThemeExists(self, themeName):
470+ def checkIfThemeExists(self, theme_name):
471 """
472 Check if theme already exists and displays error message
473
474- ``themeName``
475+ ``theme_name``
476 Name of the Theme to test
477 """
478- theme_dir = os.path.join(self.path, themeName)
479+ theme_dir = os.path.join(self.path, theme_name)
480 if os.path.exists(theme_dir):
481 critical_error_message_box(
482 translate('OpenLP.ThemeManager', 'Validation Error'),
483@@ -635,12 +657,12 @@
484 return False
485 return True
486
487- def saveTheme(self, theme, imageFrom, imageTo):
488+ def saveTheme(self, theme, image_from, image_to):
489 """
490 Called by thememaintenance Dialog to save the theme
491 and to trigger the reload of the theme list
492 """
493- self._writeTheme(theme, imageFrom, imageTo)
494+ self._writeTheme(theme, image_from, image_to)
495 if theme.background_type == \
496 BackgroundType.to_string(BackgroundType.Image):
497 self.mainwindow.imageManager.update_image(theme.theme_name,
498@@ -648,7 +670,7 @@
499 self.mainwindow.imageManager.process_updates()
500 self.loadThemes()
501
502- def _writeTheme(self, theme, imageFrom, imageTo):
503+ def _writeTheme(self, theme, image_from, image_to):
504 """
505 Writes the theme to the disk and handles the background image if
506 necessary
507@@ -659,24 +681,24 @@
508 theme_dir = os.path.join(self.path, name)
509 check_directory_exists(theme_dir)
510 theme_file = os.path.join(theme_dir, name + u'.xml')
511- if self.oldBackgroundImage and \
512- imageTo != self.oldBackgroundImage:
513- delete_file(self.oldBackgroundImage)
514- outfile = None
515+ if self.old_background_image and \
516+ image_to != self.old_background_image:
517+ delete_file(self.old_background_image)
518+ out_file = None
519 try:
520- outfile = open(theme_file, u'w')
521- outfile.write(theme_pretty_xml)
522+ out_file = open(theme_file, u'w')
523+ out_file.write(theme_pretty_xml)
524 except IOError:
525 log.exception(u'Saving theme to file failed')
526 finally:
527- if outfile:
528- outfile.close()
529- if imageFrom and imageFrom != imageTo:
530+ if out_file:
531+ out_file.close()
532+ if image_from and image_from != image_to:
533 try:
534 encoding = get_filesystem_encoding()
535 shutil.copyfile(
536- unicode(imageFrom).encode(encoding),
537- unicode(imageTo).encode(encoding))
538+ unicode(image_from).encode(encoding),
539+ unicode(image_to).encode(encoding))
540 except IOError:
541 log.exception(u'Failed to save theme image')
542 self.generateAndSaveImage(self.path, name, theme)
543@@ -684,39 +706,39 @@
544 def generateAndSaveImage(self, dir, name, theme):
545 log.debug(u'generateAndSaveImage %s %s', dir, name)
546 frame = self.generateImage(theme)
547- samplepathname = os.path.join(self.path, name + u'.png')
548- if os.path.exists(samplepathname):
549- os.unlink(samplepathname)
550- frame.save(samplepathname, u'png')
551- thumb = os.path.join(self.thumbPath, u'%s.png' % name)
552- create_thumb(samplepathname, thumb, False)
553- log.debug(u'Theme image written to %s', samplepathname)
554+ sample_path_name = os.path.join(self.path, name + u'.png')
555+ if os.path.exists(sample_path_name):
556+ os.unlink(sample_path_name)
557+ frame.save(sample_path_name, u'png')
558+ thumb = os.path.join(self.thumb_path, u'%s.png' % name)
559+ create_thumb(sample_path_name, thumb, False)
560+ log.debug(u'Theme image written to %s', sample_path_name)
561
562 def updatePreviewImages(self):
563 """
564 Called to update the themes' preview images.
565 """
566- self.mainwindow.displayProgressBar(len(self.themelist))
567- for theme in self.themelist:
568+ self.mainwindow.displayProgressBar(len(self.theme_list))
569+ for theme in self.theme_list:
570 self.mainwindow.incrementProgressBar()
571 self.generateAndSaveImage(
572 self.path, theme, self.getThemeData(theme))
573 self.mainwindow.finishedProgressBar()
574 self.loadThemes()
575
576- def generateImage(self, themeData, forcePage=False):
577+ def generateImage(self, theme_data, forcePage=False):
578 """
579 Call the renderer to build a Sample Image
580
581- ``themeData``
582+ ``theme_data``
583 The theme to generated a preview for.
584
585 ``forcePage``
586 Flag to tell message lines per page need to be generated.
587 """
588- log.debug(u'generateImage \n%s ', themeData)
589+ log.debug(u'generateImage \n%s ', theme_data)
590 return self.mainwindow.renderer.generate_preview(
591- themeData, forcePage)
592+ theme_data, forcePage)
593
594 def getPreviewImage(self, theme):
595 """
596@@ -729,15 +751,15 @@
597 image = os.path.join(self.path, theme + u'.png')
598 return image
599
600- def _createThemeFromXml(self, themeXml, path):
601+ def _createThemeFromXml(self, theme_xml, path):
602 """
603 Return a theme object using information parsed from XML
604
605- ``themeXml``
606+ ``theme_xml``
607 The XML data to load into the theme
608 """
609 theme = ThemeXML()
610- theme.parse(themeXml)
611+ theme.parse(theme_xml)
612 theme.extend_image_filename(path)
613 return theme
614
615@@ -792,53 +814,53 @@
616 Version 1 theme to convert
617 """
618 theme = Theme(xml_data)
619- newtheme = ThemeXML()
620- newtheme.theme_name = self.bad_v1_name_chars.sub(u'', theme.Name)
621+ new_theme = ThemeXML()
622+ new_theme.theme_name = self.bad_v1_name_chars.sub(u'', theme.Name)
623 if theme.BackgroundType == 0:
624- newtheme.background_type = \
625+ new_theme.background_type = \
626 BackgroundType.to_string(BackgroundType.Solid)
627- newtheme.background_color = \
628+ new_theme.background_color = \
629 unicode(theme.BackgroundParameter1.name())
630 elif theme.BackgroundType == 1:
631- newtheme.background_type = \
632+ new_theme.background_type = \
633 BackgroundType.to_string(BackgroundType.Gradient)
634- newtheme.background_direction = \
635+ new_theme.background_direction = \
636 BackgroundGradientType. \
637 to_string(BackgroundGradientType.Horizontal)
638 if theme.BackgroundParameter3.name() == 1:
639- newtheme.background_direction = \
640+ new_theme.background_direction = \
641 BackgroundGradientType. \
642 to_string(BackgroundGradientType.Horizontal)
643- newtheme.background_start_color = \
644+ new_theme.background_start_color = \
645 unicode(theme.BackgroundParameter1.name())
646- newtheme.background_end_color = \
647+ new_theme.background_end_color = \
648 unicode(theme.BackgroundParameter2.name())
649 elif theme.BackgroundType == 2:
650- newtheme.background_type = \
651+ new_theme.background_type = \
652 BackgroundType.to_string(BackgroundType.Image)
653- newtheme.background_filename = unicode(theme.BackgroundParameter1)
654+ new_theme.background_filename = unicode(theme.BackgroundParameter1)
655 elif theme.BackgroundType == 3:
656- newtheme.background_type = \
657+ new_theme.background_type = \
658 BackgroundType.to_string(BackgroundType.Transparent)
659- newtheme.font_main_name = theme.FontName
660- newtheme.font_main_color = unicode(theme.FontColor.name())
661- newtheme.font_main_size = theme.FontProportion * 3
662- newtheme.font_footer_name = theme.FontName
663- newtheme.font_footer_color = unicode(theme.FontColor.name())
664- newtheme.font_main_shadow = False
665+ new_theme.font_main_name = theme.FontName
666+ new_theme.font_main_color = unicode(theme.FontColor.name())
667+ new_theme.font_main_size = theme.FontProportion * 3
668+ new_theme.font_footer_name = theme.FontName
669+ new_theme.font_footer_color = unicode(theme.FontColor.name())
670+ new_theme.font_main_shadow = False
671 if theme.Shadow == 1:
672- newtheme.font_main_shadow = True
673- newtheme.font_main_shadow_color = unicode(theme.ShadowColor.name())
674+ new_theme.font_main_shadow = True
675+ new_theme.font_main_shadow_color = unicode(theme.ShadowColor.name())
676 if theme.Outline == 1:
677- newtheme.font_main_outline = True
678- newtheme.font_main_outline_color = \
679+ new_theme.font_main_outline = True
680+ new_theme.font_main_outline_color = \
681 unicode(theme.OutlineColor.name())
682 vAlignCorrection = VerticalType.Top
683 if theme.VerticalAlign == 2:
684 vAlignCorrection = VerticalType.Middle
685 elif theme.VerticalAlign == 1:
686 vAlignCorrection = VerticalType.Bottom
687- newtheme.display_horizontal_align = theme.HorizontalAlign
688- newtheme.display_vertical_align = vAlignCorrection
689- return newtheme.extract_xml()
690+ new_theme.display_horizontal_align = theme.HorizontalAlign
691+ new_theme.display_vertical_align = vAlignCorrection
692+ return new_theme.extract_xml()
693