Learning Python Update

Sorry folks, I broke this blog a while ago and it took me a while to get it back up. Sorry for anyone that was using it, turns out there was an issue with a PHP upgrade that was forced on me by my hosts.

The old theme doesn’t work anymore, but at least the content is up!

Let me know if anything doesn’t work.

New Android App: MemeToad

Today I released my newest Android App: MemeToad it’s a meme generator for your Android phone and/or tablet. I’ve been working on this app for the last while in the evenings.

It’s tough to find the time when you’ve got a family and a full-time job but I’m happy to have stick with it and put it out there.

If you have an Android device and you are into meme’s check it out it’s free. I know it’s not Python related, but it’s all I’ve got.

Cheers.

Hacking Fixed, and Python on the Web

Hey Everyone, just an update on the last post. I was able to dig through the wordpress files and find where the hack was and it appears to be fixed now.

Again if you notice anything strange happening here, redirects to external sites and whatnot, please let me know.

Also, does anyone here use any of the python web frameworks? I’d like to try my hand at them, but I’m having difficulty deciding between Pylons, Django, and Zope. I’m a total n00b when it comes to web programming, so it’s something that I’d like to be better at, so one of my requirements is being easy for beginners to learn.

If anyone has any thoughts or advice please post a comment.

AVC: Simplifying your GUI Code

Note: This article was first published the April 2008 issue of Python Magazine

By: Mark Mruss

GUI programming, like many other types of programming, can sometimes prove exhausting because you must repeat yourself over and over again. AVC is one tool available to Python GUI programmers that attempts to simplify things by synchronizing application data and GUI widgets.

Introduction

Every once in a while I find myself browsing the Internet trying to find out what’s new and exciting in the Python world. Sometimes I browse to find topics for this article; other times mere curiosity draws me across the web. While I was browsing the other day, I stumbled across AVC: the Application View Controller [1]. I was immediately intrigued by it because its’ name is so similar to the Model View Controller (MVC) pattern. Being familiar with the Model View Controller pattern, and admittedly having struggles with it in the past, I decided to check out AVC to determine if it might be a viable alternative.

After reading about AVC I was intrigued for several reasons. The main reason was the promise of “a multiplatform, fully automatic, live connection among graphical interface widgets and application variables.” [2] This means that graphical widgets can be connected to variables and automatically synchronized. One of the (many?) problems with Graphical User Interface (GUI) programming is that you often find yourself doing the same thing over and over again. One of the things that you end of doing over and over again is setting the contents of a widget based on the value of a variable, and then subsequently, setting that variable’s value based on the current state of the widget. Whenever someone promises me an automatic connection between GUI widgets and my variables, I’m interested.

Continue reading AVC: Simplifying your GUI Code

Elegant XML parsing using the ElementTree Module

Mark Mruss

Note: This article was first published the October 2007 issue of Python Magazine

XML is everywhere. It seems you can’t do much these days unless you utilize XML in one way or another. Fortunately, Python developers have a new tool in our standard arsenal: the ElementTree module. This article aims to introduce you to reading, writing, saving, and loading XML using the ElementTree module.

  1. Introduction
  2. Reading XML data
  3. Listing 1
  4. Listing 2
  5. Reading XML Attributes
  6. Writing XML
  7. Listing 3
  8. Writing XML Attributes
  9. Reading XML Files
  10. Writing XML Data to a File
  11. Reading from the Web
  12. Conclusion

Continue reading Elegant XML parsing using the ElementTree Module

Level Editor 0.2

So I had some free time since I last posted so I hacked a little bit more into my simple game editor. I’ve a few things in there that I wanted to get in:

  • A grid
  • A paint mode to easily add sprites
  • An erase mode so that sprites can be removed
  • Fully (or so it seems) working property addition to the sprites
  • Added some organization to the code. I was hacking on this enough that putting things in their right spot started to make more and more sense.
  • Started to use mercurial to keep track of source changes. I know how important version control is, and after making a silly mistake I decided that I wanted to start using it with this project.

You can take a look at how things are working here:

Python Game pyglet editor

It’s not pretty yet, but it’s coming along.

Pyglet Level Editor

Hey Everyone,

Sorry I’ve been away for a bit, work and trips and writing for Python Magazine had me pretty busy and I wasn’t able to reply to everyone’s comments on the simple Python game engine. I really do appreciate the comments though so please keep them coming.

I have been thinking about the simple game engine quite a bit though and wondering where to start on it all, and whether or not it makes sense to start on it at all! After some thinking I decided that what I would want most (for a variety of reasons) would be an easy to use level editor. So with a day off from work and life yesterday I started to do some hacking with PyGTK and pyglet to see if I couldn’t get a simple level editor going.

The results are still quite crude, but the basics are starting to get in there:

Python Game pyglet editor

As you can see it’s a PyGTK application with an OpenGL window that displays pyglet sprites. There is a properties list, where you can add and edit properties or the sprite. There is also a “content” list that displays all of the graphics in your project’s “content” directory. Then you can add any of those images to your level. You can also select sprites and move them around, or edit their properties (notice the monster with the yellow border around it?).

The idea is that eventually this will save the information out into a human readable file type (yaml, xml, whatever) that games (your game?) will then read in for their levels. The properties will be saved with each sprite and then applied when you load the level. That way you can add specific properties to specific sprites.

This is still very much a work in progress, but when it gets a little bit more stable and if people are interested I think I’ll create a project on sourceforge or google code so the other people can start working with it or hacking it.

So…ideas? Comments? Thoughts?

I’m still here

No I’m not dead…even after the recent car accident….I’ve just been busy. Busy writing for columns for the monthly Python Magazine. But that does not mean that his blog is dead! In fact I’ve been spending the last hour looking around the web for something new and cool in the world of Python.

I’m looking for something new to sink my teeth into, something different. I’m looking forward to Python 3000, I’ve been trying to keep up with many of the changes and so far it’s looking really good. But in the mean time there must be something happening in the far off corners of the Python world…where someone is doing something extremely cool.

Please if you have an idea let me know, send me an email, or add a comment to this post. Is there anything that you want me to cover here? A tutorial that you would like? A tutorial that you have written? A new module you wrote? Whatever it is let me know! A new visualization tool? More Python on the web?

I’ve been spending too much time in the world of C++ lately and I’m hungry for some Python…

Creating a game with PyGlet and Python

For this tutorial I’m going to take a look at PyGlet: “a cross-platform windowing and multimedia library for Python.” The reason that I decided to take a look at PyGlet is because it is an alternative to PyGame in the Python gaming world and: “No external dependencies or installation requirements. For most application and game requirements, pyglet needs nothing else besides Python, simplifying distribution and installation.”[1]

The first step to using PyGlet is to actually download it and install it (http://pyglet.org/download.html) as of writing this PyGlet is at version 1.0 alpha 2 (as I finished this tutorial Beta 1 was released but I have been unable to try it out), so between now and the final release there are bound to be a few changes. Once you have download the correct version for your system install it an you are ready to go. I’m writing this on a Debian box so I downloaded the source distribution and installed it using the following, as per the instructions:


python setup.py install

Now like PyGame, PyGlet is a framework for developing games or other applications, it is not a game engine, therefore if you are looking to create a full game you will need to create your own, or use someone else’s. This tutorial will not going into full game creation, instead it will introduce PyGlet using a small sample application, hopefully giving you enough of the basics, or enough of a taste to continue on with it.

You can download the full source to this tutorial here.

Python Game PyGlet

Continue reading Creating a game with PyGlet and Python

Python 3000 Status Update from Guido

I just stumbled on this and I thought I’d pass it onto my fellow python programmers, it’s a python 3000 status update from Guido van Rossum.

Personally I’m looking forward to Python 3.0, I don’t know if I’ll like the break in backwards compatibility but a lot of the changes seem great.

Making the print statement a function is a good choice in my opinion.

So instead of:

print "this is printing"

We’ll be using:

print("this is python 3.0")

Also instead of % to format strings, there will be a format() function, which is so much clearer in my opinion.

There are many other changes (say goodbye to old-style classes) so give the link a read and let me know what you think!