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 logging
import types
import os import os
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
@ -98,9 +97,9 @@ class MediaManagerItem(QtGui.QWidget):
QtGui.QWidget.__init__(self) QtGui.QWidget.__init__(self)
self.parent = parent self.parent = parent
self.settingsSection = title.lower() self.settingsSection = title.lower()
if type(icon) is QtGui.QIcon: if isinstance(icon, QtGui.QIcon):
self.icon = icon self.icon = icon
elif type(icon) is types.StringType: elif isinstance(icon, basestring):
self.icon.addPixmap(QtGui.QPixmap.fromImage(QtGui.QImage(icon)), self.icon.addPixmap(QtGui.QPixmap.fromImage(QtGui.QImage(icon)),
QtGui.QIcon.Normal, QtGui.QIcon.Off) QtGui.QIcon.Normal, QtGui.QIcon.Off)
else: else:

View File

@ -145,7 +145,7 @@ class Renderer(object):
return split_text return split_text
def pre_render_text(self, text): def pre_render_text(self, text):
metrics = QtGui.QFontMetrics(self.mainFont) metrics = QtGui.QFontMetrics(self.main_font)
#work out line width #work out line width
line_width = self._rect.width() line_width = self._rect.width()
#number of lines on a page - adjust for rounding up. #number of lines on a page - adjust for rounding up.
@ -248,7 +248,7 @@ class Renderer(object):
self.frame = QtGui.QImage(self.bg_frame) self.frame = QtGui.QImage(self.bg_frame)
if self._theme.display_slideTransition: if self._theme.display_slideTransition:
self.frame_opaque = QtGui.QImage(self.bg_frame) 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) bbox = self._render_lines_unaligned(lines, False, (x, y), True)
if footer_lines: if footer_lines:
bbox = self._render_lines_unaligned(footer_lines, True, bbox = self._render_lines_unaligned(footer_lines, True,
@ -304,15 +304,15 @@ class Renderer(object):
gradient.setColorAt(1, gradient.setColorAt(1,
QtGui.QColor(self._theme.background_endColor)) QtGui.QColor(self._theme.background_endColor))
painter.setBrush(QtGui.QBrush(gradient)) painter.setBrush(QtGui.QBrush(gradient))
rectPath = QtGui.QPainterPath() rect_path = QtGui.QPainterPath()
max_x = self.frame.width() max_x = self.frame.width()
max_y = self.frame.height() max_y = self.frame.height()
rectPath.moveTo(0, 0) rect_path.moveTo(0, 0)
rectPath.lineTo(0, max_y) rect_path.lineTo(0, max_y)
rectPath.lineTo(max_x, max_y) rect_path.lineTo(max_x, max_y)
rectPath.lineTo(max_x, 0) rect_path.lineTo(max_x, 0)
rectPath.closeSubpath() rect_path.closeSubpath()
painter.drawPath(rectPath) painter.drawPath(rect_path)
elif self._theme.background_type == u'image': elif self._theme.background_type == u'image':
# image # image
painter.fillRect(self.frame.rect(), QtCore.Qt.black) painter.fillRect(self.frame.rect(), QtCore.Qt.black)
@ -321,7 +321,7 @@ class Renderer(object):
painter.end() painter.end()
log.debug(u'render background End') log.debug(u'render background End')
def _correctAlignment(self, rect, bbox): def _correct_alignment(self, rect, bbox):
""" """
Corrects the vertical alignment of text. Corrects the vertical alignment of text.
@ -493,19 +493,19 @@ class Renderer(object):
if self._theme.font_footer_weight == u'Bold': if self._theme.font_footer_weight == u'Bold':
footer_weight = 75 footer_weight = 75
#TODO Add myfont.setPixelSize((screen_height / 100) * font_size) #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 self._theme.font_footer_proportion, # size
footer_weight, # weight footer_weight, # weight
self._theme.font_footer_italics) # italic 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 main_weight = 50
if self._theme.font_main_weight == u'Bold': if self._theme.font_main_weight == u'Bold':
main_weight = 75 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 self._theme.font_main_proportion, # size
main_weight, # weight main_weight, # weight
self._theme.font_main_italics)# italic 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, def _get_extent_and_render(self, line, footer, tlcorner=(0, 0), draw=False,
color=None, outline_size=0): color=None, outline_size=0):
@ -530,10 +530,10 @@ class Renderer(object):
Defaults to *None*. The colour to draw with. Defaults to *None*. The colour to draw with.
""" """
# setup defaults # setup defaults
if footer : if footer:
font = self.footerFont font = self.footer_font
else: else:
font = self.mainFont font = self.main_font
metrics = QtGui.QFontMetrics(font) metrics = QtGui.QFontMetrics(font)
w = metrics.width(line) w = metrics.width(line)
if footer: if footer:
@ -576,7 +576,7 @@ class Renderer(object):
self.painter2.drawText(x, rowpos, line) self.painter2.drawText(x, rowpos, line)
return (w, h) 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. Debugging method to allow images to be viewed.

View File

@ -25,7 +25,6 @@
import os import os
import sys import sys
from types import StringType, NoneType, UnicodeType
from xml.etree.ElementTree import ElementTree, XML from xml.etree.ElementTree import ElementTree, XML
@ -56,11 +55,9 @@ class XmlRootClass(object):
for element in xml_iter: for element in xml_iter:
if element.tag != root_tag: if element.tag != root_tag:
text = element.text text = element.text
if type(text) is NoneType: if text is None:
val = text val = text
elif type(text) is UnicodeType : elif isinstance(text, basestring):
val = text
elif type(text) is StringType:
# Strings need special handling to sort the colours out # Strings need special handling to sort the colours out
if text[0] == u'$': if text[0] == u'$':
# This might be a hex number, let's try to convert it. # 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 # # Temple Place, Suite 330, Boston, MA 02111-1307 USA #
############################################################################### ###############################################################################
import types
from xml.etree.ElementTree import ElementTree, XML from xml.etree.ElementTree import ElementTree, XML
from PyQt4 import QtGui from PyQt4 import QtGui
@ -121,8 +119,7 @@ class Theme(object):
if element_text is None: if element_text is None:
val = element_text val = element_text
# strings need special handling to sort the colours out # strings need special handling to sort the colours out
if type(element_text) is types.StringType or \ if isinstance(element_text, basestring):
type(element_text) is types.UnicodeType:
if element_text[0] == u'$': # might be a hex number if element_text[0] == u'$': # might be a hex number
try: try:
val = int(element_text[1:], 16) val = int(element_text[1:], 16)

View File

@ -408,7 +408,7 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog):
def setBackground(self, background, gradient): def setBackground(self, background, gradient):
if background == 0: # Solid if background == 0: # Solid
self.theme.background_type = u'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.theme.background_color = u'#000000'
self.ImageLineEdit.setText(u'') self.ImageLineEdit.setText(u'')
elif background == 1: # Gradient elif background == 1: # Gradient
@ -419,9 +419,9 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog):
self.theme.background_direction = u'vertical' self.theme.background_direction = u'vertical'
else: else:
self.theme.background_direction = u'circular' 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' 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.theme.background_endColor = u'#ff0000'
self.ImageLineEdit.setText(u'') self.ImageLineEdit.setText(u'')
else: else:

View File

@ -74,7 +74,7 @@ class DisplayWidget(QtGui.QWidget):
QtCore.Qt.Key_Backspace: 'slidecontroller_live_previous_noloop'} QtCore.Qt.Key_Backspace: 'slidecontroller_live_previous_noloop'}
def keyPressEvent(self, event): def keyPressEvent(self, event):
if type(event) == QtGui.QKeyEvent: if isinstance(event, QtGui.QKeyEvent):
#here accept the event and do something #here accept the event and do something
if event.key() == QtCore.Qt.Key_Up: if event.key() == QtCore.Qt.Key_Up:
Receiver.send_message(u'slidecontroller_live_previous') Receiver.send_message(u'slidecontroller_live_previous')
@ -375,7 +375,7 @@ class VideoDisplay(Phonon.VideoWidget):
self.setVisible(False) self.setVisible(False)
def keyPressEvent(self, event): def keyPressEvent(self, event):
if type(event) == QtGui.QKeyEvent: if isinstance(event, QtGui.QKeyEvent):
#here accept the event and do something #here accept the event and do something
if event.key() == QtCore.Qt.Key_Escape: if event.key() == QtCore.Qt.Key_Escape:
self.onMediaStop() self.onMediaStop()

View File

@ -44,7 +44,7 @@ class ServiceManagerList(QtGui.QTreeWidget):
self.parent = parent self.parent = parent
def keyPressEvent(self, event): def keyPressEvent(self, event):
if type(event) == QtGui.QKeyEvent: if isinstance(event, QtGui.QKeyEvent):
#here accept the event and do something #here accept the event and do something
if event.key() == QtCore.Qt.Key_Enter: if event.key() == QtCore.Qt.Key_Enter:
self.parent.makeLive() self.parent.makeLive()
@ -918,7 +918,7 @@ class ServiceManager(QtGui.QWidget):
else: else:
#we are not over anything so drop #we are not over anything so drop
replace = False replace = False
if item == None: if item is None:
self.droppos = len(self.serviceItems) self.droppos = len(self.serviceItems)
else: else:
#we are over somthing so lets investigate #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'} QtCore.Qt.Key_Backspace: 'slidecontroller_live_previous_noloop'}
def keyPressEvent(self, event): def keyPressEvent(self, event):
if type(event) == QtGui.QKeyEvent: if isinstance(event, QtGui.QKeyEvent):
#here accept the event and do something #here accept the event and do something
if event.key() == QtCore.Qt.Key_Up: if event.key() == QtCore.Qt.Key_Up:
self.parent.onSlideSelectedPrevious() self.parent.onSlideSelectedPrevious()

View File

@ -438,7 +438,7 @@ class ThemeManager(QtGui.QWidget):
return newtheme.extract_xml() return newtheme.extract_xml()
def saveTheme(self, name, theme_xml, theme_pretty_xml, image_from, def saveTheme(self, name, theme_xml, theme_pretty_xml, image_from,
image_to) : image_to):
""" """
Called by thememaintenance Dialog to save the theme Called by thememaintenance Dialog to save the theme
and to trigger the reload of the theme list and to trigger the reload of the theme list

View File

@ -27,6 +27,7 @@ import logging
import os import os
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
from openlp.core.utils import AppLocation from openlp.core.utils import AppLocation
from openlp.core.lib import translate from openlp.core.lib import translate
@ -41,7 +42,7 @@ class LanguageManager(object):
@staticmethod @staticmethod
def get_translator(language): def get_translator(language):
if LanguageManager.AutoLanguage : if LanguageManager.AutoLanguage:
language = QtCore.QLocale.system().name() language = QtCore.QLocale.system().name()
lang_Path = AppLocation.get_directory(AppLocation.AppDir) lang_Path = AppLocation.get_directory(AppLocation.AppDir)
lang_Path = os.path.join(lang_Path, u'resources', u'i18n') lang_Path = os.path.join(lang_Path, u'resources', u'i18n')
@ -81,7 +82,7 @@ class LanguageManager(object):
def set_language(action): def set_language(action):
actionName = u'%s' % action.objectName() actionName = u'%s' % action.objectName()
qmList = LanguageManager.get_qm_list() qmList = LanguageManager.get_qm_list()
if LanguageManager.AutoLanguage : if LanguageManager.AutoLanguage:
language = u'[%s]' % qmList[actionName] language = u'[%s]' % qmList[actionName]
else: else:
language = u'%s' % qmList[actionName] language = u'%s' % qmList[actionName]
@ -106,7 +107,7 @@ class LanguageManager(object):
@staticmethod @staticmethod
def get_qm_list(): def get_qm_list():
if LanguageManager.__qmList__ == None: if LanguageManager.__qmList__ is None:
LanguageManager.init_qm_list() LanguageManager.init_qm_list()
return LanguageManager.__qmList__ return LanguageManager.__qmList__

View File

@ -242,7 +242,7 @@ class BibleCommon(object):
text = text.replace(u''', u'\'') text = text.replace(u''', u'\'')
# Remove some other tags # Remove some other tags
start_tag = text.find(u'<') start_tag = text.find(u'<')
while start_tag > -1 : while start_tag > -1:
end_tag = text.find(u'>', start_tag) end_tag = text.find(u'>', start_tag)
text = text[:start_tag] + text[end_tag + 1:] text = text[:start_tag] + text[end_tag + 1:]
start_tag = text.find(u'<') start_tag = text.find(u'<')
@ -260,10 +260,10 @@ def unescape(text):
""" """
def fixup(markup): def fixup(markup):
text = markup.group(0) text = markup.group(0)
if text[:2] == u'&#': if text.startswith(u'&#'):
# character reference # character reference
try: try:
if text[:3] == u'&#x': if text.startswith(u'&#x'):
return unichr(int(text[3:-1], 16)) return unichr(int(text[3:-1], 16))
else: else:
return unichr(int(text[2:-1])) return unichr(int(text[2:-1]))

View File

@ -184,7 +184,7 @@ class BGExtract(BibleCommon):
log.debug(u'init %s', proxyurl) log.debug(u'init %s', proxyurl)
self.proxyurl = 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 Access and decode bibles via the BibleGateway website

View File

@ -27,7 +27,7 @@ import logging
import sys import sys
import os import os
from types import StringType, ListType from types import ListType
sys.path.append(os.path.abspath(u'./../../../..')) sys.path.append(os.path.abspath(u'./../../../..'))
@ -417,9 +417,9 @@ class Song(object):
def _list_to_string(self, strOrList): def _list_to_string(self, strOrList):
"""Force a possibly list into a string""" """Force a possibly list into a string"""
if type(strOrList) == StringType: if isinstance(strOrList, basestring):
lst = self._split_to_list(strOrList) lst = self._split_to_list(strOrList)
elif type(strOrList) == ListType: elif isinstance(strOrList, ListType):
lst = strOrList lst = strOrList
elif strOrList is None: elif strOrList is None:
lst = [] lst = []

View File

@ -31,8 +31,9 @@
############################################################################### ###############################################################################
import os import os
from optparse import OptionParser
import urllib import urllib
from optparse import OptionParser
from PyQt4 import QtCore from PyQt4 import QtCore
ignore_pathes = [u"./scripts", u"./openlp/core/test"] ignore_pathes = [u"./scripts", u"./openlp/core/test"]
@ -62,8 +63,8 @@ def main():
# Set up command line options. # Set up command line options.
usage = u'Usage: %prog [options]' usage = u'Usage: %prog [options]'
parser = OptionParser(usage=usage) parser = OptionParser(usage=usage)
parser.add_option("-d", "--download-ts", action="store_true", dest="download", parser.add_option("-d", "--download-ts", action="store_true",
help="Load languages from Pootle Server") dest="download", help="Load languages from Pootle Server")
parser.add_option("-p", "--prepare", action="store_true", dest="prepare", 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", parser.add_option("-u", "--update", action="store_true", dest="update",
@ -90,7 +91,8 @@ def main():
def downloadTranslations(): def downloadTranslations():
print "download()" print "download()"
for language in translations: 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 print filename
page = urllib.urlopen(u"%s%s.ts" % (translation_path, language)) page = urllib.urlopen(u"%s%s.ts" % (translation_path, language))
content = page.read().decode("utf8") content = page.read().decode("utf8")
@ -115,13 +117,13 @@ def preparation():
for search in ignore_pathes: for search in ignore_pathes:
if path.startswith(search): if path.startswith(search):
cond = True cond = True
if cond == True: if cond:
continue continue
cond = False cond = False
for search in ignore_files: for search in ignore_files:
if search == file: if search == file:
cond = True cond = True
if cond == True: if cond:
continue continue
if file.endswith(u'.py'): if file.endswith(u'.py'):
@ -142,7 +144,6 @@ def preparation():
write_file(os.path.join(start_dir, u'openlp.pro'), stringlist) write_file(os.path.join(start_dir, u'openlp.pro'), stringlist)
print u'done.' print u'done.'
def update(): def update():
print "update()" print "update()"
updateProcess = QtCore.QProcess() updateProcess = QtCore.QProcess()