Dugan Chen's Homepage

Various Things


PyQt Implementation of MSDN’s MVP Example

I had a look at Microsoft’s Model View Presenter example, and I couldn’t resist blogging a PyQt version. For the PyQt version, we’ll have a dropdown list of music artists. When one artist is selected, its bio is retrieved from Last.FM and loaded into the UI. I only loosely skimmed the article and its source […]

MVP with PyQt. With a Model layer.

Some of the peer feedback I received on my MVP for Qt (PyQt and PySide) made good points. Pushing all the complexity to a single monolithic Presenter class simply moves the problem; you still have to subdivide that complexity, or the Presenter will be huge. Furthermore, if you have a tabbed layout, there are benefits […]

MVP for Qt (PyQt and PySide)

I took my PyQt implementation of Michael Feather’s Humble Dialog box example, and I refactored it into a Model View Presenter implementation that fits PyQt and PySide better. I’ll show you the code first, and then I’ll discuss it: The code, filter_chain.py The code itself is PyQt, but the discussion below also applies to PySide. […]

Qt, Python, AsyncIO. And Quetzalcoatl.

I’ve know I’ve said this before, but I’m at work on the next version of Quetzalcoatl, my Qt-based MPD client for KDE, written in Python. PyQt and PySide I did not say “PyQt-based”, because PySide compatibility is on the table. Normalizing PyQt for API-compatibility with PySide is easy. If you’re importing PyQt, you set its […]

LEMP on Slackware

I’ve gotten to really like the nginx web server. Here’s how to set it up on Slackware. Nginx The nginx SlackBuild on SlackBuilds.org is ahem not quite the way I’d like it. As Apache’s document root is /var/www/htdocs, nginx’s should be /var/www/ngdocs. Therefore, I’ve created a patch to fix it. From the SlackBuild directory: Use […]

Building SDL2 programs with CMake and PkgConfig

Here’s what I feel is currently the easiest and safest way to build SDL2 programs. First, you should never be writing Makefiles by hand. You should be generating them. And for generating Makefiles, CMake is more or less the current standard. How does CMake detect where a library and its header files are installed? Well, […]

Reading Environment Variables in Python. With Metaclasses.

I work in the animation industry. Here, the standard practice is to use environment variables to control the runtime behavior of software. It is common enough, in fact, that powerful open source projects such as Rez have been started to manage it. The idea is that before launching each application, you set the environment variables […]

A Humble Dialog implementation in PyQt

The following is an implementation of the Humble Dialog Box pattern (no relation to the Humble Bundle) in PyQt. Honestly, no further explanation should be necessary. The paper opens with a screenshot of the dialog box being used as an example. I have a full implementation of that dialog box’s user interface. The rest is […]

Unit Testing PyQt Applications With Nose and Mock

I spent a couple of evenings getting familar with the Mock mocking framework for Python. Turns out it works very well for testing PyQt code. Let’s say you have the following program, which I just contrived up. It’s very contrived, because it ignores obvious and simpler implementations such as using the QWebView‘s setUrl method. Nevertheless, […]

Implementing Pythonic mixins with class decorators.

There was virtually no discussion following the posting of this PEP, meaning that everyone agreed it should be accepted. Here is the correct and Pythonic way to do mixins in Python. You don’t. You use class decorators to do the same thing. Note that class decorators were added to Python as of 2.6. I suspect […]


Next Page »