Monthly Archives: May 2010

A Quick EasyGui Tutorial

Earlier this week, I was reading my copy of “Hello World” by Warren D. Sande and Carter Sande and in its chapter on graphical user interfaces, it mentioned a library called EasyGui. It’s the first and only Python GUI project I’ve seen that’s not event-driven. Instead, EasyGui is basically a set of dialogs that can be opened on demand. This package would be handy for command line programs that need to get information from the user using a dialog or for teaching new programmers about simple GUIs. Let’s take a quick look at what EasyGui can do. We’ll use some of the examples from the book. Continue reading A Quick EasyGui Tutorial

wxPython and Threads

If you use GUIs in Python much, then you know that sometimes you need to execute some long running process every now and then. Of course, if you do that as you would with a command line program, then you’ll be in for a surprise. In most cases, you’ll end up blocking your GUI’s event loop and the user will see your program freeze. What can you do to get around just mishaps? Start the task in another thread or process of course! In this article, we’ll look at how to do this with wxPython and Python’s threading module. Continue reading wxPython and Threads

Book Preview: Python 3 Object Oriented Programming

In late December, I was approached by Packt Publishing to write a book on wxPython. I turned them down because the editor’s vision for the book and mine did not mesh. Anyway, I did end up accepting the job of being a technical editor for one of their upcoming books: Python 3 Object Oriented Programming by Dusty Phillips. I started doing that in January 2010. The “pay” is a copy of the book plus one other book of my choice from Packt’s catalog. That’s it. I won’t get either book until this one is published, which is supposed to happen in August of this year. This article is a preview of the book. Continue reading Book Preview: Python 3 Object Oriented Programming

Manipulating PDFs with Python and pyPdf

There’s a handy 3rd party module called pyPdf out there that you can use to merge PDFs documents together, rotate pages, split and crop pages, and decrypt/encrypt PDF documents. In this article, we’ll take a look at a few of these functions and then create a simple GUI with wxPython that will allow us to merge a couple of PDFs. Continue reading Manipulating PDFs with Python and pyPdf

How to Send Email with Python

Where I work, we run a number of login scripts written in Python. When an error occurs in one of those scripts, we want to know. So we wrote a simple Python script to email the error to us. Since then, I’ve needed to figure out a way to send attachments with some of my more advanced scripts. If you’re a long-time reader of this blog, then you may remember wxPyMail, which was a simple wxPython program that could send email. In this article, you’ll discover how to send email with just Python’s standard library. We will focus on smtplib and the email modules. Continue reading How to Send Email with Python

wxPython: An Introduction to XRC

Have you ever wondered if you could create a wxPython program using XML? Well, I never did either, but there is a way and its name is XRC. In fact, wxPython comes with an editor called XRCed that you can use to layout your GUI and generate the XML code with. In this article, we’ll give you a quick walk-through of XRC and how to use it to create a couple GUI skeletons. We will look at two examples that use only XRC controls and then a third that mixes in some additional non-XRC widgets. Continue reading wxPython: An Introduction to XRC

May 2010 Pyowa Wrap-up

Last night, we had our May 2010 Pyowa meeting. It is the only Python Users Group in Iowa and we welcome anyone who is programming in Python (or interested in learning Python) to come and be a part of our group. At this meeting, we had three good presentations. The first was given by Jim and his topic was web scraping. He uses a combination of Mechanize and lxml to scrape the Ames City website for archival purposes on one of his own websites.

Mechanize allows Jim to impersonate a browser and navigate a website. It can fill in forms, login with your supplied credentials, etc. He then uses lxml to parse the pages he wants and if he needs to download something, he just uses os.system in conjunction with wget. The beautiful soup library was also mentioned, but Jim didn’t use it. One of our other members said that their organization did use beautiful soup for a while and was pleased with the results.

Our next two presentations were given by a fellow named Kevin. He spoke on the Mercurial distributed version control system and Trac, a web-based issue tracker. Kevin walked us through how to set up a Mercurial repository, add files, branch, update, merge and more. He did all this using virtualenv, a handy way to isolate projects. After completing the Mercurial talk, Kevin showed us how to set up Trac with his Mercurial repository, add tickets, commit fixes to the tickets from within Mercurial, and various administration tools that are included with Trac. Kevin also highlighted some of the Trac and Mercurial plugins that he liked.

If you would like to come to our next meeting, it will be held at the same location, the Ames Public Library in Ames, IA on June 3rd, which is a Thursday. If you would like to share your experiences with Python or one of its many projects, that would be great! Please email me at mike at pythonlibrary dot org so we can get you scheduled. Watch our website for the most up-to-date information.

Pyowa: The Iowa Python Users Group

It’s been a while since I wrote about Pyowa, the Iowa Python Users Group that I founded. Our first meeting was September 24th, 2008 and I had high hopes for the group. However, it hasn’t grown much at all in almost two years. For some reason, we have meetings scheduled through July of this year anyway. We get 3-10 people at our meetings with an average of 4 or 5. Our next meeting is tomorrow, May 6th in Ames, IA. We’ll be meeting at the Ames Public Library from 7-8:45 p.m. Here’s what we’ll be covering:

  • Web Scraping
  • Mercurial source control
  • Trac: An Issue Tracking System

If you think you can come, let me know in the comments or by emailing me. If you have ideas for how to get more people to show up, please let me know. I could use some more good ideas. I hope to see you there!

Python: How to Tell How Long Windows Has Been Idle

The other day, I received a request to create a script that could tell how long a Windows XP machine had been idle and to alert the user if it had been idle for a certain amount of time. I did a little research with Google and found a couple of ways to accomplish this feat. The only one I was able to get working was a ctypes example, so without further ado, let’s check it out! Continue reading Python: How to Tell How Long Windows Has Been Idle