[Glade-users] Building a simple composite widget?
Juan Pablo Ugarte
juanpablougarte at gmail.com
Thu Feb 22 14:26:34 UTC 2018
On Tue, 2018-02-20 at 16:03 -0600, Pat Riehecky wrote:
> I'm trying to build a set of reusable widgets. Basically I have a
> bunch
> of places where I need the same dropdown boxes. Each box may have a
> different selected value (Instance A uses Index 1 while Instance B
> uses
> Index 2), but the items in the list are the same.
>
> I'm really just looking to build a set of Pre-populated
> "GtkComboBox"
> items - A simplified example is attached.
>
> I'd prefer to store the possible enum values within a widget and
> then
> interrogate it rather than a bunch of "GtkListStore" items I need to
> edit over and over.
>
> Is there a way I can convert the attached "ProtocolDropdown" object
> into
> a widget? I'd want it to stay associated with the "Protocols"
> "GtkListStore".
>
> Building a C program to track this feels like massive overkill, but
> I
> don't see a way to "Export object as widget".
First of all you have to make your custom GtkComboBox derived class
https://developer.gnome.org/gtk3/stable/GtkWidget.html#composite-templa
tes
(In Glade check the composite checkbox next to widget ID to make that
toplevel a composite template)
Then you will need to write a custom catalog for Glade to know about
your new widget
https://developer.gnome.org/gladeui/3.20/catalogintro.html
AS the first implementation you do not need to load your library in
Glade you can simply define your new class and add parent="GtkComboBox"
Something like...
<?xml version="1.0" encoding="UTF-8"?>
<glade-catalog name="custom"
depends="gtk+">
<glade-widget-classes>
<glade-widget-class name="MyComboBox"
generic-name="mycombobox"
title="MyComboBox"
parent="GtkComboBox"/>
</glade-widget-classes>
<glade-widget-group name="custom" title="Custom Widgets">
<glade-widget-class-ref name="MyComboBox"/>
</glade-widget-group>
</glade-catalog>
should do the trick after you save the catalog in a place specified in
Glade->preferences->Extra catalog paths
hope this helps
JP
More information about the Glade-users
mailing list