This Page

Notebook ExampleΒΆ

notebook.enaml

#------------------------------------------------------------------------------
#  Copyright (c) 2012, Enthought, Inc.
#  All rights reserved.
#------------------------------------------------------------------------------
""" An example of the `Notebook` widget.

This example demonstrates the use of the `Notebook` widget. A `Notebook`
displays its children as a tabbed control, where one child is visible
at a time. The children of a `Notebook` must be instances of `Page` and
parent of a `Page` must be a `Notebook`. A `Page` can have at most one 
child which must be an instance of `Container`. This `Container` is 
expanded to fill the available space in the page. A `Notebook` is layed
out using constraints just like normal constraints enabled widgets.

Implementation Notes:
    
    Changing the tab style of the `Notebook` dynamically is not 
    supported on Wx. Close buttons on tabs is not supported on 
    Wx when using the 'preferences' tab style.

"""
from enaml.widgets.api import (
    Window, Notebook, Page, Container, PushButton, Field, Html, CheckBox
)


enamldef Main(Window):
    Container:
        Notebook:
            id: nbook
            tab_style = 'preferences'
            Page:
                title = 'Foo Page'
                closable = False
                Container:
                    PushButton:
                        text = 'Open Bar Page'
                        clicked :: bar.open()
                    PushButton:
                        text = 'Open Baz Page'
                        clicked :: baz.open()
                    CheckBox:
                        text = 'Tabs Closable'
                        checked := nbook.tabs_closable
                    CheckBox:
                        text = 'Tabs Movable'
                        checked := nbook.tabs_movable
                    CheckBox:
                        text = 'Document Style Tabs'
                        checked << nbook.tab_style == 'document'
                        toggled ::
                            if checked:
                                nbook.tab_style = 'document'
                            else:
                                nbook.tab_style = 'preferences'
            Page:
                id: bar
                title = 'Bar Page'
                Container:
                    Field:
                        pass
                    Field:
                        pass
                    Field:
                        pass
            Page:
                id: baz
                title = 'Baz Page'
                Container:
                    padding = 0
                    Html:
                        source = '<h1><center>Hello World!</center></h1>'

$ enaml-run notebook.enaml
../_images/notebook1.png ../_images/notebook2.png ../_images/notebook3.png