ruby 如何在Ruby Gtk3中使用Glade资源

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby 如何在Ruby Gtk3中使用Glade资源相关的知识,希望对你有一定的参考价值。

<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.16.1 -->
<interface>
  <requires lib="gtk+" version="3.10"/>
  <object class="GtkWindow" id="main_window">
    <property name="width_request">100</property>
    <property name="height_request">40</property>
    <property name="can_focus">False</property>
    <property name="halign">end</property>
    <signal name="destroy" handler="on_main_window_destroy" swapped="no"/>
    <child>
      <object class="GtkButton" id="button">
        <property name="label">gtk-execute</property>
        <property name="visible">True</property>
        <property name="can_focus">True</property>
        <property name="receives_default">True</property>
        <property name="use_stock">True</property>
        <signal name="clicked" handler="on_button_clicked" swapped="no"/>
      </object>
    </child>
  </object>
</interface>
#!/usr/bin/env ruby

require 'gtk3'

def not_yet_implemented(object)
  puts "#{object.class.name} sent a signal!"
end

def on_main_window_destroy(object)
  Gtk.main_quit()
end

main_window_res = 'main_window.xml'

builder = Gtk::Builder.new
builder.add_from_file(main_window_res)

# Attach signals handlers
builder.connect_signals do |handler|
  begin
    method(handler)
  rescue
    puts "#{handler} not yet implemented!"
    method('not_yet_implemented')
  end
end

main_window = builder.get_object('main_window')
main_window.show()

Gtk.main

以上是关于ruby 如何在Ruby Gtk3中使用Glade资源的主要内容,如果未能解决你的问题,请参考以下文章

在 Ruby 中使用 GTK3 进度条

Ruby GTK3 如何更改应用程序主题?

如何读出 gtk3 对象的“glade ID”

使用 Cairo 的 Ruby Gtk3 内存泄漏

C 和 GTK3 - 使用 Glade 时不显示应用程序菜单

如何将 GTK2 像素图移植到 GTK3_