File size: 2,443 Bytes
15f5485
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#------------------------------------------------------------------------------
# Copyright (c) 2013, Nucleic Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING.txt, distributed with this software.
#------------------------------------------------------------------------------
from atom.api import Bool, Enum, Typed, ForwardTyped, observe, set_default

from enaml.core.declarative import d_

from .constraints_widget import ConstraintsWidget, ProxyConstraintsWidget
from .split_item import SplitItem


class ProxySplitter(ProxyConstraintsWidget):
    """ The abstract definition of a proxy Splitter object.

    """
    #: A reference to the Splitter declaration.
    declaration = ForwardTyped(lambda: Splitter)

    def set_orientation(self, orientation):
        raise NotImplementedError

    def set_live_drag(self, live_drag):
        raise NotImplementedError


class Splitter(ConstraintsWidget):
    """ A widget which displays its children in separate resizable
    compartements that are connected with a resizing bar.

    A Splitter can have an arbitrary number of Container children.

    """
    #: The orientation of the Splitter. 'horizontal' means the children
    #: are laid out left to right, 'vertical' means top to bottom.
    orientation = d_(Enum('horizontal', 'vertical'))

    #: Whether the child widgets resize as a splitter is being dragged
    #: (True), or if a simple indicator is drawn until the drag handle
    #: is released (False). The default is True.
    live_drag = d_(Bool(True))

    #: A splitter expands freely in height and width by default.
    hug_width = set_default('ignore')
    hug_height = set_default('ignore')

    #: A reference to the ProxySplitter object.
    proxy = Typed(ProxySplitter)

    def split_items(self):
        """ Get the split item children defined on the splitter.

        """
        return [c for c in self.children if isinstance(c, SplitItem)]

    #--------------------------------------------------------------------------
    # Observers
    #--------------------------------------------------------------------------
    @observe(('orientation', 'live_drag'))
    def _update_proxy(self, change):
        """ An observer which sends state change to the proxy.

        """
        # The superclass handler implementation is sufficient.
        super(Splitter, self)._update_proxy(change)