After having googeled all afternoon I give up and start this thread. I have a commandline python script which I want to turn into a nautilus script. This requires that the script at some point uses a popup window to print a message instead of printing in the shell. The code was as follows:
PHP Code:
if ip_addr:
print "Now serving on http://%s:%s/" % (ip_addr, httpd.server_port)
I changed that successfully to
PHP Code:
if ip_addr:
os.system('zenity --info --text="Now serving on http://%s:%s/"' % (ip_addr, httpd.server_port))
So far so good. Now comes the tricky part. I want a window that enables me to cancel the script or approve. This would mean a zenity --queston window, with a 'cancel' and a 'ok' button. In zenity 'cancel' returns the value '1', and 'ok' returns the value '0'. But how do I tell the script to react on these buttons? 'Cancel' would mean 'sys.exit ()' and 'ok' would mean 'continue'. I checked loads of documentation on the subprocess possibility (which seems to have replaced the os.popen command) but I don't understand how it works or how to have it interact with a window. Who helps me out? It doesn't have to be with zenity by the way. A gtk-window or whatever comes standard with Ubuntu is also ok.
Bookmarks