Slide 1

Slide 1 text

Python Desktop Application Development Therry van Neerven The Brainport Eindhoven Python Meetup Group Meeting #2 9-11-2014

Slide 2

Slide 2 text

Where is the presentation about? • My journey of building the SendCloud Client. • The frameworks and tools that I’ve used and some of the inner workings. • How I would do it differently the next time.

Slide 3

Slide 3 text

The SendCloud Client • A tool which allows you to scan invoices and packing slips in order to get the right label for the postal package right out of your printer within a few seconds.

Slide 4

Slide 4 text

Motivations to build a desktop application • A high performance (user interface). • The native look of the OS. • Do things that can’t be done from within a browser like printing without a dialog.

Slide 5

Slide 5 text

Motivations to build a desktop application in Python. • I wanted to learn more about Python. • Python allowed me to work quickly. • There are a lot of libraries available which allowed me to integrate features very fast. (Requests, PyWin32, PyUSB)

Slide 6

Slide 6 text

GUI frameworks • Tkinter • WxPython (WxWidgets) • PyQt, PySide • PyGTK • Kivy https://wiki.python.org/moin/GuiProgramming

Slide 7

Slide 7 text

GUI frameworks Interesting ones PyQt/PySide + Active development (PyQt, PySide is behind.) + Many features including like printing, webkit view etc. - PyQt requires some licensing costs when releasing commercially. Kivy + Android, iOS and all major desktop platforms + Build on PyGame (OpenGL), MIT license and “innovative UI” oriented. - Less features included and not native looking.

Slide 8

Slide 8 text

Tutorials on how to build apps Kivy Pong game: http://kivy.org/docs/tutorials/pong.html Building a tekst editor with PyQt: http://www.binpress.com/tutorial/building-a-text-editor-with-pyqt-part-one/ Various GUI related tutorials (older, but nice to start with): http://zetcode.com/ Get your hands dirty!

Slide 9

Slide 9 text

“Freezing” your application • You compile your Python scripts to bytecode. • Put them in a (zip) folder. • You append the zip folder to a Python Interpreter. • You place the Python Interpreter in a folder where it can find all the other dependencies like Qt and your funny kitten images.

Slide 10

Slide 10 text

Freezing packages • CX_Freeze • Nuitka (C++ Compiler with freezing options. It can hide your code better) • Py2exe (Site is outdated, but https://pypi.python.org/pypi/py2exe/ seems to be active again) • WARNING: Freezing may be difficult, always start with a small project.

Slide 11

Slide 11 text

Cross platform building • Freezing is very similair on every platform. (Mobile excluded) • However you need to freeze the package on the same OS as the target OS. • Virtual machines! (Vagrant) • Script your build process. You will build your app very often! • Wine(Bottler) may work. • http://pyvideo.org/video/958/deep-freeze-building-better-stand-alone-apps-wit • https://www.vagrantup.com/

Slide 12

Slide 12 text

Installers and updating the app Installers (Windows): • Inno Setup • NSIS • Pynsist (Install Python and your app without having to freeze) Updating: • Simple: Create a new installer for every build. • Esky http://www.jrsoftware.org/isinfo.php http://nsis.sourceforge.net/Main_Page https://pypi.python.org/pypi/esky https://github.com/takluyver/pynsist

Slide 13

Slide 13 text

Hints and tricks • Choose the GUI framework that fits your needs. Frameworks like Qt are very powerful, but also very complicated when you want to do more advanced tasks. • Automate the things you do very often. Makefiles or small Python scripts can save you hours of typing and clicking. • Not every framwork or package is mature. Discuss the issues you have on GitHub and StackOverflow.

Slide 14

Slide 14 text

The good and the bad of the application + It works! + Very interesting experience - Cross platform compatibility - Maintainability

Slide 15

Slide 15 text

How it can be done better. “Do things that can’t be done from within a browser like printing without a dialog.”

Slide 16

Slide 16 text

Modern web apps are awesome. • AngularJS, Knockout, EmberJS allow you to make high quality front-end interfaces. • JavaScript, HTML, CSS. My collegues know about this! • “For Mozilla, anything that the Web can’t do, or anything that the Web is not faster and better at than native technologies, is a bug.” – Andreas Gal, CTO Mozilla.

Slide 17

Slide 17 text

The browser can do many things, but not everything…

Slide 18

Slide 18 text

Webbrowser – local server Webbrowser (AngularJS App) Desktop Application With REST API or Websocket based RPC Online server Online Local https://blabla.com/cool_api/* ws://127.0.0.1:8080/ws Action: Print Document x Get Document x as Base64 Encoded String session.call(‘com.blabla.pinter’, base64_encoded_document).then(…); Python magic to print the document with Qt http://crossbar.io (Wamp, WS implementation) http://doc.qt.digia.com/solutions/4/qtservice/qtservice-example-server.html (Simple HTTP server) http://flask.pocoo.org/ (Web microframework)

Slide 19

Slide 19 text

Embedded webbrowser options • Qt Webkit • Not the newest version. • You can link Qt signal and slots to JavaScript. • Chrominium Embedded Framework • Embed a version of “Chrome” in your app. • Complicated and not mature yet for Python. https://code.google.com/p/cefpython/ http://qt-project.org/doc/qt-4.8/qtwebkit-bridge.html

Slide 20

Slide 20 text

More info, help, support or a job: [email protected] http://www.github.com/Ecno92/ http://www.github.com/SendCloud/ https://www.sendcloud.nl/jobs