#!/usr/bin/env wish package require sound snack::sound beep -file "~/.local/share/pomo/beep.wav" snack::sound chime -file "~/.local/share/pomo/chime.wav" set appname "Tk timer" # set timeleft {25 0} # state can be "paused" or "running" or "stopped" set state "stopped" # phase can be "work" or "break" set phase "work" proc dec {} { global timeleft if {[lindex $timeleft 0] == 0 && [lindex $timeleft 1] == 0} { return 0 } elseif {[lindex $timeleft 1] == 0} { set timeleft [lreplace $timeleft 1 1 59] set timeleft [lreplace $timeleft 0 0 [expr [lindex $timeleft 0] - 1]] } else { set timeleft [lreplace $timeleft 1 1 [expr [lindex $timeleft 1] - 1]] } return 1 } proc notify {} { variable msg global phase global appname if {$phase == "work"} { set msg "Break time: Remember to stretch" } else { set msg "Are you ready to get back to work?" } chime play exec notify-send $appname $msg } proc setuptime {} { global phase global timeleft if {$phase == "work"} { set timeleft {25 0} } else { set timeleft {5 0} } .display configure -text [format "%02d:%02d" [lindex $timeleft 0] [lindex $timeleft 1]] } font create bigText -family Helvetica -size 72 font create buttonText -family Helvetica -size 30 # play/pause button button .pp -background blue -font buttonText -text "Play" -command playpause button .skip -font buttonText -text "Skip" -command skip label .display -font bigText proc next-phase {} { global phase global state notify set state "stopped" .pp configure -text "Play" if {$phase == "work"} { set phase "break" } else { set phase "work" } setuptime } proc countdown {} { global state global result global timeleft if {$state == "running"} { set result [dec] if {!$result} { next-phase } else { .display configure -text [format "%02d:%02d" [lindex $timeleft 0] [lindex $timeleft 1]] after 1000 countdown } } } proc playpause {} { global phase global state variable txt if {$state == "running"} { set state "paused" set txt "Play" } else { if {$state == "stopped"} { beep play } set state "running" set txt "Pause" countdown } .pp configure -text $txt } proc skip {} { after cancel countdown next-phase } grid rowconfigure . 0 -weight 1 grid rowconfigure . 3 -weight 1 grid columnconfigure . 0 -weight 1 grid columnconfigure . 3 -weight 1 grid .display -column 1 -columnspan 2 -row 1 grid .pp -column 1 -row 2 grid .skip -column 2 -row 2 setuptime