GTK+ and Glade3 GUI Programming Tutorial - Part 2
Choosing a Programming Language for GTK+ Development
In part 1 of the GTK+ and Glade3 GUI Programming Tutorial series, we designed a graphical user interface (GUI) for a GTK+ text editor application. After doing so, we were left with an XML file (tutorial.glade) which described our application's user interface.
In this part of the GTK+ and Glade3 GUI Programming Tutorial series I will be discussing the various programming languages available for GTK+ development. Subsequent parts of this tutorial will cover both C programming and Python programming. With my help, you will have to make the decision of which one you want to learn how to use (or both!).
GTK+ and Glade3 GUI Programming Tutorial Contents
Contents
-
Part 1 - Designing a User Interface Using Glade 3
- Quick Overview of GTK+ Concepts
- Introduction to Glade3
- Getting Familiar with the Glade Interface
- Manipulating Widget Properties
- Specifying Callback Functions for Signals
- Adding Widgets to the GtkWindow
- How Packing Effects the Layout
- Editing the Menu (or Toolbar)
- Final Touches to the Main Window
- Getting Additional Help Using Glade
- What Next?
- Part 2 - Choosing a Programming Language for GTK+ Development
- Part 3 - Writing a Basic Program to Implement the Glade File
Which is the BEST Language?
Let's get this out of your system now. This is a question for which you can spend the rest of your life reading answers to--and each will be different. The problem is that this is the wrong question to ask as the answer is different for every person in each different circumstance. Each language comes with it's advantages and it's drawbacks. The question to ask: Which language is well suited for me on this particular project?
Language Choice Considerations
The important thing to remember when starting in with a language, is to keep an open mind about other languages. You may start GTK+ programming with language X, and later switch to language Y once you know and understand how it's benefits are suited to your task. The GTK+ concepts will remain the same from language to language.
- Experience Level How experienced you are with programming in general as well as how much time, patience, and devotion you are willing to spend are important factors in choosing a language. People without any programming experience have to learn fundamental programming concepts as well as the syntax and features of a new language. An experienced programmer can pick up a new language very quickly in comparison and can focus more on what the language has to offer as opposed to it's learning curve. Furthermore, if you're already a PHP expert, perhaps starting GTK+ development with PHP might appeal to you. Maybe you took a course on C++ in college and want to start there. Maybe you only worked with Visual Basic but are ready to take the plunge and learn C.
- Activity and Community Support GTK+ is written in C. Other languages are available through "language bindings" which "wrap" the functionality. How active the project is which provides said bindings is an important factor. You want to choose a language that is up-to-date with new releases of GTK+ and bug fixes (all languages I've mentioned are pretty well up to date). Furthermore, a strong user-base and thus large community will be important as you get most of your support from the community. The more people using a particular language for GTK+, the more information there will be readily available.
- Efficient Programmer vs. Efficient Program There's often a trade-off between how easy the program is to use and how efficient the program is in terms of speed and how much you can do with it on a lower-level. For many applications, the difference in efficiency of any two languages is negligable--and a new programmer would never even notice. For this reason, the increase in productivity is often the deciding factor. As and example, if I needed to write a program which allowed me to simply interface with some command-line utitlity through a GUI, I would likely choose Python or Ruby. However, if I were going to develop a sophisticated, powerful IDE, I would likely choose C or C++. In fact, you can even use several languages in one project! You could write the memory or processor intensive routines in C or C++ and do the rest in Python or Ruby.
- Language Sexiness That's right-- how a language looks and feels is often a factor. You spend a lot of time staring at that code. How it flows on the screen, how it reads, and the overall development process in a particular language might appeal to you more than another. You should enjoy the programming you're doing. It's great having options isn't it!
A Look at Python vs. C
I have chosen to fork this tutorial into 2 languages based on the above criteria. It is my humble opinion that C and Python fit the above criteria best. Both have very, very strong community support and are being used for a large portion of the projects developed for Linux and especially GNOME. Furthermore, they sit on sort of opposite ends of the spectrum with regard to the efficiency vs. productivity debate. You could even follow this tutorial down both paths and compare the 2 languages yourself.
If you have no programming experience, or perhaps just a little experience with something like Visual Basic or PHP, I recommend starting with Python. Even if you are an experienced programmer with C, C++, or Java experience you may want to learn Python. It's an exciting modern language, fun to program with, and incredible quick to learn and use. For Rapid Application Development in Linux, Glade and Python make a great team. Learn more about the Python GTK+ binding PyGTK at www.pygtk.org.
If you're an experienced programmer or dedicated student, it may be worth your while to learn C or C++ for GTK+ development--especially if you're already familiar with C or C++. Learning GTK+ in C makes switching to another language such as Python a breeze. Furthermore, you'll have more options for contributing to existing projects. Personally, I do the majority of my GTK+ development in C despite the extra time it takes.
What's Next?
In GTK+ and Glade3 GUI Programming Tutorial - Part 3 I will talk about setting up your development environment and walk through a minimal implementation of the Glade file we created in part 1 using both C and Python.
If you don't want to read along and would rather just see the final implementations:
- Glade XML file describing GTK+ text editor GUI (tutorial.glade from part 1)
- GtkBuilder XML file descirbing GTK+ text editor GUI (tutorial.xml from part 2)
- GTK+ text editor implemented using C (main.c from part 4)
- GTK+ text editor implemented using Python (tutorial.py from part 4)
28 Comments about "GTK+ and Glade3 GUI Programming Tutorial - Part 2"
RSS Feed
I have created a client server socket programm in fedra core 8 using c language.
all i need is i want a window with two buttons one for client side and other for server side so that if i click on respective buttons it has to link to the terminal so that i can run the respective programm.
please hep me.
thanks in advance,
Gagan
Thanks for the article. I also strongly recommend looking at D bindings of GTK+ named GtkD. D is a powerful, fast and easy programming language that is between C/C++/C# and Python.
I would try a different approach. If at all possible I would try to invoke the
C program from python, using either os.system or one of the different popen functions
depending on how you communicate with the program.
I've only picked up python in the last 2 years but it really is much easier to code and debug, much more portable, more productive, elegant, has comprehensive higher level libraries, and is just more "sexy" as Micha puts it. Whether you're a programming newbie, or very experienced, I think python is nearly always better (unless you are writing a device driver!).
I am eagerly waiting for the tutorial part-3 in this series.
Regards,
Kunal
I want to use Glade 3 and C++ to develop applications under Linux, so I'm learning a lot from your tutorials, especially the more complete one you posted earlier ('Simple Gnome Application Using libglade and C/GTK+').
Information on Glade 3 seems fairly thin on the ground, similarly with using it with C++ (I'm still struggling with that a bit). I'm eagerly awaiting your third part of this tutorial!
Can't wait to to see the next chapter.
Waiting impatiently for Part 3.
After trying that route I've decided to go back to square one and use libglade and GTK+ with C (no Python or PyGTK).
The ease of PyGTK to build a GUI is very nice but take a good look at the Python/C API and you'll change your mind about that approach. But if your application is written in Python then a GUI written in PyGTK with libglade is cake.
Hope that saves other people the trouble that I ran into.
There is one info I have looked for all over the web but can't seem to find the answer (I'm probably blind...)
How to link the signal of a button to another widget within glade. Clicking one button to simply call & open another window within the same glade file. A detailed procedure on that subject could be very useful.
About the only thing I really need to do is have the PyGTK GUI pass a list of filenames to my c functions and then display in a text box the output that normally goes to stdout.
Pyrex a good tool for this? Or would you recommend a different approach?
Thanks a million!
Keep up the great work.
Thank you.
Leave a Comment about "GTK+ and Glade3 GUI Programming Tutorial - Part 2"