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¶
Known Subclasses¶
wx.dataview.DataViewSpinRenderer
Methods Summary¶
Constructor. |
|
Override this to react to the activation of a cell. |
|
Override this to react to cell activation. |
|
Override this to create the actual editor control once editing is about to start. |
|
Return the attribute to be used for rendering. |
|
Returns the Variant type used with this renderer. |
|
Return size required to show content. |
|
Helper for |
|
Override this so that the renderer can get the value from the editor control (pointed to by editor) |
|
Override this and make it return |
|
Override this to react to a left click. |
|
Override this to render the cell. |
|
This method should be called from within |
|
Override this to start a drag operation. |
Properties Summary¶
See |
|
See |
Class API¶
- class wx.dataview.DataViewCustomRenderer(DataViewRenderer)¶
Possible constructors:
DataViewCustomRenderer(varianttype=DataViewCustomRenderer.GetDefaultType (), mode=DATAVIEW_CELL_INERT, align=DVR_DEFAULT_ALIGNMENT) -> None
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:
varianttype (string)
mode (DataViewCellMode)
align (int)
- Return type:
None
- Activate(self, cell, model, item, col)¶
Override this to react to the activation of a cell.
- Parameters:
cell (wx.Rect)
model (wx.dataview.DataViewModel)
item (wx.dataview.DataViewItem)
col (int)
- 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_ACTIVATABLEmode.- 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
Noneotherwise (for keyboard activation). Mouse coordinates are adjusted to be relative to the cell.
- Return type:
bool
Added 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(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_EDITABLEmode. Editing is typically triggered by slowly double-clicking the cell or by a platform-dependent keyboard shortcut (F2is typical on Windows, Space and/or Enter is common elsewhere and supported on Windows too).- Parameters:
- 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
- GetAttr(self)¶
Return the attribute to be used for rendering.
This function may be called from
Renderimplementation to use the attributes defined for the item if the renderer supports them.Notice that when
Renderis 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 ifwx.dataview.DataViewItemAttr.GetBoldor GetItalic() returnsTrue) so it may not be necessary to call it explicitly if you only want to render text using the items attributes.- Return type:
Added in version 2.9.1.
- static GetDefaultType()¶
Returns the Variant type used with this renderer.
- Return type:
str
Added in version 4.1/wxWidgets-3.1.0.
- GetTextExtent(self, str)¶
Helper for
GetSizeimplementations, respects attributes.- Parameters:
str (string)
- Return type:
- 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:
DVCVariant
- HasEditorCtrl(self)¶
Override this and make it return
Truein 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_ACTIVATABLEmode.- Parameters:
cursor (wx.Point)
cell (wx.Rect)
model (wx.dataview.DataViewModel)
item (wx.dataview.DataViewItem)
col (int)
- 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.SetValuewas called so that this instance knows what to render.
- RenderText(self, text, xoffset, cell, dc, state)¶
This method should be called from within
Renderwhenever 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.
- StartDrag(self, cursor, cell, model, item, col)¶
Override this to start a drag operation.
Not yet supported.
- Parameters:
cursor (wx.Point)
cell (wx.Rect)
model (wx.dataview.DataViewModel)
item (wx.dataview.DataViewItem)
col (int)
- Return type:
bool
Properties¶