PEP8 type checking and cleanups

This commit is contained in:
Jon Tibble 2010-06-09 18:09:32 +01:00
parent 5bd60d1fd4
commit 0b1621923a
14 changed files with 58 additions and 63 deletions

View File

@ -24,7 +24,6 @@
###############################################################################
import logging
import types
import os
from PyQt4 import QtCore, QtGui
@ -98,9 +97,9 @@ class MediaManagerItem(QtGui.QWidget):
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:

View File

@ -145,7 +145,7 @@ class Renderer(object):
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 @@ class Renderer(object):
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 @@ class Renderer(object):
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 @@ class Renderer(object):
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 @@ class Renderer(object):
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 @@ class Renderer(object):
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 @@ class Renderer(object):
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.

View File

@ -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 @@ class XmlRootClass(object):
for element in xml_iter:
if element.tag != root_tag:
text = element.text
if type(text) is NoneType:
if text is None:
val = text
elif type(text) is UnicodeType :
val = text
elif type(text) is StringType:
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.

View File

@ -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 @@ class Theme(object):
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)

View File

@ -408,7 +408,7 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog):
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 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog):
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:

View File

@ -74,7 +74,7 @@ class DisplayWidget(QtGui.QWidget):
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 @@ class VideoDisplay(Phonon.VideoWidget):
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()

View File

@ -44,7 +44,7 @@ class ServiceManagerList(QtGui.QTreeWidget):
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 @@ class ServiceManager(QtGui.QWidget):
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

View File

@ -70,7 +70,7 @@ class SlideList(QtGui.QTableWidget):
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()

View File

@ -438,7 +438,7 @@ class ThemeManager(QtGui.QWidget):
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

View File

@ -27,6 +27,7 @@ import logging
import os
from PyQt4 import QtCore, QtGui
from openlp.core.utils import AppLocation
from openlp.core.lib import translate
@ -41,7 +42,7 @@ class LanguageManager(object):
@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 @@ class LanguageManager(object):
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 @@ class LanguageManager(object):
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 @@ class LanguageManager(object):
@staticmethod
def get_qm_list():
if LanguageManager.__qmList__ == None:
if LanguageManager.__qmList__ is None:
LanguageManager.init_qm_list()
return LanguageManager.__qmList__

View File

@ -242,7 +242,7 @@ class BibleCommon(object):
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 unescape(text):
"""
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]))

View File

@ -184,7 +184,7 @@ class BGExtract(BibleCommon):
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

View File

@ -27,7 +27,7 @@ import logging
import sys
import os
from types import StringType, ListType
from types import ListType
sys.path.append(os.path.abspath(u'./../../../..'))
@ -417,9 +417,9 @@ class Song(object):
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 = []

View File

@ -31,8 +31,9 @@
###############################################################################
import os
from optparse import OptionParser
import urllib
from optparse import OptionParser
from PyQt4 import QtCore
ignore_pathes = [u"./scripts", u"./openlp/core/test"]
@ -62,16 +63,16 @@ def main():
# 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 main():
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 @@ def preparation():
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 @@ def preparation():
write_file(os.path.join(start_dir, u'openlp.pro'), stringlist)
print u'done.'
def update():
print "update()"
updateProcess = QtCore.QProcess()