Share
Embed
Python Desktop Application Development
Slides of the Python Desktop Application Development Talk @ The Brainport Eindhoven Python Meetup Group Meeting #2
(http://www.meetup.com/Brainport-Python-Meetup-Group/events/206346802/)
Summary: http://reinout.vanrees.org/weblog/2014/11/11/python-desktop-development.html
Therry van Neerven
November 11, 2014
Transcript
20 slides
-
Python Desktop Application Development Therry van Neerven The Brainport Eindhoven
Python Meetup Group Meeting #2 9-11-2014 -
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. -
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. -
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. -
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) -
GUI frameworks • Tkinter • WxPython (WxWidgets) • PyQt, PySide
• PyGTK • Kivy https://wiki.python.org/moin/GuiProgramming -
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. -
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! -
“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. -
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. -
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/ -
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 -
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. -
The good and the bad of the application + It
works! + Very interesting experience - Cross platform compatibility - Maintainability -
How it can be done better. “Do things that can’t
be done from within a browser like printing without a dialog.” -
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. -
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) -
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 -
More info, help, support or a job: [email protected] http://www.github.com/Ecno92/ http://www.github.com/SendCloud/
https://www.sendcloud.nl/jobs