Re: Parsing custom-typed properties from Glade file



Thank you for your tip, guys!

Here is how I solved:

GType
Glib::Value<MyEnum>::value_type()
{
   static volatile gsize g_define_type_id__volatile = 0;

   if (g_once_init_enter(&g_define_type_id__volatile)) {
    static const GEnumValue color_components_enum[4] = {
      {MyEnum::TYPE_R, "TYPE_R", "red"},
      {MyEnum::TYPE_G, "TYPE_G", "green"},
      {MyEnum::TYPE_B, "TYPE_B", "blue"},
      {0, nullptr, nullptr}
    };
    GType g_define_type_id = g_enum_register_static(g_intern_static_string("color-component"), color_components_enum);
    g_once_init_leave(&g_define_type_id__volatile, g_define_type_id);
  }
  return g_define_type_id__volatile;
}

Em qua., 22 de jul. de 2020 às 14:12, N <nicklas karlsson17 gmail com> escreveu:
Enums are very useful for selection, combobox. I have selections and parse the number in the combox, this does not feel ideal.

In C with switch(...) and correct warning turned on compiler flag a warning in case a value is forgotten, I trick I often used to remember all cases but only work then enumerations are known at compile time. As a bonus work get easier for computer with numbers instead of text strings.

As I only handle types known at compile time glade file should then correct done have these and only these enumerations, an exact mapping. To check these agree is also an interesting problem.

Nicklas Karlsson


> Is Type a custom enum? I have never tried to use such an enum in a glade
> file, but I looked at what gtk does.
>
> Their enums are registered with g_enum_register_static(). Each enum
> value is specified with a GEnumValue, which contains a nickname. The
> nickname is used in glade files. Example:
>                  <property name="direction">none</property>
>
> On 2020-07-22 07:00, Rodolfo Ribeiro Gomes via gtkmm-list wrote:
> > Hello, everyone.
> >
> > I created a custom widget that has a Glib::Property of an enum type.
> > Glib::Property<Type> property_type_;
> >
> > When I try to load from a glade file, I got this error message:
> >
> > Gtk-WARNING **: 01:43:34.849: Failed to set property
> > gtkmm__CustomObject_widget_color_slider.type to 1: Could not parse '1'
> > as a glibmm__CustomBoxed_N6studio11ColorSlider4TypeE
> >
> > Here is the xml property line:
> >             <property name="type">1</property>
> >
> > How can I properly parse the property tag contents ?
> >
> >
> _______________________________________________
> gtkmm-list mailing list
> gtkmm-list gnome org
> https://mail.gnome.org/mailman/listinfo/gtkmm-list


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]