[pygtk] Window waits to complete code brfore show

Miki daily.cron at gmail.com
Tue Feb 27 04:37:28 WST 2007


Dear friends,
I'm newbie to python and pygtk, and I'm writing a simple network
application.
The application should show a window with a progress bar while the python
code using the os module to do a ping checks.

While I'm running the short program the window with simple label won't show
on the screen until the python finish all the code (after do the ping
checks).

Anyone know how could I show the window widget (and his content) in parallel
while the rest of the codeis running?

Here is my code (it also available here: http://www.shorttext.com/3u1gd)

#!/usr/bin/env python
#
#
#
import pygtk
pygtk.require('2.0')
import gtk
import os
import re


#Create simple gtk window with label
w =3D gtk.Window()
l =3D gtk.Label("pppp")
w.add(l)
w.show_all()

PINGIP=3DFalse #Set the PINGIP flag to false
ConnectionIP =3D False
ConnectionDNS =3D False

#Check Ping to IP Address and DNS function
def CheckPing(IP):
    global PINGIP
    command =3D 'ping -c 2 ' + IP
    w=3Dos.popen(command) #Make ping test in the OS level
    while (True):
        s=3Dw.readline()
        if re.search("ttl=3D",s):
            PINGIP =3D True # If the ping test results include "TTL" then
connection is alive
        if not s:
            break

CheckPing("212.143.162.141")
CheckPing("64.233.183.104")

# Connection to IP address is ok? do ping to host name
if PINGIP:
    ConnectionIP =3D True
    PINGIP=3DFalse
    CheckPing("www.nba.com")
    CheckPing("www.google.com")
    if PINGIP:
        ConnectionDNS =3D True

#Print the results
if ConnectionIP and ConnectionDNS:
    print "Connection is OK"
elif ConnectionIP:
    print "Only IP - no DNS"
else:
    print "No connection"

if __name__ =3D=3D "__main__":
    gtk.main()



Thanks,
Miki
daily.cron at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.daa.com.au/pipermail/pygtk/attachments/20070226/90f11636/at=
tachment.htm


More information about the pygtk mailing list