I’m trying to replicate https://gitlab.gnome.org/GNOME/libadwaita/-/blob/main/demo/pages/flap in Python with PyGObject.
I’ve managed to create the all the UI parts but have some problem with the logic how to populate some of the drops down. One example would be:
<child>
<object class="AdwComboRow">
<property name="title" translatable="yes">Fold Policy</property>
<property name="selected" bind-source="flap" bind-property="fold-policy" bind-flags="sync-create|bidirectional"/>
<property name="model">
<object class="AdwEnumListModel">
<property name="enum-type">AdwFlapFoldPolicy</property>
</object>
</property>
<property name="expression">
<closure type="gchararray" function="fold_policy_name"/>
</property>
</object>
</child>
Where the C code looks like
static char *
fold_policy_name (AdwEnumListItem *item,
gpointer user_data)
{
switch (adw_enum_list_item_get_value (item)) {
case ADW_FLAP_FOLD_POLICY_NEVER:
return g_strdup (_("Never"));
case ADW_FLAP_FOLD_POLICY_ALWAYS:
return g_strdup (_("Always"));
case ADW_FLAP_FOLD_POLICY_AUTO:
return g_strdup (_("Auto"));
default:
return NULL;
}
}
I’m trying something like this in Python
@Gtk.Template.Callback()
def fold_policy_name(self, item):
if item == 'ADW_FLAP_FOLD_POLICY_NEVER':
return 'Never'
elif item == 'ADW_FLAP_FOLD_POLICY_ALWAYS':
return 'Always'
elif item == 'ADW_FLAP_FOLD_POLICY_AUTO':
return 'Auto'
else:
return NULL
Which doesn’t work since item is not a string <Adw.EnumListItem object at 0x7f1cf3ba1900 (AdwEnumListItem at 0x5585e4660750)>
How can I do adw_enum_list_item_get_value (item)
in Python to be able to do the compare?