[pygtk] X server exiting how to catch

2006-11-08 Thread Mike Bernson
I am trying to trap 2 condition

1 When the xserver dies (connection lost)
Is there any way to trap this condition from python ?
I have a number of task that are running I want them to die
when the xserver dies and the application see it. There is also
some cleanup I would like to do.

2 When the user logs off.
Looking for session management Any pointers under python ?
___
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] Unresponsive Window with commands.getstatusoutput

2006-11-08 Thread Christopher Bland

>> I've read a bunch of threads and such online but I'm having a hard time
>> wrapping my brain around this one...
>> 
>> I have an app that makes a call to commands.getstatusoutput(...) and
>> the system call (dd to image a drive) takes a LONG time. Obviously this
>> is blocking any/all GTK calls and the window never gets refreshed so
>> the user things that the app froze and then closes it.
>> 
>> I have a progress bar which I set to pulse during this operation so the
>> user gets some warm-fuzzy that it is working but that obviously doesn't
>> work.
>> 
>> Has anyone done anything similar to this and gotten the window to be
>> semi-responsive? I've been working on this for a few weeks and it's
>> killing me. Any input would be much appreciated. Thanks!

>I've used threads for all of these situations. The thread would execute
>the long running program letting the "main thread" process the event
>loop.

What I ended up doing was using the popen2.Popen4 command and kept
polling it to see if it was complete. That solved my problem.

[code]
fd = popen2.Popen4('dd if=/dev/sda of=/path/to/file.bin')
while fd.poll() == -1:
refresDisp()

# more processing once dd is done.
[/code]

Thanks for the input! Hopefully this snippet could help others in the
future.

>> 
>> Here are some lines in from my code (I am not using threading either):
>> 
>> mygui.py
>> import moreCode
>> 
>> def progress_time out(pbobj):
>> # increment the progress bar and do some other things
>> return True
>> 
>> class MyGUI:
>> def __init__(self):
>> # all of my initialization code to get the GUI up
>> self.timer = gobject.timeout_add(100, progress_timeout, self)
>> self.window.show_all()
>> 
>> def main(self):
>> gtk.main()
>> 
>> def startWork(self, widget, data=None):
>> # This gets called when the user clicks a 'Start' button
>> moreCode.doStuffNow()
>> 
>> if __name__ == '__main__':
>> gui = MyGUI()
>> gui.main()
>> 
>> moreCode.py
>> import commands
>> def doStuffNow:
>> # This is where the bulk of my processing is done
>> # including the call to image my drive.
>> out = commands.getstatusoutput('dd if=/dev/abc
>> of=/my/path/image.bin, conv=notrunc,noerror,sync')
>> return
>> 
>> 
>> 
>>



Try Juno Platinum for Free! Then, only $9.95/month!
Unlimited Internet Access with 1GB of Email Storage.
Visit http://www.juno.com/value to sign up today!


___
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] Unresponsive Window with commands.getstatusoutput

2006-11-08 Thread Stephen Kennedy

I have an app that makes a call to commands.getstatusoutput(...) and
the system call (dd to image a drive) takes a LONG time. Obviously this
is blocking any/all GTK calls and the window never gets refreshed so
the user things that the app froze and then closes it.


Hi Christopher, as you know the problem is that getstatusoutput blocks
the event loop.

You have basically two options. 1) use threads 2) use nonblocking i/o.
I'm not a fan of threads for pygtk apps so I'll explain 2.

Use the subprocess module to open a pipe to the child.
Set the pipe to nonblocking (fcntl module)
Use gobject.io_add_watch to register a callback whenever there is data available
Depending on what you're reading, you may accumulate the input or
process it bit by bit.

Good luck,
Stephen.
___
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] Unresponsive Window with commands.getstatusoutput

2006-11-08 Thread Steve McClure
On Wed, 2006-11-08 at 19:34 +, Christopher Bland wrote:
> I've read a bunch of threads and such online but I'm having a hard time
> wrapping my brain around this one...
> 
> I have an app that makes a call to commands.getstatusoutput(...) and
> the system call (dd to image a drive) takes a LONG time. Obviously this
> is blocking any/all GTK calls and the window never gets refreshed so
> the user things that the app froze and then closes it.
> 
> I have a progress bar which I set to pulse during this operation so the
> user gets some warm-fuzzy that it is working but that obviously doesn't
> work.
> 
> Has anyone done anything similar to this and gotten the window to be
> semi-responsive? I've been working on this for a few weeks and it's
> killing me. Any input would be much appreciated. Thanks!

I've used threads for all of these situations. The thread would execute
the long running program letting the "main thread" process the event
loop.

> 
> Here are some lines in from my code (I am not using threading either):
> 
> mygui.py
> import moreCode
> 
> def progress_time out(pbobj):
> # increment the progress bar and do some other things
> return True
> 
> class MyGUI:
> def __init__(self):
> # all of my initialization code to get the GUI up
> self.timer = gobject.timeout_add(100, progress_timeout, self)
> self.window.show_all()
> 
> def main(self):
> gtk.main()
> 
> def startWork(self, widget, data=None):
> # This gets called when the user clicks a 'Start' button
> moreCode.doStuffNow()
> 
> if __name__ == '__main__':
> gui = MyGUI()
> gui.main()
> 
> moreCode.py
> import commands
> def doStuffNow:
> # This is where the bulk of my processing is done
> # including the call to image my drive.
> out = commands.getstatusoutput('dd if=/dev/abc
> of=/my/path/image.bin, conv=notrunc,noerror,sync')
> return
> 
> 
> 
> 
> Try Juno Platinum for Free! Then, only $9.95/month!
> Unlimited Internet Access with 1GB of Email Storage.
> Visit http://www.juno.com/value to sign up today!
> 
> 
> ___
> 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/
-- 
Steve McClure Racemi
email: [EMAIL PROTECTED]380 Interstate North Pkwy, SE
voice: 404-892-5850   Suite 250
fax: 404-892-7215 Atlanta, GA 30339
  http://www.racemi.com

___
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] Having problems using gtk.CellRendererCombo

2006-11-08 Thread John Wood

Thank you for your response. (Sorry Kim for not replying to the list,
it was my intention, I will be more alert in the future :))

I got the code working almost the way I wanted. The only thing is that
I the actual widget is not visible. Is this the expected behavior? I
was under the impression that I would have a gtk.ComboBox in each of
the cells in the TreeViewColumn.

I include the current version of the sample program to show the "quirk".

#!/usr/bin/env python
import sys

try:
  import pygtk
  pygtk.require("2.6")
except:
  pass

try:
  import gtk, gobject
except:
  sys.exit(1)

class CellRendererExample:
  """ Main class of the application. """

  items = ("item 1",
   "item 2",
   "item 3",
   "item 4",
   "item 5")

  def __init__(self):
  # Create window and connect its destroy signal.
  window = gtk.Window()
  window.connect("destroy", gtk.main_quit)

  # Create and add a treeview widget to the window.
  self.treeview = gtk.TreeView()
  window.add(self.treeview)

  # Create a text column
  column0 = gtk.TreeViewColumn("Text",
gtk.CellRendererText(),
text=0)

  # Create a combobox column
  lsmodel = gtk.ListStore(str)

  for item in self.items:
  lsmodel.append([item])

  cellcombo = gtk.CellRendererCombo()

  cellcombo.set_property("text-column", 0)
  cellcombo.set_property("editable", True)
  cellcombo.set_property("has-entry", False)
  cellcombo.set_property("model", lsmodel)

  cellcombo.connect("edited", self.cellcombo_edited)

  column1 = gtk.TreeViewColumn("Combobox", cellcombo, text=1)

  self.treeview.append_column(column0)
  self.treeview.append_column(column1)

  # Create liststore.
  liststore = gtk.ListStore(str, str)

  # Append a couple of rows.
  liststore.append(["Some text", "Click here to select an item."])
  liststore.append(["More text", "Click here to select an item."])
  liststore.append(["More text", "Click here to select an item."])
  liststore.append(["More text", "Click here to select an item."])
  liststore.append(["More text", "Click here to select an item."])

  # Set model.
  self.treeview.set_model(liststore)

  window.show_all()

  def cellcombo_edited(self, cellrenderertext, path, new_text):
  treeviewmodel = self.treeview.get_model()
  iter = treeviewmodel.get_iter(path)
  treeviewmodel.set_value(iter, 1, new_text)

  def main(self):
  gtk.main()

if __name__ == "__main__":
  cre = CellRendererExample()
  cre.main()
___
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] Unresponsive Window with commands.getstatusoutput

2006-11-08 Thread Christopher Bland
I've read a bunch of threads and such online but I'm having a hard time
wrapping my brain around this one...

I have an app that makes a call to commands.getstatusoutput(...) and
the system call (dd to image a drive) takes a LONG time. Obviously this
is blocking any/all GTK calls and the window never gets refreshed so
the user things that the app froze and then closes it.

I have a progress bar which I set to pulse during this operation so the
user gets some warm-fuzzy that it is working but that obviously doesn't
work.

Has anyone done anything similar to this and gotten the window to be
semi-responsive? I've been working on this for a few weeks and it's
killing me. Any input would be much appreciated. Thanks!

Here are some lines in from my code (I am not using threading either):

mygui.py
import moreCode

def progress_time out(pbobj):
# increment the progress bar and do some other things
return True

class MyGUI:
def __init__(self):
# all of my initialization code to get the GUI up
self.timer = gobject.timeout_add(100, progress_timeout, self)
self.window.show_all()

def main(self):
gtk.main()

def startWork(self, widget, data=None):
# This gets called when the user clicks a 'Start' button
moreCode.doStuffNow()

if __name__ == '__main__':
gui = MyGUI()
gui.main()

moreCode.py
import commands
def doStuffNow:
# This is where the bulk of my processing is done
# including the call to image my drive.
out = commands.getstatusoutput('dd if=/dev/abc
of=/my/path/image.bin, conv=notrunc,noerror,sync')
return




Try Juno Platinum for Free! Then, only $9.95/month!
Unlimited Internet Access with 1GB of Email Storage.
Visit http://www.juno.com/value to sign up today!


___
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] Having problems using gtk.CellRendererCombo

2006-11-08 Thread Kim Novak

Please respond to the list.

The combobox only shows up when you click on the cell to edit it. If you 
are expecting to see an arrow icon in each cell that is a combo box you 
won't, I think that would get pretty messy and am glad it is not there.


John Wood wrote:

Thank you for your response.

I got the code working almost the way I wanted. The only thing is that
I the actual widget is not visible. Is this the expected behavior? I
was under the impression that I would have a gtk.ComboBox in each of
the cells in the TreeViewColumn.

I include the current version of the sample program to show the "quirk".

#!/usr/bin/env python
import sys

try:
   import pygtk
   pygtk.require("2.6")
except:
   pass

try:
   import gtk, gobject
except:
   sys.exit(1)

class CellRendererExample:
   """ Main class of the application. """

   items = ("item 1",
"item 2",
"item 3",
"item 4",
"item 5")

   def __init__(self):
   # Create window and connect its destroy signal.
   window = gtk.Window()
   window.connect("destroy", gtk.main_quit)

   # Create and add a treeview widget to the window.
   self.treeview = gtk.TreeView()
   window.add(self.treeview)

   # Create a text column
   column0 = gtk.TreeViewColumn("Text",
 gtk.CellRendererText(),
 text=0)

   # Create a combobox column
   lsmodel = gtk.ListStore(str)

   for item in self.items:
   lsmodel.append([item])

   cellcombo = gtk.CellRendererCombo()

   cellcombo.set_property("text-column", 0)
   cellcombo.set_property("editable", True)
   cellcombo.set_property("has-entry", False)
   cellcombo.set_property("model", lsmodel)

   cellcombo.connect("edited", self.cellcombo_edited)

   column1 = gtk.TreeViewColumn("Combobox", cellcombo, text=1)

   self.treeview.append_column(column0)
   self.treeview.append_column(column1)

   # Create liststore.
   liststore = gtk.ListStore(str, str)

   # Append a couple of rows.
   liststore.append(["Some text", "Click here to select an item."])
   liststore.append(["More text", "Click here to select an item."])
   liststore.append(["More text", "Click here to select an item."])
   liststore.append(["More text", "Click here to select an item."])
   liststore.append(["More text", "Click here to select an item."])

   # Set model.
   self.treeview.set_model(liststore)

   window.show_all()

   def cellcombo_edited(self, cellrenderertext, path, new_text):
   treeviewmodel = self.treeview.get_model()
   iter = treeviewmodel.get_iter(path)
   treeviewmodel.set_value(iter, 1, new_text)

   def main(self):
   gtk.main()

if __name__ == "__main__":
   cre = CellRendererExample()
   cre.main()

2006/11/6, Kim Novak <[EMAIL PROTECTED]>:

The CellRendererCombo needs to be editable. The drop-down will only
appear when you click on the cell.

cellcombo.set_property("editable", True)

John Wood wrote:
> Hello,
>
> I'm having a hard time using a gtk.CellRendererCombo in my treeview
> widget. The problem is that the combobox widget won't show. I've read
> the pygtk reference a number times and the I get no errors executing
> my code. I've created a small sample program which illustrates my
> problem.
>
> Any help is much appreciated, if someone can point me to a pygtk
> program that uses gtk.CellRendererCombo that would be great.
>
> John
>
> #!/usr/bin/env python
> import sys
>
> try:
>import pygtk
>pygtk.require("2.6")
> except:
>pass
>
> try:
>import gtk
> except:
>sys.exit(1)
>
> class CellRendererExample:
>""" Main class of the application. """
>
>def __init__(self):
># Create window and connect its destroy signal.
>window = gtk.Window()
>window.connect("destroy", gtk.main_quit)
>
># Create and add a treeview widget to the window.
>self.treeview = gtk.TreeView()
>window.add(self.treeview)
>
># Create a text column
>column0 = gtk.TreeViewColumn("Text",
>gtk.CellRendererText(),
>text=0)
>
># Create a combobox column
>cellcombo = gtk.CellRendererCombo()
>
>model = gtk.ListStore(str)
>
>for k in range(1,10):
>model.append(["item_%d" % k])
>
>cellcombo.set_property("model", model)
>
>column1 = gtk.TreeViewColumn("Combobox", cellcombo)
>
>column1.add_attribute(cellcombo, "text-column", 1)
>
>self.treeview.append_column(column0)
>self.treeview.append_column(column1)
>
># Create liststore.
>liststore = gtk.ListStore(str, int)
>
># Append a couple of rows.
>liststore.append(["Some text", 0])
>liststore.append(["More text", 1])
>
># Set model.
>self.treeview.set_model(liststore)
>
>   

Re: [pygtk] Different background color per row in TreeView

2006-11-08 Thread Danni Moiseyev
look at  this:http://www.pygtk.org/pygtk2reference/class-gtktreeviewcolumn.html#method-gtktreeviewcolumn--set-cell-data-func
it helped me On 11/8/06, Volker Helm <[EMAIL PROTECTED]> wrote:
Hi,I know how to change the color of a row from default (value False) to one other color (value True) depending of the value of a cell in the row.Now, I've got the problem, that I need to change the color of a row depending on the value of a cell using at least three different colors.
Thanks for your help in advance,Volker--Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer
___pygtk mailing list   pygtk@daa.com.auhttp://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
___
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] Different background color per row in TreeView

2006-11-08 Thread Brian
On Wed, 2006-08-11 at 10:59 +0100, Volker Helm wrote:
> Hi,
> 
> I know how to change the color of a row from default (value False) to one 
> other color (value True) depending of the value of a cell in the row.
> 
> Now, I've got the problem, that I need to change the color of a row depending 
> on the value of a cell using at least three different colors.
> 
> Thanks for your help in advance,
> 
> Volker

I don't know myself, but I have seen this this come up before.  You
should be able to find something in the archives of this list.
-- 
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] Different background color per row in TreeView

2006-11-08 Thread Volker Helm
Hi,

I know how to change the color of a row from default (value False) to one other 
color (value True) depending of the value of a cell in the row.

Now, I've got the problem, that I need to change the color of a row depending 
on the value of a cell using at least three different colors.

Thanks for your help in advance,

Volker
-- 
Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen! 
Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer
___
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/