Hello,
I am trying to put some buttons over a drawing area in a fixed
container, but the drawingarea always ends up looking like it is on top
of the buttons despite my draw sequence. Is it because the expose or
configure events are drawing over the buttons. If so how do I trigger
the buttons to redraw? See sample below(modified from the tutorial):
#!/usr/bin/env python
# example fixed.py
import gtk
class FixedExample:
# This callback method moves the button to a new position
# in the Fixed container.
def move_button(self, widget):
self.x = (self.x+30)%300
self.y = (self.y+50)%300
self.fixed.move(widget, self.x, self.y)
def __init__(self):
self.x = 50
self.y = 50
# Create a new window
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.set_title("Fixed Container")
# Here we connect the "destroy" event to a signal handler
window.connect("destroy", gtk.mainquit)
# Sets the border width of the window.
window.set_border_width(10)
# Create a Fixed Container
self.fixed = gtk.Fixed()
window.add(self.fixed)
self.fixed.show()
self.f1=gtk.DrawingArea()
self.f1.connect("expose-event", self.expose)
self.f1.connect("configure-event", self.configure)
self.f1.set_size_request(200,200)
self.fixed.put(self.f1,0,0)
for i in range(1, 4):
# Creates a new button with the label "Press me"
button = gtk.Button("Press me")
# When the button receives the "clicked" signal, it will
call the
# method move_button().
button.connect("clicked", self.move_button)
# This packs the button into the fixed containers window.
self.fixed.put(button, i*50, i*50)
# The final step is to display this newly created widget.
button.show()
# Display the window
window.show_all()
x, y, width, height = self.f1.get_allocation()
self.pixmap = gtk.gdk.Pixmap(self.f1.window, width, 3000)
def draw_objects(self):
x, y, width, height = self.f1.get_allocation()
self.pixmap = gtk.gdk.Pixmap(self.f1.window, width, height)
self.pixmap.draw_rectangle(self.f1.get_style().white_gc,True,
0,0, width, 3000)
def expose(self,a,b):
self.draw_objects()
x, y, width, height = self.f1.get_allocation()
self.f1.window.draw_drawable(self.f1.get_style().fg_gc[gtk.STATE_NORMAL],self.pixmap,
0, 0, 0, 0, width, 3000)
return False
def configure(self,a,b):
x, y, width, height = self.f1.get_allocation()
self.pixmap = gtk.gdk.Pixmap(self.f1.window, width, 3000)
x, y, width, height = self.f1.get_allocation()
self.f1.window.draw_drawable(self.f1.get_style().fg_gc[gtk.STATE_NORMAL],self.pixmap,0,
0, 0, 0, width, 3000)
return False
def main():
# Enter the event loop
gtk.main()
return 0
if __name__ == "__main__":
FixedExample()
main()
_______________________________________________
pygtk mailing list [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/