Size of a DC in a ScrolledWindow?

Ian York wrote:

MacOS 10.5, Python2.5.1, wxPython 2.8.4.0

I have a wx.FlatNotebook containing several pages of
wx.ScrolledWindows. Each ScrolledWindow contains an independent wx.DC
drawing, some of which may require scrolling to see completely, others
of which may not.

When I print one of the pages, I can use either GetClientSize(), which
returns the unscrolled size, or GetVirtualSize(), which returns the
size of the full drawing if it's spilled over off the visible page
(i.e. requires scrolling). I use GetVirtualSize so I can print the
whole drawing. This is all fine.

The problem arises if I have two drawings, one of which spills over
and one of which does not. Both drawings register as having the same
GetVirtualSize(), even though only one actually needs it, so the
drawing prints too small.

I've tried dc.GetClippingBox(), dc.GetSize(). and dc.MaxX(),
dc.MinX(), dc.MaxY(), dc.MinY(), but all the dc info seems to be
visible size, ignoring the part that's off the screen (i.e. these
commands all return the same info as GetClientSize(), which is too
small if it's scrolled off the window).

Is there a way of getting accurate dc sizes in a ScrolledWindow, or
otherwise determining if a drawing actually requires scrolling or
not?

I think you have a couple of the basic concepts turned around. First, the DC will only ever be the size of the physical device (the window), the virtual size is just a helper provided by wx to help you deal with scrolling. Second, you should have a way to know how much space your drawing will need, and then set the virtual size of the scrolled window to be that size. Then if the virtual size ends up being bigger than the client size then you will get scrollbars, otherwise there will be no scrollbars. Your drawing code really shouldn't care if there are scrollbars or not, it just needs to draw as if there is no scrolling and wx.ScrolledWindow will take care of the rest. You just need to call self.PrepareDC(dc) at the beginning of the draw and it will reset the DC's origin to take the current scroll position into account automatically.

ยทยทยท

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!