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
|
.. wxPython Phoenix documentation
This file was generated by Phoenix's sphinx generator and associated
tools, do not edit by hand.
Copyright: (c) 2011-2018 by Total Control Software
License: wxWindows License
.. include:: headings.inc
.. _wx.ArtProvider:
==========================================================================================================================================
|phoenix_title| **wx.ArtProvider**
==========================================================================================================================================
:ref:`wx.ArtProvider` class is used to customize the look of wxWidgets application.
When wxWidgets needs to display an icon or a bitmap (e.g. in the standard file dialog), it does not use a hard-coded resource but asks :ref:`wx.ArtProvider` for it instead. This way users can plug in their own :ref:`wx.ArtProvider` class and easily replace standard art with their own version.
All that is needed is to derive a class from :ref:`wx.ArtProvider`, override either its :meth:`wx.ArtProvider.CreateBitmap` and/or its :meth:`wx.ArtProvider.CreateIconBundle` methods and register the provider with :meth:`wx.ArtProvider.Push` :
::
class MyProvider(wx.ArtProvider):
def CreateBitmap(self, id, client, size):
# Your implementation of CreateBitmap here
pass
# optionally override this one as well
def CreateIconBundle(self, id, client):
# Your implementation of CreateIconBundle here
pass
# Later on...
wx.ArtProvider.Push(MyProvider())
If you need bitmap images (of the same artwork) that should be displayed at different sizes you should probably consider overriding :meth:`wx.ArtProvider.CreateIconBundle` and supplying icon bundles that contain different bitmap sizes.
There's another way of taking advantage of this class: you can use it in your code and use platform native icons as provided by :meth:`wx.ArtProvider.GetBitmap` or :meth:`wx.ArtProvider.GetIcon` .
|phoenix_title| Identifying art resources
=========================================
Every bitmap and icon bundle are known to :ref:`wx.ArtProvider` under an unique ``ID`` that is used when requesting a resource from it. The ``ID`` is represented by the :ref:`wx.ArtID` type and can have one of these predefined values (you can see bitmaps represented by these constants in the :ref:`Art Provider Sample <art provider sample>`):
.. include:: rest_substitutions/tables/wx.ArtProvider.1.rst
Additionally, any string recognized by custom art providers registered using :meth:`wx.ArtProvider.Push` may be used.
|phoenix_title| Clients
=======================
The `client` is the entity that calls :ref:`wx.ArtProvider`'s :meth:`~wx.ArtProvider.GetBitmap` or :meth:`~wx.ArtProvider.GetIcon` function. It is represented by ClientID type and can have one of these values:
- ``ART_TOOLBAR``
- ``ART_MENU``
- ``ART_BUTTON``
- ``ART_FRAME_ICON``
- ``ART_CMN_DIALOG``
- ``ART_HELP_BROWSER``
- ``ART_MESSAGE_BOX``
- ``ART_OTHER`` (used for all requests that don't fit into any of the categories above)
Client ``ID`` serve as a hint to
:ref:`wx.ArtProvider` that is supposed to help it to choose the best looking bitmap. For example it is often desirable to use slightly different icons in menus and toolbars even though they represent the same action (e.g. ``wx.ART_FILE_OPEN``). Remember that this is really only a hint for :ref:`wx.ArtProvider` :meth:`wx.ArtProvider.GetBitmap` returns identical bitmap for different client values!
.. note::
When running under GTK+ 2, GTK+ stock item IDs (e.g. ``"gtk-cdrom"`` ) may be used as well: ::
if wx.Platform == '__WXGTK__':
bmp = wx.ArtProvider.GetBitmap("gtk-cdrom", wx.ART_MENU)
For a list of the GTK+ stock items please refer to the `GTK+ documentation page <http://library.gnome.org/devel/gtk/stable/gtk-Stock-Items.html>`_. It is also possible to load icons from the current icon theme by specifying their name (without extension and directory components). Icon themes recognized by GTK+ follow the freedesktop.org `Icon Themes specification <http://freedesktop.org/Standards/icon-theme-spec>`_. Note that themes are not guaranteed to contain all icons, so :ref:`wx.ArtProvider` may return :ref:`wx.NullBitmap` or :ref:`wx.NullIcon`. The default theme is typically installed in ``/usr/share/icons/hicolor`` .
.. seealso:: :ref:`Art Provider Sample <art provider sample>` for an example of :ref:`wx.ArtProvider` usage; :ref:`stock ID list <stock id list>`
|
|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>ArtProvider</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.ArtProvider_inheritance.png" alt="Inheritance diagram of ArtProvider" usemap="#dummy" class="inheritance"/></center>
</div>
<script type="text/javascript">toggleVisibilityOnLoad(document.getElementById('toggleBlock'))</script>
<map id="dummy" name="dummy"> <area shape="rect" id="node1" href="wx.Object.html" title="wx.Object" alt="" coords="20,5,101,35"/> <area shape="rect" id="node2" href="wx.ArtProvider.html" title="wx.ArtProvider" alt="" coords="5,83,117,112"/> </map>
</p>
|
|method_summary| Methods Summary
================================
================================================================================ ================================================================================
:meth:`~wx.ArtProvider.CreateBitmap` Derived art provider classes must override this method to create requested art resource.
:meth:`~wx.ArtProvider.CreateIconBundle` This method is similar to :meth:`~ArtProvider.CreateBitmap` but can be used when a bitmap (or an icon) exists in several sizes.
:meth:`~wx.ArtProvider.Delete` Delete the given `provider`.
:meth:`~wx.ArtProvider.GetBitmap` Query registered providers for bitmap with given ``ID``.
:meth:`~wx.ArtProvider.GetIcon` Same as :meth:`wx.ArtProvider.GetBitmap` , but return a :ref:`wx.Icon` object (or :ref:`wx.NullIcon` on failure).
:meth:`~wx.ArtProvider.GetIconBundle` Query registered providers for icon bundle with given ``ID``.
:meth:`~wx.ArtProvider.GetMessageBoxIcon` Helper used by several generic classes: return the icon corresponding to the standard ICON_INFORMATION/WARNING/ERROR/QUESTION flags (only one can be set)
:meth:`~wx.ArtProvider.GetMessageBoxIconId` Helper used by :meth:`~ArtProvider.GetMessageBoxIcon` : return the art id corresponding to the standard ICON_INFORMATION/WARNING/ERROR/QUESTION flags (only one can be set)
:meth:`~wx.ArtProvider.GetNativeSizeHint` Returns native icon size for use specified by `client` hint.
:meth:`~wx.ArtProvider.GetSizeHint` Returns a suitable size hint for the given `ArtClient`.
:meth:`~wx.ArtProvider.HasNativeProvider` Returns ``True`` if the platform uses native icons provider that should take precedence over any customizations.
:meth:`~wx.ArtProvider.Insert`
:meth:`~wx.ArtProvider.Pop` Remove latest added provider and delete it.
:meth:`~wx.ArtProvider.Push` Register new art provider and add it to the top of providers stack (i.e.
:meth:`~wx.ArtProvider.PushBack` Register new art provider and add it to the bottom of providers stack.
:meth:`~wx.ArtProvider.Remove` Remove a provider from the stack if it is on it.
================================================================================ ================================================================================
|
|api| Class API
===============
.. class:: wx.ArtProvider(Object)
ArtProvider class is used to customize the look of wxWidgets
application.
.. method:: CreateBitmap(self, id, client, size)
Derived art provider classes must override this method to create requested art resource.
Note that returned bitmaps are cached by :ref:`wx.ArtProvider` and it is therefore not necessary to optimize :meth:`CreateBitmap` for speed (e.g. you may create :ref:`wx.Bitmap` objects from XPMs here).
:param `id`: ArtID unique identifier of the bitmap.
:type `id`: wx.ArtID
:param `client`: ArtClient identifier of the client (i.e. who is asking for the bitmap). This only serves as a hint.
:type `client`: wx.ArtClient
:param `size`: Preferred size of the bitmap. The function may return a bitmap of different dimensions, it will be automatically rescaled to meet client's request.
:type `size`: wx.Size
:rtype: :ref:`wx.Bitmap`
.. note::
This is not part of :ref:`wx.ArtProvider`'s public API, use :meth:`wx.ArtProvider.GetBitmap` or :meth:`wx.ArtProvider.GetIconBundle` or :meth:`wx.ArtProvider.GetIcon` to query :ref:`wx.ArtProvider` for a resource.
.. seealso:: :meth:`CreateIconBundle`
.. method:: CreateIconBundle(self, id, client)
This method is similar to :meth:`CreateBitmap` but can be used when a bitmap (or an icon) exists in several sizes.
:param `id`:
:type `id`: wx.ArtID
:param `client`:
:type `client`: wx.ArtClient
:rtype: :ref:`wx.IconBundle`
.. staticmethod:: Delete(provider)
Delete the given `provider`.
:param `provider`:
:type `provider`: wx.ArtProvider
:rtype: `bool`
.. staticmethod:: GetBitmap(id, client=ART_OTHER, size=DefaultSize)
Query registered providers for bitmap with given ``ID``.
:param `id`: ArtID unique identifier of the bitmap.
:type `id`: wx.ArtID
:param `client`: ArtClient identifier of the client (i.e. who is asking for the bitmap).
:type `client`: wx.ArtClient
:param `size`: Size of the returned bitmap or DefaultSize if size doesn't matter.
:type `size`: wx.Size
:rtype: :ref:`wx.Bitmap`
:returns:
The bitmap if one of registered providers recognizes the ``ID`` or NullBitmap otherwise.
.. staticmethod:: GetIcon(id, client=ART_OTHER, size=DefaultSize)
Same as :meth:`wx.ArtProvider.GetBitmap` , but return a :ref:`wx.Icon` object (or :ref:`wx.NullIcon` on failure).
:param `id`:
:type `id`: wx.ArtID
:param `client`:
:type `client`: wx.ArtClient
:param `size`:
:type `size`: wx.Size
:rtype: :ref:`wx.Icon`
.. staticmethod:: GetIconBundle(id, client=ART_OTHER)
Query registered providers for icon bundle with given ``ID``.
:param `id`: ArtID unique identifier of the icon bundle.
:type `id`: wx.ArtID
:param `client`: ArtClient identifier of the client (i.e. who is asking for the icon bundle).
:type `client`: wx.ArtClient
:rtype: :ref:`wx.IconBundle`
:returns:
The icon bundle if one of registered providers recognizes the ``ID`` or NullIconBundle otherwise.
.. staticmethod:: GetMessageBoxIcon(flags)
Helper used by several generic classes: return the icon corresponding to the standard ICON_INFORMATION/WARNING/ERROR/QUESTION flags (only one can be set)
:param `flags`:
:type `flags`: int
:rtype: :ref:`wx.Icon`
.. staticmethod:: GetMessageBoxIconId(flags)
Helper used by :meth:`GetMessageBoxIcon` : return the art id corresponding to the standard ICON_INFORMATION/WARNING/ERROR/QUESTION flags (only one can be set)
:param `flags`:
:type `flags`: int
:rtype: :ref:`wx.ArtID`
.. staticmethod:: GetNativeSizeHint(client)
Returns native icon size for use specified by `client` hint.
If the platform has no commonly used default for this use or if `client` is not recognized, returns DefaultSize.
:param `client`:
:type `client`: wx.ArtClient
:rtype: :ref:`wx.Size`
.. versionadded:: 2.9.0
.. note::
In some cases, a platform may have `several` appropriate native sizes (for example, ``wx.ART_FRAME_ICON`` for frame icons). In that case, this method returns only one of them, picked reasonably.
.. staticmethod:: GetSizeHint(client, platform_default=False)
Returns a suitable size hint for the given `ArtClient`.
If `platform_default` is ``True``, return a size based on the current platform using :meth:`GetNativeSizeHint` , otherwise return the size from the topmost :ref:`wx.ArtProvider`. `DefaultSize` may be returned if the client doesn't have a specified size, like ``wx.ART_OTHER`` for example.
:param `client`:
:type `client`: wx.ArtClient
:param `platform_default`:
:type `platform_default`: bool
:rtype: :ref:`wx.Size`
.. seealso:: :meth:`GetNativeSizeHint`
.. staticmethod:: HasNativeProvider()
Returns ``True`` if the platform uses native icons provider that should take precedence over any customizations.
This is ``True`` for any platform that has user-customizable icon themes, currently only wxGTK.
A typical use for this method is to decide whether a custom art provider should be plugged in using :meth:`Push` or :meth:`PushBack` .
:rtype: `bool`
.. versionadded:: 2.9.0
.. staticmethod:: Insert(provider)
:param `provider`:
:type `provider`: wx.ArtProvider
.. wxdeprecated::
Use :meth:`PushBack` instead.
.. staticmethod:: Pop()
Remove latest added provider and delete it.
:rtype: `bool`
.. staticmethod:: Push(provider)
Register new art provider and add it to the top of providers stack (i.e.
it will be queried as the first provider).
:param `provider`:
:type `provider`: wx.ArtProvider
.. seealso:: :meth:`PushBack`
.. staticmethod:: PushBack(provider)
Register new art provider and add it to the bottom of providers stack.
In other words, it will be queried as the last one, after all others, including the default provider.
:param `provider`:
:type `provider`: wx.ArtProvider
.. versionadded:: 2.9.0
.. seealso:: :meth:`Push`
.. staticmethod:: Remove(provider)
Remove a provider from the stack if it is on it.
The provider is not deleted, unlike when using :meth:`Delete` .
:param `provider`:
:type `provider`: wx.ArtProvider
:rtype: `bool`
|