Category Archives: Python 3

wxPython 4 and PubSub

The Publish-Subscribe pattern is pretty common in computer science and very useful too. The wxPython GUI toolkit has had an implementation of it for a very long time in wx.lib.pubsub. This implementation is based on the PyPubSub package. While you could always download PyPubSub and use it directly instead, it was nice to be able to just run wxPython without an additional dependency.

However, as of wxPython 4.0.4, wx.lib.pubsub is now deprecated and will be removed in a future version of wxPython. So now you will need to download PyPubSub or PyDispatcher if you want to use the Publish-Subscribe pattern easily in wxPython.

Installing PyPubSub

You can install PyPubSub using pip.

Here’s how to do it:

pip install pypubsub

PyPubSub should install quite quickly. Once it’s done, let’s find out how to use it! Continue reading wxPython 4 and PubSub

Face Detection Using Python and OpenCV

Machine Learning, artificial intelligence and face recognition are big topics right now. So I thought it would be fun to see how easy it is to use Python to detect faces in photos. This article will focus on just detecting faces, not face recognition which is actually assigning a name to a face. The most popular and probably the simplest way to detect faces using Python is by using the OpenCV package. OpenCV is a computer vision library that’s written in C++ and had Python bindings. It can be kind of complicated to install depending on which OS you are using, but for the most part you can just use pip:

pip install opencv-python

I have had issues with OpenCV on older versions of Linux where I just can’t get the newest version to install correctly. But this works fine on Windows and seems to work okay for the latest versions of Linux right now. For this article, I am using the 3.4.2 version of OpenCV’s Python bindings. Continue reading Face Detection Using Python and OpenCV

ReportLab Book Funded + TOC

After collating the various ideas that people have been giving me during the Kickstarter campaign, I have decided to firm up my table of contents. I had already planned to cover 80-90% or more of what was in ReportLab’s user guide, but in more depth, as I thought most of those topics should be covered in book form. The rest of the book was going to be some HOW-TO type chapters and other Python packages that work with PDFs. With that in mind, here is what the table of contents is looking like:

Part I – The ReportLab Toolkit

  • Chapter 1 – The Canvas
  • Chapter 2 – Fonts
  • Chapter 3 – PLATYPUS
  • Chapter 4 – Paragraphs
  • Chapter 5 – Tables
  • Chapter 6 – Other Flowables
  • Chapter 7 – Custom Flowables
  • Chapter 8 – Charts / Graphs
  • Chapter 9 – Other Graphics
  • Chapter 10 – PDF Special Features (Forms, Links, Encryption)
  • Chapter 11 – Bar Codes / QR Codes

Part II – Tutorials / HOW-Tos

  • Chapter 12 – Turning XML into Multipage PDFs
  • Chapter 13 – Custom headers and footers, page numbers
  • Chapter 14 – Creating a table of contents (Stretch goal) 
  • Chapter 15 – Exporting Data from PDFs (pdfminer) (Stretch goal) 
  • Chapter 16 – Filling in PDF Forms with Python (pdfforms) (Stretch goal)
  • Chapter 17 – PyPDF2 / pdfrw
  • Chapter 18 – Converting Markup to PDF (rst2pdf, html2pdf, etc) (Stretch goal)
  • Chapter 19 – pyfpdf, An Alternative to ReportLab

Note that the chapter titles are subject to change. Also note that I have marked some of the chapters as “stretch goal” chapters. They may or may not get added depending on whether or not we reach our stretch goal.

Stretch Goal(s)

My stretch goal is to hit $6000 or 500 backers. If we hit either of those, than all of the chapters above will get added. If we don’t, then I will evaluate how close we got and I may put out a survey to see which two chapters we will keep and which two will be voted out of the book.

The last thing I would like to make note of is that the first 3 chapters of the book is over 60 pages of content all by themselves, so even if I only did the first section of the book (i.e. 11 or 12 chapters), the book would still be over 200 pages in length.

If you’d like to get early access to the book, then please go check out the Kickstarter!

wxPython Recipes Book Release

I was contacted earlier this year by Apress about republishing my book, wxPython Cookbook, under their branding. I thought it might be fun to see what I could learn from a publisher so I went with them as I have enjoyed several of their books in the past. The biggest change to the book is that I ended up grouping recipes into chapters instead of having each recipe be a stand-alone chapter. I also added a few new recipes to help fill in when some chapters weren’t easily sorted into groups.

Anyway, Apress just released the book in the past couple of days:

You can find the book over on Amazon or on the Apress website. You can also see a preview of the book on Google.

You can get 20% off of the book from Apress by using the following code: wx20. This code is good on the paperback and the eBook versions of the book until June 2018.

The code for the book is hosted on Apress’s Github account. I also host a copy on Github.

Regardless, feel free to check it out. If you already bought a copy of the wxPython Cookbook, then you don’t need to get this one too since it’s basically the same thing with a bit more polish and a handful of new recipes. I have plans for some other books that I will be self-publishing hopefully in 2018, so keep an eye on the blog for news about that!