[pygtk] problem with textview.get_iter from another thread

2003-06-18 Thread Philippe Sam-Long
Hi. First of all I'm quite new to python and pygtk. Anyway, there seems 
to be a problem with getting textbuffer iters from another thread than 
gtkmainloop's. Here is a fast written little piece of code testing this 
operation :

-- test.py

import threading
import time
import pygtk
pygtk.require('2.0')
import gtk
class CGuiModifyThread(threading.Thread):
   def __init__(self, gui):
   threading.Thread.__init__(self)
   self.gui  = gui
   self.done = 0
   def run(self):
   i = 0
   while (i  10):
   i = i + 1
   gtk.threads_enter ()
   gui.addpage_cb(None)
   gtk.threads_leave ()
   time.sleep(.2)
   Done = 1
   print Thread done
class CGui(gtk.Window):
   def __init__(self):
   gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
   self.connect(destroy, self.destroy_cb)
   self.vbox = gtk.VBox()
   self.add(self.vbox)
   self.checkbutton = gtk.CheckButton(Try to get iter)
   self.checkbutton.set_active(1)
   self.vbox.pack_start(self.checkbutton, gtk.FALSE, gtk.FALSE, 0)
   self.startbutton = gtk.Button(start thread)
   self.startbutton.connect(clicked, self.start_cb)
   self.vbox.pack_start(self.startbutton, gtk.FALSE, gtk.FALSE, 0)
   self.addpage = gtk.Button(Add page to notebook)
   self.addpage.connect(clicked, self.addpage_cb)
   self.vbox.pack_start(self.addpage, gtk.FALSE, gtk.FALSE, 0)
   self.notebook = gtk.Notebook()
   self.vbox.pack_start(self.notebook, gtk.FALSE, gtk.FALSE, 0)
   self.startbutton.show()
   self.addpage.show()
   self.notebook.show()
   self.vbox.show()
   def start_cb(self, data):
   print Starting thread
   self.modifyth = CGuiModifyThread (self)
   self.modifyth.start()
   def destroy_cb(self,*args):   
   self.hide()
   gtk.mainquit()

   def addpage_cb(self, data):
   textview = gtk.TextView()
   textbuffer = gtk.TextBuffer(None)
   textview.set_buffer(textbuffer)
   if (self.checkbutton.get_active()):
   print Getting iter
   iter = textbuffer.get_iter_at_offset(0)
   print Done
   textbuffer.insert(iter, Hello World\n)
   self.notebook.add(textview)
   textview.show()
gtk.threads_init ()
gtk.threads_enter ()
gui = CGui()
gui.show_all()
gtk.mainloop ()
gtk.threads_leave()
-- end

If you dont get iter while running thread, everything's OK. If you get 
iter from the mainloop it's ok. But if you get iter from a child thread 
everything freezes.
Is there any big mistake in this code (except it was made in 2 minutes)?

Thanks

--
Philippe Sam-Long
[EMAIL PROTECTED]
http://purplemonk.doesntexist.com
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


[pygtk] pthread error with pygtk

2003-06-18 Thread Dave Walton
I've got pygtk-0.6.10 installed on FreeBSD 4.6.2 with python 2.2.2,
gtk-1.2.10, and pth-2.0.0.  Things were working well before, until I
upgraded some of my software packages.  Among other things, I believe I
upgraded pth from version 1.4.  Since upgrading, things that use pygtk no
longer work, even though I've reinstalled all the relevant stuff to make
sure it's up to date and properly compiled.  

Here's an example of what I'm seeing:

 python
Python 2.2.2 (#1, Mar 24 2003, 15:55:57)
[GCC 2.95.3 20010315 (release) [FreeBSD]] on freebsd4
Type help, copyright, credits or license for more information.
 import gtk
Traceback (most recent call last):
  File stdin, line 1, in ?
  File /usr/local/lib/python2.2/site-packages/gtk-1.2/gtk.py, line 22,
in ?
import _gtk
ImportError: /usr/local/lib/pth/libpthread.so.20: Undefined symbol
sigaltstack


I have no idea what the problem here is, or how to solve it.  Any
suggestions would be most welcome.  Please cc: me, as I am not currently
subscribed.

Thanks,
Dave


-- 
--
Dave Walton[EMAIL PROTECTED]
--


-- 
--
Dave Walton[EMAIL PROTECTED]
--
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


[pygtk] Problem with iter and Tree/list model

2003-06-18 Thread Thomas Sonne Olesen
Hello mailing list

I have just released one of my programs to the public and have recieved
an error message from a user I can't reproduce. 

I hope someone can help with the problem regarding iteration in
a ListStore.

The Save function in the class i the buttom of this mail which inherit
from gtk.ListStore works on my pygtk 1.99.11 but fails on his 1.99.16
with an error: 

File /usr/local/bin/pyblink, line 104, in save
  r=self.get_value(iter,0)
  TypeError: iter must be a GtkTreeIter

Can any one see any logical error in the way the iteration is done.
I must admit i have done som guessing since the docs aren't that good.

Another (maybe related) problem is how to build the list.
What is the difference between:
iter = self.append ()
self.set (iter, 0, ref)
and 
iter = self.append ()
self.set_value (iter, 0, ref)

I hope someone can help.

Regards Thomas
email: [EMAIL PROTECTED]

class reflistStore(gtk.ListStore) :
myFilename=unsaved.rl

def __init__(self):
gtk.ListStore.__init__(self,gobject.TYPE_STRING)
self.data=[]
self.setFilename('unsaved.rl')

def save(self):
global allRefs, bibfile
fd=open(self.myFilename,w)
config.set(files,last,self.myFilename)
fd.write(---bibfile=%s\n % bibfile)
#for iter in reflist:
iter=self.get_iter_root() 
while iter :
r=self.get_value(iter,0)
fd.write(%s\n % r)
iter=self.iter_next(iter) 

fd.close()





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


Re: [pygtk] Problem with iter and Tree/list model

2003-06-18 Thread David M. Cook
On Tue, Jun 17, 2003 at 10:12:29PM +0200, Thomas Sonne Olesen wrote:

 File /usr/local/bin/pyblink, line 104, in save
   r=self.get_value(iter,0)
   TypeError: iter must be a GtkTreeIter

Try putting a 

print `iter`

here (with backticks, or use repr()) to see whether the iter is None at this
point.

Dave Cook
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/