GTK+ and Glade3 GUI Programming Tutorial - Part 2
December 27th, 2007Choosing 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
- 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)
Categories
Popular Posts
RSS Feeds
Archives
December 27th, 2007 at 2:23 pm
[...] GTK+ and Glade3 GUI Programming Tutorial - Part 2 By Micah 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 … Micah Carrick - http://www.micahcarrick.com/ [...]
January 6th, 2008 at 1:56 pm
Thanks for the GTK tutorials, very helpful for beginning gnome developers! Keep the rest coming!
January 26th, 2008 at 11:14 am
A fantastic tutorial for programming newbies like me. Hopefully, we'll soon see more parts of this tutorial to come?
Thank you.
January 31st, 2008 at 12:35 pm
Micah; great tutorial. I wrote my first gnome gui using gtkmm w/glade thanks to you.
February 2nd, 2008 at 8:08 pm
Excellent Part 1 tutorial, and I'm eagerly awaiting part 2 in python!
Keep up the great work.
February 3rd, 2008 at 10:36 am
Micah I'm having a problem with the gtk-builder-convert. It works fine for your tutorial.glade and tutorial.py. However I wanted to experiment and I added a Button to the interface (I split the status bar into two containers, status bar on the left, button on the right) and then when I run the gtk-builder-convert I Get about 20 lines of errors. Any idea why It doesn't like a button?
February 3rd, 2008 at 11:35 am
A new tutorial (3rd part) is just about finished. It will be posted very soon. As for the GtkBuilder errors, you might want to read http://developer.gimp.org/api/2.0/gtk/gtk-migrating-GtkBuilder.html and the associated bugs. Specifically with buttons, you might want to delete the "response-id" property from the glade file before attempting to convert.
February 17th, 2008 at 4:42 pm
Thanks for these tutorials. I'm using them as a guide to putting a GUI on my old C image processing program. I followed your advice about using glade and python to create a nice working GUI. Now how do I interface that with my C code? I've looked around for a guidance on this and the best advice I've found is to use Pyrex.
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!
February 18th, 2008 at 8:25 am
Honestly, I'm not the best person to ask. My experience with Python is somewhat limited. One of the PyGTK mailing lists would be much better suited to giving you information on Pyrex.
February 23rd, 2008 at 1:39 am
This is a great tutorial!
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.
February 23rd, 2008 at 7:06 pm
As it turns out PyGTK with libglade is far from easy to put a GUI on your existing C programs. Its very easy to make the GUI with PyGTK. But very difficult to interface that GUI with existing C code. To do the latter you'll either have to learn to implement the Python/C API (very, very painful), or use a simplifying tool such as Pyrex - in which case you'll have to translate all your existing c code into "pyrex" language which is fairly simple but a LOT of work. Not to mention if you want to distribute your application cross-platform then the combination of Pyrex, PyGTK, Python, and C together just made that darn near impossible.
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.
March 1st, 2008 at 8:47 pm
HAPPYB-DAY!!! you have moms permission to take $100.00 out of her credit card!!!(delete this comment if you think it will interfere with your post)
March 1st, 2008 at 8:55 pm
oh that didnt work... go here http://www.rtoot3.com/micahs-bday.html
March 10th, 2008 at 1:40 am
Great work! I hope the 3rd part is coming soon! Tutorials for Glade 3 are seemingly non-existent. Yours is the only one I've found.
March 10th, 2008 at 12:15 pm
Hi! Thanks for this great tutorial! I'm looking forward for the rest of it, however, cause I'd like to learn GTK+ C programming and this is the best tutorial I found (very clear)
March 12th, 2008 at 10:20 am
Wonderful tutorial!
Waiting impatiently for Part 3.
April 21st, 2008 at 7:16 am
Thanks a dozen for this useful tutorial.
Can't wait to to see the next chapter.
April 26th, 2008 at 2:23 pm
Very clear and helpful tutorial, good work!
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!
May 6th, 2008 at 7:31 pm
Hi Carrick,
I am eagerly waiting for the tutorial part-3 in this series.
Regards,
Kunal
May 9th, 2008 at 3:57 pm
Hope it won't be too much longer for part 3! :)
May 9th, 2008 at 5:38 pm
Part 3 is almost done guys... sorry it's been taking so long!
May 30th, 2008 at 6:24 am
Awesome website, extremely useful. Hope part 3 will come out soon looking forward to it.
May 30th, 2008 at 9:16 pm
Regarding the C versus python issue, I've been programming extensively in C/C++ for 25 years. C code just flows from my fingers without evening thinking about it. Guess what language I'd recommend? That would be Python!
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!).
May 27th, 2009 at 3:08 am
Jeff,
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.
October 9th, 2009 at 9:05 pm
emm.. informative..