Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
910 views
in Technique[技术] by (71.8m points)

gtk3 - GTK: How to get the nicks and values from a GSchema enum programmatically

I have the following GSchema:

<schemalist gettext-domain="example">
    <enum id="com.example.unit.temperature">
        <value nick="Celsius" value="0"/>
        <value nick="Fahrenheit" value="1"/>
    </enum>
    <schema id="com.example.corefreqgtk" path="/com/example/">
        <key name="unit-of-temperature" enum="com.example.corefreqgtk.unit.temperature">
            <default>'Celsius'</default>
            <summary>Unit of temperature</summary>
            <description>The unit of temperature used across the app</description>
        </key>
    </schema>
</schemalist>

And I'm looking for a way to get the nicks and values of the enum com.example.unit.temperature programmatically.

What I would like to do is to bind the unit-of-temperature key to a ComboBoxText to allow the user to select the unit of temperature, but I would like to avoid to define twice the enum inside the GScheme and in code.

My goal would be to initialize the ComboBoxText reading the possible values directly form the GSettings.

question from:https://stackoverflow.com/questions/65834384/gtk-how-to-get-the-nicks-and-values-from-a-gschema-enum-programmatically

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use GSettingsSchema to gather the data inside a GSettings schema. For keys associated with enumeration values, g_settings_schema_key_get_range() will return all possible values as an array.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...