Harsh J

Memoirs of a QWERTY Keyboard

Archive for the ‘python’ tag

Septectic!

leave a comment

Am mixing a lot of words ain’t I? This is for September + Hectic.

There’s the college technical events coming up on 14th, named ‘Pragmatics’. I’m responsible for the code event under it, and can almost smell the deadlines. Then the next day I leave for the college-provided tour across Kerala and a part of TN itself. All nicely ending with the Indian Python Conference 2009, around the month end.

Written by Harsh

September 6th, 2009 at 10:35 pm

Install Python Packages locally

8 comments

There’s a great feature in Python versions 2.6 and up that I hardly see being used; it’s the ability to install modules and packages in a per-user local directory. I like this feature since it doesn’t have any super-user power requirements and lets me install packages, modules and even scripts in my own Home directory and use it just as normally as the other global files.

To do so, one must first create the local site-packages directory, and then place the required package or module file or folder under it. The following commands are all for UNIX. ~/ expands to the user’s $HOME automatically.

# To create the required directory
mkdir -p ~/.local/lib/python2.6/site-packages

Now place the module or package folder under this directory, or link to it for achieving the same installation effect as you would with a global site-packages directory. For example, for my django copy from svn I’d do:

ln -s ~/.django-svn/django-trunk/django ~/.local/lib/python2.6/site-packages/django

Running the Python interpreter (in the same user account) will show this working:

Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> 

So there you have it, when you want a package just for your user account while developing just put it under the local site-packages directory. Python automatically adds this to its path (PYTHONPATH).

References: PEP 370 (Has notes for OS X and Windows users)

Written by Harsh

May 21st, 2009 at 11:00 am

Posted in Linux, Software

Tagged with ,

PyQt – Signals, Slots and Layouts Tutorial

8 comments

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 , , , , ,

Ubuntu 9.04 Python 2.6 Site-Packages Directory

5 comments

Strangely the site-packages directory used by Python (2.6) to place/install modules and packages is nowhere to be found in Ubuntu’s Jaunty Jackalope. The newer directory is called dist-packages, no idea why (Only know that it sounds like its for distribution-installed modules).

So to place a package or a link to one, simply do so in the /usr/local/lib/python2.6/dist-packages/ directory.

Written by Harsh

May 13th, 2009 at 1:09 am

Posted in Linux, Software

Tagged with , ,

Basics of PyQt

leave a comment

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 , , , ,