Last Updated: February 25, 2016
·
413
· blazeeboy

An alarm to tell you to go home with ruby and GTK

this script is rather simple one, it will wait until you finish work then show a window with a funny text that tells you to go home and enjoy your life.
this script will me very useful if you put it in your login scripts on your working laptop, this will make you know when will your official working hours are done and you're ready to go home.
this will work for flexible working hours as some companies tells you come in a certain hours adn you should leave after 8 hours of this time.
have fun guys :D

Gist : https://github.com/blazeeboy/RubyScripts/tree/master/2014-06-23

#!/usr/bin/env ruby
# Author : Emad Elsaid (https://github.com/blazeeboy)

require 'gtk2' # gem install gtk2

# lets define some constants we need
WORKING_HOURS = 8 # hours
WORKING_SECONDS = WORKING_HOURS * 60 * 60
ALERT = "Your working hours have been ended,\n go out and enjoy your life."

# we'll inherit the Gtk window
# and make our custom behaviour inside it
class WorkEndWindow < Gtk::Window

  # set some window properties
  # and insert a label with the desired text
  # then link the window destroy event with a
  # method to exit the application
  def initialize
    super

    self.title = ':D'
    self.border_width = 20
    self.window_position = Gtk::Window::POS_CENTER_ALWAYS

    add Gtk::Label.new ALERT
    signal_connect("destroy") { Gtk.main_quit }
    show_all
  end
end

# this will wait for you to finish work and 
# then pops up the amazing window that will
# tell you to go home ^_^ 
# it will create a window then start 
# the Gtk main loop
sleep WORKING_SECONDS
WorkEndWindow.new
Gtk.main