Stream processing in python, especially for UIs.
GUIs in python are a mess.
IO loop evented asynchrony
Modern python async-style stuff.
tl;dr Use the event loop from tornado or pyzmq. These non-thread IO things are very easy and comparatively well-documented. And they work with the new python 3 async style. You can use them to farm off heavy computation to other threaded nightmare hell farms or whatever, and they work now.
Here are some ingredients that might make these work better:
sanic is a hip, python3.5+-only, Flask-like web server. Supports websocket and graphql extensions. Check datasette for an example of integrating threading loops (asyncio.get_event_loop().run_in_executor()) See also aiohttp which is the same but runs on python 3.4.2+
terminado provides a terminal for tornado, for quick and dirty interaction.
This feels over-engineered to me, but looks easy for some common cases.
Web toolkits talking to python servers
One obvious usecase for all this evented stuff is to use the great mind-share of our time, web engines talking to servers, to do UI stuff.
Thrust renders a chromium window to look at your served code. I’m not 100% clear how it it easier than just running a browser and a server.
GUI toolkits using threads
tkinter is well-worn and sturdy dating back to the 90s. It’s a wrapper around the tcl gui toolkit, called tk. If you want to make something simple, it’s not too bad.
It can integrate with tornado.
Beware of the many renames between python 2 and 3.
It looks primitive, but you can get a long way.
- dynamic collapsible content:
def toggle(self): if bool(self.show.get()): self.sub_frame.pack(fill="x", expand=1) self.toggle_button.configure(text='-') else: self.sub_frame.forget() self.toggle_button.configure(text='+')
- snake, including sprites and canvas with collision detection.
- tkdocs is an incomplete but pretty good book on tkinter, also explaining the perl and ruby versions
- effbot tkinter guide is good and differently incomplete and slightly outdated.
- See Tkinter example for controlling a robot
- NMT Tkinter reference is in-depth but outdated.
- The official tk docs are complete, but referencey and written for tcl rather than python.
- the official python tkinter docs are fine but especially partial.
- For sorta-native look and feel you use ttk which introduces styles and themes. Neither of these are obvious.
- Control variables provide convenient data-syncing accessors for what I will loosely call “scalar types”. Think of them as primitive controllers.
- There are two layout managers, pack and grid. If you come from an HTML background the former is somewhat like a mildly crippled version of block-layout and the latter somewhat more like HTML tables. You can’t mix them within a single parent widget, but you can freely next Frame widgets with different interior layouts.
Want a somewhat more modern look, and modern conveniences. Qt5 is, by all accounts, pretty good. The dman language bindings keep changing though, and betwixt qt5 and qt4 lies a chasm which many projects have failed to cross. For QT directly apparently one should use pyotherside? Although I now see people using qtpy as a unifying abstraction layer over all the other unifying abstraction layers. Maybe if I do that the pain will go away.
To ease this pain and make everything even easier, perhaps one should use one of the mildly hip meta-frameworks, such as enaml, which handles asynchronous widget binding and such, and enaml-native, whcih attempts to create mobile-friendly react-native-esque applications.
Hip, multitouch, GPU-friendly, mobile-friendly (and a little bit retro in the design style if not the technologies) kivy, a complete app environment.
Bizarre crossovers of Web GUIs and user interfaces
In this howto, I explain the following concepts:
- How to launch a GUI toolkit in a separate thread, and how to communicate with this thread.
- How to embed a web browser inside the GUI, and how to communicate with this embedded web browser without using sockets. By not using sockets, we don’t have to worry about socket security, and we don’t have to worry about allocating a socket. […] In other words, we will have AJAX-like […] functionality to communicate with Python but without actually having to use AJAX.