python - pygobject add item to container within signal callback -


i'm working on simple gui application using pygobject , gtk+ 3. in case, i'm wanting have button brings dialog box when click ok add item list. have part working final part doesn't work adding item list. appears item added it's empty. it's selectable, though, small. i've tried adding other kinds of widgets gtk.button see if weird gtk.label. when add gtk.label in constructor works fine.

also know isn't quite way things , there oddities how i'm doing stuff in code i'm still learning how use pygobject/gtk+ 3. imagine problem stupid i'm overlooking.

mainwindow.py

import gi gi.require_version('gtk', '3.0') gi.repository import gtk import promptdialog  class mainwindow(gtk.window):   def addurlresponse(self, dialog, response, listbox):     if(response == gtk.responsetype.ok):       print(dialog.get_text())       label = gtk.label(dialog.get_text())       print(label.get_text())        listbox.add(label)       if(response != gtk.responsetype.delete_event):       dialog.destroy()     def addurl(self, button):     urldialog = promptdialog.promptdialog("add url", self)      urldialog.connect('response', self.addurlresponse, button.get_parent().get_parent().get_parent().get_children()[1])     urldialog.show_all()     def __init__(self):     gtk.window.__init__(self, title="mpv-vj")      self.playlistsbar = gtk.flowbox()     self.newbtn = gtk.button.new_with_label('+')     self.playlistsbar.add(self.newbtn)     self.playlistslist = gtk.listbox()     self.playlistsview = gtk.box(orientation=gtk.orientation.vertical, spacing=1)     self.playlistsview.pack_start(self.playlistsbar, false, false, 0)     self.playlistsview.pack_start(self.playlistslist, true, true, 0)      self.playlist1view = gtk.box(orientation=gtk.orientation.vertical, spacing=1)     self.playlist1bar = gtk.flowbox()     self.addurl1btn = gtk.button.new_with_label('+url')     self.addurl1btn.connect('clicked', self.addurl)     self.playlist1bar.add(self.addurl1btn)     self.addfile1btn = gtk.button.new_with_label('+file')     self.playlist1bar.add(self.addfile1btn)     self.adddir1btn = gtk.button.new_with_label('+dir')     self.playlist1bar.add(self.adddir1btn)     self.playlist1list = gtk.listbox()     self.playlist1view.pack_start(self.playlist1bar, false, false, 0)     self.playlist1view.pack_start(self.playlist1list, true, true, 0)          self.playlist2view = gtk.box(orientation=gtk.orientation.vertical, spacing=1)     self.playlist2bar = gtk.flowbox()     self.addurl2btn = gtk.button.new_with_label('+url')     self.playlist2bar.add(self.addurl2btn)     self.addfile2btn = gtk.button.new_with_label('+file')     self.playlist2bar.add(self.addfile2btn)     self.adddir2btn = gtk.button.new_with_label('+dir')     self.playlist2bar.add(self.adddir2btn)     self.playlist2list = gtk.listbox()     self.playlist2view.pack_start(self.playlist2bar, false, false, 0)     self.playlist2view.pack_start(self.playlist2list, true, true, 0)          self.plviewsbox = gtk.hpaned()     self.plviewsbox.pack1(self.playlist1view, true, false)     self.plviewsbox.pack2(self.playlist2view, true, false)      self.viewbox = gtk.hpaned()     self.viewbox.pack1(self.playlistsview, true, false)     self.viewbox.pack2(self.plviewsbox, true, false)     self.viewbox.set_position(200)      self.logview = gtk.listbox()      self.contentbox = gtk.vpaned()     self.contentbox.pack1(self.viewbox, true, false)     self.contentbox.pack2(self.logview, true, false)     self.contentbox.set_position(400)      self.toolbar = gtk.flowbox()     self.newbtn = gtk.button.new_with_label('new')     self.toolbar.add(self.newbtn)     self.loadbtn = gtk.button.new_with_label('load')     self.toolbar.add(self.loadbtn)     self.savebtn = gtk.button.new_with_label('save')     self.toolbar.add(self.savebtn)      self.mainbox = gtk.box(orientation=gtk.orientation.vertical, spacing=1)     self.mainbox.pack_start(self.toolbar, false, false, 0)     self.mainbox.pack_start(self.contentbox, true, true, 0)      self.add(self.mainbox)      self.resize(1000, 500) 

promptdialog.py

import gi gi.require_version('gtk', '3.0') gi.repository import gtk  class promptdialog(gtk.dialog):   def get_text(self):     return(self.entry.get_buffer().get_text())    def __init__(self, message, mainwindow):     gtk.dialog.__init__(self, title="prompt")      self.set_modal(true)     self.set_transient_for(mainwindow)      self.label = gtk.label(message)     self.entry = gtk.entry()     self.get_content_area().pack_start(self.label, true, true, 0)     self.get_content_area().pack_start(self.entry, true, true, 0)      self.add_button("ok", gtk.responsetype.ok)     self.add_button("cancel", gtk.responsetype.cancel) 

the widget added window needs have .show() method called before it'll appear.


Comments