----Next_Part(Mon_Nov_22_01:41:17_1999_886)--
Content-Type: Text/Plain; charset=iso-2022-jp
Content-Transfer-Encoding: 7bit

とりあえず、hello worldくらいはできるようになったので MLに流します。

Gtk使いの人には説明はいらないでしょう(^^;

---------- hello world --------------
require 'gtk'
require 'glade'

g  lade.new
obj  .populate('glade.xml')

obj['window1'].signal_connect('delete_event') do
  exit
end

Gtk.main

----------- end ---------------------

obj  lade.newにしたかったのですが、わからなかったので
populate methodで逃げてます(ぉ

hashだと、ちょっと読みづらいかな〜とも思いますが、良い objectが見つから
なかったので勘弁してください。批意見、大歓迎です。
--
           yashi

----Next_Part(Mon_Nov_22_01:41:17_1999_886)--
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="gladeparser.rb"

# GladeParser.rb
#
# SubClass of xmlparser.  This class generate
# a stack of hash which is associated to a 
# single widget.  a hash should have all of
# proparty which defined in xml generated by
# glade

require 'xmlparser'

class GladeParser<XMLParser
  def initialize
    @last_name  foo"
    @stack  rray.new
  end

  def startElement(name, attribs)
    if name "GTK-Interface" then
    elsif name "project" then
      project  ash.new(nil)
      @stack.push(project)
    elsif name "widget" then
      if not @stack.empty? then
	if defined? childStart
	  parent  stack.pop
	  childStart(parent)
	  @stack.push(parent)
	end
      end
      w  ash.new(nil)
      @stack.push(w)
    elsif name "child" then
    else
      @last_name  ame
    end
  end

  def character(data)
    if @stack && data "[A-Za-z0-9]" then
      hash  stack.pop
      hash.store(@last_name, data)
      @stack.push(hash)
    end
  end

  def endElement(name)
    if name "GTK-Interface" then
    elsif name "project" then
      proj  stack.pop
      projectDone(proj) if defined? projectDone
    elsif name "widget" then
      w  stack.pop
      if not @stack.empty? then
	parent  stack.pop
	name  arent["name"]
	@stack.push(parent)
      else
	name  il
      end
      widgetDone(w, name) if defined? widgetDone
    elsif name "child" then
    end
  end

end

----Next_Part(Mon_Nov_22_01:41:17_1999_886)--
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="glade.rb"

require 'gladeparser'
require 'gtk'

class Glade < GladeParser
  def populate(filename)
    if filename.is_a? String then
      data  ile.new(File.expand_path(filename))
      data.gets
    else
      raise "Wrong Type"
    end
    @hash  ash.new(nil)
    parse(data)
    return @hash
  end

  def doGtkWindow(w)
    case w['type']
    when "GTK_WINDOW_TOPLEVEL"
      type  tk::WINDOW_TOPLEVEL
    end
    @hash.store(w['name'].to_s, Gtk::Window.new(type))
  end

  def doGtkButton(w)
    label  ['label']
    if label.nil? then
      @hash.store(w['name'].to_s, Gtk::Button.new)
    else
      @hash.store(w['name'].to_s, Gtk::Button.new(label))
    end
  end

  def createWidget(w)
    case w['class']
    when "GtkWindow"
      doGtkWindow(w)
    when "GtkButton"
      doGtkButton(w)
    end
  end

  def childStart(w)
    createWidget(w)
  end

  def widgetDone(w, pname)
    if not @hash[pname].nil? then
      createWidget(w)
      child  hash[w['name']]
      parent  hash[pname]
      if parent.is_a? Gtk::Window then
	parent.add(child)
      end
    else
      @hash[w['name']].show_all
    end
  end
end

----Next_Part(Mon_Nov_22_01:41:17_1999_886)--
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="glade.xml"

<?xml version.0"?>
<GTK-Interface>

<project>
  <name>Project4</name>
  <program_name>project4</program_name>
  <directory></directory>
  <source_directory>src</source_directory>
  <pixmaps_directory>pixmaps</pixmaps_directory>
  <language>C</language>
  <gnome_support>True</gnome_support>
  <gettext_support>True</gettext_support>
  <use_widget_names>False</use_widget_names>
  <output_main_file>True</output_main_file>
  <output_support_files>True</output_support_files>
  <output_build_files>True</output_build_files>
  <backup_source_files>True</backup_source_files>
  <main_source_file>interface.c</main_source_file>
  <main_header_file>interface.h</main_header_file>
  <handler_source_file>callbacks.c</handler_source_file>
  <handler_header_file>callbacks.h</handler_header_file>
  <support_source_file>support.c</support_source_file>
  <support_header_file>support.h</support_header_file>
  <translatable_strings_file></translatable_strings_file>
</project>

<widget>
  <class>GtkWindow</class>
  <name>window1</name>
  <title>window1</title>
  <type>GTK_WINDOW_TOPLEVEL</type>
  <position>GTK_WIN_POS_NONE</position>
  <modal>False</modal>
  <allow_shrink>False</allow_shrink>
  <allow_grow>True</allow_grow>
  <auto_shrink>False</auto_shrink>

  <widget>
    <class>GtkButton</class>
    <name>button1</name>
    <can_focus>True</can_focus>
    <label>hello world</label>
  </widget>
</widget>

</GTK-Interface>

----Next_Part(Mon_Nov_22_01:41:17_1999_886)----