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 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888
|
.. 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.BitmapBundle:
==========================================================================================================================================
|phoenix_title| **wx.BitmapBundle**
==========================================================================================================================================
Contains representations of the same bitmap in different resolutions.
This class generalizes :ref:`wx.Bitmap` for applications supporting multiple DPIs and allows to operate with multiple versions of the same bitmap, in the sizes appropriate to the currently used display resolution, as a single unit. Notably, an entire :ref:`wx.BitmapBundle` can be passed to functions such as :meth:`wx.ToolBar.AddTool` to allow toolbar to select the best available bitmap to be shown.
Objects of this class are typically created by the application and then passed to wxWidgets functions, but not used by the application itself. Currently bitmap bundles can be created from:
More functions for creating bitmap bundles will be added in the future.
Objects of :ref:`wx.BitmapBundle` class have value-like semantics, i.e. they can be copied around freely (and cheaply) and don't need to be allocated on the heap. However they usually are created using static factory functions (known as "pseudo-constructors") such as :meth:`~wx.BitmapBundle.FromBitmaps` instead of using the real constructors.
Example of using this class to initialize a toolbar in a frame constructor: ::
# In __init__ for a wx.Frame
...
toolBar = self.CreateToolBar()
bitmaps = [ wx.Bitmap('open_32x32.png'),
wx.Bitmap('open_32x32.png'),
wx.Bitmap('open_32x32.png') ]
toolBar.AddTool(wx.ID_OPEN, wx.BitmapBundle.FromBitmaps(bitmaps))
The code shown above will use 32 pixel bitmap in normal ``DPI``, 64 pixel bitmap in "high ``DPI``", i.e. pixel-doubling or 200% resolution, and 48 pixel bitmap in 150% resolution. For all the other resolutions, the best matching bitmap will be created dynamically from the best available match, e.g. for 175% resolution, 64 pixel bitmap will be rescaled to 56 pixels.
Of course, this code relies on actually having the resources with the corresponding names (i.e. ``open_NxN`` ) in MSW .rc file or Mac application bundle and ``open_NxN_png`` arrays being defined in the program code, e.g. by including a file generated with ``bin2c`` (see ``BITMAP_PNG_FROM_DATA``), on the other platforms.
For the platforms with resources support, you can also create the bundle from the bitmaps defined in the resources, which has the advantage of not having to explicitly list all the bitmaps, e.g. the code above becomes ::
# RC resources are not supported in wxPython
and will load all resources called ``open`` , ``open_2x`` , ``open_1_5x`` etc (at least the first one of them must be available). See also ``BITMAP_BUNDLE_2`` macro which can avoid the need to check for ``HAS_IMAGE_RESOURCES`` explicitly in the code in a common case of having only 2 embedded resources (for standard and high ``DPI``). See also :meth:`~wx.BitmapBundle.FromSVGResource`.
Also note that the existing code using :ref:`wx.Bitmap` is compatible with the functions taking :ref:`wx.BitmapBundle` in wxWidgets 3.1.6 and later because bitmaps are implicitly convertible to the objects of this class, so just passing :ref:`wx.Bitmap` to the functions taking :ref:`wx.BitmapBundle` continues to work and if high resolution versions of bitmap are not (yet) available for the other toolbar tools, single bitmaps can continue to be used instead.
.. 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>BitmapBundle</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.BitmapBundle_inheritance.png" alt="Inheritance diagram of BitmapBundle" 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.BitmapBundle.html" title="wx.BitmapBundle" alt="" coords="5,5,143,35"/> </map>
</p>
</div>
|
|method_summary| Methods Summary
================================
================================================================================ ================================================================================
:meth:`~wx.BitmapBundle.__init__` Default constructor constructs an empty bundle.
:meth:`~wx.BitmapBundle.Clear` Clear the existing bundle contents.
:meth:`~wx.BitmapBundle.FromBitmap` Create a bundle from a single bitmap.
:meth:`~wx.BitmapBundle.FromBitmaps` Create a bundle from the given collection of bitmaps.
:meth:`~wx.BitmapBundle.FromFiles` Create a bundle from bitmaps stored as files.
:meth:`~wx.BitmapBundle.FromIconBundle` Create a bundle from an icon bundle.
:meth:`~wx.BitmapBundle.FromImage` Create a bundle from a single image.
:meth:`~wx.BitmapBundle.FromImpl` Create a bundle from a custom bitmap bundle implementation.
:meth:`~wx.BitmapBundle.FromResources` Create a bundle from the bitmaps in the application resources.
:meth:`~wx.BitmapBundle.FromSVG`
:meth:`~wx.BitmapBundle.FromSVGFile` Create a bundle from the ``SVG`` image loaded from the given file.
:meth:`~wx.BitmapBundle.FromSVGResource` Create a bundle from the ``SVG`` image loaded from an application resource.
:meth:`~wx.BitmapBundle.GetBitmap` Get bitmap of the specified size, creating a new bitmap from the closest available size by rescaling it if necessary.
:meth:`~wx.BitmapBundle.GetBitmapFor` Get bitmap of the size appropriate for the ``DPI`` scaling used by the given window.
:meth:`~wx.BitmapBundle.GetDefaultSize` Get the size of the bitmap represented by this bundle in default resolution or, equivalently, at 100% scaling.
:meth:`~wx.BitmapBundle.GetIcon` Get icon of the specified size.
:meth:`~wx.BitmapBundle.GetIconFor` Get icon of the size appropriate for the ``DPI`` scaling used by the given window.
:meth:`~wx.BitmapBundle.GetPreferredBitmapSizeAtScale` Get the size that would be best to use for this bundle at the given ``DPI`` scaling factor.
:meth:`~wx.BitmapBundle.GetPreferredBitmapSizeFor` Get the size that would be best to use for this bundle at the ``DPI`` scaling factor used by the given window.
:meth:`~wx.BitmapBundle.GetPreferredLogicalSizeFor` Get the size that would be best to use for this bundle at the ``DPI`` scaling factor used by the given window in logical size.
:meth:`~wx.BitmapBundle.IsOk` Check if bitmap bundle is non-empty.
:meth:`~wx.BitmapBundle.IsSameAs` Check if the two bundles refer to the same object.
================================================================================ ================================================================================
|
|property_summary| Properties Summary
=====================================
================================================================================ ================================================================================
:attr:`~wx.BitmapBundle.DefaultSize` See :meth:`~wx.BitmapBundle.GetDefaultSize`
================================================================================ ================================================================================
|
|api| Class API
===============
.. class:: wx.BitmapBundle(object)
**Possible constructors**::
BitmapBundle()
BitmapBundle(bitmap)
BitmapBundle(icon)
BitmapBundle(image)
BitmapBundle(other)
Contains representations of the same bitmap in different resolutions.
.. method:: __init__(self, *args, **kw)
|overload| Overloaded Implementations:
:html:`<hr class="overloadsep" /><br />`
**__init__** `(self)`
Default constructor constructs an empty bundle.
An empty bundle can't be used for anything, but can be assigned something else later.
:html:`<hr class="overloadsep" /><br />`
**__init__** `(self, bitmap)`
Conversion constructor from a single bitmap.
This constructor does the same thing as :meth:`FromBitmap` and only exists for interoperability with the existing code using :ref:`wx.Bitmap`.
:param `bitmap`:
:type `bitmap`: wx.Bitmap
:html:`<hr class="overloadsep" /><br />`
**__init__** `(self, icon)`
Conversion constructor from a single icon.
This constructor does the same thing as :meth:`FromBitmap` and only exists for interoperability with the existing code using :ref:`wx.Icon`.
:param `icon`:
:type `icon`: wx.Icon
:html:`<hr class="overloadsep" /><br />`
**__init__** `(self, image)`
Conversion constructor from a single image.
Similarly to the constructor from :ref:`wx.Bitmap`, this constructor only exists for interoperability with the existing code using :ref:`wx.Image` and can be replaced with more readable :meth:`FromImage` in the new code.
:param `image`:
:type `image`: wx.Image
:html:`<hr class="overloadsep" /><br />`
**__init__** `(self, other)`
Copy constructor creates a copy of another bundle.
:param `other`:
:type `other`: wx.BitmapBundle
:html:`<hr class="overloadsep" /><br />`
.. method:: Clear(self)
Clear the existing bundle contents.
After calling this function :meth:`IsOk` returns ``False``.
This is the same as assigning a default-constructed bitmap bundle to this object but slightly more explicit.
.. versionadded:: 4.1/wxWidgets-3.1.7
.. staticmethod:: FromBitmap(bitmap)
Create a bundle from a single bitmap.
This is only useful for compatibility with the existing code using :ref:`wx.Bitmap`.
If `bitmap` is invalid, empty bundle is returned.
:param `bitmap`:
:type `bitmap`: wx.Bitmap
:rtype: :ref:`wx.BitmapBundle`
.. staticmethod:: FromBitmaps(*args, **kw)
|overload| Overloaded Implementations:
:html:`<hr class="overloadsep" /><br />`
**FromBitmaps** `(bitmaps)`
Create a bundle from the given collection of bitmaps.
If the `bitmaps` vector is empty, an invalid, empty bundle is returned, otherwise initialize the bundle with all the bitmaps in this vector which must be themselves valid.
:param `bitmaps`:
:type `bitmaps`: Vector
:rtype: :ref:`wx.BitmapBundle`
:html:`<hr class="overloadsep" /><br />`
**FromBitmaps** `(bitmap1, bitmap2)`
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
:param `bitmap1`:
:type `bitmap1`: wx.Bitmap
:param `bitmap2`:
:type `bitmap2`: wx.Bitmap
:rtype: :ref:`wx.BitmapBundle`
:html:`<hr class="overloadsep" /><br />`
.. staticmethod:: FromFiles(*args, **kw)
|overload| Overloaded Implementations:
:html:`<hr class="overloadsep" /><br />`
**FromFiles** `(path, filename, extension="png")`
Create a bundle from bitmaps stored as files.
Looking in `path` for files using `filename` as prefix and potentionally a suffix with scale, e.g. "_2x" or "@2x"
:param `path`: Path of the directory containing the files
:type `path`: string
:param `filename`: Bitmap's filename without any scale suffix
:type `filename`: string
:param `extension`: File extension, without leading dot ( ``png`` by default)
:type `extension`: string
:rtype: :ref:`wx.BitmapBundle`
:html:`<hr class="overloadsep" /><br />`
**FromFiles** `(fullpathname)`
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
:param `fullpathname`:
:type `fullpathname`: string
:rtype: :ref:`wx.BitmapBundle`
:html:`<hr class="overloadsep" /><br />`
.. staticmethod:: FromIconBundle(iconBundle)
Create a bundle from an icon bundle.
If `iconBundle` is invalid or empty, empty bundle is returned.
:param `iconBundle`:
:type `iconBundle`: wx.IconBundle
:rtype: :ref:`wx.BitmapBundle`
.. versionadded:: 4.1/wxWidgets-3.1.7
.. staticmethod:: FromImage(image)
Create a bundle from a single image.
This is only useful for compatibility with the existing code using :ref:`wx.Image`.
If `image` is invalid, empty bundle is returned.
:param `image`:
:type `image`: wx.Image
:rtype: :ref:`wx.BitmapBundle`
.. staticmethod:: FromImpl(impl)
Create a bundle from a custom bitmap bundle implementation.
This function can be used to create bundles implementing custom logic for creating the bitmaps, e.g. creating them on the fly rather than using predefined bitmaps.
See :ref:`wx.BitmapBundleImpl`.
:param `impl`: A valid, i.e. non-null, pointer. This function takes ownership of it, so the caller must `not` call DecRef() on it.
:type `impl`: wx.BitmapBundleImpl
:rtype: :ref:`wx.BitmapBundle`
.. staticmethod:: FromResources(name)
Create a bundle from the bitmaps in the application resources.
This function can only be used on the platforms supporting storing bitmaps in resources, and currently only works under MSW and MacOS and returns an empty bundle on the other platforms.
Under MSW, for this function to create a valid bundle, you must have ``RCDATA`` resource with the given `name` in your application resource file (with the extension `name` as prefix and suffix with the scale, e.g. "_2x" or "_1_5x" (for 150% ``DPI``) will be also loaded as part of the bundle.
:param `name`:
:type `name`: string
:rtype: :ref:`wx.BitmapBundle`
.. seealso:: :meth:`FromSVGResource`
.. staticmethod:: FromSVG(data, sizeDef)
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
:param `data`:
:type `data`: int
:param `sizeDef`:
:type `sizeDef`: wx.Size
:rtype: :ref:`wx.BitmapBundle`
.. staticmethod:: FromSVGFile(path, sizeDef)
Create a bundle from the ``SVG`` image loaded from the given file.
This function loads the ``SVG`` data from the given `path` and calls :meth:`FromSVG` with it. As it is just a wrapper for :meth:`FromSVG` , please see that function documentation for more information about ``SVG`` support.
:param `path`: Path to the ``SVG`` file. Notice that it should a local file, not an URL.
:type `path`: string
:param `sizeDef`: The default size to return from :meth:`GetDefaultSize` for this bundle.
:type `sizeDef`: wx.Size
:rtype: :ref:`wx.BitmapBundle`
.. staticmethod:: FromSVGResource(name, sizeDef)
Create a bundle from the ``SVG`` image loaded from an application resource.
Available only on the platforms supporting images in resources, i.e., MSW and MacOS.
:param `name`: On MSW, it must be a resource with ``RT_RCDATA`` type. On MacOS, it must be a file with an extension "svg" placed in the "Resources" subdirectory of the application bundle.
:type `name`: string
:param `sizeDef`: The default size to return from :meth:`GetDefaultSize` for this bundle.
:type `sizeDef`: wx.Size
:rtype: :ref:`wx.BitmapBundle`
.. seealso:: :meth:`FromResources` , :meth:`FromSVGFile`
.. method:: GetBitmap(self, size)
Get bitmap of the specified size, creating a new bitmap from the closest available size by rescaling it if necessary.
This function is mostly used by wxWidgets itself and not the application. As all bitmaps created by it dynamically are currently cached, avoid calling it for many different sizes if you do use it, as this will create many bitmaps that will never be deleted and will consume resources until the application termination.
:param `size`: The size of the bitmap to return, in physical pixels. If this parameter is DefaultSize, default bundle size is used.
:type `size`: wx.Size
:rtype: :ref:`wx.Bitmap`
.. method:: GetBitmapFor(self, window)
Get bitmap of the size appropriate for the ``DPI`` scaling used by the given window.
This helper function simply combines :meth:`GetPreferredBitmapSizeFor` and :meth:`GetBitmap` , i.e. it returns a (normally unscaled) bitmap from the bundle of the closest size to the size that should be used at the ``DPI`` scaling of the provided window.
:param `window`: Non-null and fully created window.
:type `window`: wx.Window
:rtype: :ref:`wx.Bitmap`
.. method:: GetDefaultSize(self)
Get the size of the bitmap represented by this bundle in default resolution or, equivalently, at 100% scaling.
When creating the bundle from a number of bitmaps, this will be just the size of the smallest bitmap in it.
Note that this function is mostly used by wxWidgets itself and not the application.
:rtype: :ref:`wx.Size`
.. method:: GetIcon(self, size)
Get icon of the specified size.
This is just a convenient wrapper for :meth:`GetBitmap` and simply converts the returned bitmap to :ref:`wx.Icon`.
:param `size`:
:type `size`: wx.Size
:rtype: :ref:`wx.Icon`
.. method:: GetIconFor(self, window)
Get icon of the size appropriate for the ``DPI`` scaling used by the given window.
This is similar to :meth:`GetBitmapFor` , but returns a :ref:`wx.Icon`, as :meth:`GetIcon` does.
:param `window`: Non-null and fully created window.
:type `window`: wx.Window
:rtype: :ref:`wx.Icon`
.. method:: GetPreferredBitmapSizeAtScale(self, scale)
Get the size that would be best to use for this bundle at the given ``DPI`` scaling factor.
For bundles containing some number of the fixed-size bitmaps, this function returns the size of an existing bitmap closest to the ideal size at the given scale, i.e. :meth:`GetDefaultSize` multiplied by `scale`.
Passing a size returned by this function to :meth:`GetBitmap` ensures that bitmap doesn't need to be rescaled, which typically significantly lowers its quality.
:param `scale`:
:type `scale`: float
:rtype: :ref:`wx.Size`
.. method:: GetPreferredBitmapSizeFor(self, window)
Get the size that would be best to use for this bundle at the ``DPI`` scaling factor used by the given window.
This is just a convenient wrapper for :meth:`GetPreferredBitmapSizeAtScale` calling that function with the result of :meth:`wx.Window.GetDPIScaleFactor` .
:param `window`: Non-null and fully created window.
:type `window`: wx.Window
:rtype: :ref:`wx.Size`
.. method:: GetPreferredLogicalSizeFor(self, window)
Get the size that would be best to use for this bundle at the ``DPI`` scaling factor used by the given window in logical size.
This is just call :meth:`GetPreferredBitmapSizeAtScale` with the result of :meth:`wx.Window.GetDPIScaleFactor` and convert returned value with :meth:`wx.Window.FromPhys` .
:param `window`: Non-null and fully created window.
:type `window`: wx.Window
:rtype: :ref:`wx.Size`
.. method:: IsOk(self)
Check if bitmap bundle is non-empty.
Return ``True`` if the bundle contains any bitmaps or ``False`` if it is empty.
:rtype: `bool`
.. method:: IsSameAs(self, other)
Check if the two bundles refer to the same object.
Bundles are considered to be same only if they actually use the same underlying object, i.e. are copies of each other. If the two bundles were independently constructed, they're `not` considered to be the same, even if they were created from the same bitmap.
:param `other`:
:type `other`: wx.BitmapBundle
:rtype: `bool`
.. attribute:: DefaultSize
See :meth:`~wx.BitmapBundle.GetDefaultSize`
|