1# ---------------------------------------------------------------------------- 2# manager.tcl 3# This file is part of Unifix BWidget Toolkit 4# $Id: demo_main.tcl,v 1.2 2009/10/25 20:53:58 oberdorfer Exp $ 5# ---------------------------------------------------------------------------- 6# 7 8namespace eval Demo { 9 variable _wfont 10 11 variable notebook 12 variable mainframe 13 variable status 14 variable prgtext 15 variable prgindic 16 variable font 17 variable font_name 18 variable toolbar1 1 19 variable toolbar2 1 20 21 set appDir [file dirname [info script]] 22 23 set pwd [pwd] 24 cd $appDir 25 variable DEMODIR [pwd] 26 cd $pwd 27 28 foreach script { 29 manager.tcl basic.tcl select.tcl dnd.tcl tree.tcl tmpldlg.tcl 30 } { 31 namespace inscope :: source $DEMODIR/$script 32 } 33 34 variable THEME_DIR [file join $appDir "themes"] 35 variable ctheme 36 37 set ctheme $::BWidget::colors(style) 38} 39 40 41proc Demo::setTheme { {newtheme ""} } { 42 variable ctheme 43 44 if { ![string length $newtheme] } { 45 set newtheme $ctheme 46 } 47 48 # just in case - (maybe usefull during developement) ... 49 if { ![llength [set themes [BWidget::getAvailableThemes]]] || 50 [lsearch $themes $newtheme] == -1} { 51 return -code error "color/style declaration is incomplete!" 52 } 53 54 BWidget::set_themedefaults $newtheme 55} 56 57 58proc Demo::create { } { 59 global tk_patchLevel 60 variable _wfont 61 variable notebook 62 variable mainframe 63 variable font 64 variable prgtext 65 variable prgindic 66 variable ctheme 67 68 set prgtext "Please wait while loading font..." 69 set prgindic -1 70 _create_intro 71 update 72 SelectFont::loadfont 73 74 bind all <F12> { catch {console show} } 75 bind all <Escape> { exit 0 } 76 77 78 # Menu description 79 set descmenu { 80 "&File" all file 0 { 81 {command "E&xit" {} "Exit BWidget demo" {} -command exit} 82 } 83 "&Options" all options 0 { 84 {checkbutton "Toolbar &1" {all option} "Show/hide toolbar 1" {} 85 -variable Demo::toolbar1 86 -command {$Demo::mainframe showtoolbar 0 $Demo::toolbar1} 87 } 88 {checkbutton "Toolbar &2" {all option} "Show/hide toolbar 2" {} 89 -variable Demo::toolbar2 90 -command {$Demo::mainframe showtoolbar 1 $Demo::toolbar2} 91 } 92 } 93 } 94 95 set prgtext "Creating MainFrame..." 96 set prgindic 0 97 set mainframe [MainFrame .mainframe \ 98 -menu $descmenu \ 99 -textvariable Demo::status \ 100 -progressvar Demo::prgindic] 101 102 # toolbar 1 creation 103 incr prgindic 104 set tb1 [$mainframe addtoolbar] 105 set bbox [ButtonBox $tb1.bbox1 -spacing 0 -padx 1 -pady 1] 106 $bbox add -image [Bitmap::get new] \ 107 -highlightthickness 0 -takefocus 0 -relief link -borderwidth 1 -padx 1 -pady 1 \ 108 -helptext "Create a new file" 109 $bbox add -image [Bitmap::get open] \ 110 -highlightthickness 0 -takefocus 0 -relief link -borderwidth 1 -padx 1 -pady 1 \ 111 -helptext "Open an existing file" 112 $bbox add -image [Bitmap::get save] \ 113 -highlightthickness 0 -takefocus 0 -relief link -borderwidth 1 -padx 1 -pady 1 \ 114 -helptext "Save file" 115 pack $bbox -side left -anchor w 116 117 set sep [Separator $tb1.sep -orient vertical] 118 pack $sep -side left -fill y -padx 4 -anchor w 119 120 incr prgindic 121 set bbox [ButtonBox $tb1.bbox2 -spacing 0 -padx 1 -pady 1] 122 $bbox add -image [Bitmap::get cut] \ 123 -highlightthickness 0 -takefocus 0 -relief link -borderwidth 1 -padx 1 -pady 1 \ 124 -helptext "Cut selection" 125 $bbox add -image [Bitmap::get copy] \ 126 -highlightthickness 0 -takefocus 0 -relief link -borderwidth 1 -padx 1 -pady 1 \ 127 -helptext "Copy selection" 128 $bbox add -image [Bitmap::get paste] \ 129 -highlightthickness 0 -takefocus 0 -relief link -borderwidth 1 -padx 1 -pady 1 \ 130 -helptext "Paste selection" 131 pack $bbox -side left -anchor w 132 133 # toolbar 2 creation 134 incr prgindic 135 set tb2 [$mainframe addtoolbar] 136 set _wfont [SelectFont $tb2.font -type toolbar \ 137 -command "Demo::update_font \[$tb2.font cget -font\]"] 138 set font [$_wfont cget -font] 139 pack $_wfont -side left -anchor w 140 141 BWidget::wrap label $tb2.l -text "Theme: " 142 ComboBox $tb2.cb \ 143 -values [BWidget::getAvailableThemes] \ 144 -text $ctheme \ 145 -modifycmd "[namespace current]::setTheme \[$tb2.cb cget -text\]" \ 146 -editable 0 \ 147 -hottrack 1 148 149 pack $tb2.cb $tb2.l -side right 150 151 $mainframe addindicator -text "BWidget [package version BWidget]" 152 $mainframe addindicator -textvariable tk_patchLevel 153 154 # NoteBook creation 155 set frame [$mainframe getframe] 156 set notebook [NoteBook $frame.nb] 157 158 set prgtext "Creating Manager..." 159 incr prgindic 160 set f0 [DemoManager::create $notebook] 161 set prgtext "Creating Basic..." 162 incr prgindic 163 set f1 [DemoBasic::create $notebook] 164 set prgtext "Creating Select..." 165 incr prgindic 166 set f2 [DemoSelect::create $notebook] 167 set prgtext "Creating Dialog..." 168 incr prgindic 169 set f3b [DemoDlg::create $notebook] 170 set prgtext "Creating Drag and Drop..." 171 incr prgindic 172 set f4 [DemoDnd::create $notebook] 173 set prgtext "Creating Tree..." 174 incr prgindic 175 set f5 [DemoTree::create $notebook] 176 177 set prgtext "Done" 178 incr prgindic 179 $notebook compute_size 180 pack $notebook -fill both -expand yes -padx 4 -pady 4 181 $notebook raise [$notebook page 0] 182 183 pack $mainframe -fill both -expand yes 184 update idletasks 185 destroy .intro 186} 187 188 189proc Demo::update_font { newfont } { 190 variable _wfont 191 variable notebook 192 variable font 193 variable font_name 194 195 . configure -cursor watch 196 if { $font != $newfont } { 197 $_wfont configure -font $newfont 198 $notebook configure -font $newfont 199 set font $newfont 200 } 201 . configure -cursor "" 202} 203 204 205proc Demo::_create_intro { } { 206 variable DEMODIR 207 208 set top [toplevel .intro -relief raised -borderwidth 2] 209 210 wm withdraw $top 211 wm overrideredirect $top 1 212 213 set ximg [label $top.x -bitmap @$DEMODIR/x1.xbm \ 214 -foreground grey90 -background white] 215 set bwimg [label $ximg.bw -bitmap @$DEMODIR/bwidget.xbm \ 216 -foreground grey90 -background white] 217 set frame [frame $ximg.f -background white] 218 set lab1 [label $frame.lab1 -text "Loading demo" \ 219 -background white -font {times 8}] 220 set lab2 [label $frame.lab2 -textvariable Demo::prgtext \ 221 -background white -font {times 8} -width 35] 222 set prg [ProgressBar $frame.prg -width 50 -height 10 -background white \ 223 -variable Demo::prgindic -maximum 10] 224 pack $lab1 $lab2 $prg 225 place $frame -x 0 -y 0 -anchor nw 226 place $bwimg -relx 1 -rely 1 -anchor se 227 pack $ximg 228 BWidget::place $top 0 0 center 229 wm deiconify $top 230} 231 232 233proc Demo::main {} { 234 variable DEMODIR 235 236 lappend ::auto_path [file dirname $DEMODIR] 237 package require BWidget 238 239 option add *TitleFrame.l.font {helvetica 11 bold italic} 240 241 wm withdraw . 242 wm title . "BWidget demo" 243 244 Demo::create 245 BWidget::place . 0 0 center 246 wm deiconify . 247 raise . 248 focus -force . 249} 250