glade test 1

Using Glade 1

Getting Started

Step 1 - Design a Window

  1. Open Glade, and create a new file
    (File/New menu item)
  2. Click on the Window icon
    (leftmost item under the Toplevels tab)
    This will add a main window to your glade program. It will be named window1.
  3. Next, click on the Common tab in the Window Properties pane
    (lower right) and scroll down a bit to the Widget Flags section.
  4. Check the Visible checkbox.
    If you don't make the main window visible, how are you going to be able to tell if your program is running? :)
  5. Save it with the extension .glade, e.g. test1.glade

This will produce a .glade xml file which describes the interface.

You don't need to be concerned with this xml, there's no need even to look at it, much less edit it. The sample below is provided just to satisfy your curiosity:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.16.1 -->
<interface>
  <requires lib="gtk+" version="3.0"/>
  <object class="GtkWindow" id="window1">
    <property name="visible">True</property>
    <property name="can_focus">False</property>
    <property name="title" translatable="yes">Glade Test 1</property>
    <child>
      <placeholder/>
    </child>
  </object>
</interface>

Step 2 - Link to Euphoria

Create a Euphoria program to load and run the .xml you just created:

include GtkEngine.e

add(builder,"~/demos/examples/glade/test1.glade") 

main()

Save this as test1.ex. If you keep the names the same, it will be less confusing.

Step 3 - Test Run

test1

You will always run from an x-terminal (mate-terminal, etc) until your program is completely finished. There is no way around this if you ever expect to get it completely debugged.

Run the program:

$> eui test1



Step 4 - Adding Widgets

x2


test2 You'll now have a window with a fairly complete menu and a functioning Quit button.

But wait!
The button works, but the File/Quit menu item doesn't!

Let's fix that:

Now your File menu Quit option will...erm.. quit.


Step 5 - Connecting Euphoria Functions

Let's add some actual Euphoria code next. Follow the steps directly above, but this time click on the Help menu item, and expand the list so that you can select imagemenuitem10 (Help/About).

In your terminal you should see something like:

-----------------------------------------------
-- Undeclared function in test1.glade
-----------------------------------------------

---------------------------
global function help_me() 
---------------------------

return 1
end function

What to do? Copy the function prototype and paste it into your Euphoria program. Then edit it to look like the one below:

test3
 --------------------------
 global function help_me() 
 --------------------------
 Info(,,"About","My fine program!")
 return 1
 end function

Run it again, and click on the Help/About menu item. Note that your program is still only 7 lines of code.



On to topic two