OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tix/] [demos/] [samples/] [SGrid1.tcl] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
# Tix Demostration Program
2
#
3
# This sample program is structured in such a way so that it can be
4
# executed from the Tix demo program "widget": it must have a
5
# procedure called "RunSample". It should also have the "if" statment
6
# at the end of this file so that it can be run as a standalone
7
# program using tixwish.
8
 
9
# Demonstrates the tixGrid widget
10
#
11
 
12
proc RunSample {w} {
13
    wm title $w "Doe Inc. Performance"
14
    wm geometry $w 640x300
15
 
16
    set top [frame $w.f -bd 1 -relief raised]
17
    set box [tixButtonBox $w.b -bd 1 -relief raised]
18
 
19
    pack $box -side bottom -fill both
20
    pack $top -side top -fill both -expand yes
21
 
22
    label $top.lab -text "This widget is still under alpha
23
Please ignore the debug messages
24
Not all features have been implemented" -justify left
25
    pack $top.lab -side top -anchor c -padx 3 -pady 3
26
 
27
    MakeGrid $top
28
 
29
    # Create the buttons
30
    #
31
    $box add ok     -text Ok     -command "destroy $w" -width 6
32
    $box add cancel -text Cancel -command "destroy $w" -width 6
33
}
34
 
35
# This command is called whenever the background of the grid needs to
36
# be reformatted. The x1, y1, x2, y2 sprcifies the four corners of the area
37
# that needs to be reformatted.
38
#
39
proc gformat {w area x1 y1 x2 y2} {
40
    set bg(s-margin) gray65
41
    set bg(x-margin) gray65
42
    set bg(y-margin) gray65
43
    set bg(main)     gray20
44
 
45
    case $area {
46
        main {
47
            for {set y [expr ($y1/2) * 2]} {$y <= $y2} {incr y 2} {
48
                $w format border $x1 $y $x2 $y \
49
                    -relief flat -filled 1\
50
                    -bd 0 -bg #80b080 -selectbackground #80b0ff
51
            }
52
            $w format grid $x1 $y1 $x2 $y2 \
53
                -relief raised -bd 1 -bordercolor $bg($area) -filled 0 -bg red\
54
                -xon 1 -yon 1 -xoff 0 -yoff 0 -anchor se
55
        }
56
        y-margin {
57
            $w format border $x1 $y1 $x2 $y2 \
58
                -fill 1 -relief raised -bd 1 -bg $bg($area) \
59
                -selectbackground gray80
60
        }
61
 
62
        default {
63
            $w format border $x1 $y1 $x2 $y2 \
64
                -filled 1 \
65
                -relief raised -bd 1 -bg $bg($area) \
66
                -selectbackground gray80
67
        }
68
    }
69
}
70
 
71
# Print a number in $ format
72
#
73
#
74
proc Dollar {s} {
75
    set n [string len $s]
76
    set start [expr $n % 3]
77
    if {$start == 0} {
78
        set start 3
79
    }
80
 
81
    set str ""
82
    for {set i 0} {$i < $n} {incr i} {
83
        if {$start == 0} {
84
            append str ","
85
            set start 3
86
        }
87
        incr start -1
88
        append str [string index $s $i]
89
    }
90
    return $str
91
}
92
 
93
proc MakeGrid {w} {
94
 
95
    # data format {year revenue profit}
96
    #
97
    set data {
98
        {1970   1000000000      1000000}
99
        {1971   1100000000      2000000}
100
        {1972   1200000000      3000000}
101
        {1973   1300000000      4000000}
102
        {1974   1400000000      5000000}
103
        {1975   1500000000      6000000}
104
        {1976   1600000000      7000000}
105
        {1977   1700000000      8000000}
106
        {1978   1800000000      9000000}
107
        {1979   1900000000     10000000}
108
        {1980   2000000000     11000000}
109
        {1981   2100000000     22000000}
110
        {1982   2200000000     33000000}
111
        {1983   2300000000     44000000}
112
        {1984   2400000000     55000000}
113
        {1985   3500000000     36000000}
114
        {1986   4600000000     57000000}
115
        {1987   5700000000     68000000}
116
        {1988   6800000000     79000000}
117
        {1989   7900000000     90000000}
118
        {1990  13000000000    111000000}
119
        {1991  14100000000    122000000}
120
        {1992  16200000000    233000000}
121
        {1993  28300000000    344000000}
122
        {1994  29400000000    455000000}
123
        {1995  38500000000    536000000}
124
    }
125
 
126
    set headers {
127
        "Revenue ($)"
128
        "Rev. Growth (%)"
129
        "Profit ($)"
130
        "Profit Growth (%)"
131
    }
132
 
133
    # Create the grid
134
    #
135
    tixScrolledGrid $w.g -bd 0
136
    pack $w.g -expand yes -fill both -padx 3 -pady 3
137
 
138
    set grid [$w.g subwidget grid]
139
    $grid config -formatcmd "gformat $grid"
140
 
141
    # Set the size of the columns
142
    #
143
    $grid size col 0 -size 10char
144
    $grid size col 1 -size auto
145
    $grid size col 2 -size auto
146
    $grid size col 3 -size auto
147
    $grid size col 4 -size auto
148
 
149
    # set the default size of the column and rows. these sizes will be used
150
    # if the size of a row or column has not be set via the "size col ?"
151
    # command
152
    $grid size col default -size 5char
153
    $grid size row default -size 1.1char -pad0 3
154
 
155
    set margin [tixDisplayStyle text -refwindow $grid   \
156
        -anchor c -padx 3 -font [tix option get bold_font]]
157
    set dollar [tixDisplayStyle text  -refwindow $grid  \
158
        -anchor e]
159
 
160
    # Create the headers
161
    #
162
    set x 1
163
    foreach h $headers {
164
        $grid set $x 0 -itemtype text -text $h -style $margin
165
        incr x
166
    }
167
 
168
    # Insert the data, year by year
169
    #
170
    set lastRevn {}
171
    set lastProf {}
172
    set i         1
173
    foreach line $data {
174
        set year [lindex $line 0]
175
        set revn [lindex $line 1]
176
        set prof [lindex $line 2]
177
 
178
        if {$lastRevn != {}} {
179
            set rgrowth \
180
                [format %4.2f [expr ($revn.0-$lastRevn)/$lastRevn*100.0]]
181
        } else {
182
            set rgrowth "-"
183
        }
184
        if {$lastProf != {}} {
185
            set pgrowth \
186
                [format %4.2f [expr ($prof.0-$lastProf)/$lastProf*100.0]]
187
        } else {
188
            set pgrowth "-"
189
        }
190
 
191
        $grid set 0 $i -itemtype text -style $margin -text $year
192
        $grid set 1 $i -itemtype text -style $dollar -text [Dollar $revn]
193
        $grid set 2 $i -itemtype text -style $dollar -text $rgrowth
194
        $grid set 3 $i -itemtype text -style $dollar -text [Dollar $prof]
195
        $grid set 4 $i -itemtype text -style $dollar -text $pgrowth
196
 
197
        set lastRevn $revn.0
198
        set lastProf $prof.0
199
 
200
        incr i
201
    }
202
}
203
 
204
 
205
if {![info exists tix_demo_running]} {
206
    wm withdraw .
207
    set w .demo
208
    toplevel $w
209
    RunSample $w
210
    bind $w <Destroy> exit
211
}

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.