Piet van Oostrum wrote:
>>>>>> sreekant <[EMAIL PROTECTED]> (S) wrote:
> 
>> S> I decided in the end to use fork and all is well.
> 
> But how are you doing the callback then? From your code it looks like the
> callback is called after the external command finishes. The callback would
> then be called in the child process, not in the parent process, I think. Or
> do you have a solution for that?
I am not calling the callback now.

It is a pygtk interface to octavia music description language I wrote. I 
have a button "Play" which reads the text in the gtk.TextView , converts 
it to midi and calls fluidsynth with the resulting midi file.

I want the ui to be accessible during the midi play because, the midi 
play can some times be a long piece of music.

I also have a log window which is another textview. I was loading the 
result of

res=os.popen3(my_command)
report=res[1].read()+'\n'+res[2].read()
logwindow gets the report added to it.

However now I just put a message saying "playing midi"

I don't know any way out at the moment.

################

What I need is when I click on the play button, the fileplay(widget) 
function that gets called should be able to start a new thread or a fork 
which executes the commands and updates the ui.logwindow which is a 
textview with the output of os.popen3.

During the execution the ui should be usable.

Please see the scala program in this package 
http://sourceforge.net/projects/octavia . Checkout fileplay() function 
in the most latest version 0.22 .

I don't want to attach the whole program to this message and annoy everyone.

Below is the function causing probs.

Ta
sree

###############################


def fileplay(x):
     global conf,bdir,bgplay
     lbuf.delete(lbuf.get_start_iter(),lbuf.get_end_iter())
     dat=buf.get_text(buf.get_start_iter(),buf.get_end_iter())
     if not len(dat)>0:
         return

     #see if the temporary dir to save temp gmc and midi exists
     #if not create it
     tempf=bdir+os.sep+'temp'+os.sep
     try:
         if not os.path.exists(tempf):
             os.mkdir(tempf)
     except:
         addlog(traceback.format_exc())
         return
     #save octavia in to a count+1 text file
     if os.path.exists(tempf):
         try:
             fbase=tempf+getcnt()
             fmidi=fbase+'.midi'
             f=open(fbase,'w')
             f.write(dat)
             f.close()
         except:
             addlog(traceback.format_exc())
     #run octavia
     addlog("Compiling to midi")
     if conf.has_key('octavia'):
         text2midi=conf['octavia']
     else:
         addlog("Config doesn't exist. Trying default octavia")
         text2midi='octavia'
     try:
         res=os.popen3(text2midi+' '+fbase+' '+fmidi)
         addlog(res[1].read()+res[2].read())
     except:
         addlog(traceback.format_exc())
         return
     # if midi exists, we succeded. play midi
     if os.path.exists(fmidi):
         addlog("Trying to play midi")
         if conf.has_key('midiplayer'):
             midiplay=conf['midiplayer']
         else:
             addlog("Config doesn't exist. Trying default timidity")
             midiplay='timidity'

         # start playing in a fork
         pid=os.fork()
         if pid:
             pass
         else:
             os.popen3(midiplay+' '+fmidi)
             sys.exit(0)
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to