-
Notifications
You must be signed in to change notification settings - Fork 80
Issues modifying the entries of a ComboBox #606
Comments
Can you make your example working? You can do this by pasting the xml into a string and the |
And don't be confused about the |
Absolutely! Sorry about that, I'm trying to get the XML in a julia string and getting additional odd issues, likely a product of me being new to this, I can post what I have really quickly but I don't believe it will work just yet. I've cut the project down to an MWE as much as possible. using Gtk
glade_xml = """
<interface>
<requires lib="gtk+" version="3.24"/>
<object class="GtkListStore" id="list_charge_ports">
<columns>
<!-- column-name stringcol -->
<column type="gchararray"/>
<!-- column-name idcol -->
<column type="gint"/>
</columns>
<data>
<row>
<col id="0" translatable="yes">test_from_glade</col>
<col id="1">1</col>
</row>
</data>
</object>
<object class="GtkWindow" id="main_window">
<property name="can-focus">False</property>
<child>
<!-- n-columns=3 n-rows=1 -->
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="row-homogeneous">True</property>
<property name="column-homogeneous">True</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-left">5</property>
<property name="margin-right">5</property>
<property name="margin-start">5</property>
<property name="margin-end">5</property>
<property name="margin-top">5</property>
<property name="margin-bottom">5</property>
<property name="label" translatable="yes">Charge COM Port</property>
<attributes>
<attribute name="font-desc" value="Sans Bold 10"/>
</attributes>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkComboBox" id="combo_charge_port">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="model">list_charge_ports</property>
<property name="id-column">1</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="btn_refresh_ports">
<property name="label" translatable="yes">Refresh</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
</object>
<packing>
<property name="left-attach">2</property>
<property name="top-attach">0</property>
</packing>
</child>
</object>
</child>
</object>
</interface>
"""
gladefile = GtkBuilder(buffer=glade_xml)
win = gladefile["main_window"]
showall(win)
combo_charge_port = gladefile["combo_charge_port"]
list_charge_ports = gladefile["list_charge_ports"]
btn_refresh_ports = gladefile["btn_refresh_ports"]
function btn_refresh_ports_clicked(widget)
push!(list_charge_ports, ("test", 2))
end
signal_connect(btn_refresh_ports_clicked, btn_refresh_ports, "clicked") |
So here it seems to add the entries but they are not shown. Are you sure you can link a list store with multiple entries with a combobox? |
This is indeed the problem. I've tried using list stores with single columns in them ( |
Are you on OS X as well? I can't get it work with a single column either. But this seems not to be a Julia problem. Glade also does not show the text entries, but it should. |
I'm on Windows! And yup, I just checked and the preview-snapshop in Glade also doesn't even show the default entry that was inserted from Glade itself (which also shows up on the Leaf object in Julia). I don't know if you noticed this, but the number of items in the dropdown increases when you push additional objects to the So all in all, it's accessible, but Gtk refuses to display it for some reason. I still think I'm not doing something correctly in terms of linking the combobox to the list, but this is all quite new to me. |
I think the GtkComboBox is the wrong widget. I usually use its Text variant: GtkComboBoxText. |
I think you miss the cell renderer |
Oh! Is this a different widget I should be finding in Glade? I'm not seeing an exact analog to the text version |
I always use the text based, which seems to be one, where you have a list store with just one column of strings. |
I'll find the widget and try this out, as well as potentially getting the renderer to work. If so, I'll report back here and hopefully be able to make a contribution to the docs. Thank you so much for the help! |
I would recommend that you use
I always use approach 1. for combobox and approach 2. for treeviews |
Looks like it works! I wasn't able to do much with the standard combobox, but the text one works well. The last thing is being able to clear the options (or access the underlying |
Found it. For anyone needing to modify these entries: The methods to do this are defined in lists.jl starting here. The method to remove things is generally |
I currently have a simple combobox connected to a GtkListStore with a default entry. I want to add a few entries (and later remove / update them) and finally, access the currently chosen value when a button is pressed. I've made a mockup in Glade, but am struggling to actually see the results even though I can access the added values with indexing.
The docs point me to the list and tree widgets but I'm having a very difficult time generalizing what's going on here to modifying an existing widget from glade. Using the standard accessor notation from the built gladefile, it seems I only have access to the
GtkListStoreLeaf
and not theGtkListStore
The text was updated successfully, but these errors were encountered: