# wx.RendererNative¶

First, a brief introduction to wx.RendererNative and why it is needed.

Usually wxWidgets uses the underlying low level GUI system to draw all the controls - this is what we mean when we say that it is a “native” framework. However not all controls exist under all (or even any) platforms and in this case wxWidgets provides a default, generic, implementation of them written in wxWidgets itself.

These controls don’t have the native appearance if only the standard line drawing and other graphics primitives are used, because the native appearance is different under different platforms while the lines are always drawn in the same way.

This is why we have renderers: wx.RendererNative is a class which virtualizes the drawing, i.e. it abstracts the drawing operations and allows you to draw say, a button, without caring about exactly how this is done. Of course, as we can draw the button differently in different renderers, this also allows us to emulate the native look and feel.

So the renderers work by exposing a large set of high-level drawing functions which are used by the generic controls. There is always a default global renderer but it may be changed or extended by the user, see Render Sample.

All drawing functions take some standard parameters:

• win - The window being drawn. It is normally not used and when it is it should only be used as a generic wx.Window (in order to get its low level handle, for example), but you should not assume that it is of some given type as the same renderer function may be reused for drawing different kinds of control.

• dc - The wx.DC to draw on. Only this device context should be used for drawing. It is not necessary to restore pens and brushes for it on function exit but, on the other hand, you shouldn’t assume that it is in any specific state on function entry: the rendering functions should always prepare it.

• rect - The bounding rectangle for the element to be drawn.

• flags - The optional flags (none by default) which can be a combination of the CONTROL_FLAGS.

Note that each drawing function restores the wx.DC attributes if it changes them, so it is safe to assume that the same pen, brush and colours that were active before the call to this function are still in effect after it.

## Class Hierarchy¶

Inheritance diagram for class RendererNative:

## Known Subclasses¶

wx.DelegateRendererNative

## Methods Summary¶

 DrawCheckBox Draw a check box. DrawCheckMark Draw a check mark. DrawChoice Draw a native wx.Choice. DrawCollapseButton Draw a collapse button. DrawComboBox Draw a native wx.ComboBox. DrawComboBoxDropButton Draw a button like the one used by wx.ComboBox to show a drop down window. DrawDropArrow Draw a drop down arrow that is suitable for use outside a combo box. DrawFocusRect Draw a focus rectangle using the specified rectangle. DrawGauge Draw a progress bar in the specified rectangle. DrawHeaderButton Draw the header control button (used, for example, by wx.ListCtrl). DrawHeaderButtonContents Draw the contents of a header control button (label, sort arrows, etc.). DrawItemSelectionRect Draw a selection rectangle underneath the text as used e.g. DrawItemText Draw item text in the correct color based on selection status. DrawPushButton Draw a blank push button that looks very similar to wx.Button. DrawRadioBitmap Draw a native wx.RadioButton bitmap. DrawSplitterBorder Draw the border for sash window: this border must be such that the sash drawn by DrawSplitterSash blends into it well. DrawSplitterSash Draw a sash. DrawTextCtrl Draw a native wx.TextCtrl frame. DrawTitleBarBitmap Draw a title bar button in the given state. DrawTreeItemButton Draw the expanded/collapsed icon for a tree control item. Get Return the currently used renderer. GetCheckBoxSize Returns the size of a check box. GetCheckMarkSize Returns the size of a check mark. GetCollapseButtonSize Returns the size of a collapse button. GetDefault Return the default (native) implementation for this platform – this is also the one used by default but this may be changed by calling Set in which case the return value of this method may be different from the return value of Get . GetExpanderSize Returns the size of the expander used in tree-like controls. GetGeneric Return the generic implementation of the renderer. GetHeaderButtonHeight Returns the height of a header button, either a fixed platform height if available, or a generic height based on the win window’s font. GetHeaderButtonMargin Returns the horizontal margin on the left and right sides of header button’s label. GetSplitterParams Get the splitter parameters, see wx.SplitterRenderParams. GetVersion This function is used for version checking: Load refuses to load any shared libraries implementing an older or incompatible version. Load Load the renderer from the specified DLL, the returned pointer must be deleted by caller if not None when it is not used any more. Set Set the renderer to use, passing None reverts to using the default renderer (the global renderer must always exist).

## Class API¶

class wx.RendererNative(object)

First, a brief introduction to RendererNative and why it is needed.

### Methods¶

DrawCheckBox(self, win, dc, rect, flags=0)

Draw a check box.

flags may have the CONTROL_CHECKED , CONTROL_CURRENT or CONTROL_UNDETERMINED bit set, see CONTROL_FLAGS.

Parameters

DrawCheckMark(self, win, dc, rect, flags=0)

Draw a check mark.

flags may have the CONTROL_DISABLED bit set, see CONTROL_FLAGS.

Parameters

New in version 4.1/wxWidgets-3.1.3.

DrawChoice(self, win, dc, rect, flags=0)

Draw a native wx.Choice.

Parameters

DrawCollapseButton(self, win, dc, rect, flags=0)

Draw a collapse button.

flags may have the CONTROL_EXPANDED or CONTROL_CURRENT bit set, see CONTROL_FLAGS.

Parameters

New in version 4.1/wxWidgets-3.1.0.

DrawComboBox(self, win, dc, rect, flags=0)

Draw a native wx.ComboBox.

Parameters

DrawComboBoxDropButton(self, win, dc, rect, flags=0)

Draw a button like the one used by wx.ComboBox to show a drop down window.

The usual appearance is a downwards pointing arrow.

flags may have the CONTROL_PRESSED or CONTROL_CURRENT bit set, see CONTROL_FLAGS.

Parameters

DrawDropArrow(self, win, dc, rect, flags=0)

Draw a drop down arrow that is suitable for use outside a combo box.

Arrow will have transparent background.

rect is not entirely filled by the arrow. Instead, you should use bounding rectangle of a drop down button which arrow matches the size you need.

flags may have the CONTROL_PRESSED or CONTROL_CURRENT bit set, see CONTROL_FLAGS.

Parameters

DrawFocusRect(self, win, dc, rect, flags=0)

Draw a focus rectangle using the specified rectangle.

The only supported flags is CONTROL_SELECTED for items which are selected. see CONTROL_FLAGS.

Parameters

DrawGauge(self, win, dc, rect, value, max, flags=0)

Draw a progress bar in the specified rectangle.

The value and max arguments determine the part of the progress bar that is drawn as being filled in, max must be strictly positive and value must be between 0 and max.

CONTROL_SPECIAL must be set in flags for the vertical gauges.

Parameters

New in version 4.1/wxWidgets-3.1.0.

DrawHeaderButton(self, win, dc, rect, flags=0, sortArrow=HDR_SORT_ICON_NONE, params=None)

Draw the header control button (used, for example, by wx.ListCtrl).

Depending on platforms the flags parameter may support the CONTROL_SELECTED CONTROL_DISABLED and CONTROL_CURRENT bits, see CONTROL_FLAGS.

Parameters
Return type

int

Returns

The optimal width to contain the unabbreviated label text or bitmap, the sort arrow if present, and internal margins.

DrawHeaderButtonContents(self, win, dc, rect, flags=0, sortArrow=HDR_SORT_ICON_NONE, params=None)

Draw the contents of a header control button (label, sort arrows, etc.).

This function is normally only called by DrawHeaderButton .

Depending on platforms the flags parameter may support the CONTROL_SELECTED CONTROL_DISABLED and CONTROL_CURRENT bits, see CONTROL_FLAGS.

Parameters
Return type

int

Returns

The optimal width to contain the unabbreviated label text or bitmap, the sort arrow if present, and internal margins.

DrawItemSelectionRect(self, win, dc, rect, flags=0)

Draw a selection rectangle underneath the text as used e.g.

in a wx.ListCtrl.

The supported flags are CONTROL_SELECTED for items which are selected (e.g. often a blue rectangle) and CONTROL_CURRENT for the item that has the focus (often a dotted line around the item’s text). CONTROL_FOCUSED may be used to indicate if the control has the focus (otherwise the selection rectangle is e.g. often grey and not blue). This may be ignored by the renderer or deduced by the code directly from the win. Additionally CONTROL_CELL may be used to draw a cell inside a bigger selection area.

Parameters

DrawItemText(self, win, dc, text, rect, align=ALIGN_LEFT|ALIGN_TOP, flags=0, ellipsizeMode=ELLIPSIZE_END)

Draw item text in the correct color based on selection status.

Background of the text should be painted with DrawItemSelectionRect .

The supported flags are CONTROL_SELECTED for items which are selected. CONTROL_FOCUSED may be used to indicate if the control has the focus. CONTROL_DISABLED may be used to indicate if the control is disabled.

Parameters

New in version 4.1/wxWidgets-3.1.0.

DrawPushButton(self, win, dc, rect, flags=0)

Draw a blank push button that looks very similar to wx.Button.

flags may have the CONTROL_PRESSED , CONTROL_CURRENT or CONTROL_ISDEFAULT bit set, see CONTROL_FLAGS.

Parameters

DrawRadioBitmap(self, win, dc, rect, flags=0)

Parameters

DrawSplitterBorder(self, win, dc, rect, flags=0)

Draw the border for sash window: this border must be such that the sash drawn by DrawSplitterSash blends into it well.

Parameters

DrawSplitterSash(self, win, dc, size, position, orient, flags=0)

Draw a sash.

The orient parameter defines whether the sash should be vertical or horizontal and how the position should be interpreted.

Parameters

DrawTextCtrl(self, win, dc, rect, flags=0)

Draw a native wx.TextCtrl frame.

Parameters

DrawTitleBarBitmap(self, win, dc, rect, button, flags=0)

Draw a title bar button in the given state.

DrawTreeItemButton(self, win, dc, rect, flags=0)

Draw the expanded/collapsed icon for a tree control item.

To draw an expanded button the flags parameter must contain CONTROL_EXPANDED bit, see CONTROL_FLAGS.

Parameters

static Get()

Return the currently used renderer.

Return type

wx.RendererNative

GetCheckBoxSize(self, win, flags=0)

Returns the size of a check box.

Parameters
• win (wx.Window) – A valid, i.e. non-null, window pointer which is used to get the theme defining the checkbox size under some platforms.

• flags (int) – The only acceptable flag is CONTROL_CELL which means that just the size of the checkbox itself is returned, without any margins that are included by default. This parameter is only available in wxWidgets 3.1.4 or later.

Return type

wx.Size

GetCheckMarkSize(self, win)

Returns the size of a check mark.

Parameters

win (wx.Window) – A valid, i.e. non-null, window pointer which is used to get the theme defining the checkmark size under some platforms.

Return type

wx.Size

New in version 4.1/wxWidgets-3.1.3.

GetCollapseButtonSize(self, win, dc)

Returns the size of a collapse button.

Parameters
Return type

wx.Size

New in version 4.1/wxWidgets-3.1.0.

static GetDefault()

Return the default (native) implementation for this platform – this is also the one used by default but this may be changed by calling Set in which case the return value of this method may be different from the return value of Get .

Return type

wx.RendererNative

GetExpanderSize(self, win)

Returns the size of the expander used in tree-like controls.

Parameters

win (wx.Window) – A valid, i.e. non-null, window pointer which is used to get the theme defining the expander size under some platforms.

Return type

wx.Size

New in version 4.1/wxWidgets-3.1.3.

static GetGeneric()

Return the generic implementation of the renderer.

Under some platforms, this is the default renderer implementation, others have platform-specific default renderer which can be retrieved by calling GetDefault .

Return type

wx.RendererNative

GetHeaderButtonHeight(self, win)

Returns the height of a header button, either a fixed platform height if available, or a generic height based on the win window’s font.

Parameters

win (wx.Window) –

Return type

int

GetHeaderButtonMargin(self, win)

Returns the horizontal margin on the left and right sides of header button’s label.

Parameters

win (wx.Window) –

Return type

int

New in version 2.9.2.

GetSplitterParams(self, win)

Get the splitter parameters, see wx.SplitterRenderParams.

The win parameter should be a wx.SplitterWindow.

Parameters

win (wx.Window) –

Return type

wx.SplitterRenderParams

GetVersion(self)

This function is used for version checking: Load refuses to load any shared libraries implementing an older or incompatible version.

Return type

wx.RendererVersion

Note

The implementation of this method is always the same in all renderers (simply construct wx.RendererVersion using the RendererVersion::Current_XXX values), but it has to be in the derived, not base, class, to detect mismatches between the renderers versions and so you have to implement it anew in all renderers.

static Load(name)

Load the renderer from the specified DLL, the returned pointer must be deleted by caller if not None when it is not used any more.

The name should be just the base name of the renderer and not the full name of the DLL file which is constructed differently (using DynamicLibrary.CanonicalizePluginName ) on different systems.

Parameters

name (string) –

Return type

wx.RendererNative

static Set(renderer)

Set the renderer to use, passing None reverts to using the default renderer (the global renderer must always exist).

Return the previous renderer used with Set or None if none.

Parameters

renderer (wx.RendererNative) –

Return type

wx.RendererNative

### Properties¶

Version