-
-
Save johana-star/2776252 to your computer and use it in GitHub Desktop.
SassyTomato Timer (for pomodoros)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Shoes.app :height => 215, :width => 215, :title => "SassyTomato" do | |
background pink | |
@time_to_start = Time.new | |
@stopped = true | |
def timer_button(args) | |
button args[:name] do | |
@time_to_stop = Time.now + args[:minutes] * 60 + 0.05 | |
run | |
end | |
end | |
flow do | |
stack :margin => [10, 45, 0, 0], :width => 75 do | |
image "http://i.imgur.com/NgtbE.jpg" | |
end | |
stack :margin => 10, :width => -75 do | |
edit_line(text = "current task", width: 100) | |
timer_button(name: "Start", minutes: 25) | |
timer_button(name: "Short Break", minutes: 5) | |
timer_button(name: "Long Break", minutes: 15) | |
stop_button = button "Stop" | |
stop_button.click { stop } | |
end | |
flow :align => "center" do | |
@label = para "Press start." | |
end | |
end | |
def run | |
@stopped = false | |
every 1 do | |
return if @stopped | |
stop if Time.now > @time_to_stop | |
tick | |
end | |
end | |
def stop | |
@stopped = true | |
@label.replace "Done!" | |
end | |
def tick | |
time_left = @time_to_stop - Time.now | |
minutes = (time_left / 60).to_i | |
seconds = "%02d" % (time_left % 60).to_i | |
@label.replace "#{minutes}:#{seconds} remaining." | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment