GUI design with Python – examples from crystallography. Bernhard Lohkamp Karolinska Institute Stockholm Sweden. Coot - Who are we – why am I here?. Paul Emsley (Oxford; everything). Bernhard Lohkamp (Stockholm; Python, GUI, Windows). Kevin Cowtan (York;
01 / 78GUI design with Python – examples from crystallography
1 / 17
Télécharger la présentation
GUI design with Python – examples from crystallography
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation
Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement.Téléchargez la présentation en cliquant sur ce lien.Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.
Coot - Who are we – why am I here? Paul Emsley (Oxford; everything) Bernhard Lohkamp (Stockholm; Python, GUI, Windows) Kevin Cowtan (York; crystallographic libraries & tools) Eugene Krissinel, Stuart McNicholas, and others... Bernhard.Lohkamp@ki.se
COOT • Graphical (Crystallographic-Object)-Oriented Toolkit • Used in macromolecular (X-ray) crystallography • Main aims: • Model building • Model completion • Model validation • Graphical, interactive, intuitive, … Bernhard.Lohkamp@ki.se
G(raphical) U(ser) I(nterface)GUI <-> UI • Allow end users to interact with application • Interface can be simple (e.g. command line) to complex (graphical) • Good UI: • Intuitive • Easy to use/learn • Note: applications with good UI are preferred to ones with inferior ones (independent of quality of application!?) Bernhard.Lohkamp@ki.se
GUIs • Good things about GUI • Intuitive (if designed properly) • More efficient (e.g., putting the cursor at a particular location) • Multiple activities simultaneously • Bad things about GUI • Inefficient (if mis-designed) • Difficult to automate (e.g. difficult to write a program to push a button in another application) • Speed Bernhard.Lohkamp@ki.se
The challenge of GUI programming • programming model must address the following issues: • user allowed to perform different things (e.g. type a character, type a hot-key, click on a button, resize the window, obscure the window with another application, minimize it, etc.) • program needs to adapt to different window size (and with it all its content) • Solution: • event-driven model • widget systems (controlled by a geometry manager) • Use Toolkits == TK Bernhard.Lohkamp@ki.se
Windows manager/Desktop Forms of interactionevents in context • Human Interface Device (HID) control Bernhard.Lohkamp@ki.se
Windowing system/hierarchy • Lots of layers • Not very efficient • Slow (not necessary to be fast?!) Bernhard.Lohkamp@ki.se
Connect GUI with Python • Direct via script • GUI design tools and IDEs (Integrated Development Environments) • GUI builder • GUI to build a GUI application • Useful especially for larger projects • Output usually xml • Use directly • Translate to Python script Bernhard.Lohkamp@ki.se
GUI modules for Python (I)(Toolkits, cross-platform) • PyGTK (Gnome): Coot • TK: GTK+ (GIMP Tool Kit) • Well supported • Builder (Glade) • xml direct • Not native on Mac (yet) • PyQt (KDE): CCP4mg – molecular graphics • TK: Qt (“cu-te”) • Licence issue? • Native • Builder (Designer) • xml->python Bernhard.Lohkamp@ki.se
Nomenclature/Widgets • Widget: “windowing gadget”, which means “a useful building block (gadget) to make a windowing system”. • Hierarchy (exemplified): Bernhard.Lohkamp@ki.se
Widget examples • Top level (independent widgets): • Main window • Various (pre-defined) dialogs Bernhard.Lohkamp@ki.se
Dialogs (I) • Info (Message) dialog • Dialog box Bernhard.Lohkamp@ki.se
Dialogs (II) • About dialog • Assistant Bernhard.Lohkamp@ki.se
Canvas • Drawing area • Canvas/cairo drawing (e.g. PyGoocanvas) • OpenGL drawing (e.g. PyOpenGL, PyGtkGLExt) • Can be interactive Bernhard.Lohkamp@ki.se
Tooltips • Pop ups with text (upon mouse over) • Helps to explore the GUI without reading help files • Use whenever you can (!?) Bernhard.Lohkamp@ki.se
GUI designWhat makes a good UI? • Simple • Intuitive • Respects the commonly accepted conventions • Visually organized • Native look Bernhard.Lohkamp@ki.se
Designing UIs • Two levels: • Graphical: visual aspect • Events: Functionality • Basic blocks = widgets • Making an application react to events = binding Bernhard.Lohkamp@ki.se
General concepts • Main loop and events • Packing • Showing • How to do. Bernhard.Lohkamp@ki.se
Main loop and events • TK mainloop: • Event loop • Idle until an event happens (e.g. a button is pushed, a menu is pulled, etc.) • Quit when program (GUI) finishes • Can have multiple loops (count!!) • PyGTK: gtk.main() • TKinter: tk.mainloop() • PyQT: application.exec_() Bernhard.Lohkamp@ki.se
Main loop and events • Events (examples): • Keyboard (key-pressed, key-released) • Mouse (button-pressed, button-released, motion, wheel, …) • Window/widget (resize, destroy, visibility, activate, deactivate, …) • Etc. • Event modifiers (Shift, Alt, …) • Events emit signals • Can be connected with callbacks (functions, methods) Bernhard.Lohkamp@ki.se
Synergy between objects and widgets • Variables are passed automatically within class • refer to them as self.whatever • No need to pass variables • Callback functions • Easy to handle • No need to define callbacks on the fly (lambda functions) Bernhard.Lohkamp@ki.se
Packing • Homogeneous (equal space for everyone) HBox(True/False, 0) • Expand, fill box.pack(expand=, fill=) Bernhard.Lohkamp@ki.se
Showing • Widgets itself do not show (neither do they do anything else -> connect signals!) • Need to show every (!) widget • Can hide widgets • Usually collective show for all • PyGTK: widget.show() widget.hide() widget.show_all() • Tkinter: Done via mainloop • PyQT: widget.show() widget.hide() Bernhard.Lohkamp@ki.se
window VBox HBox Label Entry ScrolledWindow TextBuffer Button Simple example • GUI command input • Schematic in terms of widgets Bernhard.Lohkamp@ki.se
Connexion au compte
Connectez-vous pour publier votre contenu sur SlideServe.