enthought / traitsui
1
# Copyright (c) 2019, Enthought Inc.
2
# All rights reserved.
3
#
4
# This software is provided without warranty under the terms of the BSD
5
# license included in LICENSE.txt and may be redistributed only
6
# under the conditions described in the aforementioned license.  The license
7
# is also available online at http://www.enthought.com/licenses/BSD.txt
8
# Thanks for using Enthought open source!
9

10 4
from abc import abstractmethod
11

12 4
from traits.api import ABCHasStrictTraits, Bool
13

14

15 4
class AbstractTreeNodeRenderer(ABCHasStrictTraits):
16
    """ Abstract base class for renderers of tree node items.
17

18
    This is currently only supported for Qt.
19
    """
20

21
    #: Whether the renderer handles rendering everything
22 4
    handles_all = Bool(False)
23

24
    #: Whether the renderer handles rendering any text
25 4
    handles_text = Bool(True)
26

27
    #: Whether the renderer handles rendering the icon or other decoration
28 4
    handles_icon = Bool(False)
29

30 4
    @abstractmethod
31
    def paint(self, node, column, object, paint_context):
32
        """ Render the node.
33

34
        Parameters
35
        ----------
36
        node : ITreeNode instance
37
            The tree node to render.
38
        column : int
39
            The column in the tree that should be rendererd.
40
        object : object
41
            The underlying object being edited.
42
        paint_context : object
43
            A toolkit-dependent context for performing paint operations.
44

45
        Returns
46
        -------
47
        size : tuple of (width, height) or None
48
            Optionally return a new preferred size so that the toolkit can
49
            perform better layout.
50
        """
51
        raise NotImplementedError()
52

53 4
    @abstractmethod
54
    def size(self, node, column, object, size_context):
55
        """ Return the preferred size for the item
56

57
        Parameters
58
        ----------
59
        node : ITreeNode instance
60
            The tree node to render.
61
        column : int
62
            The column in the tree that should be rendererd.
63
        object : object
64
            The underlying object being edited.
65
        size_context : object
66
            A toolkit-dependent context for performing sizing operations.
67

68
        Returns
69
        -------
70
        size : tuple of (width, height) or None
71
        """
72
        raise NotImplementedError()
73

74 4
    def get_label(self, node, object, column=0):
75
        """ Get the label associated with an item and column. """
76 4
        if column == 0:
77 3
            return node.get_label(object)
78
        else:
79 0
            return node.get_column_labels(object)[column]

Read our documentation on viewing source code .

Loading