1 | # ---------------------------------------------------------------------- |
---|
2 | # COMPONENT: testview - display the results of a test |
---|
3 | # |
---|
4 | # Entire right hand side of the regression tester. Displays the |
---|
5 | # golden test results, and compares them to the new results if the test |
---|
6 | # has been run. Also show tree representation of all inputs and |
---|
7 | # outputs. The -test configuration option is used to provide a Test |
---|
8 | # object to display. |
---|
9 | # ====================================================================== |
---|
10 | # AUTHOR: Michael McLennan, Purdue University |
---|
11 | # Copyright (c) 2010-2011 Purdue Research Foundation |
---|
12 | # |
---|
13 | # See the file "license.terms" for information on usage and |
---|
14 | # redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
15 | # ====================================================================== |
---|
16 | package require Itk |
---|
17 | package require RapptureGUI |
---|
18 | |
---|
19 | namespace eval Rappture::Tester { # forward declaration } |
---|
20 | |
---|
21 | option add *StatusList.font {Arial -12} widgetDefault |
---|
22 | option add *StatusList.titleFont {Arial -12 bold} widgetDefault |
---|
23 | option add *StatusList.subTitleFont {Arial -10} widgetDefault |
---|
24 | |
---|
25 | itcl::class Rappture::Tester::StatusEntry { |
---|
26 | public variable title "" |
---|
27 | public variable subtitle "" |
---|
28 | public variable body "" |
---|
29 | public variable icon "" |
---|
30 | public variable clientdata "" |
---|
31 | |
---|
32 | constructor {args} { eval configure $args } |
---|
33 | } |
---|
34 | |
---|
35 | itcl::class Rappture::Tester::StatusList { |
---|
36 | inherit itk::Widget |
---|
37 | |
---|
38 | itk_option define -font font Font "" |
---|
39 | itk_option define -titlefont titleFont Font "" |
---|
40 | itk_option define -subtitlefont subTitleFont Font "" |
---|
41 | itk_option define -selectcommand selectCommand SelectCommand "" |
---|
42 | itk_option define -selectbackground selectBackground Foreground "" |
---|
43 | |
---|
44 | constructor {args} { # defined later } |
---|
45 | destructor { # defined later } |
---|
46 | |
---|
47 | public method insert {pos args} |
---|
48 | public method delete {from {to ""}} |
---|
49 | public method size {} { return [llength $_entries] } |
---|
50 | public method get {pos args} |
---|
51 | |
---|
52 | public method xview {args} { |
---|
53 | return [eval $itk_component(listview) xview $args] |
---|
54 | } |
---|
55 | public method yview {args} { |
---|
56 | return [eval $itk_component(listview) yview $args] |
---|
57 | } |
---|
58 | |
---|
59 | protected method _redraw {} |
---|
60 | protected method _select {tag} |
---|
61 | |
---|
62 | private variable _dispatcher "" ;# dispatcher for !events |
---|
63 | private variable _entries "" ;# list of status entries |
---|
64 | } |
---|
65 | |
---|
66 | # ---------------------------------------------------------------------- |
---|
67 | # CONSTRUCTOR |
---|
68 | # ---------------------------------------------------------------------- |
---|
69 | itcl::body Rappture::Tester::StatusList::constructor {args} { |
---|
70 | Rappture::dispatcher _dispatcher |
---|
71 | $_dispatcher register !redraw |
---|
72 | $_dispatcher dispatch $this !redraw "[itcl::code $this _redraw]; list" |
---|
73 | |
---|
74 | itk_component add listview { |
---|
75 | canvas $itk_interior.lv -relief flat |
---|
76 | } { |
---|
77 | usual |
---|
78 | keep -xscrollcommand -yscrollcommand |
---|
79 | } |
---|
80 | pack $itk_component(listview) -expand yes -fill both |
---|
81 | |
---|
82 | eval itk_initialize $args |
---|
83 | } |
---|
84 | |
---|
85 | itk::usual StatusList { |
---|
86 | keep -background -foreground -cursor |
---|
87 | keep -selectbackground |
---|
88 | keep -font -titlefont -subtitlefont |
---|
89 | } |
---|
90 | |
---|
91 | # ---------------------------------------------------------------------- |
---|
92 | # DESTRUCTOR |
---|
93 | # ---------------------------------------------------------------------- |
---|
94 | itcl::body Rappture::Tester::StatusList::destructor {} { |
---|
95 | delete 0 end |
---|
96 | } |
---|
97 | |
---|
98 | # ---------------------------------------------------------------------- |
---|
99 | # USAGE: insert <pos> ?-option value -option value ...? |
---|
100 | # |
---|
101 | # Inserts a new entry into the list at the given <pos>. The options |
---|
102 | # are those recognized by a StatusEntry object. |
---|
103 | # ---------------------------------------------------------------------- |
---|
104 | itcl::body Rappture::Tester::StatusList::insert {pos args} { |
---|
105 | set entry [eval Rappture::Tester::StatusEntry #auto $args] |
---|
106 | set _entries [linsert $_entries $pos $entry] |
---|
107 | $_dispatcher event -idle !redraw |
---|
108 | } |
---|
109 | |
---|
110 | # ---------------------------------------------------------------------- |
---|
111 | # USAGE: delete <pos> ?<toPos>? |
---|
112 | # |
---|
113 | # Deletes a single entry or a range of entries from the list displayed |
---|
114 | # in this widget. |
---|
115 | # ---------------------------------------------------------------------- |
---|
116 | itcl::body Rappture::Tester::StatusList::delete {pos {to ""}} { |
---|
117 | if {$to eq ""} { |
---|
118 | set to $pos |
---|
119 | } |
---|
120 | foreach obj [lrange $_entries $pos $to] { |
---|
121 | itcl::delete object $obj |
---|
122 | } |
---|
123 | set _entries [lreplace $_entries $pos $to] |
---|
124 | $_dispatcher event -idle !redraw |
---|
125 | } |
---|
126 | |
---|
127 | |
---|
128 | # ---------------------------------------------------------------------- |
---|
129 | # USAGE: _redraw |
---|
130 | # |
---|
131 | # Used internally to update the detailed list of items maintained |
---|
132 | # by this widget. |
---|
133 | # ---------------------------------------------------------------------- |
---|
134 | itcl::body Rappture::Tester::StatusList::_redraw {} { |
---|
135 | set c $itk_component(listview) |
---|
136 | $c delete all |
---|
137 | |
---|
138 | # figure out the maximum size of all icons |
---|
139 | set iw 0 |
---|
140 | set ih 0 |
---|
141 | foreach obj $_entries { |
---|
142 | set icon [$obj cget -icon] |
---|
143 | if {$icon ne ""} { |
---|
144 | if {[image width $icon] > $iw} { set iw [image width $icon] } |
---|
145 | if {[image height $icon] > $ih} { set ih [image height $icon] } |
---|
146 | } |
---|
147 | } |
---|
148 | |
---|
149 | set tlineh [font metrics $itk_option(-titlefont) -linespace] |
---|
150 | set stlineh [font metrics $itk_option(-subtitlefont) -linespace] |
---|
151 | |
---|
152 | set x0 2 |
---|
153 | set y0 2 |
---|
154 | set n 0 |
---|
155 | foreach obj $_entries { |
---|
156 | set tag "entry$n" |
---|
157 | |
---|
158 | set icon [$obj cget -icon] |
---|
159 | set iconh 0 |
---|
160 | if {$icon ne ""} { |
---|
161 | $c create image [expr {$x0+$iw}] $y0 -anchor ne -image $icon \ |
---|
162 | -tags [list $tag main] |
---|
163 | set iconh [image height $icon] |
---|
164 | } |
---|
165 | set x1 [expr {$x0+$iw+3}] |
---|
166 | set y1 $y0 |
---|
167 | |
---|
168 | set title [$obj cget -title] |
---|
169 | if {$title ne ""} { |
---|
170 | $c create text $x1 $y1 -anchor nw -text $title \ |
---|
171 | -font $itk_option(-titlefont) -tags [list $tag main] |
---|
172 | set y1 [expr {$y1+$tlineh+2}] |
---|
173 | } |
---|
174 | |
---|
175 | set subtitle [$obj cget -subtitle] |
---|
176 | if {$subtitle ne ""} { |
---|
177 | $c create text $x1 $y1 -anchor nw -text $subtitle \ |
---|
178 | -font $itk_option(-subtitlefont) -tags [list $tag main] |
---|
179 | set y1 [expr {$y1+$stlineh+2}] |
---|
180 | } |
---|
181 | |
---|
182 | set body [$obj cget -body] |
---|
183 | if {$body ne ""} { |
---|
184 | # a little space between the title/subtitle and the body |
---|
185 | if {$y1 != $y0} { incr y1 4 } |
---|
186 | |
---|
187 | set id [$c create text $x1 $y1 -anchor nw -text $body \ |
---|
188 | -font $itk_option(-font) -tags [list $tag main]] |
---|
189 | |
---|
190 | foreach {tx0 ty0 tx1 ty1} [$c bbox $id] break |
---|
191 | set y1 [expr {$y1 + ($ty1-$ty0)}] |
---|
192 | } |
---|
193 | |
---|
194 | # make sure that y1 is at the bottom of the icon too |
---|
195 | if {$y1 < $y0+$iconh+2} { |
---|
196 | set y1 [expr {$y0+$iconh+2}] |
---|
197 | } |
---|
198 | |
---|
199 | # make a background selection rectangle |
---|
200 | set id [$c create rectangle 0 [expr {$y0-2}] 1000 $y1 \ |
---|
201 | -outline "" -fill "" -tags [list allbg $tag:bg]] |
---|
202 | $c lower $id |
---|
203 | |
---|
204 | foreach item [list $tag $tag:bg] { |
---|
205 | $c bind $item <ButtonPress> \ |
---|
206 | [itcl::code $this _select $tag] |
---|
207 | } |
---|
208 | |
---|
209 | set y0 [expr {$y1+10}] |
---|
210 | incr n |
---|
211 | } |
---|
212 | |
---|
213 | # set the scrolling region to the "main" part (no bg boxes) |
---|
214 | foreach {x0 y0 x1 y1} [$c bbox main] break |
---|
215 | $c configure -scrollregion [list 0 0 [expr {$x1+4}] [expr {$y1+4}]] |
---|
216 | } |
---|
217 | |
---|
218 | # ---------------------------------------------------------------------- |
---|
219 | # USAGE: _select <tag> |
---|
220 | # |
---|
221 | # Called internally when the user clicks on an item in the status |
---|
222 | # list that shows specific test failures. Highlights the item and |
---|
223 | # invokes any -statuscommand configured for the widget. Additional |
---|
224 | # details about the item are appended onto the command as a list of |
---|
225 | # options and values. These include the integer -index for the |
---|
226 | # position of the selected item, along with details defined when |
---|
227 | # the item was inserted into the list. |
---|
228 | # ---------------------------------------------------------------------- |
---|
229 | itcl::body Rappture::Tester::StatusList::_select {tag} { |
---|
230 | set c $itk_component(listview) |
---|
231 | $c itemconfigure allbg -fill "" |
---|
232 | $c itemconfigure $tag:bg -fill $itk_option(-selectbackground) |
---|
233 | |
---|
234 | if {[string length $itk_option(-selectcommand)] > 0} { |
---|
235 | set id ""; regexp {[0-9]+$} $tag id |
---|
236 | set vlist "" |
---|
237 | set obj [lindex $_entries $id] |
---|
238 | if {$obj ne ""} { |
---|
239 | foreach opt [$obj configure] { |
---|
240 | lappend vlist [lindex $opt 0] [lindex $opt end] |
---|
241 | } |
---|
242 | } |
---|
243 | uplevel #0 $itk_option(-selectcommand) -index $id $vlist |
---|
244 | } |
---|
245 | } |
---|