Dugan Chen's Homepage

Various Things

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 […]

A Point Free Function Composition Operator For Python

Here’s a quick implementation of a point free function composition operator for Python: The composable class works as a function decorator: The following test prints out “dcba”, which is what you would expect if you start with “d”, append “c” to it, append “b” to it, and then append “a” to it: One use case […]

Rendering Django forms for the Twitter Bootstrap

There seem to be dozens of projects to integrate Django with the Twitter Bootstrap. All of them seem to be large enough to need permanent homes on GitHub. If all you need to do is render a form the way Bootstrap expects, however, then the process is easy. The total amount of code needed is […]

Django ModelChoiceFields as autocomplete lists

Every Django user knows about its ModelChoiceFields. Pass them to a form template, and they render as HTML Select elements via which a user may choose an ORM moodel. Use them for form binding, and they’ll find you, from the form POST data, the ORM model that the user chose. But what if you don’t […]

Test Driven Development with PyQt Maya Plugins

Do you want to use PyQt to develop your Maya plugins? Of course you do; the alternative is Mel. Do you want to develop these plugins via the process known as test driven development (or a variation, as shown below)? Again, of course you do. Any other process would be inefficient. Well guess what. You […]

Elegantly Adding HTML5 Validation Attributes to Django Form Fields

The current version of Django, 1.4, does not use HTML5’s Web Forms 2.0 attributes. Later versions probably will, but here’s an elegant way to add them in the meantime. What you probably don’t want to do is this: That rolls back your reasons for choosing Python and Django. It turns out, however, that that creating […]

Building 64-bit Maya 2012 plugins with Visual Studio 2010 Express

This is how you use Visual Studio 2010 Express to build plugins for the 64-bit version of Maya 2012. Requirements To build 64-bit targets, Visual Studio Express requires the Microsoft Windows SDK. The current version is 7.1. Install it too. Strategy The idea is to build a 64-bit DLL and link it against Maya’s libraries. […]

Solarized color theme screenshot

On most Linux distributions, “ls” prints directories in dark blue text. Run an X terminal (such as XTerm) in reverse video, and you get directories in dark-blue-on-black text. I decided that anything would be better, and started looking for solutions. The first solution I found was Solarized. In addition to the main Solarized theme (which […]

« Previous PageNext Page »