Re: [pygtk] gtk.ListStore columns in a gtk.ComboBox (added full code listing)
Hi, Having recently had my own struggle with ComboBoxen (more specifically ComboBoxEntry's), I can sum up my experience with the following statement: (Py)Gtk wants ComboBoxes' models to have a str column first! I've tried using a ListStore(gobject.TYPE_PYOBJECT) (for my own models) with custom cell renderers specified (using set_cell_data_func()) and lost hours trying to get it to work. In the end, I ended up adding a str column as the _first_ column and copying a string representation of my objects to that column. This, in the end, does what I want: it saves a reference to one of my models in the ListStore. Moral of the story: adding a str column as the first column solved all my problems. If you want, you can check how I handle ComboBoxEntries: https://translate.svn.sourceforge.net/svnroot/translate/src/trunk/spelt/spelt/gui/edit_area.py In the first paragraph, I said (PyGtk), because I'm not sure if this is because of PyGtk or the C Gtk lib itself. The weird thing is that I'm using a ListStore(gobject.TYPE_PYOBJECT) with a TreeView and it works just great (in PyGtk and Gtk#)! P. S. I'm not sure why, but I don't seem to receive any responses from Mr. Kintanar. :/ Isaac Alston wrote: 2008/6/22 Bertrand Son Kintanar [EMAIL PROTECTED]: [...snip - code sample] notice the if statement highlighted. this will show the column if we set the flag to visible otherwise it will not show the column Yes, I think this might work, although I am dubious about: self.inputTreeView.append_column(column) because I don't think ComboBox has that method. However, this seems to be a lot of work... I was under the impression that gtk.ListStore was the model in a sort of mvc system in which the view is independent from the model which should easily allow different views. In this instance, it doesn't appear to be the case, which is annoying. I will sleep on this :-) . Thanks for your efforts, begin:vcard fn:Walter Leibbrandt n:Leibbrandt;Walter org:Translate.org.za adr:;;;Pretoria;Gauteng;;South Africa email;internet:[EMAIL PROTECTED] title:Developer tel;work:(012) 460 1095 x-mozilla-html:FALSE url:http://translate.org.za version:2.1 end:vcard ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] gtk.ListStore columns in a gtk.ComboBox (added full code listing)
2008/6/22 Bertrand Son Kintanar [EMAIL PROTECTED]: can you throw in the whole code? not just snippets? Yes, here it is: http://dpaste.com/hold/58199/ and here's the glade file: http://dpaste.com/hold/58200/ I didn't post them the first time, because I wasn't sure if the rest of the file was relevant. -- Isaac ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] gtk.ListStore columns in a gtk.ComboBox (added full code listing)
2008/6/22 Bertrand Son Kintanar [EMAIL PROTECTED]: i think this is because of your combo.set_model(self.search_lstore)which contains two elements. an int and a string. that makes it show the id and the name. Yes, I thought that might be the case, but perhaps you misunderstood me: I wish to keep a ListStore with an id and a field description, but only display the field description. I want to have an id for each item in the list, because the item name is not fixed and I dislike comparing English strings in checks - they could be i18ned in the future. So my question remains: how can I display a single column from a multi-column ListStore in a ComboBox? -- Isaac ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] gtk.ListStore columns in a gtk.ComboBox (added full code listing)
future. So my question remains: how can I display a single column from a multi-column ListStore in a ComboBox? I've never tryed in a ComboBox. I just guess is not very different than an Entry. I paste here some code I have worked out in the past. the code is working but I had to cut many parts that would be useless. I hope I didn't cut too much. The key point is that you create a completion object a renderer a liststore The renderer knows that it should represent what is stored in one column of the liststore, while you instruct the completion to use the other via set_match_function. entry = gtk.Entry() completion = gtk.EntryCompletion() completion.set_property('popup-set-width', True) completion.set_property('minimum-key-length', 0) completion.connect('match-selected', self.match_selected_cb, field_name) listore = gtk.ListStore(int, str) renderer = gtk.CellRendererText() completion.pack_start(renderer) completion.add_attribute(renderer, 'text', 1) completion.set_match_func(self.match_func, (col_entry, mode)) completion.set_model(listore) entry.set_completion(completion) Hope that helps sandro *:-) ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] gtk.ListStore columns in a gtk.ComboBox (added full code listing)
2008/6/22 Alessandro Dentella [EMAIL PROTECTED]: listore = gtk.ListStore(int, str) renderer = gtk.CellRendererText() completion.pack_start(renderer) completion.add_attribute(renderer, 'text', 1) completion.set_model(listore) I've already tried this and I end up with every column in the liststore being displayed in the ComboBox - maybe you missed my earlier code posting - http://dpaste.com/hold/58199/ , the glade file: http://dpaste.com/hold/58200/ , and a screenshot: http://tinyurl.com/3sbu4w . -- Isaac ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] gtk.ListStore columns in a gtk.ComboBox (added full code listing)
2008/6/22 Bertrand Son Kintanar [EMAIL PROTECTED]: [...snip - code sample] notice the if statement highlighted. this will show the column if we set the flag to visible otherwise it will not show the column Yes, I think this might work, although I am dubious about: self.inputTreeView.append_column(column) because I don't think ComboBox has that method. However, this seems to be a lot of work... I was under the impression that gtk.ListStore was the model in a sort of mvc system in which the view is independent from the model which should easily allow different views. In this instance, it doesn't appear to be the case, which is annoying. I will sleep on this :-) . Thanks for your efforts, -- Isaac ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/