Class: GtkAdventCalendar::Calendar
- Inherits:
-
Gtk::Frame
- Object
- Gtk::Frame
- GtkAdventCalendar::Calendar
- Defined in:
- lib/gtk_advent_calendar/calendar.rb
Constant Summary collapse
- LAST_DAY =
25- CELL_WIDTH =
40
Instance Method Summary collapse
- #day(n) ⇒ Object
- #days_of_the_week ⇒ Object
-
#initialize ⇒ Calendar
constructor
A new instance of Calendar.
- #month ⇒ Object
- #show_uri(uri) ⇒ Object
- #week ⇒ Object
Constructor Details
#initialize ⇒ Calendar
Returns a new instance of Calendar.
8 9 10 11 12 13 14 |
# File 'lib/gtk_advent_calendar/calendar.rb', line 8 def initialize super @day = 1 box = Gtk::Box.new(:vertical) box.add(month) add(box) end |
Instance Method Details
#day(n) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/gtk_advent_calendar/calendar.rb', line 45 def day(n) = Gtk::Button.new(:label => n.to_s) .width_request = CELL_WIDTH .height_request = CELL_WIDTH .signal_connect("clicked") do show_uri("http://en.wikipedia.org/wiki/December_#{n}") end end |
#days_of_the_week ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/gtk_advent_calendar/calendar.rb', line 25 def days_of_the_week box = Gtk::Box.new(:horizontal) %w(Sun Mon Tue Wed Thu Fri Sat).each do |day_of_the_week| label = Gtk::Label.new("#{day_of_the_week}.") label.width_request = CELL_WIDTH box.add(label) end box end |
#month ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/gtk_advent_calendar/calendar.rb', line 16 def month box = Gtk::Box.new(:vertical) box.add(days_of_the_week) while @day <= LAST_DAY do box.add(week) end box end |
#show_uri(uri) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/gtk_advent_calendar/calendar.rb', line 55 def show_uri(uri) case RUBY_PLATFORM when /darwin/ system("open", uri) when /mswin|mingw|cygwin|bccwin/ system("start", uri) else if Gtk.respond_to?(:show_uri) Gtk.show_uri(uri) else system("firefox", uri) end end end |
#week ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/gtk_advent_calendar/calendar.rb', line 35 def week box = Gtk::Box.new(:horizontal) 7.times do break if @day > LAST_DAY box.add(day(@day)) @day += 1 end box end |