Re: CustomItem not displaying on mouse click



On Wed, 22 Dec 2010 21:52:45 +0000, Damon Chaplin
<damon karuna eclipse co uk> wrote:
> On Wed, 2010-12-22 at 20:13 +0100, Shashank Bandari wrote:
> 
>> Hi Damon,
>>     I have checked it by adding a print statement in the
>> canvas_move_up() function and it is being called on mouse release
>> event. The sample code along with the glade file is attached for
>> further reference. The issue is that I can see the item on canvas if I
>> minimize and then maximize the window.
> 
> If I create a simple ellipse item instead of your custom item it works
> fine. So it looks like a problem with your custom item - probably the
> bounds are being set incorrectly.
> 
> Damon

Is there something wrong in the code below to set the bounds:


class GeneratorItem(CustomItem):

    def __init__(self, x, y, width, height, line_width, **kwargs):
        CustomItem.__init__(self, **kwargs)
        self.x = x
        self.y = y
        self.width = width
        self.height = height
        self.line_width = line_width

    def do_update(self, entire_tree, cr):
        half_lw = self.line_width/2
        self.bounds.x1 = float(self.x - half_lw)
        self.bounds.y1 = float(self.y - half_lw)
        self.bounds.x2 = float(self.x + self.width + half_lw)
        self.bounds.y2 = float(self.y + self.height + half_lw)
        return self.bounds

    def do_paint(self, cr, bounds, scale):
        cr.arc(self.x, self.y, 20, 0,360)
        cr.move_to(self.x-4,self.y+5)
        cr.show_text("G")
        cr.set_line_width(self.line_width)
        cr.set_source_rgb(0, 0, 0)
        cr.stroke()

I have set the bounds as per the code in the demo file. Kindly update
the code if required.

-- 
_Thanking You,_
Shashank Bandari

shashank bandari ieee org


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