Extension Modules => Extension Modules => GTK-Server => Topic started by: Support on December 03, 2007, 07:42:42 am

Title: GTK Glade - Hello World
Post by: Support on December 03, 2007, 07:42:42 am
This example is using the GTK Glade designer to create a fixed size window, apply a fixed position grid and putting a label in the center of the screen. The ScriptBasic event handler is looking for the close window system button event to exit the REPEAT loop.


Code: [Select]

' Glade Hello World

' GTK Interface
include gtk.bas

' GTK Interface Function
FUNCTION GUI(g0, g1, g2, g3, g4, g5, g6, g7, g8, g9)
LOCAL gtk_cmd
gtk_cmd = STR(g0) & " " & STR(g1) & " " & STR(g2) & " " & STR(g3) & " " & STR(g4) & " " & STR(g5) & " " & STR(g6) & " " & STR(g7) & " " & STR(g8) & " " & STR(g9)
GUI = GTK::gtk(gtk_cmd)

' GTK Function DEF's

' Initialize GTK & Glade

' Load and show Glade defined window
xml = GUI("glade_xml_new", "")
GUI("glade_xml_signal_autoconnect", xml)

' Get window ID and define window close event
win = GUI("glade_xml_get_widget", xml, "window1")
GUI("gtk_server_connect", win, "delete-event", "window")

' Event Handler
this_event = GUI("gtk_server_callback", "WAIT")
UNTIL this_event = "window"

END - Glade project XML file
Code: [Select]

<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
<!DOCTYPE glade-interface SYSTEM "">


<widget class="GtkWindow" id="window1">
  <property name="visible">True</property>
  <property name="title" translatable="yes">Hello</property>
  <property name="type">GTK_WINDOW_TOPLEVEL</property>
  <property name="window_position">GTK_WIN_POS_NONE</property>
  <property name="modal">False</property>
  <property name="default_width">400</property>
  <property name="default_height">350</property>
  <property name="resizable">True</property>
  <property name="destroy_with_parent">False</property>
  <property name="decorated">True</property>
  <property name="skip_taskbar_hint">False</property>
  <property name="skip_pager_hint">False</property>
  <property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
  <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
  <property name="focus_on_map">True</property>
  <property name="urgency_hint">False</property>

    <widget class="GtkFixed" id="fixed1">
      <property name="visible">True</property>

<widget class="GtkLabel" id="label1">
 <property name="width_request">122</property>
 <property name="height_request">17</property>
 <property name="visible">True</property>
 <property name="label" translatable="yes">Hello World !</property>
 <property name="use_underline">False</property>
 <property name="use_markup">False</property>
 <property name="justify">GTK_JUSTIFY_LEFT</property>
 <property name="wrap">False</property>
 <property name="selectable">False</property>
 <property name="xalign">0.5</property>
 <property name="yalign">0.5</property>
 <property name="xpad">0</property>
 <property name="ypad">0</property>
 <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
 <property name="width_chars">-1</property>
 <property name="single_line_mode">False</property>
 <property name="angle">0</property>
 <property name="x">128</property>
 <property name="y">128</property>


To get an idea of the types of widgets you can use in your screen design, check out the following link.

GNOME 2.20 Release Notes (

GTK+ Reference Manual (
Title: GTK Glade - Hello World
Post by: Pjot on February 08, 2008, 09:22:06 am
The code can be improved as follows:
Code: [Select]

' Glade Hello World

' GTK Interface
include gtk.bas

' Initialize GTK & Glade
gtk_init("NULL", "NULL")

' Load and show Glade defined window
xml = glade_xml_new("")

' Get window ID and define window close event
win = glade_xml_get_widget(xml, "window1")
gtk_server_connect(win, "delete-event", "window")

' Event Handler
    this_event = gtk_server_callback("WAIT")
UNTIL this_event = "window"


The 'gtk.bas' file in the Scriptbasic include directory already contains individual wrappers for the GTK and GLADE functions mentioned in the GTK-server configfile. This way you can program GTK as if you are using the original API.

Title: GTK Glade - Hello World
Post by: Support on February 09, 2008, 10:05:35 am

Thanks for the code clean-up !



Here is a link to the GTK Widget Gallery (