Sunday, November 18, 2007

TechBlog: GTK+ programming starters

TechBlog: GTK+ programming starters

GTK+ programming starters

Hey friends,

Bored of programming in CUI (character user interface), wanna do some GUI programming, want it to run in Linux as well as in the Windows environment. then GTK+ is for you.


GTK stands for GIMP Tool Kit.

GTK is a a multi-platform library for creating graphical user interfaces. It is designed to be small and efficient, but still flexible enough to allow the programmer freedom in the interfaces created. GTK allows the programmer to use a variety of standard user interface widgets such as push, radio and check buttons, menus, lists and frames. It also provides several "container" widgets which can be used to control the layout of the user interface elements.


To make life easier for you, GTK presents this flexibility in a uniform framework. Specifically, it implements its own support for object oriented programming that is well adapted to the purposes of a user interface toolkit and it aims at providing a reasonable sane and disciplined programming interface. This uniformity and discipline is intended to make it easy and reliable to access GTK from languages other than C


Ok , enough of the talk... lets start on some hands on coding for a better understanding of the library.



I would suggest you to download and install the Glade before starting.

Glade is a RAD tool to enable quick & easy development of user interfaces for the GTK+ toolkit and the GNOME desktop environment.

It is very similar to the Visual Basic development environment. With all drap and drop features you can come up with a proffessional looking software within minutes.

I would tell you how to make an application that would have 2 buttons - one to eject the CD tray, and the other to Load the CD tray.

I will use the Linux environment ( but it is entirely my choice, you may use Windows in case you want to)


OK. Here it comes ...





Step 1. Open Glade and Start a new project.





Choose Project -> New.





Step 2. Choose 'Window' from the palette. This is the main window, and we would build everything on it.





Add 'Vertical Boxes' and make 2 rows.





Add 2 buttons by choosing 'Buttons' from the Palette toolbar and add one to each row.


Step 3. Now Click on the Button1 and choose View -> Show Property Editor.





Put a proper name for the button1 as "Eject" and choose "Load" for button2.





Choosing button1 only, go to the Signals tab and choose 'clicked' in the signal. Click on Add button. This is the callback function for the signal. That is whenever there is an event of mouse click on the button1, the on_button1_clicked() function will be invoked.





Do the same with button2.


Step 4. Save the project and note the path it is saved.






The project should look a bit like this now !




Step 5. 'Build' the project. This creates all the .c files required for the project and automatically puts in barebone code in it too!!





Step 6. Here comes the hard core coding part, but do not fear !


In the Projects directory, go to the src folder. This is where the actually codes are saved. There should be a number of files in here, but the one of our concern is the callbacks.c file.


open it. you should see two empty functions -- void on_button1_clicked and void on_button2_clicked.





Now, add this code to the on_button1_clicked: system("eject");

and in the on_button2_clicked add: system("eject -t");





eject and eject -t are the shell commands to eject and load a CD tray respectively. We are passing this to system() function. The system function takes a string arguments and runs it in a shell. So what we effectively get is a CD tray opener !





Now save and close the file.





Step 7. In the parent directory, run the autogen.sh script from the terminal, by typing ./autogen after going to the parent directory. This should compile and build the project and create an executable file. Run the executable file and enjoy !!!








You have built a professional level GUI program. If you compile/ build it in windos environment, you would get an windows executable.



Simple, isn't it?




In case you have doubts or you want to know more, write comments here. I am also available at my email address given.

Friday, July 6, 2007

The internet

Hey folks!
Good to be back after a long time.

The topic I want to tell you about today is "internet".
well let me clear this first. The word "internet" has been created from - "interconnection of networks".

Any interconnection of networks is termed as an internet.
There is a slight difference between "internet" and THE "Internet" ( notice the capital I). The Internet is the World Wide Web (WWW) as we know of. This is also a interconnection of networks, but this consists of interconnection of a number of networks spread throughout the world.

The internet I am talking about is any general interconnection of networks.
The internet is logically divided into a number of layers, with the layers arranged in a stack like fashion. The layers are namely -

(from the top to the bottom)
1. Application layer
2. Transport layer.
3. Datalink layer.
4. The host to network layer.

The tasks and roles of each layers are well defined and so is the interface between any two layers are well defined. This make is easier to change or modify any layer without disturbing of effecting any other layer.

The Host to Network layer is the layer that is made up of the electrical signals that pass through the wires and make up the 1s and the 0s.

In the data link layer, the information moves in the form of 'packets' - which are units of data. The have a header as well as a trailer attached to it.

The transport layer is the layer that takes up teh responsibility of setting up a connection and ensuring that the data arrives in order and is dutyfully acknowledged (in case of connection oriented protocols) and is ultimately brought down gracefully.

All the network based programs reside in the application layer.


Will talk more about the layers in details later on. Till then, enjoy !!