#!/bin/sh # the next line restarts using wish \ exec wish "$0" -- "$@" # tktips - wrapper around "fortune tips", # gives option to create .notips to avoid automatically getting # tips in the future. # # Call this from .xinitrc as: # /usr/local/bin/tktips -n & # # Rob Funk # 1999-Apr-03 # # Version 1.1 # changes in 1.1: # - if -n given n command line, don't run if .notips exists # - initial state of checkbox reflects (non)existence of .notips file # - update-on-exit (Go proc) both creates and removes .notips # depending on state of checkbox, rather than only creating. # - fix key bindings: # Escape exits with no changes # Return on "Another Tip" button gives another tip # otherwise Return updates .notips file state and exits # - make file paths easily settable at beginning # - Add Toggle proc so that a key can be bound to toggling notips state # (currently unused) # # Version 1.1a: # - Make it dockable in Window Maker (at least) # - fix .xinitrc comment above to use -n option set notipsfile "~/.notips" set fortune "/usr/games/fortune" # This is a bit clumsy, but it works if {[lindex $argv 0] == "-n"} { if {[file exists $notipsfile]} { exit 2 } } proc Go {turnoff} { global notipsfile if {$turnoff} { # create empty notips file set notips [open $notipsfile "w"] close $notips } elseif {[file exists $notipsfile]} { file delete $notipsfile } destroy . } proc Cancel {} { destroy . } proc SetFortune w { global fortune set f [exec $fortune tips] destroy $w.top.f label $w.top.f -text $f -justify left -relief sunken -bd 1 -padx 2m -pady 2m pack $w.top.f -in $w.top -padx 2m -pady 2m Center . } proc Toggle turnoff { set turnoff [expr ! $turnoff] } proc Center w { wm withdraw $w set x [expr [winfo screenwidth $w]/2 - [winfo reqwidth $w]/2] set y [expr [winfo screenheight $w]/2 - [winfo reqheight $w]/2] wm geom $w +$x+$y wm deiconify $w } Center . wm title . "Linux Tip" # Next two lines make this dockable (at least in Window Maker) wm command . [concat $argv0 $argv] wm group . . set w "" frame $w.top -relief raised -bd 1 frame $w.mid -relief raised -bd 1 frame $w.bot -relief raised -bd 1 pack $w.top $w.mid $w.bot -fill both SetFortune $w if {[file exists $notipsfile]} {set turnoff 1} checkbutton $w.mid.cb -text "Don't show these tips in the future" -variable turnoff pack $w.mid.cb -in $w.mid bind $w.mid.cb {Go $turnoff} ;# could also call {Toggle $turnoff} button $w.bot.button0 -text OK -command {Go $turnoff} frame $w.bot.default -relief sunken -bd 1 raise $w.bot.button0 $w.bot.default pack $w.bot.default -in $w.bot -side left -expand 1 -padx 3m -pady 1m pack $w.bot.button0 -in $w.bot.default -ipadx 1c -padx 2 -pady 2 button $w.bot.button1 -text "Another Tip" -command {SetFortune $w} pack $w.bot.button1 -in $w.bot -side left -expand 1 -ipadx 1c -padx 3m -pady 1m bind $w.bot.button0 {Go $turnoff} bind $w.bot.button1 {SetFortune $w} bind . {Cancel} # Give focus to OK button focus $w.bot.button0