Gnome development via Python Programming –
Hi Guys. So, today we would be talking about the infamous Gnome development. So, if you are new to python and Linux, then this is not the perfect place for you. You need to go back and get some basics cleared. But, if you are a basic python programmer and if you know at least how to work on fedora or ubuntu, then this tutorial is exactly for you.
People who have a background of other programming languages, this blog may help them, but having at least the basics right will give them a clear understanding of exactly how this works. So, do we start?
First things that we would be needed is a stable python environment. The one which I am using and I would suggest using is Python 2.7. Though people nowadays use Python 3.3 or 3.4, I would suggest using 2.7, because it is still the world’s most largely used version of python and extremely stable and compatible. Thought Python 3.4 is compatible, but there are some things which still break python 3.4, which obviously we don’t want.
The second thing would be a proper Python GTK. The latest and stable release as of now is Python GTK+. Although before proceeding further, one must read the GNOME HIG, which is Human Interface Guidelines, on how to design an effective Gnome App with the help of python. But again, if it were so easy, you wouldn’t be here in the first place.
Gnome HIG is not as easy to understand. Thus, in this blog, I will try to give the best understanding possible and to make it as simple as I can. But once, you have understood everything from this blog, and when I say everything, I mean it. So, after completing this blog, I would surely suggest you reading GNOME Human Interface Guidelines.
To start with GTK+ provide n number of possibilities as well as common design patterns to create an effective user interface. So, assuming that you know how to create and rung python files I will be proceeding forward. Getting started with gnome apps in windows is extremely easy. So, since I had a good understanding about creating python GUI Apps using pyqt and Tkinter , I thought it would be easy to develop gnome GUI apps, but was exactly the opposite.
The hardest part was to get started. All the tutorials I saw when learning was just a direct entry to the GUI way, but with no easy way for beginners. I was getting more and more extremely irritated by how hopeless codes I had written when I started to actually understand Gnome GUI. Hence, after a long search, I finally settled for PyGTK/GTK+ and Glade.
Both are cross-platform, so working, installing and compiling them exactly isn’t a big deal. But, since this is a blog for beginners, I won’t be getting into much detail about Glade and stuff. I would suggest going with a Visual Grep tool which is very simple. When I was learning to develop gnome apps, I didn’t know about V-Grep. But now, I have simplified this for you. You can also use grep from a command line. But sometimes, you just need something simple rather than it being extremely awesome and complicated.
I can’t make it simpler, than using Albert Einstein’s Quote:
4.8 (612 ratings)
“If you can’t explain it to a six-year-old, you don’t understand it yourself.”
Obviously, the quote is a broad concept, but we aren’t here to talk about the quote, are we?
Next thing, you need to understand is the IDE concept. You would obviously be needing a proper IDE. So, as a beginner, I would suggest using PyCharm Community Edition. Pycharm is an Integrated Development Environment which is extremely robust with full support for tab and code completion, refactoring and debugging.
While there are other IDEs like Adjuta and Eclipse, they too can be used for GTK+ Gnome development stack, but none of them is as robustly focused on development as PyCharm.
GTK3 uses introspective bindings which can be problematic for some IDEs. But Pycharm handles it with a charm by generating a skeleton which is also known as its modules. But in case, that’s not our choice, you can always use a package called as fakegir which does the same thing.
But if you try to run an App within PyCharm using fakegir, it will fail, the reason being fakegir files supplants the real GTK application. But still, its a fair trade. You cannot get everything that you want without losing something.
An alternate way would be to use the Gnome development builder IDE. It is an IDE that makes Gnome base building extremely simple.
One look at Gnome development builder and you will know that this works extremely closely with GNOME3 HIG with a minimal interface. Even though with a minimalistic interface, it does include lots of features that will make the gnome applications look like Loki in front of Hulk. Get the point. Yeah! That’s exactly how it is. Besides, the Gnome development builder helps to solve problems and create GUIs on a real-time basis. Gnome builder is a solid ecosystem that you may want to try before getting on to anything else.
And Speaking of PyGTK, which is also awesome, but not exactly a beginner type, it contains PyGObject project which is extremely interesting. It gives developers more power and flexibility. Previously, development of gnome apps was limited by SUGAR due to unavailability of python bindings and lack of its maintenance and packaging. PyGTk also supports the ability to move between Python and C which means you can quickly create prototypes in python, and then simply compile it into C for performance enhancements.
The modules that run on top of the main PyGObject code don’t have to worry about supporting C Python APIs. They only need to understand the base GObject Introspection concepts such as annotation and modelling API’s so that they are wrappable. This base understanding actually makes GObject developers write clearer public APIs by restricting the use of, or confining to private APIs, some of the more esoteric code patterns that C allows.
We don’t have a single runtime, so, unfortunately, you can’t mix scripting languages, but most projects that use introspection will either be written exclusively in one scripting language or use a compiled language for their base and a scripting language for rapid prototyping, as a glue language or for plugins. The biggest challenge has been coordinating with the different libraries and applications which support or are supported by PyGObject.
Introspection is very new and with that comes growing pains. Before the binding developers could work in a bubble, catching up to whatever the API developers added or changed, however, they saw best. However, now everything is so highly integrated that the binding developers have to closely work with the API developers.
This can cause a lot of frustration and a bit of extra work for all involved, but in the long run, the closer collaboration will reveal itself in a better end user experience.
If I have learned anything in GNOME over the years, it is the end user that matters and using Introspection helps move towards that goal.
Speaking of the End User, we have come to an end of this blog. To be precise, the more I say, the more it can get confusing to think of which one to used exactly when starting to learn. Gnome development builder is simple and has lots of features. But Python has extreme support and I would suggest going with that though It can get a bit messy at times.
Here are some articles that will help you to get more detail about the Gnome development via Python Programming so just go through the link.