Add pythonized versions for new doc snippets

This commit is contained in:
Robin Dunn
2022-08-06 11:40:10 -07:00
parent 2c5bf90721
commit 25fa3d9931
2 changed files with 40 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
class MyCustomBitmapBundleImpl(wx.BitmapBundleImpl):
def GetDefaultSize():
return wx.Size(32, 32)
def GetPreferredBitmapSizeAtScale(self, scale):
return self.DoGetPreferredSize(scale)
def GetBitmap(self, size):
# For consistency with GetNextAvailableScale(), we must have
# bitmap variants for 32, 48 and 64px sizes.
availableSizes = [32, 48, 64]
if (size.y <= 64)
... get the bitmap from somewhere ...
else:
n = self.GetIndexToUpscale(size)
bitmap = ... get bitmap for availableSizes[n] ...
wx.Bitmap.Rescale(bitmap, size)
return bitmap
def GetNextAvailableScale(self, idx):
# The zero marks the end of available scales, and it this method
# won't be called again after the zero is returned.
availableScales = [1.0, 1.5, 2.0, 0]
scale = availableScales[idx]
idx += 1
return (scale, idx)

View File

@@ -0,0 +1,12 @@
class MyWindow(wx.Window):
...
def OnPaint(self, event):
bmp = wx.Bitmap();
bmp.CreateWithDIPSize(self.GetClientSize(), self.GetDPIScaleFactor())
memdc = wx.MemoryDC(bmp)
... use memdc to draw on the bitmap ...
dc = wx.PaintDC(self)
dc.DrawBitmap(bmp, wx.Point(0, 0))