Line 129: |
Line 129: |
| ===How to write a plugin=== | | ===How to write a plugin=== |
| | | |
− | Your plugin should be placed in a subdirectory of the plugins directory. In that subdirectory, you need to create a .py file that is a subclass of the Plugin class. The directory and .py file must have the same name and the subclass must also have the same name, with the additional requirement that the first letter of the class name be capitalized. | + | Your plugin should be placed in a subdirectory of the plugins directory. In that subdirectory, you need to create a .py file that defines a subclass of the Plugin class. The directory and .py file must have the same name and the subclass must also have the same name, with the additional requirement that the first letter of the class name be capitalized. |
| | | |
| For example: | | For example: |
− | * the camera plugin, <code>camera_sensor.py</code> is in <code>./plugns/camera_sensor</code> | + | * the camera plugin, <code>camera_sensor.py</code> is in <code>./plugins/camera_sensor</code> |
| * the class, <code>Camera_sensor</code> is defined in <code>camera_sensor.py</code>, e.g., | | * the class, <code>Camera_sensor</code> is defined in <code>camera_sensor.py</code>, e.g., |
| | | |
Line 138: |
Line 138: |
| class Camera_sensor(Plugin): | | class Camera_sensor(Plugin): |
| | | |
− | You will also need a __init__.py file and optionally, an icon subdirectory for your palette icon.
| + | In that subdirectory, you will also need a __init__.py file (which can be empty) and optionally, an icon subdirectory for your palette icon. |
| | | |
| Turtle Art calls the __init__ method when starting up and traps import errors as its means to determine whether or not a plugin has the resources it needs to run. (You may want to remove this exception handler when debugging your plugin. It is in the _init_plugins method in tawindow.py.) It then calls the setup method when creating the palettes. It calls the start method whenever a stack of blocks is run and the stop method when execution is over. Also, there are methods for goto_background, return_to_foreground, and quit. (These methods are typically ignored.) | | Turtle Art calls the __init__ method when starting up and traps import errors as its means to determine whether or not a plugin has the resources it needs to run. (You may want to remove this exception handler when debugging your plugin. It is in the _init_plugins method in tawindow.py.) It then calls the setup method when creating the palettes. It calls the start method whenever a stack of blocks is run and the stop method when execution is over. Also, there are methods for goto_background, return_to_foreground, and quit. (These methods are typically ignored.) |