Any guidelines to develop a Qt UI with Pyside? - python

I'm new to Qt and Pyside, and confused with lots of dazzling concepts and tools.
Instead of using IDE provided, I prefer to vim.
So I wonder what the generic guideline is. That is to say, what're the QML, Qt Creator, Qt Designer? Do I need to use all of them? And what's the normal workflow?
And at last, there're few tutorials about Qt in python, so can I invoke the Qt C++ docs for help (any big differences between C++ Qt programming and Python one)?

I wrote some PyQt based tutorials after leaving my last job, they can apply to PySide also and have some helpful tips in there too: http://bitesofcode.blogspot.com/
I agree you don't need QML or Qt Creator - but using the Qt Designer for building your interfaces would definitely be the way I would recommend going about it.

I make GUIs in a text editor, right in the Python program. You don't have to use QML, Qt Creator. Just read the Jan Bodnar's PySide tutorial and then you'll be able to figure out the rest by yourself, by looking at PySide or C++ Qt documentation

Related

Can I leverage the Qt Meta-Object system in PyQt like I can in PythonQt?

I know in PythonQt I can access MOC'd QObject based classes in Python code and that python code can be executed from C++. Is it possible to do something similar using PyQt or is it intended to be used only to write Qt in Python?
I understand SIP is used to expose C/C++ code to Python but that doesn't seem to be as elegant as using the meta-object system.
I have never used PythonQt, but after a brief skim of the features, it seems that, in terms of conceptual emphasis, it really should have been called QtPython.
PyQt started life as a tool for prototyping Qt C++ applications in python. As a consequence, it was originally a very thin wrapper around the Qt library, which made it almost trivial to port Qt code from python to C++ and vice versa. And it still is quite easy to do this. But since PyQt4, the emphasis has shifted strongly towards making it easier to write Qt applications in Python; and with PyQt5, it has moved even further in that direction.
So PyQt is now intended purely for writing Qt applications in python (and the same goes for PySide). It does not provide any facility for executing python code within C++ (other than indirectly via virtual functions). If you need to expose third-party Qt classes to python, you would need to wrap them using Sip.
As for the meta-object system: PyQt does wrap QMetaObject and so forth, but there is not enough information in your question to know whether that would be of any use to you.

LGPL or similar GUI toolkit for Python3 and above

I've been using Python 3 for some months and I would like to create some GUIs. Does anyone know a good GUI Python GUI framework I could use for this?
I don't want to use TkInter because I don't think it's very good. I also don't want to use PyQt due to its licensing requirements in a commercial application.
First of all, I suggest you to stay with Python 2.x if you want to develop commercial products at this moment.
This is because it is still the most widely available version of Python.
Currently, Ubuntu ships with 2.7.2 and OS X Lion with 2.7.2, too.
Regarding PyQT, you can use Nokia's re-implementation of it, PySide. It is under LGPL, so yes, you can create commercial products. Moreover, QT also transitioned to LGPL. See QT License here.
Update: Additionally, support for Python 3.x is still under development for many GUI frameworks, PySide included.
Hummm. . . .
Hard to believe that Qt is forbidden for commercial use, as it has been created by some of the most important companies in the world . . . http://qt.nokia.com/
Go for pyQt ;)
You probably mean that PyQt can only be used for GPL projects. However, the equivalent PySide Python bindings for QT are LGPL, like QT itself, so you can use those; unfortunately, they only support Python 2.5/7 at the moment.
If you don't mind being cross-platform, you can fall back on the win32api stuff (bleh), or go the hybrid way with Jython (which supports Swing as well as any other Java-based toolkit) or IronPython (which uses .Net).
Pyside might be the best bet for you :
http://www.pyside.org/
It is basically Qt but under the LGPL license, which means you can use it in your commercial application.
Well, If you feel Qts is not suitable(thats hard to belive either) you could switch to
WxPython . It too has an good learning curve and can satisfy your commersial needs

PyQt Designer where to write code?

I have PyQT v.4.8.8 installed.When I draw layouts and I want to view the code , it comes with error that is unable to launch uic as in snapshot:
I can compile the .ui files manually in cmdLine. But I dont know where to put the code for slot,methods ,signals.
1- Where should I set the settings for finding uic to compile ui? My installation does not have pyuic4.
2 - Where can I define my own slots/methods and functoins signatures ? (receiver object,sender) I can see the Edit signals/slots in edit menu but that only shows standard signals/slots.Doesn't have options to define yours.
As the name says, the Qt designer is for interface design only. You cannot use it to write the code for the actual application logic. For this, you'll need a normal Python editor. The exact details on how to use designer files in Python are explained in PyQt reference guide, Using Qt Designer.
Btw, uic is not for PyQt, but for compiling user interfaces into C++. To compile user interfaces to Python, you need to use pyuic4. This tool cannot be run from the designer, you need to run it manually. But it is recommended to load the user interface dynamically at runtime using the PyQt4.uic modules as explained in the reference guide.
I found this tutorial for PyQt4 explaining how to add your own slots in Qt4.Very informative.

Python GUI(tkinter; pygtk+glade), py2exe

I'm new with python programming and GUI. I search on internet about GUI programming and see that there are a lot of ways to do this. I see that easiest way for GUI in python might be tkinter(which is included in Python, and it's just GUI library not GUI builder)? I also read a lot about GLADE+PyGTK(and XML format), what is there so special(glade is GUI builder)?
Can anyone make some "personal opinion" about this choices?
I have python code, I need to make simple GUI(2 button's-open-close-read-write,and some "print" work) and then make some .exe file (is there best choice py2exe=?). Is there a lot of changes in code to make GUI?
Many thanks
If your GUI is really that simple, you should go with the built-in tkinter.
There's a Hello, Tkinter tutorial that you can follow, it's pretty straightforward. Concerning the creation of executables, py2exe should work without problems in most cases (though I haven't tried with tkinter). Another way to create an executable is to add a special parameter to your "setup.py" file:
setup(...,
entry_points = {"gui_scripts" : ['name-of-executable = name_of_package.launcher:main']})
This would, for example, create an executable that can be run by typing "name-of-executable" into a terminal (even on Windows if Python's "scripts" path is in the PATH ^^). It runs the function "main" in the module called "name_of_package". That way, you don't have to use py2exe but can create a Windows installer, or a Debian package, for instance.
For more complex projects, I can absolutely recommend PyGTK with Glade as interface designer. It requires several Python packages to be installed, plus a GTK+ installation (which is not always that easy on Windows). The API is awesome, well-documented and Glade is very easy to use, once you get used to the layouting concepts of GTK. But my opinion is kind of biased because I've done multiple projects in PyGTK. wxWidgets or PyQT are good alternatives. For example, bazaar explorer is written using QT.
I really like PyQt bindings for Qt library.
What is PyQt?
Qt itself is a very nice framework - rich, powerfull, elegant (for my taste, at least). And PyQt does a very nice job of exposing that functionality to a scripting environment.
Plus, there is a very nice book about PyQt development - Rapid GUI Programming with Python and Qt - working through it helped me a lot.

Python - Best GUI library for the job?

I've been using WxPython and I've tried Tk, but it seems that, while both are good and I'll likely use them for other projects, neither of those appear to be capable of accomplishing the things that I want for my current project (which is fine, they're good at what they do).
Basically what I'm looking for is something that will allow me to make rich graphical GUIs. My specific goal is a window that will draw bitmap buttons, resize the parent window automatically to fit them, and possibly animate the resize with a slide effect and have the buttons fade in. Also being able to have my own window border style instead of the inbuilt one is important to me.
This particular project will be Windows only, so non-portable libraries are fine in this case, though portable ones would be great too.
If I missed how this can be done in either WxPython or Tk, I'm all ears.
PySide: http://www.pyside.org/
The PySide project provides
LGPL-licensed Python bindings for the
Qt cross-platform application and UI
framework. PySide Qt bindings allow
both free open source and proprietary
software development and ultimately
aim to support all of the platforms as
Qt itself.
The Windows version of PySide is quite new and may be considered as a beta version. PySide is API compatible with PyQt.
How about PyQt?
http://www.riverbankcomputing.co.uk/software/pyqt/intro
Just sharing my opinion: Kivy.
Innovative open-source library. Supports both 2.x and 3.x versions of Python.
Kivy - Open source Python library for rapid development of applications
that make use of innovative user interfaces, such as multi-touch apps.
Kivy is based on OpenGL ES 2 and includes native multi-touch for each platform and Android/iOS. It’s an event-driven framework based around a main loop, and is thus also suitable for game development.
Try Pyglet. Its a library for python that makes using OpenGL very easy. You can draw pretty good 2d interfaces using Quads.
I can't tell you what is best because that is subjective but I can give you another option: PyGTK
PyGTK lets you to easily create programs with a graphical user interface using the Python programming language. The underlying GTK+ library provides all kind of visual elements and utilities for it and, if needed, you can develop full featured applications for the GNOME Desktop.
PyGTK applications are truly multiplatform and they're able to run, unmodified, on Linux, Windows, MacOS X and other platforms.

Categories