Thanks for gracious comments sir here is my code when i draw a rectangle and upon zoomin or zoomout everything on canvas disappears and please add code for how to undo last drawn shape.

Farrukh

On 08-May-14 11:08 PM, Chris Barker wrote:
Hi,

I've cc'd this to the mailing list -- please keep questions there so others can benefit from the answers.

http://mail.paulmcnett.com/cgi-bin/mailman/listinfo/floatcanvas


On Thu, May 8, 2014 at 3:42 AM, Farrukh <[email protected] <mailto:[email protected]>> wrote:

    1- I am using  "FloatCanvas.FloatCanvas(self.panel)"  and when i
    "self.canvas.Zoom(1.1)" or "self.canvas.Zoom(0.9)" all of my drawn
    shapes disappear.


That _should_ work -- you might try calling FloatCanvas.Draw() to make sure it re-draws. If that doesn't work, something else is up. post a small example and we can figure it out.

Also check out the Demos in the source:

http://svn.wxwidgets.org/viewvc/wx/wxPython/3rdParty/FloatCanvas/Demos/

maybe one of them will show you what you need to do.

    2- "self.dc = wx.ClientDC(self.canvas)" works fine but i cant undo
    last drawn shape, i have searched but couldn't implement anything,
    i tried memorydc but nothing.


you shouldn't need to do anything by hand with the DC -- if you do, it's likely to get confused with what the Canvas is doing...

    3- i also need edit drawn shape after a while user feels to change
    any shape in terms of color, line style line thickness, fill color.


you should be able to make any change, then call Draw() again, and the change should be reflected. See the example in the main demo, and some in that pile of small Demos.

-Chris




    if possible please can include these in a simple program so i can
    understand better. I will be greatfull for your help. eagerly
    waiting for reply.

    Farrukh

    ---
    This email is free from viruses and malware because avast!
    Antivirus protection is active.
    http://www.avast.com




--

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 <tel:%28206%29%20526-6959>   voice
7600 Sand Point Way NE (206) 526-6329 <tel:%28206%29%20526-6329>   fax
Seattle, WA 98115 (206) 526-6317 <tel:%28206%29%20526-6317> main reception

[email protected] <mailto:[email protected]>



---
This email is free from viruses and malware because avast! Antivirus protection 
is active.
http://www.avast.com
import wx, os, sys, os.path, math
from wx.lib.floatcanvas import NavCanvas, FloatCanvas, Resources, Utilities, 
GUIMode
from wx.lib.floatcanvas.Utilities import GUI
import wx.lib.scrolledpanel as scrolled

try:
    from agw import pybusyinfo as PBI
except ImportError: # if it's not there locally, try the wxPython lib.
    import wx.lib.agw.pybusyinfo as PBI
        
#USE_BUFFERED_DC = False
USE_BUFFERED_DC = False
                   
class Example(wx.Frame):
        def __init__(self, parent, title, size):
                style=( wx.MINIMIZE_BOX | wx.MAXIMIZE_BOX | wx.SYSTEM_MENU | 
wx.CLOSE_BOX | wx.CAPTION | wx.CLIP_CHILDREN )
                wx.Frame.__init__(self, parent, title=title, size=size, style = 
style)  # pos is not working in this statement. 
                self.Centre()
                self.toppanel = wx.Panel(self)
                self.cpanel = wx.ScrolledWindow(self)
                
                self.maxVirtualWidth  = 1000
                self.maxVirtualHeight = 1000
                self.cpanel.SetVirtualSize((self.maxVirtualWidth, 
self.maxVirtualHeight))
                self.cpanel.SetScrollRate(20,20)
         
                self.penclr = wx.Colour(0, 255, 255, 128)
                self.brushclr  = wx.Colour(3, 2, 255, 240)
                self.detailpenclr = wx.Colour(255, 0, 0, 128)
                self.detailbrushclr  = wx.Colour(252, 253, 0, 240)
                self.r = 255
                self.g = 0
                self.b = 0
                self.thickness = 2
                self.linetype = wx.SHORT_DASH
                self.Tol = 2
                self.Drawing = False
                self.RBRect = None
                self.Rects = []
                
                self.toppanel.SetBackgroundColour( ( 223, 235, 247 ) )
                # LIGHT GRAY, LIGHT STEEL BLUE, WHEAT
                
                w, h = self.cpanel.GetSize()
                #self.Bind(wx.EVT_PAINT, self.OnPaint)
                #NC = NavCanvas.NavCanvas(self.cpanel, size=(-1,-1), 
ProjectionFun = None, Debug = 0)
                #self.cpanel.tb = NC.ToolBar
                #self.cpanel.tb.AddSeparator()
                #self.cpanel.tb.Realize()
                
                NC = FloatCanvas.FloatCanvas(self.cpanel)
                self.canvas = NC
                
                if USE_BUFFERED_DC:
                        self.buffer = wx.EmptyBitmap(w, h)
                        self.dc = wx.BufferedPaintDC(None, self.buffer, 
style=wx.BUFFER_VIRTUAL_AREA)
                
                elif False:
                        self.buffer = wx.EmptyBitmap(w, h)
                        self.dc = wx.BufferedDC(None, self.buffer)
                
                elif False:
                        self.cdc = wx.ClientDC(self.canvas)
                        bmp = wx.EmptyBitmap(w, h)
                        memDC = wx.MemoryDC()
                        memDC.SelectObject(bmp)
                        memDC.Blit( 0, 0, w, h, self.cdc, 0, 0  )
                        memDC.SelectObject(wx.NullBitmap)
                        
                        self.dc = memDC
                
                else:
                        self.dc = wx.ClientDC(self.canvas)
        
                self.canvas.MinScale = 0.2
                self.canvas.MaxScale = 2.4
                
                self.canvas.Bind(FloatCanvas.EVT_MOTION, self.OnMove)
                self.canvas.Bind(FloatCanvas.EVT_LEFT_DOWN, self.OnDown)
                self.canvas.Bind(FloatCanvas.EVT_LEFT_UP, self.OnUp)
                self.timer = wx.Timer(self)
                
                self.toppanel.zoomin = wx.Button(self.toppanel, label='+', 
pos=(190, 2), size=(40, 25))
                self.toppanel.Bind(wx.EVT_BUTTON, self.ZoomIn, 
self.toppanel.zoomin)
                
                self.toppanel.zoomout = wx.Button(self.toppanel, label='-', 
pos=(240, 2), size=(40, 25))
                self.toppanel.Bind(wx.EVT_BUTTON, self.ZoomOut, 
self.toppanel.zoomout)

                canvas_sizer = wx.BoxSizer(wx.HORIZONTAL)
                canvas_sizer.Add(self.canvas, 1, wx.EXPAND | wx.ALIGN_CENTRE | 
wx.ALL, border=0)
                self.cpanel.SetSizer(canvas_sizer)
                                
                sizer = wx.BoxSizer(wx.VERTICAL)
                sizer.Add(self.toppanel, 1, wx.EXPAND | wx.ALIGN_TOP)
                sizer.Add(self.cpanel, 19, wx.EXPAND | wx.ALIGN_CENTRE | 
wx.ALL, border=25)
                #self.SetAutoLayout(True)
                self.SetSizer(sizer)
                
                self.statusbar = self.CreateStatusBar(2, wx.ST_SIZEGRIP) 
                self.statusbar.SetStatusWidths([-4, -1])
                self.statusbar.SetStatusText('Ready', 0)
                self.statusbar.SetStatusText('Float Canvas', 1)
                                        
        def NewRect(self, rect):
                self.Rects.append(self.canvas.AddRectangle(*rect, LineWidth=2))
                self.canvas.Draw(True)

        def OnMove(self, e):
                upx, upy = e.GetPosition()
                self.statusbar.SetStatusText('x:'+str(upx)+'  y:'+str(upy),1)
                
                if self.Drawing:
                        x, y = self.StartPoint
                        Cornerx, Cornery = e.GetPosition()
                        w, h = ( Cornerx - x, Cornery - y)
                        self.pt1x = x
                        self.pt1y = y
                        self.statusbar.SetStatusText('Left_Down 
x:'+str(self.pt1x)+'  y:'+str(self.pt1y)+ ' -- Left_Down x:'+str(Cornerx)+'  
y:'+str(Cornery),0)
                        if abs(w) > self.Tol and abs(h) > self.Tol:
                                # draw the RB box
                                self.dc.SetPen(wx.Pen(self.penclr, 
self.thickness, self.linetype))
                                self.dc.SetBrush(wx.Brush(self.brushclr))
                                self.dc.SetLogicalFunction(wx.XOR)
                                if self.RBRect:
                                        
self.dc.DrawRectanglePointSize(*self.RBRect)
                                self.RBRect = ( (self.pt1x,self.pt1y), (w, h) )
                                self.dc.DrawRectanglePointSize(*self.RBRect)
                                        
        def OnDown(self, e):
                self.canvas.SetCursor(wx.StockCursor(wx.CURSOR_PENCIL)) # 
change default + cursor to pencil
                # Start drawing
                self.Drawing = True
                self.StartPoint = e.GetPosition()
                x, y = self.StartPoint
                e.Skip()
                
        def OnUp(self, e):
                self.canvas.SetCursor(wx.StockCursor(wx.CURSOR_ARROW)) # change 
default + cursor to pencil
                # Stop Drawing
                if self.Drawing:
                        self.Drawing = False
                self.RBRect = None
        
        def ZoomIn(self, e):
                self.canvas.Zoom(1.1)
                self.canvas.Draw()
                e.Skip()

        def ZoomOut(self, e):
                self.canvas.Zoom(0.9)   
                self.canvas.Draw()
                e.Skip()
                                
if __name__ == '__main__':
    app = wx.App()
    Example(None, 'Float Canvas', size=(800, 660)).Show()
    app.MainLoop()
_______________________________________________
FloatCanvas mailing list
[email protected]
http://mailman.paulmcnett.com/cgi-bin/mailman/listinfo/floatcanvas

Reply via email to