Learn Python with Talk Python's Python courses

#183: Qt for Python Transcript

Recorded on Tuesday, Oct 2, 2018.

00:00 Michael Kennedy: Python is taking over much of the development world, as it quickly is becoming one of the, or simply the most widely-used programming languages. But that does not mean that Python is without its weaknesses. In my mind, there are three such weaknesses. Number 1, GUI applications, desktop applications, that kind of thing; number 2, a native general purpose mobile app for IOS and Android framework that we can build that in Python; and number 3, deployment. So that is a single binary or set of binary and resource files that I can send either to a mobile device or to a desktop app or to a server and it just runs regardless of what they have installed on their system. This episode is primarily about, number 1, the GUI frameworks. One of the best frameworks out there looking to make Python a better language for desktop applications is Qt. Namely, Qt for Python. This week you'll meet Cristián Maureira-Fredes from Qt to tell us all about the revitalization of Qt in the Python space. But you also learn they have aspirations to make Qt for Python an option for mobile app development and to solve the deployment problem as well. That hits all three of the weak spots I was telling you about. We could only be rooting for them to solve these problems. This is Talk Python To Me, Episode 183, recorded October 10th, 2018. Welcome to Talk Python To Me, a weekly podcast on Python, the language, the libraries, the ecosystem, and the personalities. This is your host, Michael Kennedy, follow me on Twitter where I'm @mkennedy, keep up with the show and listen to past episodes at talkPython.fm, and follow the show on Twitter via @talkPython. Cristián, welcome to Talk Python to Me.

01:47 Cristián Maureira-Fredes: Thank you very much.

01:48 Michael Kennedy: It's great to have you here. I'm very much looking forward to talking about Python and GUIs, something I would love to spread the word about, something I would like to see more options for, and it seems like you are doing great work around that.

02:00 Cristián Maureira-Fredes: Yeah, totally, I mean, that's why I'm here. I mean, Qt for Python is something kind of new for the Qt product itself, so I'm looking forward to discuss more things about it.

02:10 Michael Kennedy: Yeah, exactly, it seems like there's a real revitalization around that project, which is awesome. Before we get to that though, let's start with your story. How did you get into programming in Python?

02:18 Cristián Maureira-Fredes: Well, everything started when I started in the university. I had no knowledge of programming whatsoever. I still remember the first class on the blackboard, it was an x = x + 1, make no mathematical sense to me. And, yeah, it was mainly in C, but on the second year, there was some weird class talking about Python that I didn't know, and from that day on, I mean I started to do things by myself, and then here I am.

02:44 Michael Kennedy: That's really awesome. So you have that formal computer science degree program you went through?

02:49 Cristián Maureira-Fredes: Yeah, yeah, and back in my country, I'm from Chile and there is like, something called like, informatics engineer, so there is more like computer science with like a bit more of like how company works and everything like that so it's like a six year or something to study.

03:02 Michael Kennedy: Yeah, well that sounds like a really cool project, or uh, studying, course of study.

03:06 Cristián Maureira-Fredes: Yeah totally.

03:07 Michael Kennedy: And so, how about today? What are you doing now?

03:10 Cristián Maureira-Fredes: Well we are currently approaching the official release of Qt Python, so we are really excited about it, but of course, you will understand there are many things to do, so we are, you know I mean, today was like a normal day, something, some blocks, and trying to bring all the features for the final release that will happen at the end of the year.

03:29 Michael Kennedy: I'm very excited for that. So you work for the Qt company that makes Qt.

03:33 Cristián Maureira-Fredes: Yes, I, yeah exactly I, recently, well not recently, at the beginning of this year, well I am here currently in Berlin, I was doing my PhD here and then I decided to move it back to industry so I decided to work with the good company because I was aware of it, I mean since like 2009 or something I had some small projects and I was really curious about it, what they were doing and there was this opening, I apply and I started to work here, yeah, in the Qt company.

04:01 Michael Kennedy: Excellent, so I guess a good place to start is just, what is Qt? Because we have things like PySide and PyQt and Qt for Python but Qt is a UI framework much larger than just Python, right?

04:16 Cristián Maureira-Fredes: Right, I mean, to be honest, when I first started to work in Qt for me was just a library to do interface, right? So, but with the, with the old, the other years of experience, I started to notice that it's really more than a cross-platform application framework. And I mean, I noticed that, even for C++ user, you were able to, to write some scripts and combine and have some tools for SQL or any like sockets and modules for everything that you can imagine . I mean the modules are really a lot and the things that you can do are really unimaginable, so.

04:49 Michael Kennedy: So let me see here if I have my conception correct, I'll bounce this off of you and you let me know. So, for me it seems like Qt is a framework for building cross platform applications.

05:02 Cristián Maureira-Fredes: Yes.

05:03 Michael Kennedy: Much of that is GUI but there's also things like custom threading things and like you said, other libraries as well. Is that a pretty good summary?

05:12 Cristián Maureira-Fredes: Yeah, that's a good summary. That's the summary when I start my talks about it.

05:17 Michael Kennedy: Alright perfect. So I guess I have a pretty good conception of it. And I feel like the apps built in Qt are really nice because they seem, they seem like they belong on the application or on the OS or platform that they're running on. I feel like so many of these cross-platform things just stand out like a sore thumb. One, a lot of them look like they're from like, you know, 1990 because you're like, whoa, that is not what a button looks like on macOS or on Windows or whatever it happens to be you're on, right?

05:46 Cristián Maureira-Fredes: Exactly, yeah, my first experience, for example, I remember when I was learning Python I wanted to do some simple application and I tried to use TK, you know TKInter.?

05:55 Michael Kennedy: Oh yeah.

05:56 Cristián Maureira-Fredes: I tried, I mean, I admire the work but I mean, interface don't look really well there, and then I started to move around and everything and of course I'm aware that you know, for example, one of the biggest projects that uses Qt is KDE and at least, when I started with Linux, it was the most like, you know, graphical appealing, embodiment for me, so.

06:16 Michael Kennedy: Yeah, that's really nice, that's really great. So let's bring this conversation over to Python now and maybe we could do a quick tour of what are our options for building in Python GUIs, at all. I mean, you brought up TKInter, well obviously we have Qt, Qt for Python, nowadays. There's other things like wxPython, do you want to give us a quick tour of what our options are?

06:40 Cristián Maureira-Fredes: Well, I mean, you mentioned like the main ones, right? I mean, if you go into the Wikipage, for example, you can see that the list is like over 30, different modules to do different things and but of course, not all of them are active now. So, personally, the one that I am aware of that they are currently in the loop, or like they, TKInter, I mean, they love wxPython, there is also PyQt, another set of bindings for Qt, and also there is another one called, what's the name, Kivy that they also, lately, I have heard a lot, in Hacker News and Reddit so I think it is quite becoming a little bit famous.

07:16 Michael Kennedy: Yeah, that's a good, yeah, Kivy's doing good stuff. I feel like it's really focused on more on like game experiences and something like Qt, you could build, you know a traditional application, right? You could build visuals to your code or PyCharm or a web browser or something like that.

07:34 Cristián Maureira-Fredes: Yeah I mean, as you can see now, at the beginning of course, for me, KDE was the biggest and only project but with the time, I mean, you can notice that nowadays with all these data science boom, you can find like tools like Tableau, for example, that is written in using Qt or the latest version of VirtualBox and VLC and not even there, I mean, because since I've joined the company I noticed that, okay, I was saying is this is a company, I mean do we have other clients or outside the open source projects? And, I noticed that for example, many companies on the automotive industry are using it right now. I mean, of course, here in Germany there is Mercedes, and also lately, Peyo announced something like, that they were including Qt but most importantly, at least for me for my geek standards as they call, the Tesla car, for example, is assigned using one of the Qt things I would use.

08:27 Michael Kennedy: That's cool.

08:27 Cristián Maureira-Fredes: So it was really impressive, but it was impressive for me.

08:31 Michael Kennedy: Yeah Tesla's definitely one of the more, you know, turned-on car companies in terms of technology. So that's pretty awesome. And you also have, you said that's in, LG Smart TVs, is that right?

08:42 Cristián Maureira-Fredes: Yeah, I mean, also I mean, there was a couple of these TVs that has a manual, I don't know how to describe it but it's on the button that you have like, a different elements of the menu and stuff and that's also written with Qt and there is also some entertainment system by different electronic companies and I mean, this is not just the official clients of Qt, right? I mean, you know it's an open source project also. So there are many companies out there and luckily on the latest conference that I went, for example, I met people of the biggest companies that approached me, as Ah yes, we are using Qt for some internal project and everything, so of course we have a lot of open source clients, so.

09:20 Michael Kennedy: Oh, that's really cool. I've talked to some companies even thinking about using it for devices, little embedded devices and stuff.

09:26 Cristián Maureira-Fredes: Yeah, that's really a hot topic right now and I mean, I didn't have the luck yet to work on them, embedded systems, but there is a lot of people doing that little work on embedded systems and devices, so. And every time that there are conference I mean those are the thing that steal the show. I mean, all this embedded system that we have in comparison with other technologies, but yeah. Sadly I am not an expert in that field but maybe next time we can go further.

09:49 Michael Kennedy: Yeah that would be great. Yeah it feels like Kickstarter should be involved. A little Qt, a little Kickstarter and something awesome could be launched, yeah? Very, very cool. So the reason I reached out to you guys is we do this overview of the various GUI options and you know, those folks who listen to my other podcast, PythonBytes, know that we've gone over so many options and there's, there are a bunch of them, but, I feel like, like I said, Qt is one of the more, it looks native and it seems like you can build really nice apps with it. But for a while, there had been this, I don't know, this sort of almost discontent where we had what, PySide, we had PySide2, we had PyQt for Qt 4, and then Qt 5, it was like, well what is the license model? What one is up to date? What should we do? Can you just sort of, let us know, you know, why did you guys work on Qt for Python and you know, what is the state of that whole conversation there?

10:49 Cristián Maureira-Fredes: Yeah well I mean, the story is a little bit long, but mainly it started with like a, there was some, some correlations of Qt in a different country, I think it was Brazil and they decided to start a new set of bindings for Qt and the PySide project was born. And then...

11:06 Michael Kennedy: Maybe define that, real quick, for folks, like when you say binding, what do you mean? These are like Python libraries that we can use in Python but they talk to the C API?

11:16 Cristián Maureira-Fredes: Exactly. There is some, say Python code, that will keep you connected to C library. So that's why, how we can expose this C++ framework to Python world. So we have some glue in the middle that maybe later we can discuss but yeah, I mean, I know it's confusing about the names, but I mean it's really depending on the same use of the Qt projects. Because I mean, there was some Nokia-related things and going on in the middle, and then there was like no Nokia and then the project it started to evolve, the Qt it was, Qt 4 back then, and they decide "Okay, but now it's Qt 5." So what do we do? And there was some force by the community that started to support it and that's why PySide2 was born because now there was support for Qt 5 but the problem is that, at the company, we didn't want to focus just in the module. And this is really important for me to say because Qt for Python is not just a module. I mean, we have a lot of ideas and things going on that will try to complement this PySide2 module that currently we have.

12:20 Michael Kennedy: Okay, that sounds very interesting. So where does Qt for Python fit? Is this just you taking over PySide2 project? Is this something different?

12:30 Cristián Maureira-Fredes: Yeah, well that's the thing. I mean, at the beginning, I associated with Qt, but not officially supported. So now they move all this, the noise that we have been generating is because we are officially supporting PySide2 as a module and now one of the Qt products. And that means that any person that wants to start the use Qt by Open-source would have the options to get a PySide2 as a module also to play around with Python or if your a client for example, and you aim to have some commercial license and everything, you'll have the option also to give these officially supported bindings that can allows you to use Qt from Python.

13:03 Michael Kennedy: That sounds awesome. I'm really excited to hear that you're, you know, focusing full effort on this GUI platform for Python.

13:11 Cristián Maureira-Fredes: Yeah totally.

13:12 Michael Kennedy: It's going to be great and you said the official first release of this Qt for Python update is targeted to the end of the year?

13:21 Cristián Maureira-Fredes: Yeah, well at the moment, well the project was heavily developed and we decided to give it a try. So we generated the first set of wheels that we released from PyPI and like in June I think, but of course this was under the technical preview labels so of course use it at your own risk. We are currently like reaching a maturities stage that we are sure that the by the end of the year, which is the release of Qt 5.12, we will include the official wheels without the technical preview tags, so yeah. We are really looking forward to it.

13:58 Michael Kennedy: Yeah, that's going to be super cool. Now, you're talkin' 'about wheels, so that's when I pip install a thing and you know downloads it and installs it in a nice simple Pythonic way. I believe previously in the PySide, PyQt days, that was harder to basically deploy an app that was built on Qt or one of those frameworks right?

14:21 Cristián Maureira-Fredes: Right, right.

14:22 Michael Kennedy: So, go ahead.

14:24 Cristián Maureira-Fredes: Well even if, before I mean I don't know, I know that you have been using Python for a lot of time, but even the time with X, you remember that X was first before the wheel? It was quite complicated to generate this kind of like projects and stuff and I was struggling with this. At the moment for example, many users asks us like how to deploy applications? How to move these things around? But, yeah we usually encourage people to use PyInstaller, but yes. Spoiler alert, that's one of the things that we are currently working on like try to help the users to provide ways to deploy that application in a more easy way, because Qt is cross-platform, so of course you will like to have some binary that you can like move around and try to execute and try to don't worry about in which platform you are running.

15:12 Michael Kennedy: Oh you guys would take it up a level if you did that. I mean if there was a build my project for macOS, build my project for Linux, and here's the thing you give your users, or you put on your website, seriously, that, I mean you already have one of the best cross-platform frameworks and if you could solve the deployment problem for Python, oh it would be on.

15:32 Cristián Maureira-Fredes: Yeah there is a few options out there, I mean currently there was some on our blog, there was some story of another system that was called FBS, which is a guy that we had a pleasure to talk with and also he had some small project that is starting to attack this problem, because it's really I mean, it's like every day someone in IRC is asking about like how do I deploy my application? How can I integrate this with other tools and everything?

15:56 Michael Kennedy: Yeah, yeah, that's the fman Build System from Michael Herman, that's pretty awesome. Yeah so, that's a pretty promising project and if you could get some sweet integration, where you know a lot of, it seems really really nice. And he's doin' a lot of stuff with Qt. That's cool that you guys are talking. I think it's already better that you can pip install -r requirements.txt or pipenv your world and you just get the Qt runtime, the Qt runtime, excuse me. Which, it doesn't mean like I go get this weird installer from some other place that you're not really sure, install that right? It's nice to have it just come already and if you could get like a true binary then that would solve, I think that would really be somethin'.

16:39 Cristián Maureira-Fredes: Yeah, even internally I mean there were many people I mean, since this is a long standing company using C++, and a couple of people that are recently joining the company when they first try it and they always said like, I just pip installed PySide2 and I have everything else from Python and which kind of magic is this? I mean they were not even aware of how fast it can be and I think that this is one of the main reasons that why the Qt company wanted to officially support Python right? Because I mean, this is a podcast about Python, so we don't need to convince people about it but they're not...

17:10 Michael Kennedy: You'd be surprised. There's a lot of people that listen that maybe Python is not their main language or they're just getting started and they're still exploring. You'd be surprised so, there's probably a lot of people who, you know, still even if they've been doing Python for 20 years, maybe they're like well, it's great for websites and back-ends, but I'm not going to build my UI in Python right? Convince us. Convince us about Python. I think it's great if you can do it.

17:36 Cristián Maureira-Fredes: Yeah well I mean every single person that is patching code at some point is aware of Stack Overflow and for example I remember that this year's is our Stack Overflow insights, was showing how popular Python was becoming and after all these years, I remember back in the day, in the university I was like, there was the Perl people and the Python people and of course all the Perl people are the devil and we will not hookup with Perl. But currently you can see that even some index that like measure the amount of questions or search queries about programming like the TIOBE index for example, they were showing Python approaching the top three.

18:14 Michael Kennedy: Yeah, it's amazing.

18:15 Cristián Maureira-Fredes: And looking at that, not even like general users because I mean, I have also some background in academia when I was doing my PhD, I encountered that most of the old researchers were using programming languages like Fortran for example, but all the new ones were using Python and that's how we have now the IPython notebook in fact now we're called Jupyter project and all this data science rated things that is mainly using language Python I mean, and you cannot like expect for some like new position that the science is to ask us for, I don't know C or Fortran, that's really really in the past though. I think that's the key.

18:51 Michael Kennedy: This portion of Talk Python to Me is brought to you by Linode. Are you looking for bullet proof hosting that's fast, simple and incredibly affordable? Look passed that bookstore and check out Linode at talkpython.fm/linode. That's L-I-N-O-D-E. Plans start at just $5 a month for a dedicated server with a gig of ram. We have ten data centers across the globe, so no matter where you are, there's a data center near you. Whether you want to run your Python web app, host a private git server or file server, you'll get native ssd's on all the machines. A newly upgraded 200 gigabit network. 24/7 friendly support even on holidays and a 7 day money back guarantee. Do you need a little help with your infrastructure? They even offer professional services to help you get started with architecture, migrations and more. To get a dedicated server for free for the next four months, just visit talkpython.fm/linode. Yeah, is the Qt company largely a C++ organization given that a lot of the main product is in C?

19:52 Cristián Maureira-Fredes: Yeah, yeah of course. We've had some automations and internal tools, but you can find that people knowing about the many other programming languages, I mean I know that there are like also Perl experts, a guy using Python for automating tasks or maybe they have some system build with Go and everything like that but I mean, the majority of the users and the community around is like purely C++ experts.

20:17 Michael Kennedy: Right, right. I feel the package management aspect, you know, pip install antigravity for example type of things, really is something that Python brings. It's so special compared to say C and C++, right? It's just a different level of productivity. Complete entirely.

20:37 Cristián Maureira-Fredes: Yeah, exactly. That's one of the reasons that we are trying to use, for example, to try to, not to convince but to bring Python to C++ developer. I mean, how fast something could be to start something. I mean, even if you want to have small GUI, just something with clicking some buttons. You know in C++ at least you have writing the code, compiling the code, and executing and if you want to skip one of these steps, which is just write your code and execute it, I think that's really amazing and that's one of the main reasons. That's why started to even spread the word about Python in general when I was starting my PhD also and that's the main motivation that we currently have as a company.

21:15 Michael Kennedy: Yeah that's cool. I agree, I think you missed a step it's also the figure out why that segfault is happening.

21:23 Cristián Maureira-Fredes: That's a thing, I mean, day by day, all the people on the team is dealing with this segfaults just to provide users for segfaults free. And you know, we were combined in two worlds, I mean, that's nightmares that sometimes have happened and on the other side we have all the CPython instructors, so we try to combine these two things so. Debugging the development of Qt Python it is a challenging but at the same time it's a lot of nice source of knowledge.

21:51 Michael Kennedy: Yeah, so, yeah let's dig into how it works a little bit, and I want to follow up on this, you know, how you bridge these two worlds. There's a lot of interesting possibilities there. So how do we go from Qt code, Qt headers and widgets and stuff to generating what is at code level called PySide2?

22:11 Cristián Maureira-Fredes: 'Kay so, the things that we do is at the original idea was to attract all this information from the Qt headers and for this we use Clank and also we have some internal tool that is called Shiboken with that allows you to, allow us to modify the status, because I mean you know sometimes you have the C++, some void* or some ** pointers and stuff like that, so we need to manually transform all these things and bring everything to the Python world.

22:40 Michael Kennedy: Right 'cause Python doesn't have a void** type right?

22:44 Cristián Maureira-Fredes: Exactly so we do black magic inside and under the hood that allows you to use the method that includes some void* things.

22:52 Michael Kennedy: Yeah, for sure. Okay so, there's the C++ definition of how to directly, natively work with Qt and then use this thing called Shiboken which generates modules that interact. That are basically for CPython that can then talk to it. So are you using CFFI or CAPI or how does that work?

23:14 Cristián Maureira-Fredes: That's the magic. Back in the day, when the developers started with PySide, they started to use Boost Python, that's personally I know that I have been using, but I don't know if you have experience with it.

23:24 Michael Kennedy: I have none, no. What's Boost Python?

23:26 Cristián Maureira-Fredes: Boost Python is just the same idea and it allows you to generate binaries for Python from some C++ project. But the problem with this is as was the main problem back then is that there is a lot of user templates in C++ which is one of the obscurest areas of C++ world and this also increase the size of the binaries that you're generating so, the developers back then they say okay, what is the best solution right now? Let's write our own binding generator. So it was heavily inspiring Boost Python and trying to remove the template situation and there is this type system thing that I mentioned, this pure XML file with some directives of modifying signatures for example of methods. And then you can use this to generate the CPython code that you can compile into the form and Python module.

23:26 Michael Kennedy: Okay, sounds very interesting and I've recently learned that you can take this Shiboken and you can apply it to any C library potentially is not just for Qt, right? So this could be a useful tool for people who actually don't care about UIs.

23:26 Cristián Maureira-Fredes: Yes, exactly. As soon as we started to release official set of wheels we started to get people like, I want the binary for my project and everything and yeah, it's possible to. I encourage people to take a look in our blog there was a post there that write Python bindings for C++ project without any Qt on it. So of course it's something that is still under development and is open-source so there is still some incompatibilities. For example, we have some issues with templates. When and if your project has templates, but also maybe smart pointers and things like that, but in general, at least for us to do the work and we are planning now that once the official release is out that the open-source committee will react and help us to improve Shiboken itself.

23:26 Michael Kennedy: Yeah, it sounds like a really useful tool on it's own. Help me understand why or how this might differ from say using something like Cython or something like that, would another reasonable path be to write part of your code in Cython and directly interact with the C part?

23:26 Cristián Maureira-Fredes: Well it's Cython is just at least I use it just for optimizing some Python code but since we need it to create this bridge to have this glue between C++ and Python world. I think it as generator was needed and there are other options like that out there that you mentioned for example that CFFI and also there is nice what was the name of this module? Pybind11, that also allows you to generate the link between these two worlds. I think that it's Shiboken will be one of the nice options out there but still I think that we need to there's a lot of things to be done there.

23:26 Michael Kennedy: Yeah, yeah of course. Okay interesting. Let's talk first at a high level about what some of the modules are, you touched on this a little bit, but what do we get, what do we have to work with when we work with PySide2?

23:26 Cristián Maureira-Fredes: Yeah, well said, it sometimes can be really overwhelming for people to meet Qt in the sense that there is so many things to do, but for the user that are starting with generating graphic user interfaces, that we have like three main modules in Qt that are of course exposed in Qt to Python. So, the Qt core, the one that has all the basic definitions of types and classes that you will use, and then we have some GUI elements that for example, you can encounter. There is some like the base of how it is created for example, pixels or aligns of that, and then you have widgets which is the more general one that exposes pre-made things, like if you have a button, a group box, a check box, and everything. So usually old examples code that we currently have most of them use this three modules for different functionality. But a normal user, I think I will play around Qt widgets and maybe Qt core, for getting a few things.

23:26 Michael Kennedy: Right. You also have things like Qt charts, Qt multimedia, testing even right?

23:26 Cristián Maureira-Fredes: Yeah well that's the thing, there are many other modules that allow you to do things with Qt that sometimes are exposed in Python natively. For example, we decided there's a few mathematical modules that we decided not expose to get to Python directly because of course you have the math model, in Python you have any other numerical library, there right? But Qt charts for example, is the one that gets more of our attention, at least there is a couple of nice examples in our code base that really brings people to enjoy and that said oh my god yes, this is so easy and I can combine it with any other numerical data other sources that they have.

23:26 Michael Kennedy: That's cool, so if I was doing Scikit, NumPy, those types of things, I could take that data and visualize it in say like a Qt chart or something like that or Qt chart?

23:26 Cristián Maureira-Fredes: Yeah, yeah, exactly. That's one of the nice things that we are doing. Of course since all the API that we use is C++ based, we are now in a moment of defining of how to break this API up but not in a bad sense of it, in the sense of bringing Qt to Python in a more compatible way for Python world. So for example, there is a lot of research being done, of allowing NumPy or SciPy types into Qt methods and classes.

23:26 Michael Kennedy: Now that is awesome. Because it's in C in NumPy for example right? Why does it have to go into Python then back out into another C layer, right? If you could just say, hey you, you're all down there, figure that out.

23:26 Cristián Maureira-Fredes: Yeah exactly. That's the thing that we need to see what is underneath all this amazing NumPy arrays and see how we can make it compatible with the signatures of the method for example.

23:26 Michael Kennedy: And Pandas and whatnot, yeah that's really cool.

23:26 Cristián Maureira-Fredes: Exactly.

23:26 Michael Kennedy: Alright so, one of things that really appeals to me with building GUI applications, is a visual designer. I know you can write code, and I know you can specify an app, but being able to say here's a button, I'm going to put that button next to that input box, and just drag it there and then I'd like to have this method called when I click it so I wire up an event to it, a call back to it. So the Qt project has something like this right?

23:26 Cristián Maureira-Fredes: Yeah, exactly. We have our own IDE, which is Qt Creator and inside this IDE I confess, even when I started to work there I was really not into this idea because I prefer it to use Beam for example, but I just have to discover the amount of things that you can do inside and it's quite remarkable. It's my, for example, way to go for debugging applications nowadays, but now that you mention the designer you also have the ability of design interface it's like the principle, what you see is what you get, so you drag and drop things, move things around, then you generate some kind of scheme, right? So this scheme would be translated into a UI file which is something, of course internally of the Qt, and then with this UI file, you can do as you want, I mean you can use it in your C++ project or you can use it to file convert for example. You can load it dynamically or you can generate some Python code from this UI file.

23:26 Michael Kennedy: This portion of Talk Python To Me is brought to you by Rollbar. Got a question for you, have you been outsourcing your bug discovery to your users? Have you been making them send you bug reports? You know there's two problems with that. You can't discover all the bugs this way and some users don't bother reporting bugs at all, they just leave, sometimes forever. The best software teams practice proactive error monitoring. They detect all the errors in their production apps and services in real time and debug important errors in minutes or hours, sometimes before users even notice. Team from companies like Twilio and Sicar and CircleCI use Rollbar to do this. With Rollbar, you get real time feed of all the errors so you know what's broken in production, and Rollbar automatically collects all the relevant data and metadata that you need to debug the errors, so you don't have to sift through logs. If you aren't using Rollbar yet, they have a special offer for you and it's really awesome. Sign up and install Rollbar at talkpython.fm/rollbar and Rollbar will send you a $100 gift card to use at the open collective, where you can donate to any of the 900 plus projects listed under the Open-source collective or to the Women Who Code organization. Get notified of errors in real time and make a difference in open-source. Visit talkpython.fm/rollbar today. When you started talking about editors, that a very sensitive very sensitive thing for me as well, right? It sounds to me like I can take the Qt Creator, which is what that IDE you were talking about is called, right? I can take that and I can define my UI files but then I can still use my other editor to write the main code or something like this if I wanted?

23:26 Cristián Maureira-Fredes: Well, yes. But again, that's another spoiler alert. No, but I mean we are working on proper integration with Qt Creator. At the moment, you can use it to code your applications and everything is there. And now we have even some testing phase for out of completion. But the problem is we don't want to just provide a nice editor and that's it. We want to integrate more options and better integration with the Qt projects. Just the thing that you mentioned about deployment or maybe transfer or creating base projects in Python. So everything is on our todo list for the future of the projects. So that's why we are so looking forward to release as soon as possible to start to work on these features. And now, I mean lately, in the last post that we have from Qt Python, we have some intern that was working with us and he managed to, for example, to extend the same IDE, Qt Creator, with Python scripts. And this is something that is really new because in the past it was just C++ but now since we have PySide2, you will be allowed to modify the IDE, even with Python. So we are Pythonizing everything.

23:26 Michael Kennedy: That is cool. So basically I could write like extensions or plug-ins or whatever you want to call it for Qt Creator in Python?

23:26 Cristián Maureira-Fredes: Exactly. That's the idea.

23:26 Michael Kennedy: That's cool. I guess that brings up another thought for me. So much of Qt is in C, the entire API is C++ based and what not. Do you see people writing part of their application in C++ but then maybe hosting the CPython runtime so that other people can extend their applications with Python or does that not really happen?

23:26 Cristián Maureira-Fredes: Yeah, to be honest I was expecting less people to be doing this but its crazy the amount of questions we receive every day that are, yeah... Most of the people out there from companies and even some startups and stuff, they are trying to extend C++ applications in the same idea that we are presenting for Qt Creator and they are trying to use PySide for it. So we have, for example, the same idea of writing plugins for your application is being done by any other project. One of our clients, for example, which is the graphical effects industry that's called Autodesk. They are also allowing users to extend the application itself, writing the plugins with PySide. And also I have heard some stories of people with some big C++ files trying to allow users to write Python stuff. So yeah, this is totally possible.

23:26 Michael Kennedy: How interesting. So I guess some other areas you might try to work on is we talked about embedded systems a little bit, what about mobile?

23:26 Cristián Maureira-Fredes: Yeah, well mobile is something that every time we go to some conference or talk, there is the question, what about mobile support?

23:26 Michael Kennedy: People pull out there phone, and they're like here, I want it here. Billions of people are here. How do I do this? Are you working on this?

23:26 Cristián Maureira-Fredes: Yeah, this is something that will be like also in our todo list. But we are focusing on the previous topic before. But yeah, its something that we need to do. We need to achieve. And at the moment, you have the option to go around with the iOS or the Android with Qt. There are some options even in Qt Creator to deploy C++ applications. But it's something that's really pending on us. But it's something that we would totally like to do because even though if you didn't have the same feeling and you cannot compete with the native stuff like Android in Java. There's a lot of things to be done there. You can see like the revolution that coding has after it was introduced in Android, that is, of course, kind of getting rid of all the Java ugly code and bringing some new stuff in it. So yeah, we are totally going to be a part of that movement too.

23:26 Michael Kennedy: I would love for you guys to be a part of that, if you're bringing Python along for the party, that'd be cool. Its really kind of surprising to me that Kotlin, which is a language created by JetBrains in the last five years, it's not very old, actually almost displaced Java in the Android space. It's quite interesting.

23:26 Cristián Maureira-Fredes: I mean if you have some experience with Java you will understand the pain. I mean, sadly, I have some experience too. I mean it was really frustrating even in writing really small pieces of code. At least for me, coding I always have the same idea that the people behind coding like really decided to write something in a more Pythonistic way. We cannot deny it. It's really has a lot of Python in it. And even if you're writing some stuff, you're like hmm, this sounds like Python. I'm pretty sure they had Python in mind when trying to write.

23:26 Michael Kennedy: Interesting. See I really haven't done too much with Kotlin. Maybe I should check it out.

23:26 Cristián Maureira-Fredes: Yeah it's quite nice.

23:26 Michael Kennedy: It sounds interesting. There was an article, I can't remember where it was, that was on major unexpected magazine or news source, that was talking about the future of programming languages and it says one of the predictions is that Python is going to be the great-grandfather of many, many programming languages. I think that's probably true and this sounds like that. You have Swift as well.

23:26 Cristián Maureira-Fredes: Right, right, exactly. I haven't tried Swift. But I think its, yeah, Python is a whole new starting point for the future generations of programming because it's bringing something that is simplicity. You know, the first time I encountered Python it was so easy to do things. I mean you didn't know, oh, there was a semi-colon or no open brackets or closing brackets or what is the start...

23:26 Michael Kennedy: It is so interesting that when you come from one of these C based languages like C++, C#, Java, whatever, even JavaScript, you feel like all these curly braces are required, all these parentheses around the if statement are required. And then you can work on Python and it's a bit of a shock to the system, for sure. You're like, wait a minute, spacing matters? There's no curly braces? But then, after just a week, if you go back to the other language you're like what's all this stuff. You're right, these parentheses here are not necessary. Why do I have to type all this stuff?

23:26 Cristián Maureira-Fredes: Yes, and I remember back in University, even teaching C, it was really a nightmare because we would all write code and even write normal handwriting and stuff differently. But having this space requirements it is something that is so enlightenment for writing code and its really difficult to write obfuscated Python code. But I have seen, maybe you're aware of this really obfuscated code in tournaments that you have...

23:26 Michael Kennedy: Yes, that's really interesting. Yeah, tell people about that because I remember just being blown away.

23:26 Cristián Maureira-Fredes: Well this whole idea of obfuscated code is when you see the code it resembles something and its usually a really cryptic thing and moving bytes around and stuff. For example, I remember the more shocking to me was something about a circle made with dots and slash and stuff like that and then when you compile the circle and you execute it, you get the value of pi.

23:26 Michael Kennedy: That is beautiful.

23:26 Cristián Maureira-Fredes: And I was like, what? That was really weird. And with Python, we will likely not have this type of obfuscated tournaments because it will be a nightmare.

23:26 Michael Kennedy: It definitely goes against the zen of Python, for sure. Speaking of styles and stuff coming together and worlds crashing, something that was surprising to me and I'd like to ask you about, is when I look at PySide2 or just PySide, the APIs here, they all look C style. You know, lowercase first variable, and then uppercase first letter and then uppercase second compacted word or composite word. As opposed to the Snake case of underscores and all lowercase. What's the story with this semi non-Pythonic Python API?

23:26 Cristián Maureira-Fredes: This is a really hard topic. Every time that I bring the talk about Qt Python with C++ developer, Java developers, or even Python developers, everyone starts to fight with each other because there is something set we cannot break in the sense that like... The reason, for example, for keeping the camel case for the Qt API is because every person that already knows Qt or has some project in Qt, it will be so easy for them to just rewrite code in a Python way using the same API. Because if we start to replace all the camel cases for underscore, which is the Python way of doing it, we'll have break everything. People will start to run examples from C++, they will be unable to decipher how to write these things in Python. So we said, okay, we need to settle somewhere. So every time that we use the Qt API, we'll use camelcase. But everything else will be following all the paths that we want in the Python stylings. That's why the example mix. Yeah, I think it is a balance between two worlds. And we're not the only ones. I think that there is asyncio or I don't know, there was another model in Python that used camelcase for the API. I'm not sure about it. But I mean I think that it's a nice solution.

23:26 Michael Kennedy: Yeah, I have seen it before. I can't remember where it was. But I was like, why is this library got this style? I think it was in the standard library. That's funny. That makes sense to me. It's a bit of a trade off, right. You've already got this code that exists and if you're going to generate it, there's this easiest to sort of generate exactly the same names if you don't necessarily have to do the documentation as differently.

23:26 Cristián Maureira-Fredes: For us, for translating examples, for example, we grab any functions written in C++ then we copy it to Python, we remove the brackets, we check the consistency, we remove all the semi-colons and that's it. And then you have it.

23:26 Michael Kennedy: All the complicated stuff, you take it away. All the unnecessary symbolic stuff that's hanging around. And look, its the Python version. Interesting. I've seen other frameworks where they have something that's ultimately a C API underneath and it supports different languages and they've taught basically the equivalent of their Shiboken to say if I'm generating Python it looks like this, if I'm generating JavaScript, JavaScript has this coding convention. But I can see the argument for just saying, most of the people who are coming to this world are coming from the C++ world and their code looks like this, let's not shock them too much.

23:26 Cristián Maureira-Fredes: Yeah, exactly.

23:26 Michael Kennedy: But you have this debate often?

23:26 Cristián Maureira-Fredes: Yeah, it is something that is... Even when we are writing the codebase of the project, we have people that are really into Python, people that come from C++, so when we are doing all the code reviews we start to clash between, ah you need to leave in a space, no that's not CPython standard, no that's C++ standard... So we need to agree even among us.

23:26 Michael Kennedy: Yeah, interesting. So one thing that I saw showing up in the documentation and the API and stuff was this thing called signals and slots. What's this and how does this look in Python?

23:26 Cristián Maureira-Fredes: So yeah, signals and slots are the base of Qt. So the idea behind this is that we treat every single element of the interface and also underneath as an object, as a q object. So these objects can interact between them. And the idea of signals and slots is like that. An object will have something that will trigger something else. So let's put it like simple, if you have a button then a button is also a q object and this button will have a special signal that we will call, for example, clicked, of course because you can click the button. And then this click signal will trigger something else. So then you can have another function or method or whatever you want to call it that will be the slot of it. So every time that you click the button it will do something. So it's a really basic principle but it is the base of the whole Qt framework. So that will be roughly the same in Qt Python and we follow the same idea. We're not adding new signals or removing old ones. It's just keeping the same API. So it's really nice of it.

23:26 Michael Kennedy: Okay, so this is the way to basically wire up function calls for user interface events, mouse over, click, whatever.

23:26 Cristián Maureira-Fredes: Yes, exactly, hover, trigger, check, everything.

23:26 Michael Kennedy: So what's the performance look like if I've got a non-trivial C++ application written in Qt and then I were to rewrite that in Qt for Python, what would my experience be like?

23:26 Cristián Maureira-Fredes: For general applications like even big ones, for example a browser, personally I haven't performed any real tests with milliseconds and that but I cannot notice any lags or delays for having something written in Python. And the only problem with time that will come is only if you're writing Python code that is slow. So if you start to iterate a list of lists in the wrong way and then are accessing all the time to all the data, maybe you will, of course, encounter some bad speed for your application. But roughly there is, for example, some browsers are reading as an example inside a Qt code that we had the Python version and we couldn't notice any difference of executing the C++ and the Python versions because they're quite simple and they're fast. Because after all, we are just calling the C++ methods and functions underneath.

23:26 Michael Kennedy: That's a really interesting bit there. I feel like when people talk about performance of Python a lot of times they say, oh its' way slower than C or whatever. But much of the time if you're doing data sciency stuff or, in the case of Qt, you're doing a little bit of Python orchestration around objects that are executing in C directly, right? So in your web browser example, you might say if somebody types in the address bar and hits enter, you want it to drive the web browser widget to go to that address. But really the only Python code that executes is got a string, tell the C library to go drive the thing to this URL, right? So it's only if you're actually doing lots of computation directly in Python, right?

23:26 Cristián Maureira-Fredes: Yes, I think most of these statements come from people that are really not experienced in Python in the sense of like, they try to rewrite Java or C++ code in the same way. You are aware of, of course, if you write iterations in lists or list comprehension or maybe you have some ways of optimizing your code. You can even reach like the same levels. I think this will depend on the amount of knowledge a user has, right? Because, of course, if you translate any C++ application out of loops and everything, into Python will be way slower. So we need to rethink the algorithms to use Python in a better way.

23:26 Michael Kennedy: Yeah, for sure. And I brought up the import antigravity. So much of what I think would happen if you're coming from one of these other libraries that doesn't have as many foundational things to use, is you just copy the code over and you try to execute it on CPython, but instead of some great big loop you pip install a thing that has optimized part of it and you just call that, right? And that completely changes the story. It's pretty interesting. So you think it's a pretty reasonable thing to do to write Qt applications, GUI applications in Python. It's not going to be a complete night and day thing?

23:26 Cristián Maureira-Fredes: Yeah, totally. At least, that's my personal opinion. I'm looking forward to having some real world cases of people doing some really weird things about like populating tables of like one million times one million and they have some speed issues. But I think that we are up into it. We had a case recently, there was a bug. There was some person that was populating a table that was like one hundred times and the table was like huge and, of course, the user brought the bug in. We didn't understand what was the real use of this. But we were quite open about this and we decided to start to optimize our code and even some C++ optimizations, for example, going to vectors instead of lists. And things like this. So we are quite open this and every time that someone brings some speed issues to the IRC channel, we try to figure it out and try to solve it.

23:26 Michael Kennedy: It seems like you're doing a good job. It sounds great. Alright, are you ready for a tough question?

23:26 Cristián Maureira-Fredes: Yes, I am.

23:26 Michael Kennedy: You said that this is available for open source projects for free or there is a license that I can buy. So for open source it's under what, GPL, LGPL?

23:26 Cristián Maureira-Fredes: LGPL.

23:26 Michael Kennedy: LGLP. So if I write like, let's suppose I write a database management application. I want to have a new designer and graphical designer for like working with databases, I'm going to write that in Qt for Python. That would mean my application would have to be open source?

23:26 Cristián Maureira-Fredes: I mean that is just following the LGPL restriction rights, so yeah.

23:26 Michael Kennedy: But if I don't want that, what do I do? If I want to sell that product, for example?

23:26 Cristián Maureira-Fredes: That's the thing. Since of course, Qt space and this open source idea, but we're also a company and we need to have some customers with some support and everything, we sell licenses for commercial use. So this will allow you to build whatever you want in Qt and sell it as your own project and everything. So that's one of the things that the Qt Python project will bring to new customers. That with this same license, you will be able to build any application using the PySide2 module and sell it if your business is about it. So that's one of the nice things. And, of course, I know we will keep all the code open source and LGPL related, so yeah.

23:26 Michael Kennedy: Right, okay. What does that cost me?

23:26 Cristián Maureira-Fredes: I really don't know the price at the moment. But I can point you to any sales person of ours. It really depends on the size of the amount of licenses you want to buy.

23:26 Michael Kennedy: Do you know how it's portioned? Is it the number of customers I have? Is it the number of developers working on the project?

23:26 Cristián Maureira-Fredes: I really don't know.

23:26 Michael Kennedy: I think that it's based on the developers. But I don't that well either. But there's a, if I want to build commercial applications, there's a path for that and if I want to build open source applications, there's a path for that.

23:26 Cristián Maureira-Fredes: Exactly.

23:26 Michael Kennedy: Okay, that sounds good. I guess, you know, you've touched on some of these things but maybe I'll just give you a chance to summarize it or bring anything we haven't mentioned yet. Where's this going? So end of the year, we're going to have Qt 5.12 with Python, Qt for Python out and things like that. Then what?

23:26 Cristián Maureira-Fredes: The future... The only restrictions that we currently have, the only constraint, is we would like to have more people on board about it because we have a lot of ideas but we don't have a lot of time as usual. So our number one, I think, task is the Qt Creator integrations. So to have a proper IDE to be compatible with Qt and then to be able to deploy the applications and try to have everything on the same ecosystem. Right, the designer and then build your UI files into Python files and everything. I think that's one of the high priorities. And this comes at the hands of all the deployment aspects that we want to cover. After that, it really will be depending on the users that we have. I mean we are really, really open about it. And every time on IRC we ask what do you think will be better for the next step, personally I would like to go into, after the Qt Creator and deployment, maybe for embedded systems because I have approached by many people who say I have an application and I really want to start to use Qt for Python, so please what do I need to do? So there are a lot of people doing this. And after that, after embedded systems, which is one of the strong features of Qt. I think that we can totally go to mobile because I think it is something that people are always asking for and currently we have developments of them onto smart phones that we get every day and everything. It is something that would be really nice to combine having your Qt desktop application but also on mobile tablets and phones and everything.

23:26 Michael Kennedy: I think if you guys can nail the deployment thing. I push a button and I have a macOS .app that I could give to people, that would be a game changer. Similarly, if you say I could push a button and heres the thing that I put in the iOS or Android app store on Google Play, also massively a game changer. I'm excited to hear this and I wish good luck on the journey because we all need it.

23:26 Cristián Maureira-Fredes: Yeah, thank you.

23:26 Michael Kennedy: Cool, well I think we pretty much covered the topic. I know there is a lot more we could go into but it's a good introduction for people. So, Qt for Python. I am so excited that you all are working on it. Let me ask you the two questions before you get out of here. If you're going to write some Python code, what editor do you use?

23:26 Cristián Maureira-Fredes: Vim, forever. I cannot get out of it. I initially recommend for people starting it to use services like Eric for example. The small IDE or VS Code, or PyCharm for example. I am really used to Vim so I cannot get out of it in all sense. So please if you know, help me. No, but it's my ecosystem so it's the only thing I require to do everything.

23:26 Michael Kennedy: Cool. So then, notable PyPi packages. Maybe not the most popular but one that you've come across and said, oh people should know about this.

23:26 Cristián Maureira-Fredes: Yeah, well of course PySide2.

23:26 Michael Kennedy: Of course.

23:26 Cristián Maureira-Fredes: But during my studies, I think that all the SciPy suite is something that was a must. I couldn't do anything without NumPy, matplotlib, all these things, so I am really trying to follow all the developments of data science, for example, or the Jupyter Notebooks. I think those are amazing for the Python community. And lately, I think the other day, I was listening to one of your podcasts and I discovered black for modifying the code and that was really a game changer.

23:26 Michael Kennedy: Yeah black is cool. And it was really really nice. Cool, those are definitely good ones. Alright, Christian, people are excited about Qt for Python. Final call to action, what do they do?

23:26 Cristián Maureira-Fredes: So okay, for the moment, you can go to your terminal and just pip install PySide2 and try all the examples we have inside. We are quite active in IRC. I personally promise that I will be there in working hours. But I try to answer all the questions. We have a lot of users since we started the first wheel set. So if you have any questions, just go on IRC and we will be there and also it is quite important now that by the end of the year, we have the Qt World Summit, which is the yearly event of Qt. A lot of people go there all the time, so the new users and everything. And we have two dates. One is in Boston, the 29th and 30th of October. We also have the same event in Berlin. So I will be giving a talk on Qt for Python, which is called Mastering Qt for Python in 20 Minutes. So if you really want to go to these events, maybe later you can share the link or something. I think they are really nice events to know about Qt for Python and Qt in general.

23:26 Michael Kennedy: Yeah, those are great. Are you going to be at PyCon 2019?

23:26 Cristián Maureira-Fredes: Ah, no. I didn't have chance to go there. But no, I am totally planning to go there for next year because since the release was this year, we wanted to go there and try to talk once the product is out right? Yeah, I think that we will give it try next year to try and maybe go to a couple of PyCons in the US, if we can, and Euro Python maybe here in Europe.

23:26 Michael Kennedy: Excellent, well I hope to see you there and definitely maybe your conferences, the Qt world summit sounds interesting as well. So thank you so much. I really appreciate you being on the show and keep up the good work. I can't wait for that build deploy button.

23:26 Cristián Maureira-Fredes: Thanks as well. It was really a pleasure to be here. And yeah, we are looking forward to it also. Stay tuned.

23:26 Michael Kennedy: Alright, talk to you later.

23:26 Cristián Maureira-Fredes: Thank you very much, bye.

23:26 Michael Kennedy: This has been another episode of Talk Python to Me. Our guest on this episode has been Cristián Maureira-Fredes and its been brought to you by Linode and Rollbar. Linode is bulletproof hosting for whatever your building with Python. Get four months free at talkpython.fm/linode, that's L-I-N-O-D-E. Rollbar takes the pain out of errors. They give the context and insight you need to quickly fix errors that might have gone unnoticed until your users complained, of course. Track a ridiculous number of errors for free as Talk Python listeners at talkpython.fm/rollbar. Want to level up your Python? If you're just getting started, try my Python Jumpstart by Building 10 Apps or our brand new 100 Days of Code in Python. And if you're interested in more than one course, be sure to check out the everything bundle. It's like a subscription that never expires. Be sure to subscribe to the show. Open your favorite pod catcher and search for Python. We should be right at the top. You can also find iTunes feed at /iTunes. Google Play fee at /play. And direct RSS feed at /rss on talkpython.fm. This is your host Michael Kennedy. Thanks so much for listening. I really appreciate it. Now get out there and write some Python code.

Back to show page