Changes

Line 129: Line 129:  
===How to write a plugin===
 
===How to write a plugin===
   −
To add a plugin, simply drop a file into the plugins directory. The file must end with _plugin.py and the base class in the file must be descendent from the Plugin class defined in plugin.py
+
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.
   −
'''Note''' that the name of your new class much match the name of the file, but with the first letter capitalized, e.g.:
+
For example:
 +
* the camera plugin, <code>camera_plugin.py</code> is in <code>./plugns/camera_plugin</code>
 +
* the class, <code>Camera_plugin</code> is defined in <code>camera_plugin.py</code>, e.g.,
   −
camera_plugin.py contains:
   
  class Camera_plugin(Plugin):
 
  class Camera_plugin(Plugin):
   −
Turtle Art called 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.)
+
You will also need a __init__.py file 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.)
    
Adding a new palette is simply a matter of:
 
Adding a new palette is simply a matter of: