Class: GtkAdventCalendar::Calendar

Inherits:
Gtk::Frame
  • Object
show all
Defined in:
lib/gtk_advent_calendar/calendar.rb

Constant Summary collapse

LAST_DAY =
25
CELL_WIDTH =
40

Instance Method Summary collapse

Constructor Details

#initializeCalendar

Returns a new instance of Calendar.



8
9
10
11
12
13
14
15
# File 'lib/gtk_advent_calendar/calendar.rb', line 8

def initialize
  super
  @day = 1
  box = Gtk::Box.new(:vertical)
  box.add(Gtk::Label.new)
  box.add(month)
  add(box)
end

Instance Method Details

#day(n) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/gtk_advent_calendar/calendar.rb', line 46

def day(n)
  button = Gtk::Button.new(:label => n.to_s)
  button.width_request = CELL_WIDTH
  button.height_request = CELL_WIDTH
  button.signal_connect("clicked") do
    show_uri("http://ja.wikipedia.org/wiki/12%E6%9C%88#{n}%E6%97%A5")
  end
  button
end

#days_of_the_weekObject



26
27
28
29
30
31
32
33
34
# File 'lib/gtk_advent_calendar/calendar.rb', line 26

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

#monthObject



17
18
19
20
21
22
23
24
# File 'lib/gtk_advent_calendar/calendar.rb', line 17

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



56
57
58
59
60
61
62
63
64
65
# File 'lib/gtk_advent_calendar/calendar.rb', line 56

def show_uri(uri)
  case RUBY_PLATFORM
  when /darwin/
    system("open", uri)
  when /mswin|mingw|cygwin|bccwin/
    system("start", uri)
  else
    system("firefox", uri)
  end
end

#weekObject



36
37
38
39
40
41
42
43
44
# File 'lib/gtk_advent_calendar/calendar.rb', line 36

def week
  box = Gtk::Box.new(:horizontal)
  7.times do
    break if @day > LAST_DAY
    box.add(day(@day))
    @day += 1
  end
  box
end