Console Controller
The embedded Python console is based on the recipe found here.
It subclasses InteractiveConsole
which provides the interpreter
functionality. It also creates a shared namespace to allow the global namespace
to share objects with the embedded interpreter. This is important for being
able to manipulate the runtime system with user commands. The user commands act
on the objects in the shared namespace, which are the same objects that exist
in the global namespace.
-
class
ctrl_console.
Console
(main, console_ui, names=None)
Handles console functionality. Interprets commands and calls appropriate
functions. This is modeled as a singleton.
Parameters: |
- console_ui (UI_Panel) – This is a reference to a panel that represents a console.
- names (Dict) – The defined names in the Python environment.
|
Variables: |
- parent – The UI that represents the console.
- root – A reference to the main screen.
- shared – Creates a shared namespace that allows the embedded
interpreter to access global namespace objects.
- console_inst – Static. Holds the single instance.
|
-
enter
(source)
This function processes user input. It preprocesses the text before
sending it to the interpreter to provide additional functionality. It
also provides redirection from standard output to the console’s
display area.
Parameters: | source (String) – User Python input. |
-
focus_prompt
(dt=0)
Gives focus to the code input box.
-
preprocess
(source)
This is a hook function that defines any reserved commands that will
not get sent to the Python interpreter.
-
redirected
(out=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>, err=<kivy.logger.LogFile object>)
Changes system stdout
and system stderr
to any other string io
stream. Is disabled when in debugging mode with a breakpoint set.
Parameters: |
- out (StringIO) – The string stream that recieves system output. Default,
sys.stdout .
- err (StringIO) – The string stream that recieves system error strings.
Default,
sys.stderr .
|
Console UI Elements
This module defines the components used to build a console panel. It is used by
the console assembler to produce the console.
-
class
ui_console.
CmdLine
(**kwargs)
A text box for users to input Python code to the interpreter.
Variables: |
- buffer – A history of commands.
- cmd_index – The length of the command history list.
- kb – The
KeyboardMap that defines and responds to
hotkeys specific to the console.
|
-
build_keyboard
()
Provides function maps for hotkey shortcuts.
Todo
Document shortcuts in User Guide.
-
next_cmd
()
Retrieves a command from the history one position later.
-
on_text_validate
()
Internal. A callback that sends validated text to the controller.
-
on_touch_down
(touch)
Internal. A callback to respond to touch (click) events.
Parameters: | touch (MotionEvent) – The touch data associated with the call. |
-
on_touch_up
(touch)
Internal. A callback to respond to touch (click) events.
Parameters: | touch (MotionEvent) – The touch data associated with the call. |
-
paste_cmd
()
Paste the clipboard contents to the text value.
-
previous_cmd
()
Retrieves a command from the history one position earlier.
-
class
ui_console.
CodeDisplay
(font_size='11sp', **kwargs)
The primary display area for the console. It shows the output from the
Python interpreter. This is read-only.
Parameters: | font_size (String) – The font size to display given in Kivy Units. |
Variables: | font_size – The current font size setting. |
Todo
Allow select and copy with mouse. Currently, mouse will move the
panel around rather than allowing selection.
-
keyboard_on_key_down
(keyboard, keycode, codepoint, modifiers)
Internal. A callback function that responds to keypresses.
Parameters: |
- keyboard (Kivy Keyboard) – A reference to the Kivy keyboard controller.
- keycode (Integer) – A numeric code representing the key pressed. See
KeyboardMap for more info on
keycodes.
- codepoint (String) – The string value of the key.
- modifiers (String) – The string value of any modifier keys also pressed.
|
-
on_touch_down
(touch)
Internal. A callback to respond to touch (click) events.
Parameters: | touch (MotionEvent) – The touch data associated with the call. |
-
on_touch_up
(touch)
Internal. A callback to respond to touch (click) events.
Parameters: | touch (MotionEvent) – The touch data associated with the call. |
-
class
ui_console.
UI_Console_Inner
(**kwargs)
This contains the user input textbox as well as the system output display.
Variables: |
- code_ui – A code textbox to display system output.
- prompt_ui – A code textbox for user input.
- cmd_ui – The command prompt characters
>>> .
|
Command
This is an implementation of the Command design pattern. This module defines a
registry of commands within the system. Most user-accessible commands should
derive from one of the types: Command
or SingletonCommand
.
Each command defined in this manner should add themselves to the command
registry CMDS
. This makes the command available to the console.
-
class
command.
Command
Inherit from Command
to create new commands that need to hold
state. If your command does not need multiple instances with different
states, use SingletonCommand
instead. All undoable commands will
derive from this class because undoables need to store state prior to
modification.
-
execute
()
A fall-back execute()
intended to be overridden by your derived
class.
-
static
get_app
()
Returns the currently running app.
-
undo
()
A fall-back undo()
intended to be overridden by your derived
class.
-
class
command.
DeleteCircuitCmd
(to_delete=None)
Deletes a circuit and all associated vertices from the database.
Parameters: | info – The CircuitInfo belonging to the circuit
you wish to delete. |
-
class
command.
HelpCmd
Prints all available commands to console.
-
class
command.
HistoryCmd
Print the command history.
-
class
command.
ListCircuitsCmd
Lists all currently available circuits.
-
class
command.
LoadCircuitCmd
(name=None)
Open an existing circuit in the current project.
:param circuit_name: The name of the circuit to load.
:param circuit_name: str
-
class
command.
NewCircuitCmd
(name=None)
Creates a new circuit and loads it.
Parameters: | name (str) – The name of the circuit to create. Default = ‘Untitled’. |
-
class
command.
OpenConsoleCmd
Opens the console window if closed, otherwise, does nothing.
-
class
command.
OpenHelpViewCmd
Opens a Quantum Documentation panel.
-
class
command.
OpenProfilerCmd
Opens a profiler window.
-
class
command.
OpenProjectCmd
(project=None)
Opens a project from a graph data file.
Parameters: |
- path – The path to the project file.
- filename – The name of the file.
- ext – The file extension.
|
-
static
close_project
()
Clears out all project data currently in TitanDB. Hopefully, user has
been prompted to save data into project file before this is executed!
-
static
open_project
(path, filename, ext)
Opening a new project clears the current TitanDB and populates it with
data from an existing graph file.
-
class
command.
RedoCmd
Redo the last command executed.
-
class
command.
RenameCircuitCmd
Renames the current circuit.
Parameters: | new_name (str) – The new name to give the current circuit. |
-
class
command.
RunCircuitCmd
Schedules a circuit execution.
:param debug: Boolean value to set debug mode. Default=False
:type debug: boolean
:param step: Number of steps to execute in debug mode. Default=1
:type step: int
-
class
command.
SaveCmd
Saves the circuit to the database.
-
class
command.
ScreenSwitchCmd
Switch between app and loading screens for debugging.
-
class
command.
SingletonCommand
Inherit from this class if all instances of your command should actually
reference a single instance in memory. This is typical for non-undoable
commands.
-
class
command.
SweepAllCmd
Sweep aside all panels.
-
class
command.
SweepConsoleCmd
Sweep console into or out of view. If closed, open a new instance.
-
class
command.
ToggleScreencastCmd
Turn on or off screencast keys.
-
class
command.
UndoCmd
Undo the last command executed.
-
command.
undoable
(func)
A decorator for execution functions. Any @undoable
class must implement
an undo
function.