Class: VR::Col::CalendarCol

Inherits:
Object
  • Object
show all
Includes:
GladeGUI
Defined in:
lib/treeview/columns/CalendarCol.rb

Overview

The CalendarCol class is a simple calendar window where you can edit the date:

This class is very useful when you want to display and edit dates in a VR::ListView. You can define a column with the type VR::Col::CalendarCol and the column will display as a date, and when the user clicks on the date, a calendar window will appear so he/she can edit it:

@view = VR::ListView.new(:name => String, :birthday => VR::Col::CalendarCol)
row = @view.add_row
row[:name] = "Eric"
row[:birthday] = VR::Col::CalendarCol.new(DateTime.new(1966, 7, 14))

See the example project, “listview_objects” for more.

Instance Attribute Summary collapse

Attributes included from GladeGUI

#builder

Instance Method Summary collapse

Methods included from GladeGUI

#buttonCancel__clicked, #extract_key, #get_glade_active_record, #get_glade_all, #get_glade_variables, #load_glade, #parse_signals, #set_drag_drop, #set_glade_active_record, #set_glade_all, #set_glade_hash, #set_glade_variables, #try_to_select_text_in_combobox, #window1__destroy, #window1__key_press_event

Constructor Details

#initialize(datetime, flags = {}) ⇒ CalendarCol

  • datetime - Instance of DateTime class that holds the date value.

  • date_format - String that holds the Ruby date format. Default: “%d %b %Y %I:%M%p”

  • show_time - true/false If this is false, the time will not appear in the edit window.

  • show_calendar - true/false If this is false, Calendar will not appear. Only time will edit.



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/treeview/columns/CalendarCol.rb', line 32

def initialize(datetime, flags = {})  #flags = :hide_date => true, hide_time => true, :format => "%d %b %Y   %I:%M%p"
  @format = flags[:format]
  @format ||= flags[:hide_date] ? "%I:%M%p" : "%d %b %Y   %I:%M%p"
  @format ||= flags[:hide_time] ? "%d %b %Y" : @date_format
  @hide_date = flags[:hide_date]
  @hide_time = flags[:hide_time]
  @show_calendar = show_calendar
  @date = datetime
  @hour = @date.strftime("%I").to_f
  @minute = @date.min()
  @am = (@date.hour < 12)
  @pm = !@am
end

Instance Attribute Details

#dateObject

Returns the value of attribute date



25
26
27
# File 'lib/treeview/columns/CalendarCol.rb', line 25

def date
  @date
end

#date_formatObject

Returns the value of attribute date_format



25
26
27
# File 'lib/treeview/columns/CalendarCol.rb', line 25

def date_format
  @date_format
end

#show_calendarObject

Returns the value of attribute show_calendar



25
26
27
# File 'lib/treeview/columns/CalendarCol.rb', line 25

def show_calendar
  @show_calendar
end

#show_timeObject

Returns the value of attribute show_time



25
26
27
# File 'lib/treeview/columns/CalendarCol.rb', line 25

def show_time
  @show_time
end

Instance Method Details

#<=>(calendar) ⇒ Object

Used for sorting in ListView



75
76
77
# File 'lib/treeview/columns/CalendarCol.rb', line 75

def <=>(calendar)
  return @date <=> calendar.date
end

#am__toggled(*args) ⇒ Object



58
59
60
# File 'lib/treeview/columns/CalendarCol.rb', line 58

def am__toggled(*args)
  @builder["pm"].active = !@builder["am"].active?
end

#buttonSave__clicked(*args) ⇒ Object



66
67
68
69
70
71
72
# File 'lib/treeview/columns/CalendarCol.rb', line 66

def buttonSave__clicked(*args) 
  get_glade_variables()
  m = @builder["am"].active? ? "AM" : "PM"
  t = DateTime.strptime("#{@hour.to_i.to_s} #{@minute.to_i.to_s} #{m}", "%I %M %p")
  @date = DateTime.new(@date.year, @date.month, @date.day, t.hour, t.min, 0)
  @builder["window1"].destroy
end

#pm__toggled(*args) ⇒ Object



62
63
64
# File 'lib/treeview/columns/CalendarCol.rb', line 62

def pm__toggled(*args)
  @builder["am"].active = !@builder["pm"].active? 
end

#show_glade(parent = nil) ⇒ Object



46
47
48
49
50
# File 'lib/treeview/columns/CalendarCol.rb', line 46

def show_glade(parent = nil)
  super      
  @builder["hboxTime"].hide if @hide_time
  @builder["date"].hide if @hide_date
end

#to_sObject

Output shown in ListView according to the @date_format instance variable. If you want to change the appearance of this object, assign a new vale to @date_format.



54
55
56
# File 'lib/treeview/columns/CalendarCol.rb', line 54

def to_s
  @date.strftime(@format)
end

#valueObject



79
80
81
# File 'lib/treeview/columns/CalendarCol.rb', line 79

def value
  @date
end