forked from openlp/openlp
PEP8 type checking and cleanups
This commit is contained in:
parent
5bd60d1fd4
commit
0b1621923a
@ -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:
|
||||
|
@ -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):
|
||||
@ -531,9 +531,9 @@ class Renderer(object):
|
||||
"""
|
||||
# setup defaults
|
||||
if footer:
|
||||
font = self.footerFont
|
||||
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.
|
||||
|
||||
|
@ -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.
|
||||
|
@ -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)
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
|
||||
@ -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__
|
||||
|
||||
|
@ -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]))
|
||||
|
@ -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 = []
|
||||
|
@ -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,8 +63,8 @@ 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)")
|
||||
parser.add_option("-u", "--update", action="store_true", dest="update",
|
||||
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user