Module: Alexandria::UI::CalendarPopup

Included in:
BookPropertiesDialogBase, SmartLibraryPropertiesDialogBase
Defined in:
lib/alexandria/ui/calendar_popup.rb

Instance Method Summary collapse

Instance Method Details

#assign_selected_dateObject



28
29
30
31
32
33
34
35
# File 'lib/alexandria/ui/calendar_popup.rb', line 28

def assign_selected_date
  date_arr = @calendar.date
  year = date_arr[0]
  month = date_arr[1] # + 1 # gtk : months 0-indexed, Time.gm : 1-index
  day = date_arr[2]
  time = Time.gm(year, month, day)
  @calendar_popup_for_entry.text = format_date(time)
end

#clear_date_entry(entry) ⇒ Object



37
38
39
# File 'lib/alexandria/ui/calendar_popup.rb', line 37

def clear_date_entry(entry)
  entry.text = ""
end

#display_calendar_popup(entry) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/alexandria/ui/calendar_popup.rb', line 41

def display_calendar_popup(entry)
  setup_calendar_widgets unless defined? @calendar_popup

  @calendar_popup_for_entry = entry
  unless entry.text.strip.empty?
    time = parse_date(entry.text)
    unless time.nil?
      @calendar.year = time.year
      @calendar.month = time.month - 1
      @calendar.day = time.day
    end
  end
  @calendar_popup.set_relative_to(entry)
  @calendar_popup.popup
end

#setup_calendar_widgetsObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/alexandria/ui/calendar_popup.rb', line 10

def setup_calendar_widgets
  @calendar_popup = Gtk::Popover.new
  @calendar_popup.position = :bottom

  @calendar = Gtk::Calendar.new
  @calendar.show
  @calendar_popup.add(@calendar)

  @calendar.signal_connect("day-selected") do
    assign_selected_date
  end

  @calendar.signal_connect("day-selected-double-click") do
    assign_selected_date
    @calendar_popup.hide
  end
end