dc vs. self.dc in ScrolledWindow

Why would scrollbars in a ScrolledWindow appear or disappear depending on whether my DC is a self.dc or a dc? (The scrollbars appear when I resize the window, or when I scroll.) This is MacOS10.4.9, Intel Mac, Python 2.4
, wx.Python 2.8.4 .

I’ve attached a little script that shows this, the bottom line is this part:

def OnPaint(self, event):
    dc = wx.PaintDC(self)
    self.PrepareDC(dc)
    #self.DoDrawingSelfDC(dc)

    #self.DoDrawingSelfDC2(dc)
    self.DoDrawingDC(dc)
   
def DoDrawingSelfDC(self, dc):
    # No scrollbars
    self.dc = dc
    self.dc.BeginDrawing()
    self.dc.SetPen

(wx.Pen(‘RED’))
self.dc.DrawRectangle(50, 50, 1500, 500)
self.dc.EndDrawing()

def DoDrawingSelfDC2(self, dc):
    # No scrollbars
    self.dc = dc
    dc.BeginDrawing()
    dc.SetPen(wx.Pen('RED'))
    dc.DrawRectangle(50, 50, 1500, 500)
    dc.EndDrawing() 
   
def DoDrawingDC(self, dc):
    # Scrollbars
    dc.BeginDrawing()
    dc.SetPen(wx.Pen('RED'))
    dc.DrawRectangle(50, 50, 1500, 500)
    dc.EndDrawing() 

ScrolledWindow.py (1.26 KB)

···


Ian York (
iayork@iayork.com) <http://www.iayork.com/>
“-but as he was a York, I am rather inclined to suppose him a
very respectable Man.” -Jane Austen, The History of England

Ian York wrote:

Why would scrollbars in a ScrolledWindow appear or disappear depending on whether my DC is a self.dc or a dc? (The scrollbars appear when I resize the window, or when I scroll.) This is MacOS10.4.9, Intel Mac, Python 2.4 , wx.Python 2.8.4 .

Not sure why it would affect scrollbars like this on the Mac (maybe they just are not being drawn because of the DC retention) but DC's should never be retained. They are designed to be created, used and disposed of. The various platforms (and various DC types) will have problems if you do. For example on (older) Windows the DCs are a "scarce resource" meaning that there are only a certain number that can be created at any one time for the whole system. Some DCs don't actually flush to the screen until the DC is destroyed. Etc.

···

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