Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/ruby
- =begin
- pomodoro.rb - Ruby/GTK timer
- © 2008 Fernando Vezzosi <fv@linuxvar.it>
- =end
- require 'gtk2'
- time_work = 5
- time_rest = 1
- label_work = 'Produci Consuma Muori'
- label_rest = 'Riposa'
- label, timer, timeout = nil, nil, 1
- window, label, button_ok = nil, nil, nil
- # "OK" button
- button_ok = Gtk::Button.new.add(Gtk::Label.new '_OK', true)
- button_ok.signal_connect :clicked do
- timeout = (timeout == time_rest) ? time_work : time_rest;
- puts "set timeout to #{timeout}"
- label.text = (label.text == label_rest) ? label_work : label_rest;
- window.hide
- timer.wakeup
- end
- # "Exit" button
- button_exit = Gtk::Button.new.add(Gtk::Label.new 'E_xit', true)
- button_exit.signal_connect :clicked do
- puts "i go out and enjoy life"
- Gtk.main_quit
- end
- # Button panel
- bbox = Gtk::HButtonBox.new
- bbox.layout_style = Gtk::ButtonBox::Style::CENTER
- bbox.add_child Gtk::Builder.new, button_ok
- bbox.add_child Gtk::Builder.new, Gtk::VSeparator.new
- bbox.add_child Gtk::Builder.new, button_exit
- # Label
- label = Gtk::Label.new
- label.markup = '<span foreground="red" weight="ultrabold">Pomodoro</span>: 25 minutes work, 5 minutes rest'
- # clock
- clock = Gtk::Label.new
- clock.markup = '<span size="x-large">00:00:00</span>'
- vbox = Gtk::VBox.new
- vbox.add_child Gtk::Builder.new, label
- vbox.add_child Gtk::Builder.new, clock
- vbox.add_child Gtk::Builder.new, Gtk::HSeparator.new
- vbox.add_child Gtk::Builder.new, bbox
- # main window
- window = Gtk::Window.new 'pomodoro'
- window.set_wmclass 'pomodoro', 'dialog'
- window.set_default_size 400, 150
- timer = Thread.new do
- while true do
- puts "sleeping #{timeout}"
- sleep timeout
- window.show_all
- sleep
- end
- end
- window.add vbox
- Gtk.main
Add Comment
Please, Sign In to add comment