Version 17 of Canvas presentation graphics

Updated 2008-10-29 05:45:43 by Stu

Richard Suchenwirth 2002-04-30 - Before knowing of Arjen Markus's A simple slideshow, I decided that a presentation about Tcl/Tk should be done in Tcl/Tk. Here is my version which uses a canvas and can also produce Postscript of the pages (text in German, sorry, but that's what I wrote it for).

WikiDbImage present.jpg

The screenshot above shows a line highlighted in red, which happens when you mouse over it.


iShow is a much simplified version later variation of this.


 set pages {
    {{Tcl/Tk in der Praxis} {
	.
	. Richard Suchenwirth, Siemens Dematic PA RC D2
	. 2002-04-30
    }}
    {{Tcl/Tk in der Praxis} {
	+ Tcl: "Tool Command Language"
	. Open Source: freie Software (BSD-Lizenz)
	+ Scripting mit Tcl: plattformunabhängig Mac/Unix/Windows..
	+ Programmierung in Tcl
	. Aufbau komplexer Anwendungen möglich
	+ UI-Programmierung in Tk ("ToolKit")
    }}
    {{Scripting mit Tcl} {
	+ typischerweise auf eine Quelldatei beschränkt
	. Argumente des Aufrufs in argv, Name des Scripts in argv0
	+ Direkt ausführbare Skripte (executable file)
	+ Aufruf von externen Programmen mit exec/open
	+ Environment in Array ::env abgebildet
	+ Viele externe Programme (sed, awk) intern ersetzbar
	+ Kontrollstrukturen: if, while, foreach, for
    }}
    {{Kleine Tcl-Beispiele} {
	+ Filter (liest stdin, schreibt stdout)
	> while {[gets stdin line]>=0} {
	 >    # irgendeine Verarbeitung des Inputs, z.B. 
	>    set line [string toupper $line]
	>    puts stdout $line
	> }
	+ Iteration über Dateien: Größensumme in Bytes
	> set sum 0
	> foreach i [glob *] {incr sum [file size $i]}
	> puts "Total size: $sum Bytes"
    }}
    {{Programmierung mit Tcl} {
	+ kein Gegensatz zu Scripting, eher gleitender Übergang 
	+ Code typischerweise in Prozeduren organisiert 
	+ Libraries: Code auf mehrere Files (autoload, package) verteilt 
	. Libraries mit Selbsttest-Code (empfohlen)
	+ Strukturierung von Variablen- u. Prozedurnamen mit Namespaces 
	+ Erweiterbarkeit mit C/C++-Libraries
    }}
    {{GUI-Programmierung mit Tk} {
	+ Widgets: label, *button, menu, listbox, text, canvas ... 
	+ Geometrie-Manager: pack, grid, place 
	+ Bindings: Ereignisse (Maus, Tastatur) an Widgets
	+ Event-Modell
    }}
    {{Beispiel: Editor mit Scrollbars} {
	> #---------------------------------- Widgets anlegen
	> text .t -xscrollcommand ".x set" -yscrollcommand ".y set"
	> scrollbar .x -command ".t xview" -ori hori
	> scrollbar .y -command ".t yview" -ori vert
	> #---------------------------------- Widgets managen
	> grid .t .y -sticky news
	> grid .x    -sticky ew
	> #------------------- Gewichte für Größenveränderung
	> grid rowconf    . 0 -weight 1
	> grid columnconf . 0 -weight 1
    }}
    {{Beispiel: diese Präsentation} {
	+ Diese Präsentation ist ein Tcl/Tk Script in 117 Zeilen
	. davon ca. 50 Programmcode, 70 Zeilen Daten
	+ Canvas-Widget
	. Items der Typen 'text', 'line' und 'oval'
	+ Folien können als Postscript-Files erzeugt werden.
    }}
 }
 namespace eval present {set version 0.0}

 proc present::go {w Pages} {
    variable pages $Pages npage 0 fonts
    array set fonts {
	h1   {Times   36}
	h2   {Times   24}
	body {Times   18}
	pre  {Courier 18}
    }
    focus $w
    bind $w <space> {incr present::npage; present::page %W}
    bind $w p     {%W postscript -file p$present::npage.ps -rotate 1}
    bind $w <1>   {incr present::npage; present::page %W}
    bind $w <3>   {incr present::npage -1; present::page %W}
    present::page $w
 }
 proc present::bullet {w x y} {
    $w create oval [expr $x-20] [expr $y-5] [expr $x-10] [expr $y+5] -fill black 
 }
 proc present::page w {
    variable pages; variable npage
    variable fonts
    set maxpages [llength $pages]
    set npage [expr {$npage<0? 0: $npage>=$maxpages? $maxpages-1: $npage}]
    $w delete all
    foreach {title body} [lindex $pages $npage] break
    set x 50; set y 50
    $w create text $x $y -anchor w -text $title -font $fonts(h1) -fill blue
    $w create line $x [expr $y+30] 32000 [expr $y+30] -width 3 -fill red
    incr y 40
    foreach line [split $body \n] {
	set line [string trim $line]
	switch  -- [string index $line 0] {
	    >       {set font $fonts(pre)}
	    +       {set font $fonts(h2);bullet $w $x $y}
	    default {set font $fonts(body)}
	}
	$w create text $x $y -anchor w -text [string range $line 2 end] -font $font
	incr y 40
    }
 }
 if {[file tail [info script]]==[file tail $argv0]} {
    pack [canvas .c -bg white -width 800 -height 600] -fill both -expand 1
    present::go .c $pages
 }

Corrected a typo on the page "Kleine Tcl-Beispiele" (a closing brace too much) -- TR


Arts and crafts of Tcl-Tk programming

Category Application

Category Graphics Category Presentation