class MyRendererTimeStampButton

this file is part of manqod manqod is distributed under the CDDL licence the author of manqod is Dobai-Pataky Balint(dpblnt@gmail.com)

Attributes

pc[RW]

Public Class Methods

new(pc) click to toggle source
Calls superclass method
# 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

Public Instance Methods

item() click to toggle source
# File lib/FormHolder/Form/InputHolder/TimeStampButton.rb, line 89
def item;pc.item;end
parentM() click to toggle source
# File lib/FormHolder/Form/InputHolder/TimeStampButton.rb, line 87
def parentM;pc.parentM;end
target() click to toggle source
# File lib/FormHolder/Form/InputHolder/TimeStampButton.rb, line 88
def target;item['to_call'];end
text() click to toggle source
# File lib/FormHolder/Form/InputHolder/TimeStampButton.rb, line 63
def text
        wg_to_time.to_i.to_s
end
time_to_wg(d=text) click to toggle source
# 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_s() click to toggle source
# File lib/FormHolder/Form/InputHolder/TimeStampButton.rb, line 90
def to_s;"TimeStampButton(#{item['description']})";end
update(new_value=item['default']) click to toggle source
# 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_time() click to toggle source
# 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