[GtkGLExt] problem with GTK.TreeView and GLArea



Hi,

I've been playing a bit with teapot2.py from the pygtkglext examples. The program teapot4.py attached here illustrates a problem I also encounterd with a larger app I'm developping with pygtkglext. Just run it:

python teapot4.py

and click on the "add items" button". When starting the application I get four error messages:

(teapot4.py:5097): Gdk-CRITICAL **: file gdkwindow-x11.c: line 1950 (gdk_window_set_geometry_hints): assertion `window != NULL' failed

(teapot4.py:5097): Gdk-CRITICAL **: file gdkwindow-x11.c: line 1331 (gdk_window_resize): assertion `window != NULL' failed

(teapot4.py:5097): Gdk-CRITICAL **: file gdkwindow-x11.c: line 1950 (gdk_window_set_geometry_hints): assertion `window != NULL' failed

(teapot4.py:5097): Gdk-CRITICAL **: file gdkwindow-x11.c: line 1331 (gdk_window_resize): assertion `window != NULL' failed

After clicking the button the window resizes unexpectedly and a part of the window is not used. When I comment out these lines from the example:

                 if sys.platform != 'win32':
                         self.set_resize_mode(gtk.RESIZE_IMMEDIATE)

all the problems dissapear, but I don't understand why. (These lines are also used in teapot2.py) What should these lines do? When I remove them, everything works fine.

Could someone else try this so we are sure it's not a driver/hardware problem? I am using gtk+2.2.4, pygtk-2.0.0 and pygtkglext-1.0.0

regards,

Toon Verstraelen
#!/usr/bin/env python

import sys
import math

import pygtk
pygtk.require('2.0')
from gtk.gtkgl.apputils import *

# Implement the GLScene interface
# to have a teapot rendered.

class Teapot(GLScene):

	def __init__(self):
		GLScene.__init__(self, gtk.gdkgl.MODE_RGB | gtk.gdkgl.MODE_DEPTH | gtk.gdkgl.MODE_DOUBLE)
		self.formerx = 0
		self.formery = 0
	
	def init(self):
		glMaterial(GL_FRONT, GL_AMBIENT,   [0.2, 0.2, 0.2, 1.0])
		glMaterial(GL_FRONT, GL_DIFFUSE,   [0.8, 0.8, 0.8, 1.0])
		glMaterial(GL_FRONT, GL_SPECULAR,  [1.0, 0.0, 1.0, 1.0])
		glMaterial(GL_FRONT, GL_SHININESS, 50.0)
		
		glLight(GL_LIGHT0, GL_AMBIENT,  [0.0, 1.0, 0.0, 1.0])
		glLight(GL_LIGHT0, GL_DIFFUSE,  [1.0, 1.0, 1.0, 1.0])
		glLight(GL_LIGHT0, GL_SPECULAR, [1.0, 1.0, 1.0, 1.0])
		glLight(GL_LIGHT0, GL_POSITION, [1.0, 1.0, 1.0, 0.0])
		
		glLightModel(GL_LIGHT_MODEL_AMBIENT, [0.2, 0.2, 0.2, 1.0])
		
		glEnable(GL_LIGHTING)
		glEnable(GL_LIGHT0)
		glDepthFunc(GL_LESS)
		glEnable(GL_DEPTH_TEST)
		glMatrixMode(GL_MODELVIEW)
		glLoadIdentity()
		glTranslate(0, 0, -10)	
		
	def reshape(self, width, height):
		glViewport(0, 0, width, height)
		glMatrixMode(GL_PROJECTION)
		glLoadIdentity()
		if width > height:
			w = float(width) / float(height)
			glFrustum(-w, w, -1.0, 1.0, 5.0, 60.0)
		else:
			h = float(height) / float(width)
			glFrustum(-1.0, 1.0, -h, h, 5.0, 60.0)
		glMatrixMode(GL_MODELVIEW)
	
	def display(self, width, height):
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
		gtk.gdkgl.draw_teapot(gtk.TRUE, 1)

# A simple window to show the Teapot scene

class TeapotWindow(gtk.Window):
	def __init__(self):
		gtk.Window.__init__(self)
		
		# Set self attfibutes.
		self.set_title('Teapot')
		# COMMENT OUT THESE LINES AND THE PROBLEM IS GONE
		# BEGIN
		if sys.platform != 'win32':
			self.set_resize_mode(gtk.RESIZE_IMMEDIATE)
		# END

		self.set_reallocate_redraws(gtk.TRUE)
		self.connect('destroy', lambda quit: gtk.main_quit())
		
		# Create the box.
		self.hbox = gtk.HBox()
		self.hbox.set_border_width(5)
		self.hbox.set_spacing(5)
		self.add(self.hbox)
		
		# Create a treeview
		self.tv = gtk.TreeView()
		self.tm = gtk.ListStore(int)
		self.tv.set_model(self.tm)
		self.tv.insert_column_with_attributes(0, "test", gtk.CellRendererText(), text=0)
		for i in range(3):
			self.tm.append([i*i-i])	

		# add scrollbox with treeview
		self.sb = gtk.ScrolledWindow()
		self.hbox.pack_start(self.sb, expand=True, fill=True)
		self.sb.add(self.tv)
		
		# The Teapot scene and the GLArea widget to display it.
		self.teapot = Teapot()
		self.glarea = GLArea(self.teapot)
		self.glarea.set_size_request(200,200)
		self.glarea.show()
		self.hbox.pack_start(self.glarea, expand=True, fill=True)
		
		# add items
		self.bu = gtk.Button('add items')
		self.hbox.pack_start(self.bu, expand=True, fill=True)
		self.bu.connect('clicked', self.on_bu_clicked)
		
		self.show_all()
		
	def on_bu_clicked(self, widget):
		for i in range(300):
			self.tm.append([i*i-i])			
		
	def run(self):
		self.show()
		gtk.main()

if __name__ == '__main__':
	app = TeapotWindow()
	app.run()


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]