Skip to content

Instantly share code, notes, and snippets.

@MatthieuDartiailh
Last active May 23, 2016 13:38
Show Gist options
  • Save MatthieuDartiailh/0db8fc2967f992c8bb2401618013c354 to your computer and use it in GitHub Desktop.
Save MatthieuDartiailh/0db8fc2967f992c8bb2401618013c354 to your computer and use it in GitHub Desktop.
Demonstrate issue in reparenting in enaml
# -*- coding: utf-8 -*-
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 = []
func refresh():
for c in sp_children:
c.set_parent(self)
c.show()
initialized ::
refresh()
PushButton:
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}
initialized::
C1.set_parent(scroll)
C1.show()
Container:
ObjectCombo:
items = sorted(displayables)
selected ::
# if 'oldvalue' in change:
# displayables[change['oldvalue']].set_parent(None)
view = displayables[change['value']]
# if view.proxy_is_active:
# view.proxy.layout_container = None
view.set_parent(scroll)
view.refresh()
view.show()
ScrollArea: scroll:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment