.. wxPython Phoenix documentation This file was generated by Phoenix's sphinx generator and associated tools, do not edit by hand. Copyright: (c) 2011-2020 by Total Control Software License: wxWindows License .. include:: headings.inc .. _wx.BitmapBundleImpl: ========================================================================================================================================== |phoenix_title| **wx.BitmapBundleImpl** ========================================================================================================================================== Base class for custom implementations of :ref:`wx.BitmapBundle`. This class shouldn't be used directly in the application code, but may be derived from to implement custom bitmap bundles. Example of use: :: class MyCustomBitmapBundleImpl(wx.BitmapBundleImpl): def __init__(self): super().__init__() self.img = wx.Image(pngFile) self.size = self.img.GetSize() def GetDefaultSize(self): # Report the best or default size for the bitmap return self.size def GetPreferredBitmapSizeAtScale(self, scale): # Return the size of the bitmap at the given display scale. It # doesn't need to be size*scale if there are unscaled bitmaps # near that size. return self.size * scale def GetBitmap(self, size): # Return the version of the bitmap at the desired size img = self.img.Scale(size.width, size.height) return wx.Bitmap(img) toolBar.AddTool(wx.ID_OPEN, wx.BitmapBundle.FromImpl(MyCustomBitmapBundleImpl()) Full (but still very simple) example of using it can be found in the toolbar sample code. .. versionadded:: 4.1/wxWidgets-3.1.6 | |class_hierarchy| Class Hierarchy ================================= .. raw:: html
Inheritance diagram for class BitmapBundleImpl:
| |method_summary| Methods Summary ================================ ================================================================================ ================================================================================ :meth:`~wx.BitmapBundleImpl.DoGetPreferredSize` Helper for implementing :meth:`~BitmapBundleImpl.GetPreferredBitmapSizeAtScale` in the derived classes. :meth:`~wx.BitmapBundleImpl.GetBitmap` Retrieve the bitmap of exactly the given size. :meth:`~wx.BitmapBundleImpl.GetDefaultSize` Return the size of the bitmaps represented by this bundle in the default ``DPI``. :meth:`~wx.BitmapBundleImpl.GetIndexToUpscale` Return the index of the available scale most suitable to be upscaled to the given size. :meth:`~wx.BitmapBundleImpl.GetNextAvailableScale` Return information about the available bitmaps. :meth:`~wx.BitmapBundleImpl.GetPreferredBitmapSizeAtScale` Return the preferred size that should be used at the given scale. :meth:`~wx.BitmapBundleImpl.~wxBitmapBundleImpl` ================================================================================ ================================================================================ | |property_summary| Properties Summary ===================================== ================================================================================ ================================================================================ :attr:`~wx.BitmapBundleImpl.DefaultSize` See :meth:`~wx.BitmapBundleImpl.GetDefaultSize` ================================================================================ ================================================================================ | |api| Class API =============== .. class:: wx.BitmapBundleImpl(RefCounter) Base class for custom implementations of BitmapBundle. .. method:: DoGetPreferredSize(self, scale) Helper for implementing :meth:`GetPreferredBitmapSizeAtScale` in the derived classes. This function implements the standard algorithm used inside wxWidgets itself and tries to find the scale closest to the given one, while also trying to choose one of the available scales, to avoid actually rescaling the bitmaps. It relies on :meth:`GetNextAvailableScale` to get information about the available bitmaps, so that function must be overridden if this one is used. Typically this function is used in the derived classes implementation to forward :meth:`GetPreferredBitmapSizeAtScale` to it and when this is done, :meth:`GetBitmap` may also use :meth:`GetIndexToUpscale` to choose the bitmap to upscale if necessary: :: 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 means 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) :param `scale`: The required scale, typically the same one as passed to :meth:`GetPreferredBitmapSizeAtScale` . :type `scale`: float :rtype: :ref:`wx.Size` .. versionadded:: 4.1/wxWidgets-3.1.7 .. method:: GetBitmap(self, size) Retrieve the bitmap of exactly the given size. Note that this function is non-const because it may generate the bitmap on demand and cache it. :param `size`: :type `size`: wx.Size :rtype: :ref:`wx.Bitmap` .. method:: GetDefaultSize(self) Return the size of the bitmaps represented by this bundle in the default ``DPI``. Must always return a valid size. :rtype: :ref:`wx.Size` .. method:: GetIndexToUpscale(self, size) Return the index of the available scale most suitable to be upscaled to the given size. See :meth:`DoGetPreferredSize` for an example of using this function. :param `size`: The required size, typically the same one as passed to :meth:`GetBitmap` :type `size`: wx.Size :rtype: `int` .. versionadded:: 4.1/wxWidgets-3.1.7 .. method:: GetNextAvailableScale(self, idx) Return information about the available bitmaps. Overriding this function is optional and only needs to be done if either :meth:`DoGetPreferredSize` or :meth:`GetIndexToUpscale` are called. If you do override it, this function must return the next available scale or 0.0 if there are no more. The returned scales must be in ascending order and the first returned scale, for the initial `i` value of 0, should be 1. The function must change `i`, but the values of this index don't have to be consecutive and it's only used by this function itself, the caller only initializes it to 0 before the first call. See :meth:`DoGetPreferredSize` for an example of implementing this function. :param `idx`: :type `idx`: int :rtype: `tuple` :returns: ( `double`, `idx` ) .. versionadded:: 4.1/wxWidgets-3.1.7 .. method:: GetPreferredBitmapSizeAtScale(self, scale) Return the preferred size that should be used at the given scale. Must always return a valid size. :param `scale`: :type `scale`: float :rtype: :ref:`wx.Size` .. method:: ~wxBitmapBundleImpl(self) .. attribute:: DefaultSize See :meth:`~wx.BitmapBundleImpl.GetDefaultSize`