Hey,
I tried all your suggestions except copying NavCanvas, but nothing
worked so far. Therefore, I've attached an altered example which shows
the exact same behaviour as in my application.
So when I put the navcanvas into another wx.panel it does not scale up
to the whole wx.frame size. However, putting the Navcanvas directly into
the wx.frame works fine.
Otherwise, is there somewhere an example how to subclass/copy the
navcanvas? I mean the only thing I really need for my application is the
'Pan' feature where I can move the image on the canvas.
Thanx for your help in advance,
Carl.
On 11/07/12 23:00, Chris Barker wrote:
On Wed, Jul 11, 2012 at 3:48 AM, Carl Bednorz <cb1...@my.bristol.ac.uk> wrote:
I decided to use floatcanvas for my MSc project where I develop a custom
handwriting recognition system.
One part of this system is to have an image viewer in the UI. I've already
played a little bit with the nav and float canvas, but I'm
stuck now for 2 days in a problem with the nav canvas and I have no idea
why, so I'd appreciate it a lot if you could help me with my problem.
In general: I have a wx.panel in which I'd like to have the navcanvas.
Unfortunately, the nav canvas ignores the size parameter so that the canvas
is just a very small rectangle. However, when I just use a floatcanvas with
a custom build navigation everything works fine, but the disadvantage here
is that I'd like to use the UI elements like (zooming, moving, etc.) how
it's established in the nav canvas.
I've attached my code to this mail.
hmm -- odd -- Both NavCanvas and FloatCanvas are wx.Panels. I'd expect
them to act similarly. I can't run your code -- it require images or
something that I don't have. Ideally, if you can make a small runnable
sample that doesn't require any other data, it's easier for others to
test. But looking quickly at the code:
class DocumentPanel(wx.Panel):
'''
The Document Panel class creates a wx.Panel that provides an image
viewer to access
the historical document databases.
'''
def __init__(self, parent):
'''
Constructor
'''
#Init the wx.Panel
self.panel = wx.Panel.__init__(self, parent, wx.ID_ANY)
this is odd -- this is usually:
wx.Panel.__init__(self, parent, wx.ID_ANY)
I'm not sure assigning to self.panel hurts anything, but as the panel
is self, it's not helping.
#NOTE: The created navcanvas is not fit into the panel but
just a small rectangle window!
NC = NavCanvas.NavCanvas(self, size=(400,400), ProjectionFun =
None , Debug=0, BackgroundColor = "Blue").Canvas
I'm not sure why the size isn't being respoected, but it's probably
better to use a sizer to get it to fill the Panel:
S = wx.BoxSizer(wx.Vertical)
S.Add(NC, 1, wx.EXPAND)
self.SetSizer(S)
I do see:
#Add the image control the the main sizer
self.mainSizer.Add(self.Canvas, 0, wx.ALL | wx.LEFT , 5)
perhaps making that second argument 1 will help -- in general, I"d
thikn yuou'd want the Canvas to re-size with the window anyway.
Though if there is nothing else in the Panel, you could subclass
NavCanvas, rather than putting it on a Panel.
self.Canvas = NC
Careful here -- a Navcanvas is a Panel that holds a toolbar and a
FloatCanvas -- it is not actually a FloatCanvas, so it doens't support
all teh FloatCanvasmethods -- you probably want:
self.Canvas = NC.Canvas
NOTE: NavCanvas is not a sub-classes FloatCanvas because you can't
subclass form wx.Window twice. I started out delegating all method
calls to the NavCanvas to its internal FloatCanvas, but that got
messing and confusing.
Another option is to copy (or subclass) NanCanvas, and make your own
versin of it.
HTH
-Chris
I'm looking forward to hearing from you soon.
Best Regards,
Carl Bednorz
_______________________________________________
FloatCanvas mailing list
FloatCanvas@paulmcnett.com
http://paulmcnett.com/cgi-bin/mailman/listinfo/floatcanvas
'''
Created on 9 Jul 2012
@author: cb1754
'''
"""
This demo shows how to use a ScaledBitmap2 (which is like a scaled bitmap,
but uses memory more efficiently for large images and high zoom levels.
It also draws random points on top of the image, because someone on the
wxPython mailing list asked for that...
"""
## Set a path to an Image file here:
ImageFile = "white_tank.jpg"
import wx
import random
## 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()
panel = viewerPanel(self)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(panel, 1, wx.ALL | wx.EXPAND, 0)
self.Show()
class viewerPanel(wx.Panel):
def __init__(self,parent):
'''
Constructor
'''
#Init the wx.Panel
wx.Panel.__init__(self, parent, wx.ID_ANY)
#Create the main sizer
self.mainSizer = wx.BoxSizer(wx.VERTICAL)
# Add the Canvas
Canvas = NavCanvas.NavCanvas(self,
ProjectionFun = None,
BackgroundColor = "DARK SLATE BLUE",
).Canvas
#Canvas = FloatCanvas.FloatCanvas(self, wx.ID_ANY, BackgroundColor = "White")
Canvas.MaxScale=20 # sets the maximum zoom level
self.Canvas = Canvas
FloatCanvas.EVT_MOTION(self.Canvas, self.OnMove )
# create the image:
placeholder = wx.EmptyImage(400, 200)
self.width, self.height = placeholder.GetSize()
img = Canvas.AddScaledBitmap( placeholder,
(0,0),
Height=placeholder.GetHeight(),
Position = 'tl',
)
#Box.Bind(FloatCanvas.EVT_FC_LEFT_DOWN, self.Binding)
self.mainSizer.Add(self.Canvas, 1, wx.ALL| wx.EXPAND | wx.GROW , 0)
## now set up a timer
self.timer = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.AddPoint, self.timer)
Canvas.ZoomToBB()
self.timer.Start(20)
def AddPoint(self, evt=None):
x = random.randint(0, self.width)
y = random.randint(0, self.height)
self.Canvas.AddPoint((x,-y), Diameter=8) # minus y, because floatcanvas uses y-up
self.Canvas.Draw()
wx.GetApp().Yield(onlyIfNeeded=True)
def OnMove(self, event):
"""
Updates the status bar with the world coordinates
"""
self.SetStatusText("%i, %i"%tuple(event.Coords))
def Binding(self, event):
print "Writing a png file:"
self.Canvas.SaveAsImage("junk.png")
print "Writing a jpeg file:"
self.Canvas.SaveAsImage("junk.jpg",wx.BITMAP_TYPE_JPEG)
app = wx.App(False)
F = DrawFrame(None, title="FloatCanvas Demo App", size=(700,700) )
app.MainLoop()
_______________________________________________
FloatCanvas mailing list
FloatCanvas@paulmcnett.com
http://paulmcnett.com/cgi-bin/mailman/listinfo/floatcanvas