To add support for a new file format, write a new
import kurt from kurt.plugin import Kurt, KurtPlugin class MyScratchModPlugin(KurtPlugin): def load(self, fp): kurt_project = kurt.Project() # ... set kurt_project attributes ... # return kurt_project def save(self, fp, kurt_project): # ... save kurt_project attributes to file ... Kurt.register(MyScratchModPlugin())
Take a look at
kurt.scratch20 for a more detailed example.
List available plugins¶
To get a list of the plugins registered with
>>> kurt.plugin.Kurt.plugins.keys() ['scratch20', 'scratch14']
You should see your plugin in the output, unless you forgot to
Some things to keep in mind:
- Most Scratch file formats have the stage as the base object – so project attributes, such as the notes and the list of sprites, are stored on the stage object.
- For Scratch, which doesn’t support stage-specific variables, global variables and lists are stored on the Project, not the Stage.
- If your plugin contains obsolete blocks, they should be at the end of the
blockslist. Otherwise things might not work properly.
Handles a specific file format.
Loading and saving converts between a
Project, kurt’s internal representation, and a file of this format.
Short name of this file format, Python identifier style. Used internally by kurt.
display_name= 'Scratch 2.0 Sprite'¶
Human-readable name of this file format. May be displayed to the user. Should not contain “Project” or “File”.
"Scratch 2.0 Sprite",
The extension used by this format, with leading dot.
Project.loadto recognise its files.
A list of the
Featuresthat the plugin supports.
The list of
PluginBlockTypeobjects supported by this plugin, in the order they appear in the program’s interface.
Load a project from a file with this format.
Project.pathwill be set later.
Project.namewill be set to the filename of the path to the file if unset.
Parameters: fp – A file pointer to the file, opened in binary mode. Returns:
Save a project to a file with this format.
- path – A file pointer to the file, opened in binary mode.
- project – a
The Kurt file format loader.
This class manages the registering and selection of file formats. Used by
Register a new
Once registered, the plugin can be used by
Project.loadsees a file with the right extension
Project.convertis called with the format as a parameter
Returns the first format plugin whose attributes match kwargs.
nameis used as the
ValueErrorif the format doesn’t exist.
Return the block with the given
Returns None if the block is not found.
Return a list of blocks matching the given
Capitalisation and spaces are ignored.