Project

General

Profile

Actions

Basic builder

It's a very simple interface built with GtkBuilder.

  1. add the file with _gtkBuilderNewFromFile
  2. if needed, get any included object (for example, a window, a button ...) with _gtkBuilderWidgetGet
  3. if needed, define any callback and others codes ...
  4. run the GTK+ loop.

Note : Don't call _gtkWidgetShow(All), all included widgets will be automatically shown.

Look this Scol code :

fun cbDestroy (obj, uparam)=
    _fooS strcat "upram = " itoa uparam;
    /* Stop the GTK+ loop */
    _gtkMainQuit;
    0;;

fun cbButtonClicked (obj, uparam)=
    _fooS strcat "button param = " uparam;
    0;;

fun main ()=
    _showconsole;
    // add a .xml file
    let _gtkBuilderNewFromFile _channel _checkpack "tests/2dgtk/0.glade" -> builder in

    // get object from the builder : a window and a button
    let _gtkBuilderWidgetGet builder "main_window" -> win in
    let _gtkBuilderWidgetGet builder "button_1" -> button in
    (
    // define the callbacks
    _gtkWindowCBdestroyed win @cbDestroy 10;
    _gtkButtonCB button @cbButtonClicked "yes !" SCOL_GTK_BUTTON_CB_CLICKED;
    // run the GTK+ loop
    _gtkMain;
    0
    );;

and now, the xml file :

<?xml version="1.0"?>
<interface>
  <requires lib="gtk+" version="2.16"/>
  <!-- interface-naming-policy project-wide -->
  <object class="GtkWindow" id="main_window">
    <property name="visible">True</property>
    <property name="title" translatable="yes">Test 2dGtk - 0</property>
    <child>
      <object class="GtkVBox" id="main_box">
        <property name="visible">True</property>
        <property name="spacing">5</property>
        <child>
          <object class="GtkButton" id="button_1">
            <property name="label" translatable="yes">button 1</property>
            <property name="visible">True</property>
            <property name="can_focus">True</property>
            <property name="receives_default">True</property>
          </object>
          <packing>
            <property name="position">0</property>
          </packing>
        </child>
      </object>
    </child>
  </object>
</interface>

Return Examples

Updated by iri about 13 years ago ยท 7 revisions