openlp-core team mailing list archive
-
openlp-core team
-
Mailing list archive
-
Message #01723
[Merge] lp:~meths/openlp/trivialfixes into lp:openlp
Jon Tibble has proposed merging lp:~meths/openlp/trivialfixes into lp:openlp.
Requested reviews:
OpenLP Core (openlp-core)
More cleaning:
* PEP8 type checking
* Fix theme export breakage
* Whitespace
--
https://code.launchpad.net/~meths/openlp/trivialfixes/+merge/27215
Your team OpenLP Core is requested to review the proposed merge of lp:~meths/openlp/trivialfixes into lp:openlp.
=== modified file 'openlp/core/lib/mediamanageritem.py'
--- openlp/core/lib/mediamanageritem.py 2010-05-29 19:50:50 +0000
+++ openlp/core/lib/mediamanageritem.py 2010-06-10 00:10:45 +0000
@@ -24,7 +24,6 @@
###############################################################################
import logging
-import types
import os
from PyQt4 import QtCore, QtGui
@@ -98,9 +97,9 @@
QtGui.QWidget.__init__(self)
self.parent = parent
self.settingsSection = title.lower()
- if type(icon) is QtGui.QIcon:
+ if isinstance(icon, QtGui.QIcon):
self.icon = icon
- elif type(icon) is types.StringType:
+ elif isinstance(icon, basestring):
self.icon.addPixmap(QtGui.QPixmap.fromImage(QtGui.QImage(icon)),
QtGui.QIcon.Normal, QtGui.QIcon.Off)
else:
=== modified file 'openlp/core/lib/renderer.py'
--- openlp/core/lib/renderer.py 2010-05-29 19:50:50 +0000
+++ openlp/core/lib/renderer.py 2010-06-10 00:10:45 +0000
@@ -145,7 +145,7 @@
return split_text
def pre_render_text(self, text):
- metrics = QtGui.QFontMetrics(self.mainFont)
+ metrics = QtGui.QFontMetrics(self.main_font)
#work out line width
line_width = self._rect.width()
#number of lines on a page - adjust for rounding up.
@@ -248,7 +248,7 @@
self.frame = QtGui.QImage(self.bg_frame)
if self._theme.display_slideTransition:
self.frame_opaque = QtGui.QImage(self.bg_frame)
- x, y = self._correctAlignment(self._rect, bbox)
+ x, y = self._correct_alignment(self._rect, bbox)
bbox = self._render_lines_unaligned(lines, False, (x, y), True)
if footer_lines:
bbox = self._render_lines_unaligned(footer_lines, True,
@@ -304,15 +304,15 @@
gradient.setColorAt(1,
QtGui.QColor(self._theme.background_endColor))
painter.setBrush(QtGui.QBrush(gradient))
- rectPath = QtGui.QPainterPath()
+ rect_path = QtGui.QPainterPath()
max_x = self.frame.width()
max_y = self.frame.height()
- rectPath.moveTo(0, 0)
- rectPath.lineTo(0, max_y)
- rectPath.lineTo(max_x, max_y)
- rectPath.lineTo(max_x, 0)
- rectPath.closeSubpath()
- painter.drawPath(rectPath)
+ rect_path.moveTo(0, 0)
+ rect_path.lineTo(0, max_y)
+ rect_path.lineTo(max_x, max_y)
+ rect_path.lineTo(max_x, 0)
+ rect_path.closeSubpath()
+ painter.drawPath(rect_path)
elif self._theme.background_type == u'image':
# image
painter.fillRect(self.frame.rect(), QtCore.Qt.black)
@@ -321,7 +321,7 @@
painter.end()
log.debug(u'render background End')
- def _correctAlignment(self, rect, bbox):
+ def _correct_alignment(self, rect, bbox):
"""
Corrects the vertical alignment of text.
@@ -493,19 +493,19 @@
if self._theme.font_footer_weight == u'Bold':
footer_weight = 75
#TODO Add myfont.setPixelSize((screen_height / 100) * font_size)
- self.footerFont = QtGui.QFont(self._theme.font_footer_name,
+ self.footer_font = QtGui.QFont(self._theme.font_footer_name,
self._theme.font_footer_proportion, # size
footer_weight, # weight
self._theme.font_footer_italics) # italic
- self.footerFont.setPixelSize(self._theme.font_footer_proportion)
+ self.footer_font.setPixelSize(self._theme.font_footer_proportion)
main_weight = 50
if self._theme.font_main_weight == u'Bold':
main_weight = 75
- self.mainFont = QtGui.QFont(self._theme.font_main_name,
+ self.main_font = QtGui.QFont(self._theme.font_main_name,
self._theme.font_main_proportion, # size
main_weight, # weight
self._theme.font_main_italics)# italic
- self.mainFont.setPixelSize(self._theme.font_main_proportion)
+ self.main_font.setPixelSize(self._theme.font_main_proportion)
def _get_extent_and_render(self, line, footer, tlcorner=(0, 0), draw=False,
color=None, outline_size=0):
@@ -530,10 +530,10 @@
Defaults to *None*. The colour to draw with.
"""
# setup defaults
- if footer :
- font = self.footerFont
+ if footer:
+ font = self.footer_font
else:
- font = self.mainFont
+ font = self.main_font
metrics = QtGui.QFontMetrics(font)
w = metrics.width(line)
if footer:
@@ -576,7 +576,7 @@
self.painter2.drawText(x, rowpos, line)
return (w, h)
- def snoop_Image(self, image, image2=None):
+ def snoop_image(self, image, image2=None):
"""
Debugging method to allow images to be viewed.
=== modified file 'openlp/core/lib/xmlrootclass.py'
--- openlp/core/lib/xmlrootclass.py 2010-05-27 20:56:34 +0000
+++ openlp/core/lib/xmlrootclass.py 2010-06-10 00:10:45 +0000
@@ -25,7 +25,6 @@
import os
import sys
-from types import StringType, NoneType, UnicodeType
from xml.etree.ElementTree import ElementTree, XML
@@ -56,11 +55,9 @@
for element in xml_iter:
if element.tag != root_tag:
text = element.text
- if type(text) is NoneType:
- val = text
- elif type(text) is UnicodeType :
- val = text
- elif type(text) is StringType:
+ if text is None:
+ val = text
+ elif isinstance(text, basestring):
# Strings need special handling to sort the colours out
if text[0] == u'$':
# This might be a hex number, let's try to convert it.
=== modified file 'openlp/core/theme/theme.py'
--- openlp/core/theme/theme.py 2010-05-28 15:01:50 +0000
+++ openlp/core/theme/theme.py 2010-06-10 00:10:45 +0000
@@ -23,8 +23,6 @@
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
-import types
-
from xml.etree.ElementTree import ElementTree, XML
from PyQt4 import QtGui
@@ -121,8 +119,7 @@
if element_text is None:
val = element_text
# strings need special handling to sort the colours out
- if type(element_text) is types.StringType or \
- type(element_text) is types.UnicodeType:
+ if isinstance(element_text, basestring):
if element_text[0] == u'$': # might be a hex number
try:
val = int(element_text[1:], 16)
=== modified file 'openlp/core/ui/amendthemeform.py'
--- openlp/core/ui/amendthemeform.py 2010-06-08 15:38:09 +0000
+++ openlp/core/ui/amendthemeform.py 2010-06-10 00:10:45 +0000
@@ -408,7 +408,7 @@
def setBackground(self, background, gradient):
if background == 0: # Solid
self.theme.background_type = u'solid'
- if self.theme.background_color is None :
+ if self.theme.background_color is None:
self.theme.background_color = u'#000000'
self.ImageLineEdit.setText(u'')
elif background == 1: # Gradient
@@ -419,9 +419,9 @@
self.theme.background_direction = u'vertical'
else:
self.theme.background_direction = u'circular'
- if self.theme.background_startColor is None :
+ if self.theme.background_startColor is None:
self.theme.background_startColor = u'#000000'
- if self.theme.background_endColor is None :
+ if self.theme.background_endColor is None:
self.theme.background_endColor = u'#ff0000'
self.ImageLineEdit.setText(u'')
else:
=== modified file 'openlp/core/ui/maindisplay.py'
--- openlp/core/ui/maindisplay.py 2010-05-15 06:57:29 +0000
+++ openlp/core/ui/maindisplay.py 2010-06-10 00:10:45 +0000
@@ -74,7 +74,7 @@
QtCore.Qt.Key_Backspace: 'slidecontroller_live_previous_noloop'}
def keyPressEvent(self, event):
- if type(event) == QtGui.QKeyEvent:
+ if isinstance(event, QtGui.QKeyEvent):
#here accept the event and do something
if event.key() == QtCore.Qt.Key_Up:
Receiver.send_message(u'slidecontroller_live_previous')
@@ -375,7 +375,7 @@
self.setVisible(False)
def keyPressEvent(self, event):
- if type(event) == QtGui.QKeyEvent:
+ if isinstance(event, QtGui.QKeyEvent):
#here accept the event and do something
if event.key() == QtCore.Qt.Key_Escape:
self.onMediaStop()
=== modified file 'openlp/core/ui/servicemanager.py'
--- openlp/core/ui/servicemanager.py 2010-06-07 21:36:22 +0000
+++ openlp/core/ui/servicemanager.py 2010-06-10 00:10:45 +0000
@@ -44,7 +44,7 @@
self.parent = parent
def keyPressEvent(self, event):
- if type(event) == QtGui.QKeyEvent:
+ if isinstance(event, QtGui.QKeyEvent):
#here accept the event and do something
if event.key() == QtCore.Qt.Key_Enter:
self.parent.makeLive()
@@ -918,7 +918,7 @@
else:
#we are not over anything so drop
replace = False
- if item == None:
+ if item is None:
self.droppos = len(self.serviceItems)
else:
#we are over somthing so lets investigate
=== modified file 'openlp/core/ui/slidecontroller.py'
--- openlp/core/ui/slidecontroller.py 2010-06-07 21:36:22 +0000
+++ openlp/core/ui/slidecontroller.py 2010-06-10 00:10:45 +0000
@@ -70,7 +70,7 @@
QtCore.Qt.Key_Backspace: 'slidecontroller_live_previous_noloop'}
def keyPressEvent(self, event):
- if type(event) == QtGui.QKeyEvent:
+ if isinstance(event, QtGui.QKeyEvent):
#here accept the event and do something
if event.key() == QtCore.Qt.Key_Up:
self.parent.onSlideSelectedPrevious()
=== modified file 'openlp/core/ui/thememanager.py'
--- openlp/core/ui/thememanager.py 2010-06-08 15:38:09 +0000
+++ openlp/core/ui/thememanager.py 2010-06-10 00:10:45 +0000
@@ -197,12 +197,12 @@
u'Theme %s is use in %s plugin' % (theme,
plugin.name)))
return
- if unicode(self.parent.ServiceManagerContents.ThemeComboBox.currentText()) == theme:
- QtGui.QMessageBox.critical(
- self, translate(u'ThemeManager',u'Error'),
+ if unicode(self.parent.ServiceManagerContents.ThemeComboBox \
+ .currentText()) == theme:
+ QtGui.QMessageBox.critical(self,
+ translate(u'ThemeManager', u'Error'),
translate(u'ThemeManager',
- u'Theme %s is use by Service Manager' % theme),
- QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok))
+ u'Theme %s is use by Service Manager' % theme))
return
self.themelist.remove(theme)
th = theme + u'.png'
@@ -228,8 +228,7 @@
if item is None:
QtGui.QMessageBox.critical(self,
translate(u'ThemeManager', u'Error'),
- translate(u'ThemeManager', u'You have not selected a theme.'),
- QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok))
+ translate(u'ThemeManager', u'You have not selected a theme.'))
return
theme = unicode(item.data(QtCore.Qt.UserRole).toString())
path = QtGui.QFileDialog.getExistingDirectory(self,
@@ -243,13 +242,21 @@
try:
zip = zipfile.ZipFile(themePath, u'w')
source = os.path.join(self.path, theme)
- for files in os.walk(source)[2]:
- for name in files:
+ for files in os.walk(source):
+ for name in files[2]:
zip.write(
os.path.join(source, name),
os.path.join(theme, name))
+ QtGui.QMessageBox.information(self,
+ translate(u'ThemeManager', u'Theme Exported'),
+ translate(u'ThemeManager',
+ u'Your theme has been successfully exported.'))
except (IOError, OSError):
log.exception(u'Export Theme Failed')
+ QtGui.QMessageBox.critical(self,
+ translate(u'ThemeManager', u'Theme Export Failed'),
+ translate(u'ThemeManager',
+ u'Your theme could not be exported due to an error.'))
finally:
if zip:
zip.close()
@@ -438,7 +445,7 @@
return newtheme.extract_xml()
def saveTheme(self, name, theme_xml, theme_pretty_xml, image_from,
- image_to) :
+ image_to):
"""
Called by thememaintenance Dialog to save the theme
and to trigger the reload of the theme list
=== modified file 'openlp/core/utils/languagemanager.py'
--- openlp/core/utils/languagemanager.py 2010-06-08 15:38:09 +0000
+++ openlp/core/utils/languagemanager.py 2010-06-10 00:10:45 +0000
@@ -27,6 +27,7 @@
import os
from PyQt4 import QtCore, QtGui
+
from openlp.core.utils import AppLocation
from openlp.core.lib import translate
@@ -41,7 +42,7 @@
@staticmethod
def get_translator(language):
- if LanguageManager.AutoLanguage :
+ if LanguageManager.AutoLanguage:
language = QtCore.QLocale.system().name()
lang_Path = AppLocation.get_directory(AppLocation.AppDir)
lang_Path = os.path.join(lang_Path, u'resources', u'i18n')
@@ -81,7 +82,7 @@
def set_language(action):
actionName = u'%s' % action.objectName()
qmList = LanguageManager.get_qm_list()
- if LanguageManager.AutoLanguage :
+ if LanguageManager.AutoLanguage:
language = u'[%s]' % qmList[actionName]
else:
language = u'%s' % qmList[actionName]
@@ -89,9 +90,9 @@
u'general/language', QtCore.QVariant(language))
log.info(u'Language file: \'%s\' written to conf file' % language)
QtGui.QMessageBox.information(None,
- translate(u'LanguageManager', u'Language'),
- translate(u'LanguageManager',
- u'After restart new Language settings will be used.'))
+ translate(u'LanguageManager', u'Language'),
+ translate(u'LanguageManager',
+ u'After restart new Language settings will be used.'))
@staticmethod
def init_qm_list():
@@ -106,7 +107,7 @@
@staticmethod
def get_qm_list():
- if LanguageManager.__qmList__ == None:
+ if LanguageManager.__qmList__ is None:
LanguageManager.init_qm_list()
return LanguageManager.__qmList__
=== modified file 'openlp/plugins/bibles/lib/common.py'
--- openlp/plugins/bibles/lib/common.py 2010-06-01 17:13:54 +0000
+++ openlp/plugins/bibles/lib/common.py 2010-06-10 00:10:45 +0000
@@ -242,7 +242,7 @@
text = text.replace(u''', u'\'')
# Remove some other tags
start_tag = text.find(u'<')
- while start_tag > -1 :
+ while start_tag > -1:
end_tag = text.find(u'>', start_tag)
text = text[:start_tag] + text[end_tag + 1:]
start_tag = text.find(u'<')
@@ -260,10 +260,10 @@
"""
def fixup(markup):
text = markup.group(0)
- if text[:2] == u'&#':
+ if text.startswith(u'&#'):
# character reference
try:
- if text[:3] == u'&#x':
+ if text.startswith(u'&#x'):
return unichr(int(text[3:-1], 16))
else:
return unichr(int(text[2:-1]))
=== modified file 'openlp/plugins/bibles/lib/http.py'
--- openlp/plugins/bibles/lib/http.py 2010-06-01 00:05:05 +0000
+++ openlp/plugins/bibles/lib/http.py 2010-06-10 00:10:45 +0000
@@ -184,7 +184,7 @@
log.debug(u'init %s', proxyurl)
self.proxyurl = proxyurl
- def get_bible_chapter(self, version, bookname, chapter) :
+ def get_bible_chapter(self, version, bookname, chapter):
"""
Access and decode bibles via the BibleGateway website
=== modified file 'openlp/plugins/songs/lib/songxml.py'
--- openlp/plugins/songs/lib/songxml.py 2010-05-29 19:50:50 +0000
+++ openlp/plugins/songs/lib/songxml.py 2010-06-10 00:10:45 +0000
@@ -27,7 +27,7 @@
import sys
import os
-from types import StringType, ListType
+from types import ListType
sys.path.append(os.path.abspath(u'./../../../..'))
@@ -417,9 +417,9 @@
def _list_to_string(self, strOrList):
"""Force a possibly list into a string"""
- if type(strOrList) == StringType:
+ if isinstance(strOrList, basestring):
lst = self._split_to_list(strOrList)
- elif type(strOrList) == ListType:
+ elif isinstance(strOrList, ListType):
lst = strOrList
elif strOrList is None:
lst = []
=== modified file 'scripts/translation_utils.py'
--- scripts/translation_utils.py 2010-05-20 16:46:53 +0000
+++ scripts/translation_utils.py 2010-06-10 00:10:45 +0000
@@ -31,8 +31,9 @@
###############################################################################
import os
+import urllib
+
from optparse import OptionParser
-import urllib
from PyQt4 import QtCore
ignore_pathes = [u"./scripts", u"./openlp/core/test"]
@@ -62,16 +63,16 @@
# Set up command line options.
usage = u'Usage: %prog [options]'
parser = OptionParser(usage=usage)
- parser.add_option("-d", "--download-ts", action="store_true", dest="download",
- help="Load languages from Pootle Server")
+ parser.add_option("-d", "--download-ts", action="store_true",
+ dest="download", help="Load languages from Pootle Server")
parser.add_option("-p", "--prepare", action="store_true", dest="prepare",
- help="preparation (generate pro file)")
+ help="preparation (generate pro file)")
parser.add_option("-u", "--update", action="store_true", dest="update",
- help="update translation files")
+ help="update translation files")
parser.add_option("-g", "--generate", action="store_true", dest="generate",
- help="generate qm files")
+ help="generate qm files")
parser.add_option("-a", "--all", action="store_true", dest="all",
- help="proceed all options")
+ help="proceed all options")
(options, args) = parser.parse_args()
if options.download:
@@ -90,7 +91,8 @@
def downloadTranslations():
print "download()"
for language in translations:
- filename = os.path.join(u'..',u'resources', u'i18n', u"openlp_%s.ts" % language)
+ filename = os.path.join(u'..', u'resources', u'i18n',
+ u"openlp_%s.ts" % language)
print filename
page = urllib.urlopen(u"%s%s.ts" % (translation_path, language))
content = page.read().decode("utf8")
@@ -115,13 +117,13 @@
for search in ignore_pathes:
if path.startswith(search):
cond = True
- if cond == True:
+ if cond:
continue
cond = False
for search in ignore_files:
if search == file:
cond = True
- if cond == True:
+ if cond:
continue
if file.endswith(u'.py'):
@@ -142,7 +144,6 @@
write_file(os.path.join(start_dir, u'openlp.pro'), stringlist)
print u'done.'
-
def update():
print "update()"
updateProcess = QtCore.QProcess()
Follow ups