howto glade freebasic
DESCRIPTION
Howto Glade FreebasicTRANSCRIPT
7/18/2019 Howto Glade Freebasic
http://slidepdf.com/reader/full/howto-glade-freebasic-56d683e68b2be 1/15
Howto: Rapid GUI creation with FreeBasic and glade/Gtk
by Klaus Siebke, www.siebke.com
Preface
For a longer time I was looking for a programming environment that offers both: easy touse and platform independent. Some weeks ago I found FreeBasic to fulfill theserequirements perfectly. ust code your program once and run it in native mode under !S"indows and #inu$ %and if you like you can still run it under &'S(. )dditionally FreeBasicin combination with glade*+tk offers a simple framework to create identical +,Iapplications for "indows and for #inu$.-he only lack so far is a tool to simplify the +,I program creation with glade*+tk.So I wrote a small utility named glade2bas which will help you to reali/e your own +,Iapplication with FreeBasic and glade*+tk.
What you need
1. First of all you need the FreeBasic compiler for your preferred OS which can bedownloaded from: http://www.freebasic.net/.
. !hen you need to install "tk. #f you are usin$ %inu& it's already included in yourdistribution (at least in )buntu/Kubuntu or openSuS*+. ust $o to your packa$emana$er (apt or yast+ and select it. #f you are usin$ -S indows, download thelatest binary from the official serer: ftp://ftp.$tk.or$/pub/$tk/ and install it.
0. !he ne&t component you need is $lade, the user interface builder. For %inu& users
it's the same as for "tk: install the packa$e with your packa$e mana$er that's it.)sers workin$ with -S indows should $o to http://$ladewin0.sourcefor$e.net/,download the latest ersion of $lade and install it.
2. 3n editor to code your application. # would prefer "eany which supports FreeBasicin a ery comfortable way. 4ou can compile and run your application 5out of thebo&5. "eany is aailable for -S indows and %inu& and like all the aboe softwarecomponents it's free. 4ou can download "eany from http://$eany.uena.de/ .6oweer, in some %inu& distributions "eany is already included. #n this case makesure that the distribution's ersion is 7.1 or hi$her (otherwise the FreeBasicsupport is not implemented+.
8. !he $ladebas utility to create a shell pro$ram out of the $lade file. 4ou can
download the source of this utility from my pa$ewww.siebke.com/freebasic/$ladebas.9ip. )n9ip the file in your FreeBasic sourcedirectory and compile it with fbc ;s $ui $ladebas.bas.
A first application
%et's start with a simple e&le. %ike you probably know it from other pro$rammin$lan$ua$es, it's a small 56ello orld5 application.
esigning the interface with glade
!o desi$n the window(s+ you can either use $lade or $lade 0 whateer you prefer.Because it's the newer ersion, # use $lade0 in the followin$ e&le.
7/18/2019 Howto Glade Freebasic
http://slidepdf.com/reader/full/howto-glade-freebasic-56d683e68b2be 2/15
3fter startin$ $lade;0 you will $et this screen:
!o create a new window for your application, direct your mouse pointer to the 5<alette5 andchoose the first icon under 5!opleels5:
=lick on it and your first $lade/"tk window will be created:
>ow you hae to add a layout to the window. 4ou will find it in the 5<alette5 under5=ontainers5:
7/18/2019 Howto Glade Freebasic
http://slidepdf.com/reader/full/howto-glade-freebasic-56d683e68b2be 3/15
3$ain, click on the icon and then into your window. !he window appearance will chan$e asfollows:
>ow you are able to place some elements on the window. #n the 5<alette5 you will find a lotof wid$ets under 5=ontrol and ?isplay5. Select the 5OK button5 and the 5label5 wid$et byclickin$ first on the icon and then on your screen:
7/18/2019 Howto Glade Freebasic
http://slidepdf.com/reader/full/howto-glade-freebasic-56d683e68b2be 4/15
#f you like, you can now resi9e and arran$e the elements a little bit:
!o chan$e the te&t and the action of the elements click on the wid$et to be chan$ed andlook at the 5<roperties5:
=han$e the te&t of the label from 5label5 to 56ello orld@5 and the te&t of the OK button
from 5button5 to 5OK5.
7/18/2019 Howto Glade Freebasic
http://slidepdf.com/reader/full/howto-glade-freebasic-56d683e68b2be 5/15
4our window should now look like this one:
%et's chan$e some properties (title, startup position and si9e+ of the window itself:
7/18/2019 Howto Glade Freebasic
http://slidepdf.com/reader/full/howto-glade-freebasic-56d683e68b2be 6/15
Finally you should define some actions (Asi$nals+ to react on in the FreeBasic pro$ram:
1. ?efine a si$nal to terminate the pro$ram when the window is deleted. "o to theproperties and click on the 5Si$nals5 tab strip. !hen $o to line 5delete;eent andclick in the 56andler column:
!he name of the handler will automatically be completed:
<ress *nter to assi$n the handler name to the eent.
=lick here and
enter an 5o5
7/18/2019 Howto Glade Freebasic
http://slidepdf.com/reader/full/howto-glade-freebasic-56d683e68b2be 7/15
. ?efine a si$nal when the OK button is pressed =lick on the OK button wid$et onyour screen. "o to the properties and click on the 5Si$nals5 tab strip (sameprocedure as with the si$nal aboe the handler name will be automaticallycompleted when you key in 5o5 and press *nter afterwards+:
<lease sae your work now as file 5helloworld.$lade5 by pressin$ the sae button in the$lade main window:
For this simple e&le that's all on the $lade desi$n side. 4ou can now close theapplication and run the utility $ladebas.
7/18/2019 Howto Glade Freebasic
http://slidepdf.com/reader/full/howto-glade-freebasic-56d683e68b2be 8/15
!on"ert glade to FreeBasic with glade#$as
3fter startin$ $ladebas the followin$ screen appears:
=lick on the open button ri$ht to the te&t field and select the file 5helloworld.$lade5.
7/18/2019 Howto Glade Freebasic
http://slidepdf.com/reader/full/howto-glade-freebasic-56d683e68b2be 9/15
>ow you can $enerate the FreeBasic shell pro$ram by clickin$ on the 5=onert5 button:
!he utility has created files: helloworld.decl and helloworld.bas.
Add your logic to the application
%ets hae a look at the $enerated source. Start "eany and open the file helloworld.bas:
7/18/2019 Howto Glade Freebasic
http://slidepdf.com/reader/full/howto-glade-freebasic-56d683e68b2be 10/15
!he $enerated pro$ram is already runable. 4ou can compile und run it. 6oweer it will notreact on the defined si$nals. So it makes sense to add some additional statements.
On the top of the left side you can see the si$nals we defined in the $lade desi$n listed by"eany as 5functions5:
=lick on the first function 5onCbutton1Cclicked5 and the editor on the ri$ht will directlyposition to that function (or S)B in FreeBasic notation+:
>ow you can add a statement to react on the eent that is initiated when the OK button ispressed. ust key in:
print OK button pressed
below the comment bo&.
7/18/2019 Howto Glade Freebasic
http://slidepdf.com/reader/full/howto-glade-freebasic-56d683e68b2be 11/15
!he other S)B (onCwindow1CdeleteCeent+ shall terminate the pro$ram. So key in:
$tkCmainCDuit(+
below that comment bo&.
>ow your code should look this way:
!o%pile the application
!o compile the pro$ram directly out of "eany please check the settin$s. "o to 5Build5 andthen to 5Set #ncludes and 3r$uments5 in the menu:
7/18/2019 Howto Glade Freebasic
http://slidepdf.com/reader/full/howto-glade-freebasic-56d683e68b2be 12/15
-ake sure that the correct path to the FB= e&ecutable is specified for -S indows # hadto chan$e it on my machine as follows:
For %inu& you can leae the "eany default alues unchan$ed ...
... but you will hae to chan$e the !erminal strin$ in the properties:
3fter checkin$ the aboe settin$s press the 5=ompile5 button on the tool bar and you will$et this messa$es in the status window:
Specify the pathof your source
codes here
7/18/2019 Howto Glade Freebasic
http://slidepdf.com/reader/full/howto-glade-freebasic-56d683e68b2be 13/15
3lternatiely you can open a command shell and compile the pro$ram manually.
Run the application
ithin "eany simply press the 5*&ecute5 button and the pro$ram starts:
!ry the OK button an see what happens in the command shell window:
>ow click on the 5&5 on the ri$ht corner of the window ...
7/18/2019 Howto Glade Freebasic
http://slidepdf.com/reader/full/howto-glade-freebasic-56d683e68b2be 14/15
... and the application finishes.
6ere's how it looks in %inu& (kubuntu+:
&u%%ary
#n this lesson you learned how to write a simple $lade/"tk application with FreeBasic.For more information about "tk isit http://www.$tk.or$/. 6int: the $enerated shell pro$ramand the utiltiy pro$ram are fully commented (in en$lish and $erman+ and can sere as
e&les for the $lade/"tk ")# pro$rammin$ with FreeBasic.
7/18/2019 Howto Glade Freebasic
http://slidepdf.com/reader/full/howto-glade-freebasic-56d683e68b2be 15/15
'rou$leshooting
#f you are runnin$ into problems (especially on -S indows+ check the followin$:
?o you hae the latest "tk ersion installed on your systemE!here's a trick: the latest "tk ersion is always part of "#-<. So dowload "#-<
from http://www.$imp.or$/ and install it. 3fterwards copy (with replace+ the directory=:<ro$ram Files"#-<;.7bin into your "tk path, which should be=:<ro$ram Files=ommon Files"!K.7bin.
#s the lib$lade;.7;7.dll correctly installed (either in the application directory or in thewindowssystem0 directory+E
?isclaimer:
-icrosoft (-S+ indows and the indows lo$o are trademarks or re$istered trademarks of -icrosoft =orporation in the )nited Statesand/or other countries.
3ll other product and company names mentioned may be trademarks or re$istered trademarks of their owners.