【发布时间】:2015-05-18 16:46:30
【问题描述】:
我了解函数 gtk_builder_new_from_file 或 gtk_builder_new_from_string 的参数是什么,但我有点想知道什么是资源路径:
GtkBuilder *
gtk_builder_new_from_resource (const gchar *resource_path);
我找不到任何示例(C、python、vala 或其他我不介意的)。
编辑:解决方案
感谢 gniamt 的帮助,这里有一个 ruby 中的基本示例 (https://github.com/ruby-gnome2/ruby-gnome2):
首先是一个简单的ui文件simple_window.ui:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.18.3 -->
<interface>
<requires lib="gtk+" version="3.12"/>
<object class="GtkWindow" id="window">
<property name="can_focus">False</property>
<child>
<object class="GtkLabel" id="label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">label</property>
<property name="ellipsize">end</property>
</object>
</child>
</object>
</interface>
然后创建一个 simple_window.gresource.xml 文件:
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/simple_window">
<file>simple_window.ui</file>
</gresource>
</gresources>
将其打包为:
glib-compile-resources simple_window.gresource.xml
其中创建了一个 simple_window.gresource 二进制文件。
现在是 ruby 脚本:
#!/usr/bin/env ruby
require "gtk3"
path = File.expand_path(File.dirname(__FILE__))
resource = Gio::Resource.load("#{path}/simple_window.gresource")
Gio::Resources.register(resource)
builder = Gtk::Builder.new(:resource => "/simple_window/simple_window.ui")
window = builder.get_object("window")
window.show_all
Gtk.main
【问题讨论】:
-
GLib.Resource 类的文档提供了可能有所帮助的冗长描述。
标签: ruby gtk3 pygobject ruby-gnome2