2004-08-04 [SRIV] weeCalc: a proof of concept calculator app for weeDesk. I know the name was reserved for a speadsheet app, but until someone takes 10 minutes to code one up, this will be weeCalc. Background: This app was originally a Visual Tcl project that I coded for my linux iPaq, hence the dimensions. The buttons are big enough to be easily operated by my index fingers. I gutted all the Vtcl crap out, Still needs a lot of reformatting to make it readable, so dont complain about its ugliness. This calculator script runs fine from wish or tclkit. I use it as my everyday calculator app. Save this file as calc.tcl in the same directory as weedesk. Then, add these lines to the end of weedesk.tcl: #start of weeCalc code pack forget .win1.t set base .win1 source calc.tcl bind .win1.ent38 "winSelect .win1" start of code: #!/bin/sh # the next line restarts using wish\ exec wish "$0" "$@" package require Tk ############################################################################# ## Procedure: blink_disp proc blink_disp {} { global display set ::clickoff 0 set temp $display set display "" update after 100 set display $temp } ############################################################################# ## Procedure: compute proc compute {} { global display display_dec result last_op func current_val base switch -exact -- $base { hex {set display_dec [format "%d" 0x$display] } dec {if {[string first "." $current_val ] == "-1"} {append current_val "."} if {$display == "."} {set display "0."} set display_dec $display } } if {$last_op == ""} { if {$current_val != "0"} { # puts "$current_val $display_dec $display" if {[catch {set display_dec [expr $current_val $func $display_dec]} result]} {set display_dec "error"} # set current_val "0" if {$display_dec != "error"} { set integer [expr int($display_dec)] if {$integer == $display_dec} {set display_dec $integer} switch -exact -- $base { dec {set display $display_dec} hex {set display [format "%X" $display_dec]} } } else { set display $display_dec } } } set current_val $display_dec } ################### # CREATING WIDGETS ################### if {! [info exists base]} { #standalone wish app tewaks set base "" wm focusmodel . passive wm maxsize . 232 270 wm minsize . 232 270 wm geometry . 232x270 wm overrideredirect . 0 wm resizable . 1 1 wm deiconify . bind . {exit} wm title . "SR Calc v1.1" . configure -background #666666 set ::offcommand "exit" } else { #weeDesk specific app tweaks $base configure -height 270 -width 232 -background #666666 set ::offcommand "winClose $base" $base-tab.title configure -text "weeCalc v1.1" } entry $base.ent38 \ -background #ffffcac07ae1 -font {Helvetica -24 bold} \ -insertbackground black -justify right -textvariable display button $base.but39 \ -background #fdc5ffff90a3 \ -command {global display last_op if {$last_op != "" } { set display "0" set last_op ""} if {[string equal $display "0"]} {set display ""} append display "1" blink_disp} \ -text 1 button $base.but40 \ -background #fdc5ffff90a3 \ -command {global display last_op if {$last_op != "" } { set display "0" set last_op ""} if {[string equal $display "0"]} {set display ""} append display "2" blink_disp} \ -text 2 button $base.but41 \ -background #fdc5ffff90a3 \ -command {global display last_op if {$last_op != "" } { set display "0" set last_op ""} if {[string equal $display "0"]} {set display ""} append display "3" blink_disp} \ -text 3 button $base.but42 \ -background #fdc5ffff90a3 \ -command {global display last_op if {$last_op != "" } { set display "0" set last_op ""} if {[string equal $display "0"]} {set display ""} append display "4" blink_disp} \ -text 4 button $base.but43 \ -background #fdc5ffff90a3 \ -command {global display last_op if {$last_op != "" } { set display "0" set last_op ""} if {[string equal $display "0"]} {set display ""} append display "5" blink_disp} \ -text 5 button $base.but44 \ -background #fdc5ffff90a3 \ -command {global display last_op if {$last_op != "" } { set display "0" set last_op ""} if {[string equal $display "0"]} {set display ""} append display "6" blink_disp} \ -text 6 button $base.but45 \ -background #fdc5ffff90a3 \ -command {global display last_op if {$last_op != "" } { set display "0" set last_op ""} if {[string equal $display "0"]} {set display ""} append display "7" blink_disp} \ -text 7 button $base.but46 \ -background #fdc5ffff90a3 \ -command {global display last_op base if {$base == "hex" || $base == "dec"} { if {$last_op != "" } { set display "0" set last_op ""} if {[string equal $display "0"]} {set display ""} append display "8" } blink_disp} \ -text 8 button $base.but47 \ -background #fdc5ffff90a3 \ -command {global display last_op base if {$base == "hex" || $base == "dec"} { if {$last_op != "" } { set display "0" set last_op ""} if {[string equal $display "0"]} {set display ""} append display "9" } blink_disp} \ -text 9 button $base.but48 \ -background #fdc5ffff90a3 \ -command {global display last_op if {$last_op != "" } { set display "0" set last_op ""} if {[string equal $display "0"]} { set display "0" } else { append display "0" } blink_disp} \ -text 0 button $base.but49 -background #fdc5ffff90a3 -text . \ -command {global display last_op base if {$base == "dec"} { if {$last_op != "" } { set display "0" set last_op ""} if {$display == "0."} {set display ""} if {[string first "." $display ] == "-1"} { append display "."} } blink_disp } button $base.but50 -background #8cccb3f7ffff -text = \ -command { global display result last_op func current_val compute blink_disp set current_val "0" set last_op "=" set func "=" } button $base.but51 -background #beb8ec6affff -text / \ -command {global last_op func compute set last_op "div" set func "/" compute blink_disp } button $base.but52 -background #beb8ec6affff -text * \ -command {global last_op func compute set last_op "mul" set func "*" compute blink_disp } button $base.but53 -background #beb8ec6affff -text - \ -command {global last_op func compute set last_op "sub" set func "-" compute blink_disp } button $base.but54 -background #beb8ec6affff -text + \ -command {global last_op func compute set last_op "add" set func "+" compute blink_disp } button $base.but55 \ -background #a4ddffff8e14 \ -command {global display result last_op func current_val set display "0" set current_val "0" set last_op "" set func "" blink_disp} \ -text On/C button $base.but56 -background #ffffa28fe308 -text MR \ -command {global display memory last_op set display $memory set last_op "" blink_disp } button $base.but57 \ -background #ffffa28fe308 -text M+ \ -command {global display memory last_op set memory $display blink_disp } button $base.but58 \ -background #ffffa28fe308 -text M- \ -command {global display memory last_op set memory "0" blink_disp } button $base.but59 -background #999999 -text Off \ -command { if {$::clickoff} { eval $::offcommand } else { set ::clickoff 1 } } button $base.but60 \ -background #a4ddffff8e14 \ -command {global display set display "0" blink_disp} -text CE button $base.but61 \ -background #ffffe5c2970a -text Base \ -command {global base display display_dec blink_disp switch -exact -- $base { hex {set base "dec" set display [format "%d" 0x$display] set display_dec $display } dec {set base "hex" set display [format "%X" [expr int($display)]] } } } button $base.but62 \ -background #ffffa1898ccc \ -command {global display last_op base if {$base == "hex"} { if {$last_op != "" } { set display "0" set last_op ""} if {[string equal $display "0"]} {set display ""} append display "A" } blink_disp} \ -text A button $base.but63 \ -background #ffffa1898ccc \ -command {global display last_op base if {$base == "hex"} { if {$last_op != "" } { set display "0" set last_op ""} if {[string equal $display "0"]} {set display ""} append display "B" } blink_disp} \ -text B button $base.but64 \ -background #ffffa1898ccc \ -command {global display last_op base if {$base == "hex"} { if {$last_op != "" } { set display "0" set last_op ""} if {[string equal $display "0"]} {set display ""} append display "C" } blink_disp} \ -text C button $base.but65 \ -background #ffffa1898ccc \ -command {global display last_op base if {$base == "hex"} { if {$last_op != "" } { set display "0" set last_op ""} if {[string equal $display "0"]} {set display ""} append display "D" } blink_disp} \ -text D button $base.but66 \ -background #ffffa1898ccc \ -command {global display last_op base if {$base == "hex"} { if {$last_op != "" } { set display "0" set last_op ""} if {[string equal $display "0"]} {set display ""} append display "E" } blink_disp} \ -text E button $base.but67 \ -background #ffffa1898ccc \ -command {global display last_op base if {$base == "hex"} { if {$last_op != "" } { set display "0" set last_op ""} if {[string equal $display "0"]} {set display ""} append display "F" } blink_disp} \ -text F label $base.lab68 \ -background #666666 -foreground #fdc5ffff90a3 -text dec \ -textvariable base label $base.lab69 \ -background #666666 -font {Helvetica -14 bold} \ -foreground #a4ddffff8e14 -text {} -textvariable func menu $base.m70 \ -disabledforeground #a1a1a1 -tearoff 1 ################### # SETTING GEOMETRY ################### place $base.ent38 -x 13 -y 7 -width 183 -height 37 -anchor nw -bordermode ignore place $base.but39 -x 50 -y 195 -width 40 -height 28 -anchor nw -bordermode ignore place $base.but40 -x 95 -y 195 -width 40 -height 28 -anchor nw -bordermode ignore place $base.but41 -x 140 -y 195 -width 40 -height 28 -anchor nw -bordermode ignore place $base.but42 -x 50 -y 160 -width 40 -height 28 -anchor nw -bordermode ignore place $base.but43 -x 95 -y 160 -width 40 -height 28 -anchor nw -bordermode ignore place $base.but44 -x 140 -y 160 -width 40 -height 28 -anchor nw -bordermode ignore place $base.but45 -x 50 -y 125 -width 40 -height 28 -anchor nw -bordermode ignore place $base.but46 -x 95 -y 125 -width 40 -height 28 -anchor nw -bordermode ignore place $base.but47 -x 140 -y 125 -width 40 -height 28 -anchor nw -bordermode ignore place $base.but48 -x 50 -y 230 -width 40 -height 28 -anchor nw -bordermode ignore place $base.but49 -x 95 -y 230 -width 40 -height 28 -anchor nw -bordermode ignore place $base.but50 -x 140 -y 230 -width 87 -height 28 -anchor nw -bordermode ignore place $base.but51 -x 185 -y 90 -width 42 -height 28 -anchor nw -bordermode ignore place $base.but52 -x 185 -y 125 -width 42 -height 28 -anchor nw -bordermode ignore place $base.but53 -x 185 -y 160 -width 42 -height 28 -anchor nw -bordermode ignore place $base.but54 -x 185 -y 195 -width 42 -height 28 -anchor nw -bordermode ignore place $base.but55 -x 5 -y 55 -width 40 -height 28 -anchor nw -bordermode ignore place $base.but56 -x 5 -y 160 -width 40 -height 28 -anchor nw -bordermode ignore place $base.but57 -x 5 -y 195 -width 40 -height 28 -anchor nw -bordermode ignore place $base.but58 -x 5 -y 230 -width 40 -height 28 -anchor nw -bordermode ignore place $base.but59 -x 5 -y 90 -width 40 -height 28 -anchor nw -bordermode ignore place $base.but60 -x 5 -y 125 -width 40 -height 28 -anchor nw -bordermode ignore place $base.but61 -x 185 -y 55 -width 42 -height 28 -anchor nw -bordermode ignore place $base.but62 -x 50 -y 90 -width 40 -height 28 -anchor nw -bordermode ignore place $base.but63 -x 95 -y 90 -width 40 -height 28 -anchor nw -bordermode ignore place $base.but64 -x 140 -y 90 -width 40 -height 28 -anchor nw -bordermode ignore place $base.but65 -x 50 -y 55 -width 40 -height 28 -anchor nw -bordermode ignore place $base.but66 -x 95 -y 55 -width 40 -height 28 -anchor nw -bordermode ignore place $base.but67 -x 140 -y 55 -width 40 -height 28 -anchor nw -bordermode ignore place $base.lab68 -x 200 -y 5 -width 28 -height 20 -anchor nw -bordermode ignore place $base.lab69 -x 200 -y 25 -width 28 -height 20 -anchor nw -bordermode ignore ############################################################################# set ::clickoff 0 set display "0" set display_dec "0" set last_op "" set func "" set base "dec" set current_val "0" set memory "0" update