我想在横幅示例中制作带有类似标题的可重用容器。(所以它就像一个自定义的 GroupBox)。所以我添加到类中的每个元素都应该添加到类子容器中,而不是添加到自身中。请参阅下面的代码,我标记了我只想编写子元素的位置。
from enaml.widgets.api import *
from enaml.layout.api import *
from enaml.styling import *
enamldef BannerSheet(StyleSheet):
Style:
element = 'Label'
style_class = 'banner'
Setter:
field = 'background'
value = ('lineargradient(x1: 0, y1:0, x2:0, y2:1, '
'stop: 0 #222222, stop: 0.5 #1A1A1A, stop: 1 #111111)')
Setter:
field = 'color'
value = '#FFFFEF'
Setter:
field = 'padding'
value = '5px'
Setter:
field = 'font'
value = '18pt Verdana'
enamldef Banner(Container):
BannerSheet:
pass
padding = 0
alias title : lbl.text
constraints = [lbl.left == left,
lbl.right == right,
con.top == lbl.bottom,
con.bottom<=bottom]
Label: lbl:
name = 'abd'
style_class = 'banner'
Container: con:
pass
enamldef DemoContainer(Container):
padding = 0
Banner: b:
title = 'Bar'
#i want children here to be put into the banner.con container.
#so e.g.
Label:
text = 'This should be below the title label"