ROY ZINN wrote:
I'm quite new to FloatCanvas (and drawing in general).
Welcome
I saw the examples of FloatCanvas, but i couldn't figure how to place an
object (such as text) on the top left corner for example.
I saw that the placement is done by Point = (x,y), but i'm sure there is
a better way then to guess x,y ....
One of the benefits of FloatCanvas is that you can use any coordinate
system you want, rather than having to use pixels.
The default coordinate system is x-right, y-up.
FloatCanvas does not include any method to help with laying things out
(like sizers, etc) , you'll have to do that yourself.
the left side is a list of the captured events (looks like listctrl). To
the right of the list (which is part of the canvas) there's is the main
drawing.
I'm not sure I understand, but you'll probably find it easier to make
the list and the main drawing all with floatcanvas, to make it easier to
line things up.
I need to draw 2 'frames'. each 'frame' is divided to 8 equal
spaces with dashed line seperating them : | | | | | | | | |
so, to keep the math easy, you could make each "frame" 8 units wide, and
each line 8 units tall.
to make the horizontal lines, something like:
for i in range(num_rows/2):
Canvas.AddRectangle((0, i*8),
(width, 8),
LineColor = None,
FillColor = "Grey",
FillStyle = "Solid",)
to put a dashed line in every 1 unit:
for i in range(8):
Canvas.AddLine(((i,bottom)(i,top)),
LineColor = "Black",
LineStyle = "ShortDash",# or "Dot",
"LongDash","ShortDash", "DotDash"
LineWidth = 1,)
etc...
I've enclosed a sample to get you started.
-Chris
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
[EMAIL PROTECTED]
#!/usr/bin/env python
import wx
## import the installed version
#from wx.lib.floatcanvas import NavCanvas, FloatCanvas
## import a local version
import sys
sys.path.append("../")
from floatcanvas import NavCanvas, FloatCanvas
class DrawFrame(wx.Frame):
"""
A frame used for the FloatCanvas Demo
"""
def __init__(self, *args, **kwargs):
wx.Frame.__init__(self, *args, **kwargs)
self.CreateStatusBar()
# Add the Canvas
# Canvas = NavCanvas.NavCanvas(self,-1,
# size = (500,500),
# ProjectionFun = None,
# Debug = 0,
# BackgroundColor = "White",
# ).Canvas
Canvas = FloatCanvas.FloatCanvas(self,-1,
size = (500,500),
ProjectionFun = None,
Debug = 0,
BackgroundColor = "White",
)
self.Canvas = Canvas
FloatCanvas.EVT_MOTION(self.Canvas, self.OnMove )
# Some default sizes:
self.LineHeight = 1
self.TextWidth = 8
self.SpaceWidth = 1
self.Labels = ["SW Tasks", "Set RX Rf"] + ["A Row Label"]*16
self.NumRows = len(self.Labels)
self.BuildChartBackground()
self.AddLabels()
self.Show()
Canvas.ZoomToBB()
def BuildChartBackground(self):
Canvas = self.Canvas
top = 0
bottom = -(self.LineHeight * self.NumRows)
width = self.SpaceWidth * 16 + self.TextWidth
# put in the rows:
for i in range(1, self.NumRows+1, 2):
Canvas.AddRectangle((0-self.TextWidth, -i*self.LineHeight),
(width, self.LineHeight),
LineColor = None,
FillColor = "LightGrey",
FillStyle = "Solid",)
# put a dashed line in every 1 unit:
for i in range(16):
Canvas.AddLine(((i*self.SpaceWidth,bottom),(i*self.SpaceWidth,top)),
LineColor = "Black",
LineStyle = "Dot",
# or "Dot", "ShortDash", "LongDash","ShortDash", "DotDash"
LineWidth = 1,)
def AddLabels(self):
Canvas = self.Canvas
for i, label in enumerate(self.Labels):
Canvas.AddScaledText(label,
( -self.TextWidth, -(i+0.2)*self.LineHeight ),
Size = 0.6 * self.LineHeight,
Color = "Black",
BackgroundColor = None,
Family = wx.MODERN,
Style = wx.NORMAL,
Weight = wx.NORMAL,
Underlined = False,
Position = 'tl',
)
def OnMove(self, event):
"""
Updates the status bar with the world coordinates
"""
self.SetStatusText("%.2f, %.2f"%tuple(event.Coords))
app = wx.App(False)
F = DrawFrame(None, title="FloatCanvas Demo App", size=(700,700) )
app.MainLoop()
_______________________________________________
FloatCanvas mailing list
[email protected]
http://mail.mithis.com/cgi-bin/mailman/listinfo/floatcanvas