class CListBox __init__(self, parent, text, items, max_sizey = None) class CMultiListBox __init__(self, parent, text, items, max_sizey = None, mode = "multiple") Class CListBox represents a listbox control, a list of text lines zero or one of which may be selected by the user. Class CMultiListBox represents a multiple selection list box. For mode "multiple", clicking an item toggles its selected state. For mode "extended", hold down the control key and click the item. The exact multiple selection behavior is native to the platform used. Listboxes may have a vertical scroll bar if all the items do not fit into the space available. Instance Variables wpyParent, wpyText, wpyChildList, wpySizeX/Y, wpyLocX/Y wpySelected, int, readonly after Create() The index (0, 1, 2, ...) of the listbox item which is currently selected, or -1 if there is no selection. Not used for CMultiListBox. wpyListBoxItems, list or tuple of strings, readonly after Create() The list of strings in the listbox; set by "items" in the constructor. May be changed until Create() is called. wpyScrollWidth, int, readonly The width of the vertical scroll bar were there to be one. wpyLineHeight, int, readonly The height of one line in the listbox. The total height of the listbox is this times the number of lines plus the borders. Methods __init__(self, parent, text, items, max_sizey = None) Return a listbox with self.wpySizeX/Y set according to the arguments given. No items are selected (wpySelection == -1). parent, object The view or dialog parent of the control. text, string The name of the list box. This is not visible, but must be a valid Python name because it is used to make the message handler name. items, list A list of strings to appear in the listbox. max_sizey, int or None A maximum height (in pixels) for the listbox. If the listbox exceeds this height, then the scrollbar size is added to the width, and the height is limited to the maximum and rounded to a whole number of lines. Otherwise, the listbox width is equal to the largest item in the list, and the height just fits all the items. A scrollbar may or may not be shown. This option just adds extra width in case it is needed. Create(self) Make the list box visible by calling the underlying GUI. NOTE: Create() may slightly alter self.wpySizeY so that the listbox is an integral number of lines high. SetCurSel(self, index, set = 1) index, int set, boolean Set/unset the current listbox selection for the index "index". The special index -1 unselects all items. The special index -2 selects all items of a CMultiListBox. GetSelItems(self) Return a list of the selected items in the list box, or an empty list if no items are selected. For CListBox, this still returns a list, but you may wish to use self.wpySelected directly. SetAllTabStops(self, stop) int stop Set all tab stops to "stop" character widths. SetTabStops(self, tup) tuple of integers, tup Set the tab stops in the list box according to the tuple of integers tup. Each unit means the width of a character. WpySetItems(self, items, select = None) items, list or tuple of strings selected, int Set the items in the list box to the new list "items". The old items will be replaced. Select the item with index "select", or else no item is selected. Messages No messages are sent to a CMultiListBox instance. These messages are sent to CListBox instances using the command router mechanism. The handler names are generated using wpyText which must be a valid Python name. The "WPYTEXT" below refers to this name. OnListBoxWPYTEXT(self, control) Sent when an item in the list box is selected. OnListBoxDblWPYTEXT(self, control) Sent when the user double clicks an item. Examples list = ["Red", "Green", "Blue", "Purple", "Orange"] # Create a listbox, no scroll bar. CListBox(parent, "colors", list).Create() # Create a listbox in a space 136 pixels high, add scroll bar if required. # The height will be about 136 pixels or less, and rounded to a whole number of lines. CListBox(parent, "colors", list, 136).Create() # Create a listbox with a scroll bar, set the height to 136 pixels. The # actual size may be rounded to prevent partial lines. s = CListBox(parent, "colors", list, 0) s.wpySizeY = 136 s.Create() # Create a custom size listbox. The list of items is # long or unknown, so don't take time to create sizes using it. s = CListBox(parent, "colors", []) s.wpySizeX = my_size_x s.wpySizeY = my_size_y s.wpyListBoxItems = list s.Create() # Create a listbox showing three items. s = CListBox(parent, "colors", list, 0) s.wpySizeY = s.wpyLineHeight * 3 s.Create()