File: TrnModule.tcl

package info (click to toggle)
trn4 4.0-test76-3
  • links: PTS
  • area: non-free
  • in suites: woody
  • size: 2,988 kB
  • ctags: 2,965
  • sloc: ansic: 48,337; sh: 6,770; tcl: 1,696; yacc: 660; perl: 108; makefile: 72
file content (118 lines) | stat: -rw-r--r-- 2,727 bytes parent folder | download | duplicates (12)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#TrnModule: provides frames or toplevels to TrnModules--will later provide
#           common functionality of all modules.

class TrnModule
TrnModule inherit Widget

#toplevel config is an error
TrnModule option {-toplevel} {0} verify {
    if {$toplevel} {
	set toplevel 1
    } else {
	set toplevel 0
    }
}

TrnModule option {-width} {120} configure {
    instvar f
    $f config -width $width
}

TrnModule option {-height} {100} configure {
    instvar f
    $f config -height $height
}

#XXX clean this up, allow for initial setting
TrnModule option {-title} {} configure {
    instvar f toplevel
    if {$toplevel} {
	wm title $f $title
    }
}

TrnModule method init { args } {
    instvar f toplevel height width

    eval $self conf_verify $args

    if {$toplevel} {
	set f [next toplevel -width $width -height $height]
    } else {
	set f [next -width $width -height $height]
    }
    $self setsize
    return $f
}

#If not a toplevel, pack the frame
TrnModule method modulepack { args } {
    instvar f toplevel
    if {!$toplevel} {
	catch {pack $f -expand yes -fill both}
    }
}

#Later: save sizes of internal frames?
#            (might need to know resizing command, or make standard)

#Set size if there is a default (and if we are a toplevel)
#If there is no default, make the window saved later

#Note: This code used to set the size and position immediately.
#      Unfortunately, the window would (usually) not be mapped, so the
#      window manager did not adjust for the decorations.

TrnModule method setsize {} {
    instvar toplevel f
    global _TrnModule_winpos _TrnModule_winlist

    if {$toplevel} {
	set _TrnModule_winlist($f) 1
    }
}

#consider special check if no data
#Only currently mapped windows are saved.
proc TrnModule_savesizes {fname} {
    global _TrnModule_winpos _TrnModule_winlist

    foreach w [array names _TrnModule_winlist] {
	catch {
	    if {[winfo ismapped $w]} {
		set _TrnModule_winpos($w) [winfo geometry $w]
	    }
	}
    }
    set data [array get _TrnModule_winpos]

    set file [open $fname "w"]
    puts $file $data
    close $file
}

proc TrnModule_loadsizes {fname} {
    global _TrnModule_winpos
    catch {
	set file [open $fname "r"]
	gets $file data
	close $file
	array set _TrnModule_winpos $data
    }
}

#Reset all windows to their saved sizes.
proc TrnModule_setsizes {} {
    global _TrnModule_winpos _TrnModule_winlist
    foreach w [array names _TrnModule_winlist] {
	catch {wm geom $w $_TrnModule_winpos($w)}
    }
}

#Reset all windows to their natural sizes.
proc TrnModule_naturalsizes {} {
    global _TrnModule_winpos _TrnModule_winlist
    foreach w [array names _TrnModule_winlist] {
	catch {wm geom $w $_TrnModule_winpos($w)}
    }
}