Screenplay

The screenplay is a list of paragraphs (see Paragraph). It remembers the cursor’s position and serves as an interface between Screenplay View and paragraphs (meaning a view cannot modify paragraphs directly but has to move the screenplay’s cursor to the appropriate position and call input methods etc. of the screenplay.)

Editing And the Undo/Redo System

All screenplay methods for editing have to make use of the _input, _delete, _new_paragraph, _delete_paragraph and _change_paragraph_type methods and make error checks (e.g. don’t delete more text than there is to delete) (error checks planned to happen in those methods instead of their callers in the future).

Breaking down editing to these five methods ensures a simple undo/redo system. The undo/redo system makes use of a somewhat stack (not exactly a stack) of action bundles. An action bundle is a list of actions that happened in a short period of time.

For example, entering a "\n" right into a paragraph deletes everything after the cursor in this paragraph (_delete), then creates a new paragraph with the deleted text (_new_paragraph). This pushes an action bundle of two actions onto the undo stack. If a user types in multiple characters in rapid succession she creates an action bundle of all those characters.

Undoing an action now means undoing an action bundle by undoing every little action in the right order. Redoing an action means redoing an action bundle. This has the nice effect of 1) masking that complex actions are multiple simple ones and 2) bundling multiple inputs together to potentially be undone later (no user wants to undo character by character).

Source Code Docstrings

class shane.screenplay.ActionBundle(action)

A bundle of actions remembering when last action was inserted.

add_action(action)

Add new action.

is_relatively_new()

Return if not much time has passed since last action addition.

class shane.screenplay.ChangePTypeAction(pindex: int, prev_type: shane.paragraph.PType, new_type: shane.paragraph.PType)

Action for paragraph type change.

class shane.screenplay.DeleteAction(pindex: int, position: int, text: str)

Action for text deletion.

class shane.screenplay.DeleteParagraphAction(pindex: int, ptype: shane.paragraph.PType, text: str)

Action for paragraph deletion.

class shane.screenplay.InputAction(pindex: int, position: int, text: str)

Action for text input.

class shane.screenplay.NameDB

Name database for a screenplay to store and retrieve names.

add(name: str)

Add a name to the database.

clear()

Clear the database’s contents.

get_next(name: str, starting_with: str) → str

Get a name from the database based on a name’s beginning.

class shane.screenplay.NewParagraphAction(pindex: int, ptype: shane.paragraph.PType, text: str)

Action for paragraph creation.

class shane.screenplay.Screenplay(path: str = None)

A screenplay.

do_autocomplete_name()

Autocomplete name at cursor position.

do_convert_tab_style()

Convert paragraph at cursor position according to tab convention.

do_convert_to_next_ptype()

Convert paragraph at cursor position to next type in order.

do_convert_to_prev_ptype()

Convert paragraph at cursor position to previous type in order.

do_delete_backward()

Delete one character backwards from cursor position.

do_delete_forward()

Delete one character forwards from cursor position.

do_input(text: str)

Input text at cursor position.

do_move_cursor_down()

Move cursor one line downward.

do_move_cursor_left()

Move cursor one character backward.

do_move_cursor_line_end()

Move cursor to line and (as in End).

do_move_cursor_line_start()

Move cursor to line start (as in Home).

do_move_cursor_next_scene()

Move cursor to next scene heading.

do_move_cursor_paragraph_end()

Move cursor to paragraph end.

do_move_cursor_prev_scene()

Move cursor to previous scene heading.

do_move_cursor_right()

Move cursor one character forward.

do_move_cursor_up()

Move cursor one line upward.

do_rebuild_autocomplete_db()

Rebuild name database.

do_redo()

Redo recently undone action.

do_save(path: str)

Save screenplay to path.

do_undo()

Undo newest action.

get_cursor_info() -> (<class 'int'>, <class 'int'>)

Return cursor’s paragraph index and position in paragraph.

get_cursor_paragraph() → shane.paragraph.Paragraph

Return cursor’s paragraph.

get_line_count() → int

Get number of lines.

get_paragraph_at_index(index: int) → shane.paragraph.Paragraph

Return paragraph at index.

get_paragraph_count() → int

Return number of paragraphs.

get_path() → str

Get path for screenplay.

get_pindex_at_line(line: int) -> (<class 'int'>, <class 'int'>)

Return paragraph’s index for line and offset into said paragraph.