Class: MyRendererTimeStampButton

Inherits:
Gtk::Button
  • Object
show all
Includes:
Conf, ManqodCommon
Defined in:
lib/FormHolder/Form/InputHolder/TimeStampButton.rb

Overview

this file is part of manqod manqod is distributed under the CDDL licence the author of manqod is Dobai-Pataky Balint([email protected])

Constant Summary

Constants included from ManqodCommon

ManqodCommon::CRITICAL, ManqodCommon::DEBUG, ManqodCommon::ERROR, ManqodCommon::INFO, ManqodCommon::NORMAL, ManqodCommon::WARNING

Constants included from Eprint

Eprint::DOMAIN, Eprint::LEVEL

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Conf

#get_conf, #load_conf, #save_conf, #set_conf

Methods included from ManqodCommon

#add_where, #admin, #admin_cache, #admin_qrow, #admin_rows, #backtrace_to_debug, #cache, #changed_ids_of_base, #client, #client_fields, #client_image_of_id, #client_qrow, #client_query, #client_rows, #eeval, #escape_string, #getBinding, #guess_base, #guess_table, #image_of_id, #lzero, #manqod_db, #measure, #myexec, #nick, #nick_id, #number_format, #qrow, #query, #reconnect_manqod_db, #rows, #run_events, #send_message, #sendmail, #set_manqod_db_uri, #set_nick

Methods included from Eprint

#ecode, #edebug, #eerror, #einfo, #enormal, #eprint, #ewarn, #gtk_set_edebug, #set_edebug, #tell_exception

Constructor Details

#initialize(pc) ⇒ MyRendererTimeStampButton

Returns a new instance of MyRendererTimeStampButton.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/FormHolder/Form/InputHolder/TimeStampButton.rb', line 8

def initialize(pc)
@pc=pc
@timestamp_format=pc.gtk_attribute("timestamp-format") || "%Y-%m-%d %H:%M:%S"
super(item['description'])
@calendar_win=Gtk::Window.new(Gtk::Window::POPUP)
@calendar_win.set_modal(true).set_has_frame(false).add(@box=Gtk::Table.new(5,2)).set_transient_for(@pc.caller.get_ancestor(Gtk::Window))
@box.attach_defaults(@calendar=Gtk::Calendar.new,0,5,0,1).
		attach_defaults(@hw=Gtk::SpinButton.new(0,23,1).set_has_frame(false).set_numeric(true).set_increments(1,10).set_digits(0),0,1,1,2).
 	attach_defaults(@mw=Gtk::SpinButton.new(0,59,1).set_has_frame(false).set_numeric(true).set_increments(1,10).set_digits(0),1,2,1,2).
 	attach_defaults(@sw=Gtk::SpinButton.new(0,59,1).set_has_frame(false).set_numeric(true).set_increments(1,10).set_digits(0),2,3,1,2).
 	attach_defaults(@ok=Gtk::Button.new.set_image(Gtk::Image.new(Gtk::Stock::OK,Gtk::IconSize::MENU)),3,4,1,2).
 	attach_defaults(@cancel=Gtk::Button.new.set_image(Gtk::Image.new(Gtk::Stock::CANCEL,Gtk::IconSize::MENU)),4,5,1,2)

@calendar.set_show_details(true) if @calendar.respond_to?("set_show_details")
@calendar.show_day_names=true

@calendar.signal_connect('day-selected-double-click'){|me| @ok.clicked}
@hw.signal_connect('activate'){|me| @ok.clicked}
@mw.signal_connect('activate'){|me| @ok.clicked}
@sw.signal_connect('activate'){|me| @ok.clicked}
signal_connect('clicked'){|me|
	edebug("#{item['default']} clicked","gtk_button")
	time_to_wg(item['default'])
	x,y=@pc.caller.get_ancestor(Gtk::Window).position
	xd,yd=translate_coordinates(@pc.caller.get_ancestor(Gtk::Window),x,y+allocation.height+allocation.y)
	@calendar_win.move(xd,yd)
	@calendar_win.show_all
}
@ok.signal_connect('clicked'){|me|
	@calendar_win.hide
	item['default']=wg_to_time.to_i
	set_label(wg_to_time.strftime(@timestamp_format))
	edebug("#{self} changed to #{wg_to_time}","form","debug")
	run_events(item['id'],'form_item-Action')
	pc.changed
	pc.notify_observers(self)
	edebug("#{self} emiting 'changed' to observers","form","debug")
	run_events(item['id'],'form_item-Action')
}
@cancel.signal_connect('clicked'){|me|
	@calendar_win.hide
}
end

Instance Attribute Details

#pcObject

Returns the value of attribute pc.



51
52
53
# File 'lib/FormHolder/Form/InputHolder/TimeStampButton.rb', line 51

def pc
  @pc
end

Instance Method Details

#itemObject



89
# File 'lib/FormHolder/Form/InputHolder/TimeStampButton.rb', line 89

def item;pc.item;end

#parentMObject



87
# File 'lib/FormHolder/Form/InputHolder/TimeStampButton.rb', line 87

def parentM;pc.parentM;end

#targetObject



88
# File 'lib/FormHolder/Form/InputHolder/TimeStampButton.rb', line 88

def target;item['to_call'];end

#textObject



63
64
65
# File 'lib/FormHolder/Form/InputHolder/TimeStampButton.rb', line 63

def text
	wg_to_time.to_i.to_s
end

#time_to_wg(d = text) ⇒ Object



78
79
80
81
82
83
84
# File 'lib/FormHolder/Form/InputHolder/TimeStampButton.rb', line 78

def time_to_wg(d=text)
	t=Time.at(d.to_i)
	@hw.set_value(t.hour)
	@mw.set_value(t.min)
	@sw.set_value(t.sec)
	@calendar.set_year(t.year).set_month(t.month-1).set_day(t.day).mark_day(t.day)
end

#to_sObject



90
# File 'lib/FormHolder/Form/InputHolder/TimeStampButton.rb', line 90

def to_s;"TimeStampButton(#{item['description']})";end

#update(new_value = ) ⇒ Object



53
54
55
56
57
58
59
60
61
# File 'lib/FormHolder/Form/InputHolder/TimeStampButton.rb', line 53

def update(new_value=item['default'])
	new_value=Time.new.to_i if new_value == ""
	item['default']=new_value
	run_events(item['id'],'form_item-BeforeUpdate')
	pc.run_query
	time_to_wg(item['default'])
	set_label(wg_to_time.strftime(@timestamp_format))
	run_events(item['id'],'form_item-AfterUpdate')
end

#wg_to_timeObject



67
68
69
70
71
72
73
74
75
76
77
# File 'lib/FormHolder/Form/InputHolder/TimeStampButton.rb', line 67

def wg_to_time
	begin
		@hw.update
		@mw.update
		@sw.update
		Time.mktime(@calendar.date[0],@calendar.date[1],@calendar.date[2],@hw.value,@mw.value,@sw.value)
	rescue => err
		eerror(err)
		Time.new
	end
end