Harsh J

Memoirs of a QWERTY Keyboard

Archive for the ‘Qt’ tag

The case of the non-exiting Mozilla Firefox

9 comments

Being a KDE user has its ups and downs. The ups are that its beautiful, has a very wide and usable range of applications, updates often for bugfixes, and is generally very customizable. The downs are a few – with the Firefox+GTK integration being one of them. It makes your browser look UGLY! Of course, there are Qt-friendly browsers like Opera and Konqueror, even Arora, but these hardly work well with many sites, especially those of Google (Wave, for example). I’m not gonna delve into that subject, since this post is about using Firefox on KDE 4 (version 4.3.x).

You might have heard of the GTK engine that themes for Qt, known as gtk-engine-qt on most distributions (or with -kde4 suffix, if thats how they’ve integrated). This helps all GTK applications look great on KDE by providing *near* native look and feel. So I install that and smile, happy that my entire K Desktop is as I want it – dark, without gloss and perfectly usable with certain plasma widgets. That is until I notice my Firefox simply does not close itself when asked to, and hangs instead.

At first one would think its due to a plugin, or an extension, probably something added on that is causing it to hang when its supposed to terminate. Even the KB article at Mozillazine supports that fact. Perhaps its a popular reason, but I tried and it didn’t solve the issue for me. I jumped a few steps out of frustration and went on to move my .mozilla directory to a different name, just to see if it was a profile-related issue, and it still refused to close, driving me mad having to `killall firefox` it each time since it always hung at exit. So I switched to Opera and used it with horrible colors – Pages appeared normally as they would be rendered but the forms and other things just didn’t go well with my dark color scheme (Eclipse), making it appear like the image below, unreadable and thus untypable upon.

Unreadable, Unseeable - The form elements as they appear in my Opera (While using a dark color scheme in the DE)

Unreadable, Unseeable - The form elements as they appear in my Opera (While using a dark color scheme in the DE)

The browser’s great otherwise, its fast and very customizable, but I couldn’t make any changes to these colors. I suppose one can achieve it by writing their own userstyle.css file but that is too much work. Used Opera until today, when I finally found this (pretty old) bug in the gtk-engine-qt project tracker. Uninstalled gtk-engine-qt and lo, all was normal again, closed fine and opened fine. Re-installed all plugins and extensions, and said bye-bye to Opera.

All I now miss is a native-looking dark theme with Oxygen icons, as my K Desktop contains. I’m making do with the Black Stratini theme as of now, it’s beautiful but I like the Oxygen icons better. 440 words for just the choice of browser on a dark theme, tch.

Written by Harsh

October 9th, 2009 at 10:02 am

PyQt – Signals, Slots and Layouts Tutorial

18 comments

Note: If you’re new to using PyQt but are interested in great cross-platform GUI application development please read the PyQt Introduction article.

Having seen how a simple PyQt application code looks, let’s delve into user-interaction. We’ll learn about Qt’s signal-to-slot connection model for processing input and other events, and layouts for proper placement of widgets on a window.

The PyQt Class Hierarchy

PyQt is completely built upon the Object-Oriented concepts, so it is important to understand how all classes are related to each other in it.

Almost all GUI classes extend upon their Abstract class which defines common behaviour for similar widgets. These abstract classes, or any widget class, inherit QWidget, the base class of all drawable GUI components. QWidget inherits QObject, a class that has nothing to do with GUI but forms the base class of every PyQt class and helps provide the framework-related features.

The following hierarchy diagram depicts this clearly for the QPushButton class:

The QPushButton Class Hierarchy

The QPushButton Class Hierarchy

The QPaintDevice class helps draw (or paint) things on the screen, thus its also used with anything that’s drawable – We’ll learn more about Painting in a later article.

References: QWidget
Read the rest of this entry »

Written by Harsh

May 14th, 2009 at 11:37 am

Posted in Software

Tagged with , , , , ,

Basics of PyQt

one comment

Note: If you’re new to using PyQt but are interested in great cross-platform GUI application development please read the PyQt Introduction article.

This is a total beginners-only post. In this post, I will talk about what PyQt is, what it does and what are its major components you should know about before you start thinking about developing with it. I’ve made a simple Google Docs presentation about these and its viewable below or in full screen at this link.

Read the rest of this entry »

Written by Harsh

April 29th, 2009 at 9:34 am

Posted in Software

Tagged with , , , ,

The PyQt Intro

9 comments

This article is an introduction to the PyQt GUI Application Development Framework that uses Python and Nokia’s Qt.

Contents:

  1. Pretext
  2. Prerequisites
  3. Sample Code
  4. Breaking Down the Code
  5. Getting Further

Pretext

Ever wondered how to easily write good programs using Python? Programs that would run on any platform – from Windows to Mac OS X along with the various Linux variants? Programs that look good, look native, and also work great?

Here’s one solution – PyQt! With it you can create complete, working applications that may look like this:

Fresco - An application developed with PyQt4

Nokia’s Qt is a free (LGPL) cross-platform C++/Java based application-framework, with GUI being its most prominent feature.

PyQt is simply a python-binding to the C++ libraries that Qt provides. Using PyQt one can write neat looking GUI applications that do a lot, and do so easily.

Nokia's Qt 4

A series of articles, starting with this one will aim to tutor interested programmers into using this wonderful library, and developing applications with it.

Prerequisites

The most-minimal pre-requisites are:

  • Basic Python programming knowledge.
  • A little know-how about GUI and the event-based-programming concepts.

Two primary resources where we start from:

  1. Nokia’s Qt
  2. Riverbank Computing’s PyQt

Downloading and installing PyQt is fairly easy on Linux thanks to the various package managers. Do check out the download links at each of the above-mentioned links to get them on other platforms as well. Installation help is also provided by Riverbank Computing to help you set-up the PyQt4 library on your OS.

Sample Code

So let’s start off in the same style as almost everything do in a programmer’s perspective: Hello World!

Below is a well documented program for the same:


import sys

# Importing the necessary Qt classes.

from PyQt4.QtGui import QLabel, QApplication

# We use the from foo import * syntax here because
# all of Qt's objects begin with a Q
# and thus we shouldn't run into namespace problems.

if __name__=='__main__':

	App = QApplication(sys.argv)

	# All Qt programs need an
	# QApplication instance.

	# We pass the sys.argv as its arguments
	# because Qt is adept at handling some
	# of the default command-line options
	# like style, size, etc by itself.

	Label = QLabel( "Hello World!" )

	# QLabel is the class providing a
	# simple label

	Label.show()

	# Like in most GUI toolkits, we have
	# to manually set it to show

	App.exec_()

	# Notice the _ after exec, this is to
	# avoid the confusion with Python's
	# exec() built-in-function

	# exec_() starts the main application
	# loop. Something like main() of other
	# toolkits.

This is how it looks when run, a simple application that displays some popular text:

A simple Hello World application written with Qt

Breaking it down

The first thing we have initialized under our ‘__main__’ is the QApplication instance, App. Every GUI application needs this instance to be present. It handles the look and feel of the application and is the main thread of the same. Without it Qt will error out and not run any GUI.

Next we create a label. A label is a simple text-displaying widget used in many forms to describe the input fields and other things. In Qt, its called the QLabel and resides under the QtGui namespace. We create one with a simple Hello World text under the object name Label.

Now we call the show() method of the label so that it appears on the screen. This method is applicable to all QWidget-class children, and QLabel is one among them. Calling show() draws the label widget’s window on the screen.

Finally, we start the application loop, the one responsible for making an application run as an infinite loop waiting for user-interaction. Its done by the exec_() method of QApplication (App is the instance name). Note the _underscore_ in the function name, this is to avoid confusion between Python’s own exec() built-in-function.

Getting Further

Tutorials

FAQs

Read the rest of this entry »

Written by Harsh

April 26th, 2009 at 8:01 am

Posted in Software

Tagged with , , , , , ,

To keep this blog away from a Necrologist

leave a comment

With the onslaught of these micro-blogging sites I just can’t think of writing anything more than 140 characters. I’ve tried posting a digest of the same in the blog every week just to keep it going here but it does not look so neat. The Lifestream plug-in, now in action at one of my pages, keeps track of most of the 2.0 updates while I try to bring myself back to posting proper web logs.

With the model exams over, I have about a month’s holidays to prepare for the 6th semester exams. Too much time, probably cause I listen in the classes. This semester was pretty good compared to the five before since it had two programming and one cryptography topic accompanied with some mathematics to keep the dullness taking over. I don’t know what they’ve chosen as electives for the next semester, but I do know that learning Compilers and related topics at college has nil possibility now. I can learn things myself but I don’t always have that discipline required, hence the sadness of not being taught.

I’ve decided to merge here, the PyQt blog I have running over at WordPress.com. I’ve not posted much there, and think that it will be better off at my own blog. Will be posting the existing posts one at a time. Qt 4.5 brings in quite a lot of performance boosts and their blog is very active these days with new concepts/features being put up almost every week. Thank you Nokia!

I also upgraded my Ubuntu from 8.10 to 9.04 flawlessly. The updater’s config-file diff warning notices need to have more options since it blocks the update process; an editor should do well. Jaunty Jackalope, as it is called this time, has good updates like OpenOffice.org 3 (Took long enough), Qt 4.5 (Wonder how KDE4 would perform on this one), Python 2.6 (Deprecation warnings, yum). A lot of other updates are present too, I just mentioned the ones I cared about.

One of my cabinet fans started making very loud droning noises and it made my temper flare quite a few times. I literally punched it, hard. The everlasting dust issue also started to seek attention again and I had no choice but to sit down, yet again, and clean the CPU off its dust. The graphic card had quite a lot of dust collected upon it this time, and that was the reason why the computer whined when I played a graphic-intensive game. After cleaning off the cabinet using an air-blower, I detached the side fans and after discovering that they had a secret compartment beneath the sticker I gave it some oiling.

It does not make much noises now, except for a few audible scratches when my Prescott is really hot trying to run the VisualBoy Advance at 400% throttle. Peace in my small room, at last. I’m losing patience on this 4 year old machine and I have probably mentioned that a hundred times. Yet I can’t seem to take a decision and buy a newer PC, and I don’t know why. The only things am sure about right now is on getting a 22-inch monitor and half a terabyte of secondary storage with two or four gigabytes of primary memory thrown in. The processor and the motherboard, however, are still delaying my decision with new ones coming in every other month. I’m dying to dive into the upgrade pool.

Having, at least, three weeks of free time I decided to get myself the Spider-Man’s Web of Shadows game. It does lack in performance but has some cool moves, like the last movie game did. I also want to play the Broken Sword series again but I don’t think I’ll find time to do that. For now, let’s just swing with the symbiotic.

Anyway, that’s all I’ve done in the past three days. More as they come.

Written by Harsh

April 25th, 2009 at 7:59 am

Posted in Personal

Tagged with , , , , , , ,