File: wx.BitmapBundleImpl.txt

package info (click to toggle)
wxpython4.0 4.2.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 232,540 kB
  • sloc: cpp: 958,937; python: 233,059; ansic: 150,441; makefile: 51,662; sh: 8,687; perl: 1,563; javascript: 584; php: 326; xml: 200
file content (352 lines) | stat: -rw-r--r-- 9,845 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
.. 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

   <div id="toggleBlock" onclick="return toggleVisibility(this)" class="closed" style="cursor:pointer;">
   <img id="toggleBlock-trigger" src="_static/images/closed.png"/>
   Inheritance diagram for class <strong>BitmapBundleImpl</strong>:
   </div>
   <div id="toggleBlock-summary" style="display:block;"></div>
   <div id="toggleBlock-content" style="display:none;">
   <p class="graphviz">
   <center><img src="_static/images/inheritance/wx.BitmapBundleImpl_inheritance.png" alt="Inheritance diagram of BitmapBundleImpl" usemap="#dummy" class="inheritance"/></center>
   <script type="text/javascript">toggleVisibilityOnLoad(document.getElementById('toggleBlock'))</script>
   <map id="dummy" name="dummy"> <area shape="rect" id="node1" href="wx.BitmapBundleImpl.html" title="wx.BitmapBundleImpl" alt="" coords="5,83,172,112"/> <area shape="rect" id="node2" href="wx.RefCounter.html" title="wx.RefCounter" alt="" coords="30,5,147,35"/> </map> 
   </p>
   </div>

|


|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`