Linking more functions

Opening a file

Use Glade to select the File/Open menu item, which will be named imagemenuitem2
(note that you are free to change the name of any item by typing the new name into the ID: entry on the General tab for that item.
Let's do so, and change this to the more meaningful name: file_open (as usual, no quotes).

Now select the Signals tab, and set the activate handler to be open_file (ok, so I'm not being very original, too bad :p)

Click the Save the current project toolbutton, and run your program again. In the terminal you should see something resembling:

---------------------------------------------------------------------
-- Undeclared function in /home/irv/demos/examples/glade/test1.glade
---------------------------------------------------------------------

-----------------------------------------------------------------------
global function open_file() 
-----------------------------------------------------------------------

return 1
end function

You should have expected that. Copy this template, paste it into your Eu program, and fill in the blank. You'll also have to be sure to add
include GtkFileSelector.e to the top of your program (right after include GtkEngine.e).


include GtkEngine.e
include GtkFileSelector.e

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

main()

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

-----------------------------------------------------------------------
global function open_file() 
-----------------------------------------------------------------------
display(fileselector:Open("*.ex"))
return 1
end function
Click on a file, and you should see the filename and path displayed on your terminal.

Adding Widgets

Containers

If you recall, the original Box we added as the first item in our window had 3 'divisions'. We filled the first (top) with a menu, and the 3rd (bottom) with a button. The middle one is empty, and so doesn't show at all. Let's add some things to the middle.

We can't put more than one item in there, try it, you'll see.

We'll need a container if we want more than one thing there, so choose Box, drop it into the empty middle space, change number of items to 2, and click create. The orientation is vertical, which won't do for this particular demo, so change it to Horizontal.

In the left-hand panel of the Box we just added, drop an image. It's the little house with the yellow roof. In the right-hand panel, drop a label. Under Appearance/Label: type in some text. Use markup if you like, and click the Use Markup checkbox. Save your work, you should do this frequently.

test5 What about the image? We'll need to pick one, so click on the little missing image icon on your program's window, and choose:

*You'll find that if you use an image loaded from a file, the image must be in the same folder as your program, otherwise it's difficult (but not impossible) for your program to find it at runtime.

Run the program again, and note that no changes or additions or adjustments were required to the 12 lines of Euphoria source code.



test6 Suppose we want an image more pleasing than the one above? Just change the open_file function a bit:

-----------------------------------------------------------------------
global function open_file() 
-----------------------------------------------------------------------
fileselector:filters = {"image"}
object newfile = fileselector:Open("*")
if sequence(newfile) then
	set("image1","from file",newfile)
end if
return 1
end function
Just click on the image you prefer. I like this one:



More complex object such as TreeViews, ListViews, etc. will take some experimenting with Glade, creating them with Glade is not nearly as easy as just typing in a few lines of Euphoria code. Look at some of the demos to see how that's done. If you wish to use Glade for these, you'll have to experiment. It seems impossible to cover the details in anything less than a video series or a complete book.