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

Constructor Details

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

Returns a new instance of CalendarCol



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



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

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

#am__toggled(*args) ⇒ Object



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

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

#buttonSave__clicked(*args) ⇒ Object



70
71
72
73
74
75
76
# File 'lib/treeview/columns/CalendarCol.rb', line 70

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"].close
end

#each_cell(col, ren, model, iter) ⇒ Object

def to_s

  @date.strftime(@format)
end


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

def each_cell(col, ren, model, iter)
  ren.text = @date.strftime(@format)
end

#pm__toggled(*args) ⇒ Object



66
67
68
# File 'lib/treeview/columns/CalendarCol.rb', line 66

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

#valueObject



83
84
85
# File 'lib/treeview/columns/CalendarCol.rb', line 83

def value
  @date
end