Archive for November, 2013

Recently I’ve started learning about Kivy, a Python Natural User Interface (NUI) toolkit. As I understand it, Kivy is kind of a spiritual successor to pyMT, which you can read more about here. In this article, we will be learning how Kivy handles layout management. While you can position widgets using x/y coordinates, in every GUI toolkit I’ve used, it’s almost always better to use some kind of layout management that the toolkit provides. This allows the widgets to resize and move appropriately as the user changes the window’s size. In Kivy, these things Layouts. If you’ve used wxPython, they are analogous to wxPython’s sizers.

I should also note that Kivy can do layouts in two different ways. The first way is to do Layouts with Python code only. The second way is to use a mixture of Python and Kv language. This is to promote the model-view-controller way of doing things. It looks kind of like CSS and reminds me a little of wxPython and XRC. We will look at how to use both methods in this article. While Kivy supports multiple types of Layouts, this article will be focusing only on the BoxLayout. We will show how to nest BoxLayouts. (more…)

Python’s “batteries included” philosophy even includes a module for object serialization. They call it the pickle module. Some people call serialization by other names, such as marshalling or flattening. In Python, it’s known as “pickling”. The pickle module also has an optimized C-based version known as cPickle that can run up to 1000 times faster than the ordinary pickle. The documentation does come with a warning though and it’s important so it is reprinted below:

Warning: The pickle module is not intended to be secure against erroneous or maliciously constructed data. Never unpickle data received from an untrusted or unauthenticated source.

Now that we have that out of the way, we can start learning how to use pickle! By the end of this post, you may be hungry! (more…)

I like to use Wingware’s IDE for coding in Python. I am working through some sample applications with Kivy, a cross-platform Python GUI framework that can also create UIs for mobile. Anyway, getting Kivy set up in Wing is slightly confusing, so here’s a crash course:

  1. Download Kivy
  2. Unzip Kivy somewhere. In my case, I unzipped it here: C:\kivy1.7.2\
  3. Run kivy.bat which is in the directory you unzipped to. You should see something like the following

kivy_bat (more…)

The other day, someone asked me if I could write a script that could cleanup a directory of all files that are greater than or equal to X number of days old. I ended up using Python’s core modules for this task. We will spend some time looking at one way to do this useful exercise.

FAIR WARNING: The code in this article is designed to delete files. Use at your own risk!

(more…)

I was recently asked to review a Python blog, which is something I’ve never really done before. The blog’s name is “Bite Sized Python Tips” and you can find it here: http://freepythontips.wordpress.com/. It is run by a fellow named Yasoob. When I first glanced through the site, I saw a lot of articles that were similar to my own. However, I think that was just coincidence. Anyway, this guy writes a lot of articles. I like that his site is clean and simple. The articles are a decent size and they cover a wide variety of topics. I think it’s worth following for beginners and intermediate programmers just for garnering ideas. I recommend checking it out for yourself and you can decide if you want to add it to list of blogs to read.

There aren’t very many Tkinter books in existence, which is something I’ve always found a little odd as it is the GUI toolkit that is included with Python. Basically you have Grayson’s Python and Tkinter Programming from 2000 or Roseman’s Modern Tkinter for Busy Python Developers from 2012. I reviewed the latter here, if you’re interested. There are other books that include Tkinter programming (like Core Python or Programming Python), but those texts are not Tkinter focused books. This brings us to 2013′s release of Tkinter GUI Application Development HOTSHOT by Bhaskar Chaudhary, the 3rd book about Tkinter in the last 13 years! Today, you can read my review of this interesting book.

Full disclosure: Packt Publishing asked me to be a technical reviewer of this book, so I received a free copy after the review process was finished.

Here’s the quick review for those of you without a lot of time:

Quick Review

  • Why I picked it up: Technically, I didn’t as I received it as “payment” for helping edit the book, but I would have picked it up just because there are so few Tkinter books and I find GUI programming a fascinating subject.
  • Why I finished it: The book has lots of fun fully-functional applications, so I kept reading just to see what the author would come up with next.
  • I’d give it to: Programmers that want to jump into GUI application development feet first – this book has lots of good examples of applications without the spaghetti code!

(more…)

Packt Publishing recently contacted me about reviewing their new book, Instant Flask Web Development by Ron DuPlain. They sent me an ebook copy and I just finished it up. I always strive to give an honest opinion about the Python books I read as I want my readers to know whether or not a book is worthy of their hard-earned cash. If you don’t have much time for a review, then you can check out my short one below. If you have a few minutes, you can read the rest!

Quick Review

  • Why I picked it up: I’ve been interested in learning Flask (and web development in general) for a while now and this book just dropped in my lap.
  • Why I finished it: It’s short and has a lot of interesting little recipes and tips.
  • I’d give it to: I would give this book to someone who already knows Python and probably knows a little about web programming too.

(more…)

This Contest is now over!

Packt Publishing has asked me to run a run a contest for them to give away their new book: Instant Flask Web Development by Ron DuPlain. It has been receiving favorable reviews on Amazon and I plan to release a review of the book soon.

I have 3 digital copies of the book to give away. Here’s a little information regarding what the book covers:

instant_flask

  • Manage your project dependencies using virtualenv
  • Understand how Flask provides URL routing and web request handling
  • Recognize how Flask serves static files on disk
  • Learn about modeling, storing, and querying data with SQLAlchemy
  • Present HTML forms and validate input with WTForms
  • Build a page layout with Twitter Bootstrap using a base Jinja template
  • Create, recall, update, delete, and list database records
  • Build custom template filters in Jinja to format data
  • Authenticate users and maintain sessions

How to Enter?

All you need to do is head on over to the book page and look through the product description of the book and drop a line via the comments below this post to let us know what interests you the most about this book. It’s that simple.

Winners will get an e-copy of the Book.

Deadline

The contest will close on November 15th, 2013 at 12:01 p.m. CST. Winners will be contacted by the email they used when commenting! Don’t worry, I’m the only one who can see your email address on this blog.

The wxPython Frame widget is used in almost all wxPython applications. It has the minimize, maximize and close buttons on it as well as the caption along the top that identifies the application. The wx.Frame allows you to modify its styles in such a way that you can remove or disable various buttons and features. In this article, we will look at some of the ways that you can change the behavior of the wx.Frame widget. Specifically, we will cover the following:

  • Different ways to create a default frame
  • How to create a frame without a caption (i.e. no title bar)
  • How to create a frame with a disabled close button
  • How to create a frame without a maximize or minimize button
  • How to create a frame that cannot be resized
  • How to create a frame without the system menu
  • How to make your frame stay on top of other windows

(more…)

Today we’ll be looking at how to acquire data from the popular movie site, Rotten Tomatoes. To follow along, you’ll want to sign up for an API key here. When you get your key, make a note of your usage limit, if there is one. You don’t want to do too many calls to their API or you may get your key revoked. Finally, it’s always a very good idea to read the documentation of the API you will be using. Here are a couple of links:

Once you’ve perused that or decided that you’ll save it for later, we’ll continue our journey. (more…)