On Thu, Jul 12, 2012 at 1:36 AM, Carl Bednorz <[email protected]> wrote:
> 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.
first, there is a little bug:
Traceback (most recent call last):
File "zoomTest2.py", line 116, in OnMove
self.SetStatusText("%i, %i"%tuple(event.Coords))
AttributeError: 'viewerPanel' object has no attribute 'SetStatusText'
which could be getting in the way. commenting out the offending code,
I do see your issue.
Ah Ha! you need to call SetSizer -- both in the Frame and in the Panel:
class DrawFrame(wx.Frame):
...
def __init__(self, *args, **kwargs):
... wx.Frame.__init__(self, *args, **kwargs)
self.mainSizer.Add(NC, 1, wx.ALL| wx.EXPAND | wx.GROW , 0)
self.SetSizer(self.mainSizer)
class viewerPanel(wx.Panel):
def __init__(self,parent):
...
self.mainSizer.Add(NC, 1, wx.ALL| wx.EXPAND | wx.GROW , 0)
self.SetSizer(self.mainSizer)
This isn't FloatCanvas specific -- when you create a sizer, it is not
associated with a Window -- you need to do that with a SetSizer()
call.
There also was a bit of confusion about NavCanvas vs. the FloatCanvas
it contains
I've cleaned that up in the enclosed.
> 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.
That's because a wx.Frame with only one Window on it automatically
sizes that Window to fit -- so need for a Sizer, or to set it right.
> 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.
I"m not sure I do have a sample of that -- but if you only want PAn,
you could grab the NavCanvas code ans strip out what you don't want --
or simply set the GUIMode to GUIMode.GUIMove() some other way:
self.Canvas.SetMode(GUIMode.GUIMove())
Take a look -- there isn't much code in the NavCanvas. All the real
work is in the GUIModes
HTH,
-Chris
> 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 <[email protected]>
>> 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
>>> [email protected]
>>> http://paulmcnett.com/cgi-bin/mailman/listinfo/floatcanvas
>>>
>>
>>
>
>
>
> _______________________________________________
> FloatCanvas mailing list
> [email protected]
> http://paulmcnett.com/cgi-bin/mailman/listinfo/floatcanvas
>
--
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]
zoomTest2.py
Description: Binary data
_______________________________________________ FloatCanvas mailing list [email protected] http://paulmcnett.com/cgi-bin/mailman/listinfo/floatcanvas
