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 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973
|
.. 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.VListBox:
==========================================================================================================================================
|phoenix_title| **wx.VListBox**
==========================================================================================================================================
:ref:`wx.VListBox` is a ListBox-like control with the following two main differences from a regular :ref:`wx.ListBox`: it can have an arbitrarily huge number of items because it doesn't store them itself but uses the :meth:`~wx.VListBox.OnDrawItem` callback to draw them (so it is a virtual listbox) and its items can have variable height as determined by :meth:`~wx.VListBox.OnMeasureItem` (so it is also a listbox with the lines of variable height).
Also, as a consequence of its virtual nature, it doesn't have any methods to append or insert items in it as it isn't necessary to do it: you just have to call :meth:`~wx.VListBox.SetItemCount` to tell the control how many items it should display. Of course, this also means that you will never use this class directly because it has pure virtual functions, but will need to derive your own class from it (for example, :ref:`wx.html.HtmlListBox`).
However it emits the same events as :ref:`wx.ListBox` and the same event macros may be used with it. Since :ref:`wx.VListBox` does not store its items itself, the events will only contain the index, not any contents such as the string of an item.
.. seealso:: :ref:`wx.html.SimpleHtmlListBox`, :ref:`wx.html.HtmlListBox`
|
|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>VListBox</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.VListBox_inheritance.png" alt="Inheritance diagram of VListBox" 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.VScrolledWindow.html" title="wx.VScrolledWindow" alt="" coords="105,315,253,344"/> <area shape="rect" id="node9" href="wx.VListBox.html" title="wx.VListBox" alt="" coords="131,392,228,421"/> <area shape="rect" id="node2" href="wx.Panel.html" title="wx.Panel" alt="" coords="70,237,145,267"/> <area shape="rect" id="node3" href="wx.VarVScrollHelper.html" title="wx.VarVScrollHelper" alt="" coords="179,237,327,267"/> <area shape="rect" id="node4" href="wx.Object.html" title="wx.Object" alt="" coords="5,5,87,35"/> <area shape="rect" id="node6" href="wx.EvtHandler.html" title="wx.EvtHandler" alt="" coords="48,83,159,112"/> <area shape="rect" id="node5" href="wx.Window.html" title="wx.Window" alt="" coords="59,160,148,189"/> <area shape="rect" id="node7" href="wx.VarScrollHelperBase.html" title="wx.VarScrollHelperBase" alt="" coords="173,160,344,189"/> <area shape="rect" id="node8" href="wx.Trackable.html" title="wx.Trackable" alt="" coords="112,5,213,35"/> </map>
</p>
|
|sub_classes| Known Subclasses
==============================
:ref:`wx.html.HtmlListBox`
|
|method_summary| Methods Summary
================================
================================================================================ ================================================================================
:meth:`~wx.VListBox.__init__` Default constructor, you must call :meth:`~VListBox.Create` later.
:meth:`~wx.VListBox.Clear` Deletes all items from the control.
:meth:`~wx.VListBox.Create` Creates the control.
:meth:`~wx.VListBox.DeselectAll` Deselects all the items in the listbox.
:meth:`~wx.VListBox.GetFirstSelected` Returns the index of the first selected item in the listbox or ``NOT_FOUND`` if no items are currently selected.
:meth:`~wx.VListBox.GetItemCount` Get the number of items in the control.
:meth:`~wx.VListBox.GetItemRect` Returns the rectangle occupied by this item in physical coordinates.
:meth:`~wx.VListBox.GetMargins` Returns the margins used by the control.
:meth:`~wx.VListBox.GetNextSelected` Returns the index of the next selected item or ``NOT_FOUND`` if there are no more.
:meth:`~wx.VListBox.GetSelectedCount` Returns the number of the items currently selected.
:meth:`~wx.VListBox.GetSelection` Get the currently selected item or ``NOT_FOUND`` if there is no selection.
:meth:`~wx.VListBox.GetSelectionBackground` Returns the background colour used for the selected cells.
:meth:`~wx.VListBox.HasMultipleSelection` Returns ``True`` if the listbox was created with ``LB_MULTIPLE`` style and so supports multiple selection or ``False`` if it is a single selection listbox.
:meth:`~wx.VListBox.IsCurrent` Returns ``True`` if this item is the current one, ``False`` otherwise.
:meth:`~wx.VListBox.IsSelected` Returns ``True`` if this item is selected, ``False`` otherwise.
:meth:`~wx.VListBox.OnDrawBackground` This method is used to draw the item's background and, maybe, a border around it.
:meth:`~wx.VListBox.OnDrawItem` The derived class must implement this function to actually draw the item with the given index on the provided DC.
:meth:`~wx.VListBox.OnDrawSeparator` This method may be used to draw separators between the lines.
:meth:`~wx.VListBox.OnMeasureItem` The derived class must implement this method to return the height of the specified item (in pixels).
:meth:`~wx.VListBox.Select` Selects or deselects the specified item which must be valid (i.e. not equal to ``NOT_FOUND`` ).
:meth:`~wx.VListBox.SelectAll` Selects all the items in the listbox.
:meth:`~wx.VListBox.SelectRange` Selects all items in the specified range which may be given in any order.
:meth:`~wx.VListBox.SetItemCount` Set the number of items to be shown in the control.
:meth:`~wx.VListBox.SetMargins` Set the margins: horizontal margin is the distance between the window border and the item contents while vertical margin is half of the distance between items.
:meth:`~wx.VListBox.SetSelection` Set the selection to the specified item, if it is -1 the selection is unset.
:meth:`~wx.VListBox.SetSelectionBackground` Sets the colour to be used for the selected cells background.
:meth:`~wx.VListBox.Toggle` Toggles the state of the specified `item`, i.e. selects it if it was unselected and deselects it if it was selected.
================================================================================ ================================================================================
|
|property_summary| Properties Summary
=====================================
================================================================================ ================================================================================
:attr:`~wx.VListBox.ItemCount` See :meth:`~wx.VListBox.GetItemCount` and :meth:`~wx.VListBox.SetItemCount`
:attr:`~wx.VListBox.Margins` See :meth:`~wx.VListBox.GetMargins` and :meth:`~wx.VListBox.SetMargins`
:attr:`~wx.VListBox.SelectedCount` See :meth:`~wx.VListBox.GetSelectedCount`
:attr:`~wx.VListBox.Selection` See :meth:`~wx.VListBox.GetSelection` and :meth:`~wx.VListBox.SetSelection`
:attr:`~wx.VListBox.SelectionBackground` See :meth:`~wx.VListBox.GetSelectionBackground` and :meth:`~wx.VListBox.SetSelectionBackground`
================================================================================ ================================================================================
|
|api| Class API
===============
.. class:: wx.VListBox(VScrolledWindow)
**Possible constructors**::
VListBox()
VListBox(parent, id=ID_ANY, pos=DefaultPosition, size=DefaultSize,
style=0, name=VListBoxNameStr)
VListBox is a ListBox-like control with the following two main
differences from a regular ListBox: it can have an arbitrarily huge
number of items because it doesn't store them itself but uses the
OnDrawItem() callback to draw them (so it is a virtual listbox) and
its items can have variable height as determined by OnMeasureItem()
(so it is also a listbox with the lines of variable height).
.. method:: __init__(self, *args, **kw)
|overload| Overloaded Implementations:
**~~~**
**__init__** `(self)`
Default constructor, you must call :meth:`Create` later.
**~~~**
**__init__** `(self, parent, id=ID_ANY, pos=DefaultPosition, size=DefaultSize, style=0, name=VListBoxNameStr)`
Normal constructor which calls :meth:`Create` internally.
:param `parent`:
:type `parent`: wx.Window
:param `id`:
:type `id`: wx.WindowID
:param `pos`:
:type `pos`: wx.Point
:param `size`:
:type `size`: wx.Size
:param `style`:
:type `style`: long
:param `name`:
:type `name`: string
**~~~**
.. method:: Clear(self)
Deletes all items from the control.
.. method:: Create(self, parent, id=ID_ANY, pos=DefaultPosition, size=DefaultSize, style=0, name=VListBoxNameStr)
Creates the control.
To finish creating it you also should call :meth:`SetItemCount` to let it know about the number of items it contains.
The only special style which may be used with :ref:`wx.VListBox` is ``LB_MULTIPLE`` which indicates that the listbox should support multiple selection.
:param `parent`:
:type `parent`: wx.Window
:param `id`:
:type `id`: wx.WindowID
:param `pos`:
:type `pos`: wx.Point
:param `size`:
:type `size`: wx.Size
:param `style`:
:type `style`: long
:param `name`:
:type `name`: string
:rtype: `bool`
:returns:
``True`` on success or ``False`` if the control couldn't be created.
.. method:: DeselectAll(self)
Deselects all the items in the listbox.
This method is only valid for multi selection listboxes.
:rtype: `bool`
:returns:
``True`` if any items were changed, i.e. if there had been any selected items before, or ``False`` if all the items were already deselected.
.. seealso:: :meth:`SelectAll` , :meth:`Select`
.. method:: GetFirstSelected(self)
Returns the index of the first selected item in the listbox or ``NOT_FOUND`` if no items are currently selected.
`cookie` is an opaque parameter which should be passed to the subsequent calls to :meth:`GetNextSelected` . It is needed in order to allow parallel iterations over the selected items.
Here is a typical example of using these functions:
::
item, cookie = vlbox.GetFirstSelected()
while item != wx.NOT_FOUND:
# ... process item ...
item, cookie = vlbox.GetNextSelected(cookie)
This method is only valid for multi selection listboxes.
:rtype: `tuple`
:returns:
( `int`, `cookie` )
.. method:: GetItemCount(self)
Get the number of items in the control.
:rtype: `int`
.. seealso:: :meth:`SetItemCount`
.. method:: GetItemRect(self, item)
Returns the rectangle occupied by this item in physical coordinates.
If the item is not currently visible, returns an empty rectangle.
:param `item`:
:type `item`: int
:rtype: :ref:`wx.Rect`
.. versionadded:: 2.9.0
.. method:: GetMargins(self)
Returns the margins used by the control.
The ``x`` field of the returned point is the horizontal margin and the ``y`` field is the vertical one.
:rtype: :ref:`wx.Point`
.. seealso:: :meth:`SetMargins`
.. method:: GetNextSelected(self, cookie)
Returns the index of the next selected item or ``NOT_FOUND`` if there are no more.
This method is only valid for multi selection listboxes.
:param `cookie`:
:type `cookie`: long
:rtype: `tuple`
:returns:
( `int`, `cookie` )
.. seealso:: :meth:`GetFirstSelected`
.. method:: GetSelectedCount(self)
Returns the number of the items currently selected.
It is valid for both single and multi selection controls. In the former case it may only return 0 or 1 however.
:rtype: `int`
.. seealso:: :meth:`IsSelected` , :meth:`GetFirstSelected` , :meth:`GetNextSelected`
.. method:: GetSelection(self)
Get the currently selected item or ``NOT_FOUND`` if there is no selection.
:rtype: `int`
.. method:: GetSelectionBackground(self)
Returns the background colour used for the selected cells.
By default the standard system colour is used.
:rtype: :ref:`wx.Colour`
.. seealso:: :meth:`wx.SystemSettings.GetColour` , :meth:`SetSelectionBackground`
.. method:: HasMultipleSelection(self)
Returns ``True`` if the listbox was created with ``LB_MULTIPLE`` style and so supports multiple selection or ``False`` if it is a single selection listbox.
:rtype: `bool`
.. method:: IsCurrent(self, item)
Returns ``True`` if this item is the current one, ``False`` otherwise.
The current item is always the same as selected one for the single selection listbox and in this case this method is equivalent to :meth:`IsSelected` but they are different for multi selection listboxes where many items may be selected but only one (at most) is current.
:param `item`:
:type `item`: int
:rtype: `bool`
.. method:: IsSelected(self, item)
Returns ``True`` if this item is selected, ``False`` otherwise.
:param `item`:
:type `item`: int
:rtype: `bool`
.. method:: OnDrawBackground(self, dc, rect, n)
This method is used to draw the item's background and, maybe, a border around it.
The base class version implements a reasonable default behaviour which consists in drawing the selected item with the standard background colour and drawing a border around the item if it is either selected or current.
:param `dc`:
:type `dc`: wx.DC
:param `rect`:
:type `rect`: wx.Rect
:param `n`:
:type `n`: int
.. todo:: Change this function signature to non-const.
.. method:: OnDrawItem(self, dc, rect, n)
The derived class must implement this function to actually draw the item with the given index on the provided DC.
:param `dc`: The device context to use for drawing.
:type `dc`: wx.DC
:param `rect`: The bounding rectangle for the item being drawn (DC clipping region is set to this rectangle before calling this function).
:type `rect`: wx.Rect
:param `n`: The index of the item to be drawn.
:type `n`: int
.. todo:: Change this function signature to non-const.
.. method:: OnDrawSeparator(self, dc, rect, n)
This method may be used to draw separators between the lines.
The rectangle passed to it may be modified, typically to deflate it a bit before passing to :meth:`OnDrawItem` .
The base class version of this method doesn't do anything.
:param `dc`: The device context to use for drawing.
:type `dc`: wx.DC
:param `rect`: The bounding rectangle for the item.
:type `rect`: wx.Rect
:param `n`: The index of the item.
:type `n`: int
.. todo:: Change this function signature to non-const.
.. method:: OnMeasureItem(self, n)
The derived class must implement this method to return the height of the specified item (in pixels).
:param `n`:
:type `n`: int
:rtype: :ref:`wx.Coord`
.. method:: Select(self, item, select=True)
Selects or deselects the specified item which must be valid (i.e. not equal to ``NOT_FOUND`` ).
This function is only valid for the multiple selection listboxes, use :meth:`SetSelection` for the single selection ones.
:param `item`:
:type `item`: int
:param `select`:
:type `select`: bool
:rtype: `bool`
:returns:
``True`` if the items selection status has changed or ``False`` otherwise.
.. method:: SelectAll(self)
Selects all the items in the listbox.
This method is only valid for multi selection listboxes.
:rtype: `bool`
:returns:
``True`` if any items were changed, i.e. if there had been any unselected items before, or ``False`` if all the items were already selected.
.. seealso:: :meth:`DeselectAll` , :meth:`Select`
.. method:: SelectRange(self, from_, to_)
Selects all items in the specified range which may be given in any order.
This method is only valid for multi selection listboxes.
:param `from_`:
:type `from_`: int
:param `to_`:
:type `to_`: int
:rtype: `bool`
:returns:
``True`` if the items selection status has changed or ``False`` otherwise.
.. seealso:: :meth:`SelectAll` , :meth:`Select`
.. method:: SetItemCount(self, count)
Set the number of items to be shown in the control.
This is just a synonym for :meth:`wx.VScrolledWindow.SetRowCount` .
:param `count`:
:type `count`: int
.. method:: SetMargins(self, *args, **kw)
Set the margins: horizontal margin is the distance between the window border and the item contents while vertical margin is half of the distance between items.
By default both margins are 0.
|overload| Overloaded Implementations:
**~~~**
**SetMargins** `(self, pt)`
:param `pt`:
:type `pt`: wx.Point
**~~~**
**SetMargins** `(self, x, y)`
:param `x`:
:type `x`: int
:param `y`:
:type `y`: int
**~~~**
.. method:: SetSelection(self, selection)
Set the selection to the specified item, if it is -1 the selection is unset.
The selected item will be automatically scrolled into view if it isn't currently visible.
This method may be used both with single and multiple selection listboxes.
:param `selection`:
:type `selection`: int
.. method:: SetSelectionBackground(self, col)
Sets the colour to be used for the selected cells background.
The background of the standard cells may be changed by simply calling :meth:`wx.Window.SetBackgroundColour` .
:param `col`:
:type `col`: wx.Colour
.. note::
Using a non-default background colour may result in control having an appearance different from the similar native controls and should be avoided in general.
.. seealso:: :meth:`GetSelectionBackground`
.. method:: Toggle(self, item)
Toggles the state of the specified `item`, i.e. selects it if it was unselected and deselects it if it was selected.
This method is only valid for multi selection listboxes.
:param `item`:
:type `item`: int
.. seealso:: :meth:`Select`
.. attribute:: ItemCount
See :meth:`~wx.VListBox.GetItemCount` and :meth:`~wx.VListBox.SetItemCount`
.. attribute:: Margins
See :meth:`~wx.VListBox.GetMargins` and :meth:`~wx.VListBox.SetMargins`
.. attribute:: SelectedCount
See :meth:`~wx.VListBox.GetSelectedCount`
.. attribute:: Selection
See :meth:`~wx.VListBox.GetSelection` and :meth:`~wx.VListBox.SetSelection`
.. attribute:: SelectionBackground
See :meth:`~wx.VListBox.GetSelectionBackground` and :meth:`~wx.VListBox.SetSelectionBackground`
|