On Sun, Dec 7, 2008 at 5:45 PM, Nitro <[EMAIL PROTECTED]> wrote:
> Am 07.12.2008, 20:22 Uhr, schrieb Marcos Duarte <[EMAIL PROTECTED]>:
>
>> I am observing an unstable behavior of FloatCanvas2 (FC2) when I
>> manually change the size of the window up to a point where the canvas
>> itself disappear.
>> After I resize the window again my program (which has some mouse
>> drawing and image showing) stops to work: the stuff I draw does not
>> appear on the screen anymore.
>>
>> For example, run the SimpleLineDrawer example in the demo folder of
>> FC2, minimize the window until the canvas disappear, release the
>> mouse, and resize the window again. You should see that the lines
>> can't be drawn anymore.
>>
>> I also observe a similar problem when I try to implement a
>> SplitterWindow; when the width of the FC2 panel is minimized, the
>> canvas simply disappear (when I click the refresh button, the image
>> appears again but I still have problems with drawing stuff on the
>> canvas).
>>
>> The examples in FloatCanvas (FC) don't show this problem. Is there any
>> solution for that in FC2?
>>
>> By the way, there is a small typo on line 166 of navcanvas.py: it
>> should be 'jpg' and not 'png' at the second condition below:
>> if not (filename.lower().endswith('png') or
>> filename.lower().endswith('png') or filename.lower().endswith('bmp')):
>
> All bugs fixed in svn. Reasons were the size == (0,0) check for creating
> bitmaps was not enough, you need to check each component individually. The
> other bug was fixed a bit differently than you suggested, but essentially
> the same.
>
> Thanks for reporting this!
>
> -Matthias
> _______________________________________________

Thanks, it works fine now.

Two other questions:
I am playing with FC2 to change the object the mouse is over it.
It works but the response of the mouse to other events are affected
(It is more difficult to delete the object with right button).
If you could try the attached code (change the image on line 23), you
see that you can add points with the left button and delete them with
the right button (its is just a continuation of you have helped me).
Now, if you uncomment lines 57-68, you will see that is tougher to
delete the point and I don't know how to solve that.

Another question: when I use the move-object gui button, I would like
to still be able to show at the status bar which object the mouse
cursor is over it. In the way I wrote, at the moment I use the gui
buttons, what I run inside the class canvas stops to run. I tried to
implement the mouse response in the class frame by accessing the
canvas.hitTest form outside but it does not work. Any suggestion?

thanks

Marcos Duarte
http://lob.iv.fapesp.br/
University of Sao Paulo, Brazil
"""
Select coordinates and draw with mouse selection
"""

import wx
import wx.lib.floatcanvas.floatcanvas2 as fc
#import numpy as np


class Drawer(object):
    def __init__(self, canvas):
        self.point = ''
        self.npoint = 0
        self.curr_point = ''
        self.curr_obj = ''
        self.select = 0
        self.select2 = 0
        self.canvas = canvas
        # Event handlers
        self.canvas.subscribe( self.OnLeftDown, 'input.left_down' )
        self.canvas.subscribe( self.OnMove, 'input.move' )
        # Show image
        name = 'spine.jpg'
        img = wx.Image( name )
        self.canvas.create( 'Bitmap', img, pos=(0,0), name=name, look=('white','white'), where='back' )
        self.canvas.zoomToExtents()

    def OnLeftDown(self, evt):
        pos = evt.coords.world # evt.coords is an array
        self.point = (pos[0], pos[1]) # list
        self.npoint += 1
        # Draw point:
        #Some possible looks:
        #look = fc.SolidColourLook( line_colour = 'red', fill_colour = (255,0,0,255) ) # one solid color
        #look = fc.OutlineLook( line_colour='green', width=4, style='solid' ) #hollow point
        look = fc.RadialGradientLook( (0,255,0,255), (0,0), (255,0,0,200), (0,0), 4, (255,0,0,200), line_style = 'solid', line_width = 3 )
        self.Node = self.canvas.create('Circle', 10, pos=self.point, name='Point # %d' % self.npoint, look=look, where='front')
        self.curr_point = self.Node.name
        self.select2 = 0
        # bind event handlers:
        self.Node.subscribe( self.OnRightDown, 'right_down' )
        
    def OnRightDown(self, evt):
        self.canvas.removeChild( evt.node )
        self.npoint -= 1

    def OnMove(self, evt):
        self.curr_point = ''
        self.curr_obj = ''
        nodes = self.canvas.hitTest(evt.wx_event.GetPosition())
        if nodes:
            self.curr_obj = nodes[0].name
            if nodes[0].name[0] == 'P':
                self.curr_point = nodes[0].name
## The code below shows the selected point; it works but it messes a little with 
##  other mouse events (it's more difficult to delete a point with the right button).
#                self.point = (nodes[0].pos[0], nodes[0].pos[1])
#                look = fc.OutlineLook( line_colour='red', width=4, style='solid' )
#                if self.select2: 
#                    self.select = self.canvas.create('Circle', 14, pos=self.point, name = 'sel', look=look, where='front')
#            elif self.select:
#                self.canvas.removeChild( self.select )
#                self.select = 0
#            else:
#                self.select2 = 1
#        elif self.select:
#            self.canvas.removeChild( self.select )  
#            self.select = 0



class Frame(wx.Frame):
    def __init__(self, parent):
        self.size = (800, 600)
        wx.Frame.__init__(self, parent, -1, title="Xc", size=self.size)
        #MenuBar
        self.MakeMenuBar()
        #Status bar
        self.statusbar = self.CreateStatusBar()
        self.statusbar.SetFieldsCount(4)
        self.statusbar.SetStatusWidths([-1,-1,-1,-1])
        #The canvas
        self.canvas = fc.NavCanvas( self, backgroundColor = 'white' )
        self.drawer = Drawer(self.canvas)
        #Event handlers
        self.canvas.subscribe( self.OnMotion, 'raw_input.move' )
        self.canvas.subscribe( self.OnMotion, 'raw_input.right_down' )
        self.canvas.subscribe( self.OnMotion, 'raw_input.left_down' )
      
    def MakeMenuBar(self):
        self.menuBar = wx.MenuBar()
        file_menu = wx.Menu()
        item = file_menu.Append(-1, "&Exit")
        self.Bind(wx.EVT_MENU, self.OnExit, item)
        self.menuBar.Append(file_menu, "&File")
        self.SetMenuBar(self.menuBar)

    def OnMotion(self, event):
        coords = event.coords.world.round(1)
        coords[1] = -coords[1]

        self.statusbar.SetStatusText("Coordinates: %s" % coords, 0)
        self.statusbar.SetStatusText("Number of Points: %d" % self.drawer.npoint, 1)
        self.statusbar.SetStatusText("Current Point: %s" % self.drawer.curr_point, 2)
        self.statusbar.SetStatusText("Current Object: %s" % self.drawer.curr_obj, 3)

    def OnExit(self,event):
        self.Close(True)


class App(wx.App):
    """Application class"""
    def OnInit(self):
        self.frame = Frame(None)
        self.frame.Show(True)
        self.SetTopWindow(self.frame)
        return True


def main():
    app = App(redirect = False)
    app.MainLoop()

if __name__ == '__main__':
    main()
_______________________________________________
FloatCanvas mailing list
[email protected]
http://mail.mithis.com/cgi-bin/mailman/listinfo/floatcanvas

Reply via email to