1#!/bin/sh 2# the next line restarts using tclsh \ 3exec tclsh "$0" "$@" 4 5# $Id: test-button.tcl,v 1.14 2005/02/25 21:51:53 baum Exp $ 6 7# ensure that "." is the decimal point 8unset -nocomplain env(LC_ALL) 9set ::env(LC_NUMERIC) "C" 10 11set auto_path [linsert $auto_path 0 [file join [file dirname [info script]] ../src]] 12package require Gnocl 13 14set button [gnocl::button] 15 16proc assert { opt val } { 17 set val2 [$::button cget $opt] 18 if { $val != $val2 } { 19 error "$opt: $val != $val2" 20 } 21 puts "$opt: $val == $val2" 22} 23 24foreach el { "Simple<big> _St</big>ring" "%_Under_line" "%<<b>Pango</b>" 25 "%#Quit" } { 26 $button configure -text $el 27 assert -text $el 28} 29 30foreach val { "%#Save" "" "%/./one.png" } { 31 $button configure -icon $val 32 if { [catch {assert -icon $val} erg] } { 33 puts $erg 34 } 35} 36 37foreach val { "normal" "half" "none" "normal" } { 38 $button configure -relief $val 39 assert -relief $val 40} 41 42foreach opt {-text -icon } { 43 foreach el [lsort [gnocl::info allStockItems]] { 44 if { [catch {$button configure $opt "%#$el"} erg] } { 45 puts $erg 46 } else { 47 assert $opt "%#$el" 48 } 49 } 50} 51 52foreach opt {-name -data -tooltip -widthGroup -heightGroup -sizeGroup} { 53 foreach val {"qqq" "bbb" "" "" "ddd" "" } { 54 $button configure $opt $val 55 assert $opt $val 56 } 57} 58 59foreach opt {-visible -sensitive} { 60 foreach val {0 1 0 1} { 61 $button configure $opt $val 62 assert $opt $val 63 } 64} 65 66 67foreach opt {-onClicked -onShowHelp -onPopupMenu -onButtonPress \ 68 -onButtonRelease } { 69 foreach val {"puts hallo" "" "puts qqq"} { 70 $button configure $opt $val 71 assert $opt $val 72 } 73} 74$button configure -onShowHelp "puts hallo" 75assert -onShowHelp "puts hallo" 76assert -onClicked "puts qqq" 77 78foreach opt {-normalBackgroundColor -activeBackgroundColor \ 79 -prelightBackgroundColor} { 80 foreach val {"65535 0 0" "0 65535 0" "0 0 65535"} { 81 $button configure $opt $val 82 assert $opt $val 83 } 84} 85 86set but2 [gnocl::button] 87set box [gnocl::box -children [list $button $but2]] 88set win [gnocl::window -child $box] 89 90foreach el {1 2} { 91 $but2 configure -hasFocus 1 92 after 200 93 puts [gnocl::update] 94 assert -hasFocus 0 95 96 $button configure -hasFocus 1 97 after 200 98 puts [gnocl::update] 99 assert -hasFocus 1 100} 101 102$win delete 103 104puts "----- automatic tests done ------------" 105 106 107set left [gnocl::box -orientation vertical] 108# set right [gnocl::box -orientation vertical] 109set mainBox [gnocl::box -orientation horizontal -children $left] 110# $mainBox addEnd $right 111 112set relief normal 113set txtNo 0 114set commandList { "puts Hallo" "" {puts "Hallo 2"}} 115set command "" 116 117$left add [gnocl::button -onClicked {puts "markup test"} -text \ 118 "%<normal <b>_bold</b> <big>big</big> <small>small</small>" \ 119 -onButtonRelease {puts "button release %w %b"} \ 120 -onButtonPress {puts "button pressed %w %b"}] 121$left add [gnocl::button -text "relief half" -relief $relief \ 122 -activeBackgroundColor red -normalBackgroundColor blue \ 123 -prelightBackgroundColor green -onClicked {configRelief %w}] 124 125set but [gnocl::button -text "%__Command changed" \ 126 -onClicked "puts {Hello World!}"] 127$left add [gnocl::button -text "Command change" \ 128 -onClicked "configCommand $but"] 129$left add $but 130$left add [gnocl::button -text "" -onClicked {configText %w}] 131$left add [gnocl::button -text "%_Un_derline" \ 132 -onClicked {puts "%w underline"} -onShowHelp {puts "%w showHelp %h"} \ 133 -onPopupMenu {puts "%w popup menu"} -tooltip "This is a tooltip"] 134 135$left add [gnocl::button -text "%_H_elp" -icon "%#Save"] 136 137$but onClicked 138 139proc configCommand { widg } { 140 set ll [lsearch -exact $::commandList $::command] 141 incr ll 142 if { $ll >= [llength $::commandList] } { 143 set ll 0 144 } 145 set ::command [lindex $::commandList $ll] 146 $widg configure -onClicked $::command 147} 148proc configRelief { widg } { 149 switch $::relief { 150 normal { set ::relief half } 151 half { set ::relief none } 152 none { set ::relief normal } 153 } 154 $widg configure -relief $::relief -text "relief $::relief" 155} 156 157proc configText { widg } { 158 switch $::txtNo { 159 0 { $widg configure -text %#Yes } 160 1 { $widg configure -text %_ec_ho } 161 2 { $widg configure -text %#No } 162 3 { $widg configure -text "%_h_allo Icon" -icon "%#Save" } 163 4 { $widg configure -icon "" } 164 5 { $widg configure -text "%_hal_lo Icon" -icon "%#Save" } 165 6 { $widg configure -icon "%#SaveAs" } 166 7 { $widg configure -text "%__File" -icon "%/./one.png" } 167 } 168 incr ::txtNo 169 if { $::txtNo == 8 } { 170 set ::txtNo 1 171 } 172} 173 174if { $argc == 1 } { 175 set win [gnocl::plug -socketID [lindex $argv 0] -child $mainBox -onDestroy exit] 176} else { 177 set win [gnocl::window -child $mainBox -onDestroy exit] 178} 179 180gnocl::mainLoop 181 182