Convert print statements to print function

Use print_function from __futures__ and covert print statements to
function calls for later use in Python 3.  Also, clean up minor
verbiage.
This commit is contained in:
Charles Merriam 2014-12-13 12:15:00 -08:00
parent 029796c42e
commit 40e930bfcc
1 changed files with 17 additions and 16 deletions

View File

@ -5,7 +5,7 @@ Application Suite
Explore how applications start. Starts applications one after another, waiting for Explore how applications start. Starts applications one after another, waiting for
each to be closed first. each to be closed first.
''' '''
from __future__ import print_function
import sys import sys
import re import re
from random import choice from random import choice
@ -19,7 +19,7 @@ from kivy.lang import Builder
from kivy.uix.floatlayout import FloatLayout from kivy.uix.floatlayout import FloatLayout
# Note that importing FloatLayout causes Kivy to execute, including # Note that importing FloatLayout causes Kivy to execute, including
# starting up the Logger and some other messages. # starting up the Logger and some other messages.
print "** In main program, done with imports" print("** In main program, done with imports")
class TestBuildApp(App): class TestBuildApp(App):
""" Use build() function to return a widget. """ """ Use build() function to return a widget. """
@ -28,7 +28,7 @@ class TestBuildApp(App):
Called after trying to load a .kv file. Called after trying to load a .kv file.
Returns a new Button as a root widget. Returns a new Button as a root widget.
""" """
print "** inside build()" print("** inside build()")
return Button(text='hello from TestBuildApp') return Button(text='hello from TestBuildApp')
class TestKVFileApp(App): class TestKVFileApp(App):
@ -53,9 +53,9 @@ class TestKVStringApp(App):
Kivy language string. """ Kivy language string. """
def build(self): def build(self):
""" Called by kivy run(). """ """ Called by kivy run(). """
print "** inside build()" 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" print("** widget built")
return widget return widget
class TestPrebuiltApp(App): class TestPrebuiltApp(App):
@ -63,7 +63,7 @@ class TestPrebuiltApp(App):
of the Python program, then use a dummy class for that widget. of the Python program, then use a dummy class for that widget.
This costs a bit more in start-up time. """ This costs a bit more in start-up time. """
Builder.load_string("<Prebuilt>\n Button:\n text:'hello from TestPrebuiltApp'") Builder.load_string("<Prebuilt>\n Button:\n text:'hello from TestPrebuiltApp'")
print "** in TestPrebuiltApp, class initialization built <Prebuilt>" print("** in TestPrebuiltApp, class initialization built <Prebuilt>")
class Prebuilt(FloatLayout): class Prebuilt(FloatLayout):
""" Empty class to cause setting root to <Prebuilt> tag and """ Empty class to cause setting root to <Prebuilt> tag and
@ -83,14 +83,14 @@ def print_class(class_name):
regex = "^(class " + class_name + "\\b.*?)^\\S" 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: if match:
print match.group(1) print(match.group(1))
# the __name__ idiom executes when run from command line but not from import. # the __name__ idiom executes when run from command line but not from import.
if __name__ == '__main__': if __name__ == '__main__':
dash = "-" * 40 dash = "-" * 40
arg = sys.argv[1][0].lower() if len(sys.argv) > 1 else "h" arg = sys.argv[1][0].lower() if len(sys.argv) > 1 else "h"
print dash print(dash)
if arg == 'r': if arg == 'r':
arg = choice('bfds') arg = choice('bfds')
@ -111,22 +111,23 @@ if __name__ == '__main__':
print_class("TestPrebuiltApp") print_class("TestPrebuiltApp")
TestPrebuiltApp().run() TestPrebuiltApp().run()
else: # help else: # help
print """ print("""
This demo runs different application windows based on a command line argument. This demo runs different application windows based on a command line argument.
Try using one of these: Try using one of these:
b - Use build() method to return a widget b - Use build() method to return a widget
d - Use a kv file from a different directory d - Use a kv file from a different directory
f - Use a kv file with the widget object f - Use a kv file with the widget object
s - Use a kiva language string to create the widget. p - Use prebuilt widget inside a layout
p - Use prebuilt widget from a kivy string s - Use a kiva language string to create the widget
r - pick one of the demos at random. r - pick one of the demos at random.
h - show this help message. h - show this help message.
After closing the application window, this program will exit. While the run() method After closing the application window, this program will exit.
does return, kivy cannot run another application. While the run() method does return, kivy cannot run another
""" application window after one has been closed.
""")
print dash print(dash)
print "This program is gratified to be of use." print("This program is gratified to be of use.")