Also posted to the wxPython list...
-------- Original Message --------
Subject: Re: [wxpython-users] attaching floatcanvas on a wxpanel
Date: Wed, 12 Nov 2008 22:22:14 -0800
From: Christopher Barker <[EMAIL PROTECTED]>
Reply-To: [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
References: <[EMAIL PROTECTED]>
Astan Chee wrote:
I have problems attaching a floatcanvas/navcanvas on a wxpanel. I've
attached my code and what I'm trying to do is to is to position the
navcanvas inside a wxpanel but not maximized (I want to define where and
how big it is).
Honestly, I always use Sizers -- are you sure you can't use them for this?
Anyway, it seems that it should work, but you're right, it doesn't. I
think it's one of those things where it depends on the order that things
are created. But anyway, a work around is an extra call to SetSize:
self.navCanvas = NavCanvas.NavCanvas(self.mother)
self.navCanvas.SetSize( (1030, 533) )
No need to call this -- it happens in __init_ anyway.
self.navCanvas.Canvas.InitAll()
#for point in self.points:
# self.navCanvas.Canvas.AddPoint(point)
you might want to use a PointSet Object:
self.navCanvas.Canvas.AddPointSet(self.points)
and here a line object takes a sequence of point coordinates:
# pos = 0
# for p in range(0,len(self.points)-1):
# xy = (self.points[pos],self.points[pos+1])
# self.navCanvas.Canvas.AddLine(xy)
# pos+=1
self.navCanvas.Canvas.AddLine(self.points)
I've enclosed my edited version. It's also edited for style:
http://wiki.wxpython.org/wxPython%20Style%20Guide
Another style note: you've got a lot of nested Windows all in one class
here. That may be been for test purposes, but if not, you'll find it
easier to manage your code of you break things out into separate classes.
-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]
--
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]
import wx
import numpy as N
from wx.lib.floatcanvas import NavCanvas, FloatCanvas, Resources
import wx.html as html
######MAIN WINDOW##########
class mainWindow(wx.Frame):
def __init__(self,parent):
wx.Frame.__init__(self,parent,
title="FrameCanvas",
size=(1050,950),
pos=(8,8))
self.wxNoteBook1 = wx.Notebook(self, pos=(0,0))
self.Center()
wxNoteBookPage = wx.Panel(self.wxNoteBook1)
self.chkUndone = wx.CheckBox(wxNoteBookPage,
label="Change Mode",
pos=(40,40))
self.chkUndone.Bind(wx.EVT_CHECKBOX, self.OnUpdateSettings)
self.htmlGraph = html.HtmlWindow(wxNoteBookPage,
pos=(4,387),
size=(1030,533),
style=html.HW_SCROLLBAR_NEVER|html.HW_NO_SELECTION,
name="htmlGraph")
self.points = [(0,-1),(1,-1),(2,3),(3,3),(4,3),(5,-1),(6,1)]
self.mother = wx.Panel(wxNoteBookPage,
pos=(4,387),
size=(1030,533),
style=wx.MAXIMIZE_BOX | wx.RESIZE_BORDER,
name="mother")
self.navCanvas = NavCanvas.NavCanvas(self.mother, BackgroundColor = 'red',
)
self.navCanvas.SetSize( (1030, 533) )
self.mother.Hide()
self.mother.Disable()
self.wxNoteBook1.AddPage(wxNoteBookPage,"JoBo",True)
Canvas = self.navCanvas.Canvas
Canvas.AddPointSet(self.points, Diameter=3, Color='Purple')
Canvas.AddLine(self.points)
Canvas.ZoomToBB()
def OnUpdateSettings(self,event):
if self.chkUndone.GetValue():
self.htmlGraph.Hide()
self.htmlGraph.Disable()
self.mother.Enable()
self.mother.Show()
else:
self.htmlGraph.Enable()
self.htmlGraph.Show()
self.mother.Hide()
self.mother.Disable()
#######MAIN APP#######
class App(wx.App):
def OnInit(self):
frame=mainWindow(None)
self.SetTopWindow(frame)
frame.Show()
return True
if __name__=="__main__":
app=App(0)
app.MainLoop()
_______________________________________________
wxpython-users mailing list
[EMAIL PROTECTED]
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users
_______________________________________________
FloatCanvas mailing list
[email protected]
http://mail.mithis.com/cgi-bin/mailman/listinfo/floatcanvas