You are not logged in.
Pages: 1
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.
There is no knowledge that is not power!
Offline
Strange, but adding '&' in the end works for me:
>>> os.system('emacs')
- interpreter is stuck
>>> os.system('emacs &')
- returns immediately
Offline
LOOLL, I've reached the same conclusion as it's treated like a bash command. But thank you for your help.
There is no knowledge that is not power!
Offline
the new recommended way of running external processes is to use module: subprocess
http://docs.python.org/lib/module-subprocess.html
Offline
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
Pages: 1