File: macro_example_1.tcl

package info (click to toggle)
abacus 0.9.13-4
  • links: PTS
  • area: main
  • in suites: potato
  • size: 6,308 kB
  • ctags: 5,120
  • sloc: ansic: 27,540; cpp: 11,426; tcl: 7,564; makefile: 386; yacc: 327; lex: 265; sh: 221
file content (62 lines) | stat: -rw-r--r-- 1,583 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# An example of what can happen when you mix the abacus with Tcl/Tk ... simple
# but should give you an idea of what can be done

proc GoPickNumber {num} {
    
    # someone should do a regexp on num here to check if it's really a number
    # or a character string, but since this is an example it doesn't matter
    # that much ;>

    CellSet example 0 0 $num
    if {$num<0} {set num -num}
    while {$num>0} {set num [expr $num - 2]}
    if { $num==0 } {
	CellSet example 0 1 "The value in cell 0 0 is even"
    } else {
	CellSet example 0 1 "The value in cell 0 0 is odd"
    }
}    

proc DoMenu {} {
    toplevel .picknumber
    wm title .picknumber "Pick a Number"
    
    frame .picknumber.picknumberby

    label .picknumber.picknumberby.text -text "Pick a number:"
    set Number ""
    entry .picknumber.picknumberby.entry -textvariable Number

    pack .picknumber.picknumberby.text \
	.picknumber.picknumberby.entry -side left
    
    frame .picknumber.endr
    button .picknumber.endr.ok -text Ok \
	-command {
	    GoPickNumber $Number
	    return 0
	}
    button .picknumber.endr.abort -text Abort \
	-command {
	    destroy .picknumber
	    return -1
	}
    pack .picknumber.endr.ok .picknumber.endr.abort -fill x -expand yes \
	-side bottom
    pack .picknumber.endr .picknumber.picknumberby \
	-side bottom -fill x -expand yes
    
    focus .picknumber
    grab .picknumber
    tkwait window .picknumber
}

CellSet example 0 0 2
CellSet example 0 1 "The value in cell 0 0 is even"
while {1==1} {
    if {[DoMenu]==0} {
	update
    } else {
	return 0
    }
}