summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorJohan Dahlin <johan@src.gnome.org>2004-07-28 15:53:18 +0000
committerJohan Dahlin <johan@src.gnome.org>2004-07-28 15:53:18 +0000
commit144597af0772f77da25bbc4182ad024d15939f6d (patch)
tree5df2ee33a447374a1eecfe3ab2b35e0c9351508b /examples
parent35c11dd8a12e5c5835551b0735017713965bc619 (diff)
downloadpygtk-144597af0772f77da25bbc4182ad024d15939f6d.tar.gz
pep-8
Diffstat (limited to 'examples')
-rw-r--r--examples/pygtk-demo/demos/images.py107
1 files changed, 54 insertions, 53 deletions
diff --git a/examples/pygtk-demo/demos/images.py b/examples/pygtk-demo/demos/images.py
index b6ab1b78..e6cc7cb7 100644
--- a/examples/pygtk-demo/demos/images.py
+++ b/examples/pygtk-demo/demos/images.py
@@ -1,4 +1,4 @@
-#! /usr/bin/python2.3
+#!/usr/bin/env python
#
# Copyright (C) 2004 Joey Tsai <joeytsai@joeytsai.com>
#
@@ -16,6 +16,7 @@
# License along with this library; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
+
"""Images
GtkImage is used to display an image; the image can be in a number of formats.
@@ -23,36 +24,36 @@ Typically, you load an image into a GdkPixbuf, then display the pixbuf.
This demo code shows some of the more obscure cases, in the simple case a call
to gtk.Image's set_from_file() is all you need.
-
"""
import sys
-import pygtk; pygtk.require("2.0")
+import pygtk
+pygtk.require("2.0")
+
import gobject
import gtk
description = "Images"
-
-def error_dialog( message, parent=None ):
- dialog = gtk.MessageDialog( parent,
+def error_dialog(message, parent=None):
+ dialog = gtk.MessageDialog(parent,
gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
- gtk.MESSAGE_WARNING, gtk.BUTTONS_OK, message )
+ gtk.MESSAGE_WARNING, gtk.BUTTONS_OK, message)
dialog.run()
dialog.destroy()
-def on_timeout( loader, fileobject ):
+def on_timeout(loader, fileobject):
run_again = True
try:
- bytes = fileobject.read( 256 )
- loader.write( bytes )
+ bytes = fileobject.read(256)
+ loader.write(bytes)
except (IOError, gobject.GError), e:
- error_dialog( str(e) )
+ error_dialog(str(e))
run_again = False
- if bytes == "":
+ if not bytes:
run_again = False
if not run_again:
@@ -65,36 +66,36 @@ def on_timeout( loader, fileobject ):
return run_again
-def on_area_prepared( loader, image ):
+def on_area_prepared(loader, image):
pixbuf = loader.get_pixbuf()
- image.set_from_pixbuf( pixbuf )
+ image.set_from_pixbuf(pixbuf)
-def on_area_updated( loader, x, y, w, h, image ):
+def on_area_updated(loader, x, y, w, h, image):
image.queue_draw()
-def get_progressive_image( filename ):
+def get_progressive_image(filename):
try:
- fileobject = file( filename, "r" )
+ fileobject = open(filename, "r")
except IOError, e:
- error_dialog( str(e) )
- return None
+ error_dialog(str(e))
+ return
image = gtk.Image()
loader = gtk.gdk.PixbufLoader()
- loader.connect( "area_prepared", on_area_prepared, image )
- loader.connect( "area_updated", on_area_updated, image )
+ loader.connect("area_prepared", on_area_prepared, image)
+ loader.connect("area_updated", on_area_updated, image)
- gobject.timeout_add( 150, on_timeout, loader, fileobject )
+ gobject.timeout_add(150, on_timeout, loader, fileobject)
return image
-def get_image( filename ):
+def get_image(filename):
try:
- anim = gtk.gdk.PixbufAnimation( filename )
+ anim = gtk.gdk.PixbufAnimation(filename)
except gobject.GError, e:
- error_dialog( str(e) )
- return None
+ error_dialog(str(e))
+ return
image = gtk.Image()
@@ -105,54 +106,54 @@ def get_image( filename ):
return image
-def align_image( image, label_text ):
+def align_image(image, label_text):
label = gtk.Label()
- label.set_markup( "<u>%s</u>" % label_text )
+ label.set_markup("<u>%s</u>" % label_text)
frame = gtk.Frame()
- frame.set_shadow_type( gtk.SHADOW_IN )
+ frame.set_shadow_type(gtk.SHADOW_IN)
if image:
- frame.add( image )
+ frame.add(image)
else:
- frame.add( gtk.Label("(No image)") )
+ frame.add(gtk.Label("(No image)"))
- align = gtk.Alignment( 0.5, 0.5, 0, 0 )
- align.add( frame )
+ align = gtk.Alignment(0.5, 0.5, 0, 0)
+ align.add(frame)
- vbox = gtk.VBox( spacing=8 )
- vbox.set_border_width( 4 )
- vbox.pack_start( label )
- vbox.pack_start( align )
+ vbox = gtk.VBox(spacing=8)
+ vbox.set_border_width(4)
+ vbox.pack_start(label)
+ vbox.pack_start(align)
return vbox
-def on_button_toggled( button, vbox ):
+def on_button_toggled(button, vbox):
for widget in vbox.get_children():
if widget != button:
- widget.set_sensitive( not button.get_active() )
+ widget.set_sensitive(not button.get_active())
def main():
vbox = gtk.VBox()
- button = gtk.ToggleButton( "_Insensitive" )
- button.connect( "toggled", on_button_toggled, vbox )
+ button = gtk.ToggleButton("_Insensitive")
+ button.connect("toggled", on_button_toggled, vbox)
- i1 = get_image( "gtk-logo-rgb.gif" )
- i2 = get_image( "floppybuddy.gif" )
- i3 = get_progressive_image( "alphatest.png" )
+ i1 = get_image("gtk-logo-rgb.gif")
+ i2 = get_image("floppybuddy.gif")
+ i3 = get_progressive_image("alphatest.png")
- vbox.pack_start( align_image(i1, "Image loaded from a file") )
- vbox.pack_start( align_image(i2, "Animation loaded from a file") )
- vbox.pack_start( align_image(i3, "Progressive image loading") )
- vbox.pack_start( button )
+ vbox.pack_start(align_image(i1, "Image loaded from a file"))
+ vbox.pack_start(align_image(i2, "Animation loaded from a file"))
+ vbox.pack_start(align_image(i3, "Progressive image loading"))
+ vbox.pack_start(button)
win = gtk.Window()
- win.set_title( "Images" )
- win.set_border_width( 8 )
- win.connect( "destroy", lambda w: gtk.main_quit() )
- win.add( vbox )
+ win.set_title("Images")
+ win.set_border_width(8)
+ win.connect("destroy", gtk.main_quit)
+ win.add(vbox)
win.show_all()
gtk.main()
@@ -160,4 +161,4 @@ def main():
return 0
if __name__ == "__main__":
- sys.exit( main() )
+ sys.exit(main())