Module | TkEvent
In: | tk/lib/tk/event.rb

### Methods

generate valid_fields valid_for_generate

### Classes and Modules

Class TkEvent::Event

### Constants

KEY_TBL | = | [ [ ?#, ?n, :serial ], [ ?a, ?s, :above ], [ ?b, ?n, :num ], [ ?c, ?n, :count ], [ ?d, ?s, :detail ], [ ?f, ?b, :focus ], [ ?h, ?n, :height ], [ ?i, ?s, :win_hex ], [ ?k, ?n, :keycode ], [ ?m, ?s, :mode ], [ ?o, ?b, :override ], [ ?p, ?s, :place ], [ ?s, ?x, :state ], [ ?t, ?n, :time ], [ ?w, ?n, :width ], [ ?x, ?n, :x ], [ ?y, ?n, :y ], [ ?A, ?s, :char ], [ ?B, ?n, :borderwidth ], [ ?D, ?n, :wheel_delta ], [ ?E, ?b, :send_event ], [ ?K, ?s, :keysym ], [ ?N, ?n, :keysym_num ], [ ?P, ?s, :property ], [ ?R, ?s, :rootwin_id ], [ ?S, ?s, :subwindow ], [ ?T, ?n, :type ], [ ?W, ?w, :widget ], [ ?X, ?n, :x_root ], [ ?Y, ?n, :y_root ], nil |  | [ <’%’ subst-key char>, <proc type char>, <instance var (accessor) name>]
PROC_TBL | = | [ [ ?n, TkComm.method(:num_or_str) ], [ ?s, TkComm.method(:string) ], [ ?b, TkComm.method(:bool) ], [ ?w, TkComm.method(:window) ], [ ?x, proc{|val| begin TkComm::number(val) |  | [ <proc type char>, <proc/method to convert tcl-str to ruby-obj>]

### Public Instance methods

generate(win, modkeys={})

[Source]

    # File tk/lib/tk/event.rb, line 249
        def generate(win, modkeys={})
          klass = self.class

          if modkeys.has_key?(:type) || modkeys.has_key?('type')
            modkeys = TkComm._symbolkey2str(modkeys)
            type_id = modkeys.delete('type')
          else
            type_id = self.type
          end

          type_name  = klass.type_name(type_id)
          unless type_name
            fail RuntimeError, "type_id #{type_id} is invalid"
          end

          group_flag = klass.group_flag(type_id)

          opts = valid_for_generate(group_flag)

          modkeys.each{|key, val|
            if val
              opts[key.to_s] = val
            else
              opts.delete(key.to_s)
            end
          }

          if group_flag != Grp::KEY
            Tk.event_generate(win, type_name, opts)
          else
            # If type is KEY event, focus should be set to target widget.
            # If not set, original widget will get the same event.
            # That will make infinite loop.
            w = Tk.tk_call_without_enc('focus')
            begin
              Tk.tk_call_without_enc('focus', win)
              Tk.event_generate(win, type_name, opts)
            ensure
              Tk.tk_call_without_enc('focus', w)
            end
          end
        end

valid_fields(group_flag=nil)

[Source]

    # File tk/lib/tk/event.rb, line 215
        def valid_fields(group_flag=nil)
          group_flag = self.class.group_flag(self.type) unless group_flag

          fields = {}
          FIELD_FLAG.each{|key, flag|
            next if (flag & group_flag) == 0
            begin
              val = self.__send__(key)
            rescue
              next
            end
            next if !val || val == '??'
            fields[key] = val
          }

          fields
        end

valid_for_generate(group_flag=nil)

[Source]

    # File tk/lib/tk/event.rb, line 233
        def valid_for_generate(group_flag=nil)
          fields = valid_fields(group_flag)

          FIELD_OPERATION.each{|key, cmd|
            next unless fields.has_key?(key)
            val = FIELD_OPERATION[key].call(fields[key])
            if val
              fields[key] = val
            else
              fields.delete(key)
            end
          }

          fields
        end

[Validate]