source: trunk/gui/apps/table

Last change on this file was 5662, checked in by ldelgass, 9 years ago

Fixes for table script. Although this script is not installed or used, it might
be useful as starting point for a results browser/diff tool.

  • Property svn:executable set to *
File size: 10.3 KB
Line 
1# -*- mode: Tcl -*-
2
3package require Rappture
4package require RapptureGUI
5
6# TK code
7package require fileutil
8proc is_xml {name} {return [string match *.xml $name]}
9
10# Starting main tk code
11
12package require BLT
13if { $tcl_version >= 8.0 } {
14    namespace import blt::*
15    namespace import -force blt::tile::*
16}
17
18proc SortColumn { column } {
19    set old [.t sort cget -column]
20    set decreasing 0
21    if { "$old" == "$column" } {
22        set decreasing [.t sort cget -decreasing]
23        set decreasing [expr !$decreasing]
24    }
25    .t sort configure -decreasing $decreasing -column $column -mode integer
26    if { ![.t cget -flat] } {
27        .t configure -flat yes
28    }
29    .t sort auto yes
30    blt::busy hold .t
31    update
32    blt::busy release .t
33}
34
35proc resulttable {cmpfiles} {
36    # creating xml tables for each xml run files go here
37    set tree2 [tree create]
38    treeview .k \
39        -width 0 \
40        -yscrollcommand { .vvvs set } \
41        -xscrollcommand { .hhhs set } \
42        -selectmode single \
43        -tree $tree2
44    .k column configure treeView -text ""
45    .k column configure treeView -hide no -edit no \
46        -icon blt::tv::normalOpenFolder
47    focus .k
48    scrollbar .vvvs -orient vertical -command { .k yview }
49    scrollbar .hhhs -orient horizontal -command { .k xview }
50
51    table . \
52        0,0 .k -fill both \
53        0,1 .vvvs -fill y \
54        1,0 .hhhs -fill x
55    table configure . c1 r1 -resize none
56
57    puts "resulttable: $cmpfiles"
58
59    set flags [list]
60    set numfiles [llength $cmpfiles]
61    set biglist [list]
62
63    set memberlist [list]
64    set contentlist [list]
65    set counter 0
66    foreach filepath $cmpfiles {
67        set filename [file tail $filepath]
68        set lib [Rappture::library $filepath]
69        set inputs [$lib children -as component "input"]
70        foreach input $inputs {
71            set path "input.${input}.current"
72            if {$counter == 0} {
73                lappend memberlist $path
74            }
75            set value [$lib get $path]
76            puts "$path: $value"
77            lappend contentlist $value
78            unset value
79        }
80        set outputs [$lib children -as component "output"]
81        foreach output $outputs {
82            set path "output.${output}"
83            set value [$lib get $path]
84            if {"" != $value} {
85                if {$counter == 0} {
86                    lappend memberlist $path
87                }
88                puts "$path: $value"
89                lappend contentlist $value
90                unset value
91            }
92        }
93        set temp [list]
94        lappend temp $filename $contentlist
95        unset contentlist
96        lappend biglist $temp
97        unset temp
98        incr counter;
99    }
100    #puts memberlist
101    #puts $memberlist
102    puts "START_BIG_LIST [llength $biglist]"
103    puts $biglist
104    puts END_BIG_LIST
105    # Adding columns to table
106    #.k column insert end "filename" -text "File Name"
107    foreach path $memberlist {
108        puts "add column: $path"
109        if { "" == $path } {
110            continue
111        }
112        .k column insert end $path -text $path
113    }
114    # Comparing XML Tree
115    set count 0
116    set element1 [lindex $biglist 0]
117    set name1 [lindex $element1 0]
118    set content1 [lindex $element1 1]
119    foreach element2 $biglist {
120        if {$count != 0} {
121            foreach {name2 content2} $element2 {
122                set contentlen [llength $content2]
123                for {set i 0} {$i < $contentlen} {incr i} {
124                    #puts insideforloop
125                    set similarexisted 0
126                    if {[lindex $content1 $i] eq [lindex $content2 $i]} {
127                        #puts insidesame
128                    } else {
129                        #puts insidediff
130                        lappend flags 1
131                        continue
132                    }
133                    if { $similarexisted == 0 } {
134                        lappend flags 0
135                    }
136                }
137            }
138        }
139        incr count
140    }
141
142    foreach element $biglist {
143        set name [lindex $element 0]
144        set content [lindex $element 1]
145        set id [.k insert end $name]
146        set list_content [list]
147        foreach path $memberlist value $content flag $flags {
148            lappend list_content $path
149
150            if { $flag == 0} {
151                lappend list_content "Same"
152            } else {
153                lappend list_content $value
154            }
155        }
156        puts [llength $list_content]
157        puts $list_content
158        .k entry configure $id -data $list_content
159    }
160
161    #set templist [list]
162    #lappend templist "input.number(n1).current"
163    #lappend templist "h"
164    #lappend templist "input.number(n2).current"
165    #lappend templist "i"
166    #lappend templist "output.number(sum).current"
167    #lappend templist "k"
168    #.k entry configure $id -data $templist
169    #.k entry configure $id \
170    #    -data [list input.number(n1).current "h" input.number(n2).current "i" output.number(sum).current "k"]
171}
172
173proc newtable {appname} {
174    global tree1
175
176    set tree1 [tree create]
177    treeview .h \
178        -width 0 \
179        -yscrollcommand { .vvs set } \
180        -xscrollcommand { .hhs set } \
181        -selectmode single \
182        -tree $tree1
183    .h column configure treeView -text ""
184    .h column configure treeView -hide yes -edit no \
185        -icon blt::tv::normalOpenFolder
186    focus .h
187    scrollbar .vvs -orient vertical -command { .h yview }
188    scrollbar .hhs -orient horizontal -command { .h xview }
189
190    .h style checkbox mycheck -onvalue "yes" -offvalue "no" -showvalue yes
191    .h column insert end select -text "Select" -edit yes -style mycheck
192
193    table . \
194        0,0 .h  -fill both \
195        0,1 .vvs -fill y \
196        1,0 .hhs -fill x
197    table configure . c1 r1 -resize none
198
199    # Starting tk code
200    .h column insert end "tname" -text "Tool Name"
201    .h column insert end "date"  -text "Date"
202    global env
203    set files [fileutil::find $env(HOME)/data/results is_xml]
204    if {$files == ""} {
205    } else {
206        foreach line $files {
207            set fileone [open $line]
208            set content [read $fileone]
209            close $fileone
210            regexp {<title>(.*)</title>} $content junk title
211            if {![info exists title]} {
212                continue
213            }
214            set title [string trim $title]
215            set time ""
216            regexp {<time>(.*)</time>} $content junk time
217            set time [string trim $time]
218            #if {($params(-title) == "") || ($params(-title) == $title)} {
219            #    set id [.t insert end $line]
220            #    .t entry configure $id -data [list tname $title date $time]
221            #}
222            #
223            #set id [.h insert end $line]
224            if { $appname == $title } {
225                set id [.h insert end $line]
226                .h entry configure $id \
227                    -data [list tname $title date $time select yes]
228            }
229            unset fileone
230            unset content
231            unset title
232            unset time
233            if {[info exists junk]} { unset junk }
234            unset line
235        }
236    }
237    .h bind all <ButtonRelease-1> {
238    }
239
240    button .compare -text "Compare" -command compare
241    blt::table .  \
242        2,0 .compare -anchor e -columnspan 2
243
244    proc compare {} {
245        global tree1
246        # declaring lists
247        set filename [list]
248
249        foreach node [$tree1 children root] {
250            set label [$tree1 label $node]
251            set select [$tree1 get $node "select"]
252            set tname [$tree1 get $node "tname"]
253            puts stderr "found at node $node: select=$select tname=$tname"
254            if { $select == "yes" } {
255                puts $label
256                lappend filename $label
257            }
258        }
259        set cmpfileslen [llength $filename]
260        resulttable $filename
261    }
262    #foreach column [.h column names] {
263    #    .h column configure $column -command [list SortColumn $column]
264    #}
265}
266
267proc startupcode {} {
268    set tree [tree create]
269    treeview .t \
270        -width 0 \
271        -yscrollcommand { .vs set } \
272        -xscrollcommand { .hs set } \
273        -selectmode single \
274        -tree $tree
275    .t column configure treeView -text ""
276    .t column configure treeView -hide yes -edit no \
277        -icon blt::tv::normalOpenFolder
278    focus .t
279    scrollbar .vs -orient vertical -command { .t yview }
280    scrollbar .hs -orient horizontal -command { .t xview }
281    table . \
282        0,0 .t -fill both \
283        0,1 .vs -fill y \
284        1,0 .hs -fill x
285    table configure . c1 r1 -resize none
286    .t column insert end "appname" -text "Application Name"
287    .t column insert end "xmlfilename" -text "File Name"
288    global env
289    set files [fileutil::find $env(HOME)/data/results is_xml]
290    set appnamelist [list]
291    if {$files == ""} {
292    } else {
293        foreach line $files {
294            set existed false
295            set fileone [open $line]
296            set content [read $fileone]
297            close $fileone
298            regexp {<title>(.*)</title>} $content junk title
299            if {![info exists title]} {
300                puts stderr "ERROR: No title found in $line"
301                continue
302            }
303            set title [string trim $title]
304            #puts "found title: $title"
305
306            foreach app $appnamelist {
307                if {$title == $app} {
308                    set existed true
309                    break
310                }
311            }
312            if { ! $existed } {
313                set temp [file tail $line]
314                set id [.t insert end $line]
315                .t entry configure $id \
316                    -data [list appname $title xmlfilename $temp]
317                lappend appnamelist $title
318            }
319            unset existed
320            unset fileone
321            unset content
322            unset title
323            unset line
324        }
325        #puts $appnamelist
326    }
327
328    .t bind all <ButtonRelease-1> {
329        set ids [.t curselection]
330        set name [eval .t get -full $ids]
331        set fileone [open $name]
332        set content [read $fileone]
333        close $fileone
334        regexp {<title>(.*)</title>} $content junk title
335        set title [string trim $title]
336        # pass title and display the result in new page
337        newtable $title
338    }
339}
340
341startupcode
342
343#blt::treeview .t
344#set node [.t insert end root "one"]
345#treeview .h -bg white
346#.h configure -background "green"
347#set id [.h insert end "myEntry"]
Note: See TracBrowser for help on using the repository browser.