background preloader

Python

Facebook Twitter

WebKit in PyQt - rendering web pages. In the 4.4 release of Qt bindings to WebKit have been added. WebKit is a web page rendering engine, that is used in Safari and Google Chrome. Qt bindings are also available in PyQt and in other languages. To get qt-webkit we need just Qt and PyQt 4.4 or newer. Linux users have to check if they have "qt-webkit" installed (if qt comes in several packages).

Here is a basic QWebView usage: #! Sample result: Functionality of the "browser" is currently low, but WebKit bindings provide a lot of goodies. Now we will make more functional example browser. Now we make a Python class from that UI: pyuic4 httpWidget.ui > httpWidget.py And we can code the rest: Connect signals with slots QWebView signals (like page loading status, page title)Buttons signalsUI look configuration Here is the final code for the UI we designed: Save the code in a file in the same directory as the UI file, and run it (i used run.py): python run.py In the __init__ we set the default web page, and some margins for the widgets.

PyFileDir. Decorators I: Introduction to Python Decorators. Computing ThoughtsDecorators I: Introduction to Python Decoratorsby Bruce EckelOctober 18, 2008 Summary This amazing feature appeared in the language almost apologetically and with concern that it might not be that useful. I predict that in time it will be seen as one of the more powerful features in the language. The problem is that all the introductions to decorators that I have seen have been rather confusing, so I will try to rectify that here. (This series of articles will be incorporated into the open-source book Python 3 Patterns & Idioms). First, you need to understand that the word "decorator" was used with some trepidation, because there was concern that it would be completely confused with the Decorator pattern from the Design Patterns book. At one point other terms were considered for the feature, but "decorator" seems to be the one that sticks.

Indeed, you can use Python decorators to implement the Decorator pattern, but that's an extremely limited use of it. The output is: HowTo/Sorting. Original version by Andrew Dalke with a major update by Raymond Hettinger Python lists have a built-in sort() method that modifies the list in-place and a sorted() built-in function that builds a new sorted list from an iterable. There are many ways to use them to sort data and there doesn't appear to be a single, central place in the various manuals describing them, so I'll do so here. Sorting Basics A simple ascending sort is very easy -- just call the sorted() function. It returns a new sorted list: >>> sorted([5, 2, 3, 1, 4]) [1, 2, 3, 4, 5] You can also use the list.sort() method of a list.

>>> a = [5, 2, 3, 1, 4] >>> a.sort() >>> a [1, 2, 3, 4, 5] Another difference is that the list.sort() method is only defined for lists. Key Functions Starting with Python 2.4, both list.sort() and sorted() added a key parameter to specify a function to be called on each list element prior to making comparisons. For example, here's a case-insensitive string comparison: Operator Module Functions.

Server_implementation

JonathanGardnerPyQtTutorial. This is a short tutorial to get you up to speed with PyQt. It assumes some knowledge of bash, Python, and Qt. If you have questions or comments, you can send them to me at jgardner@jonathangardner.net. You may also make corrections to this page. A (brazilian) portuguese translation is available at thanks to Rodrigo B.

Vieira. Abstract We will cover: Using Qt Designer to generate Qt ui files. Requirements You will need: Red Hat 8.0 with the following configuration: qt-devel RPM properly installed PyQt-devel RPM properly installed PyQt works on other systems. You should already know: How to use a text editor, and how to get that text editor to edit Python code properly. If you haven't fulfilled these requirements, you may have some trouble getting the tutorial to work. Using Qt Designer First things first. . $ designer You are presented with Qt designer. I won't assume you are totally inept at using Qt Designer. Create a new widget. Using pyuic #!