home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 4 / DATAFILE_PDCD4.iso / languages / tcl / !Tcl / doc / W_Intro < prev    next >
Encoding:
Text File  |  1996-01-28  |  23.4 KB  |  548 lines

  1.  
  2.           -- w --    wimp extensions for Tcl
  3.  
  4. The w extensions provide 7 commands
  5.  
  6.     w_init         .. initialize
  7.     w_bar          .. setup iconbar icon
  8.     w_error        .. show wimp error box
  9.     w_box          .. dialog box commands
  10.     w_task         .. taskwindow commands
  11.     w_draw         .. draw graphics window commands
  12.     w_text         .. scrolling text window commands
  13.  
  14. They use three global variables w_where and w_debug and w_file.
  15.  
  16. The w_init command must be called before any other w_ commands are called.
  17. It can only be called once.
  18.  
  19. INTRODUCTION
  20.  
  21. The w commands operate by installing a selection of scripts that are called when
  22. various wimp events such as mouse clicks occur.
  23.  Before the scripts are interpreted %-substitution takes place in order to pass
  24. any necessary arguments to the script. The script is scanned for % characters.
  25. If the % is followed by a lower case letter the percent and letter are replaced
  26. by a string, otherwise the % but not the character is dropped.
  27.  The avaliable substitution letters depend on the event concerned and are
  28. detailed below. Using other letters can have unpredictable results.
  29.  
  30. example
  31.          w_init myprog
  32.          w_bar  -click {clickproc %b}
  33.          proc clickproc {button} { if {$button=="sS"} exit}
  34.  
  35. The w_init command starts up the wimp. The application will have taskname
  36. "myprog" in the task display list.
  37. w_bar puts an wimp sprite called !myprog on the iconbar. If it is clicked on
  38. the script {clickproc %b} is %-substituted and then run. %b gives a string of
  39. the form  [a|s][S][C]. a for the alter button and s for select. S if the
  40. shift key is held down and C for the control key.
  41.  
  42. So if you click select on the icon with only the shift key held down the script
  43.  
  44.           clickproc sS
  45.  
  46. is interpreted and the program exits.
  47.  
  48. If an uncaught error occurs while interpreting these scripts, or while
  49. interpreting the source file after w_init has been called two things happen
  50.  
  51.  1) The global variable w_where is set to a string indicating which script the
  52.     error occured in. e.g. "iconbar click" for the script in the example above.
  53.  
  54.  2) The contents of global variable w_debug are interpreted.
  55.  
  56. w_init sets w_debug to
  57.  
  58.     "if {![w_error \"Error in $w_where :- $errorInfo\" -ok -cancel]} exit"
  59.  
  60.     this puts up a wimp error box indicating the place and nature of the error.
  61.     If you click on Cancel the program exits, on OK and it continues,
  62.     abandoning the script.
  63.  
  64.     NOTE: If an error occurs before a call to w_bar and you continue
  65.           you will not have an iconbar icon and must quit from the task display.
  66.  
  67.     The file !Tcl.library.debug contains a slightly more sophisticated debugging
  68.     system. To use it put the line
  69.  
  70.                    source {<tcl$Dir>.library.debug}
  71.  
  72.     in your code AFTER the call to w_init.
  73.  
  74. OBJECT IDENTIFIERS
  75.  
  76.      The procedures w_draw w_text w_task and w_box all take a <name> parameter.
  77. This is passed to the object when it is created, and used to identify the object
  78. in other calls. Two objects of the same type must be given different names.
  79.  
  80.    example
  81.             w_text output create
  82.             w_text output print "Hello World"
  83.             w_text output open
  84.  
  85. This creates a scrolling text document called "output", puts some text in it and
  86. then opens a window on it.
  87.  
  88. TAGS
  89.      Some of the functions below return results from menu or dialog box
  90. actions in variables. If the same menu or dialog box description is used more
  91. than once it is necessary to separate the results. This is done by passing a
  92. tag to the construction. This causes the variable used to be <name>(<tag>)
  93. instead of just <name>. Items in menus opened from windows can be tagged with
  94. the name of the window, iconbar menu items can be tagged "bar". Transient
  95. dialog boxes can be tagged with the tag of their menu, persistent ones can be
  96. passed a tag when they are opened.
  97.  
  98.     example
  99.              w_box filebox create "File Name" { vlist {write Filename fname }
  100.                                                       {default Set  {list 1}}
  101.                                               }
  102.              w_box filebox open
  103.  
  104. The create command creates a dialog box template called filebox, with a
  105. writable icon labelled "Filename" and and a default action item labelled "Set".
  106. The second command opens a copy of "filebox" as a persistent dialog box.
  107.  
  108. Clicking on "Set" copies the contents of the writeable icon into the global
  109. variable "fname".
  110.  If instead we open the box using
  111.  
  112.              w_box filebox open box1
  113.  
  114. clicking on set copies the icon contents into fname(box1). "box1" is called the
  115. tag.
  116.  
  117.  
  118. MENU DESCRIPTIONS
  119.  
  120. A menu description is a word that decomposes into a list. The first item
  121. of the list is the menu title, the remainder are menu item descriptions.
  122. There must be at least one of the latter.
  123.  
  124. A menu item description is a word that decomposes into a list, the first item
  125. is the text that appears in the menu. Any remaining items are
  126.  
  127.            -tag                ... tag the menu item by the window name or "bar"
  128.            -click <script>     ... run script if this item is selected
  129.            -tick  <variable>   ... the item can be ticked or unticked by
  130.                                    selecting it. The tick status (0 or 1)
  131.                                    is stored in the variable.
  132.                                    you can change it by writing to the variable
  133.                                    you can monitor it with a trace on the
  134.                                    variable.
  135.            -grey <variable>    ... uses <variable> to decide whether the item
  136.                                    is greyed out. 1=>grey 0=> don't grey.
  137.            -sub  <menudescription>
  138.                                ... creates a submenu
  139.            -dbox <name>        ... opens a transient dbox
  140. -sub and -dbox cannot be used together.
  141. -click and -tick cannot be used together.
  142. -tag must preceed -tick -grey or -dbox options
  143.  
  144. The percent substitution %w is set to the window name (or "bar") when the click
  145. script or scripts associated with a transient dbox are interpreted.
  146.  
  147. example
  148.            w_bar -menu { MyProg { Info -dbox progInfo}
  149.                                 { Submenu -sub { MyProg {I1 -tick ticked}
  150.                                                         {I2 -click {check %w}}
  151.                                                }
  152.                                 }
  153.                                 { Quit -click exit}
  154.                        }
  155.  
  156. This command puts an icon on the iconbar with a menu.
  157. The first item leads to a transient dialog box called progInfo
  158. The second leads to a submenu.
  159. The third causes the program to quit.
  160. The second item on the submenu runs the script "check bar".
  161.  
  162. LENGTHS     <length> = <number>?[i|m|c|p|d]?
  163.  
  164.        Lengths in w commands are given by a (possibly decimal) number
  165. possibly followed immediately by a single letter unit. If no unit letter
  166. is given the length is in OS units. The unit letters are
  167.  
  168.                  i inches
  169.                  m millimeters
  170.                  c centimeters
  171.                  p points
  172.                  d draw units
  173.       example
  174.  
  175.             w_text mywind create -width 6.5i
  176.  
  177. Creates a text window 6.5 inches wide.
  178.  
  179. COLOURS     <colour> = <number>:<number>:<number>  or <name>
  180.  
  181.  
  182.         Colours in w commands are given by 3 numbers in the range 0-255
  183. representing the red green and blue components separated by colons.
  184. Alternatively if a name, not beginning with a digit, is given it
  185. is looked up in the global array colours(<name>) to get a number sequence
  186. of the above form.
  187.         The name "none" gives a transparent 'colour' for draw path objects.
  188.  
  189.     example
  190.             set colours(red) 255:0:0
  191.             w_text mytext create -fg red -bg 200:200:255
  192.  
  193. gives a text window with red text on a pale blue background.
  194.  
  195. FONTS      <font> = f<name>?@<length>? or F<fontname>?@<length>?
  196.  
  197.     The second form takes a pathname in a font directory. The first looks
  198. up <name> in the global array fonts(<name>) to obtain a fontname.
  199.  
  200.     The array "fonts"  is usually set up with standard names of font types,
  201. allowing users to specify their preferences.
  202.  
  203.                      n   normal font
  204.                      i   italic font
  205.                      b   bold font
  206.                      t   typewriter (monospaced) font
  207.                      a   alternative font
  208.                          (e.g. sans-serif if the others have serifs)
  209.  
  210.       example
  211.  
  212.              set fonts(n) Trinity.Medium
  213.              set fonts(i) Trinity.Italic
  214.              set fonts(b) Trinity.Bold
  215.              w_text mytext options -pon
  216.              w_text mytext write "This is |fi|italic, |fn| this is |fb|bold"
  217.              w_text mytext print
  218.              w_text mytext write "This is |FTrinity.Bold@40p|Big and Bold"
  219.  
  220. The  fourth line turns || processing on. The fifth writes "italic," in italic
  221. and "bold" in bold. The last writes "Big and Bold" in 40 point bold.
  222.  
  223. Note that w_text documents use a constant line spacing. If you use large fonts
  224. for titles etc. you may need to add blank lines to avoid overlaps as in the
  225. penultimate line.
  226.  
  227. TEXT FEATURES
  228.  
  229. When the w_text commands add text to a document the following substitutions
  230. can be optionally made.
  231.  
  232.             |<font>|      ... change font
  233.             |<colour>|    ... change colour
  234.             ||            ... display a |
  235.  
  236. DRAW OBJECTS
  237.  
  238.     There are four types of objects displayed in draw diagrams
  239.     text objects, path objects,sprites and group objects.
  240.  
  241.     <textobject> = text <point> <string> <options>
  242.  
  243. A point has the format (<number>,<number>) the numbers are diagram coordinates.
  244.  
  245. Possible options are
  246.  
  247.          -<font>         ... The font
  248.          -c<colour>      ... Text colour
  249.          -b<colour>      ... Background colour hint
  250.          -o<origin>      ... Determines which point in the text is placed
  251.                              at the given point.
  252.  
  253.            <origin> = ?[l|c|r]??[t|m|b]?
  254.  
  255.            x-position :- l=>left c=>center r=>right  nothing=> text base left
  256.            y-position :- t=>top m=>middle b=>bottom  nothing=> text baseline
  257.  
  258.      <path object> =  path <path sequence> <options>
  259.  
  260.      A path sequence is a string of the form
  261.  
  262.      <point><gap><point> .... <gap><point>?.?
  263.  
  264. A terminating full stop indicates that the path is closed.
  265.  
  266. Gaps can be            nothing       ... move between points
  267.                           -          ... join points with line
  268.                 '<'<point><point>'>' ... Bezier curve with the given
  269.                                          control points
  270. Possible options are
  271.  
  272.                -i<colour>     ... interior colour (default none)
  273.                -c<colour>     ... path colour     (default black)
  274.                -t<length>     ... thickness (half width) (default thin)
  275.                -r             ... round corners  (default mitres)
  276.  
  277.      <sprite object> = sprite <name> <point> ?<point?
  278.  
  279.                 name is a name of a sprite in the user sprite area
  280.                 the bottom left corner is placed at the first point
  281.                 if the second point is provided it is the top right
  282.                 corner, otherwise the sprite is scaled to its natural
  283.                 mode independent size.
  284.                 At present sprites of 16 colours or less need to be
  285.                 provided with a palette, or they will appear in a
  286.                 peculiar set of colours.
  287.  
  288.      <group object> =  group <list of objects>
  289.  
  290.  
  291.      examples
  292.  
  293.               w_draw mydiagram text (1,2) "Hello World" -ocm -cred
  294.               w_draw mydiagram path (1,2)-(3,2)-(3,4)-(1,4). -iblue -cnone
  295.               w_draw mydiagram sprite mysprite (1,1) (2,2)
  296.               w_draw mydiagram group\
  297.                                { text (5,5) "Hello again"}
  298.                                { path (4,5)<(4,6)(6,6)>(6,5) -t.05i }
  299.  
  300. The first command puts red text centered at (1,2)
  301. The second draws a blue square with no boundary.
  302. The third plots mysprite scaled to a 1 unit square.
  303. The last put some text above a curve in a group object.
  304.  
  305. DIALOG BOX COMPONENTS
  306.  
  307.  
  308.     action <name> [<script>]                ... action icon
  309.     default <name> [<script>]               ... default action icon
  310.  
  311. If the icon is selected and there is no script the box is just closed. 
  312. If there is a script first all the dialog box variables are set, then
  313. the script is interpreted. If the script returns "0" the box is closed.
  314.  
  315.     info    <name> <text>                   ... static text display
  316.     display <name> <variable> ?<width>?     ... display of variable value
  317.                                                 <width> in characters
  318.                                                 default=20
  319.  
  320.     option  <name> <variable>               ... option icon
  321.     radio   <name> <variable>               ... radio button
  322.  
  323. The contents of these icons are read from the variables when the box
  324. is opened, they are copied back when the variables are set.  
  325. Option icon variables contain 0=>deselected 1=>selected.
  326. Radio icons are in the same group if they have the same variable. The variable
  327. is set to <name> for the selected button.
  328.  
  329.     write   <name> <variable> ?<width>? ?<length>?  ... writeable icon
  330.  
  331. The contents of <variable> are placed in the icon when it is opened and
  332. copied back when variables are set. Width gives the number of characters
  333. displayed and length the size of the buffer.
  334. Defaults: width=20 length=256.
  335.  
  336.     save  <hexfiletype> <variable> <script> ... save icon and filename icon
  337.  
  338. This gives an icon corresponding to the filetype that can be dragged.
  339. It asks the task it is dropped on to save a file whose leafname is taken
  340. from the writeable icon. If the task responds <script> is interpreted with
  341. global variable w_file  set to the full filename required.
  342. Variables are set before the script is interpreted. The script should save to
  343. the required filename.
  344. It should return 0,1,2 or 3. 2 or 3 indicate failure to save correctly.
  345. 0 or 2 indicate that the dialog box should be closed.
  346.  
  347.     sprite <spritename>                     ... display a sprite
  348.  
  349.     The sprite is looked for first in the user sprite area and then in 
  350.     the wimp sprite area. 
  351.  
  352.     box   <name> <component>                ... box round component
  353.     hlist <list of components>              ... horizontal list
  354.     vlist <list of component>               ... vertical list
  355.  
  356.  
  357. COMMANDS
  358.  
  359.     w_init <progname> ?<spritefile>?
  360.                         ... initialise the wimp system, register the program as
  361.                             a wimp task called <progname>
  362.                             progname is truncated to 8 characters.
  363.                             It is used to generate icon names, default window
  364.                             names and task names.
  365.                             The other w_commands cannot be called before w_init.
  366.                             w_init can only be called once.
  367.                             if spritefile is provided it is loaded from 
  368.                             <<progname>$dir>.<spritefile> into the user
  369.                             sprite area.
  370.  
  371.     w_bar ...           ... w_bar puts an icon called !progname on the icon bar.
  372.                             This should be in the wimp sprite area.
  373.                             It should probably be called once only.
  374.                             It can be followed by some of the following pairs
  375.  
  376.        -menu <menudescription>
  377.                         ... provides an iconbar menu
  378.        -click <script>  ... interpret <script> on an iconbar click
  379.                             sets %b to a button description string
  380.        -drag  <script>  ... interpret <script> after something is dragged to the
  381.                             iconbar.
  382.                             sets global variable w_file to the filename
  383.                             and %t to the filetype in decimal.
  384.  
  385.     w_error <text> ?-ok? ?-cancel?
  386.                         ... display <text> in a wimp error box. <text> is
  387.                             truncated to 251 characters. -ok gives an OK button
  388.                             -cancel gives a CANCEL button. (default OK only)
  389.                             returns OK=>1 CANCEL=>0.
  390.  
  391.     w_box  <name> create <title> <component> ?-tag?
  392.                         ... creates a dialog box template called <name>
  393.                             with title <title> containing <component>.
  394.                             If the "-tag" option is given variable use will
  395.                             be tagged.
  396.  
  397.     w_box <name> open ?<tag>?
  398.                         ... opens a persistent dialog box using a template
  399.                             called <name> previously created using
  400.                             w_box <name> create ...
  401.                             If <tag> is given and the -tag option was given
  402.                             during creation variable use will be tagged.
  403.  
  404.     w_task   <name>   create ...
  405.  
  406.                          ... Creates a taskwindow task called <name>.
  407.                              It can be followed by some of the following pairs
  408.  
  409.        -receive <script> ... Runs <script> when the task sends data
  410.                              sets %o to the received data.
  411.                              Note the data may be broken into chunks not at
  412.                              line boundaries.
  413.  
  414.        -quit <script>    ... Runs <script> when the task closes down.
  415.        -command <string> ... Passes <string> to the CLI in the taskwindow
  416.                              <string> is truncated to 140 characters.
  417.        -slot <number>    ... Sets the task's initial wimpslot to <number>K.
  418.                              Defaults to 128K
  419.  
  420.     w_task <name> send <string>
  421.                          ... Sends <string> to the task.
  422.                              Not including a newline.
  423.     w_task <name> kill   ... Kill the task (this will run any "-quit" script).
  424.     w_task <name> suspend
  425.                          ... Suspend the task.
  426.     w_task <name> resume ... Resume after suspension.
  427.  
  428.     w_text    <name>   create ...
  429.                          ... Creates a document window.
  430.                              It can be followed by some of the following pairs
  431.  
  432.        -title  <string>  ... Sets the title for any windows on the document.
  433.        -close  <script>  ... Runs script when the user attempts to close the
  434.                              last window on the document.
  435.                              %w is set to the window name.
  436.                              The script can return:-
  437.                              0 => Close window and document.
  438.                              1 => Close neither.
  439.                              anything else => Close window but not document.
  440.                              If no "-close" option is given the window and
  441.                              document are both closed.
  442.  
  443.        -fg     <colour>      Sets the main text colour. Default black.
  444.        -bg     <colour>      Sets the background colour. Default white.
  445.  
  446.        -menu   <menudescription>
  447.                              The menu is opened from any of the document's
  448.                              windows.
  449.  
  450.        -width  <length>      Sets the window width.(Default 800 os units)
  451.        -size   <length>  ... Sets the main font size (Default 20p)
  452.        -height <length>  ... Sets the separation between lines.
  453.                              ( Default depends on main font size.)
  454.  
  455.     w_text   <name>   options ...
  456.                              Sets some text options.
  457.                              It can be followed by some of the following pairs
  458.  
  459.            -l<length>    ... left margin                   (from left of window)
  460.            -i<length>    ... paragraph indent (write only) (from left of window)
  461.            -r<length>    ... right margin                 (from right of window)
  462.            -j[on|of]     ... justify          (write only)
  463.            -p[on|off]    ... process
  464.            -L            ... set left         (print only)
  465.            -C            ... center           (print only)
  466.            -R            ... set right        (print only)
  467.  
  468.                              The options apply to any "write" or "print"
  469.                              commands after the option command
  470.  
  471.                              defaults are -l0 -i0 -r0 -joff -poff -L
  472.  
  473.     w_text    <name>   print  ...
  474.  
  475.                          ... The following arguments are joined with space
  476.                              separators. If the "process" option is on they
  477.                              are scanned for || sequences.
  478.                              The result is printed in a single line.
  479.                              The most recently opened window (if any)
  480.                              is scrolled to show the text.
  481.  
  482.     w_text    <name>   write  ...
  483.  
  484.                          ... The following arguments are joined with space
  485.                              separators. If the "process" option is on they
  486.                              are scanned for || sequences.
  487.                              The result is split into lines and displayed as
  488.                              a paragraph. The first line is indented by the
  489.                              paragraph indent. If the "justify" option is on
  490.                              all but the last line will be justified to both
  491.                              margins.
  492.                              The most recently opened window (if any)
  493.                              is scrolled to show the text.
  494.  
  495.     w_text <name> open   ... Open a window on the document.
  496.  
  497.     w_draw    <name>  create ...
  498.                              Creates a draw diagram.
  499.                              It can be followed by some of the following pairs
  500.  
  501.        -title  <string>  ... Sets the title for any windows on the diagram.
  502.        -close  <script>  ... Runs <script> when the user attempts to close the
  503.                              last window on the diagram.
  504.                              %w is set to the window name.
  505.                              The script can return:-
  506.                              0 => Close window and diagram.
  507.                              1 => Close neither.
  508.                              anything else => Close window but not diagram.
  509.                              If no "-close" option is given the window and
  510.                              diagram are both closed.
  511.  
  512.        -click   <script> ... Runs <script> when the user clicks on the diagram.
  513.                              %b is set to the button type.
  514.                              %x and %y are set to the position of the click
  515.                              in diagram coordinates. (Origin at bottom left)
  516.  
  517.        -page    <pagesize>...Sets the diagram size. This can be either
  518.                              A<number>?[p|l]? or <length>x<length>
  519.                              p and l denote portrait (default) or landscape.
  520.                              Without a -page option defaults to A4p.
  521.  
  522.        -bg      <colour>  ...Sets the background colour.
  523.  
  524.        -xscale  <length>  ..\ Determines the scale used for describing
  525.        -yscale  <length>  ../ objects, and for returning mouse clicks.
  526.                               Defaults 1i.
  527.  
  528.        -menu    <menudescription>
  529.                              The menu is opened from any of the documents
  530.                              windows.
  531.  
  532.     w_draw <name> open   ... Open a window on the document.
  533.  
  534.     w_draw <name> save  <filename>
  535.                          ... Save the diagram as a draw file
  536.  
  537.     w_draw <name> ?above <number>? <object>
  538.                          ... Adds an object to the diagram.
  539.                              Returns a number to identify the object within
  540.                              the diagram. If no "above" option is given
  541.                              the object is at the back of the diagram,
  542.                              otherwise it is in front of the <number> given.
  543.                              If <number> is not found (e.g. <number>=-1)
  544.                              it is placed at the front.
  545.  
  546.     w_draw <name> delete <number>
  547.                           ...Removes the numbered object from the diagram.
  548.