Live data from Hacker News

PyQt5 Tutorial: Create a Python GUI in 2018

build-system.fman.io

171–180 of 211 posts

Re: PyQt5 Tutorial: Create a Python GUI in 2018

#171
post #167

Earlier quoted context omitted.

Really good? Platform-native APIs.

Agreed, but you can use those from Python, through pywin32 and (for a few rare things that are missing in the former) ctypes. (If you're on Windows. On Linux, Qt could be considered native. On Mac there is PyObjC. )

Pywin32 to call native apis for GUIs sounds very, very painful. I had a few run-ins with pywin32 and COM automation, I don’t think I could bear the thought of developing a full UI with that sort of hacks. At that point, might as well go C# (or IronPython, if it’s still around) and enjoy the VS goodies.

Re: PyQt5 Tutorial: Create a Python GUI in 2018

#172
post #168
post #155

Earlier quoted context omitted.

I don't consider connecting signals in xml (via designer) better than connecting them in code. The line is still there, just in different place.

But the UI changes very rarely, and it’s out of the way most of the time; whereas the class method is always in the way in parts of code that could see a lot of day-to-day activity, migrations (py3...) and so on.

On the other hand refactoring is much easier if all your signals are connected in code.

Re: PyQt5 Tutorial: Create a Python GUI in 2018

#173

We use Qt heavily at Starsky Robotics. We initially used it because it has tight integration with ROS via RQT [1], but I'm pretty impressed with the framework in general. Lots of great tools out of the box, QtCreator is awesome and once you get the right signal/slot model in your head everything is a breeze. Plus getting to prototyping in python is always fast! For our use case, relative speed of the GUI isn't a fact…

I'm presenting QGIS-ROS at ROSCon this year. It's a QGIS plugin for integrating real time robot data. Was relatively easy to do thanks to QGIS being Qt 5.

Felt exactly like making a RQT plugin.

Re: PyQt5 Tutorial: Create a Python GUI in 2018

#174
post #171
post #167

Earlier quoted context omitted.

Agreed, but you can use those from Python, through pywin32 and (for a few rare things that are missing in the former) ctypes. (If you're on Windows. On Linux, Qt could be considered native. On Mac there is PyObjC. )

Pywin32 to call native apis for GUIs sounds very, very painful. I had a few run-ins with pywin32 and COM automation, I don’t think I could bear the thought of developing a full UI with that sort of hacks. At that point, might as well go C# (or IronPython, if it’s still around) and enjoy the VS goodies.

COM might have its issues, but I meant using the win32gui, win32api etc. modules to call the native win32 C API for UI. That's hardly a hack, and perhaps even slightly less painful than doing it from C. (I'm only using it for some fairly small things, though.)

Re: PyQt5 Tutorial: Create a Python GUI in 2018

#176
post #129

Earlier quoted context omitted.

The API still looks messy and unpythonic though, sadly. Look at the basic hello world example. Why do I need to pass QApplication an empty array? Why am I calling a method ending with _ to launch the program? And the fact the label magically attaches to the app through some side effect is also confusing. Does anyone know if there's any good shim/wrapper around PyQt that has a better API?

Maybe it's not pythonic but I can assure you, after having passed 6 years working with it that it's extremely efficient and very well integrated with python. It just works, and a complaint about aesthetics won't change that :-)

I second that. Maybe the interface isn't very Pythonic, but it's very Qt-ic, if that's a word. The behavior of PyQt hews closely to the behavior described in Qt's excellent C++ documentation. Furthermore, PyQt lets you do things that you may take for granted, like connecting signals to Python functions and subclassing Qt Widgets. And not only can you subclass a Qt Widget, you can override its methods. Also, you can send a Python str to any method that accepts a QString. I could go on and on about how the boring stuff stays pleasantly boring.

Having used much worse Python bindings for other C++ libraries, the degree to which PyQt just works without blowing up in your face is itself pretty astonishing. Add to that the maturity and depth of the Qt Widget library, and the result is a real pleasure to use.

Re: PyQt5 Tutorial: Create a Python GUI in 2018

#177
I recently went through almost the exact same exercise (use PyQt5 to write a desktop program that would wrap our warehouse management system's web interface with QtWebKit and - upon receiving a specific download - call out to the REST API for a separate shipping system to book a shipment and print the shipping label). I was developing on Linux (I use Slackware day-to-day), but the pack stations at our warehouses run Windows 10, so it needed to be cross-platform.

The Linux side was surprisingly painless, but getting the Windows side going was a nightmare; none of the traditional options for creating a standalone Windows executable actually worked, and I ended up resorting to installing MSYS2 on every machine, then packaging the app for MSYS2 (and pulling in all of Qt5 as a dependency, meaning that it takes up multiple gigabytes of space for what should be a pretty simple desktop app).

I didn't know about fbs. I'm gonna try it out tonight. The fact that it seems to require resulting apps to be under the GPL is unfortunate, but that's already the case for PyQt5, so whatever.

Re: PyQt5 Tutorial: Create a Python GUI in 2018

#178
post #129

Earlier quoted context omitted.

The API still looks messy and unpythonic though, sadly. Look at the basic hello world example. Why do I need to pass QApplication an empty array? Why am I calling a method ending with _ to launch the program? And the fact the label magically attaches to the app through some side effect is also confusing. Does anyone know if there's any good shim/wrapper around PyQt that has a better API?

Maybe it's not pythonic but I can assure you, after having passed 6 years working with it that it's extremely efficient and very well integrated with python. It just works, and a complaint about aesthetics won't change that :-)

My first foray with Qt was also my first (serious) foray with Python, so it was easy for me to ignore pythonicity and just write something that approximately resembles Qt's existing style.

Knowing some of my coworkers, though (who use Python daily), I can understand why it'd be jarring.

Post reply on HN