File: devguide-21.html

package info (click to toggle)
sketch 0.6.13-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 5,284 kB
  • ctags: 8,453
  • sloc: python: 34,711; ansic: 16,543; makefile: 83; sh: 26
file content (94 lines) | stat: -rw-r--r-- 3,819 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<html>
<head>
<title>Developer's Guide: Plugin Configuration</title>
</head>
<body bgcolor=white text=black link=blue vlink=navy alink=red>
<TABLE WIDTH="100%">
<TR>
<TH ALIGN="left" WIDTH="33%"><img SRC="Images/arrow-left.png" WIDTH="16" HEIGHT="16" ALIGN="top" ALT="Prev"></TH>
<TH ALIGN="center" WIDTH="33%"><img SRC="Images/arrow-up.png" WIDTH="16" HEIGHT="16" ALIGN="top" ALT="Up"></TH>
<TH ALIGN="right" WIDTH="33%"><img SRC="Images/arrow-right.png" WIDTH="16" HEIGHT="16" ALIGN="top" ALT="Next"></TH>
</TR>
<TR>
<TD ALIGN="left"><A HREF="devguide-20.html">Plugins
</A></TD>
<TD ALIGN="center"><A HREF="devguide-20.html">Plugins
</A></TD>
<TD ALIGN="right"><A HREF="devguide-22.html">Import Filters
</A></TD>
</TR>
</TABLE>
<HR NOSHADE>
<H2><FONT face="Helvetica,Arial"><A NAME="N1"></A>Plugin Configuration</font></H2>

<P>On startup, Sketch searches for plugins on the <EM>plugin path</EM>. Every
Python source file found is scanned for configuration information.
Later, when the the plugin is needed it is imported.</P>
<P>The plugin path is a list of directories stored in
<CODE>Sketch.config.plugin_path</CODE>. The directory names should be absolute
pathnames. Sketch uses a notation borrowed from the kpathsea library
(which is used by many TeX programs to search files):
<UL>
<LI>If a directory name ends in a slash ('/') search in that
directory and in the directories immediately contained in it.
</LI>
<LI>If a directory name ends with two slashes ('//') search in
that directory and recursively in all subdirectories.
</LI>
<LI>Else, search only in that directory</LI>
</UL>
</P>

<P>The configuration information is a series of Python statements
(assignments), each on its own line, between the lines '<CODE>###Sketch
Config</CODE>' and `<CODE>###End</CODE>'.</P>
<P>One of the assignments must be to a variable named `<CODE>type</CODE>'. This
specifies the type of the plugin (import filter, plugin object, etc.).</P>
<P>Another variable that may be used in the future, is `<CODE>version</CODE>' which
will be used to specify the version of the plugin-config conventions
used (not the version of the plugin itself).</P>
<P>Other variable names are type dependent.</P>
<P>Each of the lines may be commented out.</P>
<P>Example:
<table width="100%" cellpadding="10"><tr><td bgcolor="#FFFFD0">
<PRE>
###Sketch Config
#type = Import
#class_name = 'SKLoader'
#rx_magic = '^##Sketch 1 *(?P&lt;minor&gt;[0-9]+)'
#tk_file_type = ('Sketch Document', '.sk')
format_name = 'SK-1'
###End
</PRE>
</td></tr></table>
</P>
<P>Sketch uses this method--instead of importing every plugin module
and requiring that they register themselves with the plugin
manager--to avoid loading unnecessary modules.</P>
<P>Implementation Note: currently Sketch reads the lines between
`###Sketch Config' and `###End' into a single string (after removing the
initial `#'s if present) and exec's it with a globals dictionary
containing the predefined plugin types and an empty locals dictionary
which receives all the variables. A consequence of this approach is that
it is currently possible to use arbitrary Python statements and not just
assignments. Don't rely on this, it could be changed in the future.</P>


<HR NOSHADE>
<TABLE WIDTH="100%">
<TR>
<TD ALIGN="left"><A HREF="devguide-20.html">Plugins
</A></TD>
<TD ALIGN="center"><A HREF="devguide-20.html">Plugins
</A></TD>
<TD ALIGN="right"><A HREF="devguide-22.html">Import Filters
</A></TD>
</TR>
<TR>
<TH ALIGN="left" WIDTH="33%"><img SRC="Images/arrow-left.png" WIDTH="16" HEIGHT="16" ALIGN="top" ALT="Prev"></TH>
<TH ALIGN="center" WIDTH="33%"><img SRC="Images/arrow-up.png" WIDTH="16" HEIGHT="16" ALIGN="top" ALT="Up"></TH>
<TH ALIGN="right" WIDTH="33%"><img SRC="Images/arrow-right.png" WIDTH="16" HEIGHT="16" ALIGN="top" ALT="Next"></TH>
</TR>
</TABLE>
</body>
</html>