Extending the code editor

class pyto_core.EditorDelegate

An object that receives events from the code editor. Override it to implement your plugin.

did_run_script(script_path: str, local: dict, exception: Exception)

Called when a script finished running.

Parameters:
  • script_path – The path of the script.
  • local – The __dict__ attribute of the executed script.
  • exception – The exception raised by the script. Can be None.
editor_button_icon(script_path: str) → Union[PIL.Image.Image, None, str]

By overriding this method, a new button will be added the the code editor’s toolbar.

From this function, return the icon of this button.

There are three possible return types:

  • A PIL Image
  • An Objective-C UIImage object
  • A string with the name of an SF Symbol. List of SF Symbols

This method receives the path of the script being edited as parameter. If you want to not display a button for specific scripts, raise NotImplementedError.

Parameters:script_path – The path of the script being edited.
Return type:Union[Image.Image, UIImage, str]
editor_button_pressed(script_path: str)

If the editor_button_icon() function is implemented, this method will be called when the button in the toolbar is pressed.

Parameters:script_path – The path of the script being edited.
run_script(script_path: str, run: Callable[[], None])

Called when a script will be executed.

If the run() function isn’t called, the script will not be executed.

Parameters:
  • script_path – The path of the script to be executed.
  • run – Call this function to run the script.
show_ui(view: pyto_ui.View, mode: ui_constants.PRESENTATION_MODE)

This function is called when a View will be presented.

If you override this method, views will not be presented automatically. Use the show_view() or the show_view() function to show the passed view.

Parameters:
  • view – The View to be presented.
  • mode – The presentation mode.
pyto_core.set_editor_delegate(delegate: pyto_core.EditorDelegate)

Sets a EditorDelegate object as the object that will respond to events.