Dies ist die Support Website des Buches:: Das Python Praxisbuch Der große Profi-Leitfaden für Programmierer Farid Hajji Addison Wesley / Pearson Education ISBN 978-3-8273-2543-3 (Sep 2008), 1298 Seiten. ****************** 16. GUI-Toolkits ****************** wxPython ======== Screenshots: `Das wxPython Logo `_ URLs: * `Website der wxWidget C++ Bibliothek `_ * `Website des wxPython Ports `_ wxPython installieren --------------------- Installation unter Unix ^^^^^^^^^^^^^^^^^^^^^^^ Installation unter Windows ^^^^^^^^^^^^^^^^^^^^^^^^^^ Erste Schritte in wxPython -------------------------- Wie finde ich mich in wxPython zurecht? ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. literalinclude:: ../att/gui/wx_app1.py `wx_app1.py `_ Screenshots: * `Ausgabe von wx_app1.py `_ * `Die C++ API von wxFrame (Konstruktor) `_ * `Die PyCrust Shell tooltips `_ * `Die PyCrust Shell auto-completion `_ Ein Fenster mit einem Button ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. literalinclude:: ../att/gui/wx_app2.py `wx_app2.py `_ .. literalinclude:: ../att/gui/wx_app2a.py `wx_app2a.py `_ Screenshots: * `Ausgabe von wx_app2.py `_ Sizer oder: ein Fenster mit zwei Buttons ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. literalinclude:: ../att/gui/wx_app3.py `wx_app3.py `_ Screenshots: * `Ausgabe von wx_app3.py `_ Ein Button und ein Dialogfenster ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. literalinclude:: ../att/gui/wx_app4.py `wx_app4.py `_ Screenshots: * `Ausgabe von wx_app4.py `_ Ein Dialogfenster als Passwortabfrage ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. literalinclude:: ../att/gui/wx_app5.py `wx_app5.py `_ Screenshots: * `Ausgabe von wx_app5.py `_ Menü mit Statuszeile ^^^^^^^^^^^^^^^^^^^^ Das folgende Programm wird stückweise in diesme Abschnitt vorgeführt. Hier ist es nochmal als Ganzes zu sehen: .. literalinclude:: ../att/gui/wx_app6.py `wx_app6.py `_ Screenshots: * `Ausgabe von wx_app6.py `_ * `Das File-Menü von wx_app6.py unter FreeBSD (GTK2+) `_ * `Das Languages-Menü von wx_app6.py `_ Weitere Widgets ^^^^^^^^^^^^^^^ Screenshots: * `Das demo.py Programm, hier bei FileDialog `_ * `FileDialog unter Windows `_ * `FileDialog unter FreeBSD (GTK2+) `_ Responsive GUIs --------------- Das Problem des eingefrorenen GUI ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. literalinclude:: ../att/gui/wx_app7.py `wx_app7.py `_ Screenshots: * `Ausgabe von wx_app7.py `_ Timer ^^^^^ .. literalinclude:: ../att/gui/wx_app7a.py `wx_app7a.py `_ .. literalinclude:: ../att/gui/wx_app7b.py `wx_app7b.py `_ .. literalinclude:: ../att/gui/wx_app7c.py `wx_app7c.py `_ Delayed Results ^^^^^^^^^^^^^^^ .. literalinclude:: ../att/gui/wx_app7d.py `wx_app7d.py `_ .. literalinclude:: ../att/gui/wx_app8.py `wx_app8.py `_ Screenshots: * `Ausgabe von wx_app8.py `_ Threads ^^^^^^^ Das folgenden Programm wird stückweise in diesem Abschnitt vorgestellt. Hier nochmal als Ganzes: .. literalinclude:: ../att/gui/wx_app9.py `wx_app9.py `_ .. literalinclude:: ../att/gui/counterthread.py `counterthread.py `_ Screenshots: * `Ausgabe von wx_app9.py `_ Externe Prozesse ^^^^^^^^^^^^^^^^ Das folgende Programm wird stückweise in diesem Abschnitt vorgestellt. Hier nochmal als Ganzes: .. literalinclude:: ../att/gui/wx_app10.py `wx_app10.py `_ Screenshots: * `Ausgabe von wx_app10.py `_ Integration mit Twisted ^^^^^^^^^^^^^^^^^^^^^^^ .. literalinclude:: ../att/gui/wxdemo.py `wxdemo.py `_ Screenshots: * `Ausgabe von wxdemo.py `_ Schnelle Entwicklung mit RAD-Tools ---------------------------------- wxGlade ^^^^^^^ URLs: * `Die wxGlade Website `_ Screenshots: * `Der wxGlade Desktop `_ * `Einen Titel im Properties Fenster setzen `_ * `Der Objekt-Baum hat sich verändert `_ * `Einen Text für die StatusBar `_ * `Der Menü-Editor `_ * `Das Frame mit einem GridSizer unterteilen `_ * `Der Desktop sieht jetzt so aus `_ * `Und nun generieren wir den Code `_ * `Die Anwendung ausführen `_ .. literalinclude:: ../att/gui/myApp.py `myApp.py `_ .. literalinclude:: ../att/gui/myApp.wxg :language: xml `myApp.wxg `_ XRC-Ressourcen ^^^^^^^^^^^^^^ .. literalinclude:: ../att/gui/myApp.xrc :language: xml `myApp.xrc `_ URLs: * `XRCed als alleinstehende Application `_ (ist auch Bestandteil von wxPython) * `Beispiel für wx.wrc `_ Weitere RAD-Tools ^^^^^^^^^^^^^^^^^ URLs: * `Boa Constructor `_ * `SPE IDE - Stani's Python Editor `_ * `Python Card `_ Screenshots: * `So sieht Boa Constructor aus `_ PyQt4 ===== PyQt4 installieren ------------------ URLs: * `Die Qt4 C++ Bibliothek `_ * `Der PyQt4 Port `_ * `Das sip Tool `_ Installation unter Unix ^^^^^^^^^^^^^^^^^^^^^^^ Installation unter Windows ^^^^^^^^^^^^^^^^^^^^^^^^^^ Screenshots: * `Erst muß die Qt-Bibliothek installiert werden `_ * `Dann soll MinGW installiert werden `_ (haben wir aber schon im ersten Kapitel) * `Diese Fehlermeldung kann man getrost wegklicken `_ Erste Schritte in PyQt4 ----------------------- Screenshots: * `PyQt Examples and Demos `_ Wie finde ich mich in PyQt4 und Qt4 zurecht? ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Screenshots: * `Qt Assistent `_ * `QPushButton C++ API `_ * `QPushButton Python API `_ Ein Fenster mit einem Button ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. literalinclude:: ../att/gui/pyqt4_tutorial_t2.py `pyqt4_tutorial_t2.py `_ Screenshots: * `Ausgabe von pyqt4_tutorial_t2.py `_ * `QPushButton C++ API (Details zu Signalen und Slots) `_ * `QApplication C++ API `_ * `QCoreApplication C++ API `_ Geometrie, Signale und Slots ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. literalinclude:: ../att/gui/pyqt4_tutorial_t5.py `pyqt4_tutorial_t5.py `_ Screenshots: * `Ausgabe von pyqt4_tutorial_t5.py `_ Responsive GUIs --------------- Ein HTTP-Downloader ^^^^^^^^^^^^^^^^^^^ Das folgende Programm wird stückweise in diesem Abschnitt eingeführt und erklärt. Hier steht es nochmal als Ganzes: .. literalinclude:: ../att/gui/pyqt4_network_http.py `pyqt4_network_http.py `_ Screenshots: * `Ausgabe von pyqt4_network_http.py `_ * `Die C++ API von QHttp `_ Integration mit Twisted ^^^^^^^^^^^^^^^^^^^^^^^ URLs: * `Die Website von QTReactor `_ Schnelle Entwicklung mit RAD-Tools ---------------------------------- Qt Designer ^^^^^^^^^^^ Screenshots: * `Der Qt Designer `_ .. literalinclude:: ../att/gui/pyqt4_demo.ui :language: xml `pyqt4_demo.ui `_ .ui-Dateien laden ^^^^^^^^^^^^^^^^^ Aus :file:`pyqt4_demo.ui` wird mit ``uic`` die Datei :file:`pyqt4_demo.cpp` erzeugt: .. literalinclude:: ../att/gui/pyqt4_demo.cpp :language: c++ `pyqt4_demo.cpp `_ Und ``pyuic4`` erzeugt daraus die Datei :file:`pyqt4_demo.py`, die so aussieht: .. literalinclude:: ../att/gui/pyqt4_demo.py `pyqt4_demo.py `_ .. literalinclude:: ../att/gui/pyqt4_pyuic_load_ui1.py `pyqt4_pyuic_load_ui1.py `_ .. literalinclude:: ../att/gui/pyqt4_pyuic_load_ui2.py `pyqt4_pyuic_load_ui2.py `_ .. literalinclude:: ../att/gui/pyqt4_pyuic_compile_on_the_fly.py `pyqt4_pyuic_compile_on_the_fly.py `_ eric4, eine PyQt4-IDE --------------------- URLs: * `Die Website des Eric4 Projekts `_ * `Die Website des QScintilla2 Projekts `_ Screenshots: * `Die Eric4 Umgebung `_ Tkinter ======= Erste Schritte in Tkinter ------------------------- .. literalinclude:: ../att/gui/tksimple.py `tksimple.py `_ Screenshots: * `Ausgabe von tksimple.py `_ Wie findet man sich in Tkinter zurecht? --------------------------------------- URLs: * http://wiki.python.org/moin/TkInter * http://tkinter.unpythonic.net/wiki/ * http://www.pythonware.com/library/tkinter/introduction/index.htm * http://effbot.org/zone/wck.htm * http://www.astro.washington.edu/owen/TkinterSummary.html * `Ein GUI-Builder für Tkinter `_ .. note:: Die Python-Shell IDLE ist in Tkinter geschrieben. Daher lassen sich im IDLE-Quellcode eine Menge guter Anwendungsbeispiele für Tkinter finden. Übrigens: da IDLE Teil der Python Standard Library ist, lassen sich Komponenten daraus ebenfalls für eigene Projekte selbstverständlich wiederverwenden. (15.08.2008) Text-basierte GUIs ================== pythondialog ------------ URLs: * `Die Website der dialog Bibliothek `_ * `Die Website von pythondialog `_ (aber mit ``easy_install pythondialog`` installieren) .. literalinclude:: ../att/gui/pydialog_input_password.py `pydialog_input_password.py `_ .. literalinclude:: ../att/gui/pydialog_yesno.py `pydialog_yesno.py `_ .. literalinclude:: ../att/gui/pydialog_fselect.py `pydialog_fselect.py `_ Screenshots: * `Ausgabe von pydialog_input_password.py `_ * `Ausgabe von pydialog_yesno.py `_ * `Ausgabe von pydialog_fselect.py `_ Weitere NGUI ------------ URLs: * `Die Website von PyTVision `_ * `Die Website von Turbo Vision (1) `_ * `Die Website von Turbo Vision (2) `_ Low-level APIs ============== Ein Blick unter die Haube: Rohe Events -------------------------------------- GUI-Toolkits vereinfachen eine komplexe API ------------------------------------------- Signatur der Funktion ``XCreateWindow``: .. code-block:: c extern Window XCreateWindow( Display* /* display */, Window /* parent */, int /* x */, int /* y */, unsigned int /* width */, unsigned int /* height */, unsigned int /* border_width */, int /* depth */, unsigned int /* class */, Visual* /* visual */, unsigned long /* valuemask */, XSetWindowAttributes* /* attributes */ ); Signatur der Funktion ``CreateWindow``: .. code-block:: c HWND CreateWindow( LPCTSTR lpClassName, LPCTSTR lpWindowName, DWORD dwStyle, int x, int y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam ); Zusammenfassung ===============