jump to navigation

Getting started with PySide, Part 1: Setting up on Windows March 6, 2014

Posted by PythonGuy in Advanced Python, Qt, Windows.
add a comment

After a long, circuitous journey in the wonderful world of game development in Python, Python Guy decided he likes Qt best. So he is trying out PySide, the LGPL version of PyQt. Python Guy has done a lot of PyQt in the past, but that was a long, long time ago and Python, Qt, and everything have moved on since then.

Why does Python Guy like Qt? For starters, it is clean. No, it is not simple, but it is clean. You can tell that every API, every parameter, every value in an Enum has been carefully thought out. There is no more nor no less than what you need.

Qt also strongly encourages a sane object model. All the things in Qt can be subclassed. Override what you need to override, and no more.

Qt’s signal/slot paradigm is beautiful. Python Guy tries to use it in everything he writes. The closest comparable thing is Javascript’s DOM event model, except that the DOM event model only applies to DOM objects. Qt has taken the concept of signals and slots and perfected it. Python Guy was pleased that there is a new syntax to do connections: Object.signal.connect(callable). That is nice and concise and clear and his preferred syntax for that sort of thing.

You might think Qt is a horrible platform for a game. That may be true if you intend to implement all the visual UI elements yourself. But if you’d rather focus on game play and mechanics, you’ll appreciate having an event loop, a complete set of UI elements, and a nice library that is quick to work with across platforms.

This article covers how to setup your dev environment in Windows.

For starters, you need to get used to the fact that the Windows command line is virtually useless compared to what you’re used to in the Linux world. Get over it, and don’t use it.

Install GitHub.com’s software. It will make it easy to start a new project and handle all the Git commands for you. If you get in a weird spot, there is a Git shell you can use to straighten it out. Don’t get in a weird spot. Learn how Git really works. If you don’t want to pay, make your projects public. There is no shame in showing the world the software you are working on. In fact, Python Guy doesn’t like closed-source software. So do the right thing and tell the world what you are playing with.

Install Python27. Python Guy looks forward to Python 3 and encourages you to try it out today. However, Python Guy was tired and simply wanted to get something that works. Be sure to update your environment variables, setting PATH appropriately.

Install PySide. This will install Qt, Qt Designer and Qt Linguist for you under its module in C:/Python27/Lib/site-packages. It also installs pyside-uic.exe under C:/Python27/Scripts. This will be useful.

Start your new project using the GitHub interface. Then open an explorer window at that directory. Click on the gear to see the extended options for a project. There you can find the option to open an explorer window.

In the explorer, add a new file, “README”. If you don’t see the “.txt” ending, you need to configure your Windows to show that to you. Otherwise, you’ll end up with things like “myprog.py.txt” which is not what you want.

Add some text to the README file. Commit it. Push it up to your repository.

Use your favorite editor. Python Guy prefers ViM. But you can use whatever you like best.

If you are using Linux, setup is as easy as using your package system to install all the necessary dependencies.

We’ll start with actual coding in the next article. We’re going to use Qt Designer to build our widgets and MainWindow for us, and then simply write code to plug everything together.

The game will be a simple game, a sort of Hammurabi clone. So we can focus on Qt, game building, and Python.