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.
wx.dataview.DataViewSpinRenderer
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. |
See |
|
See |
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.
__init__
(self, varianttype=DataViewCustomRenderer.GetDefaultType(), mode=DATAVIEW_CELL_INERT, align=DVR_DEFAULT_ALIGNMENT)¶Constructor.
varianttype (string) –
mode (DataViewCellMode) –
align (int) –
Activate
(self, cell, model, item, col)¶Override this to react to the activation of a cell.
cell (wx.Rect) –
model (wx.dataview.DataViewModel) –
item (wx.dataview.DataViewItem) –
col (int) –
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.
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.
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
(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).
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 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.
New in version 2.9.1.
GetDefaultType
()¶Returns the Variant type used with this renderer.
string
New in version 4.1/wxWidgets-3.1.0.
GetTextExtent
(self, str)¶Helper for GetSize
implementations, respects attributes.
str (string) –
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
editor (wx.Window) –
value
HasEditorCtrl
(self)¶Override this and make it return True
in order to indicate that this renderer supports in-place editing.
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.
cursor (wx.Point) –
cell (wx.Rect) –
model (wx.dataview.DataViewModel) –
item (wx.dataview.DataViewItem) –
col (int) –
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.
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.
StartDrag
(self, cursor, cell, model, item, col)¶Override this to start a drag operation.
Not yet supported.
cursor (wx.Point) –
cell (wx.Rect) –
model (wx.dataview.DataViewModel) –
item (wx.dataview.DataViewItem) –
col (int) –
bool