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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455
|
[subsection {Class API}]
The package exports the API described here.
[list_begin definitions]
[call [cmd ::diagram] [arg objectName] [arg canvas] [opt [arg script]]]
The command creates a new instance of a diagram
controller and returns the fully qualified name of the
object command as its result.
The new instance is connected to the specified
[arg canvas] object, which is used as the diagrams
graphics engine. This is usually an instance of Tk's
canvas, however any object which is API compatible to
Tk's canvas can be used here.
[para]
The API of this object command is described in the
following section, [sectref {Object API}]. It may be
used to invoke various operations on the object.
[para]
If the [arg script] argument is specified then method
[method draw] will be invoked on it.
[list_end]
[subsection {Object API}]
Instances of the diagram class support the following
methods:
[list_begin definitions]
[call [arg diagramObject] [method {new direction}] [arg name] [opt "[arg key] [arg value]..."]]
This method defines a new named direction and its
attributes. The latter is given through the
[arg key]/[arg value] pairs coming after the [arg name].
[para]
Users are mostly free to specify arbitrary attributes
with whatever meaning they desire. The exception are
the names [emph angle] and [emph opposite]. They are
special to the diagram package and have a fixed meaning.
[list_begin definitions]
[def angle]
This attribute specifies the angle of the direction in
degrees, where 0 points east (to the right) and 90 points
north (up).
[def opposite]
This attribute specifies the name of the direction
which should be considered as complementary to the
named one.
[list_end]
[call [arg diagramObject] [method {new element}] [arg name] [arg attributes] [arg cmdprefix]]
This method defines a new graphics element for the
drawing language. I.e. [arg name] will become a new
command in the language, and the specified command
prefix ([arg cmdprefix]) will be called to perform
the actual drawing.
[para]
[arg attributes] specifies the set of attributes for which
data has to be available. I.e. the system will run the
...-callbacks for these attributes.
See the method [method {new attribute}] for more information
on attribute definitions.
[para]
The command prefix is expected to conform to the
following signature:
[list_begin definitions]
[def "[cmd cmdprefix] [arg canvas] [arg attributes]"]
Where [arg canvas] is the handle of the canvas widget
to draw to, and [arg attributes] is a dictionary
holding the attributes for the element, be they
user-specified, or defaults.
[para]
The results of the command has to be a list containing
at least two and at most four items. These are, in order:
[list_begin enumerated]
[enum] The list of canvas items the drawn element consists of.
[enum] The dictionary of named locations in the element, its
[term corners].
[enum] An optional mode, either "relative" or "absolute".
When not returned "relative" is assumed. In the
case of a relative element position the attributes
"with" and "at" are used to determine the final
position of the new element.
[enum] An optional name of a direction. If not the
empty string this is handed to the automatic
layouter as the new direction to follow.
[list_end]
[list_end]
[call [arg diagramObject] [method {new alias}] [arg name] [arg cmdprefix]]
This method defines a new command for the drawing
language. I.e. [arg name] will become a new command in
the language, and the specified command prefix
([arg cmdprefix]) will be called on use of this new
command. Any arguments given to the command are
simply passed to the prefix. There is no fixed siganture.
[para]
Note that the prefix is run in the context of the
drawing language, allowing the direct use of any
existing commands.
[call [arg diagramObject] [method {new command}] [arg name] [arg arguments] [arg body]]
This is like [method {new alias}] except that the new
command is defined as a procedure in the language's
context, with regular argument list and body.
[call [arg diagramObject] [method {new attribute}] [arg name] [opt "[arg key] [arg value]..."]]
This method defines a new named attribute which can be
used by graphical elements. The handling of the
attribute by the processor is declared through the
[arg key]/[arg value] pairs coming after the [arg name].
[para]
The accepted keys and their meanings are:
[list_begin definitions]
[def [const key]]
The value of this key is the name of the key
under which the attribute's value shall be
stored in the attribute dictionary given to
the drawing command after attribute processing
is complete.
[para]
This key is optional. If it is not specified it
defaults to the name of the attribute.
[def [const get]]
The value of this key is a command prefix
which will be invoked to retrieve the
attribute's argument(s) from the command
line.
[para]
This key is optional. If it is not specified a
default is used which takes the single word
after the attribute name as the attribute's
value.
[para]
The signature of the command prefix is
[list_begin definitions]
[def "[cmd cmdprefix] [arg wordqueue]"]
Where [arg wordqueue] is the handle of
a queue object conforming to the API
of the queues provided by package
[package struct::queue]. This queue
contains the not-yet-processed part of
the attribute definitions, with one
entry per word, with the first entry
the word [emph after] name of the
attribute. In other words, the
attribute's name has already been
removed from the queue.
[para]
The result of the command is the value
of the attribute, which may have been
taken from the queue, or not.
[list_end]
[def [const transform]]
The value of this key is a command prefix
which will be invoked to transform the
retrieved value (See [const get]) into their
final form.
[para]
This key is optional. If it is not specified
no transformation is done.
The signature of the command prefix is
[list_begin definitions]
[def "[cmd cmdprefix] [arg value]"]
Where [arg value] is the value to transform.
[para]
The result of the command is the final
value of the attribute.
[list_end]
[def [const type]]
The value of this key is a command prefix
which will be invoked to validate the
attribute's argument(s).
[para]
This key is optional. If it is not specified
no validation is done.
[para]
The signature of the command prefix is that of
snit validation types. See the documentation
of the [package snit] package.
[def [const merge]]
The value of this key is a command prefix
which will be invoked to insert the
transformed and validated attribute value into
the dictionary of collected attributes.
[para]
This key is optional. If it is not specified
a default merge is chosen, based on the data
for key [const aggregate], see below.
The signature of the command prefix is
[list_begin definitions]
[def "[cmd cmdprefix] [arg value] [arg dict]"]
Where [arg value] is the value to
insert, and [arg dict] the dictionary
of attributes and values collected so
far.
[para]
The result of the command is the new
dictionary of attributes.
[list_end]
[def [const aggregate]]
The value of this key is a boolean flag. It
has an effect if and only if the key [const \
merge] was not specified. This key is
optional. If it is not specified it defaults
to [const False].
[para]
If the key is effective, the value of [const \
False] means that the attribute's value is
[emph set] into the dictionary using the value
of key [arg key] (see above) as index,
[emph overwriting] any previously specified value.
[para]
If the key is effective, the value of [const \
True] means that the attribute's value is
[emph added] to the dictionary using the value
of key [arg key] (see above) as index,
[emph extending] any previously specified value.
This means that the final value of the
attribute as seen after processing will be a
list of the collected values.
[def [const default]]
The value of this key is a command prefix
which will be invoked after collection of
attributes has been completed and this
attribute is in the list of required
attributes for the drawing element (See
argument [arg attributes] of method
[method {new element}]).
[para]
Note that the connection is made through the
value of key [arg key], not through the
attribute name per se.
[para]
Further note that this command prefix is
invoked even if a user specified attribute
value is present. This allows the command
to go beyond simply setting defaults, it
can calculate and store derived values as
well.
[para]
This key is optional. If an element requires
this attribute, but [arg default] is not
specified then nothing will be done.
[para]
The signature of the command prefix is
[list_begin definitions]
[def "[cmd cmdprefix] [method init]"]
This method is run when the attribute
is defined, its responsibility is to
initialize anything in the language
namespace for the attribute and
default processing.
[para]
The result of this method is ignored.
[def "[cmd cmdprefix] [method fill] [arg varname]"]
This method is run to put defaults, or
derived values into the attribute dictionary
named by [arg varname]. This variable will
be found in the calling context.
[para]
The result of this method is ignored.
[def "[cmd cmdprefix] [method set] [arg name] [arg value]"]
This method is run to push current a
attribute value into the language
namespace, to make it the new default.
[para]
The result of this method is ignored.
[list_end]
[def [const linked]]
This key is effective if and only if key
[const default] is not specified. In that
case is supplies a default handling for
[const default], linking the attribute to a
variable in the language context.
[para]
The value for this key is a 2-element list
containing the name of the variable to link
to, and its initial value, in this order.
[list_end]
[call [arg diagramObject] [method {unknown attribute}] [arg cmdprefix]]
This method registers the command prefix with the
subsystem processing the attributes for element
commands, telling it to call it when it encounters an
attribute it is unable to handle on its on.
[para]
It is allowed to register more than callback, these
will be called in order of registration (i.e. first to
last), until one of the callbacks accepts the current
input.
The command prefix is expected to conform to the
following signature:
[list_begin definitions]
[def "[cmd cmdprefix] [arg wordqueue]"]
Where [arg wordqueue] is the handle of a queue
object conforming to the API of the queues
provided by package [package struct::queue].
This queue contains the not-yet-processed part
of the attribute definitions, with one entry
per word, with the first entry the name of the
attribute which could not be processed.
[para]
The results of the command has to be a boolean
value where [const True] signals that this
callback has accepted the attribute, processed
it, and the new state of the [arg wordqueue]
is where the general processing shall continue.
[para]
Given the signature the command has basically
two ways of handling (rewriting) the attributes
it recognizes:
[list_begin enumerated]
[enum] Replace the attribute (and arguments)
with a different attribute and arguments.
[enum] Push additional words in front to get
the general processing unstuck.
[list_end]
[list_end]
[call [arg diagramObject] [method draw] [arg script]]
This method runs the given [arg script] in the
context of the drawing language definitions.
See section [sectref {Language Reference}] for
details on the available commands.
[para]
[emph Note] that [arg script] is [emph trusted].
It is executed in the current interpreter with
access to its full abilities.
For the execution of untrusted diagram scripts this
interpreter should be a safe one.
[list_end]
[comment {
[subsection {Element/Attribute Processing}]
[image examples/figure-00-eap]
}]
|