Skip to content

Instantly share code, notes, and snippets.

@vestige
Created July 14, 2011 14:18
Show Gist options
  • Save vestige/1082534 to your computer and use it in GitHub Desktop.
Save vestige/1082534 to your computer and use it in GitHub Desktop.
LT_timer
# -*- coding: utf-8 -*-
require 'readline'
require 'gnomecanvas2'
require 'timer'
require 'timerserv'
require 'drb/drb'
class Timer
def initialize
@seconds = 60 * 3
@color_table = [[(30..3600), "#00FF00","#003333"],
[(15...30), "#FFA500","#004444"],
[(05...15), "#FFA500","#2f4f4f"],
[(-1...05), "#FF3300","#111100"]]
@msg_table = [[(1...5),"Danger!",0xDD880080],
[(-1...1),"End!!!",0xFFFFFFD0]]
@start_time = nil
@stop_time = nil
end
def started?
@start_time ? true : false
end
def remain
if started? then
(@stop_time - Time.now).to_i
else
@seconds
end
end
def start
@start_time = Time.now + 1
@stop_time = @start_time + @seconds
end
def reset
if !started?
start
else
stop
end
end
def clear
@start_time = nil
@stop_time = nil
end
alias :stop :clear
def update
if started? then
if remain < 0 then
stop
end
end
end
def percent(t)
t = remain()
if t > 0 then
t*1.0/@seconds
else
0
end
end
def remain_text(t)
t = 0 if t < 0
min, sec = t.divmod 60
sprintf("%d:%02d", min, sec)
end
def color(t)
return ["#000000","#FFFFFF"] unless @color_table
@color_table.each do |table|
if table[0].include?(t)
return table[1..2]
end
end
@color_table.last[1..2]
end
def msg(t)
return "" unless @msg_table
@msg_table.each do |e|
if e[0].include?(t) then
return e[1..2]
end
end
["",0x000000FF]
end
def extend_time
return "" unless @stop_time
@stop_time += 10
end
def reduce_time
return "" unless @stop_time
@stop_time -= 10
end
end
def setup_timerview
timer = Timer.new
bk_text = {
:text => "RubyKaigi\n\n2010",
:font => "Impact 130",
:offset => 0x10
}
timer_text_font = "FreeSerif Bold 250"
msg_text_font = "FreeSans Bold 180"
side_bar = {
:step => 60,
:color => 0xFFCC44CF
}
view = TimerView.new(timer)
view.bk_text = bk_text
view.timer_text_font = timer_text_font
view.msg_text_font = msg_text_font
view.side_bar = side_bar
view.setup()
return view
end
def setup_window(timerview)
h = {
:title=>"RubyKaigi 2010"
}
BaseWindow.new(timerview, h)
end
def main
Gtk.init
timerview = setup_timerview()
window = setup_window(timerview)
window.show_all
Gtk.main
end
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment