Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.8k 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.


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

1 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...