File: test_layout_container.py

package info (click to toggle)
python-enaml 0.19.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,284 kB
  • sloc: python: 31,443; cpp: 4,499; makefile: 140; javascript: 68; lisp: 53; sh: 20
file content (72 lines) | stat: -rw-r--r-- 1,886 bytes parent folder | download
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
70
71
72
#------------------------------------------------------------------------------
# Copyright (c) 2013-2025, Nucleic Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file LICENSE, distributed with this software.
#------------------------------------------------------------------------------
from utils import compile_source, wait_for_window_displayed


MANUAL_REPARENTING = \
"""from enaml.core.api import Conditional
from enaml.widgets.api import (Window, Container, ObjectCombo, PushButton,
                               ScrollArea, GroupBox, Label)


enamldef Displayable(GroupBox): cont:

    attr sp_children = []
    alias btn_clicked : btn.clicked

    func refresh():
        for c in sp_children:
            c.set_parent(self)
            c.show()

    initialized ::
        refresh()

    PushButton: btn:
        text = 'Add label'
        clicked ::
            Label(text='Dummy').set_parent(cont)

C2 = Displayable(title='C2')

C1 = Displayable(title='C1', sp_children=[C2])


enamldef Main(Window):

    attr displayables = {'C1': C1, 'C2': C2}
    alias selected_disp : cb.selected

    initialized::
        C1.set_parent(scroll)
        C1.show()

    Container:
        ObjectCombo: cb:
            items = sorted(displayables)
            selected ::
                view = displayables[change['value']]
                view.set_parent(scroll)
                view.refresh()
                view.show()

        ScrollArea: scroll:
            pass
"""


def test_manual_reparenting(enaml_qtbot):
    """Test manually reparenting widgets which are previously child and parent.

    """
    win = compile_source(MANUAL_REPARENTING, 'Main')()
    win.show()
    win.send_to_front()
    wait_for_window_displayed(enaml_qtbot, win)
    win.selected_disp = 'C2'
    win.displayables['C2'].btn_clicked = True