Re: CustomItem not displaying on mouse click



On Wed, 2010-12-22 at 09:01 +0000, Shashank Bandari wrote:
> Hi,
>  I am trying to use a custom item to draw objects onto the canvas on a 
> mouse click. The item is not displayed on mouse click.
> However if I minimise the window and then maximise, the item is 
> displayed. The code is shown below.
> 
> #!/usr/bin/env python
> import sys
> import pygtk
> import string
> 
> pygtk.require('2.0')
> import gtk
> import gobject
> import gtk.glade
> import goocanvas
> import cairo
> import os.path
> 
> from Objects import GeneratorItem
> 
> class MainWindow:
>  def __init__(self):
>    self.edit_state=0
>    self.builder = gtk.Builder()
>    self.builder.add_from_file("sample_glade.glade")
>    self.window=self.builder.get_object("sample_window")
>    self.canvas_window=self.builder.get_object("main_canvas") #Scrolled 
> Window
>    self.canvas=goocanvas.Canvas()
>    self.canvas_window.add(self.canvas)
>    self.window.show_all()
>    
> self.canvas.connect("button_release_event",self.canvas_mouse_up,None)
> 
>  def canvas_mouse_up(self,item,event,cr):
>    root = self.canvas.get_root_item()
>    item = GeneratorItem.GeneratorItem(x=100, y=100, width=100, 
> height=100,line_width=20)
>    root.add_child(item)
>    self.canvas.request_update()
>    self.canvas_window.show_all()
> 
> window=MainWindow()
> gtk.main()
> 
> GeneratorItem is the sample CustomRectItem from the demos directory.
> 
> Kindly suggest the points I am missing in the code.

It looks like it should work.

Does the item display correctly if you add it when you create the
canvas?

Are you sure canvas_mouse_up() is being called?

Damon




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