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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
#------------------------------------------------------------------------------
# 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.
#------------------------------------------------------------------------------
""" An example of using dynamic notebook pages.
This example demonstrates using the `Include` component to dynamically
insert and remove pages from a notebook.
<< autodoc-me >>
"""
from enaml.core.api import Include
from enaml.layout.api import vbox, hbox, align, spacer
from enaml.widgets.api import (
Window, Notebook, Page, Container, PushButton, Field, Html, CheckBox
)
enamldef ContentPage(Page):
attr n: int
closable = False
Container:
constraints = [
vbox(
hbox(pb, cb, fld),
html,
),
align('v_center', pb, cb, fld),
]
PushButton: pb:
text = 'Button'
CheckBox: cb:
text = 'Activate'
Field: fld:
pass
Html: html:
source = '<h1><center>Dynamic Page %d</center></h1>' % n
enamldef Main(Window): main:
attr counter = 0
Container:
constraints = [
vbox(
hbox(show_st, hide_st, spacer, ins_dyn, rem_dyn),
nbook,
),
]
PushButton: show_st:
text = 'Show Static Pages'
clicked ::
static1.show()
static2.show()
PushButton: hide_st:
text = 'Hide Static Pages'
clicked ::
static2.hide()
static1.hide()
PushButton: ins_dyn:
text = 'Insert Dynamic Page'
clicked ::
title = 'Dynamic Page %s' % main.counter
page = ContentPage(n=main.counter, title=title)
dyn_pages.objects.insert(0, page)
main.counter += 1
PushButton: rem_dyn:
text = 'Remove Dynamic Page'
clicked ::
if dyn_pages.objects:
dyn_pages.objects.pop()
Notebook: nbook:
tab_style = 'document'
Page: static1:
title = 'Static Page1'
Container:
padding = 0
Html:
source = '<h1><center>Static Page 1</center></h1>'
Page: static2:
title = 'Static Page2'
Container:
padding = 0
Html:
source = '<h1><center>Static Page 2</center></h1>'
Include: dyn_pages:
pass
|