Move the sources to trunk
[opencv] / apps / cvenv / cvenv.tcl
1 #########################################################################################
2 #
3 #  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4 #
5 #  By downloading, copying, installing or using the software you agree to this license.
6 #  If you do not agree to this license, do not download, install,
7 #  copy or use the software.
8 #
9 #
10 #                        Intel License Agreement
11 #                For Open Source Computer Vision Library
12 #
13 # Copyright (C) 2000, Intel Corporation, all rights reserved.
14 # Third party copyrights are property of their respective owners.
15 #
16 # Redistribution and use in source and binary forms, with or without modification,
17 # are permitted provided that the following conditions are met:
18 #
19 #   * Redistribution's of source code must retain the above copyright notice,
20 #     this list of conditions and the following disclaimer.
21 #
22 #   * Redistribution's in binary form must reproduce the above copyright notice,
23 #     this list of conditions and the following disclaimer in the documentation
24 #     and/or other materials provided with the distribution.
25 #
26 #   * The name of Intel Corporation may not be used to endorse or promote products
27 #     derived from this software without specific prior written permission.
28 #
29 # This software is provided by the copyright holders and contributors "as is" and
30 # any express or implied warranties, including, but not limited to, the implied
31 # warranties of merchantability and fitness for a particular purpose are disclaimed.
32 # In no event shall the Intel Corporation or contributors be liable for any direct,
33 # indirect, incidental, special, exemplary, or consequential damages
34 # (including, but not limited to, procurement of substitute goods or services;
35 # loss of use, data, or profits; or business interruption) however caused
36 # and on any theory of liability, whether in contract, strict liability,
37 # or tort (including negligence or otherwise) arising in any way out of
38 # the use of this software, even if advised of the possibility of such damage.
39 #
40 #
41
42 #set image_path "./"
43
44 if {$tcl_platform(platform) == "windows"} {
45     set default_normal_bg SystemButtonFace
46     set default_normal_fg SystemButtonText
47     set default_light_bg SystemScrollbar
48     set default_dark_bg SystemDisabledText
49     set default_window_bg SystemWindow
50     set default_window_fg SystemWindowText
51     set default_select_bg SystemHighlight
52     set default_select_fg SystemHighlightText
53 } else {
54     set default_normal_bg #909090
55     set default_normal_fg #000000
56     set default_light_bg #000000
57     set default_dark_bg #303030
58     set default_window_bg #909090
59     set default_window_fg #000000
60     set default_select_bg #000080
61     set default_select_fg #ffffff
62 }
63
64 set defaults {default_normal_bg default_normal_fg default_light_bg default_dark_bg\
65                        default_window_bg default_window_fg default_select_bg default_select_fg}
66
67 # Default Colors
68 set EditorTextbg $default_window_bg
69 set EditorTextfg $default_window_fg
70 set EditorStringfg #00FF00
71 set EditorNumberfg #00FFFF
72 set EditorCommentfg #808080
73 set EditorKeywordfg #FFFF00
74 set EditorSelectbg $default_select_bg
75 set EditorSelectfg $default_select_fg
76 set EditorCursorbg $default_light_bg
77
78 # Default Fonts
79 set EditorTextfont    "{Courier} 12 normal roman"
80 set EditorStringfont  "{Courier} 12 normal roman"
81 set EditorNumberfont  "{Courier} 12 normal roman"
82 set EditorCommentfont "{Courier} 12 normal italic"
83 set EditorKeywordfont "{Courier} 12 normal roman"
84
85 pLoadColors
86
87 proc ClearColors {offset1 offset2 fedit} {
88         foreach i [$fedit tag names] {
89         #if {$i!="select"} then {
90                 $fedit tag remove $i "0.0 + $offset1 chars" "0.0 + $offset2 chars"
91         #       }
92         }
93 }
94
95 namespace eval CVEnv {
96         variable mainf
97         variable tb
98         variable statustext
99     variable inputvar ""
100     variable inputdata ""
101     variable inputlist {}
102
103         variable pw
104         variable ptop
105         variable pbot
106         variable pwch
107         variable prig
108         variable nblef
109         variable nbrig
110         variable nbbot
111         variable outtx
112     variable parsetx
113         variable tree
114     variable inputcb
115
116         variable showtb 1
117         variable showstb 1
118         variable showlp 1
119         variable showbp 1
120
121     variable savebefore 1
122     variable clearoutputbefore 1
123     variable clearerrorbefore 1
124
125         variable curfile
126     variable curpage
127     variable curframe
128         variable curln "--"
129         variable curcol "--"
130     variable curinput 0
131
132     variable pagesnum 0
133     variable pagescount 0
134     
135     variable files {}
136     variable pages {}
137 }
138
139 proc CVEnv::leftpane {on} {
140         if {$on} {
141         pack forget $CVEnv::nbrig
142         
143         pack $CVEnv::nbrig -in $CVEnv::prig -fill both -expand yes -padx 1 -pady 1
144         pack $CVEnv::pwch -fill both -expand yes
145         } else {
146                 pack forget $CVEnv::nbrig
147                 pack forget $CVEnv::pwch
148
149                 pack $CVEnv::nbrig -in $CVEnv::ptop -fill both -expand yes -padx 1 -pady 1
150         }
151 }
152
153 proc CVEnv::longmenu {on} {
154         if {$on} {
155                 .menubar.file entryconfig 2 -state active
156                 .menubar.file entryconfig 4 -state active
157                 .menubar.file entryconfig 5 -state active
158
159                 .menubar insert 1 cascade -label "Edit" -menu .menubar.edit\
160                         -underline 0
161         } else {
162                 .menubar.file entryconfig 2 -state disabled
163                 .menubar.file entryconfig 4 -state disabled
164                 .menubar.file entryconfig 5 -state disabled
165             
166                 .menubar delete 1 1
167         }
168 }
169
170 proc CVEnv::longstbar {on} {
171         if {$on} {
172                 pack $CVEnv::mainf.status.indf.f0 -side left -fill y -expand 1          
173         } else {
174                 pack forget $CVEnv::mainf.status.indf.f0                
175         }
176 }
177
178 proc CVEnv::longbar {on} {
179         if {$on} {
180                 pack $CVEnv::tb.bbox1 -side left -anchor w
181                 pack $CVEnv::tb.sep1 -side left -fill y -padx 4 -anchor w
182                 pack $CVEnv::tb.bbox2 -side left -anchor w
183                 pack $CVEnv::tb.sep2 -side left -fill y -padx 4 -anchor w
184                 pack $CVEnv::tb.bbox3 -side left -anchor w
185                 pack $CVEnv::tb.sep3 -side left -fill y -padx 4 -anchor w
186         } else {
187                 pack forget $CVEnv::tb.sep3
188                 pack forget $CVEnv::tb.bbox3
189                 pack forget $CVEnv::tb.sep2
190                 pack forget $CVEnv::tb.bbox2
191                 pack forget $CVEnv::tb.sep1
192                 pack forget $CVEnv::tb.bbox1
193         }
194 }
195
196 proc CVEnv::about {} {
197     set dlg [Dialog .aboutdlg -parent . -modal local \
198                  -separator 1           \
199                  -title   "About CVEnv" \
200                  -side    right         \
201                  -anchor  s                     \
202                  -default 0]
203     $dlg add -name ok -width 5
204     
205         set top [$dlg getframe]
206             
207         image create photo original -file [file join $::image_path pictures/CVEnv.gif]
208         canvas $top.c -bd 2 -relief ridge -width 295 -height 195 
209         $top.c create image 0 0 -anchor nw -image original
210         pack $top.c -side top -expand yes -fill x
211
212     set frame [frame $top.f -background white -bd 2 -relief ridge]
213     set lab  [label $frame.lab1 -text \
214                 "Program CVEnv v. 1.0 \nIntel corporation. 2000-2001 y."        \
215                            -background white -font {times 8}]
216     pack $lab
217     pack $frame -side top -expand yes -fill x -padx 2 -pady 2
218
219     $dlg draw
220     destroy $dlg
221 }
222
223 proc CVEnv::modify_font {lbtypes lbcolors samf font} {
224     global EditorTextfont
225     global EditorStringfont
226     global EditorNumberfont
227     global EditorCommentfont
228     global EditorKeywordfont
229     
230     set curtype  [$lbtypes get [$lbtypes curselection]]
231     set curcolor [$lbcolors get [$lbcolors curselection]]
232
233     set name font
234     set name $curtype$curcolor$name
235     set $name $font
236
237     $samf.label configure -font $font
238 }
239
240 proc CVEnv::modify_fg {lbtypes lbcolors samf cbfgf cbbgf color} {
241     global EditorTextfg
242     global EditorStringfg
243     global EditorNumberfg
244     global EditorCommentfg
245     global EditorKeywordfg
246     global EditorSelectfg
247
248     set curtype  [$lbtypes get [$lbtypes curselection]]
249     set curcolor [$lbcolors get [$lbcolors curselection]]
250
251     set name fg
252     set name $curtype$curcolor$name
253     set $name $color
254
255     $samf.label configure -fg $color
256     $cbfgf configure -entrybg $color -selectbackground $color -text ""
257 }
258
259 proc CVEnv::modify_bg {lbtypes lbcolors samf cbfgf cbbgf color} {
260     global EditorTextbg
261     global EditorSelectbg
262     global EditorCursorbg
263
264     set curtype  [$lbtypes get [$lbtypes curselection]]
265     set curcolor [$lbcolors get [$lbcolors curselection]]
266
267     set name bg
268     set name $curtype$curcolor$name
269     set $name $color
270
271     $samf.label configure -bg $color
272     $samf configure -bg $color
273     $cbbgf configure -entrybg $color -selectbackground $color -text ""
274 }
275
276 proc getvar {name value} {
277     upvar $name localVar
278     upvar $value lvalue
279         
280     set localVar $lvalue
281 }
282
283 proc CVEnv::default_bg {lbtypes lbcolors samf cbfgf cbbgf} {
284     global defaults
285     global default_normal_bg
286     global default_normal_fg
287     global default_light_bg
288     global default_dark_bg
289     global default_window_bg
290     global default_window_fg
291     global default_select_bg
292     global default_select_fg
293
294     set index [$cbbgf getvalue]
295     set name [lindex $defaults $index]
296     set color ""
297
298     ::getvar color $name
299
300     if [string compare $color ""] {
301             CVEnv::modify_bg $lbtypes $lbcolors $samf $cbfgf $cbbgf $color
302     }
303 }
304
305 proc CVEnv::default_fg {lbtypes lbcolors samf cbfgf cbbgf} {
306     global defaults
307     global default_normal_bg
308     global default_normal_fg
309     global default_light_bg
310     global default_dark_bg
311     global default_window_bg
312     global default_window_fg
313     global default_select_bg
314     global default_select_fg
315
316     set index [$cbfgf getvalue]
317     set name [lindex $defaults $index]
318     set color ""
319
320     ::getvar color $name
321
322     if [string compare $color ""] {
323             CVEnv::modify_fg $lbtypes $lbcolors $samf $cbfgf $cbbgf $color
324     }
325 }
326
327 proc CVEnv::getconf {lbtypes lbcolors samf cbfgf cbbgf} {
328     global EditorTextbg
329     global EditorTextfg
330     global EditorStringfg
331     global EditorNumberfg
332     global EditorCommentfg
333     global EditorKeywordfg
334     global EditorSelectbg
335     global EditorSelectfg
336     global EditorCursorbg
337     global EditorTextfont
338     global EditorStringfont
339     global EditorNumberfont
340     global EditorCommentfont
341     global EditorKeywordfont
342     
343     set curtype  [$lbtypes get [$lbtypes curselection]]
344     set curcolor [$lbcolors get [$lbcolors curselection]]
345
346     if {([string compare $curcolor "Text"]) && ([string compare $curcolor "Select"])} {
347         if {([string compare $curcolor "Cursor"])} {
348
349             $cbbgf configure -state disabled
350             $cbfgf configure -state normal
351
352             set name fg
353             set name $curtype$curcolor$name
354             set tmp ""
355             ::getvar tmp $name
356             if [string compare $tmp ""] {
357                     CVEnv::modify_fg $lbtypes $lbcolors $samf $cbfgf $cbbgf $tmp
358             }
359
360             CVEnv::modify_bg $lbtypes $lbcolors $samf $cbfgf $cbbgf $EditorTextbg
361
362             set name font
363             set name $curtype$curcolor$name
364             set tmp ""
365             ::getvar tmp $name
366
367             CVEnv::modify_font $lbtypes $lbcolors $samf $tmp
368
369         } else {
370
371             $cbfgf configure -state disabled
372             $cbbgf configure -state normal
373
374             set name bg
375             set name $curtype$curcolor$name
376             set tmp ""
377             ::getvar tmp $name
378             if [string compare $tmp ""] {
379                 CVEnv::modify_bg $lbtypes $lbcolors $samf $cbfgf $cbbgf $tmp
380             }
381
382             CVEnv::modify_fg $lbtypes $lbcolors $samf $cbfgf $cbbgf $EditorTextfg
383             CVEnv::modify_font $lbtypes $lbcolors $samf $EditorTextfont
384         }
385         
386     } else {
387
388         $cbbgf configure -state normal
389         $cbfgf configure -state normal
390
391         set name bg
392         set name $curtype$curcolor$name
393         set tmp ""
394         ::getvar tmp $name
395         if [string compare $tmp ""] {
396             CVEnv::modify_bg $lbtypes $lbcolors $samf $cbfgf $cbbgf $tmp
397         }
398    
399         set name fg
400         set name $curtype$curcolor$name
401         set tmp ""
402         ::getvar tmp $name
403         if [string compare $tmp ""] {
404                 CVEnv::modify_fg $lbtypes $lbcolors $samf $cbfgf $cbbgf $tmp
405         }
406
407         if {([string compare $curcolor "Select"])} {
408             set name font
409             set name $curtype$curcolor$name
410             set tmp ""
411             ::getvar tmp $name
412
413             CVEnv::modify_font $lbtypes $lbcolors $samf $tmp
414         } else {
415             CVEnv::modify_font $lbtypes $lbcolors $samf $EditorTextfont
416         }
417     }
418 }
419
420 proc CVEnv::custom_bg {lbtypes lbcolors samf cbfgf cbbgf} {
421
422     #set initialColor [$button cget -$name]
423
424     set color [tk_chooseColor -title "Choose a color" -parent .colordlg \
425         -initialcolor blue]
426     if [string compare $color ""] {
427             CVEnv::modify_bg $lbtypes $lbcolors $samf $cbfgf $cbbgf $color
428     }
429
430 }
431
432 proc CVEnv::custom_fg {lbtypes lbcolors samf cbfgf cbbgf} {
433     
434     #set initialColor [$button cget -$name]
435
436     set color [tk_chooseColor -title "Choose a color" -parent .colordlg \
437         -initialcolor blue]
438     if [string compare $color ""] {
439             CVEnv::modify_fg $lbtypes $lbcolors $samf $cbfgf $cbbgf $color
440     }
441
442 }
443
444 proc CVEnv::colordialog {} {
445     set dlg [Dialog .colordlg -parent . -modal local \
446                  -separator 1           \
447                  -title   "Colors configuration"        \
448                  -side    bottom                \
449                  -anchor  c                     \
450                  -default 2]
451     #$dlg add -name reset -width 7 -text Reset
452     $dlg add -name ok -width 7
453     $dlg add -name cancel -width 7
454     
455         set top [$dlg getframe]
456             
457         set frame [frame $top.flef ]
458         set titlebox  [TitleFrame $top.flef.titlebox -font {times 8} \
459                         -side left -text Types]
460             set f [$titlebox getframe]
461             set sw [ScrolledWindow $f.sw -auto both]
462                 set lbtypes [listbox $sw.lbtypes -width 21 -height 6 -exportselection no]
463                 $lbtypes insert end "Editor"
464                 $lbtypes selection set 0
465
466                 $sw setwidget $sw.lbtypes
467                 pack $sw.lbtypes -fill both -expand yes 
468                 pack $sw  -side top  -expand yes -fill both
469         pack $titlebox -side top
470
471         set framebox  [TitleFrame $frame.framebox -font {times 8} \
472                         -side left -text Sample]
473             set f [$framebox getframe]
474
475                 set samf [frame $f.samf -width 148 -height 56 \
476                       -bg white -bd 0 -relief flat \
477                       -highlightthickness 1 -takefocus 0 \
478                       -highlightbackground black \
479                       -highlightcolor black]
480
481                     set lab  [label $samf.label \
482                       -background white -foreground black \
483                       -borderwidth 0 -takefocus 0 -highlightthickness 0 \
484                       -text "Sample text"]
485                     place $lab -relx 0.5 -rely 0.5 -anchor c
486                 pack $samf -pady 4 -fill x
487             
488         pack $framebox -side top
489     pack $frame -side left -expand yes -fill x -padx 2 -pady 2
490
491     
492     set frame [frame $top.frig]
493         set tf [TitleFrame $top.frig.f -font {times 8} \
494                         -side left -text Font]
495             set f [$tf getframe]
496
497             #set _wfont [SelectFont $f.font -type toolbar]
498             set _wfont [SelectFont $f.font -type toolbar -command ""]
499                     
500             pack $_wfont -side left -anchor w
501
502         pack $tf -side top -fill x -expand yes
503         
504         set titlebox  [TitleFrame $top.frig.titlebox -font {times 8} \
505                         -side left -text Colors]
506             set f [$titlebox getframe]
507             set sw [ScrolledWindow $f.sw -auto both]
508                 set lbcolors [listbox $sw.lbcolors -width 41 -height 6 -exportselection no]
509
510                 $lbcolors insert end Text
511                 $lbcolors insert end String
512                     $lbcolors insert end Number
513                     $lbcolors insert end Comment
514                 $lbcolors insert end Keyword
515                     $lbcolors insert end Select
516                 $lbcolors insert end Cursor
517                 $lbcolors selection set 0
518
519                 $sw setwidget $sw.lbcolors
520                 pack $sw.lbcolors -fill both -expand yes 
521                 pack $sw  -side top  -expand yes -fill both
522
523             set lef [frame $f.flef -bd 2 -relief ridge]
524                 set fontlab [label $lef.fontlab -text Foreground -font {times 8}]
525                 pack $fontlab -side top -anchor nw
526                 set fontcb [ComboBox $lef.fontcb -width 19 -editable no \
527                 -values {default_normal_bg default_normal_fg default_light_bg default_dark_bg\
528                          default_window_bg default_window_fg default_select_bg default_select_fg}]
529                 
530                 pack $fontcb -side top
531                 pack $lef -side left -fill x -expand yes
532             set rig [frame $f.frig -bd 2 -relief ridge]
533                 set sizelab [label $rig.sizelab -text Background -font {times 8}]
534                 pack $sizelab -side top -anchor nw
535                 set sizecb [ComboBox $rig.fontcb -width 19 -editable no\
536                 -values {default_normal_bg default_normal_fg default_light_bg default_dark_bg\
537                          default_window_bg default_window_fg default_select_bg default_select_fg}]
538
539                 $fontcb configure -modifycmd "CVEnv::default_fg $lbtypes $lbcolors $samf $fontcb $sizecb"
540                 $fontcb bind <ButtonRelease-3> "CVEnv::custom_fg $lbtypes $lbcolors $samf $fontcb $sizecb"
541                 $fontcb bind <ButtonRelease-2> "CVEnv::custom_fg $lbtypes $lbcolors $samf $fontcb $sizecb"
542                 
543                 $sizecb configure -modifycmd "CVEnv::default_bg $lbtypes $lbcolors $samf $fontcb $sizecb"
544                 $sizecb bind <ButtonRelease-3> "CVEnv::custom_bg $lbtypes $lbcolors $samf $fontcb $sizecb"
545                 $sizecb bind <ButtonRelease-2> "CVEnv::custom_bg $lbtypes $lbcolors $samf $fontcb $sizecb"
546
547                 bind $lbcolors <<ListboxSelect>> "CVEnv::getconf $lbtypes $lbcolors $samf $fontcb $sizecb"
548                 CVEnv::getconf $lbtypes $lbcolors $samf $fontcb $sizecb
549                 pack $sizecb -side top
550             pack $rig -side right -fill x -expand yes
551         pack $titlebox -side top
552
553         $_wfont configure -command "CVEnv::modify_font $lbtypes $lbcolors $samf \[$_wfont cget -font\]"
554     pack $frame -side left -expand yes -fill x -padx 2 -pady 2
555
556     set ret [$dlg draw]
557     if {$ret == "1"} {
558         pLoadColors
559     } else {
560         pSaveColors
561
562         for {set i 1} {$i <= $CVEnv::pagesnum} {incr i} {
563             set frame [$CVEnv::nbrig getframe p$i].sw.tx
564
565             $frame configure -wrap none  -font $::EditorTextfont\
566                 -bg $::EditorTextbg -selectbackground $::EditorSelectbg \
567                     -fg $::EditorTextfg -selectforeground $::EditorSelectfg \
568                     -insertbackground $::EditorCursorbg
569
570             $frame tag configure text    -font $::EditorTextfont    -foreground $::EditorTextfg
571             $frame tag configure string  -font $::EditorStringfont  -foreground $::EditorStringfg
572             $frame tag configure number  -font $::EditorNumberfont  -foreground $::EditorNumberfg
573                 $frame tag configure comment -font $::EditorCommentfont -foreground $::EditorCommentfg
574                 $frame tag configure keyword -font $::EditorKeywordfont -foreground $::EditorKeywordfg
575         }
576
577     }
578     destroy $dlg
579 }
580
581 proc CVEnv::confdialog {} {
582     set dlg [Dialog .confdlg -parent . -modal local \
583                  -separator 1           \
584                  -title   "Configuration"       \
585                  -side    bottom                \
586                  -anchor  c                     \
587                  -default 2]
588     $dlg add -name ok -width 7
589     $dlg add -name cancel -width 7
590     
591         set top [$dlg getframe]
592             
593         set frame [frame $top.flef ]
594         set titlebox  [TitleFrame $top.flef.titlebox \
595                         -side left -text "Before execute options"]
596             set f [$titlebox getframe]
597             set chk1 [checkbutton $f.chk1 -text "Save text" \
598                  -variable CVEnv::savebefore]
599             pack $chk1 -side top -anchor nw
600
601             set chk2 [checkbutton $f.chk2 -text "Clear output page" \
602                  -variable CVEnv::clearoutputbefore]
603             pack $chk2 -side top -anchor nw
604
605             set chk3 [checkbutton $f.chk3 -text "Clear error page" \
606                  -variable CVEnv::clearerrorbefore]
607             pack $chk3 -side top -anchor nw
608
609         pack $titlebox -side top
610     pack $frame -side left -expand yes -fill x -padx 2 -pady 2
611
612     
613     set frame [frame $top.frig]
614     pack $frame -side left -expand yes -fill x -padx 2 -pady 2
615
616     set ret [$dlg draw]
617     
618     destroy $dlg
619 }
620
621 proc CVEnv::raiseeditor { } {
622     set CVEnv::curpage [$CVEnv::nbrig raise]
623     set CVEnv::curframe [$CVEnv::nbrig getframe $CVEnv::curpage].sw.tx
624     set pos [lsearch $CVEnv::pages $CVEnv::curpage]
625     set CVEnv::curfile [lindex $CVEnv::files $pos]   
626 }
627
628 proc CVEnv::createeditor {page text} {
629         global EditorTextbg
630     global EditorTextfg
631     global EditorStringfg
632     global EditorNumberfg
633     global EditorCommentfg
634     global EditorKeywordfg
635     global EditorSelectbg
636     global EditorSelectfg
637     global EditorCursorbg
638
639     global EditorTextfont
640     global EditorStringfont
641     global EditorNumberfont
642     global EditorCommentfont
643     global EditorKeywordfont
644     
645     set path [$CVEnv::nbrig insert end $page -text $text \
646                 -leavecmd { set CVEnv::curln "--"
647                                     set CVEnv::curcol "--"} \
648                 -raisecmd CVEnv::raiseeditor]
649     set sw [ScrolledWindow $path.sw -auto none]
650     
651     set CVEnv::curframe [text $sw.tx -wrap none  -font $EditorTextfont\
652     -bg $EditorTextbg -selectbackground $EditorSelectbg \
653         -fg $EditorTextfg -selectforeground $EditorSelectfg \
654         -insertbackground $EditorCursorbg]
655
656     $sw setwidget $sw.tx
657         pack $sw.tx -fill both -expand yes 
658         pack $sw  -side top  -expand yes -fill both
659     
660         $CVEnv::curframe tag configure text    -font $EditorTextfont    -foreground $EditorTextfg
661     $CVEnv::curframe tag configure string  -font $EditorStringfont  -foreground $EditorStringfg
662     $CVEnv::curframe tag configure number  -font $EditorNumberfont  -foreground $EditorNumberfg
663         $CVEnv::curframe tag configure comment -font $EditorCommentfont -foreground $EditorCommentfg
664         $CVEnv::curframe tag configure keyword -font $EditorKeywordfont -foreground $EditorKeywordfg
665         
666         $CVEnv::curframe tag add normal 0.0 end
667         $CVEnv::curframe index 0.0
668
669         #-----------------------------------------------------------
670     bind $CVEnv::curframe <KeyPress> {
671             pParsebegin
672     }
673
674         bind $CVEnv::curframe <KeyRelease> {
675                 pParseend
676         #set frame [$CVEnv::nbrig getframe $CVEnv::curpage]
677         set curindex [$CVEnv::curframe index insert]
678         set coordlist [split $curindex .]
679                 set CVEnv::curln [lindex $coordlist  0]
680                 set CVEnv::curcol [lindex $coordlist  1]
681         incr CVEnv::curcol
682         }
683
684         bind $CVEnv::curframe <ButtonRelease-1> {
685         #set frame [$CVEnv::nbrig getframe $CVEnv::curpage]
686                 set curindex [$CVEnv::curframe index insert]
687                 set coordlist [split $curindex .]
688                 set CVEnv::curln [lindex $coordlist  0]
689                 set CVEnv::curcol [lindex $coordlist  1]
690         $CVEnv::nbrig see $CVEnv::curpage
691             
692                 incr CVEnv::curcol
693         update
694         }
695
696         bind $CVEnv::curframe <FocusOut> {
697         set CVEnv::curln "--"
698                 set CVEnv::curcol "--"
699         }
700
701     bind $CVEnv::curframe <F5> CVEnv::execute
702
703         #-----------------------------------------------------------
704 }
705
706 proc CVEnv::new {} {
707     
708     incr CVEnv::pagescount
709     incr CVEnv::pagesnum
710
711     set CVEnv::curpage p[expr $CVEnv::pagescount]
712     set CVEnv::curfile ""
713     lappend CVEnv::pages $CVEnv::curpage
714     lappend CVEnv::files $CVEnv::curfile
715
716     set text [format "/* %u */" $CVEnv::pagescount]
717     CVEnv::createeditor $CVEnv::curpage $text
718     
719     if {$CVEnv::pagesnum == 1} {
720         CVEnv::longmenu 1
721         CVEnv::longbar 1
722         CVEnv::longstbar 1
723     }
724
725     $CVEnv::nbrig see [$CVEnv::nbrig pages end]
726     $CVEnv::nbrig raise [$CVEnv::nbrig pages end]
727 }
728
729 proc CVEnv::loadfile {name frame} {
730         set file [::open $name r]
731     pParsebegin
732
733     $frame insert 0.0 [read $file]
734     ::close $file
735     $frame index 0.0
736
737     pParseend
738 }
739
740 proc CVEnv::open {parent} {
741         set types {
742                 {"C files"      {.c .h}         }
743                 {"Text files"           {.txt}  }
744                 {"All files"            *}
745     }
746     
747     set file [tk_getOpenFile -filetypes $types -parent $parent]
748     if [string compare $file ""] {
749
750         if [$CVEnv::tree exists $file] {
751             #set page [$CVEnv::tree itemcget $file -data]
752                         set pos [lsearch $CVEnv::files $file]
753                         set page [lindex $CVEnv::pages $pos]
754                         $CVEnv::nbrig see $page
755             $CVEnv::nbrig raise $page
756         } else {
757             incr CVEnv::pagescount
758             incr CVEnv::pagesnum
759                     
760             set CVEnv::curfile $file
761             set text [lindex [split $file /] end]
762                     set CVEnv::curpage p[expr $CVEnv::pagescount]
763                         lappend CVEnv::files $CVEnv::curfile
764                         lappend CVEnv::pages $CVEnv::curpage
765         
766                         CVEnv::createeditor $CVEnv::curpage $text
767             
768                         CVEnv::loadfile $file $CVEnv::curframe
769
770                         if {$CVEnv::pagesnum == 1} {
771                                 CVEnv::longmenu 1
772                                 CVEnv::longbar 1
773                                 CVEnv::longstbar 1
774                         }
775
776                         $CVEnv::tree insert end files $file -text $file \
777                 -image [image create photo -file [file join $::image_path pictures/file.gif]]
778
779                         $CVEnv::nbrig see [$CVEnv::nbrig pages end]
780                         $CVEnv::nbrig raise [$CVEnv::nbrig pages end]
781                 }
782         }
783 }
784
785 proc CVEnv::save {} {
786     if {$CVEnv::curfile != ""} {
787         #set frame [ $CVEnv::nbrig getframe $CVEnv::curpage]
788         CVEnv::writefile $CVEnv::curfile $CVEnv::curframe
789     } else {
790         CVEnv::saveas .
791     }
792 }
793
794 proc CVEnv::writefile {name frame} {
795         set file [::open $name w]
796         set tx [$frame get 1.0 "end-1 chars"]
797         puts $file $tx
798     flush $file
799     ::close $file
800 }
801
802 proc CVEnv::saveas {parent} {
803         set types {
804                 {"C source files"       {.c}            }
805         {"C header files"       {.h}            }
806                 {"Text files"           {.txt}  }
807         {"All files"            *}
808     }
809
810     set file [tk_getSaveFile -filetypes $types -parent $parent \
811                 -initialfile Untitled -defaultextension ""]
812     if [string compare $file ""] {
813                 
814                 if [$CVEnv::tree exists $file] {
815             #set page [$CVEnv::tree itemcget $file -data]
816                         set pos [lsearch $CVEnv::files $file]
817                         set page [lindex $CVEnv::pages $pos]
818                         $CVEnv::nbrig see $page
819             $CVEnv::nbrig raise $page
820         } else {
821
822                 set pos [lsearch $CVEnv::files $CVEnv::curfile]
823         set CVEnv::files [lreplace $CVEnv::files $pos $pos $file]
824                 
825                 set text [lindex [split $file /] end]                    
826         $CVEnv::nbrig itemconfigure $CVEnv::curpage -text $text
827                 #set frame [ $CVEnv::nbrig getframe $CVEnv::curpage]
828         CVEnv::writefile $file $CVEnv::curframe
829
830                 if {$CVEnv::curfile != ""} {
831                         set ind [$CVEnv::tree index $CVEnv::curfile]
832                         $CVEnv::tree delete $CVEnv::curfile
833                         $CVEnv::tree insert $ind files $file -text $file \
834                 -image [image create photo -file [file join $::image_path pictures/file.gif]]
835                 } else {
836                         $CVEnv::tree insert end files $file -text $file \
837                 -image [image create photo -file [file join $::image_path pictures/file.gif]]
838                 }
839         
840         set CVEnv::curfile $file
841                 }
842     }
843 }
844
845 proc CVEnv::close {} {
846
847         set pos [lsearch $CVEnv::files $CVEnv::curfile]
848         set $CVEnv::files [lreplace $CVEnv::files $pos $pos]
849         set $CVEnv::pages [lreplace $CVEnv::pages $pos $pos]
850
851         $CVEnv::nbrig delete $CVEnv::curpage 1
852
853         if {$CVEnv::curfile != ""} {
854                 set ind [$CVEnv::tree index $CVEnv::curfile]
855                 $CVEnv::tree delete $CVEnv::curfile
856         }
857
858     set CVEnv::pagesnum [expr $CVEnv::pagesnum - 1]
859
860         if {$CVEnv::pagesnum == 0} {
861                 CVEnv::longmenu 0
862                 CVEnv::longbar 0
863                 #CVEnv::longstbar 0
864                 set CVEnv::curfile ""
865         } else {
866                 set page [$CVEnv::nbrig pages end]
867
868                 set pos [lsearch $CVEnv::pages $CVEnv::curpage]
869                 set CVEnv::curfile [lindex $CVEnv::files $pos]
870                         
871                 $CVEnv::nbrig see $page
872         $CVEnv::nbrig raise $page
873     }
874 }
875
876 proc CVEnv::execute {} {
877
878     if {$CVEnv::savebefore == "1"} {
879         CVEnv::save
880     } else {
881         if {$CVEnv::curfile == ""} {
882             CVEnv::saveas .
883         }    
884     }
885
886     if {$CVEnv::clearoutputbefore == "1"} {
887         $CVEnv::outtx delete 0.0 end
888     }
889
890     if {$CVEnv::clearerrorbefore == "1"} {
891         $CVEnv::parsetx delete 0.0 end
892     }
893
894     pExecute $CVEnv::curfile
895 }
896
897 proc CVEnv::create { } {
898         variable prgindic 0
899         variable prgtext
900         ## Create intro
901     ###################################################################
902     set top [toplevel .intro -relief raised -borderwidth 2]
903     wm withdraw $top
904     wm overrideredirect $top 1
905         
906         image create photo original -file [file join $::image_path pictures/CVEnv.gif]
907         canvas $top.c -bd 2 -relief ridge -width 295 -height 195 
908         $top.c create image 0 0 -anchor nw -image original
909         pack $top.c -side top -expand yes -fill x
910
911     set frame [frame $top.f -background white -bd 2 -relief ridge]
912     set lab1  [label $frame.lab1 -text "Please wait for loading..."     \
913                            -background white -font {times 8}]
914     set lab2  [label $frame.lab2 -textvariable CVEnv::prgtext   \
915                            -background white -font {times 8} -width 35]
916     set prg   [ProgressBar $frame.prg -width 50 -height 10              \
917                            -background white -variable CVEnv::prgindic -maximum 7]
918     pack $lab1 $prg $lab2
919     pack $frame -side top -expand yes -fill x -padx 2 -pady 2
920
921     BWidget::place $top 0 0 center
922     wm deiconify $top
923
924         ###################################################################
925         
926         set CVEnv::prgtext "Loading font..."
927         update
928         SelectFont::loadfont
929
930         incr CVEnv::prgindic
931         set CVEnv::prgtext   "Creating menu..."
932     update
933
934     #### Menu
935     set menu {
936         "&File" all file 0 {
937             {command "&New" {} "New document" {} -command CVEnv::new}
938                         {command "&Open" {} "Open a document" {} -command "CVEnv::open ."}
939                         {command "&Close" {} "Close the document" {} -state disable     \
940                                 -command CVEnv::close}
941                         {separator}
942                         {command "&Save" {} "Save the document" {} -state disable       \
943                                 -command CVEnv::save}
944                         {command "Save &As..." {} "Save the document as..." {}  \
945                 -state disable -command "CVEnv::saveas ."}
946                         {separator}
947                         {command "E&xit" {} "Exit the program" {} -command exit}
948         }
949         "&View" all view 0 {
950             {checkbutton "&Toolbar" {all view} "Show/hide toolbar" {}   \
951                 -variable CVEnv::showtb \
952                 -command {$CVEnv::mainf showtoolbar 0 $CVEnv::showtb}
953             }
954                         {checkbutton "&Statusbar" {all view} "Show/hide statusbar" {}   \
955                 -variable CVEnv::showstb        \
956                 -command {
957                                                         if {$CVEnv::showstb} {
958                                                                 pack $CVEnv::mainf.botf -side bottom -fill x    
959                                                         } else {
960                                                                 pack forget $CVEnv::mainf.botf
961                                                         }
962                                                  }
963             }
964                         {checkbutton "&File pane" {all view} "" {}      \
965                 -variable CVEnv::showlp                                 \
966                 -command {CVEnv::leftpane $CVEnv::showlp}
967             }
968                         
969         }
970                 "&Options" all options 0 {
971                         {command "&Configuration" {} "Enviroments settings" {}  \
972                                 -command CVEnv::confdialog}
973                         {command "&Appearance" {} "Colors & fonts setup" {} -command CVEnv::colordialog}
974                 }
975                 "&Help" all help 0 {
976                         {command "&About CVEnv" {} "Display the program info" {}        \
977                          -command CVEnv::about}
978         }
979     }
980
981     #{checkbutton "&Execute pane" {all view} "" {}      \
982             #    -variable CVEnv::showbp                                        \
983             #    -command {CVEnv::bottompane $CVEnv::showbp}
984             #}
985
986         incr CVEnv::prgindic
987         set CVEnv::prgtext   "Creating MainFrame..."
988     update
989
990     set CVEnv::mainf [MainFrame .mainf -menu $menu      \
991                       -textvariable CVEnv::statustext]
992
993     menu .menubar.edit -tearoff 0 -background $::default_normal_bg
994     MainFrame::_create_entries .mainf .menubar.edit \
995                 $::default_normal_bg {\
996                         {command "Cu&t" {} "Cut the selection" {} -command cut}
997                         {command "&Copy" {} "Copy the selection" {} -command copy}
998                         {command "&Paste" {} "Paste the clipboard" {} -command paste}
999                         {separator}
1000                         {command "&Go to.." {} "Move to a specified place" {} -command paste}
1001         }
1002
1003         incr CVEnv::prgindic
1004         set CVEnv::prgtext   "Creating toolbar..."
1005     update
1006
1007     #### toolbars creation
1008     set CVEnv::tb  [$CVEnv::mainf addtoolbar]
1009
1010     set bbox [ButtonBox $CVEnv::tb.bbox0 -spacing 0 -padx 1 -pady 1]
1011     $bbox add -image [image create photo -file [file join $::image_path pictures/new.gif]] \
1012         -highlightthickness 0 -takefocus 0 -relief link -borderwidth 2  \
1013                 -padx 1 -pady 1 -helptext "Create a new file" -command CVEnv::new
1014     $bbox add -image [image create photo -file [file join $::image_path pictures/open.gif]] \
1015         -highlightthickness 0 -takefocus 0 -relief link -borderwidth 2  \
1016                 -padx 1 -pady 1 -helptext "Open an existing file" -command "CVEnv::open ."
1017     pack $bbox -side left -anchor w
1018     
1019     set sep [Separator $CVEnv::tb.sep0 -orient vertical]
1020     pack $sep -side left -fill y -padx 4 -anchor w
1021
1022     set bbox [ButtonBox $CVEnv::tb.bbox1 -spacing 0 -padx 1 -pady 1]
1023     $bbox add -image [image create photo -file [file join $::image_path pictures/save.gif]] \
1024               -highlightthickness 0 -takefocus 0 -relief link -borderwidth 2 \
1025                           -padx 1 -pady 1 -helptext "Save file" -command CVEnv::save
1026
1027         #$bbox.b2 configure -state active -relief link
1028             #$bbox.b2 _leave
1029
1030     set sep [Separator $CVEnv::tb.sep1 -orient vertical]
1031     
1032         set bbox [ButtonBox $CVEnv::tb.bbox2 -spacing 0 -padx 1 -pady 1]
1033     $bbox add -image [image create photo -file [file join $::image_path pictures/cut.gif]] \
1034         -highlightthickness 0 -takefocus 0 -relief link -borderwidth 1  \
1035                 -padx 1 -pady 1 -helptext "Cut (Ctrl-X)"
1036     $bbox add -image [image create photo -file [file join $::image_path pictures/copy.gif]] \
1037         -highlightthickness 0 -takefocus 0 -relief link -borderwidth 1  \
1038                 -padx 1 -pady 1 -helptext "Copy (Ctrl-C)"
1039     $bbox add -image [image create photo -file [file join $::image_path pictures/paste.gif]] \
1040         -highlightthickness 0 -takefocus 0 -relief link -borderwidth 1  \
1041                 -padx 1 -pady 1 -helptext "Paste (Ctrl-V)"
1042
1043         set sep [Separator $CVEnv::tb.sep2 -orient vertical]
1044
1045     set bbox [ButtonBox $CVEnv::tb.bbox3 -spacing 0 -padx 1 -pady 1]
1046     $bbox add -image [image create photo -file [file join $::image_path pictures/exec.gif]] \
1047         -highlightthickness 0 -takefocus 0 -relief link -borderwidth 1  \
1048                 -padx 1 -pady 1 -helptext "Execute the script (F5)" \
1049                 -command CVEnv::execute 
1050
1051     $bbox add -image [image create photo -file [file join $::image_path pictures/stop.gif]] \
1052         -highlightthickness 0 -takefocus 0 -relief link -borderwidth 1  \
1053                 -padx 1 -pady 1 -helptext "Stop the execution (Shift-F5)"\
1054                 -command pStop
1055
1056     set sep [Separator $CVEnv::tb.sep3 -orient vertical]
1057
1058     $CVEnv::tb.bbox3.b1 configure -state disable -relief link
1059     
1060     incr CVEnv::prgindic
1061     set CVEnv::prgtext   "Creating statusbar..."
1062     update
1063
1064         $CVEnv::mainf addindicator
1065         $CVEnv::mainf.status.indf.f0 configure -relief flat
1066
1067         label $CVEnv::mainf.status.indf.f0.l0  -relief sunken -borderwidth 1 \
1068         -takefocus 0 -highlightthickness 0 -textvariable CVEnv::curfile
1069         pack $CVEnv::mainf.status.indf.f0.l0 -side left -fill y -expand 1
1070
1071         label $CVEnv::mainf.status.indf.f0.l1  -relief flat -borderwidth 1 \
1072         -takefocus 0 -highlightthickness 0 -text "Ln"
1073         pack $CVEnv::mainf.status.indf.f0.l1 -side left -fill y -expand 1
1074
1075         label $CVEnv::mainf.status.indf.f0.l2  -relief sunken -borderwidth 1 \
1076         -takefocus 0 -highlightthickness 0 -textvariable CVEnv::curln
1077         pack $CVEnv::mainf.status.indf.f0.l2 -side left -fill y -expand 1
1078
1079         label $CVEnv::mainf.status.indf.f0.l3  -relief flat -borderwidth 1 \
1080         -takefocus 0 -highlightthickness 0 -text "Col"
1081         pack $CVEnv::mainf.status.indf.f0.l3 -side left -fill y -expand 1
1082
1083         label $CVEnv::mainf.status.indf.f0.l4  -relief sunken -borderwidth 1 \
1084         -takefocus 0 -highlightthickness 0 -textvariable CVEnv::curcol
1085         pack $CVEnv::mainf.status.indf.f0.l4 -side left -fill y -expand 1
1086         pack forget $CVEnv::mainf.status.indf.f0
1087
1088         set CVEnv::prgtext   "Creating panes..."
1089     incr CVEnv::prgindic
1090     CVEnv::createpanes $CVEnv::mainf.frame
1091     
1092         set CVEnv::prgtext   "Done"
1093     incr CVEnv::prgindic
1094
1095     pack $CVEnv::mainf -fill both -expand yes
1096     update idletasks
1097
1098         unset CVEnv::prgindic
1099         unset CVEnv::prgtext
1100
1101     destroy .intro
1102 }
1103
1104 proc CVEnv::treeclick {node} {
1105     set file [lindex $node 0]
1106     set data [$CVEnv::tree itemcget $file -data]
1107         
1108     if [string compare $data "Files"] {
1109         set pos [lsearch $CVEnv::files $file]
1110             set page [lindex $CVEnv::pages $pos]
1111
1112         $CVEnv::nbrig see $page
1113         $CVEnv::nbrig raise $page
1114     }
1115 }
1116
1117 proc CVEnv::gotoline { line } {
1118     $CVEnv::curframe see $line.0
1119     focus -force $CVEnv::curframe
1120
1121     $CVEnv::curframe tag remove sel 0.0 $line.0
1122         $CVEnv::curframe tag add sel $line.0 [expr $line +1].0
1123         $CVEnv::curframe tag remove sel [expr $line +1].0 end
1124         update idletasks
1125 }
1126
1127 proc CVEnv::createpanes { parent } {
1128     set CVEnv::pw    [PanedWindow $parent.pw -side left]
1129     set CVEnv::ptop  [$CVEnv::pw add]
1130     
1131     set CVEnv::pwch  [PanedWindow $CVEnv::ptop.pw -side bottom]
1132     set plef  [$CVEnv::pwch add]
1133     set CVEnv::prig  [$CVEnv::pwch add]
1134
1135     set CVEnv::nblef [NoteBook $plef.nb -side bottom]
1136     set files [$CVEnv::nblef insert end "files" -text "Files" \
1137         -image [image create photo -file [file join $::image_path pictures/file.gif]]]
1138     set sw    [ScrolledWindow $files.sw \
1139                   -relief sunken -borderwidth 2]
1140     set CVEnv::tree  [Tree $sw.tree \
1141                 -relief flat -borderwidth 0 -width 15 -highlightthickness 0\
1142                                 -redraw 1]
1143         $sw setwidget $CVEnv::tree
1144         $CVEnv::tree insert end root files -text Files -data Files \
1145         -image [image create photo -file [file join $::image_path pictures/openfold.gif]]
1146     pack $sw    -side top  -expand yes -fill both
1147         #$CVEnv::nblef compute_size
1148     pack $CVEnv::nblef -fill both -expand yes -padx 1 -pady 1
1149
1150         set CVEnv::nbrig [NoteBook $CVEnv::ptop.nb -side top]
1151         
1152         #$CVEnv::nbrig compute_size
1153         pack $CVEnv::nbrig -in $CVEnv::prig -fill both -expand yes -padx 1 -pady 1
1154         pack $CVEnv::pwch -fill both -expand yes
1155
1156         set CVEnv::pbot  [$CVEnv::pw add]
1157     set CVEnv::inputcb [Entry $CVEnv::pbot.combo \
1158                    -textvariable CVEnv::inputvar \
1159                    -helptext "Input box. In order to input data press Enter."\
1160                    -command {
1161                              set CVEnv::inputdata $CVEnv::inputvar
1162                              lappend CVEnv::inputlist $CVEnv::inputdata
1163                              set CVEnv::curinput [lsearch -exact $CVEnv::inputlist $CVEnv::inputdata]
1164                              $CVEnv::inputcb configure -fg #00FFFF
1165                              pInput
1166                             } ]
1167     pack $CVEnv::inputcb -fill x -side bottom
1168
1169     bind $CVEnv::inputcb <KeyPress> {
1170                                         set CVEnv::inputdata ""
1171                                         $CVEnv::inputcb configure \
1172                                             -fg $::default_window_fg
1173                                     }
1174     bind $CVEnv::inputcb <Up> {
1175                                     if {$CVEnv::curinput != 0} {
1176                                       set CVEnv::curinput [expr $CVEnv::curinput -1]
1177                                       set CVEnv::inputvar [lindex $CVEnv::inputlist $CVEnv::curinput]
1178                                       set CVEnv::inputdata $CVEnv::inputvar
1179                                       $CVEnv::inputcb configure \
1180                                         -fg #00FFFF
1181                                     }
1182                               }
1183     bind $CVEnv::inputcb <Down> {
1184                                     incr CVEnv::curinput
1185                                     set CVEnv::inputvar [lindex $CVEnv::inputlist $CVEnv::curinput]
1186                                     set CVEnv::inputdata $CVEnv::inputvar
1187                                     $CVEnv::inputcb configure \
1188                                         -fg #00FFFF
1189                                 }
1190
1191
1192         set CVEnv::nbbot  [NoteBook $CVEnv::pbot.nb -side bottom]
1193         
1194         set parse  [$CVEnv::nbbot insert end parse  -text "Errors"]
1195         set sw [ScrolledWindow $parse.sw -auto vertical]
1196         set CVEnv::parsetx [text $sw.tx -wrap none]
1197         $sw setwidget $CVEnv::parsetx
1198         pack $CVEnv::parsetx -fill both -expand yes 
1199         pack $sw  -side top  -expand yes -fill both
1200
1201     bind $CVEnv::parsetx <Button-2> {
1202         set pos [$CVEnv::parsetx index @%x,%y]
1203         set listpos [split $pos "."]
1204         set line [lindex $listpos 0]
1205
1206         set data [$CVEnv::parsetx get "insert linestart" "insert lineend"]
1207         set datalist [split $data " "]
1208         set file [lindex $datalist 2]
1209         set line [lindex [split [lindex $datalist 5] ":"] 0]
1210
1211         if [string compare $file ""] {
1212         set pos [lsearch -exact $CVEnv::files $file]
1213         set page [lindex $CVEnv::pages $pos]
1214             if [string compare $page ""] { 
1215                 $CVEnv::nbrig see $page
1216                 $CVEnv::nbrig raise $page 
1217                 CVEnv::gotoline $line
1218             }
1219         }  
1220     }
1221     bind $CVEnv::parsetx <Button-3> {
1222         set pos [$CVEnv::parsetx index @%x,%y]
1223         set listpos [split $pos "."]
1224         set line [lindex $listpos 0]
1225
1226         set data [$CVEnv::parsetx get "insert linestart" "insert lineend"]
1227         set datalist [split $data " "]
1228         set file [lindex $datalist 2]
1229         set line [lindex [split [lindex $datalist 5] ":"] 0]
1230
1231         if [string compare $file ""] {
1232         set pos [lsearch -exact $CVEnv::files $file]
1233         set page [lindex $CVEnv::pages $pos]
1234             if [string compare $page ""] { 
1235                 $CVEnv::nbrig see $page
1236                 $CVEnv::nbrig raise $page 
1237                 CVEnv::gotoline $line
1238             }
1239         }  
1240     }
1241         
1242         set output [$CVEnv::nbbot insert end output -text "Output"]     
1243         set sw [ScrolledWindow $output.sw -auto vertical]
1244         set CVEnv::outtx [text $sw.tx -wrap none]
1245         $sw setwidget $CVEnv::outtx
1246         pack $CVEnv::outtx -fill both -expand yes 
1247         pack $sw  -side top  -expand yes -fill both
1248         
1249         bind $CVEnv::outtx <KeyPress> {$CVEnv::outtx configure -state disable}
1250         bind $CVEnv::outtx <KeyRelease> {$CVEnv::outtx configure -state normal}
1251     bind $CVEnv::outtx <Button-1> {$CVEnv::outtx configure -state normal}
1252     bind $CVEnv::parsetx <KeyPress> {$CVEnv::parsetx configure -state disable}
1253         bind $CVEnv::parsetx <KeyRelease> {$CVEnv::parsetx configure -state normal}
1254     bind $CVEnv::parsetx <Button-1> {$CVEnv::parsetx configure -state normal}
1255         
1256         #$CVEnv::nbbot compute_size
1257         pack $CVEnv::nbbot -fill both -expand yes -padx 1 -pady 1 -side top
1258
1259     $CVEnv::tree bindText <Double-Button-1> "CVEnv::treeclick"
1260     #Tree::bindImage $path <Button-1> "$path selection set"
1261
1262         
1263         pack $CVEnv::pw -fill both -expand yes
1264 }
1265
1266 proc CVEnv::update_font { newfont } {
1267     variable _wfont
1268     variable notebook
1269     variable font
1270     variable font_name
1271
1272     . configure -cursor watch
1273     if { $font != $newfont } {
1274         $_wfont configure -font $newfont
1275         $notebook configure -font $newfont
1276         set font $newfont
1277     }
1278     . configure -cursor ""
1279 }
1280
1281 proc main {} {
1282     package require BWidget
1283     #option add *TitleFrame.l.font {helvetica 11 bold italic}
1284     wm withdraw .
1285     wm title . "CVEnv"
1286
1287     CVEnv::create
1288
1289     BWidget::place . 640 480 center
1290     wm deiconify .
1291     raise .
1292     wm geometry . 640x480
1293
1294     set y0 [winfo y .]
1295     set x0 [winfo x .]
1296     set ypw [expr $y0 + 360]
1297     set xpw [expr $x0 + 130]
1298     
1299     update
1300     PanedWindow::_end_move_sash $CVEnv::pw $CVEnv::pw.sash              \
1301                 1 0 0x0FFFFFFF $ypw rooty height
1302     PanedWindow::_end_move_sash $CVEnv::pwch $CVEnv::pwch.sash  \
1303                 1 0 0x0FFFFFFF $xpw rootx width
1304
1305         $CVEnv::nblef raise [$CVEnv::nblef page 0]
1306         $CVEnv::nbbot raise [$CVEnv::nbbot page 1]
1307     
1308     update
1309
1310     focus -force .
1311 }
1312
1313 main