[wingide-users] Perplexed

Brian Rowlands (Greymouth High School) RowlandsB at greyhigh.school.nz
Sun Jun 27 15:52:37 MDT 2010


Hi Folks
New to both Wing IDE and Python and busily trying to get my head around
threads when I tried a simple example off the WWW.

It falls over in Wing IDE but the author assures me it works fine when
he tested it after I wrote to him. He had someone else test it and it
worked too on a windows platform ( which is what I'm using).

Wind IDE Personal doesn't report any errors.

Am I allowed to ask if someone could test it via their IDE and let me
know the results please?

If so, code is shown below.

Thanks

Brian

#!/usr/bin/env python
#-*- coding:utf-8 -*-
# By Chris Oliver <chris at excid3.com>
# Adapted from
http://www.pygtk.org/pygtk2tutorial/examples/helloworld.py
 
 
import pygtk
pygtk.require("2.0")
 
import gobject
import gtk
gtk.gdk.threads_init()
 
import threading
 
 
class HelloWorld:
    def __init__(self):
        """
            Initializes the GTK application, in our case, create the
window
            and other widgets
        """
 
        # Create a window
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.set_border_width(10)
 
        # Setup the application to exit GTK when the window is closed
        self.window.connect("destroy", self.destroy)
 
        # Create a button
        self.button = gtk.Button("Hello World")
 
        # Make the button call self.hello() when it is clicked
        self.button.connect("clicked", self.hello_helper)
 
        # Add the button into the window
        self.window.add(self.button)
 
        # Display the button and the window
        self.button.show()
        self.window.show()
 
 
    def hello(self, widget, data=None):
        import time
        time.sleep(25)
        print "Hello"
 
 
    def hello_helper(self, widget, data=None):
        print "starting new thread"
        threading.Thread(target=self.hello, args=(widget, data)).start()
 
    def main(self):
        """
            This function starts GTK drawing the GUI and responding to
events
            like button clicks
        """
 
        gtk.main()
 
 
    def destroy(self, widget, data=None):
        """
            This function exits the application when the window is
closed.
            Without this the GTK main thread would continue running
while no
            interface would be displayed. We want the application to
exit when
            the window is closed, so we tell the GTK loop to stop so we
can
            quit.
        """
 
        gtk.main_quit()
 
 
if __name__ == "__main__":
    # Create an instance of our GTK application
    app = HelloWorld()
    app.main() 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/wingide-users/attachments/20100628/52aed028/attachment.html


More information about the wingide-users mailing list