Introduction
Qt is a cross platform application framework that is made up of not only a GUI widget toolkit, but also classes for working with OpenGL, SQL databases, threading, network protocols (HTTP, FTP, UDP, TCP) and much more. Currently Python has two separate bindings for the Qt framework: Pyside and PyQt. In this post we look at Pyside and PyQt and the resources that exist for learning them.
Pyside or PyQt?
Both Pyside and PyQt have full Python bindings for Qt 4.7 and are available for Mac, Windows and Linux. The main difference between the two is how they are licensed. PyQt is developed by River Bank Computing and is available under the GPL or a commercial license. This means that if your application is open source you can use the free GPL version, but if your application is closed source you need to buy the commercial license (350 GBP). Pyside is licensed under the LGPL so it can be used in both open and closed source applications with no cost. In addition to the standard Desktop bindings, Pyside is also available for the Maemo and MeeGo mobile platforms.
Because Pyside is a relatively young project the majority…
Dojo is an open source Javascript toolkit. It provides an easy way to access and modify the DOM as well as a rich user interface widget library. One of the most powerful widgets in the Dojo toolkit is DataGrid. It provides an easy way to represent what is essentially a cross between a spreadsheet and a table. In a recent Django project I needed to output the contents of a model into the DataGrid. Thanks to django-dojoserializer this is very easy.
Setup
We need the Python package django-dojoserializer. This can be installed by downloading the source and running
python setup.py install
or with setuptools using
easy_install django-dojoserializer
or with pip using
pip install django-dojoserializer
Then add django-dojoserializer to the INSTALLED_APPS tuple in settings.py.
Dojo will need to be linked correctly in the Django template. We need to require the dojox.grid.DataGrid and dojo.data.ItemFileReadStore classes.
<script src="/static/libs/dojo/dojo.js" djConfig="parseOnLoad: true">%lt;/script>
<script type="text/javascript">
dojo.require('dojox.grid.DataGrid');
dojo.require('dojo.data.ItemFileReadStore');
</script>
Django Model
PROXY_TYPE_CHOICES = (
('SOCKS4', 'SOCKS4'),
('SOCKS5', 'SOCKS5'),
('HTTP', 'HTTP'),
)
class Proxy(models.Model):
ip = models.CharField(max_length=50)
type = models.CharField(max_length=6, choices=PROXY_TYPE_CHOICES)
alive = models.BooleanField(default=False)
added = models.DateTimeField(auto_now=False, auto_now_add=True)
last_checked = models.DateTimeField(auto_now=True, auto_now_add=False)
def __unicode__(self):
return self.ip
Django View
The view needs…
Introduction
In a recent Django project I needed to issue some HTTP requests to a website, save the results and then display the information to the user. I could have issued those HTTP requests in a Django view, however the requests could take up to 10 seconds to return, and I didn’t want the page hanging that long for the user. I ended up using Celery, an asynchronous task queue written in Python, to execute the requests.
Installation
Celery
Celery is in pypi so installation is simple.
easy_install celery
pip install celery
Or download the source code, extract it and
python setup.py install
Django + Celery
In a high traffic production environment Celery should be paired with the RabbitMQ backend. However for my low traffic application I went with the django-kombu backend. django-kombu uses the Django database as a message store and requires very little configuration compared to other backends. We also need the djcelery package.
easy_install django-kombu
easy_install django-celery
Configuration
Before we can start using Celery we need configure our Django project. In settings.py make sure you add djkombu and djcelery to the INSTALLED_APPS tuple. Also make sure your database is configured and working.
Also add…
The Python user base has grown exponentially over the years, thanks to the sheer brilliance of the language and regular updates from the brilliant python community.
You can find Python everywhere – Rapid Application Development, Game Development, System Administration, Visualization, Web Development, Scientific Programming, Embedded Systems and what not!
In this article, we’re going to take a look at some of the open source python projects for the web.
1. HTML5Lib
HTML5Lib is a Python implementation of a HTML parser based on the WHATWG HTML5 specification. It includes HTML and CSS sanitizer, DOM to SAX convertor, character encoding detection and filtering and serializing of tress.
2. Django-CMS
This is perhaps the best CMS based on Django. The installation is little tricky and you need to be familiar with Python and Django to successfully install Django-CMS. Once done, it’s easy to use and configure. Some of the major features include Flexible Plugin Architecture, SEO Optimization, Editorial Workflow, Versioning and support for custom extensions.
Get more information about Django-CMS at – http://www.django-cms.org
3. Tornado
From their website – “Tornado is an open source version of the scalable, non-blocking web server and tools that power
…
Introduction
In the Python Web Framework Django, template tags can be used to modify data that is about to be output in a Django template file. In this tutorial we will learn how to create and use our own template tags in a Django application.
Setting Up
Template tag definitions are stored in Django apps. The template tags in each app should be relevant to the models and views in that app. You shouldn’t have one app that stores every single template tag you use throughout your website. Each app can contain a directory called templatetags and assuming the app is added to settings.INSTALLED_APPS, Django will automatically search that appname/templatetags/ directory for template tag definitions. Remember to put an __init__.py file in each templatetags directory because the template tags inside them are imported.
Example
In an application I worked on recently I needed to display some data about a World Of Warcraft character such as their race, class and gender. The information about the character was stored in a database table and was referenced like so:

This means that if the character was a Male Orc Shaman, then the…
Skype4Py is a Python module that allows developers to programatically interact with the Skype client running on their computer. In this tutorial we will look at and use the Skype4Py module to create simple but useful scripts.
Installation
Skype4Py is a normal Python module and is listed in the Python package index (Pypi). To install it with setuptools enter the following in a command prompt.
easy_install Skype4Py
To install it with pip enter the following in a command prompt.
pip install Skype4Py
Getting Started
Skype4Py interacts with the Skype client running on your desktop, it doesn’t talk directly to the Skype servers. For any of the scripts we cover in this tutorial to work the Skype application must be running and you need to be logged in. You can either start Skype yourself or use the following snippet to start it using Skype4Py.
s = Skype4Py.Skype()
if not s.Client.IsRunning:
s.Client.Start()
Before we can interact with the Skype client from Skype2Py, we need to connect Skype4Py to the instance of Skype running on your desktop. This is done using the Attach method.
import Skype4Py
s = Skype4Py.Skype()
s.Attach()
After executing this you need to check the Skype client on…
I’ve been writing programs in Python for the past 3 years and I must accept that I am a big fan of its no-nonsense approach towards programming and it’s clean and easy to understand syntax. It was recently chosen as the
best programming and scripting language by Linux Developers and is also considered as the
Holy Grail of programming by CERN. It is perhaps the
best language for beginners as it lets you focus on programming without worrying much about syntax.
Today, Python is being extensively used at Google, Yahoo, CERN, NASA and ITA. It has been successfully embedded in a number of software products as a scripting language including Maya,MotionBuilder, SoftImage, Cinema4D, Blender, GIMP and Paint Shop Pro. Python has also been actively used for writing web applications. Some of the most sophisticated Python web frameworks include Django, Pylons, TurboGears and Web2Py.
In this article, I’ll provide you some resources, which will help you get started with Python:
Google Code: Getting Started – Python
Python Programming Tutorials
A Gentle Introduction to Programming Using Python
Dive Into Python
How to think like a computer scientist – Learning with Python
I hope these resources
…
If you are building a Django frontend for a legacy application chances are you will need to integrate your existing user database table(s) with the the Django authentication system (django.contrib.auth). In this tutorial we will look at writing our own authentication backend and plugging it into django.contrib.auth.
Getting Started
Authentication backends are pure python classes. Given a username and password, they are expected to validate them against an authentication source (such as a database) and return a User object. There is no requirement as to where the class is placed, however I always put it in the same directory as the application that handles registrations and logging in.
When a user logs in, Django will check the AUTHENTICATION_BACKENDS (tuple) setting and iterate through all backends until one returns true. The default authentication backend is django.contrib.auth.backends.ModelBackend.
Writing Our Backend
Our backend must have two methods: authenticate and get_user
authenticate takes two arguments – username and password. It is expected to return a User instance or None. The authenticate method should check the given username and password against the user table of the legacy application. If the credentials match, then create a new User instance, save it, and return it. If…
ActionScript,Best Practices,Design,Flash,Flex,JavaScript,Programming,Python,Ruby on Rails,Web 2.0,Web Development,Zend,jQuery,php
Now, I am no expert in OOP or software design, but here’s a philosophy which might help you make the most of what you know about OOP and software design.