|
| 1 | +# Introduction |
| 2 | + |
| 3 | +This book is about creating dialogs for Desktop applications with Python 3, PyQt 5 and Qt Quick. |
| 4 | + |
| 5 | +Last year, after having watched [Introduction to Qt Quick Controls in Qt 5.1](https://www.youtube.com/watch?v=_6_F6Kpjd-Q) on YouTube I got very excited and loved the idea of being able to mock dialogs and applications with an harmonius mixture of pseudo JSON and Javascript. |
| 6 | + |
| 7 | +Having being involved in the development of Scribus for the past ten years, I dreamed of designers squeezing their Javascript skills to send us interactive mockups that only required to be rewired to the Scribus code for being integrated into our source code. |
| 8 | +While this has yet to happened, this manual is part of the first step to get a new Scripter engine into Scribus that will allow us to integrate in the Scribus UI, Python scripts combined with Qt Quick dialogs. |
| 9 | + |
| 10 | +The path was steeper than I would have thought. On the one side, the move from Qt Quick 1 to Qt Quick 2 has made a lot of tutorials and snippets you can find on the internet slightly outdated: they are familiar enough, so that you get the fealing they might solve your problem, but result in code that fails with error messages that are not helpful enough to bring you on the right path. |
| 11 | + |
| 12 | +- http://stackoverflow.com/questions/15406002/does-python-go-well-with-qml-qt-quick |
| 13 | + |
| 14 | +# Requirements |
| 15 | + |
| 16 | + |
| 17 | +For enjoying this book you should have: |
| 18 | + |
| 19 | +- A text editor or Qt Creator. |
| 20 | +- A computer with Python, PyQt 5 and the Qt Quick 2.X modules installed. |
| 21 | +- Basic Python programming skills. |
| 22 | +- Some knowledge about what Qt 5 is and what signals and slots are. |
| 23 | + |
| 24 | + |
| 25 | +TODO: And if you don't already have the required skills, a few links that can help you getting on track |
| 26 | + |
| 27 | +# PyQt 5 |
| 28 | + |
| 29 | +- http://pyqt.sourceforge.net/Docs/PyQt5/index.html |
| 30 | + |
| 31 | +# QML and Qt Quick |
| 32 | + |
| 33 | +- [A nice example of QML file](https://github.com/ioriayane/KanmusuMemory/blob/master/qml/KanmusuMemory/TimerSetting.qml) |
| 34 | + |
| 35 | +# Qt Creator or a text editor |
| 36 | + |
| 37 | + |
| 38 | + |
| 39 | +# Your first dialog |
| 40 | + |
| 41 | +Create a first dialog, that simply shows a button that you can click to quit: |
| 42 | + |
| 43 | +[%source%main.qml](examples/your-first-dialog/main.qml) |
| 44 | + |
| 45 | +You can preview the dialog with the `qmlviewer` : |
| 46 | + |
| 47 | + $ qmlviewer main.qml |
| 48 | + |
| 49 | +The minimal code that allows you to show the QML window with PyQt: |
| 50 | + |
| 51 | +[%source%dialog.py](examples/your-first-dialog/dialog.py) |
| 52 | + |
| 53 | + $ python dialog.py |
| 54 | + |
| 55 | + |
| 56 | +# Column and rows |
| 57 | + |
| 58 | +[%source%dialog.py](examples/your-first-dialog/dialog.py) |
| 59 | + |
| 60 | + $ qmlviewer columns.py |
| 61 | + |
| 62 | +# The basics of the dialog items |
| 63 | + |
| 64 | +## Push Buttons |
| 65 | + |
| 66 | +## Groups |
| 67 | + |
| 68 | +## Radio Buttons |
| 69 | + |
| 70 | +## Combo Boxes |
| 71 | + |
| 72 | +- http://qt-project.org/doc/qt-5/qml-qtquick-controls-combobox.html |
| 73 | + |
| 74 | +## Scrollable Lists |
| 75 | + |
| 76 | +This is TableView |
| 77 | + |
| 78 | +- http://qt-project.org/doc/qt-5/qml-qtquick-controls-tableview.html |
| 79 | + |
| 80 | +# Pure Javascript Mockups |
| 81 | + |
| 82 | +## Properties |
| 83 | + |
| 84 | +Further reading: |
| 85 | + |
| 86 | +- http://qt-project.org/doc/qt-5/qtqml-syntax-objectattributes.html |
| 87 | + |
| 88 | +## Models |
| 89 | + |
| 90 | +# Communicating between Python and QML |
| 91 | + |
| 92 | +- http://qt-project.org/doc/qt-5/qtqml-cppintegration-exposecppattributes.html |
| 93 | + |
| 94 | +## Signals from Qt Quick to Python |
| 95 | + |
| 96 | +## Sending values from Python to Qt Quick |
| 97 | + |
| 98 | +## Python Models for Qt Quick |
| 99 | + |
| 100 | +Models have to be passed as an attribute before the `.qml` file is read. |
| 101 | + |
| 102 | +TODO: find out how to use classes as models. |
| 103 | + |
| 104 | +- http://qt-project.org/doc/qt-4.8/qdeclarativemodels.html |
| 105 | +- http://qt-project.org/wiki/Filling-and-reading-QML-UI-forms-from-Python |
| 106 | + |
| 107 | +# The standard dialogs |
| 108 | + |
| 109 | +## Message dialogs |
| 110 | + |
| 111 | +## Input dialogs |
| 112 | + |
| 113 | +## File Open dialogs |
| 114 | + |
| 115 | +## File Save dialogs |
| 116 | + |
| 117 | +# Packaging |
| 118 | + |
| 119 | +## Windows |
| 120 | + |
| 121 | +TODO: digest this thread from the PyQt mailing list |
| 122 | + |
| 123 | +> py2exe generated a folder with a lot of dll files, but it didn't include the necessary plugins, copying the contents of the plugins/ directory into the executable's directory seems to have helped (no longer getting a message that qt's windows plugin is missing) but now the application simply crashes as soon as it starts. The error message it displays is an uninformative "program.exe stopped working". I tried to run the executable from the commandline in the hopes of catching some output telling me what I did wrong, but nothing was displayed. |
| 124 | +
|
| 125 | +> We're deploying PyQt5 on Windows with the help of `cx_Freeze`, which works really well in our experience. I think we have to copy QtSql plugin files though IIRC. Try it, it's easy. |
| 126 | +
|
| 127 | +# Installing Python, PyQt 5 and Qt Quick |
| 128 | + |
| 129 | +TODO: add links to How-tos |
| 130 | +TODO: eventually, show how to get it to work in some Linux distributions and promote Virtualbox |
0 commit comments