turtlico.lib package¶
Subpackages¶
Submodules¶
turtlico.lib.codepiece module¶
- class turtlico.lib.codepiece.CodeBuffer(project: turtlico.lib.projectbuffer.ProjectBuffer, record_history=False, code: Optional[str] = None, single_line=False)¶
Bases:
gi.overrides.GObject.Object
- HISTORY_CAPACITY = 10¶
- can_redo¶
- can_undo¶
- clear()¶
- code_changed¶
- do_code_changed()¶
- do_get_property(pspec)¶
- do_set_property(pspec, value)¶
- get_command_data_preview(command: turtlico.lib.command.Command) Optional[gi.repository.Gdk.Texture] ¶
- get_range(s: turtlico.lib.codepieceselection.CodePieceSelection) List[List[turtlico.lib.command.Command]] ¶
- history: list¶
- history_index: int¶
- insert(commands: List[List[turtlico.lib.command.Command]], x: int, y: int, autoindent: bool = False)¶
- lines: List[List[turtlico.lib.command.Command]]¶
- load(code: List[Tuple[str, str]])¶
- record_history: bool¶
- record_history_pause: bool¶
- redo()¶
- reload()¶
- replace_command(cmd: turtlico.lib.command.Command, x: int, y: int)¶
- save() List[Tuple[str, str]] ¶
- single_line¶
- undo()¶
- turtlico.lib.codepiece.CodePiece¶
Represents a piece of code with known commands
- Type
List[List[Command]]
alias of
List
[List
[turtlico.lib.command.Command
]]
- class turtlico.lib.codepiece.CodePieceDrop(tcppiece: List[Tuple[str, str]])¶
Bases:
gi.overrides.GObject.Object
- tcppiece: List[Tuple[str, str]]¶
- turtlico.lib.codepiece.TcpPiece¶
Represents a part of Turtlico project file
- Type
List[Tuple[str, str]]
alias of
List
[Tuple
[str
,str
]]
Bases:
Exception
- turtlico.lib.codepiece.clone_codepiece(commands: List[List[turtlico.lib.command.Command]]) List[List[turtlico.lib.command.Command]] ¶
- turtlico.lib.codepiece.compare_codepiece(a: List[List[turtlico.lib.command.Command]], b: List[List[turtlico.lib.command.Command]]) bool ¶
- turtlico.lib.codepiece.deserialize_bytes(dsr: gi.repository.Gdk.ContentDeserializer)¶
- turtlico.lib.codepiece.deserialize_bytes_finish(outs: gi.repository.Gio.MemoryOutputStream, res: gi.repository.Gio.AsyncResult, dsr: gi.repository.Gdk.ContentDeserializer)¶
- turtlico.lib.codepiece.get_codepiece_content_provider(commands: List[List[turtlico.lib.command.Command]]) gi.repository.Gdk.ContentProvider ¶
- turtlico.lib.codepiece.get_tcppiece_from_clipboard(widget: gi.overrides.Gtk.Widget) Optional[List[Tuple[str, str]]] ¶
- turtlico.lib.codepiece.get_tcppiece_from_provider(cp: gi.repository.Gdk.ContentProvider) Optional[List[Tuple[str, str]]] ¶
- turtlico.lib.codepiece.load_codepiece(contents: List[Tuple[str, str]], project: turtlico.lib.projectbuffer.ProjectBuffer, ignore_errors=False) List[List[turtlico.lib.command.Command]] ¶
- turtlico.lib.codepiece.parse_tcp(contents: str) List[Tuple[str, str]] ¶
- turtlico.lib.codepiece.save_codepiece(contents: List[List[turtlico.lib.command.Command]]) List[Tuple[str, str]] ¶
- turtlico.lib.codepiece.save_tcp(contents: List[Tuple[str, str]]) str ¶
turtlico.lib.codepieceselection module¶
- class turtlico.lib.codepieceselection.CodePieceSelection(start_x, start_y, end_x, end_y)¶
Bases:
gi.overrides.GObject.Object
- contains(x: int, y: int) bool ¶
- do_get_property(pspec)¶
- do_set_property(pspec, value)¶
- end_x¶
- end_y¶
- start_x¶
- start_y¶
- validate(code: List[List[turtlico.lib.command.Command]])¶
turtlico.lib.command module¶
- class turtlico.lib.command.Command(data, definition)¶
Bases:
NamedTuple
- data: str¶
Alias for field number 0
- definition: turtlico.lib.command.CommandDefinition¶
Alias for field number 1
- class turtlico.lib.command.CommandCategory(plugin: turtlico.lib.command.Plugin, category_icon: turtlico.lib.icon.base.CommandIconInterface, command_definitions: list)¶
Bases:
gi.overrides.GObject.Object
- command_definitions: gi.overrides.Gio.ListStore¶
objects of commands that the category contains.
- Type
Gio.ListStore[CommandDefinition]
- icon: turtlico.lib.icon.base.CommandIconInterface¶
Icon for the category
- plugin: turtlico.lib.command.Plugin¶
The plugin that will contain the category
- Type
- class turtlico.lib.command.CommandDefinition(id: str, command_icon: turtlico.lib.icon.base.CommandIconInterface, help: str, command_type: turtlico.lib.command.CommandType, function: Optional[str] = None, default_params: Optional[str] = None, data_only: bool = False, show_data: bool = True, color: turtlico.lib.icon.base.CommandColor = CommandColor.DEFAULT, snippet: Optional[str] = None)¶
Bases:
gi.overrides.GObject.Object
- color: turtlico.lib.icon.base.CommandColor¶
Color of the command. See docs of CommandColor.
- command_type: turtlico.lib.command.CommandType¶
Type of the command. See docs for CommandType.
- Type
- data_only: bool¶
True if the original icon of the command vanishes if any data are set
- Type
bool
- default_params: Optional[str]¶
Python code containing default parameters. METHOD: If there is no parameter specified for the command - no parenthesis or a LITERAL/LITERAL_CONST command follows it - code from this variable is inserted after the function bewtween parenthesis.
- Type
str
- static escape_id_for_html(id: str) str ¶
- function: Union[str, Callable[[str, bool], turtlico.lib.command.LiteralParserResult]]¶
For most of command types this is the name of the Python function/code that is represented by this.
For LITERAL command type this is a reference to a function that takes two arguments: command data and a boolean value that indicates whether the command is placed standalone in the program. This means that the command is not a parameter for another funcion or that it’s not contained in an IF expression etc. The function returns a LiteralParserResult object.
- Type
Union[str, Callable[[str, bool], LiteralParserResult]]
- help: str¶
A short string that tells the user what does the command do
- Type
str
- icon: turtlico.lib.icon.base.CommandIconInterface¶
Icon of the command
- id: str¶
Command id. ID has to be original and should contain no special characters.
- Type
str
- show_data: bool¶
True if data are presented via a text label to the user
- Type
bool
- snippet: Optional[List[Tuple[str, str]]]¶
Code that is inserted insted of this icon when Autocomplete context menu option is used.
- Type
TcpPiece
- class turtlico.lib.command.CommandEvent(name, handler, connector, params)¶
Bases:
NamedTuple
- connector: str¶
Code in tcp format that connect the event to the new function. Use ‘{0}’ to get the user chosen function name.
- handler: str¶
Code in tcp format that will be inserted to the new handler function
- insert_into(project: turtlico.lib.projectbuffer.ProjectBuffer, code: turtlico.lib.codepiece.CodeBuffer, name: str)¶
- name: str¶
User friendly name of the event
- params: str¶
Handler argument default variable names separated by commas.
- class turtlico.lib.command.CommandModule(deps: set[str], code: str, deps_required: bool = True)¶
Bases:
object
- code: str¶
Python code of the module. There is usually a function defined. The name of the function must have a ‘tcp_’ prefix.
- deps: set¶
List of another module ids that are used by code of this module.
- deps_required: bool = True¶
Set to False if the code is able to work without deps
- class turtlico.lib.command.CommandType(value)¶
Bases:
enum.Enum
An enumeration.
- CODE_SNIPPET = 3¶
Insert Python code from function variable without any additional logic.
- DIPERATOR = 4¶
Dual Input oPERATOR Sibling icons are placed on the same line in output along the DIPERATOR. Like KEYWORD but does not start a new line.
- INTERNAL = 0¶
Command that is processed by special code in the compiler.
- KEYWORD = 2¶
Keyword with one parameter (the next icon is placed on the same line in Python output).
- KEYWORD_WITH_ARGS = 5¶
Keyword with multiple parameters (commands inserted on the same line). Paremeters ends with :.
- LITERAL = 6¶
Literals represent their data. They can be used as a paramater for a method without parenthesis. The command must have function property set to a function that returns data representation in Python code (see LiteralParserResult and function property in CommandDefinition)
- LITERAL_CONST = 7¶
Like LITERAL but has constant data (stored in function). The difference between this and CODE_SNIPPET is that CODE_SNIPPET can’t be used as a parameter without parenthesis.
- METHOD = 1¶
Represents a function that may return a result. Methods take parameters in parenthesis or from next icon of LITERAL or LITERAL_CONST type (parenthesis are automatically inserted). If no parameter is specified inserts parenthesis with code from default_params property (see CommandDefinition). inserts
- class turtlico.lib.command.LiteralParserResult(code, required_modules)¶
Bases:
NamedTuple
- code: str¶
Python code that represents content of the literal
- required_modules: set¶
Set of modules that are in code so they should be loaded
- exception turtlico.lib.command.MissingPluginException(plugin_id: str)¶
Bases:
Exception
- class turtlico.lib.command.Plugin(name: str, list_priority: int = 0, doc_url: Optional[str] = None)¶
Bases:
object
- categories: list¶
List of categories that this contains
- Type
list[CommandCategory]
- doc_url: Optional[str]¶
Contains URL with reference documentation for this. None means that there is no documentation available for this plugin. Turtlico app opens this URL with command ID tag (e.g. #go) when showing help for a command.
- Type
Union[str, None]
- events: list¶
List of events that this contains
- Type
list[CommandEvent]
- static get_all() dict ¶
- static get_from_paths(plugin_paths: list) dict ¶
Load plugins from paths
- Parameters
plugin_paths (list[str]) – The paths
- Returns
ID, Plugin object pairs sorted by list priority and name
- Return type
dict[str, Plugin]
- static get_id_from_path(path: str) str ¶
Returns id as a string
- static get_paths() list ¶
Returns paths of all available plugins Path is a path to a Python module
- static get_paths_in_path(path: str) list ¶
Return paths of plugin files in path
- Parameters
path (str) – Search for plugins in this path
- Returns
Paths of Python files of the plugins
- Return type
list[str]
- id: str¶
The ID of the plugin. This is set automatically.
- Type
str
- list_priority: int¶
Higher priority moves the plugin higher in icons view categories
- Type
int
- modules: dict¶
Dictionary of module-id module pairs that this contains. The id must have ‘tcp_’ prefix.
- Type
dict[str, CommandModule]
- name: str¶
The user friendly name of the plugin
- Type
str
- static new_from_path(path: str) turtlico.lib.command.Plugin ¶
path: Path to a Python module
- static resolve_paths_from_ids(plugin_ids: list) list ¶
Resolves plugin IDs to plugin paths that are installed in the system.
- Parameters
plugin_ids (list[str]) – The list of IDs to resolve
- Raises
MissingPluginException – Raises if a plugin is not found
- Returns
List of paths
- Return type
list[str]
turtlico.lib.compiler module¶
- class turtlico.lib.compiler.Compilation(compiler: turtlico.lib.compiler.Compiler)¶
Bases:
object
Context of current compilation
- cmd_data: str¶
- compile_line(line: List[List[turtlico.lib.command.Command]], line_y: int, cancellable: gi.repository.Gio.Cancellable)¶
- compiler: turtlico.lib.compiler.Compiler¶
- debug_info: Dict[int, Tuple[int, int]]¶
- finish() tuple ¶
- global_variables: set¶
- increase_indent: bool¶
- indentation: str¶
- keyword_level: int¶
- line: list¶
- line_start_command: turtlico.lib.command.Command¶
- modules_to_load: dict¶
- out_line: int¶
- output: list¶
- param_level: int¶
- x: int¶
- y: int¶
- class turtlico.lib.compiler.Compiler(project_buffer: turtlico.lib.projectbuffer.ProjectBuffer)¶
Bases:
gi.overrides.GObject.Object
- compile(code: List[List[turtlico.lib.command.Command]], cancellable: Optional[gi.repository.Gio.Cancellable] = None) tuple ¶
- modules: dict¶
- project_buffer: turtlico.lib.projectbuffer.ProjectBuffer¶
- reload_definitions(*args)¶
turtlico.lib.projectbuffer module¶
- exception turtlico.lib.projectbuffer.CorruptedFileException¶
Bases:
Exception
- class turtlico.lib.projectbuffer.ProjectBuffer¶
Bases:
gi.overrides.GObject.Object
Contains information about a project
- available_commands: dict¶
- available_commands_changed¶
- changed¶
- do_available_commands_changed()¶
- do_get_property(pspec)¶
- do_set_property(pspec, value)¶
- enabled_plugins: dict¶
- get_command(id, data) tuple ¶
- get_definition_plugin(command: turtlico.lib.command.CommandDefinition) Optional[turtlico.lib.command.Plugin] ¶
- load_from_file(file: gi.repository.Gio.File)¶
- project_file¶
The Gio.File of currently opened project
- run_in_console¶
- save() bool ¶
- save_as(file: gi.repository.Gio.File) bool ¶
Saves buffer to the file. The file will become current project_file.
- Parameters
file (Gio.File) – The file
- Returns
True if the project was saved successfully
- Return type
bool
- set_command_data(command, data) turtlico.lib.command.Command ¶
- set_plugin_enabled(plugin_id: str, enabled: bool)¶
- exception turtlico.lib.projectbuffer.RemovedUsedPluginException(missing_commands: set, plugin: turtlico.lib.command.Plugin)¶
Bases:
Exception
- missing_commands: set¶
- plugin: turtlico.lib.command.Plugin¶