here2share

The TK Library --

May 13th, 2021
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 41.23 KB | None | 0 0
  1. The TK Library
  2.  
  3.  
  4. 1. Introduction and Warning
  5.  
  6.  
  7. Dylan/TK is an experimental TK binding for the Mindy Dylan interpreter. Although it is definitely usable, it is not intended to be an "industrial strength" product. The implementation strategy virtually guarantees that there will be some rough edges.
  8.  
  9. This binding operates by starting a wish interpreter as a slave process and passing both Tcl routines and data between the Mindy interpreter and the slave process. However, Dylan/TK provides an abstraction layer that should vastly reduce or even eliminate the need for users to be familiar with the Tcl extension language. For example, the following Dylan code:
  10.  
  11.     define constant text-frame
  12.  
  13.       = make(<frame>, height: 500, fill: "both", side: "bottom", expand: #t);
  14.  
  15.     define constant text-window
  16.  
  17.       = make(<text>, in: text-frame, relief: "sunken", font: normal-font,
  18.  
  19.              fill: "both", side: "right", expand: #t);
  20.  
  21.     define constant text-scroll
  22.  
  23.       = scroll(text-window, in: text-frame, fill: "y");
  24. could be used to produce the effect as the following Tcl/Tk code:
  25.  
  26.     frame .text-frame -height 500
  27.  
  28.     pack .text-frame -fill both -side bottom -expand 1
  29.  
  30.     text .text-frame.text -relief sunken -font normal-font
  31.  
  32.     pack .text-frame.text -in .text-frame -fill both -side right -expand 1
  33.  
  34.     scrollbar .text-frame.scroll -command {.text-frame.text yview }
  35.  
  36.     .text-frame.text configure -yscrollcommand {.text-frame.scroll set }
  37.  
  38.     pack .text-frame.scroll -in .text-frame -fill y
  39. while being considerably clearer to the average Dylan programmer.
  40.  
  41. Note: In order for this implementation to work you must have a copy of wish available on your system. This implementation was developed upon version 4.0 of Tcl/Tk but should work any version Tk implementation after 4.0. Since version 4 introduces incompatible changes, you should not (at present) expect all features to work with earlier versions.
  42.  
  43. 2. General Principles
  44.  
  45.  
  46. In order to use Dylan/Tk, you should import module Tk from library Tk. This defines the <window> class, a variety of subclasses representing most of the Tk widgets, and a variety of support routines. All of these will be explained in some detail below. However, the user will sometimes find that he can gain more information by going to the book Tcl and the Tk Toolkit by John Osterhout, which explains the widgets’ behavior in more depth than is practical for this document.
  47.  
  48. Any Dylan program which uses the Tk library will automatically create a top level window (which is accessible via the *root-window* variable) and a separate thread to process events upon that window. You build an interface by making widgets and "packing" them into windows -- either the root window, newly created top-level windows, or into subwindows of these windows.
  49.  
  50. An simple application might be the following:
  51.  
  52.     define method main (program-name :: <string>, #rest args);
  53.  
  54.     make(<message>, text: "Hello, world!", aspect: 500, side: "top");
  55.  
  56.     make(<button>, text: "Okay", relief: "raised",
  57.  
  58.          command: curry(destroy-window, *root-window*), expand: #t);
  59.  
  60.     map-window(*root-window*);
  61.  
  62.     end method main;
  63. This creates a text message and a pushbutton, packs them into the root window, and then exits, and makes the root window visible. It then exits the main thread, leaving just the event processing thread active. When the button is pressed, it will destroy the root window (and all its subwindows). Since there are no windows left, the event thread exits, and the program terminates. We could just as easily specified "command: exit", which would force the Dylan program to exit, killing off all threads, and thus destroying the windows. Go ahead and try it, if you like.
  64.  
  65. Widgets, like any other Dylan object, are typically created via make. There are three different varieties of keywords which can be specified:
  66.  
  67. Widget Specific Options:
  68. These include the aspect: and command: keywords in the above example. Their precise effects depend upon the definition of the widget.
  69. Standard Options:
  70. These include the relief: keyword in the above example. They are accepted by most (if not all) widgets, and have pretty much the same effect for all of them. (Some keywords, like text:, are not accepted by all widgets, but are common and predictable enough that users may be left to infer their effects.)
  71. Packing Options:
  72. These include the side: and expand: keywords in the above example. They are used to control the positioning and resizing of the new widgets within their "parent" windows. They are, for the most part, passed on directly to the pack function. In very rare cases, you will wish to create a window without (yet) packing it into another window. In this case, you can specify pack: #f to defer calling pack until you are ready to do so.
  73.  
  74. 3. Parameter and Return Values
  75.  
  76.  
  77. The values which are passed into make or into many other Tcl/Tk functions are passed into to Tcl/Tk as strings, and thus it is sometimes most convenient to write them as strings in Dylan. Most Dylan/Tk functions therefore accept strings as parameter values. However, you will usually find it easier to work with a richer set of types within Dylan’s type system. Parameters values can commonly include instances of the following native Dylan classes:
  78.  
  79. <boolean>
  80. <integer>
  81. <function>
  82. <string>
  83. <sequence>
  84. <class>
  85. and will occasionally include others on a case-by-case basis. In addition, the following new classes are also frequently accepted as parameter values:
  86.  
  87. <window>
  88. <tk-variable>
  89. <text-index>
  90. <text-mark>
  91. Those Dylan/Tk functions which return values typically cast the results back into meaningful Dylan types before returning them. However, there are some occasions where this proves impractical, and result values remain as <string>s which must be explicitly cast into appropriate types. For example, the configuration function returns the values of all the configuration options for a widget. Since it can’t guess what the types of these values ought to be, they simply remain as <string>s.
  92.  
  93. In some cases you must specify callback functions for Dylan/Tk widgets. These are typically specified via the command: keyword to make. On the few occasions where these functions take parameters, they will be passed in as <string>, and may include "\" quotation characters. You may need to call tk-unquote to strip out backslashes or to call tk-as to convert this to another type. For example: tk-as(<boolean>, "1") returns #t.
  94.  
  95. 4. The "Standard" Options
  96.  
  97.  
  98. The following options seem to apply universally to all widgets. They are mostly concerned with presentation details of the widget’s window, as opposed to the widget’s function.
  99.  
  100. background:
  101. This specifies the background color to be used within the widget. Typically it is a color name, like Black or LightBrown, or as hexadecimal integers, like #x3a7 or #x3000a0007000.
  102. borderwidth:
  103. This specifies the size of the border to be placed around the window. Typically this will be an integer which specifies the number of pixels, but you may also use string values like "1c", "1m", "1i", "1p", which specify centimeters, millimeters, inches, and points respectively. This keyword is typically combined with the relief: keyword.
  104. cursor:
  105. This specifies a bitmap which will be displayed when the user’s cursor is in this widget. The most useful forms will be name to specify a name from the standard cursor font, or @Sourcefile fgColor to load the cursor from a file.
  106. foreground:
  107. This specifies the background color to be used within the widget. Typically it is a color name, like Black or LightBrown, or as hexadecimal integers, like #x3a7 or #x3000a0007000.
  108. highlightbackground:
  109. This specifies the color of the highlight area (a thin border surronding the widget) when it is disabled. This is normally a color name, like Black or LightBrown, or as hexadecimal integers, like #x3a7 or #x3000a0007000.
  110. highlightforeground:
  111. This specifies the color of the highlight area (a thin border surronding the widget) when it is enabled. This is normally a color name, like Black or LightBrown, or as a hexadecimal integer, like #x3a7 or #x3000a0007000.
  112. highlightthickness:
  113. This specifies the thickness of the highlight area. Typically this will be an integer which specifies the number of pixels, but you may also use string values like "1c", "1m", "1i", "1p", which specify centimeters, millimeters, inches, and points respectively. A value of zero will remove the highlight ring.
  114. relief:
  115. This specifies what sort of 3D border should be displayed around the widget. This must be one of: "flat" (default), "groove", "raised", "ridge", or "sunken".
  116. Other options are by no means universal, but tend to mean the same thing whenever they occur:
  117.  
  118. bitmap:
  119. This specifies a bitmap which will be displayed in the given widget. The most useful forms will be name to specify a name from the standard cursor font, or @Sourcefile fgColor to load the cursor from a file.
  120. command:
  121. This specifies an action to be taken when a particular widget is invoked or when values associated with the widget change. Typically this will be a Dylan function, but it may also be a bit of Tcl code which can be executed directly by the interpreter. The number of parameters which might be passed to the function vary depending on the widget, but they will all be passed in as <string>s.
  122. font:
  123. This is a string which specifies the font to be used for any text which is displayed within the widget.
  124. justify:
  125. This is a string which specifies how the text within the widget is to be justified. Possible valuse are "left", "center", and "right".
  126. state:
  127. This specifies whether the given widget is in an active state. Typically, any widget which accepts a command: keyword will accept this keyword as well. Acceptable values are "normal", "disabled", and sometimes "active" (for buttons only).
  128. text:
  129. This is a string which will be displayed in the widget in an implementation dependent way. A few widgets also take a label: keyword which acts much the same way.
  130. textvariable:
  131. This specifies a "variable" containing a value which will be displayed in the widget. If the variables value changes, the widget is updated. If the widget allows editing, the variable will be updated after each change. Dylan/Tk programs will typically supply a <tk-variable> object for this keyword. (These will be explained in a later section.)
  132. underline:
  133. This specifies a charater in the text string of a widget to underline.
  134. variable:
  135. This functions much like the textvariable: keyword, but tends to be displayed somewhat differently.
  136.  
  137. 5. Windows
  138.  
  139.  
  140. The abstract type <window> represents any one of a wide variety of widgets, although it doesn’t include pseudo-widgets like menu entries, text tags, or canvas items (which will be discussed later). They are almost always created via make, which accepts all of the standard options described above, as well as the packer options name:, in:, after:, before:, side:, expand:, padx:, pady:, and pack:. (Packing will be described briefly in the next section.) All windows except <toplevel>s must specify their parents by some means -- either directly via in: or indirectly via after: or before:.
  141.  
  142. You also have the right to specify a debug name for the window via the name: option. If you refuse this right, one will be created for you automatically.
  143.  
  144. One window is automatically created as a result of importing the tk library. This is the top level window *root-window*.
  145.  
  146. There are a small set of methods which operate upon all windows:
  147.  
  148.  
  149.  
  150. configure (widget :: <window>, #all-keys) [Function]
  151.  
  152. Configure accepts pretty much the same options as initialize, and uses them to change the state of the object.
  153.  
  154.  
  155. configuration (widget :: <window>) => (result :: <sequence>) [Function]
  156.  
  157. Returns a complete list of options for the given widget. Each option consists of a sequence of the switch name, rdb name, rdb class, default, and value. The "value" will be a string, which may be converted to a more pleasing form via either tk-as or tk-unquote.
  158.  
  159.  
  160. map-window (window :: <window>) => () [Function]
  161.  
  162. Make sure that a window is displayed on the screen. *root-window* is unmapped initially, so nothing will appear until you call map-window(*root-window*).
  163.  
  164.  
  165. unmap-window (window :: <window>) => () [Function]
  166.  
  167. Remove a window from the display. This is handy to keep from showing intermediate states of newly defined windows.
  168.  
  169.  
  170. destroy-window (window :: <window>) => () [Function]
  171.  
  172. Completely obliterate a window, removing it from the screen and all knowledge of mankind.
  173.  
  174.  
  175. pack (window :: <window>, #all-keys) => (window :: <window>) [Function]
  176.  
  177. This is explained in the next section. You should never need to call pack unless you either specified "pack: #f" when making the window or you used the unpack function to remove it from the display.
  178.  
  179.  
  180. unpack (window :: <window>) => (window :: <window>) [Function]
  181.  
  182. This hides a window which has previously been packed into another window. The window still exists, and may be updated or repacked into its parent. You may not pack the window into a different parent -- this will result in errors.
  183.  
  184.  
  185. \= (window :: <window>, window :: <window>) => equal? :: <boolean> [Method]
  186. \= (window :: <window>, path-name :: <string>) => equal? :: <boolean> [Method]
  187. \= (path-name :: <string>, window :: <window>) => equal? :: <boolean> [Method]
  188.  
  189. The three \= methods are useful for comparing two windows to see if they are, in fact, the same widget. Most function which should return windows will return them as <window> objects, but if you are dealing with lower level Tk, it may be useful to compare a Tk window path-name to a Dylan <window> object.
  190.  
  191. 6. Packing
  192.  
  193.  
  194. Unless they are some sort of top level window (i.e. *root-window* or instances of <toplevel> or <menu>), windows must be "packed" into some containing window before they will appear on the screen. Normally, all Dylan/Tk windows are automatically packed when they are created, using the procedure and options described below. The exception to this is if the pack: option is given a value of #f or is the window was unpacked; in these cases, the pack function will need to be called explicity to display the window. The Dylan/Tk pack function closely follows the Tcl/Tk function described in "Tcl and the Tk Toolkit", and you should look there for more complete information. However, we will provide a brief overview here.
  195.  
  196. Each "slave" (i.e. non-top-level) window must be packed into some other window. You specify this window either directly, via "in: parent" or indirectly via "before: sibling" or "after: sibling". (The latter options specify that the window should have the same parent as the specified "sibling", and that they should be placed just before or after the sibling in the parent’s "packing order".) If no parent is specified explicitly, Dylan/Tk implicitly assumes "in: *root-window*".
  197.  
  198. The side: option specifies where the widget should be placed relative to the ones which follow it in the "packing order". If you specify "side: "left"", then all widgets which are packed into the parent after this one (either because they were created later or because of a before: or after: option) will be placed somewhere to the right of this widget. Note that it will not necessarily be placed on the parent’s absolute left side, because all windows which precede this one in the packing order have "first dibs" on prime real estate. Possible values for this option are "left", "right", "top", and "bottom" -- the default is "left".
  199.  
  200. If you were to execute:
  201.  
  202. let w1 = make(<listbox>, in: *root-window*, side: "left");
  203.  
  204. let w2 = make(<text>, before: w1, side: "top");
  205.  
  206. let w3 = make(<scrollbar>, after: w1);
  207. you would end up with something like:
  208.  
  209. Window W2 comes first in the packing order (because of the before: option) and preempts the top of the root window. W1 comes second, and grabs the left side of the remaining space, leaving a small chunk on the right for W3 (and any windows which might be packed after W3).
  210.  
  211. The other options available are anchor:, expand:, fill:, padx:, and pady:, which are explained in the book. Expand: typically takes a boolean value, while fill: takes one of "x", "y", "both", or "none".
  212.  
  213. The unpack function will remove a window from the control of the "packer" and, as a side effect, remove it from the display. The window will still exist and can be updated or repacked via the pack function. You will, however, get errors if you try to specify a different parent when you repack it.
  214.  
  215. 7. Event bindings
  216.  
  217.  
  218. Each Dylan/Tk widget has a default set of "bindings" which determine how they react to X events like button or key presses. These may be changed or extended via the "bind" function. Windows, "tag" strings, and subclasses of <window> can have bindings, and more than one binding may apply to an event. All of the applicable bindings will get called, unless explicitly avoided, and the call order can be changed.
  219.  
  220.  
  221.  
  222. bind (window-tag-or-class, event :: <string>, command) => (window)
  223.  
  224. This function specifies an action to be performed when an X event matching "event" occurs. Typically this is a nil-adic Dylan function, but it may also be an arbitrary line of Tcl code. A typical binding might be the following:
  225.    bind(l1, "<Double-Button-1>",  method ()
  226.  
  227.           do(print-config, current-selection(l1))
  228.  
  229.           end method);
  230. This would cause Dylan/Tk to call print-config on each of the current selections in the <listbox> "l1" whenever the leftmost mouse button is double-clicked.
  231. The first argument to this function may be a <window> object, in which case it acts on only that window, a "tag" string, which acts on all windows with that tag, or a subclass of <window>, which acts on all objects of that type.
  232. There are five other utility functions which allow you to determine and manipulate the bindings for windows:
  233.  
  234.  
  235.  
  236. get-binding (window-tag-or-class, event) => (result :: <string>) [Function]
  237.  
  238. Returns the window, tag, or class’s binding for a single event. Unless you have specified an explicit binding, this will be an empty string.
  239.  
  240.  
  241. get-bindings (window-tag-or-class) => (result :: <sequence>) [Function]
  242.  
  243. Returns a complete list of explicit bindings for a window, tag string, or class. Each element of the sequence will be a <pair> of event-name and binding.
  244.  
  245.  
  246. binding-call-order (window :: <window>) => (result :: <sequence>) [Function]
  247.  
  248. Returns a list of bindings that apply to a window, in the order that they are called. Each element is a Tk text string which could represent a window, a tag, or a class.
  249.  
  250.  
  251. binding-call-order-setter (bindings :: <sequence>, window :: <window>) => (bindings :: <sequence>) [Function]
  252.  
  253. Sets the calling order for bindings. The elements of the sequence may be <window> objects, tag strings, or subclasses of <window>
  254.  
  255.  
  256. tk-break () [Function]
  257.  
  258. If you don’t want to call all bindings which apply to an event, use the tk-break command to stop the execution of bindings. This command must be executed on the top level of the binding, and not in any functions that the command calls.
  259.  
  260. 8. Active Variables
  261.  
  262.  
  263. Some widgets have the ability to take an obsessive interest in the value of some "variable". They may update their contents or appearance when the variable’s value changes, or they might update the variable in response to some user action. Because this level of monitoring is not supported by ordinary Dylan variables, Dylan/Tk users must instead use instances of <active-variable>.
  264.  
  265. Make on <active-variable> requires a value: keyword and accepts an optional class: keyword. If specified, the class defines the logical type of the variable’s value. The value slot will always contain a value of that type, although value-setter will accept arbitrary types (especially <string>) and attempt to convert them to the given type.
  266.  
  267. You may also specify a Dylan function to be executed when an active variable’s value changes (i.e. becomes \~= to the old value). This method is specified via the command: keyword to make. It will be invoked with both the new and the old value at some point after the value is changed. Note that the value is updated immediately (i.e. asynchronously), while the calls to the given command are executed sequentially along with event callbacks.
  268.  
  269. Active variables will typically be passed as values of variable: or text-variable: keywords.
  270.  
  271. 9. The widget types
  272.  
  273.  
  274. Dylan/Tk provides types corresponding to all of the standard Tcl/Tk widgets:
  275.  
  276. <button>:
  277. Options:
  278. #"activebackground"
  279. #"activeforeground"
  280. #"bitmap"
  281. #"command"
  282. #"disabledforeground"
  283. #"font"
  284. #"height"
  285. #"justify"
  286. #"state"
  287. #"text"
  288. #"textvariable"
  289. #"underline"
  290. #"width"
  291. #"wraplength"
  292. Functions:
  293. activate (button) => button
  294. deactivate (button) => button
  295. flash (button) => button
  296. invoke (button) => button
  297. <checkbutton>:
  298. Options:
  299. #"activebackground"
  300. #"activeforeground"
  301. #"bitmap"
  302. #"command"
  303. #"disabledforeground"
  304. #"font"
  305. #"height"
  306. #"offvalue"
  307. #"onvalue"
  308. #"selector"
  309. #"state"
  310. #"text"
  311. #"textvariable"
  312. #"variable"
  313. #"width".
  314. Functions:
  315. select-value (button) => button
  316. deselect-value (button) => button
  317. toggle-value (button) => button
  318. <menubutton>
  319. Options:
  320. #"activebackground"
  321. #"activeforeground"
  322. #"bitmap"
  323. #"disabledforeground"
  324. #"font"
  325. #"height"
  326. #"indicatoron"
  327. #"justify"
  328. #"menu"
  329. #"state"
  330. #"text"
  331. #"textvariable"
  332. #"underline"
  333. #"width"
  334. #"wraplength"
  335. Functions:
  336. activate (button) => button
  337. deactivate (button) => button
  338. <radiobutton>:
  339. Options:
  340. #"activebackground"
  341. #"activeforeground"
  342. #"bitmap"
  343. #"command"
  344. #"disabledforeground"
  345. #"font"
  346. #"height"
  347. #"indicatoron"
  348. #"justify"
  349. #"state"
  350. #"selectcolor"
  351. #"text"
  352. #"textvariable"
  353. #"underline"
  354. #"value"
  355. #"variable"
  356. #"width"
  357. #"wraplength".
  358. Functions:
  359. select-value (button) => button
  360. deselect-value (button) => button
  361. <canvas>:
  362. Options:
  363. #"closeenough"
  364. #"confine"
  365. #"height"
  366. #"insertbackground"
  367. #"insertborderwidth"
  368. #"insertofftime"
  369. #"insertontime"
  370. #"insertwidth"
  371. #"scrollregion"
  372. #"selectbackground"
  373. #"selectborderwidth"
  374. #"selectforeground"
  375. #"width"
  376. #"xscrollcommand"
  377. #"xscrollincrement"
  378. #"yscrollcommand"
  379. #"yscrollincrement"
  380. Functions:
  381. xview (canvas :: <canvas>, index) => canvas
  382. yview (canvas :: <canvas>, index) => canvas
  383. find-items (canvas :: <canvas>, spec, spec-args) => found-items
  384. focus (canvas :: <canvas>) => result :: <canvas-item>
  385. focus-setter (value :: <canvas-item>, canvas :: <canvas>) => ()
  386. scan-mark (window :: <canvas>, #rest coords) => window
  387. scan-dragto (window :: <canvas>, #rest coords) => window
  388. select-item (window :: <canvas>, index) => window
  389. canvas-x (canvas :: <canvas>, screen-x, #key grid-spacing = 1) => x
  390. canvas-y (canvas :: <canvas>, screen-y, #key grid-spacing = 1) => y
  391. create-arc (canvas, x1, y1, x2, y2, #rest opts) => item
  392. Options include: #"extent", #"fill", #"outline", #"outlinestipple:", #"start", #"stipple", #"style", #"tags",, #"width"
  393. create-bitmap (canvas, x1, y1, #rest opts) => item
  394. Options include: #"anchor", #"bitmap", #"background", #"foreground", #"tags"
  395. create-line (canvas, points :: <sequence>, #rest opts) => item
  396. Options include: #"arrow", #"arrowshape", #"capstyle", #"fill", #"joinstyle", #"smooth", #"splinesteps", #"stipple", #"tags", #"width"
  397. create-oval (canvas, x1, y1, x2, y2, #rest opts) => item
  398. Options include: #"fill", #"outline", #"stipple", #"tags", #"width"
  399. create-polygon (canvas, pnts :: <sequence>, #rest opts) => item
  400. Options include: #"fill", #"outline", #"smooth", #"splinesteps", #"stipple", #"tags", #"width"
  401. create-rectangle (canvas, x1, y1, x2, y2, #rest opts) => item
  402. Options include: #"fill", #"outline", #"stipple", #"tags", #"width"
  403. create-text (canvas, x1, y, #rest opts) => item
  404. Options include: #"anchor", #"fill", #"font", #"justify", #"stipple", #"tags", #"text", #"width"
  405. create-window (canvas, x1, y1, #rest opts) => item
  406. Options include: #"anchor", #"height", #"tags", #"width", #"window"
  407. postscript (canvas, #rest opts) => result :: <string>
  408. Options include: #"colormap", #"colormode", #"fontmap", #"height", #"pageanchor", #"pageheight", #"pagewidth", #"pagex", #"pagey", #"rotate", #"width", #"x", #"y".
  409. <entry>:
  410. Options:
  411. #"exportselection"
  412. #"font"
  413. #"insertbackground"
  414. #"insertborderwidth"
  415. #"insertofftime"
  416. #"insertontime"
  417. #"insertwidth"
  418. #"justify"
  419. #"selectbackground"
  420. #"selectborderwidth"
  421. #"selectforeground"
  422. #"show"
  423. #"state"
  424. #"textvariable"
  425. #"width"
  426. #"xscrollcommand"
  427. Functions:
  428. icursor (entry, index) => entry
  429. xview (entry, index) => entry
  430. delete (entry, index, #key end: last) => entry
  431. insert (entry, index, #rest elements) => entry
  432. get-all (entry) => result :: <string>
  433. get-elements (entry, index, #key end) => result :: <string>
  434. scan-mark (entry, #rest coords) => entry
  435. scan-dragto (entry, #rest coords) => entry
  436. select-adjust (entry, index) => entry
  437. select-clear (entry) => entry
  438. select-from (entry, index) => entry
  439. select-to (entry, index) => entry
  440. <frame>:
  441. Options:
  442. #"colormap"
  443. #"height"
  444. #"width"
  445. #"visual"
  446. Supports no operations.
  447. <label>:
  448. Options:
  449. #"bitmap"
  450. #"font"
  451. #"height"
  452. #"justify"
  453. #"text"
  454. #"textvariable"
  455. #"underline"
  456. #"width"
  457. #"wraplength"
  458. Supports no operations.
  459. <listbox>:
  460. Options:
  461. #"exportselection"
  462. #"font"
  463. #"height"
  464. #"selectbackground"
  465. #"selectborderwidth"
  466. #"selectforeground"
  467. #"selectmode"
  468. #"setgrid"
  469. #"width"
  470. #"xscrollcommand"
  471. #"yscrollcommand
  472. Functions:
  473. clear-selection (listbox, first :: <integer>,#rest last) => ()
  474. current-selection(listbox, #rest rest) => indices :: <sequence>
  475. nearest(listbox, y-coord) => index :: <integer>
  476. size(listbox) => result :: <integer>
  477. xview(listbox, index) => listbox
  478. yview(listbox, index) => listbox
  479. delete (listbox, index, #key end) => listbox
  480. insert (listbox, index, #rest elements) => listbox
  481. get-all (listbox) => result :: <string>
  482. get-elements (listbox, index, #key end) => result :: <string>
  483. scan-mark (listbox, #rest coords) => listbox
  484. scan-dragto (listbox, #rest coords) => listbox
  485. see (listbox, index) => ()
  486. select-adjust (listbox, index) => listbox
  487. select-clear (listbox) => listbox
  488. select-from (listbox, index) => listbox
  489. select-to (listbox, index) => listbox
  490. selection-anchor-setter (listbox, index) => listbox
  491. selection-includes? (listbox, index) => in-selection? :: <boolean>
  492. set-selection (listbox, first :: <integer>, #rest last) => ()
  493. <menu>:
  494. Options:
  495. #"activebackground"
  496. #"activeborderwidth"
  497. #"activeforeground"
  498. #"disabledforeground"
  499. #"font"
  500. #"postcommand"
  501. #"selectcolor"
  502. #"tearoff"
  503. Functions:
  504. activate-entry (menu, index) => menu
  505. delete (menu, index, #key end) => menu
  506. configure-entry (menu, index, #rest options) => menu
  507. entry-configuration (menu, index) => result :: <sequence>
  508. invoke-entry (menu, index) => result
  509. post (menu, x, y) => ()
  510. post-cascade (menu, index) => ()
  511. unpost (menu) => ()
  512. yposition-entry (menu, index) => result :: <integer>
  513. add-command (menu, #key state, command, label) => ()
  514. add-checkbutton (menu, #key variable, label) => ()
  515. add-radiobutton (menu, #key variable, value, label) => ()
  516. add-cascade (menu, #key menu, label) => ()
  517. add-separator (menu) => ()
  518. Note that if you wish to assocaiate a menu with a menubutton, you must create it in: that button.
  519. <message>:
  520. Options:
  521. #"aspect"
  522. #"font"
  523. #"justify"
  524. #"text"
  525. #"textvariable"
  526. #"width"
  527. Supports no operations.
  528. <scale>:
  529. Options:
  530. #"activebackground"
  531. #"bigincrement"
  532. #"command"
  533. #"digits"
  534. #"font"
  535. #"from"
  536. #"label"
  537. #"length"
  538. #"orient"
  539. #"repeatdelay"
  540. #"repeatinterval"
  541. #"resolution"
  542. #"showvalue"
  543. #"sliderforeground"
  544. #"sliderlength"
  545. #"state"
  546. #"tickinterval"
  547. #"to"
  548. #"troughcolor"
  549. #"variable"
  550. #"width"
  551. Functions:
  552. get-value (scale) => result :: <integer>
  553. set-value (scale, value) => scale;
  554. <scrollbar>:
  555. Options:
  556. #"activebackground"
  557. #"activerelief"
  558. #"command"
  559. #"elementborderwidth"
  560. #"jump"
  561. #"orient"
  562. #"repeatdelay"
  563. #"repeatinterval"
  564. #"troughcolor"
  565. #"width"
  566. Functions:
  567. scroll (widget, #key, #all-keys) => scrollbar
  568. get-units (scrollbar) => (#rest units :: <integer>)
  569. set-units (scrollbar, #rest Units) => scrollbar
  570. The scroll function exists to reduce the inefficiency inherent in "standard" method of connecting widgets to scrollbars. This function creates a new scrollbar with the given orientation (i.e. "vertical" or "horizontal") and connects it via lower level mechanisms to the given widget. All of the applicable creation and packing options for scrollbars are accepted.
  571. <text>:
  572. Options:
  573. #"exportselection"
  574. #"font"
  575. #"height"
  576. #"insertbackground"
  577. #"insertborderwidth"
  578. #"insertofftime"
  579. #"insertontime"
  580. #"insertwidth"
  581. #"selectbackground"
  582. #"selectborderwidth"
  583. #"selectforeground"
  584. #"setgrid"
  585. #"spacing1"
  586. #"spacing2"
  587. #"spacing3"
  588. #"state"
  589. #"tabs"
  590. #"textvariable"
  591. #"width"
  592. #"wrap"
  593. #"yscrollcommand".
  594. Functions:
  595. yview (text, index) => text
  596. delete (text, index, #key end) => text
  597. insert (text, index, #rest elements) => text
  598. get-all (text) => result :: <string>
  599. get-elements (text, index, #key end) => result :: <string>
  600. scan-mark (text, #rest coords) => text
  601. scan-dragto (text, #rest coords) => text
  602. select-adjust (text, index) => text
  603. select-clear (text) => text
  604. select-from (text, index) => text
  605. select-to (text, index) => text
  606. tags (text) => result :: <sequence>
  607. <toplevel>:
  608. Options:
  609. #"colormap"
  610. #"height"
  611. #"screen"
  612. #"visual"
  613. #"width"
  614. Functions:
  615. tk-dialog (toplevel, title, text, bitmap, default, #rest buttons) => button :: <integer>
  616. Tk-dialog automatically creates a dialog box with the given title, text, bitmap and buttons. The default argument is an integer that corresponds to the button that should be made the default (beginning at zero for the left-most button)
  617. These operations will hopefully be described at greater length in future editions of this document, but for now you are encouraged to check the Tcl/Tk manual for further information.
  618.  
  619. 10. Text indices
  620.  
  621.  
  622. The types <text-index>, <text-mark>, and <text-tag> all represent references to the contents of a <text> window. Functions are provided to let you create and manipulate instances of these types.
  623.  
  624. <Text-index>s represent an "absolute" index within a <text> object. They have two slots -- line and character. Make on <text-index> requires a line: keyword and accepts an optional character: keyword (which defaults to 0). Lines numbers start at 1, while characters start at 0, so you could specify the first character of a <text> by calling make(<text-index>, line: 1, character: 0)
  625.  
  626. The following functions create and manipulate <text-index>s:
  627.  
  628. text-at (line, character) => result :: <text-index>
  629. line-end (line) => result :: <string>
  630. as (cls == <text-index>, value :: <string>) => string
  631. as (cls == <string>, value :: <text-index>) => text-index
  632. The text-at function provides a convenient shorthand for making <text-index>s. You might, for example replace the above make call with text-at(1, 0);
  633.  
  634. Line-end creates a reference to the last character of the named line.
  635.  
  636. 11. Text marks
  637.  
  638.  
  639. <Text-mark> objects represent more abstract character positions. It will continue to refer to the same character even if other text is added or deleted. They have two slots -- value and name, and are associated with a particular <text> widget via the required make keyword in:.
  640.  
  641. If you make a <text-mark> with the name of a "standard" Tcl/Tk mark, such as "end" or "insert", then the new object will pick up the values already associated with the Tcl/Tk mark.
  642.  
  643. The following functions create or manipulate <text-mark>s:
  644.  
  645. as (cls == <string>, object :: <text-mark>) => string
  646. as (cls == <text-index>, mark :: <text-mark>) => text-index
  647. marks (text :: <text>) => result :: <sequence>
  648. The marks function returns a sequence containing all of the marks within a given <text>. This will include both the "standard" Tcl/Tk marks and any that you have created. These will not necessarily be == to the original objects.
  649.  
  650. 12. Text tags
  651.  
  652.  
  653. <Text-tag>s represent attributes which may be associated with zero or more sequences of characters in a specific <text>. You may specify different display properties or event bindings for the characters that have been associated with a particular <text-tag>.
  654.  
  655. <Text-tag>s are created within a particular <text> via make, which requires an in: keyword. Optional keywords include name:, bgstipple:, fgstipple:, font:, justify:, lmargin1:, lmargin2:, offset:, overstrike:, relief:, rmargin:, spacing1:, spacing2:, spacing3:, tabs:, wrap:, and underline:. Although tags are not widgets, they support the configure, configuration, and bind functions. You may add ranges of characters to <text-tag>s via add-tag. A complete list of functions upon <text-tag>s follows:
  656.  
  657. configure (tag, #rest options) => tag
  658. configuration (tag, index) => result :: <sequence>
  659. bind (tag, event :: <string>, command) => tag
  660. as (cls == <string>, object :: <text-tag>) => string
  661. add-tag (tag, #key start, end: last) => tag
  662. remove-tag (tag, #key start, end: last) => tag
  663. tags (text :: <text>) => result :: <sequence>
  664. delete-tag (tag) => ()
  665. raise-tag (tag, #key past :: <text-tag>) => ()
  666. lower-tag (tag, #key past :: <text-tag>) => ()
  667. next-range (tag, #key start, end) => result :: false-or(<pair>)
  668.  
  669. 13. Canvas items and tags
  670.  
  671.  
  672. <canvas-item>s represent different graphical entity within a <canvas>. Each create-shape function returns a <canvas-item> corresponding to the newly created shape. These may be used to delete, resize, move, or respecify the shape. Although canvas items are not widgets, they support the configure, configuration and bind functions. The configuration options which are accepted for a given item depend upon its type. You should consult the list of create-... functions for a list of options.
  673.  
  674. <canvas-tag>s are a convienient way of grouping various canvas items. If more than one item has a given tag, then any operation performed on the tag will be applied to all items with that tag. Tags may be created using the make method with required keywords #"in", the canvas that contains that tag, and #"name", a string identifier. Tags may be assigned to <canvas-item>s when they are created, by giving a single <canvas-tag> or a sequence of <canvas-tag>s in the #"tags" keyword.
  675.  
  676. The following functions operate upon canvas items and canvas tags:
  677.  
  678. configure (item, #rest options) => item
  679. configuration (item, index) => result :: <sequence>
  680. bind (item, event :: <string>, command) => item
  681. delete-item (item) => ()
  682. raise-item (item, #key past :: <canvas-item>) => ()
  683. lower-item (item, #key past :: <canvas-item>) => ()
  684. move-item (item, x :: <object>, y :: <object>) => ()
  685. scale-item (item, x-origin, y-origin, x-scale, y-scale) => ()
  686. item-coords (item) => result :: <sequence>
  687. item-coords-setter (value :: <sequence>, item) => ()
  688. item-type (item) => result :: <string>
  689. add-canvas-tag (item, spec, spec-args) => ()
  690. get-canvas-tags (item) => tags :: <sequence>
  691. delete-canvas-tag (item, tag-to-delete) => ()
  692.  
  693. 14. Window Information commands
  694.  
  695.  
  696. There are a variety of window information commands that return various data about the state of the widgets, most of these corresponding to Tcl/TK "winfo" commands. There are also two new objects that are returned by some of these functions, <point> and <rgb-color>. <point> has slots x and y, both integers, and <rgb-color> has slots red, green, and blue, all integers. Functions that return these classes come in two forms for flexibility in programming. One form has the class name appended to the function name , which returns the named object (e.g. mouse-point returns a <point>). The second form lists the components as part of the function name, and returns each component individually, as multiple values (e.g. mouse-x-y returns the values x and y). A complete list of the window information functions follows.
  697.  
  698. colormap-cells (window) => c-m-cells :: <integer>
  699. colormap-full? (window) => c-m-full? :: <boolean>
  700. children (window) => child-seq :: <sequence>
  701. window-containing-x-y (x, y, #key on-display-of = #f) => window
  702. window-containing-point (point :: <point>, #key on-display-of = #f) => window
  703. depth (window)=> colors :: <integer>
  704. exists? (window) => exist? :: <boolean>
  705. distance-to-float-pixels (dist, #rest units) => pixels
  706. geometry (window) => geom-string
  707. height (window) => h
  708. X-id (window) => id :: <integer>
  709. mapped? (window) => map? :: <boolean>
  710. geometry-manager (window) => manager :: <string>
  711. window-with-X-id (id :: <integer>, #key on-display-of = #f) => window
  712. distance-to-pixels (dist, #rest units) => pixels :: <integer>
  713. mouse-x-y (window) => (x, y)
  714. mouse-point (window) => point :: <point>
  715. requested-height (window) => h
  716. requested-width (window) => w
  717. width (window) => w
  718. color-to-r-g-b (window, color :: <string>) => (red, green, blue)
  719. color-to-rgb-color (window, color :: <string>) => rgb-color :: <rgb-color>
  720. abs-position-x-y (window) => (x, y)
  721. abs-position-point (window) => point :: <point>
  722. screen-name (window) => name
  723. screen-colormap-cells (window) => num-cells :: <integer>
  724. screen-depth (window) => bit-depth :: <integer>
  725. screen-height (window) => h
  726. screen-width (window) => w
  727. server (window) => srv :: <integer>
  728. toplevel (window) => top :: <window>
  729. viewable? (window) => view?
  730. visual-class (window) => vis-class :: <string>
  731. available-visuals (window) => avail-vis :: <sequence>
  732. virtual-root-height (window) => h
  733. virtual-root-width (window) => w
  734. virtual-root-position-x-y (window) => (x, y)
  735. virtual-root-position-point (window) => point :: <point>
  736. x-y-in-parent (window) => (x, y)
  737. point-in-parent (window) => point :: <point>
  738. Notes on the functions:
  739.  
  740. Distance-to-pixels and distance-to-float-pixels take a units paramater that could be one of #"centimeters", #"inches", #"millimeters", or #"points".
  741.  
  742. X-y-in-parent and point-in-parent return the position of the upper-left corner of the window in it’s parent window.
  743.  
  744. Abs-position-x-y and abs-position-point return the position of the upper-left corner of the window relative to the root window.
  745.  
  746. Mouse-x-y and mouse-point return the position of the pointer relative to the argument window.
  747.  
  748. Anything that returns a <window> or a sequence of <window>s will return a new object which refers to the same Tk widget. A \= method is provided for comparing these to the previously existing ones.
  749.  
  750. 15. Requested Enhancements
  751.  
  752.  
  753. Allow event bindings to access the window, mouse coords, character, and other "%" substitutions.
  754.  
  755. Add better support for scale and scrollbar widgets.
  756.  
  757. Provide a "focus" command.
  758.  
  759. Revise the interface to provide a more uniform object-oriented integration of <window>s, <text-tag>s, and <canvas-item>s. (This would probably be an incompatible change.)
  760.  
  761. 16. The Extension Protocol
  762.  
  763.  
  764. Because early versions of Dylan/Tk don’t support the entire functionality of Tcl/Tk, users may wish to interface directly with the underlying Tcl/Tk interpreter. This capability is provided by the Tk-extension module. (Note: if any user decides to use these capabilities to provide a firm interface to a Tcl/Tk subsystem (e.g. the "wm" command), we would willingly incorporate such code into future versions of this library.)
  765.  
  766. The following functions are exported:
  767.  
  768.  
  769.  
  770. tk-as (cls :: <class>, value) => result :: <object> [Generic Function]
  771.  
  772. Performs conversions comparable to as, but adds some which do not generalize outside Tk -- for example, tk-as(<boolean>, "1") == #t.
  773. You may wish to add methods to this function for any new Dylan types you add.
  774.  
  775.  
  776. put-tk-line (#rest pieces) => () [Function]
  777.  
  778. Converts all of the input arguments into strings (using tk-as), concatentates them into a line of tk input, and sends then to the running tk process. This routine expects no results and therefore does not wait around for them.
  779. You should be careful to include spaces between distinct tokens in the input, since put-tk-line will cheerfully combine several strings into a single Tk token.
  780.  
  781.  
  782. call-tk-function (#rest pieces) => result :: <string> [Function]
  783.  
  784. Concatenates the input into a tk command, executes it, and returns the result as a string. Pauses execution of the current thread until the tk function returns. You may need to call tk-as, tk-unquote, or parse-tk-list on the result depending upon the expected result type.
  785.  
  786.  
  787. join-tk-args (#rest object) => result :: <string> [Function]
  788.  
  789. Creates a string containing the tk representation (via tk-as) of each argument, separated by spaces.
  790.  
  791.  
  792. make-option (option, value) => option :: <string> [Function]
  793.  
  794. Creates a tk "option" switch out of option name and an arbitrary value. The value may be an <integer>, <string>, <symbol>, or <true>. If the option is #f, then an empty string (i.e. no option) will be returned.
  795.  
  796.  
  797. parse-tk-list (string, #key depth, unquote, start, end) => sequence [Function]
  798.  
  799. Takes a string returned by a tk function and converts it into a sequence of values. Values will either be ‘words’ or subsequences, depending upon whether the string contains list grouping (i.e. ‘{and}) characters. If depth is not #f, all groupings below the given depth will be returned as simple strings. If unquote is true, then result strings will be filtered through tk-unquote.
  800.  
  801.  
  802. tk-quote (object :: <object>) => result :: <string> [Function]
  803.  
  804. Performs whatever quotation is necessary to get the data to WISH intact. For most objects, this is the same as tk-as(<string>, ...), but it does extra quotation on strings to make sure brackets and such like come out OK.
  805.  
  806.  
  807. tk-unquote (string :: <string>) => result :: <string> [Function]
  808.  
  809. Strips away all quotation from a string. This will undo the various escapes required to imbed brackets and such like inside a tk list. This should be called for any user level string, just as tk-as might be called for any other data type.
  810.  
  811.  
  812. anonymous-name (#key prefix = "w") => result :: <string> [Function]
  813.  
  814. Generates a unique new (but unexciting) name for a window.
Add Comment
Please, Sign In to add comment