Class: Tk::Event::Data

Inherits:
Struct
  • Object
show all
Defined in:
lib/ffi-tk/event/data.rb,
lib/ffi-tk/event/data.rb

Constant Summary collapse

PROPERTIES =
[
  ['%#', :Integer, :serial],
  ['%b', :Integer, :button],
  ['%c', :Integer, :count],
  ['%d', :String,  :detail],
  ['%f', :String,  :focus],
  ['%h', :Integer, :height],
  ['%i', :String,  :window],
  ['%k', :Integer, :keycode],
  ['%m', :String,  :mode],
  ['%o', :String,  :override_redirect],
  ['%p', :String,  :place],
  ['%s', :String,  :state],
  ['%t', :Integer, :time],
  ['%w', :Integer, :width],
  ['%x', :Integer, :x],
  ['%y', :Integer, :y],
  ['%A', :String,  :unicode],
  ['%B', :Integer, :border_width],
  ['%D', :Integer, :mousewheel_delta],
  ['%E', :Integer, :send_event],
  ['%K', :String,  :keysym],
  ['%N', :Integer, :keysym_number],
  ['%P', :String,  :property],
  ['%R', :String,  :root],
  ['%S', :String,  :subwindow],
  ['%T', :Integer, :type],
  ['%W', :String,  :window_path],
  ['%X', :Integer, :x_root],
  ['%Y', :Integer, :y_root]
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, pattern, *properties) ⇒ Data

Returns a new instance of Data.



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/ffi-tk/event/data.rb', line 45

def initialize(id, pattern, *properties)
  super id, pattern

  PROPERTIES.each do |_code, conv, name|
    value = properties.shift
    converted = String(value)
    next if converted == '??'
    converted = __send__(conv, value)
    self[name] = converted
  end
end

Instance Attribute Details

#border_widthObject

Returns the value of attribute border_width

Returns:

  • (Object)

    the current value of border_width



4
5
6
# File 'lib/ffi-tk/event/data.rb', line 4

def border_width
  @border_width
end

#buttonObject

Returns the value of attribute button

Returns:

  • (Object)

    the current value of button



4
5
6
# File 'lib/ffi-tk/event/data.rb', line 4

def button
  @button
end

#countObject

Returns the value of attribute count

Returns:

  • (Object)

    the current value of count



4
5
6
# File 'lib/ffi-tk/event/data.rb', line 4

def count
  @count
end

#detailObject

Returns the value of attribute detail

Returns:

  • (Object)

    the current value of detail



4
5
6
# File 'lib/ffi-tk/event/data.rb', line 4

def detail
  @detail
end

#focusObject

Returns the value of attribute focus

Returns:

  • (Object)

    the current value of focus



4
5
6
# File 'lib/ffi-tk/event/data.rb', line 4

def focus
  @focus
end

#heightObject

Returns the value of attribute height

Returns:

  • (Object)

    the current value of height



4
5
6
# File 'lib/ffi-tk/event/data.rb', line 4

def height
  @height
end

#idObject

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



4
5
6
# File 'lib/ffi-tk/event/data.rb', line 4

def id
  @id
end

#keycodeObject

Returns the value of attribute keycode

Returns:

  • (Object)

    the current value of keycode



4
5
6
# File 'lib/ffi-tk/event/data.rb', line 4

def keycode
  @keycode
end

#keysymObject

Returns the value of attribute keysym

Returns:

  • (Object)

    the current value of keysym



4
5
6
# File 'lib/ffi-tk/event/data.rb', line 4

def keysym
  @keysym
end

#keysym_numberObject

Returns the value of attribute keysym_number

Returns:

  • (Object)

    the current value of keysym_number



4
5
6
# File 'lib/ffi-tk/event/data.rb', line 4

def keysym_number
  @keysym_number
end

#modeObject

Returns the value of attribute mode

Returns:

  • (Object)

    the current value of mode



4
5
6
# File 'lib/ffi-tk/event/data.rb', line 4

def mode
  @mode
end

#mousewheel_deltaObject

Returns the value of attribute mousewheel_delta

Returns:

  • (Object)

    the current value of mousewheel_delta



4
5
6
# File 'lib/ffi-tk/event/data.rb', line 4

def mousewheel_delta
  @mousewheel_delta
end

#override_redirectObject

Returns the value of attribute override_redirect

Returns:

  • (Object)

    the current value of override_redirect



4
5
6
# File 'lib/ffi-tk/event/data.rb', line 4

def override_redirect
  @override_redirect
end

#patternObject

Returns the value of attribute pattern

Returns:

  • (Object)

    the current value of pattern



4
5
6
# File 'lib/ffi-tk/event/data.rb', line 4

def pattern
  @pattern
end

#placeObject

Returns the value of attribute place

Returns:

  • (Object)

    the current value of place



4
5
6
# File 'lib/ffi-tk/event/data.rb', line 4

def place
  @place
end

#propertyObject

Returns the value of attribute property

Returns:

  • (Object)

    the current value of property



4
5
6
# File 'lib/ffi-tk/event/data.rb', line 4

def property
  @property
end

#rootObject

Returns the value of attribute root

Returns:

  • (Object)

    the current value of root



4
5
6
# File 'lib/ffi-tk/event/data.rb', line 4

def root
  @root
end

#send_eventObject

Returns the value of attribute send_event

Returns:

  • (Object)

    the current value of send_event



4
5
6
# File 'lib/ffi-tk/event/data.rb', line 4

def send_event
  @send_event
end

#serialObject

Returns the value of attribute serial

Returns:

  • (Object)

    the current value of serial



4
5
6
# File 'lib/ffi-tk/event/data.rb', line 4

def serial
  @serial
end

#stateObject

Returns the value of attribute state

Returns:

  • (Object)

    the current value of state



4
5
6
# File 'lib/ffi-tk/event/data.rb', line 4

def state
  @state
end

#subwindowObject

Returns the value of attribute subwindow

Returns:

  • (Object)

    the current value of subwindow



4
5
6
# File 'lib/ffi-tk/event/data.rb', line 4

def subwindow
  @subwindow
end

#timeObject

Returns the value of attribute time

Returns:

  • (Object)

    the current value of time



4
5
6
# File 'lib/ffi-tk/event/data.rb', line 4

def time
  @time
end

#typeObject

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



4
5
6
# File 'lib/ffi-tk/event/data.rb', line 4

def type
  @type
end

#unicodeObject

Returns the value of attribute unicode

Returns:

  • (Object)

    the current value of unicode



4
5
6
# File 'lib/ffi-tk/event/data.rb', line 4

def unicode
  @unicode
end

#widthObject

Returns the value of attribute width

Returns:

  • (Object)

    the current value of width



4
5
6
# File 'lib/ffi-tk/event/data.rb', line 4

def width
  @width
end

#windowObject

Returns the value of attribute window

Returns:

  • (Object)

    the current value of window



4
5
6
# File 'lib/ffi-tk/event/data.rb', line 4

def window
  @window
end

#window_pathObject

Returns the value of attribute window_path

Returns:

  • (Object)

    the current value of window_path



4
5
6
# File 'lib/ffi-tk/event/data.rb', line 4

def window_path
  @window_path
end

#xObject

Returns the value of attribute x

Returns:

  • (Object)

    the current value of x



4
5
6
# File 'lib/ffi-tk/event/data.rb', line 4

def x
  @x
end

#x_rootObject

Returns the value of attribute x_root

Returns:

  • (Object)

    the current value of x_root



4
5
6
# File 'lib/ffi-tk/event/data.rb', line 4

def x_root
  @x_root
end

#yObject

Returns the value of attribute y

Returns:

  • (Object)

    the current value of y



4
5
6
# File 'lib/ffi-tk/event/data.rb', line 4

def y
  @y
end

#y_rootObject

Returns the value of attribute y_root

Returns:

  • (Object)

    the current value of y_root



4
5
6
# File 'lib/ffi-tk/event/data.rb', line 4

def y_root
  @y_root
end

Instance Method Details

#callObject



57
58
59
# File 'lib/ffi-tk/event/data.rb', line 57

def call
  Handler.invoke(id, self) if id
end

#resend(widget, virtual, changes = {}) ⇒ Object

Try to resend the event with as much information preserved as possible. Unfortunately that doesn’t seem to be easy.



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/ffi-tk/event/data.rb', line 63

def resend(widget, virtual, changes = {})
  original = {}
  members.each do |name|
    value = self[name]

    case name
    when :id, :pattern, :border_width, :button, :count, :focus, :height,
      :keycode, :keysym, :keysym_number, :mode, :mousewheel_delta,
      :override_redirect, :place, :property, :root, :send_event,
      :subwindow, :type, :unicode, :width, :window, :window_path
    when :x_root
      original[:rootx] = value
    when :y_root
      original[:rooty] = value
    when :detail
      original[name] = value if value
    else
      original[name] = value
    end
  end

  Event.generate(widget, virtual, original.merge(changes))
end

#sequenceObject



91
92
93
94
# File 'lib/ffi-tk/event/data.rb', line 91

def sequence
  Kernel.warn("#{self.class}.sequence deprecated, use #{self.class}.pattern")
  pattern
end

#widgetObject



87
88
89
# File 'lib/ffi-tk/event/data.rb', line 87

def widget
  Tk.widgets[window_path]
end