Hi,
Would someone be able to see what I am doing wrong here? The minimal
code at the bottom is for a double buffered scrolled window. The code
works fine with wxPython 2.8, but fails terribly in 2.9.3.1 - the dc
is drawn to the original size of the window and not to the virtual
size. This problem is independent of wxGTK, wxMSW, and wxMac.
Cheers!
Edward
import wx
class Test(wx.Frame):
"""The about dialog base class."""
# Dimensions.
dim_x = 800
dim_y = 800
virt_x = 800
virt_y = 2500
def __init__(self, parent=None, id=-1, title='', html_text=None):
"""Build the dialog."""
# Execute the base class __init__() method.
super(Test, self).__init__(parent=parent, id=id, title=title,
style=wx.DEFAULT_FRAME_STYLE)
# Create a scrolled window.
self.window = wx.ScrolledWindow(self, -1)
# Set the window size.
self.SetSize((self.virt_x, self.dim_y))
# Set the window virtual size.
self.window.SetVirtualSize((self.virt_x, self.virt_y))
# Add y scrolling.
self.window.SetScrollRate(0, 20)
# Create the buffered device context.
self.create_buffered_dc()
# Bind events.
self.window.Bind(wx.EVT_PAINT, self.on_paint)
self.window.Bind(wx.EVT_SCROLLWIN, self.on_scroll)
def create_buffered_dc(self):
"""Build the buffered dc containing the window contents."""
# The buffer for buffered drawing (work around for a GTK bug,
the bitmap must be square!!!).
size = max(self.virt_x, self.virt_y)
self.buffer = wx.EmptyBitmap(size, size)
# Create the device context.
self.dc = wx.BufferedDC(None, self.buffer)
# Set a background.
self.dc.GradientFillLinear((0, 0, self.virt_x, self.virt_y),
'#e5feff', '#88cbff', wx.SOUTH)
# Cross.
self.dc.DrawLine(0, 0, self.virt_x, self.virt_y)
self.dc.DrawLine(self.virt_x, 0, 0, self.virt_y)
# Lines every 200 pixels.
num = self.virt_y / 200
for i in range(num+1):
pos = i * 200
self.dc.DrawLine(0, pos, self.virt_x, pos)
self.dc.SetFont(wx.Font(8, wx.FONTFAMILY_SCRIPT,
wx.NORMAL, wx.NORMAL))
self.dc.DrawText(str(pos), self.virt_x-40, pos-10)
# Finish.
self.dc.EndDrawing()
def on_paint(self, event):
"""Build the device context, add the background, and build the dialog.
@param event: The wx event.
@type event: wx event
"""
# Create the device context.
wx.BufferedPaintDC(self.window, self.buffer, wx.BUFFER_VIRTUAL_AREA)
def on_scroll(self, event):
"""Build the device context, add the background, and build the dialog.
@param event: The wx event.
@type event: wx event
"""
print "Scrolling"
self.window.PostSizeEvent()
event.Skip()
if __name__ == "__main__":
app = wx.App()
win = Test()
app.SetTopWindow(win)
win.Show()
app.MainLoop()