Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm trying to implement a drop down list in an Ubuntu app using Glade (GTK+3) and Python. I can get the ComboBoxText to display, populated with strings. However when I close the window it is contained in and then re-open it, the combobox is not there, just a completely blank window.

I added the ComboBoxText widget in question to a window in Glade. I then added this code in my Python programme:

def on_button_edit_clicked(self, widget):
    """ display list of events already stored, and allow deletion """   

    self.combo = self.builder.get_object('combo_box')
    self.store = Gtk.ListStore(str)

    self.store.append(['hello'])
    self.store.append(['goodbye'])
    self.combo.set_model(self.store)

   event_editor = self.builder.get_object("event_editor")
   event_editor.show() 

I even tried destroying the widget to see if that helps:

def on_event_editor_destroy(self, widget):
    self.combo.destroy()
    self.store = Gtk.ListStore(str)
    self.combo.set_model(self.store)

EDIT:

I have since tried some alternative code, that included a CellRendererText object, but still no luck.

These are my sources (unfortunately I can't link to them all as I don't have enough of a reputation):

I created a Gtk.ListStore(), then I created a Gtk.CellRendererText(), then I created a Gtk.ComboBox(). This was all in-line with example 13.3 here.

Nothing works. When I open the combobox window a 2nd time, it is just a blank window. Can anyone help please?

share|improve this question
    
You could try to ask such question since it is programming oriented at Stack Overflow. Also check this "gnipsel.com/glade/python06.html for more information. A quick reminders, did you check if 'combo_box' is the name for the combobox used in Glade? Did you added it in the layout manager? –  Stef K Apr 15 '13 at 22:43
    
Hi Stef, I already asked on Stackoverflow, no response :( –  Jon Hudson Apr 15 '13 at 23:35
    
Where is the "layout manager" you speak of? –  Jon Hudson Apr 15 '13 at 23:36
    
You can check here about layout manager which is responsible for placing widgets on a window. –  Stef K Apr 16 '13 at 12:08
    
How are you calling the combobox window? Are you instantiating a new class each time or using show, hide methods? Can you post more code? –  Ian B. Apr 18 '13 at 14:34
add comment

1 Answer

The problem lies with the Window.

You should implement a callback for the 'delete-event' signal of the Window widget.

def on_event_editor_delete_event(self, widget, event):
    self.event_editor.hide()
    return True

This callback hides the Window and returns True so the event isn't propagated further (i.e. the Window isn't destroyed, including your ComboBox).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.