Skip to content

Commit

Permalink
update pep8 contrib, and fix all the last warning from "make style".
Browse files Browse the repository at this point in the history
  • Loading branch information
tito committed Aug 11, 2012
1 parent 8aeab85 commit 5d50999
Show file tree
Hide file tree
Showing 62 changed files with 1,730 additions and 719 deletions.
6 changes: 2 additions & 4 deletions kivy/__init__.py
Expand Up @@ -43,7 +43,7 @@


if platform() == 'macosx' and sys.maxint < 9223372036854775807:
r ='''Unsupported Python version detected!:
r = '''Unsupported Python version detected!:
Kivy requires a 64 bit version of Python to run on OS X. We strongly advise
you to use the version of Python that is provided by Apple (don't use ports,
fink or homebrew unless you know what you're doing).
Expand Down Expand Up @@ -112,7 +112,7 @@ def parse_version(version):
if tag == 'dev' and systag != 'dev':
Logger.warning('Application requested a -dev version of Kivy. '
'(You have %s, but the application requires %s)' % (
__version__, version))
__version__, version))
# not tag rev (-alpha-1, -beta-x) allowed.
if tagrev is not None:
raise Exception('Revision format must not contain any tagrevision')
Expand Down Expand Up @@ -273,7 +273,6 @@ def kivy_usage():
Logger.setLevel(level=level)
Logger.setLevel(level=LOG_LEVELS.get('debug'))


# Can be overrided in command line
if 'KIVY_UNITTEST' not in environ:

Expand All @@ -298,7 +297,6 @@ def kivy_usage():
opts = []
args = []


need_save = False
for opt, arg in opts:
if opt in ('-h', '--help'):
Expand Down
4 changes: 2 additions & 2 deletions kivy/atlas.py
Expand Up @@ -246,7 +246,7 @@ def create(outname, filenames, size, padding=1):
imw += padding
imh += padding
if imw > size or imh > size:
Logger.error('Atlas: image %s is larger than the atlas size!'%\
Logger.error('Atlas: image %s is larger than the atlas size!' %
imageinfo[0])
return

Expand Down Expand Up @@ -310,7 +310,7 @@ def create(outname, filenames, size, padding=1):
# as the uniq id.
uid = splitext(basename(fb[6]))[0]
x, y, w, h = fb[2:6]
d[uid] = x, size-y-h, w, h
d[uid] = x, size - y - h, w, h

outfn = '%s.atlas' % outname
with open(outfn, 'w') as fd:
Expand Down
2 changes: 1 addition & 1 deletion kivy/config.py
Expand Up @@ -290,7 +290,7 @@ def write(self):
if version != KIVY_CONFIG_VERSION and 'KIVY_NO_CONFIG' not in environ:
Logger.warning('Config: Older configuration version detected'
' (%d instead of %d)' % (
version, KIVY_CONFIG_VERSION))
version, KIVY_CONFIG_VERSION))
Logger.warning('Config: Upgrading configuration in progress.')
need_save = True

Expand Down
6 changes: 4 additions & 2 deletions kivy/core/audio/audio_gstreamer.py
Expand Up @@ -112,12 +112,14 @@ def _get_length(self):
self._data.set_state(gst.STATE_PLAYING)
try:
self._data.get_state()
return self._data.query_duration(gst.Format(gst.FORMAT_TIME))[0] / 1000000000.
return self._data.query_duration(gst.Format(
gst.FORMAT_TIME))[0] / 1000000000.
finally:
self._data.set_state(gst.STATE_NULL)
self._data.set_property('volume', volume_before)
else:
return self._data.query_duration(gst.Format(gst.FORMAT_TIME))[0] / 1000000000.
return self._data.query_duration(gst.Format
(gst.FORMAT_TIME))[0] / 1000000000.
return super(SoundGstreamer, self)._get_length()

SoundLoader.register(SoundGstreamer)
10 changes: 5 additions & 5 deletions kivy/core/image/__init__.py
Expand Up @@ -97,10 +97,10 @@ def have_mipmap(self):
return len(self.mipmaps) > 1

def __repr__(self):
return '<ImageData width=%d height=%d fmt=%s ' \
'source=%r with %d images>' % (
self.width, self.height, self.fmt,
self.source, len(self.mipmaps))
return ('<ImageData width=%d height=%d fmt=%s '
'source=%r with %d images>' % (
self.width, self.height, self.fmt,
self.source, len(self.mipmaps)))

def add_mipmap(self, level, width, height, data):
'''Add a image for a specific mipmap level.
Expand Down Expand Up @@ -662,7 +662,7 @@ def read_pixel(self, x, y):
assert data.fmt in ImageData._supported_fmts
size = 3 if data.fmt in ('rgb', 'bgr') else 4
index = y * data.width * size + x * size
raw = data.data[index:index+size]
raw = data.data[index:index + size]
color = map(lambda c: ord(c) / 255.0, raw)

# conversion for BGR->RGB, BGR->RGBA format
Expand Down
36 changes: 18 additions & 18 deletions kivy/core/image/img_gif.py
Expand Up @@ -65,7 +65,7 @@ def load(self, filename):
ls_height = im.ls_height
im_images = im.images
im_palette = im.palette
pixel_map = array('B', [0]*(ls_width*ls_height*4))
pixel_map = array('B', [0] * (ls_width * ls_height * 4))
for img in im_images:
palette = img.palette if img.local_color_table_flag\
else im_palette
Expand All @@ -74,7 +74,7 @@ def load(self, filename):
#draw_method_restore_previous = 1 \
# if img.draw_method == 'restore previous' else 0
draw_method_replace = 1 \
if ((img.draw_method == 'replace') or\
if ((img.draw_method == 'replace') or
(img.draw_method == 'restore background')) else 0
pixels = img.pixels
img_height = img.height
Expand Down Expand Up @@ -125,17 +125,17 @@ def load(self, filename):
continue
# this pixel isn't transparent
#doesn't have transparent color
(pixel_map[rgba_pos], pixel_map[rgba_pos + 1],\
pixel_map[rgba_pos + 2]) = (r, g, b)
(pixel_map[rgba_pos], pixel_map[rgba_pos + 1],
pixel_map[rgba_pos + 2]) = (r, g, b)
pixel_map[rgba_pos + 3] = 255
# if magic pink move to next pixel
rgba_pos += 4
i += 1

img_data_append(ImageData(ls_width, ls_height, \
img_data_append(ImageData(ls_width, ls_height,
'rgba', pixel_map.tostring()))
if draw_method_replace:
pixel_map = array('B', [0]*(ls_width*ls_height*4))
pixel_map = array('B', [0] * (ls_width * ls_height * 4))

self.filename = filename

Expand All @@ -160,7 +160,7 @@ class Gif(object):
LABEL_COMMENT = 0xFE
LABEL_PLAINTEXT = 0x01

FMT_EXT_GRAPHIC_CONTROL = '<BBHB' #89a
FMT_EXT_GRAPHIC_CONTROL = '<BBHB' # 89a

def __init__(self, data, debug):
self.data = data
Expand Down Expand Up @@ -319,7 +319,7 @@ def fill(self):
self.color_table_flag = self.flags[7]
self.sort_flag = self.flags[3]
#3 bit
self.color_resolution = pack_bits(self.flags[4:7]) # 7 not included
self.color_resolution = pack_bits(self.flags[4:7]) # 7 not included
#3 bit
self.global_color_table_size = 2 ** (pack_bits(self.flags[:3]) + 1)

Expand Down Expand Up @@ -351,7 +351,7 @@ def fill(self):
try:
nextbyte = self_pops('<B', self_data)[0]
except:
nextbyte = 0x3b # force end
nextbyte = 0x3b # force end

#20. Image Descriptor
if nextbyte == Gif_IMAGE_SEPARATOR:
Expand Down Expand Up @@ -383,8 +383,8 @@ def fill(self):
print 'LZW length:', len(image_lzwcode)

image.lzwcode = image_lzwcode
image.pixels = self_lzw_decode(image.lzwcode, image.codesize, \
table_size)
image.pixels = self_lzw_decode(image.lzwcode, image.codesize,
table_size)

# Extensions
elif nextbyte == Gif_EXTENSION_INTRODUCER:
Expand Down Expand Up @@ -439,8 +439,8 @@ def bits_to_int(self, bits):
i = 0
for bit in bits:
if bit:
i+= 2**(c-1)
c +=1
i += 2 ** (c - 1)
c += 1
return i

def get_color_table(self, size):
Expand All @@ -451,10 +451,10 @@ def get_color_table(self, size):
palette = []
palette_append = palette.append

while pos + 3 < (size+1):
while pos + 3 < (size + 1):
red = raw_color_table[pos]
green = raw_color_table[pos+1]
blue = raw_color_table[pos+2]
green = raw_color_table[pos + 1]
blue = raw_color_table[pos + 2]
palette_append((red, green, blue))
pos += 3
return palette
Expand All @@ -476,7 +476,7 @@ def lzw_decode(self, input, initial_codesize, color_table_size):
clearcode, end_of_info = color_table_size, color_table_size + 1

if Debug:
print 'codesize: %d' %codesize
print 'codesize: %d' % codesize
print 'clearcode %d, end_of_info: %d' % (clearcode, end_of_info)

def pop(size, _bits):
Expand Down Expand Up @@ -559,7 +559,7 @@ def get_bits(flags, reverse=False, bits=8):

mybits = (1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048)[:bits]

rev_num=1
rev_num = 1
if reverse:
rev_num = -1
ret = array('B')
Expand Down
6 changes: 3 additions & 3 deletions kivy/core/spelling/__init__.py
Expand Up @@ -95,7 +95,7 @@ def list_languages(self):
Return a list of all languages supported by the registered languages.
E.g.: ['en', 'en_GB', 'en_US', 'de', ...]
'''
raise NotImplementedError('list_languages() is not implemented ' + \
raise NotImplementedError('list_languages() is not implemented '
'by abstract spelling base class!')

def check(self, word):
Expand All @@ -109,7 +109,7 @@ def check(self, word):
If the word shouldn't be checked, return None (e.g. for '').
'''
raise NotImplementedError('check() not implemented by abstract ' + \
raise NotImplementedError('check() not implemented by abstract ' +
'spelling base class!')

def suggest(self, fragment):
Expand All @@ -124,7 +124,7 @@ def suggest(self, fragment):
E.g.: 'foo' might become 'of', 'food' or 'foot'.
'''
raise NotImplementedError('suggest() not implemented by abstract ' + \
raise NotImplementedError('suggest() not implemented by abstract ' +
'spelling base class!')


Expand Down
5 changes: 2 additions & 3 deletions kivy/core/text/__init__.py
Expand Up @@ -147,7 +147,7 @@ def register(name, fn_regular, fn_italic=None, fn_bold=None,
else:
fonts.append(font)
else:
fonts.append(fonts[-1]) # add regular font to list again
fonts.append(fonts[-1]) # add regular font to list again

LabelBase._fonts[name] = tuple(fonts)

Expand Down Expand Up @@ -211,7 +211,7 @@ def shorten(self, text, margin=2):
return u'{0}...{1}'.format(text[:segment].strip(),
text[-segment:].strip())
else:
segment = max_letters - 3 # length of '...'
segment = max_letters - 3 # length of '...'
return u'{0}...'.format(text[:segment].strip())

def render(self, real=False):
Expand Down Expand Up @@ -273,7 +273,6 @@ def render(self, real=False):
if not glyph in cache:
cache[glyph] = get_extents(glyph)


# Shorten the text that we actually display
text = self.text
if options['shorten'] and get_extents(text)[0] > uw:
Expand Down
3 changes: 1 addition & 2 deletions kivy/core/text/markup.py
Expand Up @@ -284,11 +284,10 @@ def _real_render(self):
# vertical alignement
if y == 0:
if av == 1:
y = int((h - txt_height)/2)
y = int((h - txt_height) / 2)
elif av == 2:
y = h - (txt_height)


for pw, ph, part, options in line[2]:
self.options = options
r(part, x, y + (lh - ph) / 1.25)
Expand Down
2 changes: 1 addition & 1 deletion kivy/core/text/text_pygame.py
Expand Up @@ -22,7 +22,7 @@
class LabelPygame(LabelBase):

def _get_font_id(self):
return '|'.join([unicode(self.options[x]) for x \
return '|'.join([unicode(self.options[x]) for x
in ('font_size', 'font_name_r', 'bold', 'italic')])

def _get_font(self):
Expand Down
6 changes: 3 additions & 3 deletions kivy/core/video/video_gstreamer.py
Expand Up @@ -52,8 +52,8 @@ def _on_gst_message(bus, message):
# log all error messages
if message.type == gst.MESSAGE_ERROR:
error, debug = map(str, message.parse_error())
Logger.error('gstreamer_video: %s'%error)
Logger.debug('gstreamer_video: %s'%debug)
Logger.error('gstreamer_video: %s' % error)
Logger.debug('gstreamer_video: %s' % debug)


def _on_gst_eos(obj, *largs):
Expand Down Expand Up @@ -119,7 +119,7 @@ def unload(self):
self._texture = None

def load(self):
Logger.debug('gstreamer_video: Load <%s>'% self._filename)
Logger.debug('gstreamer_video: Load <%s>' % self._filename)
self._playbin.set_state(gst.STATE_NULL)
self._playbin.set_property('uri', self._get_uri())
self._playbin.set_state(gst.STATE_READY)
Expand Down
4 changes: 2 additions & 2 deletions kivy/core/video/video_pyglet.py
Expand Up @@ -40,7 +40,7 @@ def unload(self):
self._fbo = None

def load(self):
self.unload() #make sure we unload an resources
self.unload() # make sure we unload an resources

#load media file and set size of video
self._source = source = pyglet.media.load(self._filename)
Expand All @@ -61,7 +61,7 @@ def load(self):
self.time = self._player.time

def _update(self, dt):
if self._source.duration - self.time < 0.1: #we are at the end
if self._source.duration - self.time < 0.1: # we are at the end
self.seek(0)
if self.state == 'playing':
# keep track of time into video
Expand Down
2 changes: 1 addition & 1 deletion kivy/core/window/window_pygame.py
Expand Up @@ -193,7 +193,7 @@ def on_keyboard(self, key,
is_osx = platform() == 'darwin'
if key == 27 or (is_osx and key in (113, 119) and modifier == 1024):
stopTouchApp()
self.close() #not sure what to do here
self.close() # not sure what to do here
return True
super(WindowPygame, self).on_keyboard(key, scancode,
codepoint=codepoint, modifier=modifier)
Expand Down
6 changes: 3 additions & 3 deletions kivy/ext/__init__.py
Expand Up @@ -238,13 +238,13 @@ def unzip_extensions():

already_unzipped = False
if extdir in files:
Logger.trace(("Extension '%s' has already been " % extname) + \
Logger.trace(("Extension '%s' has already been " % extname) +
"extracted manually, just moving the zip.")
already_unzipped = True

# Filter the namelist of zipfile to take only the members that start
# with the extension name (MyExt/...)
members = [x for x in zipf.namelist() \
members = [x for x in zipf.namelist()
if x.startswith(extname + '/')]

if not already_unzipped:
Expand All @@ -270,7 +270,7 @@ def unzip_extensions():
fd.write(zipf.read(member))
except Exception, e:
# Catch any error, e.g. non-writable directory, etc.
Logger.error("Failed installing extension " + \
Logger.error("Failed installing extension " +
"'%s' %s." % (extname, e))
return
finally:
Expand Down

0 comments on commit 5d50999

Please sign in to comment.