Section#

class alfred3.section.Section(title: Optional[str] = None, name: Optional[str] = None, shuffle: Optional[bool] = None, **kwargs)[source]#

Bases: alfred3._core.ExpMember

The basic section, allows forward and backward movements.

Parameters
  • shuffle (bool) – If True, the order of all members in this section will be randomized every time the section is entered. Shuffling is not recursive, it only affects direct members of a section. That means, if there are subsections, their position in the parent section will be randomized, but the members within the subsection will not be affected. Defaults to False. Can be defined as a class attribute.

  • **kwargs

    Inherited keyword arguments

    name (str)

    Name of the member. Must be unique throughout the experiment. Can be defined as a class attribute. When you write a page or section in class style, the name can be inferred from the class name and does not need to be defined explicitly again. If a name is defined explicitly as a class attribute, that name is used.

    subtitle (str)

    Subtitle of the member. Can be defined as a class attribute.

    title (str)

    Title of the member. Can be defined as a class attribute.

    vargs (dict)

    A dictionary that can be used to pass additional arguments to the page. The arguments are then available as an instance attribute. As a special feature, the instance attribute allows you to access the values of the dictionary not only via the usual square-bracket notation, but also via dot-notation. This argument fulfills a similar function as **kwargs do sometimes, but it makes sure that user-defined additional arguments will not collide with inherited keywords arguments. Can be defined as a class attribute.

Examples

Using a basic section and filling it with a page in instance style:

import alfred3 as al
exp = al.Experiment()

exp += al.Section(name="main")

exp.main += al.Page(title="Demo", name="DemoPage")

Using a basic section and filling it with a page in class style:

import alfred3 as al
exp = al.Experiment()

@exp.member
class Main(al.Section): pass

@exp.member(of_section="Main")
class DemoPage(al.Page):
    title = "Demo"

Methods

added_to_experiment

Informs the member that it was added to an experiment session.

added_to_section

Informs the member that it was added to a section.

append

Appends a variable number of pages or subsections to the section.

on_enter

Executed every time this section is entered.

on_exp_access

Executed once, when the ExperimentSession becomes available to the section.

on_hand_over

Executed every time a direct subsection of this section is entered.

on_leave

Executed every time this section is left.

on_resume

Executed every time the experiment resumes from a direct subsection to this section.

position_in_section

Returns the position of this page or section inside its parent section, starting at 1.

showif

Hook for controlling whether a page or section should be shown.

uptree

List of the parent section and the grandparent sections (recursive).

validate_on_backward

Called for validation on each backward move.

validate_on_forward

Called for validation on each forward move.

validate_on_jump

Called for validation on jumping from this section.

validate_on_leave

Validates pages and their input elements within the section.

validate_on_move

Validates the current page and its elements.

visible

Returns the subset of members in the given attribute that should be shown.

Attributes

all_closed_pages

Returns a flat dict of all closed pages in this section and its subsections.

all_elements

Returns a flat dict of all elements in this section.

all_input_elements

Returns a flat dict of all input elements in this section.

all_members

Returns a flat dict of all members in this section and its subsections.

all_pages

Returns a flat dict of all pages in this section and its subsections.

all_shown_input_elements

Returns a flat dict of all shown input elements in this section.

all_shown_pages

Returns a flat dict of all pages in this section and its subsections that have already been shown.

all_subsections

Returns a flat dict of all sections in this section and its subsections.

all_updated_elements

Returns a dict of all elements in the current section that have access to the experiment session.

all_updated_members

Returns a dict of all members that already have exp access.

all_updated_pages

Returns a dict of all pages in the current section that have access to the experiment session.

allow_backward

Controls, whether participants can move backward from and to pages in this section.

allow_forward

Controls, whether participants can move forward from pages in this section.

allow_jumpfrom

Controls, whether participants can jump from pages in this section

allow_jumpto

Controls, whether participants can jump to pages in this section.

close_pages_on_leave

If True, pages in this section will be closed on leaving

data

Returns a dictionary of user input data for all pages in this section and its subsections.

empty

True, if there are no pages or subsections in this section.

exp

The ExperimentSession to which this member belongs.

experiment

The ExperimentSession to which this member belongs.

first_member

Returns the first member of the current section.

first_page

Returns the first page inside the current section.

instance_log

If True, the member will spawn a logger that can be configured individually for each instance

last_member

Returns the last member of the current section.

last_page

Returns the last page inside the current section.

members

Dictionary of the section's members.

name

Unique name of the member.

pages

Returns a flat dict of all pages in this section.

parent

Alias for section.

parent_name

Name of the parent section.

section

The member's parent section.

short_tree

Short version of tree, without the _root._content part that is the same for all members.

should_be_shown

Returns True if should_be_shown is set to True (default) and all showif conditions return True.

shuffle

If True, the members of this section will be randomized every time the section is entered.

subsections

Returns a flat dict of all subsections in this section.

subtitle

Page subtitle (str).

tag

Alias for name, included under this name for backwards compatibility.

title

Page title (str).

tree

A single string, indicating the member's position in the experiment.

uid

Alias for name, included under this name for backwards compatibility.

unlinked_data

Returns a dictionary of user input data for all unlinked pages in this section and its subsections.

vargs

A dictionary of additional arguments passed on the class upon initialization.

active

Boolean flag, indicating whether the experiment session is currently operating within this section