开发者

Handling multiple windows in PyGTK/GtkBuilder

How can I store multiple different windows/dialogs in a single GtkBuilder file and then load these windows in different classes (each class corresponding to a different window)? For instance, currently I'm doing things like:

def __init__(self):
    self.builder = gtk.Builder()
    self.builder.add_from_file('gtkbui开发者_如何学JAVAlder.xml')
    self.welcome_dialog = self.builder.get_object('welcome_dialog')
    self.builder.connect_signals(self)
    self.welcome_dialog.show()

This does produce a functioniong piece of software, but it spits out all kinds of warnings like:

welcome_dialog.py:38: RuntimeWarning: missing handler 'on_contract_window_response'
  self.builder.connect_signals(self)

for each of the signal handlers I have defined in Glade for all the other windows. I guess all I want to do is connect the signals for this single window/dialog and ignore everything else, but I'm not sure how to do that. Or maybe I am doing something horribly wrong and I should be splitting up each window into a different GtkBuilder file? Or connecting the signals for every possible window at the same (initial) time?


Using gtk.Builder.add_from_file adds the entire hierarchy from your file to the Builder object, which is why you're getting the signal connection warnings; the builder.connect_signals() call tries to connect up everything.

Instead, use gtk.Builder.add_objects_from_file to choose the individual top-level window or widget that you want to handle in your current class.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜