Can I load a gtkbuilder app into a "parent" gtkbuilder frame?
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 ea开发者_如何学JAVAch 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.
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.
精彩评论