Skip to content

Commit

Permalink
Fix examples/ PEP8 errors. Mostly white space.
Browse files Browse the repository at this point in the history
This fixes a large number of white space errors in the examples/
directory.
When I upgraded Makefile to check the 'make style' on the examples
directory,
the output was hundreds of lines long.   Currently, the output is
managable
and consists solely of "lines too long", as kv lines cannot be split.
This
commit touches an obscene number of files in trivial ways.
  • Loading branch information
merriam committed Feb 2, 2015
1 parent fdb9ce4 commit 02c30a4
Show file tree
Hide file tree
Showing 61 changed files with 412 additions and 308 deletions.
6 changes: 3 additions & 3 deletions examples/3Drendering/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
3Drendering Example
=================
This example demonstrates using OpenGL to display rotating monkey head. This
This example demonstrates using OpenGL to display rotating monkey head. This
includes loading a Blender OBJ file, shaders written in OpenGL's Shading
Language (GLSL), and using scheduled callbacks.
The file monkey.obj is a OBJ file output form the Blender free 3D creation
software. The file is text, listing vertices and faces. It is loaded
into a scene using objloader.py's ObjFile class. The file simple.glsl is
software. The file is text, listing vertices and faces. It is loaded
into a scene using objloader.py's ObjFile class. The file simple.glsl is
a simple vertex and fragment shader written in GLSL.
'''

Expand Down
8 changes: 5 additions & 3 deletions examples/RST_Editor/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import os


class LoadDialog(FloatLayout):
load = ObjectProperty(None)
cancel = ObjectProperty(None)
Expand All @@ -28,12 +29,14 @@ def dismiss_popup(self):

def show_load(self):
content = LoadDialog(load=self.load, cancel=self.dismiss_popup)
self._popup = Popup(title="Load file", content=content, size_hint=(0.9, 0.9))
self._popup = Popup(title="Load file", content=content,
size_hint=(0.9, 0.9))
self._popup.open()

def show_save(self):
content = SaveDialog(save=self.save, cancel=self.dismiss_popup)
self._popup = Popup(title="Save file", content=content, size_hint=(0.9, 0.9))
self._popup = Popup(title="Save file", content=content,
size_hint=(0.9, 0.9))
self._popup.open()

def load(self, path, filename):
Expand All @@ -52,7 +55,6 @@ def save(self, path, filename):
class Editor(App):
pass


Factory.register('Root', cls=Root)
Factory.register('LoadDialog', cls=LoadDialog)
Factory.register('SaveDialog', cls=SaveDialog)
Expand Down
3 changes: 1 addition & 2 deletions examples/android/compass/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
./build.py --package org.test.compass --name compass \
--private ~/code/kivy/examples/android/compass \
--window --version 1.0 debug installd
'''


Expand Down Expand Up @@ -47,7 +46,7 @@ def update_compass(self, *args):
(x, y, z) = Hardware.magneticFieldSensorReading()

# calculate the angle
needle_angle = Vector(x , y).angle((0, 1)) + 90.
needle_angle = Vector(x, y).angle((0, 1)) + 90.

# animate the needle
if self._anim:
Expand Down
13 changes: 6 additions & 7 deletions examples/android/takepicture/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
PythonActivity = autoclass('org.renpy.android.PythonActivity')
MediaStore = autoclass('android.provider.MediaStore')
Uri = autoclass('android.net.Uri')
Environment = autoclass('android.os.Environment')
Environment = autoclass('android.os.Environment')


class Picture(Scatter):
Expand All @@ -50,10 +50,10 @@ def build(self):
def get_filename(self):
while True:
self.index += 1
fn = Environment.getExternalStorageDirectory().getPath()+'/takepicture{}.jpg'.format(self.index)
fn = (Environment.getExternalStorageDirectory().getPath() +
'/takepicture{}.jpg'.format(self.index))
if not exists(fn):
return fn


def take_picture(self):
intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
Expand All @@ -62,19 +62,18 @@ def take_picture(self):
self.uri = cast('android.os.Parcelable', self.uri)
intent.putExtra(MediaStore.EXTRA_OUTPUT, self.uri)
PythonActivity.mActivity.startActivityForResult(intent, 0x123)

def on_activity_result(self, requestCode, resultCode, intent):
if requestCode == 0x123:
Clock.schedule_once(partial(self.add_picture, self.last_fn), 0)

def add_picture(self, fn, *args):
im = Image.open(fn)
width, height = im.size
im.thumbnail( (width/4,height/4) , Image.ANTIALIAS)
im.save(fn,quality=95)
im.thumbnail((width / 4, height / 4), Image.ANTIALIAS)
im.save(fn, quality=95)
self.root.add_widget(Picture(source=fn, center=self.root.center))


def on_pause(self):
return True

Expand Down
2 changes: 1 addition & 1 deletion examples/animation/animate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
================
This example demonstrates creating and applying a multi-part animation to
a button widget. You should see a button labelled 'plop' that will move with
a button widget. You should see a button labelled 'plop' that will move with
an animation when clicked.
'''

Expand Down
44 changes: 27 additions & 17 deletions examples/application/app_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
Application Suite
=================
Explore how applications start. Starts applications one after another, waiting for
each to be closed first.
Explore how applications start. Starts applications one after another,
waiting for each to be closed first.
'''
from __future__ import print_function
import sys
import re
from random import choice

import kivy
kivy.require('1.8.0') # Minimum API as 1.8 is when kv_directory became part of app.
kivy.require('1.8.0') # 1.8 is when kv_directory became part of app.
from kivy.app import App
from kivy.uix.button import Button
from kivy.lang import Builder
Expand All @@ -21,6 +21,7 @@
# starting up the Logger and some other messages.
print("** In main program, done with imports")


class TestBuildApp(App):
""" Use build() function to return a widget. """
def build(self):
Expand All @@ -31,38 +32,47 @@ def build(self):
print("** inside build()")
return Button(text='hello from TestBuildApp')

class TestKVFileApp(App):
""" Empty class, but name used to find .kv file.
The filename is the lowercase version of the class, i.e.,
'testkvfileapp.kv'. If not found, it strips off the final 'app', i.e.,
'testkvfile.kv'.

If not file is found, and no other method sets the self.root, the program will
run with an empty screen. """
class TestKVFileApp(App):
"""
Empty class, but name used to find .kv file. The filename is the lowercase
version of the class, i.e., 'testkvfileapp.kv'. If not found, it strips
off the final 'app', i.e., 'testkvfile.kv'. If not file is found, and no
other method sets the self.root, the program will run with an empty screen.
"""
pass


class TestKVDirApp(App):
""" Empty class except for setting class variable kv_directory.
"""
Empty class except for setting class variable kv_directory.
This directory sets the directory in which to search for the .kv file.
The name of the kv file is still governed by the class name and the .kv
file should still have one root widget. """
file should still have one root widget.
"""
kv_directory = 'app_suite_data'


class TestKVStringApp(App):
""" Use a build() function and use the kivy.lang.Builder function to parse up a
Kivy language string. """
"""
Use a build() function and use the kivy.lang.Builder function to parse up a
Kivy language string.
"""
def build(self):
""" Called by kivy run(). """
print("** inside build()")
widget = Builder.load_string("Button:\n text: 'hello from TestKVStringApp'")
widget = Builder.load_string(
"Button:\n text: 'hello from TestKVStringApp'")
print("** widget built")
return widget


class TestPrebuiltApp(App):
""" Use the Builder to create a top level widget at the beginning
of the Python program, then use a dummy class for that widget.
This costs a bit more in start-up time. """
Builder.load_string("<Prebuilt>\n Button:\n text:'hello from TestPrebuiltApp'")
kv = "<Prebuilt>\n Button:\n text:'hello from TestPrebuiltApp'"
Builder.load_string(kv)
print("** in TestPrebuiltApp, class initialization built <Prebuilt>")

class Prebuilt(FloatLayout):
Expand All @@ -81,7 +91,7 @@ def print_class(class_name):
with open(filename) as f:
data = f.read()
regex = "^(class " + class_name + "\\b.*?)^\\S"
match = re.search(regex, data, flags=re.MULTILINE|re.DOTALL)
match = re.search(regex, data, flags=re.MULTILINE | re.DOTALL)
if match:
print(match.group(1))

Expand Down
6 changes: 3 additions & 3 deletions examples/audio/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
Audio example
=============
This example plays sounds of different formats. You should see a grid of
buttons labelled with filenames. Clicking on the buttons will play, or
restart, each sound. Not all sound formats will play on all platforms.
This example plays sounds of different formats. You should see a grid of
buttons labelled with filenames. Clicking on the buttons will play, or
restart, each sound. Not all sound formats will play on all platforms.
All the sounds are from the http://woolyss.com/chipmusic-samples.php
"THE FREESOUND PROJECT", Under Creative Commons Sampling Plus 1.0 License.
Expand Down
4 changes: 2 additions & 2 deletions examples/camera/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
Camera Example
==============
This example demonstrates a simple use of the camera. It shows a window with
a buttoned labelled 'play' to turn the camera on and off. Note that
This example demonstrates a simple use of the camera. It shows a window with
a buttoned labelled 'play' to turn the camera on and off. Note that
not finding a camera, perhaps because gstreamer is not installed, will
throw an exception during the kv language processing.
Expand Down
11 changes: 6 additions & 5 deletions examples/canvas/bezier.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
Bezier Example
==============
This example shows a closed Bezier curve computed from a polygon. You
This example shows a closed Bezier curve computed from a polygon. You
should see a purple polygon, a red bezier curve computed from the polygon,
and two sliders. You can drag points on the polygon to recompute the curve.
and two sliders. You can drag points on the polygon to recompute the curve.
The two sliders control the dash length of the dashed lines making up the two
shapes.
Expand Down Expand Up @@ -37,7 +37,7 @@ def __init__(self, points=[], loop=False, *args, **kwargs):

Color(1.0, 0.0, 1.0)
self.line = Line(
points=self.points+self.points[:2],
points=self.points + self.points[:2],
dash_offset=10,
dash_length=100)

Expand All @@ -61,8 +61,9 @@ def _set_line_dash_offset(self, instance, value):

def on_touch_down(self, touch):
if self.collide_point(touch.pos[0], touch.pos[1]):
for i, p in enumerate(list(zip(self.points[::2], self.points[1::2]))):
if ( abs(touch.pos[0] - self.pos[0] - p[0]) < self.d and
for i, p in enumerate(list(zip(self.points[::2],
self.points[1::2]))):
if (abs(touch.pos[0] - self.pos[0] - p[0]) < self.d and
abs(touch.pos[1] - self.pos[1] - p[1]) < self.d):
self.current_point = i + 1
return True
Expand Down
4 changes: 2 additions & 2 deletions examples/canvas/canvas_stress.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
=============
This example tests the performance of our Graphics engine by drawing large
numbers of small sqaures. You should see a black canvas with buttons and a
label at the bottom. Pressing the buttons adds small colored squares to the
numbers of small sqaures. You should see a black canvas with buttons and a
label at the bottom. Pressing the buttons adds small colored squares to the
canvas.
'''
Expand Down
12 changes: 6 additions & 6 deletions examples/canvas/circle.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
Circle Example
==============
This example exercises circle (ellipse) drawing. You should see sliders at the
top of the screen with the Kivy logo below it. The sliders control the
angle start and stop and the height and width scales. There is a button
to reset the sliders. The entire example is coded in the
This example exercises circle (ellipse) drawing. You should see sliders at the
top of the screen with the Kivy logo below it. The sliders control the
angle start and stop and the height and width scales. There is a button
to reset the sliders. The entire example is coded in the
kv language description.
'''

Expand Down Expand Up @@ -60,9 +60,8 @@
Button:
text: 'Reset ratios'
on_press: wm.value = 1; hm.value = 1
FloatLayout:
canvas:
Color:
rgb: 1, 1, 1
Expand All @@ -75,6 +74,7 @@
'''


class CircleApp(App):
def build(self):
return Builder.load_string(kv)
Expand Down
8 changes: 4 additions & 4 deletions examples/canvas/fbo_canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
==========
This demonstrates a layout using an FBO (Frame Buffer Off-screen)
instead of a plain canvas. You should see a black canvas with a
button labelled 'FBO' in the bottom left corner. Clicking it
instead of a plain canvas. You should see a black canvas with a
button labelled 'FBO' in the bottom left corner. Clicking it
animates the button moving right to left.
'''

Expand Down Expand Up @@ -34,7 +34,7 @@ def __init__(self, **kwargs):
self.fbo_rect = Rectangle()

with self.fbo:
ClearColor(0,0,0,0)
ClearColor(0, 0, 0, 0)
ClearBuffers()

# wait that all the instructions are in the canvas to set texture
Expand Down Expand Up @@ -79,7 +79,7 @@ def build(self):

def anim_btn(*args):
if b.pos[0] == 0:
Animation(x=f.width-b.width).start(b)
Animation(x=f.width - b.width).start(b)
else:
Animation(x=0).start(b)
b.bind(on_press=anim_btn)
Expand Down
4 changes: 2 additions & 2 deletions examples/canvas/lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
============================
This demonstrates the experimental and unfinished SmoothLine feature
for fast line drawing. You should see a multi-segment
for fast line drawing. You should see a multi-segment
path at the top of the screen, and sliders and buttons along the bottom.
You can click to add new points to the segment, change the transparency
and width of the line, or hit 'Animate' to see a set of sine and cosine
animations. The Cap and Joint buttons don't work: SmoothLine has not
animations. The Cap and Joint buttons don't work: SmoothLine has not
implemented these features yet.
'''

Expand Down
Loading

0 comments on commit 02c30a4

Please sign in to comment.