我可以将 gtkbuilder 应用程序加载到“父”应用程序中吗? gtkbuilder 框架?

发布于 2024-09-24 09:54:04 字数 397 浏览 0 评论 0原文

我正在使用 Glade-3 构建一套 Gtk 应用程序。

这些应用程序应该具有共同的外观和感觉,我们已经决定所有应用程序将共享一个共同的“框架”,其中包括菜单栏、工具栏、状态栏、垂直面板 - 以及中间的空白将由每个应用程序填写。

这个通用的“框架”是使用 Glade-3 设计的,并以 Gtkbuilder 格式保存。

我想做的是使用 Glade-3 为每个应用程序设计“中间部分”,然后以某种方式将其加载到父框架中。

这样的事可能吗?我不介意在 Gtk 中重写父框架,因为它相当简单 - 主要内容将在我们肯定想使用 Glade 设计的应用程序特定细节中。

我没有看到以某种方式获得读取 Gtkbuilder 文件并将其粘贴到父小部件中的结果的方法。

我正在使用 Perl/Gtk2。

I am using Glade-3 to build a suite of Gtk applications.

The applications are supposed to have a common look-and-feel, and we have decided on a common "frame" that all apps will share, that includes a menu bar, toolbar, status-bar(s), a vertical panel - and a space in the middle that will be filled out by each application.

This common "frame" is designed using Glade-3 and saved in Gtkbuilder format.

What I would like to do is design the "middle part" for each application using Glade-3 as-well, then somehow load it into the parent frame.

Is such a thing possible? I don't mind rewriting the parent frame in Gtk as it is fairly simple - the main meat will be in the application specific details that we definitely want to design using Glade.

I have seen no way to somehow get the result of reading a Gtkbuilder file, and sticking it into a parent widget.

I am using Perl/Gtk2.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云裳 2024-10-01 09:54:04

您可以使用 GtkBuilder 完成所有这些工作。例如,给定这些 UI 文件:

<!-- parent.ui -->
<interface>
    <object class='GtkWindow' id='window'/>  <!-- See #1 -->
</interface>

<!-- child1.ui -->
<interface>
    <object class='GtkLabel' id='content'>  <!-- See #2 -->
        <property name='label'>Hello World</property>
    </object>
</interface>

<!-- child2.ui -->
<interface>
    <object class='GtkLabel' id='content'>  <!-- See #2 -->
        <property name='label'>Hi there</property>
    </object>
</interface>

您可以使用以下代码构建两个窗口(在 Python 中,抱歉;我不熟悉 Perl 绑定)。

def build(child_filename):
    builder = gtk.Builder()
    builder.add_from_file('parent.ui')
    builder.add_from_file(child_filename)
    window = builder.get_object('window')  #1
    content = builder.get_object('content')  #2
    window.add(content)
    window.show_all()
    return window

window1 = build('child1.ui')
window2 = build('child2.ui')

如果需要,您还可以构建同一窗口的多个副本。

You can do all of that using GtkBuilder. For example, given these UI files:

<!-- parent.ui -->
<interface>
    <object class='GtkWindow' id='window'/>  <!-- See #1 -->
</interface>

<!-- child1.ui -->
<interface>
    <object class='GtkLabel' id='content'>  <!-- See #2 -->
        <property name='label'>Hello World</property>
    </object>
</interface>

<!-- child2.ui -->
<interface>
    <object class='GtkLabel' id='content'>  <!-- See #2 -->
        <property name='label'>Hi there</property>
    </object>
</interface>

you can build two windows using the following code (in Python, sorry; I'm not familiar with the Perl bindings).

def build(child_filename):
    builder = gtk.Builder()
    builder.add_from_file('parent.ui')
    builder.add_from_file(child_filename)
    window = builder.get_object('window')  #1
    content = builder.get_object('content')  #2
    window.add(content)
    window.show_all()
    return window

window1 = build('child1.ui')
window2 = build('child2.ui')

You can also build multiple copies of the same window if you want.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文