Skip to main content

Creating pages

New in v12.5.0

A Page can be used to construct a combination of inputs (e.g. tabs / sections) and outputs (views). This grouping allows for specific views to become visible, depending on the page a user has selected.

Assume an editor with a GeometryView and a DataView:

...


class ExampleController(ViktorController):
...

@GeometryView(...)
def geometry_view(...):
...

@DataView(...)
def data_view(...):
...

Now we would like to have an editor with 2 pages. When a user is working on "Page 1", no views will be visible. When the user switches to "Page 2", a geometry view and a data view will become visible.

A Page is defined in the parametrization similar to tabs and sections:

from viktor.parametrization import ViktorParametrization, Page, TextField, NumberField


class Parametrization(ViktorParametrization):
page_1 = Page('Page 1 - without views')
page_1.input_1 = TextField('This is a text field')
page_1.input_2 = NumberField('This is a number field')

page_2 = Page('Page 2 - with views', views=['geometry_view', 'data_view'])
page_2.input_1 = TextField('This is a text field')
page_2.input_2 = NumberField('This is a number field')

Page 1 with no views

Page 2 with a GeometryView and a DataView

All the layered structures of Tab / Section / fields can be encapsulated in a Page:

# fields directly as input fields on a page
class Parametrization(ViktorParametrization):
page = Page(...)
page.number = NumberField(...)
...


# tabs on a page
class Parametrization(ViktorParametrization):
page = Page(...)
page.tab = Tab(...)
...


# sections on a page
class Parametrization(ViktorParametrization):
page = Page(...)
page.section = Section(...)
...