Parent

Class/Module Index [+]

Quicksearch

Object

Constants

DATA
DEMO_RECT_ITEM
DEMO_TEXT_ITEM
DEMO_WIDGET_ITEM
EXECUTE
FONT
Moves
N_COLS
N_GROUP_COLS

the values behind the comments are the ones used in the C version but as with them it takes more than 20 sec on my computer for the window to show upm I decreased them a little

N_GROUP_ROWS
N_ROWS
N_WORDS
ONLY_ONE
OptionMenuItem
PADDING
PIPELINE_NAME
PIXBUF_COLUMN
RADIUS
Rectangle
SUBDIRS
ShapesSample
TEXT_COLUMN
T_APPLICATION
T_COMBO_EDITABLE
T_COMBO_HAS_ENTRY
T_COMBO_MODEL
T_COMBO_TEXT
T_COMBO_TEXT_COLUMN
URI

Create bookmarkfile data.

XML_FILE

Public Instance Methods

add_button(hbox, button_name, &click_action) click to toggle source
# File goocanvas/sample/widgets-demo.rb, line 41
def add_button(hbox, button_name, &click_action)
  w = Gtk::Button.new(button_name)
  hbox.pack_start(w, false, false, 0)
  w.show
  w.signal_connect('clicked', &click_action)
end
add_depend_package(target_name, target_srcdir, top_srcdir, options={}) click to toggle source

add_depend_package("glib2", "ext/glib2", "/...../ruby-gnome2")

# File glib2/lib/mkmf-gnome2.rb, line 111
def add_depend_package(target_name, target_srcdir, top_srcdir, options={})
  gem_spec = find_gem_spec(target_name)
  if gem_spec
    target_source_dir = File.join(gem_spec.full_gem_path, "ext/#{target_name}")
    target_build_dir = target_source_dir
    add_depend_package_path(target_name,
                       target_source_dir,
                       target_build_dir)
  end

  [top_srcdir,
   File.join(top_srcdir, target_name),
   $configure_args['--topdir'],
   File.join($configure_args['--topdir'], target_name)].each do |topdir|
    topdir = File.expand_path(topdir)
    target_source_dir_full_path = File.join(topdir, target_srcdir)

    top_build_dir = options[:top_build_dir] || topdir
    target_build_dir = options[:target_build_dir] || target_srcdir
    target_build_dir_full_path = File.join(top_build_dir, target_build_dir)
    unless File.exist?(target_build_dir_full_path)
      target_build_dir_full_path = File.join(top_build_dir, target_srcdir)
    end
    unless File.exist?(target_build_dir_full_path)
      target_build_dir_full_path = File.join(topdir, target_build_dir)
    end
    unless File.exist?(target_build_dir_full_path)
      target_build_dir_full_path = File.join(topdir, target_srcdir)
    end
    add_depend_package_path(target_name,
                            target_source_dir_full_path,
                            target_build_dir_full_path)
  end
end
add_depend_package_path(target_name, target_source_dir, target_build_dir) click to toggle source
# File glib2/lib/mkmf-gnome2.rb, line 146
def add_depend_package_path(target_name, target_source_dir, target_build_dir)
  if File.exist?(target_source_dir)
    $INCFLAGS = "-I#{target_source_dir} #{$INCFLAGS}"
  end

  return unless File.exist?(target_build_dir)
  if target_source_dir != target_build_dir
    $INCFLAGS = "-I#{target_build_dir} #{$INCFLAGS}"
  end

  case RUBY_PLATFORM
  when /cygwin|mingw|mswin32/
    case RUBY_PLATFORM
    when /cygwin|mingw/
      $LDFLAGS << " -L#{target_build_dir}"
      $libs << " -lruby-#{target_name}"
    when /mswin32/
      $DLDFLAGS << " /libpath:#{target_build_dir}"
      $libs << " libruby-#{target_name}.lib"
    end
    target_base_dir = Pathname.new(target_source_dir).parent.parent
    target_binary_base_dir = target_base_dir + "vendor" + "local"
    if target_binary_base_dir.exist?
      $INCFLAGS = "-I#{target_binary_base_dir}/include #{$INCFLAGS}"
      target_pkg_config_dir = target_binary_base_dir + "lib" + "pkgconfig"
      PKGConfig.add_path(target_pkg_config_dir.to_s)
    end
  end
end
add_distcleanfile(file) click to toggle source
# File glib2/lib/mkmf-gnome2.rb, line 176
def add_distcleanfile(file)
  $distcleanfiles ||= []
  $distcleanfiles << file
end
add_obj(name) click to toggle source
# File glib2/lib/mkmf-gnome2.rb, line 394
def add_obj(name)
  ensure_objs
  $objs << name unless $objs.index(name)
end
build_option_menu(items, history) click to toggle source
# File gtk2/sample/testgtk/sample.rb, line 59
def build_option_menu(items, history)
  omenu = Gtk::OptionMenu.new

  menu = Gtk::Menu.new
  group = nil

  items.size.times do |i|
    menu_item = Gtk::RadioMenuItem.new(group, items[i].name)
    menu_item.signal_connect("activate") do |widget|
       items[i].block.call(widget)
    end
    group = menu_item.group
    menu.append(menu_item)
    menu_item.active = true if i == history
    menu_item.show
  end

  omenu.menu = menu
  omenu.history = history

  omenu
end
build_pipeline(file) click to toggle source
# File gstreamer/sample/xml-player.rb, line 15
def build_pipeline(file)
  source = Gst::ElementFactory.make("filesrc")
  decoder = Gst::ElementFactory.make("decodebin")
  audio_converter = Gst::ElementFactory.make("audioconvert")
  audio_resample = Gst::ElementFactory.make("audioresample")
  audio_sink = Gst::ElementFactory.make("autoaudiosink")
  source.location = file
  pipeline = Gst::Pipeline.new(PIPELINE_NAME)
  pipeline.add(source, decoder, audio_converter, audio_resample, audio_sink)
  pipeline
end
check_cairo(options={}) click to toggle source
# File glib2/lib/mkmf-gnome2.rb, line 406
def check_cairo(options={})
  rcairo_source_dir = options[:rcairo_source_dir]
  if rcairo_source_dir and !File.exist?(rcairo_source_dir)
    rcairo_source_dir = nil
  end
  if rcairo_source_dir.nil?
    cairo_gem_spec = find_gem_spec("cairo")
    rcairo_source_dir = cairo_gem_spec.full_gem_path if cairo_gem_spec
  end

  unless rcairo_source_dir.nil?
    if /mingw|cygwin|mswin32/ =~ RUBY_PLATFORM
      options = {}
      build_dir = "tmp/#{RUBY_PLATFORM}/cairo/#{RUBY_VERSION}"
      if File.exist?(File.join(rcairo_source_dir, build_dir))
        options[:target_build_dir] = build_dir
      end
      add_depend_package("cairo", "ext/cairo", rcairo_source_dir, options)
      $defs << "-DRUBY_CAIRO_PLATFORM_WIN32"
    end
    $CFLAGS += " -I#{rcairo_source_dir}/ext/cairo"
  end

  PKGConfig.have_package('cairo') and have_header('rb_cairo.h')
end
check_ruby_func() click to toggle source
# File glib2/lib/mkmf-gnome2.rb, line 366
def check_ruby_func
  #Other options
  ruby_header = "ruby.h"
  have_func("rb_define_alloc_func", ruby_header) # for ruby-1.8
  have_func("rb_block_proc", ruby_header) # for ruby-1.8

  STDOUT.print("checking for new allocation framework... ") # for ruby-1.7
  if Object.respond_to? :allocate
    STDOUT.print "yes\n"
    $defs << "-DHAVE_OBJECT_ALLOCATE"
  else
    STDOUT.print "no\n"
  end

  STDOUT.print("checking for attribute assignment... ") # for ruby-1.7
  STDOUT.flush
  if defined? try_compile and try_compile #include "ruby.h"#include "node.h"int node_attrasgn = (int)NODE_ATTRASGN;
    STDOUT.print "yes\n"
    $defs << "-DHAVE_NODE_ATTRASGN"
  else
    STDOUT.print "no\n"
  end
end
compute_size(width, height, rotate) click to toggle source
# File poppler/sample/pdf2.rb, line 23
def compute_size(width, height, rotate)
  width = width.to_f
  height = height.to_f
  radius = 0
  unless rotate.zero?
    radius = rotate / 180.0 * Math::PI
    if (90 < rotate and rotate < 180) or
        (270 < rotate and rotate < 360)
      radius -= Math::PI / 2
    end
  end
  inner_angle1 = Math.atan(width / height)
  inner_angle2 = Math.atan(height / width)
  diagonal = Math.sqrt(width ** 2 + height ** 2)

  angle1 = radius + inner_angle1
  angle2 = radius + inner_angle2

  bottom1 = diagonal * Math.cos(angle1)
  length1 = (bottom1 * Math.tan(angle1)).abs.to_i
  bottom2 = diagonal * Math.cos(angle2)
  length2 = (bottom2 * Math.tan(angle2)).abs.to_i

  if (0 <= rotate and rotate <= 90) or
      (180 <= rotate and rotate <= 270)
    [length1, length2]
  else
    [length2, length1]
  end
end
create_bbox_window(horizontal, title, pos, spacing, layout) click to toggle source
# File gtk2/sample/misc/buttonbox.rb, line 13
def create_bbox_window(horizontal, title, pos, spacing, layout)
  window = Gtk::Window.new(title)
  window.signal_connect("delete_event") do
    window.destroy
  end

  box1 = Gtk::VBox.new(false, 0)
  window.add(box1)

  if horizontal
    window.set_default_size(550, 60)
    window.move(150, pos)
    bbox = Gtk::HButtonBox.new
  else
    window.set_default_size(150, 400)
    window.move(pos, 200)
    bbox = Gtk::VButtonBox.new
  end

  bbox.layout_style = layout
  bbox.spacing = spacing
  box1.border_width = 25
  box1.pack_start(bbox, true, true, 0)

  button = Gtk::Button.new("OK")
  bbox.add(button)
  button.signal_connect("clicked") do
    window.destroy
  end

  button = Gtk::Button.new("Cancel")
  bbox.add(button)
  button.signal_connect("clicked") do
    window.destroy
  end

  button = Gtk::Button.new("Help")
  bbox.add(button)
  window.show_all
end
create_canvas() click to toggle source
# File goocanvas/sample/scalability-demo.rb, line 93
def create_canvas
  # Create the canvas.
  canvas = Goo::Canvas.new
  canvas.set_size_request(600, 450)
  
  start = Time.new
  total_width, total_height, left_offset, top_offset = setup_canvas(canvas)
  puts "Create Canvas Time Used: #{Time.new - start}"

  start = Time.new
  canvas.set_bounds(left_offset, top_offset, left_offset + total_width, top_offset + total_height)
  canvas.show

  first_time = true
  canvas.signal_connect("expose_event") do
    if first_time
      puts "Update Canvas Time Used: #{Time.new - start}"
      first_time = false
    end
    false
  end
  
  canvas
end
create_demo_item(table, demo_item_type, row, column, rows, columns, text) click to toggle source
# File goocanvas/sample/table-demo.rb, line 7
def create_demo_item(table, demo_item_type, row, column, rows, columns, text)
  case demo_item_type
  when DEMO_RECT_ITEM
    item = Goo::CanvasRect.new(table, 0, 0, 38, 19, :fill_color => 'red')
  when DEMO_TEXT_ITEM
    item = Goo::CanvasText.new(table, text, 0, 0, -1, Gtk::ANCHOR_NW, nil)
  when DEMO_WIDGET_ITEM
    widget = Gtk::Button.new(text)
    item = Goo::CanvasWidget.new(table, widget, 0, 0, -1, -1)
  end

  table.set_child_properties(item, :row => row, :column => column, :rows => rows, :columns => columns,
    :x_expand => true, :x_fill => true, :y_expand => true, :y_fill => true)

  item.signal_connect('button_press_event') do |item, target, event|
    puts "#{text} received 'button-press' signal at #{event.x}, #{event.y} (root:  #{event.x_root}, #{event.y_root})"
    true
  end
end
create_demo_table(root, x, y, width, height) click to toggle source
# File goocanvas/sample/table-demo.rb, line 62
def create_demo_table(root, x, y, width, height)
  table = Goo::CanvasTable.new(root, :row_spacing => 4.0, :column_spacing => 4.0, :width => width, :height => height)
  table.translate(x, y)

  square = Goo::CanvasRect.new(table, 0.0, 0.0, 50.0, 50.0, :fill_color => 'red')
  table.set_child_properties(square, :row => 0, :column => 0, :x_shrink => true)
  square.signal_connect('button_press_event') do |item, target, event|
    puts "Red square received 'button-press' signal at #{event.x}, #{event.y} (root:  #{event.x_root}, #{event.y_root})"
    true
  end

  circle = Goo::CanvasEllipse.new(table, 0.0, 0.0, 25.0, 25.0, :fill_color => 'blue')
  table.set_child_properties(circle, :row => 0, :column => 1, :x_shrink => true)
  circle.signal_connect('button_press_event') do |item, target, event|
    puts "Blue circle received 'button-press' signal at #{event.x}, #{event.y} (root:  #{event.x_root}, #{event.y_root})"
    true
  end

  triangle = Goo::CanvasPolyline.new(table, true, [ [ 25.0, 0.0], [ 0.0, 50.0 ], [ 50.0, 50.0 ] ], :fill_color => "yellow")
  table.set_child_properties(triangle, :row => 0, :column => 2, :x_shrink => true)
  triangle.signal_connect('button_press_event') do |item, target, event|
    puts "Yellow triangle received 'button-press' signal at #{event.x}, #{event.y} (root:  #{event.x_root}, #{event.y_root})"
    true
  end
end
create_focus_box(canvas, x, y, width, height, color) click to toggle source
# File goocanvas/sample/widgets-demo.rb, line 9
def create_focus_box(canvas, x, y, width, height, color)
  root = canvas.root_item
  item = Goo::CanvasRect.new(root, x, y, width, height, :stroke_pattern => nil, :fill_color => color, :line_width => 5.0, :can_focus => true)

  item.signal_connect('focus_in_event') do
    puts "#{color} received focus-in event"
    # Note that this is only for testing. Setting item properties to indicate
    # focus isn't a good idea for real apps, as there may be multiple views.
    item.stroke_color = 'black'
    false
  end

  item.signal_connect('focus_out_event') do
    puts "#{color} received focus-out event"
    # Note that this is only for testing. Setting item properties to indicate
    # focus isn't a good idea for real apps, as there may be multiple views.
    item.stroke_pattern = nil
    false
  end

  item.signal_connect('button_press_event') do
    puts "#{color} received button-press event"
    item.canvas.grab_focus(item)
    true
  end

  item.signal_connect('key_press_event') do
    puts "#{color} received key-press event"
    false
  end
end
create_main_window() click to toggle source

Main Window

# File gtk2/sample/testgtk/testgtk.rb, line 71
def create_main_window
  buttons = [
    ["button box", ButtonBoxSample],
    ["buttons", ButtonSample],
    ["check buttons", CheckButtonSample],
    ["color selection", ColorSelectionSample],
    ["dialog", DialogSample],
    ["entry", EntrySample],
    ["file selection", FileSelectionSample],
    ["font selection", FontSelectionSample],
    ["gamma curve", GammaCurveSample],
    ["labels", LabelSample],
    ["layout", LayoutSample],
    ["menus", MenuSample],
    ["notebook", NotebookSample],
    ["pixmap", PixmapSample],
    ["progress bar", ProgressBarSample],
    ["radio buttons", RadioButtonSample],
    ["range controls", RangeSample],
    ["reparent", ReparentSample],
    ["rulers", RulerSample],
    ["saved position", SavedPositionSample],
    ["scrolled windows", ScrolledWindowSample],
    ["shapes", ShapesSample],
    ["spinbutton", SpinButtonSample],
    ["statusbar", StatusbarSample],
    ["toggle buttons", ToggleButtonSample],
    ["toolbar", ToolbarSample],
    ["tooltips", TooltipsSample],
    ["WM hints", WMHintsSample],
  ]
  nbuttons = buttons.size

  window = Gtk::Window.new
  window.name = "main window"

  window.set_default_size(200, 400)
  window.move(20, 20)

  window.signal_connect("destroy"){Gtk.main_quit}

  box1 = Gtk::VBox.new(false, 0)
  window.add(box1)

  label = Gtk::Label.new("Gtk+ v#{Gtk::MAJOR_VERSION}.#{Gtk::MINOR_VERSION}.#{Gtk::MICRO_VERSION}")
  box1.pack_start(label, false, false, 0)

  label = Gtk::Label.new("Ruby/GTK2 v#{Gtk::BINDING_VERSION.join(".")}")
  box1.pack_start(label, false, false, 0)

  scrolled_window = Gtk::ScrolledWindow.new(nil, nil)
  scrolled_window.border_width = 10
  scrolled_window.set_policy(Gtk::POLICY_AUTOMATIC,
                             Gtk::POLICY_AUTOMATIC)
  box1.pack_start(scrolled_window, true, true, 0)

  box2 = Gtk::VBox.new(false, 0)
  box2.border_width = 10
  scrolled_window.add_with_viewport(box2);
  box2.focus_vadjustment = scrolled_window.vadjustment

  buttons.each do |title, sample_class|
    button = Gtk::Button.new(title)
    unless sample_class.nil?
      button.signal_connect("clicked"){|obj|
        sample_class.invoke
      }
    else
      button.sensitive = false
    end
    box2.pack_start(button, true, true, 0)
  end

  box1.pack_start(Gtk::HSeparator.new, false, true, 0)

  button = Gtk::Button.new("close")
  button.signal_connect("clicked") do
    window.destroy
    Gtk.main_quit
  end
  box1.pack_start(button, false, true, 5)
  window.show_all
end
create_makefile_at_srcdir(pkg_name, srcdir, defs = nil) click to toggle source
# File glib2/lib/mkmf-gnome2.rb, line 241
def create_makefile_at_srcdir(pkg_name, srcdir, defs = nil)
  base_dir = File.basename(Dir.pwd)
  last_common_index = srcdir.rindex(base_dir)
  if last_common_index
    builddir = srcdir[(last_common_index + base_dir.size + 1)..-1]
  end
  builddir ||= "."
  FileUtils.mkdir_p(builddir)

  Dir.chdir(builddir) do
    yield if block_given?

    $defs << defs if defs
    ensure_objs
    create_makefile(pkg_name, srcdir)
  end
end
create_menu(depth) click to toggle source
# File gtk2/sample/misc/menu.rb, line 13
def create_menu(depth)
  return nil if depth < 1
  
  menu = Gtk::Menu.new
  group = nil
  submenu = nil

  for i in 0..4
    buf = sprintf("item %2d - %d", depth, i + 1)
    menuitem = Gtk::RadioMenuItem.new(group, buf)
    group = menuitem.group
    menu.append(menuitem)
    if depth > 1
      menuitem.set_submenu create_menu(depth - 1)
    end
  end
  menu
end
create_pkg_config_file(package_name, c_package, version=nil, pc_file_name=nil) click to toggle source
# File glib2/lib/mkmf-gnome2.rb, line 181
def create_pkg_config_file(package_name, c_package,
                           version=nil, pc_file_name=nil)
  pc_file_name ||= "#{package_name.downcase.sub(/\//, '-')}.pc"
  version ||= ruby_gnome2_version || PKGConfig.modversion(c_package)

  puts "creating #{pc_file_name}"

  File.open(pc_file_name, 'w') do |pc_file|
    if package_name.nil?
      c_module_name = PKGConfig.name(c_package)
      package_name = "Ruby/#{c_module_name}" if c_module_name
    end
    pc_file.puts("Name: #{package_name}") if package_name

    description = PKGConfig.description(c_package)
    pc_file.puts("Description: Ruby bindings for #{description}") if description
    pc_file.printf("Version: #{version}")
  end

  add_distcleanfile(pc_file_name)
end
create_table(parent, row, column, embedding_level, x, y, rotation, scale, demo_item_type) click to toggle source
# File goocanvas/sample/table-demo.rb, line 27
def create_table(parent, row, column, embedding_level, x, y, rotation, scale, demo_item_type)
  # Add a few simple items.
  table = Goo::CanvasTable.new(parent, :row_spacing => 4.0, :column_spacing => 4.0)

  table.translate(x, y)
  table.rotate(rotation, 0, 0)
  table.scale(scale, scale)

  parent.set_child_properties(table, :row => row, :column => column, :x_expand => true, :x_fill => true) if row

  if embedding_level > 0
    level = embedding_level - 1
    create_table(table, 0, 0, level, 50, 50, 0, 0.7, demo_item_type)
    create_table(table, 0, 1, level, 50, 50, 45, 1.0, demo_item_type)
    create_table(table, 0, 2, level, 50, 50, 90, 1.0, demo_item_type)
    create_table(table, 1, 0, level, 50, 50, 135, 1.0, demo_item_type)
    create_table(table, 1, 1, level, 50, 50, 180, 1.5, demo_item_type)
    create_table(table, 1, 2, level, 50, 50, 225, 1.0, demo_item_type)
    create_table(table, 2, 0, level, 50, 50, 270, 1.0, demo_item_type)
    create_table(table, 2, 1, level, 50, 50, 315, 1.0, demo_item_type)
    create_table(table, 2, 2, level, 50, 50, 360, 2.0, demo_item_type)
  else
    create_demo_item(table, demo_item_type, 0, 0, 1, 1, "(0,0)")
    create_demo_item(table, demo_item_type, 0, 1, 1, 1, "(1,0)")
    create_demo_item(table, demo_item_type, 0, 2, 1, 1, "(2,0)")
    create_demo_item(table, demo_item_type, 1, 0, 1, 1, "(0,1)")
    create_demo_item(table, demo_item_type, 1, 1, 1, 1, "(1,1)")
    create_demo_item(table, demo_item_type, 1, 2, 1, 1, "(2,1)")
    create_demo_item(table, demo_item_type, 2, 0, 1, 1, "(0,2)")
    create_demo_item(table, demo_item_type, 2, 1, 1, 1, "(1,2)")
    create_demo_item(table, demo_item_type, 2, 2, 1, 1, "(2,2)")
  end
  table
end
create_top_makefile(sub_dirs=["src"]) click to toggle source
# File glib2/lib/mkmf-gnome2.rb, line 275
def create_top_makefile(sub_dirs=["src"])
  File.open("Makefile", "w") do |makefile|
    makefile.print(all:#{run_make_in_sub_dirs_command("all", sub_dirs)}install:#{run_make_in_sub_dirs_command("install", sub_dirs)}site-install:#{run_make_in_sub_dirs_command("site-install", sub_dirs)}clean:#{run_make_in_sub_dirs_command("clean", sub_dirs)})

    if /mswin32/ =~ RUBY_PLATFORM
      makefile.print(        @if exist extconf.h del extconf.h        @if exist conftest.* del conftest.*        @if exist *.lib del *.lib        @if exist *~ del *~        @if exist mkmf.log del mkmf.log)
    else
      makefile.print(distclean: clean#{run_make_in_sub_dirs_command("distclean", sub_dirs)}        @rm -f Makefile extconf.h conftest.*        @rm -f core *~ mkmf.log)
    end
  end
end
draw_text(cr) click to toggle source
# File pango/sample/pango_cairo.rb, line 24
def draw_text(cr)
  # Center coordinates on the middle of the region we are drawing
  cr.translate(RADIUS, RADIUS);

  # Create a PangoLayout, set the font and text
  layout = cr.create_pango_layout
  
  layout.set_text("Text")
  desc = Pango::FontDescription.new(FONT)
  layout.set_font_description(desc)

  # Draw the layout N_WORDS times in a circle
  N_WORDS.times do |i|
    angle = (360.0 * i) / N_WORDS;
    cr.save do
      # Gradient from red at angle == 60 to blue at angle == 300
      red = (1 + Math.cos((angle - 60) * Math::PI / 180.0)) / 2
      cr.set_source_rgb(red, 0, 1.0 - red)
      cr.rotate(angle * Math::PI / 180.0)
    
      # Inform Pango to re-layout the text with the new transformation
      cr.update_pango_layout(layout)
    
      width, height = layout.size
      cr.move_to(-(width.to_f / Pango::SCALE) / 2, -RADIUS)
      cr.show_pango_layout(layout)
    end
  end
end
drawingarea_query_tooltip(keyboard_tip, x, y, tooltip, rectangles) click to toggle source
# File gtk2/sample/misc/tooltips.rb, line 55
def drawingarea_query_tooltip(keyboard_tip, x, y, tooltip, rectangles)
    if keyboard_tip
        return false
    end
    for r in rectangles
        if r.x < x && x < r.x + 50 && r.y < y && y < r.y + 50
            tooltip.markup = r.tooltip
            return true
        end
    end
    return false
end
ensure_objs() click to toggle source
# File glib2/lib/mkmf-gnome2.rb, line 227
def ensure_objs
  return unless $objs.nil?

  source_dir = '$(srcdir)'
  RbConfig.expand(source_dir)

  pattern = "*.{#{SRC_EXT.join(',')}}"
  srcs = Dir[File.join(source_dir, pattern)]
  srcs |= Dir[File.join(".", pattern)]
  $objs = srcs.collect do |f|
    File.basename(f, ".*") + ".o"
  end.uniq
end
find_gem_spec(package) click to toggle source
# File glib2/lib/mkmf-gnome2.rb, line 97
def find_gem_spec(package)
  begin
    require 'rubygems'
    if Gem::Specification.respond_to?(:find_by_name)
      Gem::Specification.find_by_name(package)
    else
      Gem.source_index.find_name(package).last
    end
  rescue LoadError
    nil
  end
end
glib_mkenums(prefix, files, g_type_prefix, include_files, options={}) click to toggle source
# File glib2/lib/mkmf-gnome2.rb, line 399
def glib_mkenums(prefix, files, g_type_prefix, include_files, options={})
  add_distcleanfile(prefix + ".h")
  add_distcleanfile(prefix + ".c")
  GLib::MkEnums.create(prefix, files, g_type_prefix, include_files, options)
  add_obj("#{prefix}.o")
end
install_missing_native_package(native_package_info) click to toggle source
# File glib2/lib/mkmf-gnome2.rb, line 459
def install_missing_native_package(native_package_info)
  platform = package_platform
  native_package_info = normalize_native_package_info(native_package_info)
  package = native_package_info[platform]
  return false if package.nil?

  need_super_user_priviledge = true
  case platform
  when :debian
    install_command = "apt-get install -V -y #{package}"
  when :fedora, :redhat
    install_command = "yum install -y #{package}"
  when :homebrew
    need_super_user_priviledge = false
    install_command = "brew install #{package}"
  when :macports
    install_command = "port install -y #{package}"
  else
    return false
  end

  have_priviledge = (not need_super_user_priviledge or super_user?)
  unless have_priviledge
    sudo = find_executable("sudo")
  end

  installing_message = "installing '#{package}' native package... "
  message("%s", installing_message)
  failed_to_get_super_user_priviledge = false
  if have_priviledge
    succeeded = xsystem(install_command)
  else
    if sudo
      install_command = "#{sudo} #{install_command}"
      succeeded = xsystem(install_command)
    else
      succeeded = false
      failed_to_get_super_user_priviledge = true
    end
  end

  if failed_to_get_super_user_priviledge
    result_message = "require super user privilege"
  else
    result_message = succeeded ? "succeeded" : "failed"
  end
  Logging.postpone do
    "#{installing_message}#{result_message}\n"
  end
  message("#{result_message}\n")

  error_message = nil
  unless succeeded
    if failed_to_get_super_user_priviledge
      error_message = '#{package}' native package is required.run the following command as super user to install required native package:  \# #{install_command}
    else
      error_message = failed to run '#{install_command}'.
    end
  end
  if error_message
    message("%s", error_message)
    Logging.message("%s", error_message)
  end

  Logging.message("--------------------\n\n")

  succeeded
end
main() click to toggle source
# File gtk2/sample/testgtk/testgtk.rb, line 155
def main
  srand
  Gtk::RC.parse("testgtkrc")
  create_main_window
  Gtk.main
end
make_version_header(app_name, pkgname, dir = "src") click to toggle source

This is used for the library which doesn't support version info.

# File glib2/lib/mkmf-gnome2.rb, line 312
def make_version_header(app_name, pkgname, dir = "src")
  version = PKGConfig.modversion(pkgname).split(/\./)
  (0..2).each do |v|
    version[v] = "0" unless version[v]
    if /\A(\d+)/ =~ version[v]
      number = $1
      tag = $POSTMATCH
      unless tag.empty?
        version[v] = number
        version[3] = tag
      end
    end
  end
  filename = "rb#{app_name.downcase}version.h"

  puts "creating #{filename}"

  add_distcleanfile(filename)

  FileUtils.mkdir_p(dir)
  out = File.open(File.join(dir, filename), "w")

  version_definitions = []
  ["MAJOR", "MINOR", "MICRO", "TAG"].each_with_index do |type, i|
    _version = version[i]
    next if _version.nil?
    version_definitions << "#define #{app_name}_#{type}_VERSION (#{_version})"
  end
  out.print %[/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
/************************************************

  #{filename} -

  This file was generated by mkmf-gnome2.rb.

************************************************/

#ifndef __RB#{app_name}_VERSION_H__
#define __RB#{app_name}_VERSION_H__

#{version_definitions.join("\n")}

#define #{app_name}_CHECK_VERSION(major,minor,micro)    \\
    (#{app_name}_MAJOR_VERSION > (major) || \\
     (#{app_name}_MAJOR_VERSION == (major) && #{app_name}_MINOR_VERSION > (minor)) || \\
     (#{app_name}_MAJOR_VERSION == (major) && #{app_name}_MINOR_VERSION == (minor) && \\
      #{app_name}_MICRO_VERSION >= (micro)))


#endif /* __RB#{app_name}_VERSION_H__ */
]
      out.close
end
normalize_native_package_info(native_package_info) click to toggle source
# File glib2/lib/mkmf-gnome2.rb, line 452
def normalize_native_package_info(native_package_info)
  native_package_info ||= {}
  native_package_info = native_package_info.dup
  native_package_info[:fedora] ||= native_package_info[:redhat]
  native_package_info
end
normalize_uri(uri) click to toggle source
# File gstreamer/sample/video-player.rb, line 12
def normalize_uri(uri)
  uri = URI(uri)
  uri.scheme ||= "file"
  if uri.scheme == "file"
    "file://#{uri.path}"
  else
    uri.to_s
  end
end
package_platform() click to toggle source
# File glib2/lib/mkmf-gnome2.rb, line 432
def package_platform
  if File.exist?("/etc/debian_version")
    :debian
  elsif File.exist?("/etc/fedora-release")
    :fedora
  elsif File.exist?("/etc/redhat-release")
    :redhat
  elsif find_executable("brew")
    :homebrew
  elsif find_executable("port")
    :macports
  else
    :unknown
  end
end
parse(argv) click to toggle source
# File gstreamer/sample/gst-inspect.rb, line 11
def parse(argv)
  options = OpenStruct.new
  options.print_all = false
  options.print_auto_install_info = false

  opts = OptionParser.new do |opts|
    opts.banner += " [ELEMENT-NAME|PLUGIN-NAME]"

    opts.version = Gst.version

    opts.separator("")
    opts.on("-a", "--print-all", "Print all elements") do
      options.print_all = true
    end

    opts.on("--print-plugin-auto-install-info",
            "Print a machine-parsable list of features",
            "the specified plugin provides.",
            "Useful in connection with external",
            "automatic plugin installation mechanisms") do
      options.print_auto_install_info = true
    end
  end
  opts.parse!(argv)

  [options, argv.first]
end
play_pipeline(pipeline) click to toggle source
# File gstreamer/sample/xml-player.rb, line 46
def play_pipeline(pipeline)
  pipeline.play
  loop = GLib::MainLoop.new(nil, false)
  begin
    loop.run
  rescue Interrupt
  ensure
    pipeline.stop
  end
end
read_pipeline(file) click to toggle source
# File gstreamer/sample/xml-player.rb, line 31
def read_pipeline(file)
  xml = Gst::XML.new
  xml.parse_file(file)
  pipeline = xml.get_element(PIPELINE_NAME)
  children = pipeline.children
  source, decoder, audio_converter, audio_resample, audio_sink = children
  source >> decoder
  audio_converter >> audio_resample >> audio_sink
  decoder.signal_connect("new-decoded-pad") do |element, pad|
    sink_pad = audio_converter.get_pad("sink")
    pad.link(sink_pad)
  end
  pipeline
end
required_pkg_config_package(package_info, native_package_info=nil) click to toggle source
# File glib2/lib/mkmf-gnome2.rb, line 534
def required_pkg_config_package(package_info, native_package_info=nil)
  if package_info.is_a?(Array)
    required_package_info = package_info
  else
    required_package_info = [package_info]
  end
  return true if PKGConfig.have_package(*required_package_info)

  native_package_info ||= {}
  return false unless install_missing_native_package(native_package_info)

  PKGConfig.have_package(*required_package_info)
end
ruby_gnome2_version(glib_source_directory=nil) click to toggle source
# File glib2/lib/mkmf-gnome2.rb, line 203
def ruby_gnome2_version(glib_source_directory=nil)
  glib_source_directory ||= File.join(File.dirname(__FILE__), "..",
                                      "ext", "glib2")
  rbglib_h = File.join(glib_source_directory, "rbglib.h")
  return nil unless File.exist?(rbglib_h)

  version = nil
  File.open(rbglib_h) do |h_file|
    version_info = {}
    h_file.each_line do |line|
      case line
      when /\A#define RBGLIB_(MAJOR|MINOR|MICRO)_VERSION\s+(\d+)/
        version_info[$1] = $2
      end
    end
    version_info = [version_info["MAJOR"],
                    version_info["MINOR"],
                    version_info["MICRO"]].compact
    version = version_info.join(".") if version_info.size == 3
  end

  version
end
run_make_in_sub_dirs(command) click to toggle source

generate top-level Makefile

# File extconf.rb, line 89
def run_make_in_sub_dirs(command)
  if /mswin32/ =~ RUBY_PLATFORM
    "   $(COMMAND) '$(SUBDIRS)' $(MAKE) #{command}"
  else
            @(                                     \\          succeeded='';                                \\          failed='';                           \\          for dir in $(SUBDIRS); do            \\            (cd $$dir; $(MAKE) #{command});    \\            if [ $$? -eq 0 ]; then             \\              succeeded="$$succeeded $$dir";   \\            else                               \\              failed="$$failed $$dir";         \\            fi;                                        \\          done;                                        \\          if [ "$$succeeded" = "" ]; then      \\            succeeded="NONE";                  \\          fi;                                  \\          if [ "$$failed" = "" ]; then         \\            failed="NONE";                     \\          fi;                                  \\          echo;                                        \\          echo "-----";                                \\          echo "SUCCEEDED: $$succeeded";       \\          echo "FAILED: $$failed";             \\          echo "-----";                                \\          echo "Done.";                                \\        ).chomp
  end
end
run_make_in_sub_dirs_command(command, sub_dirs) click to toggle source
# File glib2/lib/mkmf-gnome2.rb, line 259
def run_make_in_sub_dirs_command(command, sub_dirs)
  if /mswin32/ =~ RUBY_PLATFORM
    sub_dirs.collect do |dir|
              @cd #{dir}        @nmake -nologo DESTDIR=$(DESTDIR) #{command}        @cd ...chmop
    end.join("\n")
  else
    sub_dirs.collect do |dir|
      "\t@cd #{dir}; $(MAKE) #{command}"
    end.join("\n")
  end
end
separator() click to toggle source

for creating a separating line

# File run-test.rb, line 13
def separator
  "-" * 80
end
setup_canvas(canvas) click to toggle source
# File goocanvas/sample/scalability-demo.rb, line 16
def setup_canvas(canvas)
  root = canvas.root_item
  root.font = 'Sans 8'

  item_width = 400
  item_height = 19
        
  cell_width = item_width + PADDING * 2
  cell_height = item_height + PADDING * 2

  group_width = N_COLS * cell_width
  group_height = N_ROWS * cell_height

  total_width = N_GROUP_COLS * group_width
  total_height = N_GROUP_ROWS * group_height

  # We use -ve offsets to test if -ve coords are handled correctly.
  left_offset = -total_width / 2
  top_offset = -total_height / 2

  style = Goo::CanvasStyle.new
  color = Gdk::Color.parse("mediumseagreen")
  pattern = Cairo::SolidPattern.new(color.red / 65535.0, color.green / 65535.0, color.blue / 65535.0)
  style.fill_pattern = pattern

  style2 = Goo::CanvasStyle.new
  color = Gdk::Color.parse("steelblue")
  pattern = Cairo::SolidPattern.new(color.red / 65535.0, color.green / 65535.0, color.blue / 65535.0)
  style2.fill_pattern = pattern

  total_items = 0

  N_GROUP_COLS.times do |group_i|
    N_GROUP_ROWS.times do |group_j|
      group_x = left_offset + (group_i * group_width);
      group_y = top_offset + (group_j * group_height);

      group = Goo::CanvasGroup.new(root)
      total_items += 1
      group.translate(group_x, group_y)
      
      N_COLS.times do |i|
        N_ROWS.times do |j|
          item_x = (i * cell_width) + PADDING
          item_y = (j * cell_height) + PADDING
          rotation = i % 10 * 2
          rotation_x = item_x + item_width / 2
          rotation_y = item_y + item_height / 2
          
          current_id = "#{group_x + item_x}, #{group_y + item_y}"
          
          item = Goo::CanvasRect.new(group, item_x, item_y, item_width, item_height)
          item.style = (j % 2) == 1 ? style : style2
          item.rotate(rotation, rotation_x, rotation_y)
          
          item.signal_connect('motion_notify_event') do
            puts "#{current_id} item received 'motion-notify' signal"
          end

          item = Goo::CanvasText.new(group, current_id,
            item_x + item_width / 2, item_y + item_height / 2, -1, Gtk::ANCHOR_CENTER)
          item.rotate(rotation, rotation_x, rotation_y)
          
          total_items += 2
          break if ONLY_ONE
        end
        break if ONLY_ONE
      end
      break if ONLY_ONE
    end
    break if ONLY_ONE
  end

  puts "Total items: #{total_items}"
  [ total_width, total_height, left_offset, top_offset ]
end
setup_win32(target_name, base_dir=nil) click to toggle source
# File glib2/lib/mkmf-gnome2.rb, line 75
def setup_win32(target_name, base_dir=nil)
  checking_for(checking_message("Win32 OS")) do
    case RUBY_PLATFORM
    when /cygwin|mingw|mswin32/
      import_library_name = "libruby-#{target_name}.a"
      $DLDFLAGS << " -Wl,--out-implib=#{import_library_name}"
      $cleanfiles << import_library_name
      base_dir ||= Pathname($0).dirname.parent.parent.expand_path
      base_dir = Pathname(base_dir) if base_dir.is_a?(String)
      binary_base_dir = base_dir + "vendor" + "local"
      if binary_base_dir.exist?
        $CFLAGS += " -I#{binary_base_dir}/include"
        pkg_config_dir = binary_base_dir + "lib" + "pkgconfig"
        PKGConfig.add_path(pkg_config_dir.to_s)
      end
      true
    else
      false
    end
  end
end
super_user?() click to toggle source
# File glib2/lib/mkmf-gnome2.rb, line 448
def super_user?
  Process.uid.zero?
end
test_hbbox() click to toggle source
# File gtk2/sample/misc/buttonbox.rb, line 54
def test_hbbox
  create_bbox_window(true, "Spread", 50, 40, Gtk::ButtonBox::SPREAD)
  create_bbox_window(true, "Edge", 250, 40, Gtk::ButtonBox::EDGE)
  create_bbox_window(true, "Start", 450, 40,  Gtk::ButtonBox::START)
  create_bbox_window(true, "End", 650, 15, Gtk::ButtonBox::END)
end
test_vbbox() click to toggle source
# File gtk2/sample/misc/buttonbox.rb, line 61
def test_vbbox
  create_bbox_window(false, "Spread", 50, 40, Gtk::ButtonBox::SPREAD)
  create_bbox_window(false, "Edge", 250, 40,  Gtk::ButtonBox::EDGE)
  create_bbox_window(false, "Start", 450, 40, Gtk::ButtonBox::START)
  create_bbox_window(false, "End", 650, 15, Gtk::ButtonBox::END)
end
textview_query_tooltip(textview, keyboard_tip, x, y, tooltip, tag) click to toggle source
# File gtk2/sample/misc/tooltips.rb, line 40
def textview_query_tooltip(textview, keyboard_tip, x, y, tooltip, tag)
    if keyboard_tip
        iter = textview.buffer.get_iter_at_offset(textview.buffer.cursor_position)
    else
        bx, by = textview.window_to_buffer_coords(Gtk::TextView::WINDOW_TEXT, x, y)
        iter, = textview.get_iter_at_position(bx, by)
    end
    if iter.has_tag?(tag)
        tooltip.text = 'Tooltip on text tag'
        return true
    else
        return false
    end
end
to_pixbuf(input, ratio) click to toggle source
# File rsvg2/sample/svg2.rb, line 44
def to_pixbuf(input, ratio)
  RSVG.pixbuf_from_file_at_zoom(input, ratio, ratio)
end
to_pixbuf_with_cairo(input, ratio) click to toggle source
# File rsvg2/sample/svg2.rb, line 26
def to_pixbuf_with_cairo(input, ratio)
  handle = nil
  Dir.chdir(File.dirname(File.expand_path(input))) do
    handle = RSVG::Handle.new_from_file(input)
  end
  dim = handle.dimensions
  width = dim.width * ratio
  height = dim.height * ratio
  surface = Cairo::ImageSurface.new(Cairo::FORMAT_ARGB32, width, height)
  cr = Cairo::Context.new(surface)
  cr.scale(ratio, ratio)
  cr.render_rsvg_handle(handle)
  temp = Tempfile.new("svg2")
  cr.target.write_to_png(temp.path)
  cr.target.finish
  Gdk::Pixbuf.new(temp.path)
end
treeview_query_tooltip(treeview, keyboard_tip, x, y, tooltip) click to toggle source
# File gtk2/sample/misc/tooltips.rb, line 20
def treeview_query_tooltip(treeview, keyboard_tip, x, y, tooltip)
    if keyboard_tip
        # Keyboard mode
        path, = treeview.cursor
        if not path
            return false
        end
    else
        bin_x, bin_y = treeview.convert_widget_to_bin_window_coords(x, y)
        # Mouse mode
        path, = treeview.get_path_at_pos(bin_x, bin_y)
        if not path
            return false
        end
    end
    data = treeview.model.get_value(treeview.model.get_iter(path), 0)
    tooltip.markup = "<b>Path #{path}:</b> #{data}"
    return true
end
try_compiler_option(opt, &block) click to toggle source
# File glib2/lib/mkmf-gnome2.rb, line 25
def try_compiler_option(opt, &block)
  checking_for "#{opt} option to compiler" do
    $CFLAGS += " #{opt}" if try_compile '', opt, &block
  end
end
type_find(file) click to toggle source
# File gstreamer/sample/type-find.rb, line 5
def type_find(file)
  pipeline = Gst::Pipeline.new("pipeline")

  source = Gst::ElementFactory.make("filesrc", "source")
  type_find = Gst::ElementFactory.make("typefind", "type-find")
  sink = Gst::ElementFactory.make("fakesink", "sink")

  pipeline.add(source, type_find, sink)
  source >> type_find >> sink

  found_caps = nil
  type_find.signal_connect("have-type") do |element, probability, caps|
    found_caps = caps
  end

  loop = GLib::MainLoop.new
  source.location = file
  bus = pipeline.bus
  bus.add_watch do |bus, message|
    case message.type
    when Gst::Message::STATE_CHANGED, Gst::Message::EOS
      loop.quit
    when Gst::Message::ERROR
      p message.parse
      loop.quit
    end
    true
  end
  pipeline.pause
  loop.run
  pipeline.stop

  if found_caps
    puts("#{file} - #{found_caps}")
  else
    puts("#{file} - No type found")
  end
end
usage() click to toggle source
# File gstreamer/sample/install-plugins.rb, line 5
def usage
  $stderr.puts "Usage: #{$0} uri"
  exit 1
end
write_pipeline(pipeline, file) click to toggle source
# File gstreamer/sample/xml-player.rb, line 27
def write_pipeline(pipeline, file)
  Gst::XML.write_file(pipeline, file)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.