Author Topic: GTK - Glade XML Project File Example  (Read 23122 times)

Support

  • Administrator
  • *****
  • Posts: 22
    • View Profile
GTK - Glade XML Project File Example
« on: March 26, 2006, 09:05:44 PM »
Here is an example of using GTK and the Glade GUI designer project file with  ScriptBasic.

Code: [Select]

' Glade XML Demo

' GTK Interface
include gtk.bas

include cio.bas
cio::detach()


' 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)
END FUNCTION

' Load GTK Function DEF's
GUI("g:\\gtk-server\\gtk-server.cfg")

' Enable GTK Logging
' GUI("gtk_server_logging", 1)

' Create GUI
xml = GUI("gtk_server_glade_file", "G:\\sb\\examples\\gtk\\glade_gui.xml")
win = GUI("gtk_server_glade_widget", "window")
GUI("gtk_server_connect", win , "destroy", "exit")
quitbtn = GUI("gtk_server_glade_widget", "QuitButton")
GUI("gtk_server_connect", quitbtn, "clicked", "quit")


' Event Handler
REPEAT
event = GUI("gtk_server_callback", "WAIT")
UNTIL event = "exit" OR event = "quit"


' End Program
GUI("g_object_unref", xml)
GUI("gtk_exit", 0)

END

Linux


Linux


Windows


Windows


Glade XML Project File
Code: [Select]

<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">

<glade-interface>

<widget class="GtkWindow" id="window">
  <property name="visible">True</property>
  <property name="title" translatable="yes">Preferences</property>
  <property name="type">GTK_WINDOW_TOPLEVEL</property>
  <property name="window_position">GTK_WIN_POS_NONE</property>
  <property name="modal">False</property>
  <property name="resizable">True</property>
  <property name="destroy_with_parent">False</property>
  <signal name="delete_event" handler="on_window1_destroy"/>

  <child>
    <widget class="GtkVBox" id="AllDaGoodies">
      <property name="border_width">6</property>
      <property name="visible">True</property>
      <property name="homogeneous">False</property>
      <property name="spacing">0</property>

      <child>
   <widget class="GtkNotebook" id="Preferences">
     <property name="visible">True</property>
     <property name="can_focus">True</property>
     <property name="show_tabs">True</property>
     <property name="show_border">True</property>
     <property name="tab_pos">GTK_POS_TOP</property>
     <property name="scrollable">False</property>
     <property name="enable_popup">False</property>

     <child>
       <widget class="GtkVBox" id="LocationOptions">
         <property name="border_width">6</property>
         <property name="visible">True</property>
         <property name="homogeneous">False</property>
         <property name="spacing">0</property>

         <child>
      <widget class="GtkRadioButton" id="Here">
        <property name="visible">True</property>
        <property name="can_focus">True</property>
        <property name="label" translatable="yes">_Here</property>
        <property name="use_underline">True</property>
        <property name="relief">GTK_RELIEF_NORMAL</property>
        <property name="active">False</property>
        <property name="inconsistent">False</property>
        <property name="draw_indicator">True</property>
      </widget>
      <packing>
        <property name="padding">0</property>
        <property name="expand">False</property>
        <property name="fill">False</property>
      </packing>
         </child>

         <child>
      <widget class="GtkRadioButton" id="There">
        <property name="visible">True</property>
        <property name="can_focus">True</property>
        <property name="label" translatable="yes">_There</property>
        <property name="use_underline">True</property>
        <property name="relief">GTK_RELIEF_NORMAL</property>
        <property name="active">False</property>
        <property name="inconsistent">False</property>
        <property name="draw_indicator">True</property>
        <property name="group">Here</property>
      </widget>
      <packing>
        <property name="padding">0</property>
        <property name="expand">False</property>
        <property name="fill">False</property>
      </packing>
         </child>
         <child>
      <widget class="GtkButton" id="HelloButton">
        <property name="visible">True</property>
        <property name="can_default">True</property>
        <property name="can_focus">True</property>
        <property name="label">Hello</property>
        <property name="use_stock">True</property>
        <property name="relief">GTK_RELIEF_NORMAL</property>
                  <signal name="clicked" handler="on_button1_clicked"/>
      </widget>
         </child>

       </widget>
       <packing>
         <property name="tab_expand">False</property>
         <property name="tab_fill">True</property>
       </packing>
     </child>

     <child>
       <widget class="GtkLabel" id="LocationLabel">
         <property name="visible">True</property>
         <property name="label" translatable="yes">Location</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>
       </widget>
       <packing>
         <property name="type">tab</property>
       </packing>
     </child>

     <child>
       <widget class="GtkColorSelection" id="ColorSelection">
         <property name="border_width">6</property>
         <property name="visible">True</property>
         <property name="has_opacity_control">True</property>
         <property name="has_palette">False</property>
       </widget>
       <packing>
         <property name="tab_expand">False</property>
         <property name="tab_fill">True</property>
       </packing>
     </child>

     <child>
       <widget class="GtkLabel" id="ColorLabel">
         <property name="visible">True</property>
         <property name="label" translatable="yes">Color</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>
       </widget>
       <packing>
         <property name="type">tab</property>
       </packing>
     </child>

     <child>
       <widget class="GtkFontSelection" id="FontSelection">
         <property name="border_width">6</property>
         <property name="visible">True</property>
         <property name="preview_text" translatable="yes">abcdefghijk ABCDEFGHIJK</property>
       </widget>
       <packing>
         <property name="tab_expand">False</property>
         <property name="tab_fill">True</property>
       </packing>
     </child>

     <child>
       <widget class="GtkLabel" id="FontLabel">
         <property name="visible">True</property>
         <property name="label" translatable="yes">Font</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>
       </widget>
       <packing>
         <property name="type">tab</property>
       </packing>
     </child>

      <child>
        <widget class="GtkScrolledWindow" id="scrolledwindow1">
          <property name="visible">True</property>
          <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
          <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
          <property name="shadow_type">GTK_SHADOW_IN</property>
          <property name="window_placement">GTK_CORNER_TOP_LEFT</property>

          <child>
            <widget class="GtkTextView" id="text1">
              <property name="visible">True</property>
              <property name="can_focus">True</property>
              <property name="editable">True</property>
              <property name="justification">GTK_JUSTIFY_LEFT</property>
              <property name="wrap_mode">GTK_WRAP_WORD</property>
              <property name="cursor_visible">True</property>
              <property name="pixels_above_lines">0</property>
              <property name="pixels_below_lines">0</property>
              <property name="pixels_inside_wrap">0</property>
              <property name="left_margin">0</property>
              <property name="right_margin">0</property>
              <property name="indent">0</property>
              <property name="text" translatable="yes"></property>
            </widget>
          </child>
        </widget>
        <packing>
          <property name="padding">0</property>
          <property name="expand">True</property>
          <property name="fill">True</property>
        </packing>
      </child>

      <child>
        <widget class="GtkLabel" id="EditLabel">
          <property name="visible">True</property>
          <property name="label" translatable="yes">Edit</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>
        </widget>
        <packing>
          <property name="type">tab</property>
        </packing>
      </child>


   </widget>
   <packing>
     <property name="padding">0</property>
     <property name="expand">True</property>
     <property name="fill">True</property>
   </packing>
      </child>

      <child>
   <widget class="GtkVBox" id="TheGlobalButtonArea">
     <property name="visible">True</property>
     <property name="homogeneous">False</property>
     <property name="spacing">0</property>

     <child>
       <widget class="GtkHSeparator" id="hseparator1">
         <property name="visible">True</property>
       </widget>
       <packing>
         <property name="padding">0</property>
         <property name="expand">False</property>
         <property name="fill">False</property>
       </packing>
     </child>

     <child>
       <widget class="GtkHButtonBox" id="hbuttonbox2">
         <property name="visible">True</property>
         <property name="layout_style">GTK_BUTTONBOX_END</property>
         <property name="spacing">0</property>

         <child>
      <widget class="GtkButton" id="QuitButton">
        <property name="visible">True</property>
        <property name="can_default">True</property>
        <property name="can_focus">True</property>
        <property name="label">gtk-quit</property>
        <property name="use_stock">True</property>
        <property name="relief">GTK_RELIEF_NORMAL</property>
                  <signal name="clicked" handler="on_window1_destroy"/>
      </widget>
         </child>
       </widget>
       <packing>
         <property name="padding">0</property>
         <property name="expand">False</property>
         <property name="fill">False</property>
       </packing>
     </child>
   </widget>
   <packing>
     <property name="padding">0</property>
     <property name="expand">False</property>
     <property name="fill">False</property>
   </packing>
      </child>
    </widget>
  </child>
</widget>

</glade-interface>

Support

  • Administrator
  • *****
  • Posts: 22
    • View Profile
Re: GTK - Glade XML Project File Example
« Reply #1 on: August 10, 2011, 08:32:44 PM »
GTK-Server for Linux has been available for over 5 years. You can download the source to build on your distribution from www.gtk-server.org. Note the ScriptBasic folder and README file to build the gtk-server.so that is specific for ScriptBasic.