Represents a single shell interface. A shell constists of one or more screens that drive the different sections of the shell. At any given time, only one screen is active. Only the active screen’s menu will be used when interacting with the user’s input. Based on the user’s decisions, the state of the shell may be transitioned between different screens.
This class contains methods screens and actions may use for transitioning between screens and interacting with user input.
Creates an empty shell. At least one screen must be added to the shell before it is used.
Parameters: |
|
---|
Adds a new menu item that will be available anywhere in the shell. Each menu item added to this screen must have a unique trigger. If a menu item with the same trigger already exists, it will be removed from the menu and replaced by the newly added item.
Parameters: | menu_item (L{MenuItem}) – new item to add to the shell; may not be None |
---|
Adds a new screen for the shell. If a screen was previously added with the same screen ID, the newly added screen will replace it.
Parameters: | screen (L{Screen}) – describes a screen in the shell; may not be None |
---|
Calls to the command line to clear the console.
Executes a function selected by the user from a menu item. This call may raise Exit in order to quit the shell.
Subclasses should override this method to inject pre-run and post-run functionality.
Transitions the state of the shell to the home screen.
Transitions the state of the shell to the previous screen. If there is no previous screen, the shell will be transitioned to the home screen.
Renders the menu for the current screen to the screen.
Launches the shell in an exception block to catch all unexpected exceptions to prevent the entire thing from crashing. If an exception is caught, the start loop will be restarted.
Starts the loop to listen for user input and handle according to the current screen.
Causes the shell to stop listening for user commands.
Transitions the state of the shell to the identified screen. If no screen exists with the given ID, the shell will be transitioned to the home screen.
Parameters: |
|
---|
A screen is an individual “section” of a shell. The granularity of its use will vary based on the application but can most easily be related to different screens in a graphical UI.
Parameters: | id (string) – uniquely identifies this screen instance in a shell; may not be None |
---|
Adds a new menu item that will be available on this screen. Each menu item added to this screen must have a unique trigger. If a menu item with the same trigger already exists, it will be removed from the menu and replaced by the newly added item.
Parameters: | menu_item (L{MenuItem}) – new item to add to this screen; may not be None |
---|
Returns the menu item for the given trigger if one exists; None otherwise.
Parameters: | trigger (string) – identifies the menu item being searched for |
---|---|
Returns: | menu item for the given trigger if one is found; None otherwise |
Return type: | L{MenuItem} or None |
Returns a list of menu items in this screen.
Returns: | list of menu items; empty list if none have been added |
---|---|
Return type: | list of L{MenuItem} |