A domain specific addon or course needs to be initialized in order for a user to be able to use it. This is done by:
- copying the
ankiscript.py
file from the Anki Script addon directory - providing a
meta.json
file - providing an
__init__.py
file
It is planned that a future version of Anki Script will provide a user interface to remove the need for these tasks.
Copying the
ankiscript.py
fileProviding a
meta.json
fileProviding an
__init__.py
file
As domain experts and course providers are unlikely to be programmers the
__init__.py
file required is a small amount of boilerplate code:
from .ankiscript import init_course
init_course('Some Domain',
help='help',
setup='setup')
If the addon is used to provide a course that progressively develops the only difference required in the
__init__.py
file is that a list
of lessons is added along with a menu location for the associated menu items:
...from .ankiscript import init_course
init_course('Anki Script example course',
help='help',
setup='setup',
lessons = [
('1: Verb infinitives', 'lesson1'),
('2: Present tense', 'lesson2'),
('3: Past tense', 'lesson3'),
('4: Verb aspects', 'lesson4')
],
menu= 'Courses.Anki Script Example')
For more advanced uses there are more possible arguments to the init_course function:
...
def init_course(name, help=None, setup=None, lessons=None, menu=None, menuItems=None, syntax=None):
"""Register a course with Anki Script.
Keyword arguments:
name -- course name
help -- directory / URL with course help, optional
setup -- directory / URL with addon initialization data, only required if the course requires initialization
lessons -- list of name, directory / URLs, only required if the course has separate lessons
menu -- menu to use for course actions, defaults to course name.
menuItems -- additional menu items as a list of name, callback pairs, optional.
syntax -- function called with a single Parser arg to set up parsing using a different syntax from default one
"""
Custom menu
The menu defaults to the addon name if no menu is specified and lessons and/or custom actions are defined.
No menu is added for the course if there are no actions for it (ie. it has no lessons and custom actions).
The course actions can be added to a submenu by using a dot '.' in the menu name to specify the menu hierarchy.
...
So a menu location of
Courses.Anki Script Example
would result in the user seeing:
Custom menu actions
A list of custom menu actions may be specified - these appear in a separate section of the domain
specific / course addon menu.
For additional menu items the callbacks must take the course object as the only parameter. These
are added as additional menu items at the end of the course menu, and enable custom actions to be
added for a course. Providing a single value of None instead of a pair will add a menu separator.
The Anki Script example course addon contains an example custom menu action that illustrates this:
def about(course):
from aqt.utils import showInfo
showInfo('About ' + course.name)
init_course('Anki Script example course',
...
menuItems=[
('About', about)
])
Help
Help information may be provided for the addon via the
help
argument.
Help information can be displayed by a script, for instance to provide instructions on any actions that they need to do
after running a script.