Loading UI Files in Qt for Python

Qt for Python (i.e. PySide2) was announced recently and got me interested in trying to use it to load up a UI file. If you don’t know, PyQt and PySide / PySide2 can use the Qt Creator application to create user interfaces using a drag-and-drop interface. This is actually very similar to the way you would create an interface using Visual Studio. Qt Creator / Designer will generate an XML file with a *.ui extension that you can then load inside of your PySide2 application (or PyQt).


Creating the User Interface

For this example, I opened up Qt Creator and went to File –> “New File or Project”. Then I chose the “Qt Widgets Application” choice. See screenshot below:

Then I opened up the mainwindow.ui that Qt Creator made for me. You can just double-click it or click on the Design button that should be on the left-hand side of the program. Here’s a screenshot that might help:

I added three widgets to my UI:

  • QLabel
  • QLineEdit
  • QPushButton

Continue reading Loading UI Files in Qt for Python

Creating Interactive PDF Forms in ReportLab with Python

The ReportLab toolkit allows you to create interactive fillable forms. The PDF standard actually has a fairly rich set of interactive elements. ReportLab doesn’t support all of these elements, but it does cover most of them. In this section, we will look at the following widgets:

  • checkbox
  • radio
  • choice
  • listbox
  • textfield

All of these widgets are created by calling various methods on the canvas.acroform property. Note that you can only have one form per document. Let’s take a look at the widgets that ReportLab supports! Continue reading Creating Interactive PDF Forms in ReportLab with Python

PyDev of the Week: Moshe Zadka

This week we welcome Moshe Zadka (@moshezadka) as our PyDev of the Week! Moshe is a core developer of the Twisted project and he is also a co-author of Expert Twisted from Apress Publishing. He is also the author of a self-published book, from python import better. You can find additional information about Moshe here where he includes links to his Github, Instagram and blog.

Let’s take a few moments to hear what he was to say.

Can you tell us a little about yourself (hobbies, education, etc)?

I am originally from Israel, and I currently live in the Bay area with my wife and my two kids (5yo and 3yo). Until I got married and life got too busy, I used to perform as Dr. Scott in a Rocky Horror Picture Show shadowcast. I intend to get back into performance once the kids are older!

I started my life as a mathematician, published a paper (“Orbifolds as Diffeologies”), but then got into the software development world, and ended up as a DevOps Engineer. Continue reading PyDev of the Week: Moshe Zadka

Filling PDF Forms with Python

Fillable forms have been a part of Adobe’s PDF format for years. One of the most famous examples of fillable forms in the United States are documents from the Internal Revenue Service. There are lots of government forms that use fillable forms. There are many different approaches for filling in these forms programmatically. The most time consuming method I have heard about is to just recreate the form in ReportLab by hand and then fill it in. Frankly I think this is probably the worst idea, except when your company is in charge of creating the PDFs itself. Then that might be a viable option because you then have complete control over the PDF creation and the inputs that need to go into it.


Creating a Simple Form

We need a simple form to use for our first example. ReportLab has built-in support for creating interactive forms, so let’s use ReportLab to create a simple form. Here is the code: Continue reading Filling PDF Forms with Python

PyDev of the Week: Kai Willadsen

This week we welcome Kai Willadsen (@kywe) as our PyDev of the Week! He is the maintainer of the Meld project, a cross-platform visual diff and merge tool written in Python. You can catch up with Kai on his blog or see what else he is working on via Github. Let’s take a few moments to get to know Kai better.

Can you tell us a little about yourself (hobbies, education, etc):

I did undergrad in computer science + cognitive science, a PhD in complex systems modeling, and a variety of post-doc work before bailing on the academic life. None of the above is even remotely relevant to my current work though!

My non-computer hobbies are basically gardening & chicken keeping. For people in the position to do so: if you’ve never kept chickens, think about it! They are the best. Continue reading PyDev of the Week: Kai Willadsen

PyCon 2018 – Conference Day 3 (May 13)

Day 3 of PyCon 2018 began with a keynote from one of the longtime core developers of Python, Brett Cannon. He spoke on the struggles of working in open source and how we should treat each other with kindness throughout the process. I completely agreed with all his points as the negativity I see sometimes is quite discouraging. I try hard when I review books to not be too negative, for example.

After the keynote, they had a poster session and job fair. The poster session is reserved for people who weren’t chosen to give a talk, but their proposal was still good enough for a poster. Or at least, that’s how it was explained to me when the first poster session occurred. I did notice that one of the talk speakers had a poster with the same name as her talk from the previous day, so maybe the rules have changed? I don’t know. I think my favorite was one about a Python keyboard where the keys were remapped to make it easier to program in Python. She had certainly done her research at any rate.

The first talk I attended was Type-checked Python in the real world by Carl Meyer from Instagram. He was pretty persuasive in his talk about how powerful the typing module is and its usefulness.

I had planned to go to Ned Batchelder’s talk, Big-O: How Code Slows as Data Grows, but I got distracted by another writing open space and one on education with Python. The latter was one I probably should have skipped as it was a continuation of a previous open space.

There was a photo booth for people who wanted to take Mother’s Day photos for their loved ones and they had also set aside a room for people to call home in.

I met a ton of people this time around, which was really neat. I met a number of core developers and a couple of people who have backed my projects on Kickstarter. I even got a photo with Guido! Overall, I think I learned a lot of interesting things and look forward to interacting with the Python community for many years to come.

PyDev of the Week: Anthony Shaw

This week we welcome Anthony Shaw (@anthonypjshaw) as our PyDev of the Week! Anthony is involved in several open source projects. You can read up on all of them over on his website. He also has a blog on Medium. Let’s take a few moments to get to know Anthony better!

Can you tell us a little about yourself (hobbies, education, etc):

I started programming from an early age and got into tech at school, studied Cybernetics at University in the UK and ended up working at a Cloud company for my first job. I’ve had all sort of roles, tech support, development, product management and my latest role I’m doing “skills transformation”, which is really about helping people learn new things, encouraging people to develop their tech skills and mentoring. I don’t code day to day for work anymore since I manage a team and have a lot of travel so I typically contribute to open-source projects in spare time and in between flights.

I like to build things with my hands to switch off from work and IT, so I’m normally building something around the house, walls, landscaping or other big DIY projects. I live on the beach on the east coast of Australia so 9 months of the year I’m making any excuse to get in the water to swim. Continue reading PyDev of the Week: Anthony Shaw

PyCon 2018 – Conference Day 2 (May 12)

Day two of PyCon 2018 was kicked off with a few lightning talks. Next up were the keynotes. The first keynote was given by Ying Li from Docker. She spent her keynote talking about good security practices in the web and used a children’s book to illustrate her topic. It was kind of a fun talk and well delivered.

The second keynote was the best keynote I have seen in a long time. It was given by Qumisha Goss who is a librarian at the Detroit Public Library where she specializes in technology. She is a certified Raspberry Pi teacher and teaches Python to 6-17 years olds. It was an inspiring keynote and talked a lot about how we need to reach out across boundaries and ages and teach one another to break down barriers. I highly recommend you watch this keynote if you have a few minutes to spare! Continue reading PyCon 2018 – Conference Day 2 (May 12)

PyCon 2018 – Conference Day 1 (May 11)

PyCon 2018 in Cleveland, Ohio kicked off their first conference day with an introduction from one of Cleveland’s natives, Ernest W. Durbin III. Then we moved on to the keynote of the morning which was given by Dan Callahan from Mozilla. He talked about tooling and how Python currently doesn’t have a big presence on the web. It was actually quite interesting and also a bit disappointing as there wasn’t really a true solution given. However his talk was quite good and insightful. Continue reading PyCon 2018 – Conference Day 1 (May 11)

Determining if all Elements in a List are the Same in Python

Editor’s note: This week we have a guest post from Alex, the CEO of CheckIO

In life we always have options whether we know about them or not. It’s the same with coding. There is a fair amount of different ways in which we can approach a particular task. We might not consider those ways, or have no clue about them, but there they are. Being a coder is not just about knowing the language and the process of writing a code. Very often being a coder means being the most creative version of yourself considering what you’ve never considered before. And on this note I’d like to introduce myself. Hi! My name’s Alex, I’m a CEO at CheckiO and I’ve been dealing with the creative aspects
of this project for quite some time.

Our users are of different coding knowledge levels and experiences, that’s why I often see the standard and more obvious task solving approaches. But from time to time I come across such unique and unordinary solutions that make me once again learn new subtleties of the language.

In this article I want to go over some of the solutions to one of a very simple tasks which in my opinion are the most interesting ones. The mission requires from you to write a function that will determine whether all array elements have the same value. Continue reading Determining if all Elements in a List are the Same in Python