You are not logged in.

#1 2007-11-21 22:21:10

spookykid
Member
From: Portugal
Registered: 2006-07-23
Posts: 141

python GTK dialog script

Hi all, I'm in the process of writing a dialog for GTK using python, I already have all the functionality I need but I have a small problem. When I press a button on the dialog window to call an external program as Firefox the dialog becomes unresponsive until I close Firefox. I'd like to be able to call Firefox and still be able to call Exaile without having to close Firefox. Any suggestions?
Here is the code:

#!/usr/bin/env python
# -*- coding: UTF-8 -*-

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# Code written by spookykid for UTOPIA Desktop
# spookykid.contact@gmail.com

import pygtk
pygtk.require("2.0")
import sys, gtk, gtk.glade, os, os.path, gobject

f_name =".utopia.rc" #Preferences file

filename = os.path.expanduser( os.path.join( "~/.config", f_name ) )  #If preferences file exists
if os.path.exists(filename) == 1:
    quit ()

#-----------------------------------------------

def do_exit (action): #quit program
    gtk.main_quit ()

def do_browser (action): #run Firefox
    os.system('firefox www.utopia.org &')

def do_appearances (action): #run gnome-appearance-properties
    os.system('gnome-appearance-properties ')

def do_music (action): #run exaile
    os.system('exaile')

def do_check (action): #if user wants to run this next time
    if checkbutton.get_active() == 1:
        os.remove(filename)
    else:
        FILE = open(filename,"w")
        FILE.writelines("WELCOME_SCREEN=1")
        FILE.close()

#-----------------------------------------------

xml = gtk.glade.XML ('/usr/bin/welcome.glade', None, None)

#-----------------------------------------------

window = xml.get_widget ('window')    
button_close = xml.get_widget ('button_close')
checkbutton = xml.get_widget ('checkbutton')
button_internet = xml.get_widget ('button_internet')
button_music = xml.get_widget ('button_music')
button_appearances = xml.get_widget ('button_appearances')

#-----------------------------------------------

button_close.connect ("clicked", do_exit)
checkbutton.connect ("toggled", do_check)
button_internet.connect ("clicked", do_browser)
button_appearances.connect ("clicked", do_appearances)
button_music.connect ("clicked", do_music)

#-----------------------------------------------

window.connect ("destroy", do_exit)
window.show_all ()
gtk.main ()

Tank you. smile


There is no knowledge that is not power!

Offline

#2 2007-11-21 22:26:02

drakosha
Member
Registered: 2006-01-03
Posts: 253
Website

Re: python GTK dialog script

Strange, but adding '&' in the end works for me:

>>> os.system('emacs')

- interpreter is stuck

>>> os.system('emacs &')

- returns immediately

Offline

#3 2007-11-21 22:38:49

spookykid
Member
From: Portugal
Registered: 2006-07-23
Posts: 141

Re: python GTK dialog script

LOOLL, I've reached the same conclusion as it's treated like a bash command. But thank you for your help. wink


There is no knowledge that is not power!

Offline

#4 2007-11-22 09:24:42

kumico
Member
Registered: 2007-09-28
Posts: 224
Website

Re: python GTK dialog script

the new recommended way of running external processes is to use module: subprocess
http://docs.python.org/lib/module-subprocess.html

Offline

#5 2007-11-22 15:10:30

abhidg
Member
From: City of Kol
Registered: 2006-07-01
Posts: 184
Website

Re: python GTK dialog script

i use something like this:

import os

os.spawnvp(os.P_NOWAIT,"programname",["","arg1","arg2",...]) # argn are the command line arguments to program.
Here, P_NOWAIT acts like the & in in os.system().

Offline

Board footer

Powered by FluxBB