class Gtk::Builder

Public Class Methods

connect_signal(builder, object, signal_name, handler_name, connect_object, flags, &block) click to toggle source
# File lib/gtk3/builder.rb, line 20
def connect_signal(builder,
                   object,
                   signal_name,
                   handler_name,
                   connect_object,
                   flags,
                   &block)
  handler_name = normalize_handler_name(handler_name)
  if connect_object
    handler = connect_object.method(handler_name)
  else
    handler = block.call(handler_name)
  end

  unless handler
    $stderr.puts("Undefined handler: #{handler_name}") if $DEBUG
    return
  end

  if flags.is_a?(Integer)
    flags = GLib::ConnectFlags.new(flags)
  end

  if flags.after?
    signal_connect_method = :signal_connect_after
  else
    signal_connect_method = :signal_connect
  end

  if handler.arity.zero?
    object.__send__(signal_connect_method, signal_name) do
      handler.call
    end
  else
    object.__send__(signal_connect_method, signal_name, &handler)
  end
end
new(options={}) click to toggle source
# File lib/gtk3/builder.rb, line 65
def initialize(options={})
  path      = options[:path] || options[:file]
  resource  = options[:resource]
  string    = options[:string]

  if path
    path = path.to_path if path.respond_to?(:to_path)
    initialize_new_from_file(path)
  elsif resource
    initialize_new_from_resource(resource)
  elsif string
    initialize_new_from_string(string, string.bytesize)
  else
    initialize_raw
  end
end
Also aliased as: initialize_raw

Private Class Methods

normalize_handler_name(name) click to toggle source
# File lib/gtk3/builder.rb, line 59
def normalize_handler_name(name)
  name.gsub(/[-\s]+/, "_")
end

Public Instance Methods

<<(target) click to toggle source
# File lib/gtk3/builder.rb, line 143
def <<(target)
  add(target)
  self
end
add(target_or_options={}) click to toggle source
# File lib/gtk3/builder.rb, line 94
def add(target_or_options={})
  if target_or_options.is_a?(Hash)
    options = target_or_options
  else
    target = target_or_options
    options = {}
    if target.respond_to?(:to_path)
      options[:path] = target.to_path
    elsif target.start_with?("<") or target.start_with?(" ")
      options[:string] = target
    elsif File.exist?(target)
      options[:path] = target
    else
      options[:resource] = target
    end
  end

  string   = options[:string]
  path     = options[:path] || options[:file]
  resource = options[:resource]

  object_ids = options[:object_ids]

  if path
    path = path.to_path if path.respond_to?(:to_path)
    if object_ids
      add_objects_from_file(path, object_ids)
    else
      add_from_file(path)
    end
  elsif resource
    if object_ids
      add_objects_from_resource(resource, object_ids)
    else
      add_from_resource(resource)
    end
  elsif string
    if object_ids
      add_objects_from_string(string, object_ids)
    else
      add_from_string(string)
    end
  else
    message = ":path (:file), :resource or :string " +
      "must be specified: #{options.inspect}"
    raise InvalidArgument, message
  end
end
add_from_string(string) click to toggle source
# File lib/gtk3/builder.rb, line 85
def add_from_string(string)
  add_from_string_raw(string, string.bytesize)
end
Also aliased as: add_from_string_raw
add_from_string_raw(string)
Alias for: add_from_string
add_objects_from_string(string, object_ids) click to toggle source
# File lib/gtk3/builder.rb, line 90
def add_objects_from_string(string, object_ids)
  add_objects_from_string_raw(string, string.bytesize, object_ids)
end
Also aliased as: add_objects_from_string_raw
add_objects_from_string_raw(string, object_ids)
connect_signals(&block) click to toggle source
# File lib/gtk3/builder.rb, line 149
def connect_signals(&block)
  connect_signals_raw do |*args|
    self.class.connect_signal(*args, &block)
  end
end
Also aliased as: connect_signals_raw
connect_signals_raw(&block)
Alias for: connect_signals
initialize_raw(options={})
Alias for: new