Guest User

Untitled

a guest
May 20th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. #!/usr/bin/ruby
  2.  
  3. =begin
  4. pomodoro.rb - Ruby/GTK timer
  5. © 2008 Fernando Vezzosi <fv@linuxvar.it>
  6. =end
  7.  
  8. require 'gtk2'
  9.  
  10. time_work = 5
  11. time_rest = 1
  12.  
  13. label_work = 'Produci Consuma Muori'
  14. label_rest = 'Riposa'
  15.  
  16. label, timer, timeout = nil, nil, 1
  17. window, label, button_ok = nil, nil, nil
  18.  
  19. # "OK" button
  20. button_ok = Gtk::Button.new.add(Gtk::Label.new '_OK', true)
  21.  
  22. button_ok.signal_connect :clicked do
  23. timeout = (timeout == time_rest) ? time_work : time_rest;
  24. puts "set timeout to #{timeout}"
  25. label.text = (label.text == label_rest) ? label_work : label_rest;
  26. window.hide
  27. timer.wakeup
  28. end
  29.  
  30. # "Exit" button
  31. button_exit = Gtk::Button.new.add(Gtk::Label.new 'E_xit', true)
  32. button_exit.signal_connect :clicked do
  33. puts "i go out and enjoy life"
  34. Gtk.main_quit
  35. end
  36.  
  37. # Button panel
  38. bbox = Gtk::HButtonBox.new
  39. bbox.layout_style = Gtk::ButtonBox::Style::CENTER
  40. bbox.add_child Gtk::Builder.new, button_ok
  41. bbox.add_child Gtk::Builder.new, Gtk::VSeparator.new
  42. bbox.add_child Gtk::Builder.new, button_exit
  43.  
  44. # Label
  45. label = Gtk::Label.new
  46. label.markup = '<span foreground="red" weight="ultrabold">Pomodoro</span>: 25 minutes work, 5 minutes rest'
  47.  
  48. # clock
  49. clock = Gtk::Label.new
  50. clock.markup = '<span size="x-large">00:00:00</span>'
  51.  
  52. vbox = Gtk::VBox.new
  53. vbox.add_child Gtk::Builder.new, label
  54. vbox.add_child Gtk::Builder.new, clock
  55. vbox.add_child Gtk::Builder.new, Gtk::HSeparator.new
  56. vbox.add_child Gtk::Builder.new, bbox
  57.  
  58. # main window
  59. window = Gtk::Window.new 'pomodoro'
  60.  
  61. window.set_wmclass 'pomodoro', 'dialog'
  62. window.set_default_size 400, 150
  63.  
  64. timer = Thread.new do
  65. while true do
  66. puts "sleeping #{timeout}"
  67. sleep timeout
  68. window.show_all
  69. sleep
  70. end
  71. end
  72.  
  73. window.add vbox
  74.  
  75. Gtk.main
Add Comment
Please, Sign In to add comment