Class: Gtk::GObject

Inherits:
Object
  • Object
show all
Defined in:
lib/gtk.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ GObject

Returns a new instance of GObject.



101
102
103
104
# File 'lib/gtk.rb', line 101

def initialize *args
  raise "hell" unless args.size == 1 && args.first.is_a?(FFI::Pointer)
  @native = args.first
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/gtk.rb', line 128

def method_missing method,*args
  method = "set_#{method.to_s[0..-2]}".to_sym if method.to_s[-1] == '='

  getter = "get_#{method}".to_sym
  klass = self.class
  while klass
    raise "hell #{method} #{self.inspect}" if klass == Object
    return send(getter,*args) if respond_to?(getter)

    name = "gtk_#{klass.name.split('::').last.underscore}_#{method}".to_sym
    getter_name = "gtk_#{klass.name.split('::').last.underscore}_#{getter}".to_sym
    if m = (Lib.attached_methods[name] || Lib.attached_methods[getter_name])
      raise "#{self.class.name}: #{method}" unless m
      if m[:args].last == :varargs
        raise ArgumentError.new unless m[:args].size <= (args.size+1)
      else
        raise ArgumentError.new unless m[:args].size == (args.size+1)
      end

      types = m[:args][1..-1]
      args = args.map do |arg|
        type = types.shift
        if arg.is_a?(GObject)
          arg.native
        elsif arg.is_a?(Symbol) && type.respond_to?(:superclass) && type.superclass == Enums
          type[arg]
        else
          arg
        end
      end

      return Lib.send(m[:name],@native,*args)
    end
    klass = klass.superclass
  end
end

Instance Attribute Details

#nativeObject

Returns the value of attribute native.



99
100
101
# File 'lib/gtk.rb', line 99

def native
  @native
end

#typeObject

Returns the value of attribute type.



99
100
101
# File 'lib/gtk.rb', line 99

def type
  @type
end

Class Method Details

.type_registerObject



106
107
108
109
110
111
112
113
114
115
# File 'lib/gtk.rb', line 106

def self.type_register
  type_name = name.gsub(/::/,'__')
  cell_progress_info = Lib::GTypeInfo.new
  @type = Lib.g_type_register_static(
    superclass.type,
    type_name,
    cell_progress_info.ref,
    0
  )
end

Instance Method Details

#signal_connect(name, &block) ⇒ Object



117
118
119
120
121
122
# File 'lib/gtk.rb', line 117

def signal_connect(name,&block)
  callback = FFI::Function.new(:void, [:pointer]) do |data|
    block.call
  end
  Lib.g_signal_connect_data(native,name,callback,nil,nil,0)
end

#unrefObject



124
125
126
# File 'lib/gtk.rb', line 124

def unref
  Lib.g_object_unref(native)
end