phoenix_title wx.dataview.DataViewCustomRenderer

You need to derive a new class from wx.dataview.DataViewCustomRenderer in order to write a new renderer.

You need to override at least wx.dataview.DataViewRenderer.SetValue , wx.dataview.DataViewRenderer.GetValue , wx.dataview.DataViewCustomRenderer.GetSize and wx.dataview.DataViewCustomRenderer.Render .

If you want your renderer to support in-place editing then you also need to override wx.dataview.DataViewCustomRenderer.HasEditorCtrl , wx.dataview.DataViewCustomRenderer.CreateEditorCtrl and wx.dataview.DataViewCustomRenderer.GetValueFromEditorCtrl .

If USE_ACCESSIBILITY setup symbol is set to 1, you might need to override also wx.dataview.DataViewRenderer.GetAccessibleDescription .

Note that a special event handler will be pushed onto that editor control which handles <ENTER> and focus out events in order to end the editing.


class_hierarchy Class Hierarchy

Inheritance diagram for class DataViewCustomRenderer:

method_summary Methods Summary

__init__

Constructor.

Activate

Override this to react to the activation of a cell.

ActivateCell

Override this to react to cell activation.

CreateEditorCtrl

Override this to create the actual editor control once editing is about to start.

GetAttr

Return the attribute to be used for rendering.

GetDefaultType

Returns the Variant type used with this renderer.

GetSize

Return size required to show content.

GetTextExtent

Helper for GetSize implementations, respects attributes.

GetValueFromEditorCtrl

Override this so that the renderer can get the value from the editor control (pointed to by editor)

HasEditorCtrl

Override this and make it return True in order to indicate that this renderer supports in-place editing.

LeftClick

Override this to react to a left click.

Render

Override this to render the cell.

RenderText

This method should be called from within Render whenever you need to render simple text.

StartDrag

Override this to start a drag operation.


property_summary Properties Summary

Attr

See GetAttr

Size

See GetSize


api Class API

class wx.dataview.DataViewCustomRenderer(DataViewRenderer)

Possible constructors:

DataViewCustomRenderer(varianttype=DataViewCustomRenderer.GetDefaultType
                       (), mode=DATAVIEW_CELL_INERT, align=DVR_DEFAULT_ALIGNMENT)

You need to derive a new class from DataViewCustomRenderer in order to write a new renderer.


Methods

__init__(self, varianttype=DataViewCustomRenderer.GetDefaultType(), mode=DATAVIEW_CELL_INERT, align=DVR_DEFAULT_ALIGNMENT)

Constructor.

Parameters


Activate(self, cell, model, item, col)

Override this to react to the activation of a cell.

Parameters
Return type

bool

Deprecated

Use ActivateCell instead.



ActivateCell(self, cell, model, item, col, mouseEvent)

Override this to react to cell activation.

Activating a cell is an alternative to showing inline editor when the value can be edited in a simple way that doesn’t warrant full editor control. The most typical use of cell activation is toggling the checkbox in wx.dataview.DataViewToggleRenderer; others would be e.g. an embedded volume slider or a five-star rating column.

The exact means of activating a cell are platform-dependent, but they are usually similar to those used for inline editing of values. Typically, a cell would be activated by Space or Enter keys or by left mouse click.

This method will only be called if the cell has the wx.dataview.DATAVIEW_CELL_ACTIVATABLE mode.

Parameters
  • cell (wx.Rect) – Coordinates of the activated cell’s area.

  • model (wx.dataview.DataViewModel) – The model to manipulate in response.

  • item (wx.dataview.DataViewItem) – Activated item.

  • col (int) – Activated column of item.

  • mouseEvent (wx.MouseEvent) – If the activation was triggered by mouse click, contains the corresponding event. Is None otherwise (for keyboard activation). Mouse coordinates are adjusted to be relative to the cell.

Return type

bool

New in version 2.9.3.

Note

Do not confuse this method with item activation in wx.dataview.DataViewCtrl and the wxEVT_DATAVIEW_ITEM_ACTIVATED event. That one is used for activating the item (or, to put it differently, the entire row) similarly to analogous messages in wx.TreeCtrl and wx.ListCtrl, and the effect differs (play a song, open a file etc.). Cell activation, on the other hand, is all about interacting with the individual cell.

See also

CreateEditorCtrl



CreateEditorCtrl(self, parent, labelRect, value)

Override this to create the actual editor control once editing is about to start.

This method will only be called if the cell has the wx.dataview.DATAVIEW_CELL_EDITABLE mode. Editing is typically triggered by slowly double-clicking the cell or by a platform-dependent keyboard shortcut (F2 is typical on Windows, Space and/or Enter is common elsewhere and supported on Windows too).

Parameters
  • parent (wx.Window) – The parent of the editor control.

  • labelRect (wx.Rect) – Indicates the position and size of the editor control. The control should be created in place of the cell and labelRect should be respected as much as possible.

  • value (DVCVariant) – Initial value of the editor.

Return type

Window

# Some integer...
l = value
return wx.SpinCtrl(parent, wx.ID_ANY, "",
                   labelRect.GetTopLeft(), labelRect.GetSize(), 0, 0, 100, l)

Note

Currently support for this method is not implemented in the native macOS version of the control, i.e. it will be never called there.

See also

ActivateCell



GetAttr(self)

Return the attribute to be used for rendering.

This function may be called from Render implementation to use the attributes defined for the item if the renderer supports them.

Notice that when Render is called, the wx.DC object passed to it is already set up to use the correct attributes (e.g. its font is set to bold or italic version if wx.dataview.DataViewItemAttr.GetBold or GetItalic() returns True) so it may not be necessary to call it explicitly if you only want to render text using the items attributes.

Return type

wx.dataview.DataViewItemAttr

New in version 2.9.1.



static GetDefaultType()

Returns the Variant type used with this renderer.

Return type

string

New in version 4.1/wxWidgets-3.1.0.



GetSize(self)

Return size required to show content.

Return type

Size



GetTextExtent(self, str)

Helper for GetSize implementations, respects attributes.

Parameters

str (string) –

Return type

Size



GetValueFromEditorCtrl(self, editor)

Override this so that the renderer can get the value from the editor control (pointed to by editor):

# sc is a wx.SpinCtrl
l = sc.GetValue()
value = l
return True
Parameters

editor (wx.Window) –

Return type

value



HasEditorCtrl(self)

Override this and make it return True in order to indicate that this renderer supports in-place editing.

Return type

bool



LeftClick(self, cursor, cell, model, item, col)

Override this to react to a left click.

This method will only be called in DATAVIEW_CELL_ACTIVATABLE mode.

Parameters
Return type

bool

Deprecated

Use ActivateCell instead.



Render(self, cell, dc, state)

Override this to render the cell.

Before this is called, wx.dataview.DataViewRenderer.SetValue was called so that this instance knows what to render.

Parameters
Return type

bool



RenderText(self, text, xoffset, cell, dc, state)

This method should be called from within Render whenever you need to render simple text.

This will ensure that the correct colour, font and vertical alignment will be chosen so the text will look the same as text drawn by native renderers.

Parameters
  • text (string) –

  • xoffset (int) –

  • cell (wx.Rect) –

  • dc (wx.DC) –

  • state (int) –



StartDrag(self, cursor, cell, model, item, col)

Override this to start a drag operation.

Not yet supported.

Parameters
Return type

bool


Properties

Attr

See GetAttr



Size

See GetSize