Python Actions
All actions have the same basic format, and nothing more than you see here is required from the TEAforEspresso class’s standpoint:
'''Descriptive comment encouraged'''
# Optional; let's you take advantage of helper functions
import tea_actions as tea
def act(context):
pass
act() should return a bool; if False Espresso will beep.
If you wish to pass any arguments to the function from your XML action definitions, you will need to define them as keyword arguments with sensible defaults. For example:
def act(context, default=None, undo_name=None, **syntaxes):
Remember not to assign values to your keyword arguments in the function’s body, or you risk changing the default value for every consecutive call. This is why many of the TEA generic actions use None
or False
for default values.
You will of course want to import any Python modules necessary for your code. If you import tea_actions, however, you may not need to import any PyObjC-specific code; most of the common things you’ll need are handled by the various tea_action functions.
If you do need direct access to Espresso classes, though, this will import the ones I most commonly use:
from espresso import *
See Espresso module for more info.
If you need access to Espresso classes not included in the Espresso module, you’ll need to do an objc lookup:
import objc
SXSelectorGroup = objc.lookUpClass('SXSelectorGroup')