scratch

gold Replay old scratch page on TCL Wiki. checking end of line issues here.

figure. SLIDE DATA FORMAT: THREE LINE-TYPE MARKERS


+----------------------------------------------------------------------------------+
| SLIDE DATA FORMAT: THREE LINE-TYPE MARKERS                                      |
|    Each slide is a two-element list { title { body } }                          |
|                                                                                  |
|    Body line markers (first character):                                         |
|    +--------+--------+-------------------+--------------------------------+     |
|    | marker | font   | visual treatment  | example                        |     |
|    +--------+--------+-------------------+--------------------------------+     |
|    |   +    | h2     | bullet (filled    | + Scripting with Tcl           |     |
|    |        | Times24| oval) drawn left  |   --> black oval + large text  |     |
|    |   >    | pre    | monospace code    | > while {[gets stdin line]>=0} |     |
|    |        |Courier | block             |   --> Courier 18               |     |
|    |   .    | body   | plain body text   | . Open Source: free software   |     |
|    |        | Times18| no bullet         |   --> Times 18, no decoration  |     |
|    | other  | body   | plain body text   | (fallback to body font)        |     |
|    +--------+--------+-------------------+--------------------------------+     |
|                                                                                  |
|    Text displayed: string range $line 2 end                                     |
|    (skips marker character and the space after it)                              |
|                                                                                  |
|    Blank lines in body: string trim --> empty string --> skipped in dump        |
|    In page proc: blank lines still consume a y-increment of 40 pixels          |
+----------------------------------------------------------------------------------+

figure. CANVAS SLIDE LAYOUT: COORDINATES AND ELEMENTS


+----------------------------------------------------------------------------------+
| CANVAS SLIDE LAYOUT: COORDINATES AND RENDERED ELEMENTS                         |
|    Canvas: 800 x 600 pixels, white background                                  |
|                                                                                  |
|    y=50   Title text (Times 36, blue, anchor west, x=50)                       |
|           +-------------------------------------------+  <- title              |
|    y=80   Red horizontal rule (line x=50 to 32000, width=3, fill red)          |
|           ============================================  <- red line             |
|    y=90   Body line 1                                                           |
|            o  Bullet text (h2, Times 24)               <- + marker             |
|    y=130  Body line 2                                                           |
|            o  Bullet text                              <- + marker              |
|    y=170  Body line 3                                                           |
|               Plain body text (Times 18)               <- . marker             |
|    y=210  Body line 4                                                           |
|               code line (Courier 18)                   <- > marker             |
|    ...                                                                          |
|                                                                                  |
|    Y increment: +40 pixels per body line                                        |
|    X position: 50 pixels from left for all elements                             |
|    Bullet oval: x-20 to x-10 at y-5 to y+5  (10px oval, centered on y)        |
|                 = pixels 30 to 40 horizontally                                  |
|    Title line: extends to x=32000 (effectively infinite width)                  |
+----------------------------------------------------------------------------------+

figure. KEYBOARD AND MOUSE BINDINGS


+----------------------------------------------------------------------------------+
| KEYBOARD AND MOUSE BINDINGS  (set in present::go proc)                         |
|                                                                                  |
| +---------------+---------------------------+--------------------------------+  |
| | event         | binding                   | action                         |  |
| +---------------+---------------------------+--------------------------------+  |
| | <1>           | left mouse click          | incr npage +1, redraw page     |  |
| | <3>           | right mouse click         | incr npage -1, redraw page     |  |
| |        | spacebar                  | incr npage +1, redraw page     |  |
| | p             | key p                     | save PostScript file           |  |
| |               |                           | p$npage.ps, -rotate 1          |  |
| | d             | key d                     | dump all slides to .txt file   |  |
| |       | Escape key                | exit (bound via: bind all)     |  |
| +---------------+---------------------------+--------------------------------+  |
|                                                                                  |
|    Boundary clamping (in page proc):                                            |
|      if npage < 0:             set npage = 0         (clamp at first slide)    |
|      if npage >= maxpages:     set npage = maxpages-1 (clamp at last slide)    |
|      expr {npage < 0 ? 0 : npage >= max ? max-1 : npage}                       |
|                                                                                  |
|    Window title update per slide:                                               |
|      wm title . "$::script $npage"                                             |
|      Shows script name + current slide number in title bar                     |
+----------------------------------------------------------------------------------+

figure. PRESENT NAMESPACE VARIABLES


+----------------------------------------------------------------------------------+
| PRESENT NAMESPACE: VARIABLES AND FONTS                                          |
|    All state kept in ::present namespace                                        |
|                                                                                  |
|    +---------------------+------------------+--------------------------------+  |
|    | variable            | initial value    | purpose                        |  |
|    +---------------------+------------------+--------------------------------+  |
|    | present::version    | 0.2              | version string                 |  |
|    | present::pages      | {}               | list of all slides             |  |
|    | present::npage      | 0                | current slide index (0-based)  |  |
|    | present::fonts(h1)  | {Times   36}     | slide title font               |  |
|    | present::fonts(h2)  | {Times   24}     | bullet / heading font (+)      |  |
|    | present::fonts(body)| {Times   18}     | plain body text font (.)       |  |
|    | present::fonts(pre) | {Courier 18}     | code / preformatted font (>)   |  |
|    +---------------------+------------------+--------------------------------+  |
|                                                                                  |
|    fonts array set in present::go on first call                                 |
|    Accessible from any proc in namespace via: variable fonts                    |
|    Font format: {family size}  (no weight specified = normal weight)            |
|    Tk default weight for text canvas items = normal                             |
+----------------------------------------------------------------------------------+

figure. PROC CALL MAP


+----------------------------------------------------------------------------------+
| PROC CALL MAP  (present:: namespace)                                            |
|                                                                                  |
|    main block (if script is run directly):                                      |
|      pack [canvas .c -bg white -width 800 -height 600]                         |
|      set ::script [wm title .]                                                  |
|      present::go .c $pages                                                     |
|           |                                                                      |
|           v                                                                      |
|    present::go {w Pages}                                                        |
|      sets pages, npage=0, fonts array                                           |
|      sets all key/mouse bindings                                                |
|      calls present::page $w  (first slide)                                     |
|           |                                                                      |
|      +----+---------+----------+                                                |
|      |              |          |                                                |
|      v              v          v                                                |
|  present::page  present::dump  (PostScript via canvas postscript command)      |
|      |                                                                          |
|      v                                                                          |
|  present::bullet {w x y}                                                       |
|    (called once per + line)                                                     |
|    $w create oval ...                                                           |
|                                                                                  |
|    Event-driven calls (user action --> binding):                                |
|      <1> /   --> incr npage; present::page %W                           |
|      <3>            --> incr npage -1; present::page %W                         |
|      p              --> $w postscript -file p$npage.ps -rotate 1               |
|      d              --> present::dump                                           |
+----------------------------------------------------------------------------------+

figure. PRESENT::PAGE PROC: RENDERING FLOW


+----------------------------------------------------------------------------------+
| PRESENT::PAGE PROC: RENDERING FLOW  (proc present::page w)                     |
|                                                                                  |
|    Step 1: Boundary clamp                                                       |
|      set maxpages [llength $pages]                                              |
|      set npage [expr {$npage<0 ? 0 : $npage>=$maxpages ? $maxpages-1 : $npage}]|
|         |                                                                        |
|         v                                                                        |
|    Step 2: Update window title                                                  |
|      wm title . "$::script $npage"                                             |
|         |                                                                        |
|         v                                                                        |
|    Step 3: Clear canvas                                                         |
|      $w delete all                                                              |
|         |                                                                        |
|         v                                                                        |
|    Step 4: Unpack slide data                                                    |
|      lassign [lindex $pages $npage] title body                                  |
|         |                                                                        |
|         v                                                                        |
|    Step 5: Draw title and rule                                                  |
|      set x 50; set y 50                                                         |
|      create text x=50 y=50 -text $title -font h1 -fill blue                    |
|      create line x=50 y=80 to 32000 y=80 -width 3 -fill red                   |
|      incr y 40  (y now = 90)                                                   |
|         |                                                                        |
|         v                                                                        |
|    Step 6: Render body lines (foreach line in split $body \n)                  |
|      string trim --> switch on first char --> select font                       |
|      if + marker: call present::bullet $w $x $y                               |
|      create text $x $y -anchor w -text [string range $line 2 end] -font $font  |
|      incr y 40                                                                  |
+----------------------------------------------------------------------------------+

figure. PRESENT::DUMP PROC: TEXT FILE OUTPUT


+----------------------------------------------------------------------------------+
| PRESENT::DUMP PROC: TEXT FILE OUTPUT  (proc present::dump {})                  |
|    Saves all slides to a plain text file; keyed by d keystroke                 |
|                                                                                  |
|    Output filename:                                                             |
|      [file rootname $::argv0].txt                                               |
|      Same folder as script; .tcl extension replaced with .txt                  |
|                                                                                  |
|    File encoding: ascii,  line ending: crlf  (Windows compatible)              |
|                                                                                  |
|    Output format per slide:                                                     |
|      ============================================================  (60 = signs) |
|      Slide N: Title Text                                                        |
|      ============================================================               |
|      [body lines formatted by marker]                                           |
|      [blank line between slides]                                                |
|                                                                                  |
|    Marker translation in dump:                                                  |
|    +--------+-----------------------------------------------+                  |
|    | marker | dump output format                            |                  |
|    +--------+-----------------------------------------------+                  |
|    |   +    |   * text  (two spaces + asterisk + space)     |                  |
|    |   >    |     text  (four spaces, code indent)          |                  |
|    |   .    |     text  (four spaces, plain indent)         |                  |
|    | other  |   text    (two spaces, default)               |                  |
|    | blank  | skipped (continue)                            |                  |
|    +--------+-----------------------------------------------+                  |
|                                                                                  |
|    After write: tk_messageBox -title "Dump saved"                              |
|      reports full output path to user                                           |
+----------------------------------------------------------------------------------+

figure. SLIDE CONTENT SUMMARY: ALL 8 SLIDES


+----------------------------------------------------------------------------------+
| SLIDE CONTENT SUMMARY: ALL 8 SLIDES                                             |
|                                                                                  |
| +----+----------------------------------+-------------------------------------+ |
| | #  | title                            | key bullet points                   | |
| +----+----------------------------------+-------------------------------------+ |
| |  0 | Tcl/Tk in Practice               | author, company, date (body lines)  | |
| |  1 | Tcl/Tk in Practice               | open source, platform-independent,  | |
| |    |                                  | scripting, programming, UI with Tk  | |
| |  2 | Scripting with Tcl               | single file, argv, exec/open, env,  | |
| |    |                                  | sed/awk replacement, control structs | |
| |  3 | Small Tcl Examples               | filter (stdin/stdout), file size sum | |
| |    |                                  | code blocks (> marker, Courier font) | |
| |  4 | Programming with Tcl             | procedures, packages, namespaces,   | |
| |    |                                  | C/C++ extensibility, autoload       | |
| |  5 | GUI Programming with Tk          | widgets, geometry managers, bindings | |
| |    |                                  | event model                         | |
| |  6 | Example: Editor with Scrollbars  | text + scrollbar code block,        | |
| |    |                                  | grid layout with weights            | |
| |  7 | Example: this Presentation       | 117 lines, canvas widget, text/     | |
| |    |                                  | line/oval items, PostScript output  | |
| +----+----------------------------------+-------------------------------------+ |
|                                                                                  |
|    Navigation: left-click or space = next; right-click = previous              |
|    Total slides: 8  (indices 0 to 7)                                            |
+----------------------------------------------------------------------------------+

figure. BULLET PROC: OVAL GEOMETRY


+----------------------------------------------------------------------------------+
| BULLET PROC: OVAL GEOMETRY  (proc present::bullet {w x y})                     |
|                                                                                  |
|    Drawn as a filled black oval to the LEFT of the text baseline                |
|                                                                                  |
|    Coordinates:                                                                 |
|      x1_oval = x - 20  =  50 - 20  =  30  (left edge)                          |
|      y1_oval = y -  5  =  y  - 5          (top edge)                           |
|      x2_oval = x - 10  =  50 - 10  =  40  (right edge)                         |
|      y2_oval = y +  5  =  y  + 5          (bottom edge)                        |
|                                                                                  |
|      Oval width  = 10 pixels  (x2 - x1)                                        |
|      Oval height = 10 pixels  (y2 - y1)                                        |
|      Oval center = (35, y)    (horizontally between x=30 and x=40)             |
|                                                                                  |
|    Visual result:                                                               |
|         x=30 x=40  x=50                                                        |
|           [===]  + Scripting with Tcl        <- oval at 30-40, text at 50      |
|                    (Times 24, anchor west)                                      |
|                                                                                  |
|    The oval baseline aligns with the text baseline:                             |
|      oval y-center = y = text y (both anchored to same y coordinate)           |
|      oval spans y-5 to y+5 = 10px height straddling the baseline               |
+----------------------------------------------------------------------------------+

figure. POSTSCRIPT EXPORT AND DUMP OUTPUT


+----------------------------------------------------------------------------------+
| POSTSCRIPT EXPORT AND DUMP OUTPUT                                               |
|                                                                                  |
|    PostScript (key p):                                                          |
|      $w postscript -file p$present::npage.ps -rotate 1                         |
|      One file per slide: p0.ps, p1.ps, ... p7.ps                               |
|      -rotate 1  --> landscape orientation                                       |
|      Saves current canvas content at moment of keypress                        |
|      Canvas items (text, line, oval) all supported in PostScript export        |
|                                                                                  |
|    Text dump (key d):                                                           |
|      All slides written in one pass to single .txt file                         |
|      Separator line: 60 equal signs (string repeat = 60)                        |
|                                                                                  |
|    Sample dump output:                                                          |
|      ============================================================               |
|      Slide 2: Scripting with Tcl                                                |
|      ============================================================               |
|        * typically limited to a single source file                              |
|          call arguments in argv, script name in argv0                          |
|        * Directly executable scripts (executable file)                          |
|        * Calling external programs with exec/open                               |
|        * Environment mapped in array ::env                                      |
|        * Many external programs (sed, awk) replaceable internally               |
|        * Control structures: if, while, foreach, for                            |
|                                                                                  |
|    tk_messageBox confirms write: "All slides written to: /path/script.txt"     |
+----------------------------------------------------------------------------------+

figure. SELF-REFERENTIAL NOTE: PRESENTATION IS ITS OWN EXAMPLE


+----------------------------------------------------------------------------------+
| SELF-REFERENTIAL NOTE: PRESENTATION IS ITS OWN EXAMPLE (Slide 7)              |
|                                                                                  |
|    Slide 7 ("Example: this Presentation") states:                              |
|      + This presentation is a Tcl/Tk script in 117 lines                       |
|      . of which approx. 50 lines program code, 70 lines data                   |
|      + Canvas widget                                                            |
|      . Items of types 'text', 'line' and 'oval'                                |
|      + Slides can be saved as PostScript files.                                 |
|                                                                                  |
|    The program demonstrates each concept it describes:                          |
|    +-------------------------------+----------------------------------------+  |
|    | concept described             | demonstrated in the program by          |  |
|    +-------------------------------+----------------------------------------+  |
|    | Canvas widget                 | pack [canvas .c ...]                    |  |
|    | text items                    | $w create text (title and body)         |  |
|    | line items                    | $w create line (red title rule)         |  |
|    | oval items                    | $w create oval (bullets)                |  |
|    | PostScript export             | $w postscript -file ... -rotate 1       |  |
|    | bindings                      | bind $w <1> / <3> /  / p / d    |  |
|    | namespace                     | namespace eval present { ... }          |  |
|    | self-test guard               | if { [file tail [info script]] eq ...}  |  |
|    +-------------------------------+----------------------------------------+  |
|                                                                                  |
|    Self-test guard pattern:                                                     |
|      if {[file tail [info script]] eq [file tail $argv0]} { ... }              |
|      Runs main block only when script is executed directly                      |
|      Allows safe sourcing as a library (present::go called externally)         |
+----------------------------------------------------------------------------------+

figure. OVERALL PROGRAM STRUCTURE

copy----

+----------------------------------------------------------------------------------+
| OVERALL PROGRAM STRUCTURE  (Tcl/Tk in Practice, R. Suchenwirth, 2002-04-30)   |
|                                                                                  |
|    SECTION 1: Slide data (lines 1-45 approx.)                                  |
|      set pages { ...8 slides as nested lists... }                               |
|         |                                                                        |
|    SECTION 2: Namespace declaration (lines 46-52)                               |
|      namespace eval present {                                                   |
|        set version 0.2                                                          |
|        variable pages {}; variable npage 0; variable fonts                     |
|      }                                                                           |
|         |                                                                        |
|    SECTION 3: Proc definitions (lines 53-120 approx.)                          |
|      proc present::go {w Pages}       <-- initialization + bindings            |
|      proc present::bullet {w x y}     <-- draw one bullet oval                 |
|      proc present::page {w}           <-- render current slide                 |
|      proc present::dump {}            <-- write all slides to .txt file        |
|         |                                                                        |
|    SECTION 4: Self-test main block (lines 121-125 approx.)                     |
|      if {[file tail [info script]] eq [file tail $argv0]} {                    |
|        pack [canvas .c -bg white -width 800 -height 600] -fill both -expand 1  |
|        set ::script [wm title .]                                                |
|        present::go .c $pages                                                   |
|      }                                                                           |
|                                                                                  |
|    117 lines total: ~50 lines code, ~70 lines slide data                       |
+----------------------------------------------------------------------------------+

Don Libes is an American computer scientist, best known for creating Expect, a powerful tool for automating interactive terminal applications in Unix. Expect allows users to script interactions with command-line programs, making it invaluable for tasks like automated testing, system administration, and network management. Don Libes has made significant contributions to the field of automation and scripting languages. Links: Wikipedia: You can find more information about Don Libes and his contributions on his Wikipedia page1. Book: Don Libes authored the book “Exploring Expect: A Tcl-based Toolkit for Automating Interactive Programs”. It provides practical examples of how Expect can be used to automate real-world tasks 23. Don Libes’ work has had a lasting impact on the field of automation, and his tools continue to be widely used by developers and system administrators


John K. Ousterhout is founder and CEO of Electric Cloud, Inc. He is also creator of the Tcl scripting language and is well known for his work in distributed operating systems, high-performance file systems, and user interfaces. Here how he describes the events: I got the idea for Tcl while on sabbatical leave at DEC's Western Research Laboratory in the fall of 1987. I started actually implementing it when I got back to Berkeley in the spring of 1988; by summer of that year it was in use in some internal applications of ours, but there was no Tk. The first external releases of Tcl were in 1989, I believe. I started implementing Tk in 1989, and the first release of Tk was in 1991. mORE on the Ousterhout website.


Hidden Comments Section

Please include your wiki MONIKER and date in your comment with the same courtesy that I will give you. Thanks, gold 3/26/2024