Version 0 of Embedding Glade UI Files into Tcl/Gnocl Scripts

Updated 2009-12-31 21:51:40 by WJG

WJG (31/Dec/09) Loading a glade file into Gnocl is fine, but what if its necessary to compile the script using FreeWrap? What is the simplest way of encapsulating the glade XML code into the package? As can be seen from the example below, a glade XML UI file can be included as a simple string and then implemented using the gnocl::glade buffer command.

#!/bin/sh
# the next line restarts using tclsh \
exec tclsh "$0" "$@"

package require Gnocl

#---------------
# Create a simple layout, a widget with a button.
#---------------
set gladeBuffer {<?xml version="1.0"?>
<glade-interface>
  <requires-version lib="gtk+" version="2.12"/>
  <widget class="GtkWindow" id="window1">
    <property name="window_position">GTK_WIN_POS_CENTER</property>
    <property name="default_width">300</property>
    <property name="default_height">100</property>
    <child>
      <widget class="GtkButton" id="button1">
        <property name="visible">True</property>
        <property name="can_focus">True</property>
        <property name="receives_default">True</property>
        <property name="label" translatable="yes">Close Me!</property>
        <property name="response_id">0</property>
      </widget>
    </child>
  </widget>
</glade-interface>}

#---------------
# Load the buffer.
#---------------
set glade1_widgets [gnocl::glade buffer $gladeBuffer]

#---------------
# Register the widgets using their glade names.
#---------------
foreach item $glade1_widgets {
    foreach {gnocl glade} $item {}
    set $glade $gnocl
}


#---------------
# Tweak settings, and display.
#---------------
$button1 configure -onClicked {gnocl::beep}
$window1 show -onDestroy {exit}
gnocl::mainLoop