Inheritance diagram for wx.combo.ComboCtrl:
A combo control is a generic combobox that allows totally custom popup. In addition it has other customization features. For instance, position and size of the dropdown button can be changed.
Setting Custom Popup for wx.combo.ComboCtrl:
wx.combo.ComboCtrl needs to be told somehow which control to use and this is done by SetPopupControl(). However, we need something more than just a wx.Control in this method as, for example, we need to call SetStringValue (“initial text value”) and wx.Control doesn’t have such method. So we also need a wx.combo.ComboPopup which is an interface which must be implemented by a control to be usable as a popup.
We couldn’t derive wx.combo.ComboPopup from wx.Control as this would make it impossible to have a class deriving from a wxWidgets control and from it, so instead it is just a mix-in.
Here’s a minimal sample of wx.ListCtrl popup:
class ListCtrlComboPopup(wx.ListCtrl, wx.combo.ComboPopup):
def __init__(self):
# Since we are using multiple inheritance, and don't know yet
# which window is to be the parent, we'll do 2-phase create of
# the ListCtrl instead, and call its Create method later in
# our Create method. (See Create below.)
self.PostCreate(wx.PreListCtrl())
# Also init the ComboPopup base class.
wx.combo.ComboPopup.__init__(self)
def AddItem(self, txt):
self.InsertStringItem(self.GetItemCount(), txt)
def OnMotion(self, evt):
item, flags = self.HitTest(evt.GetPosition())
if item >= 0:
self.Select(item)
self.curitem = item
def OnLeftDown(self, evt):
self.value = self.curitem
self.Dismiss()
# The following methods are those that are overridable from the
# ComboPopup base class.
def Init(self):
""" This is called immediately after construction finishes. You can
use self.GetCombo if needed to get to the ComboCtrl instance. """
self.value = -1
self.curitem = -1
def Create(self, parent):
""" Create the popup child control. Return True for success. """
wx.ListCtrl.Create(self, parent,
style=wx.LC_LIST|wx.LC_SINGLE_SEL|wx.SIMPLE_BORDER)
self.Bind(wx.EVT_MOTION, self.OnMotion)
self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
return True
def GetControl(self):
""" Return the widget that is to be used for the popup. """
return self
def SetStringValue(self, val):
""" Called just prior to displaying the popup, you can use it to
'select' the current item. """
idx = self.FindItem(-1, val)
if idx != wx.NOT_FOUND:
self.Select(idx)
def GetStringValue(self):
""" Return a string representation of the current item. """
if self.value >= 0:
return self.GetItemText(self.value)
return ""
def OnPopup(self):
""" Called immediately after the popup is shown. """
wx.combo.ComboPopup.OnPopup(self)
def OnDismiss(self):
" Called when popup is dismissed. """
wx.combo.ComboPopup.OnDismiss(self)
Here’s how you would create and populate it in a dialog/frame constructor:
cc = wx.combo.ComboCtrl(self, style=0, size=(250,-1))
# Create a Popup
popup = ListCtrlComboPopup()
# Associate them with each other. This also triggers the
# creation of the ListCtrl.
cc.SetPopupControl(popup)
# Add some items to the listctrl.
for x in range(75):
popup.AddItem("Item-%02d" % x)
wx.combo.BitmapComboBox, wx.combo.ComboCtrl, wx.combo.OwnerDrawnComboBox
Window Style | Description |
---|---|
wx.CB_READONLY | Same as wx.CB_DROPDOWN but only the strings specified as the combobox choices can be selected, it is impossible to select (even from a program) a string which is not in the choices list. |
wx.CB_SORT | Sorts the entries in the list alphabetically. |
wx.TE_PROCESS_ENTER | The control will generate the event wx.EVT_COMMAND_TEXT_ENTER (otherwise pressing Enter key is either processed internally by the control or used for navigation between dialog controls). Windows only. |
wx.combo.CC_SPECIAL_DCLICK | Double-clicking triggers a call to popup’s OnComboDoubleClick. Actual behaviour is defined by a derived class. For instance, wx.combo.OwnerDrawnComboBox will cycle an item. This style only applies if wx.CB_READONLY is used as well. |
wx.combo.CC_STD_BUTTON | Drop button will behave more like a standard push button. |
Event Name | Description |
---|---|
wx.EVT_TEXT(id, func) | Process a wx.wxEVT_COMMAND_TEXT_UPDATED event, when the text changes. |
wx.EVT_TEXT_ENTER(id, func) | Process a wx.wxEVT_COMMAND_TEXT_ENTER event, when RETURN is pressed in the combo control. |
Constructor, creating and showing a combo control.
Parameters:
Returns:
Implement in derived class to create a drop-down animation. Returns True if finished immediately. Otherwise the popup is only shown when the derived class calls DoShowPopup.
flags are same as for DoShowPopup
Parameters:
Returns:
bool
Creates the combo control for two-step construction. Derived classes should call or replace this function.
Parameters:
Returns:
bool
This member function is not normally called in application code. Instead, it must be called in a derived class to make sure popup is properly shown after a popup animation has finished (but only if AnimateShow did not finish the animation within it’s function scope).
flags may be one of the following bits:
Flags | Description |
---|---|
wx.combo.ComboCtrl.ShowBelow | Showing popup below the control |
wx.combo.ComboCtrl.ShowAbove | Showing popup above the control |
wx.combo.ComboCtrl.CanDeferShow | Can only return True from AnimateShow if this is set |
Parameters:
Enables or disables popup animation, if any, depending on the value of the argument.
Parameters:
Returns disabled button bitmap that has been set with SetButtonBitmaps.
Returns:
Returns button mouse hover bitmap that has been set with SetButtonBitmaps.
Returns:
Returns default button bitmap that has been set with SetButtonBitmaps.
Returns:
Returns depressed button bitmap that has been set with SetButtonBitmaps.
Returns:
Note
it’s not necessarily a wx.Button or wx.BitmapButton.
Returns custom painted area in control.
Returns:
int
See also
Returns features supported by wx.combo.ComboCtrl.
Value returned is a combination of following flags (in wx.combo.ComboCtrlFeatures structure):
Feature | Description |
---|---|
MovableButton | Button can be on either side of the control. |
BitmapButton | Button may be replaced with bitmap. |
ButtonSpacing | Button can have spacing. |
TextIndent | SetTextIndent works. |
PaintControl | Combo control itself can be custom painted. |
PaintWritable | A variable- width area in front of writable combo control’s textctrl can be custom painted. |
Borderless | wx.NO_BORDER window style works. |
All | All of the above. |
Returns:
int
Returns the insertion point for the combo control’s text field.
Returns:
long
Note
Under wxMSW, this function always returns 0 if the combo control doesn’t have the focus.
Returns the last position in the combo control text field.
Returns:
long
Returns current popup interface that has been set with SetPopupControl.
Returns:
Get the text control which is part of the combo control.
Returns:
Returns actual indentation in pixels.
Returns:
int
Returns area covered by the text field (includes everything except borders and the dropdown button).
Returns:
Returns text representation of the current value. For writable combo control it always returns the value in the text field.
Returns:
string
Returns True if given key combination should toggle the popup.
Parameters:
Returns:
bool
Returns True if the popup is currently shown
Returns:
bool
Returns True if the popup window is in the given state. Possible values are:
Popup State | Description |
---|---|
wx.combo.ComboCtrl.Hidden | Popup window is hidden. |
wx.combo.ComboCtrl.Animating | Popup window is being shown, but the popup animation has not yet finished. |
wx.combo.ComboCtrl.Visible | Popup window is fully visible. |
Parameters:
Returns:
bool
Prepare background of combo control or an item in a dropdown list in a way typical on platform. This includes painting the focus/disabled background and setting the clipping region.
Unless you plan to paint your own focus indicator, you should always call this in your PaintComboControl implementation.
In addition, it sets pen and text colour to what looks good and proper against the background.
flags are the same as wx.RendererNative flags:
Flags | Description |
---|---|
wx.CONTROL_ISSUBMENU | drawing a list item instead of combo control |
wx.CONTROL_SELECTED | list item is selected |
wx.CONTROL_DISABLED | control/item is disabled |
Parameters:
Removes the text between the two positions in the combo control text field.
Parameters:
Replaces the text between two positions with the given text, in the combo control text field.
Parameters:
Sets custom dropdown button graphics.
Parameters:
Sets size and position of dropdown button.
Parameters:
Set width, in pixels, of custom painted area in control without wx.CB_READONLY style. In read-only wx.combo.OwnerDrawnComboBox, this is used to indicate area that is not covered by the focus rectangle.
Parameters:
Sets the insertion point in the text field.
Parameters:
Parameters:
Set side of the control to which the popup will align itself. Valid values are wx.LEFT, wx.RIGHT and 0.
The default value 0 means that the most appropriate side is used (which, currently, is always wx.LEFT).
Parameters:
Set popup interface class derived from wx.combo.ComboPopup.
This method should be called as soon as possible after the control has been created, unless OnButtonClick has been overridden.
Parameters:
Extends popup size horizontally, relative to the edges of the combo control.
Parameters:
Note
Popup minimum width may override arguments.
Sets preferred maximum height of the popup.
Parameters:
Note
Value -1 indicates the default.
Sets minimum width of the popup. If wider than combo control, it will extend to the left.
Parameters:
Note
Value -1 indicates the default.
Sets the text for the text field without affecting the popup. Thus, unlike SetValue, it works equally well with combo control using wx.CB_READONLY style.
Parameters:
This will set the space in pixels between left edge of the control and the text, regardless whether control is read-only or not.
Value -1 can be given to indicate platform default.
Parameters:
Sets the text for the combo control text field.
Parameters:
Note
For a combo control with wx.CB_READONLY style the string must be accepted by the popup (for instance, exist in the dropdown list), otherwise the call to SetValue is ignored.
Same as SetValue, but also sends wx.CommandEvent of type wx.wxEVT_COMMAND_TEXT_UPDATED if withEvent is True.
Parameters:
Returns True if focus indicator should be drawn in the control.
Returns:
bool
Enable or disable usage of an alternative popup window, which guarantees ability to focus the popup control, and allows common native controls to function normally.
This alternative popup window is usually a wx.Dialog, and as such, when it is shown, its parent top-level window will appear as if the focus has been lost from it.
Parameters: