Re: [pygtk] Show command output (new IEs4Linux GUI)

2006-12-08 Thread Brian
On Fri, 2006-08-12 at 13:41 +, Ed Catmur wrote:
> Brian wrote: 
> > On Fri, 2006-08-12 at 03:38 -0200, Internet Explorer Linux wrote: 
> > > Hey, thank you guys! 
> > > I decided to do it with threads. See how it looks now: 
> > > tatanka.com.br/ies4linux/news
> > 
> > I just looked at your source.  You are not using threads.  you only
> > are 
> > initiating gtk to allow threads.  The threads.enter() and leave() 
> > functions are not needed in your code as is as all that code is
> > running 
> > in the main thread anyway.   You have not imported and used the
> > threads 
> > or threading modules that actually run the code in another thread.
> > As 
> > Edward Catmur said. If you can do it without threads, it can save a
> > lot 
> > of heartache if you don't get it right.
> > 
> > 
> 
> Nah, the threading module is imported (and the spawn/watch thread
> created) in ies4linux.py; the gtkgui file is just a module for
> constructing the gui. 
> 
> I really don't approve of the implied threading semantics, and
> reiterate that the non-threaded solution is always technically
> superior (especially in languages like Python with advanced control
> flow inversion abilities), but other than that the coding is competent
> enough for the chosen solution; it should work as intended. 
> 
> 
> Ed
> 
Sorry :(  So much for a quick look late at night when I should have gone
to bed.  I never looked at that other file.  I was also looking at it
with my own preconceived notion of what it should look like.  We got
away from the threads.enter() leave() pair long ago as it is too hard to
keep straight when a program is more complex with lots of sources for
initiating callbacks, etc..

-- 
Brian <[EMAIL PROTECTED]>

___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Show command output (new IEs4Linux GUI)

2006-12-08 Thread Ed Catmur

Brian wrote:

On Fri, 2006-08-12 at 03:38 -0200, Internet Explorer Linux wrote:

Hey, thank you guys!
I decided to do it with threads. See how it looks now:
tatanka.com.br/ies4linux/news


I just looked at your source.  You are not using threads.  you only are
initiating gtk to allow threads.  The threads.enter() and leave()
functions are not needed in your code as is as all that code is running
in the main thread anyway.   You have not imported and used the threads
or threading modules that actually run the code in another thread.  As
Edward Catmur said. If you can do it without threads, it can save a lot
of heartache if you don't get it right.


Nah, the threading module is imported (and the spawn/watch thread created) 
in ies4linux.py; the gtkgui file is just a module for constructing the gui. 

I really don't approve of the implied threading semantics, and reiterate 
that the non-threaded solution is always technically superior (especially in 
languages like Python with advanced control flow inversion abilities), but 
other than that the coding is competent enough for the chosen solution; it 
should work as intended. 


Ed
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Show command output (new IEs4Linux GUI)

2006-12-08 Thread Brian
On Fri, 2006-08-12 at 03:38 -0200, Internet Explorer Linux wrote:
> Hey, thank you guys!
> I decided to do it with threads. See how it looks now:
> tatanka.com.br/ies4linux/news

I just looked at your source.  You are not using threads.  you only are
initiating gtk to allow threads.  The threads.enter() and leave()
functions are not needed in your code as is as all that code is running
in the main thread anyway.   You have not imported and used the threads
or threading modules that actually run the code in another thread.  As
Edward Catmur said. If you can do it without threads, it can save a lot
of heartache if you don't get it right.
-- 
Brian <[EMAIL PROTECTED]>

___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Show command output (new IEs4Linux GUI)

2006-12-07 Thread Internet Explorer Linux

Hey, thank you guys!
I decided to do it with threads. See how it looks now:
tatanka.com.br/ies4linux/news

On 12/1/06, Edward Catmur <[EMAIL PROTECTED]> wrote:


On Thu, 2006-11-30 at 04:14 -0200, Internet Explorer Linux wrote:
> I'm working on a pygtk user interface to my script. My GUI configures
> some things and run an executable (IEs4linux installer, written in
> bash). I need to open some kind of window to show the installer
> output.
>
> I tried with TextView, but I don't know how to make it non-blocking. I
> tried with Threads, but it waits until installer finishes to show the
> output on TextView. I searched on Google and got some pages talking
> about this (even with "solutions"), but I could not make it work.

You need to tie the fd (from your child's stdout) into the GLib
mainloop.  The way to do this is to make it nonblocking and add a watch
on it; your watch callback then adds the data that appears on the fd to
the textview.

Obviously threads would work as well, but if you can write your
application single-threaded it'll save a load of heartache debugging
races when you get the reentrancy and locking wrong.

Here's a fairly comprehensive example; I put it together to demonstrate
watching the output of a DVD burning script, but it's obviously
applicable to your situation.

Ed

#!/usr/bin/env python

import gobject, gtk, sys, os, fcntl

def get_stock_icons(widget, id):
set = widget.style.lookup_icon_set(id)
return map(lambda x: set.render_icon(widget.style,
gtk.TEXT_DIR_NONE,
gtk.STATE_NORMAL, x, widget, None), set.get_sizes())

class LogWindow:
def input_callback(self, source, condition):
if condition & (gobject.IO_HUP):
self.eof()
return False
try:
while True:
line = source.readline()
print line.__repr__()
if line == '':
self.eof()
return False
self.append_text(line)
except IOError:
pass
return True

def eof(self):
self.ok.set_sensitive(True)
self.cancel.set_sensitive(False)
self.warn.hide()

def append_text(self, text):
end_iter = self.buffer.get_end_iter()
endmark = self.buffer.create_mark(None, end_iter)
self.textview.move_mark_onscreen(endmark)
at_end = self.buffer.get_iter_at_mark
(endmark).equal(end_iter)
self.buffer.insert(end_iter, text)
if at_end:
endmark = self.buffer.create_mark(None, end_iter)
self.textview.scroll_mark_onscreen(endmark)

def delete_event(self, widget, data = None):
self.warn.show_all()
return True

def destroy(self, widget, data = None):
gtk.main_quit()

def expanded(self, widget, param_spec, data = None):
if widget.get_expanded():
self.window.set_resizable(True)
else:
self.window.set_resizable(False)

def response(self, widget, response_id, data = None):
if response_id == gtk.RESPONSE_OK:
self.destroy(widget)
elif response_id == gtk.RESPONSE_CANCEL:
self.delete_event(widget)

def __init__(self, source):
# make source non-blocking
fd = source.fileno()
fcntl.fcntl(fd, fcntl.F_SETFL,
fcntl.fcntl(fd, fcntl.F_GETFL) |
os.O_NONBLOCK)
gobject.io_add_watch(source,
gobject.IO_IN | gobject.IO_PRI |
gobject.IO_HUP,
self.input_callback)

window = gtk.MessageDialog(buttons = gtk.BUTTONS_OK_CANCEL
)
for x in window.action_area.get_children():
if x.get_use_stock():
if x.get_label() == gtk.STOCK_OK:
self.ok = x
elif x.get_label() == gtk.STOCK_CANCEL:
self.cancel = x
self.ok.set_sensitive(False)
window.set_markup(
"""The files are being burnt to DVD.

Please wait while the process completes.""")
window.set_title("Burning DVD")
gtk.window_set_default_icon_list(
*get_stock_icons(window, gtk.STOCK_CDROM))
window.connect("delete_event", self.delete_event)
window.connect("destroy", self.destroy)
window.connect("response", self.response)

Re: [pygtk] Show command output (new IEs4Linux GUI)

2006-12-01 Thread Edward Catmur
On Thu, 2006-11-30 at 04:14 -0200, Internet Explorer Linux wrote:
> I'm working on a pygtk user interface to my script. My GUI configures
> some things and run an executable (IEs4linux installer, written in
> bash). I need to open some kind of window to show the installer
> output. 
> 
> I tried with TextView, but I don't know how to make it non-blocking. I
> tried with Threads, but it waits until installer finishes to show the
> output on TextView. I searched on Google and got some pages talking
> about this (even with "solutions"), but I could not make it work. 

You need to tie the fd (from your child's stdout) into the GLib
mainloop.  The way to do this is to make it nonblocking and add a watch
on it; your watch callback then adds the data that appears on the fd to
the textview.

Obviously threads would work as well, but if you can write your
application single-threaded it'll save a load of heartache debugging
races when you get the reentrancy and locking wrong.

Here's a fairly comprehensive example; I put it together to demonstrate
watching the output of a DVD burning script, but it's obviously
applicable to your situation.

Ed

#!/usr/bin/env python

import gobject, gtk, sys, os, fcntl

def get_stock_icons(widget, id):
set = widget.style.lookup_icon_set(id)
return map(lambda x: set.render_icon(widget.style, gtk.TEXT_DIR_NONE,
gtk.STATE_NORMAL, x, widget, None), set.get_sizes())

class LogWindow:
def input_callback(self, source, condition):
if condition & (gobject.IO_HUP):
self.eof()
return False
try:
while True:
line = source.readline()
print line.__repr__()
if line == '':
self.eof()
return False
self.append_text(line)
except IOError:
pass
return True

def eof(self):
self.ok.set_sensitive(True)
self.cancel.set_sensitive(False)
self.warn.hide()

def append_text(self, text):
end_iter = self.buffer.get_end_iter()
endmark = self.buffer.create_mark(None, end_iter)
self.textview.move_mark_onscreen(endmark)
at_end = self.buffer.get_iter_at_mark(endmark).equal(end_iter)
self.buffer.insert(end_iter, text)
if at_end:
endmark = self.buffer.create_mark(None, end_iter)
self.textview.scroll_mark_onscreen(endmark)

def delete_event(self, widget, data = None):
self.warn.show_all()
return True

def destroy(self, widget, data = None):
gtk.main_quit()

def expanded(self, widget, param_spec, data = None):
if widget.get_expanded():
self.window.set_resizable(True)
else:
self.window.set_resizable(False)

def response(self, widget, response_id, data = None):
if response_id == gtk.RESPONSE_OK:
self.destroy(widget)
elif response_id == gtk.RESPONSE_CANCEL:
self.delete_event(widget)

def __init__(self, source):
# make source non-blocking
fd = source.fileno()
fcntl.fcntl(fd, fcntl.F_SETFL, 
fcntl.fcntl(fd, fcntl.F_GETFL) | os.O_NONBLOCK)
gobject.io_add_watch(source, 
gobject.IO_IN | gobject.IO_PRI | gobject.IO_HUP,
self.input_callback)

window = gtk.MessageDialog(buttons = gtk.BUTTONS_OK_CANCEL)
for x in window.action_area.get_children():
if x.get_use_stock():
if x.get_label() == gtk.STOCK_OK:
self.ok = x
elif x.get_label() == gtk.STOCK_CANCEL:
self.cancel = x
self.ok.set_sensitive(False)
window.set_markup( 
"""The files are being burnt to DVD.

Please wait while the process completes.""")
window.set_title("Burning DVD")
gtk.window_set_default_icon_list(
*get_stock_icons(window, gtk.STOCK_CDROM))
window.connect("delete_event", self.delete_event)
window.connect("destroy", self.destroy)
window.connect("response", self.response)
self.window = window

warn = gtk.MessageDialog(parent = window,
flags = gtk.DIALOG_MODAL,
 

Re: [pygtk] Show command output (new IEs4Linux GUI)

2006-11-29 Thread Brian
On Thu, 2006-30-11 at 04:14 -0200, Internet Explorer Linux wrote:
> Hi everybody!
> 
> This is my first email to this list. My name is Sergio and I'm
> IEs4Linux project's main developer (maybe someone use my program :-)
> 
> I'm working on a pygtk user interface to my script. My GUI configures
> some things and run an executable (IEs4linux installer, written in
> bash). I need to open some kind of window to show the installer
> output. 
> 
> I tried with TextView, but I don't know how to make it non-blocking. I
> tried with Threads, but it waits until installer finishes to show the
> output on TextView. I searched on Google and got some pages talking
> about this (even with "solutions"), but I could not make it work. 
> 
> So, if anyone can help me with this thing I will be very thankful :-)
> 
> Sérgio Lopes
> From Brazil

You can check out our installer gui app.  The terminal is all python and
does compiler message filtering, etc.  There are 2 main areas that you
should look at for how we handle the textview updates.

1) in terminal/terminal.py update() where we process the text and update
the relevant textview buffers.

2) in readers/process_reader.py  which reads the virtual terminal output
(in a thread) and passes it back to the main gui for processing.

There are other ways of handling it as well, but that one works well for
us.  If you look around you will also find out how to autoscroll the
text as it is added, among other things.

The link: http://porthole.cvs.sourceforge.net/porthole/trunk/


-- 
Brian <[EMAIL PROTECTED]>

___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


[pygtk] Show command output (new IEs4Linux GUI)

2006-11-29 Thread Internet Explorer Linux

Hi everybody!

This is my first email to this list. My name is Sergio and I'm IEs4Linux
project's main developer (maybe someone use my program :-)

I'm working on a pygtk user interface to my script. My GUI configures some
things and run an executable (IEs4linux installer, written in bash). I need
to open some kind of window to show the installer output.

I tried with TextView, but I don't know how to make it non-blocking. I tried
with Threads, but it waits until installer finishes to show the output on
TextView. I searched on Google and got some pages talking about this (even
with "solutions"), but I could not make it work.

So, if anyone can help me with this thing I will be very thankful :-)

Sérgio Lopes

From Brazil
___
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/