Class: VR::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:

http://visualruby.net/img/calendar.jpg

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::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::CalendarCol)
 row = @view.add_row
 row[:name] = "Eric"
 row[:birthday] = VR::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

#active_record_valid?, #class_name, #destroy_window, #fill_control, #get_glade_active_record, #get_glade_all, #get_glade_variables, #load_glade, #parse_signals, #set_glade_active_record, #set_glade_all, #set_glade_variables, #set_parent, #show_window

Constructor Details

#initialize(datetime, date_format = nil, show_time = true, show_calendar = true) ⇒ CalendarCol

Returns a new instance of CalendarCol.



32
33
34
35
36
37
# File 'lib/treeview/columns/CalendarCol.rb', line 32

def initialize(datetime, date_format = nil, show_time = true, show_calendar = true)
	@show_time = show_time
	@show_calendar = show_calendar
	@date_format = date_format ||= date_format = "%d %b %Y   %I:%M%p"
	@date = datetime
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



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

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

#am__toggled(*args) ⇒ Object

:nodoc:



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

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

#buttonCancel__clicked(*args) ⇒ Object

:nodoc:



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

def buttonCancel__clicked(*args) # :nodoc:
	destroy_window()
end

#buttonSave__clicked(*args) ⇒ Object

:nodoc:



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

def buttonSave__clicked(*args) # :nodoc:
	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)
	destroy_window()
end

#pm__toggled(*args) ⇒ Object

:nodoc:



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

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

#show(show_time = true) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/treeview/columns/CalendarCol.rb', line 39

def show(show_time = true)
	load_glade(__FILE__)			
	@hour = @date.strftime("%I").to_f
	@minute = @date.min()
	@am = (@date.hour < 12)
	@pm = !@am
	set_glade_variables()
	@builder["hboxTime"].hide unless @show_time
	@builder["date"].hide unless @show_calendar
	show_window()
end

#to_sObject

displays time 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(@date_format)
end

#valueObject



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

def value
	@date
end