(PyGTK) Disabling ToolButton when no TreeView item is selected?

2006-12-28 Thread cypher543
I have a TreeView and a ToolButton. The ToolButton should only be
active if the user has selected an item in the TreeView. What signal
should I use to achieve this?

Thanks,
David

-- 
http://mail.python.org/mailman/listinfo/python-list


Starting a child process and getting its stdout?

2006-12-28 Thread cypher543
This has been driving me insane for the last hour or so. I have search
everywhere, and nothing works. I am trying to use the subprocess module
to run a program and get its output line by line. But, it always waits
for the process to terminate and then return the output all at once.

Can someone please show me some code that actually works for this sort
of thing? It doesn't even have to use the subprocess module. Don't
worry if the code isn't compatible with Windows. My program is targeted
at Linux/UNIX users.

Thanks!

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Starting a child process and getting its stdout?

2006-12-29 Thread cypher543
Thank you for the examples, but I have tried all of that before. No
matter what I do, my program always hangs while it waits for the
process to exit and then it prints all of the output at once. I've
tried read(), readline(), readlines(), communicate(), etc and it is
always the same.

self.buildPID = subprocess.Popen(["python", "tobeforked.py"], stdout =
subprocess.PIPE)
while self.buildPID.poll() == None:
output = self.buildPID.stdout.readline()
self.consoleLogBuffer.insert(self.consoleLogBuffer.get_end_iter(),
output)
self.consoleLog.scroll_to_mark(self.consoleLogBuffer.get_insert(), 0)

Keep in mind that I'm not required to use subprocess. But I have also
tried os.fork and the pty module. They both produce the exact same
results.

On Dec 29, 3:38 am, Tom Plunket <[EMAIL PROTECTED]> wrote:
> Tom Plunket wrote:
> >while p.poll() == None:
> >data = p.stdout.readline()
> >if data:
> >print data,If you change that print to something more 
> > decorated, like,
>
>print 'process said:', data,
>
> Then it might be more obvious where/how the print statements are getting
> routed.
>
> Keep in mind that readline() will return one line at a time, and that
> line will end with a newline, although the last line you get (at EOF)
> may not have one.
> 
> again, good luck.  Hope this helps,
> -tom!
> 
> --

-- 
http://mail.python.org/mailman/listinfo/python-list


Managing a queue of subprocesses?

2006-12-29 Thread cypher543
My app uses a "queue" of commands which are run one at a time. I am
using the subprocess module to execute the commands in the queue.
However, processes always run at the same time. How can I make one
process run at a time, and then execute the next process when the first
has terminated? My code is below:

self.cmdQueue = {}
self.queue(theProject.directory, "ls", "-l")
self.queue(theProject.directory, "echo", "hello, world!")

def consoleLogAddLine(self, text):
self.consoleLogBuffer.insert(self.consoleLogBuffer.get_end_iter(),
text)
self.consoleLog.scroll_to_mark(self.consoleLogBuffer.get_insert(), 0)

def onGetData(self, fd, cond, *args):
self.consoleLogAddLine(fd.readline())
return True

def queue(self, rootDir, cmd, args = ""):
count = len(self.cmdQueue) + 1
self.cmdQueue[count] = [cmd, args, rootDir]

def runQueue(self):
for i in self.cmdQueue.values():
self.execute(i[2], i[0], i[1])

def execute(self, rootDir, cmd, args = ""):
os.chdir(rootDir)
if args == "":
buildCmd = cmd
else:
args = args.split(" ")
buildCmd = [cmd] + args
self.buildPID = subprocess.Popen(buildCmd, stdout = subprocess.PIPE,
stderr = subprocess.STDOUT)
gobject.io_add_watch(self.buildPID.stdout, gobject.IO_IN,
self.onGetData)

As you can see, I add the commands "ls -l" and "echo Hello" to the
queue. However, "Hello" is always printed inside the output of "ls -l".
I would like to wait for "ls -l" to terminate and then run "echo
Hello". But, the output must still print to the consoleLogBuffer
line-by-line, and my GUI must not hang during execution.

Is this even possible?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Managing a queue of subprocesses?

2006-12-30 Thread cypher543
That was a very good answer, and it sure sounds like it would work.
However, I failed at implementing it. :( My updated runQueue() function
is:

def runQueue(self):
self.buildProcess = None
count = 1 # current position in the queue
while True:
if self.buildProcess is None:
self.execute(self.cmdQueue[count][2], 
self.cmdQueue[count][0],
self.cmdQueue[count][1])
count = count + 1
else:
# I'm not really sure what to put here

I pretty sure I did all of that wrong. ;) Also, how exactly would I
redirect stderr to another place?

On Dec 30, 12:22 am, Tom Plunket <[EMAIL PROTECTED]> wrote:
> cypher543 wrote:
> > self.buildPID = subprocess.Popen(buildCmd, stdout = subprocess.PIPE, stderr 
> > = subprocess.STDOUT)Instead of calling it self.buildPID, you might just 
> > call it
> self.buildProcess or something.  It's actually a Popen object that gets
> returned.
>
> So yes you can do what you want:
>
> __init__ self.buildProcess to None.  Then, in execute(), if
> (self.buildProcess is None) or (self.buildProcess.poll() is not None)
> start the next process.
>
> You've got to wait for one process to end before starting the next one,
> it's really that easy.  So, don't just go ahead and fire them all
> instantly.  Possibly what you want to do instead is have runQueue() do
> the check somehow that there's no active process running.
>
> What I would do, have runQueue() check to see if self.buildProcess is
> None.  If it is None, fire the next process in the queue.  If it isn't
> None, then check to see if it's ended.  If it has ended, then set
> self.buildProcess to None.  Next UI update the next step in the queue
> gets done.  Mind that you'll have to modify the queue as you go, e.g.
> self.queue = self.queue[1:].
>
> Finally, consider piping stderr separately, and direct its output to a
> different window in your GUI.  You could even make that window pop open
> on demand, if errors occur.
> 
> good luck,
> -tom!
> 
> --

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Starting a child process and getting its stdout?

2006-12-30 Thread cypher543
Yes, I did try your example. But, after talking on the #python IRC
channel, I realized that it wasn't the process that was blocking, it
was my GUI. I had to fire an event using gobject.io_add_watch()
whenever data was received from the child process. The event then read
from the process and added a line to my gtk.TextView.

Thank you for your suggestions, though.

On Dec 30, 12:12 am, Tom Plunket <[EMAIL PROTECTED]> wrote:
> Gabriel Genellina wrote:
> > Did you *actually* tried what Tom Plunket posted? Two tiny chars make
> > a difference.The sad irony is that before taking off for vacation I was 
> > struggling at
> work with the same problem in some sense.  I couldn't figure out why for
> some processes I got all of the output right away and for others it all
> got queued up 'til the process ended.  Working out a simple example for
> this thread showed the light: my calling of my_process.stdout.read() was
> blocking 'til EOF.  Oops.
> 
> -tom!
> 
> --

-- 
http://mail.python.org/mailman/listinfo/python-list