DEV Community

Cover image for Some Strategies for Studying New Technologies: PyGTK
Naufan Rusyda Faikar
Naufan Rusyda Faikar

Posted on

Some Strategies for Studying New Technologies: PyGTK

I have been studying a new technology, exempli gratia PyGObject, especially PyGTK, for around 1.5 months. As we know already, GObject was originally develop in C. So, anything else than that must be wrappers only. But do not even worry, since there is not any different on what *GObject is capable of. If anything, it could be just performance, for Python is relatively run slower compare to C in general. I would think if your application does not require graphic intensive processing, you can safely prefer Python to C.

GTK or even PyGTK is not a new technology at all, it has been there for a decade or two. What I meant by "new technology" in here is something really meant for beginners as they have absolutely no experience in writing such application. In spite of having no coach or partner, I want to share how I self-taught to get my first steps by relying solely on the internet.

1. Googling All the Time

Sure, it could be any web search engine that exists today, e.g. DuckDuckGo. You know, sometimes it becomes controversial when I am as a GNU/Linux user get caught not using open source technologies and even not aware of my privacy. I personally do not take too much time of listening to other people judging me when I am very well to know what I am doing. We are the writer of our own life story. I prefer Google to others just because it fits my personal needs.

But really, the essential part is not what search engine we shall use, but it is merely about try searching it first whenever we have questions. For the most part, this is how I managed to get answers to almost every problems of mine when it comes to programming.

Let us say that we want to write our very first GTK application. So, we would come up with, at least, a very commonly used keyword: "PyGTK tutorial" which we may just wrote in the Google search box. This is what I got at the first try:

Google Search Results

And then the tutorial from the official GNOME website which is still on the first search page: https://developer.gnome.org/gnome-devel-demos/stable/tutorial.py.html.en; they are all there to give us a complete guide to getting started.

Some people will end up on YouTube, because it is more interesting to see people trying to "teach us" how to get things done. I do not have any complaints, since often that is my personal way of getting excited about learning something.

After all, it is really easy to write our first PyGTK application, from installing all required dependencies to distributing worldwide. Let me take a more special case, let us say that I am interested in developing a Flatpak application. Again, the first thing to do is googling.

The first entry that appears most likely always be the official documentation Flatpak, at least as of the time I am writing this article. Sadly, it seems to provide only a simple script as our hello-world application. Whereas developing a GUI application could be more complex than it actually is.

Even Google was not quite sure when I looked for a more specific keyword: "pygtk flatpak tutorial";

Google Search Results

The first result was a Reddit thread from someone asking for tutorials, not of much use. Luckly, the second one was from Bilal Elmoussaoui. It is actually what I was looking for! Although, it seems to be his first and last article talking about PyGTK and Flatpak. Sigh. But at least, I came to know what to do next;

  1. Installing GNOME Builder; and
  2. Adding Meson in the list to learn in addition to PyGTK and Flatpak!

Well, yes, it was too much for me as a newbie. In any case, at least, I can still keep my premise: googling is a way to do for any developer.

Click ... click ... tap ... tap ... Awesome! Now, we have our own hello-world by just a few clicks and taps. It is, indeed, a simple thing, but we will disagree if we have no idea where we shall go.

2. Reading Someone Else's Code

As long as we still remember that PyGTK is an open source technology, we will find almost anywhere people write and share their source code for a spectacular set of GTK applications. For sometimes, we will have a hard time implementing what any of the documentation tells and suggests. By no mean they did a bad job writing documentation. Although, sometimes it is. But it is more likely we need an example or two, how a real-world application had implemented it. In a simpler way, what is the best practice of using this class and all their respective functions to do this and that.

People often advised that it will not ever be possible to lift a big stones by only one person. We grow, develop and learn from each other, until then we can build even a skyscraper. By learning with others does not always mean meeting and having a chat with them. Sometimes, it could merely be reading someone's else code. As reading is of use to come up with an approach that we may not have thought of in our entire life.

Do not think of reading as a separate thing, because it is always done after looking for things. Both of them are couples all the time.

Let us take a look at a different story of mine. I do know that urllib there and already built-ins in Python distribution. But somehow, I had struggled in finding any good articles tutoring how to do certain things using urllib. I ask to myself, why on earth would people prefer other packages when there is a built-in one.

Trying to do import requests did not seem successful, because I had to install it manually beforehand, by using PIP to be precise, I thought. Well, I cannot do so. As Meson has its own procedure for installing packages. So, I turned my steering for a moment to read Meson's documentation. Womp, womp ... said the sad trombone. Err, why was I thinking of Meson, when it might actually have something to do with Flatpak. Since for me, it is a lot easier to read a JSON for Flatpak than a build script for Meson. I have learned from it that we should consider taking the most simple thing we could imagine in solving any case, for the first attempt.

After gooling for minutes, I found a way of doing so. There is a script called "Flatpak PIP Generator" on the official Flatpak repository.

At another time, I wanted to have a scroll animation for my Gtk.ScrolledWindow. I have read the GTK concept about drawing stuff here. In the end, I only knew about classes and functions to use, but still did not get the how-to.

While it might be a lot of work, we probably do not want to skip a code written in other than Python or whatsoever language we used to. Writing "gtk scroll animation" in the search led me to an article by Julian, whereas using the keyword "pygtk" did not help. So, I have forced myself to read Julian's code in Rust. Meanwhile it is a language I just heard of not too long ago and never had a chance to try it. After struggling a little, pouring out sweat that never dripped, I managed to rewrite it in Python. It turns out to be a nice language, actually.

Speaking of exploring and reading belongs to someone else, I have a random small tip. Some nosy programmers sometimes create their own filename extensions, so people browsing the source code are confused about how to open them. For example, Some of them can be recognized by the operating system, while others are not.

Alt Text

As we can see from the selected file icon, the file with the "ayt" extension must be an archive which will be opened by simply double clicking it. But guess what the following?

Alt Text

Even though they have the same extension, they are not the same file type. Or even this? What could it be?

Alt Text

If we are lucky, we could figure it out by trying to open them using our beloved text editor.

Alt Text

No matter if they are binary files, just open them anyway.

Alt Text

Screenshot from 2021-03-25 06-38-34

Bang!

3. Inspecting Existing Applications

It is always a best practice to research some of the similar applications we are going to develop or some of which use the same toolkit. If it is a GTK application, fortunately, we have another great tool to be considered, it is GtkInspector. So, we are able to get some insights and even reproduce some good user interface implementations of existing applications that are known to be beautiful and user-friendly.

Alt Text

4. Hanging Out with Others

As weak creatures, we always need guidance in doing something. Luckily, we find various discussion rooms on the internet, such as GitHub Discussions and internet relay chat (IRC), easily. I remember that someone once gave us advice that ideas and creativity come through interacting with other people, or something similar. And I have proved it myself by taking many benefits of doing so.

However, there are a number of points that need to be considered when starting to enter a question-answer community. Some of them have general guidelines that are very worthy of following:

If you do not aware of their rules, I am afraid that you will end up with someone giving a sarcastic reply like this: https://letmegooglethat.com/?q=for+loop+python.

5. Sharing Helps

It is very not fair to me talking about anything that is just about taking benefits from others, but I have to be bold in speaking of making benefits to others. As besides learning by doing, there is also learning by teaching. Let us say that we are sharing a public gist, what we are all hoping for? It is obvious, a discussion of other approaches. Since to impart our knowledge means to be open receiving others. Good luck!

Discussion (0)