.. wxPython Phoenix documentation

   This file was generated by Phoenix's sphinx generator and associated
   tools, do not edit by hand.

   Copyright: (c) 2011-2020 by Total Control Software
   License:   wxWindows License

.. include:: headings.inc



.. _wx.dataview.DataViewCustomRenderer:

==========================================================================================================================================
|phoenix_title|  **wx.dataview.DataViewCustomRenderer**
==========================================================================================================================================

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

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

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

If  ``USE_ACCESSIBILITY``   setup symbol is set to 1, you might need to override also  :meth:`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
=================================

.. raw:: html

   <div id="toggleBlock" onclick="return toggleVisibility(this)" class="closed" style="cursor:pointer;">
   <img id="toggleBlock-trigger" src="_static/images/closed.png"/>
   Inheritance diagram for class <strong>DataViewCustomRenderer</strong>:
   </div>
   <div id="toggleBlock-summary" style="display:block;"></div>
   <div id="toggleBlock-content" style="display:none;">
   <p class="graphviz">
   <center><img src="_static/images/inheritance/wx.dataview.DataViewCustomRenderer_inheritance.png" alt="Inheritance diagram of DataViewCustomRenderer" usemap="#dummy" class="inheritance"/></center>
   <script type="text/javascript">toggleVisibilityOnLoad(document.getElementById('toggleBlock'))</script>
   <map id="dummy" name="dummy"> <area shape="rect" id="node1" href="wx.dataview.DataViewCustomRenderer.html" title="wx.dataview.DataViewCustomRenderer" alt="" coords="5,160,284,189"/> <area shape="rect" id="node2" href="wx.dataview.DataViewRenderer.html" title="wx.dataview.DataViewRenderer" alt="" coords="30,83,259,112"/> <area shape="rect" id="node3" href="wx.Object.html" title="wx.Object" alt="" coords="101,5,188,35"/> </map> 
   </p>
   </div>

|


|sub_classes| Known Subclasses
==============================

:ref:`wx.dataview.DataViewSpinRenderer`

|


|method_summary| Methods Summary
================================

================================================================================ ================================================================================
:meth:`~wx.dataview.DataViewCustomRenderer.__init__`                             Constructor.
:meth:`~wx.dataview.DataViewCustomRenderer.Activate`                             Override this to react to the activation of a cell.
:meth:`~wx.dataview.DataViewCustomRenderer.ActivateCell`                         Override this to react to cell `activation`.
:meth:`~wx.dataview.DataViewCustomRenderer.CreateEditorCtrl`                     Override this to create the actual editor control once editing is about to start.
:meth:`~wx.dataview.DataViewCustomRenderer.GetAttr`                              Return the attribute to be used for rendering.
:meth:`~wx.dataview.DataViewCustomRenderer.GetDefaultType`                       Returns the :ref:`Variant`  type used with this renderer.
:meth:`~wx.dataview.DataViewCustomRenderer.GetSize`                              Return size required to show content.
:meth:`~wx.dataview.DataViewCustomRenderer.GetTextExtent`                        Helper for :meth:`~DataViewCustomRenderer.GetSize`   implementations, respects attributes.
:meth:`~wx.dataview.DataViewCustomRenderer.GetValueFromEditorCtrl`               Override this so that the renderer can get the value from the editor control (pointed to by `editor`)
:meth:`~wx.dataview.DataViewCustomRenderer.HasEditorCtrl`                        Override this and make it return ``True`` in order to indicate that this renderer supports in-place editing.
:meth:`~wx.dataview.DataViewCustomRenderer.LeftClick`                            Override this to react to a left click.
:meth:`~wx.dataview.DataViewCustomRenderer.Render`                               Override this to render the cell.
:meth:`~wx.dataview.DataViewCustomRenderer.RenderText`                           This method should be called from within :meth:`~DataViewCustomRenderer.Render`   whenever you need to render simple text.
:meth:`~wx.dataview.DataViewCustomRenderer.StartDrag`                            Override this to start a drag operation.
================================================================================ ================================================================================


|


|property_summary| Properties Summary
=====================================

================================================================================ ================================================================================
:attr:`~wx.dataview.DataViewCustomRenderer.Attr`                                 See :meth:`~wx.dataview.DataViewCustomRenderer.GetAttr`
:attr:`~wx.dataview.DataViewCustomRenderer.Size`                                 See :meth:`~wx.dataview.DataViewCustomRenderer.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.



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

      Constructor.                  


      :param `varianttype`: 
      :type `varianttype`: string
      :param `mode`: 
      :type `mode`: wx.dataview.DataViewCellMode
      :param `align`: 
      :type `align`: int







   .. method:: Activate(self, cell, model, item, col)

      Override this to react to the activation of a cell.                  

                


      :param `cell`: 
      :type `cell`: wx.Rect
      :param `model`: 
      :type `model`: wx.dataview.DataViewModel
      :param `item`: 
      :type `item`: wx.dataview.DataViewItem
      :param `col`: 
      :type `col`: int




      :rtype: `bool`







      .. wxdeprecated:: 
         Use ActivateCell instead.    








   .. method:: 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 :ref:`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. 




      :param `cell`: Coordinates of the activated cell's area.   
      :type `cell`: wx.Rect
      :param `model`: The model to manipulate in response.   
      :type `model`: wx.dataview.DataViewModel
      :param `item`: Activated item.   
      :type `item`: wx.dataview.DataViewItem
      :param `col`: Activated column of  `item`.   
      :type `col`: int
      :param `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.  
      :type `mouseEvent`: wx.MouseEvent














      :rtype: `bool`



                  



      .. versionadded:: 2.9.3 
    







      .. note:: 

         Do not confuse this method with item activation in :ref:`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 :ref:`wx.TreeCtrl`  and :ref:`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.  







      .. seealso:: :meth:`CreateEditorCtrl`     








   .. method:: 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). 




      :param `parent`: The parent of the editor control.   
      :type `parent`: wx.Window
      :param `labelRect`: 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.   
      :type `labelRect`: wx.Rect
      :param `value`: Initial value of the editor.  
      :type `value`: DVCVariant










      :rtype: :ref:`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.  







      .. seealso:: :meth:`ActivateCell`     








   .. method:: GetAttr(self)

      Return the attribute to be used for rendering.                  

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

      Notice that when :meth:`Render`   is called, the :ref:`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 :meth:`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. 

                

      :rtype: :ref:`wx.dataview.DataViewItemAttr`







      .. versionadded:: 2.9.1 
     








   .. staticmethod:: GetDefaultType()

      Returns the :ref:`Variant`  type used with this renderer.                  

                

      :rtype: `string`







      .. versionadded:: 4.1/wxWidgets-3.1.0  
     








   .. method:: GetSize(self)

      Return size required to show content.                  

      :rtype: :ref:`Size`








   .. method:: GetTextExtent(self, str)

      Helper for :meth:`GetSize`   implementations, respects attributes.                  


      :param `str`: 
      :type `str`: string




      :rtype: :ref:`Size`








   .. method:: 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

                 


      :param `editor`: 
      :type `editor`: wx.Window




      :rtype: `value`








   .. method:: HasEditorCtrl(self)

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

      :rtype: `bool`








   .. method:: 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. 

                


      :param `cursor`: 
      :type `cursor`: wx.Point
      :param `cell`: 
      :type `cell`: wx.Rect
      :param `model`: 
      :type `model`: wx.dataview.DataViewModel
      :param `item`: 
      :type `item`: wx.dataview.DataViewItem
      :param `col`: 
      :type `col`: int




      :rtype: `bool`







      .. wxdeprecated:: 
         Use ActivateCell instead.    








   .. method:: Render(self, cell, dc, state)

      Override this to render the cell.                  

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


      :param `cell`: 
      :type `cell`: wx.Rect
      :param `dc`: 
      :type `dc`: wx.DC
      :param `state`: 
      :type `state`: int




      :rtype: `bool`








   .. method:: RenderText(self, text, xoffset, cell, dc, state)

      This method should be called from within :meth:`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.                  


      :param `text`: 
      :type `text`: string
      :param `xoffset`: 
      :type `xoffset`: int
      :param `cell`: 
      :type `cell`: wx.Rect
      :param `dc`: 
      :type `dc`: wx.DC
      :param `state`: 
      :type `state`: int







   .. method:: StartDrag(self, cursor, cell, model, item, col)

      Override this to start a drag operation.                  

      Not yet supported.                  


      :param `cursor`: 
      :type `cursor`: wx.Point
      :param `cell`: 
      :type `cell`: wx.Rect
      :param `model`: 
      :type `model`: wx.dataview.DataViewModel
      :param `item`: 
      :type `item`: wx.dataview.DataViewItem
      :param `col`: 
      :type `col`: int




      :rtype: `bool`








   .. attribute:: Attr

      See :meth:`~wx.dataview.DataViewCustomRenderer.GetAttr`


   .. attribute:: Size

      See :meth:`~wx.dataview.DataViewCustomRenderer.GetSize`

