David Boddie. PyCon UK 2007, Birmingham



Similar documents
Building a Python Plugin

PyQt for Desktop and Embedded Devices

EuroPython 2006, CERN, Geneva David Boddie and Torsten Marek * Qt and Trolltech are registered trademarks of Trolltech ASA

Introduction to GUI programming in Python. Alice Invernizzi

Surface and Volumetric Data Rendering and Visualisation

GUI application set up using QT designer. Sana Siddique. Team 5

BogDan Vatra and Andy Gryc. Qt on Android: Is it right for you?

The Most Popular UI/Apps Framework For IVI on Linux

Rapid GUI Application Development with Python

Neutron Science Visualization Software

Operating System Today s Operating Systems File Basics File Management Application Software

T H E G E O S PAT I A L D E S K T O P

What is An Introduction

VoIP support on Qtopia. Vladimir Minenko, Ph.D.

[PRAKTISCHE ASPEKTE DER INFORMATIK SS 2014]

Mobile Development with Qt

Rapid Application Development with GNOME and Python

Wakanda Studio Features

RIC 2007 SNAP: Symbolic Nuclear Analysis Package. Chester Gingrich USNRC/RES 3/13/07

A Modular Approach to Teaching Mobile APPS Development

Embedded Linux development training 4 days session

The power of IBM SPSS Statistics and R together

OPERATING SYSTEM SERVICES

GR A universal framework for visualization applications

Cross-platform C++ development using Qt

Postprocessing with Python

CrossPlatform ASP.NET with Mono. Daniel López Ridruejo

Open source framework for interactive data exploration in server based architecture

Professional. SlickEdif. John Hurst IC..T...L. i 1 8 О 7» \ WILEY \ Wiley Publishing, Inc.

ORACLE ADF MOBILE DATA SHEET

Chapter Contents. Operating System Activities. Operating System Basics. Operating System Activities. Operating System Activities 25/03/2014

TIBCO ActiveMatrix BusinessWorks Plug-in for TIBCO Managed File Transfer Software Installation

ft6 Motivation next step: perform the tests usually tedious, error prone work aided by a tool easily repeatable enter ft6 ft6

Eclipse 4 RCP application Development COURSE OUTLINE

DEVELOPMENT OF AN ANALYSIS AND REPORTING TOOL FOR ORACLE FORMS SOURCE CODES

The MaXX Desktop. Workstation Environment. Revised Road Map Version 0.7. for Graphics Professionals

From the Desktop to the Mobile Cloud: Extending your Qt Widget Desktop Application as a Back-end Service

IDL. Get the answers you need from your data. IDL

Why this lecture exists ITK Lecture 12: Open Source & Cross Platform Software Development

Application Framework: Apertis Hands-on

File management Editing X Window KDE. Debian/GNU Linux. Introduction II. Károly Erdei. November 21, Károly Erdei Debian/GNU Linux 1/45

QML and JavaScript for Native App Development

VisIt Visualization Tool

KIVY - A Framework for Natural User Interfaces

MALAYSIAN PUBLIC SECTOR OPEN SOURCE SOFTWARE (OSS) PROGRAMME. COMPARISON REPORT ON NETWORK MONITORING SYSTEMS (Nagios and Zabbix)

Running a Program on an AVD

Rapid Application Design with the ROOT GUI Classes

lubyk lua libraries for live arts Gaspard Bucher (Buma)! artist, musician, coder

Introduction to Android

Architecture, Design and Implementation of a Mathematical Derivation Editor. Johannes Eriksson

Visual Basic. murach's TRAINING & REFERENCE

Android Mobile App Building Tutorial

Python and Google App Engine

CS420: Operating Systems OS Services & System Calls

AUTOMATED CONFERENCE CD-ROM BUILDER AN OPEN SOURCE APPROACH Stefan Karastanev

I don t intend to cover Python installation, please visit the Python web site for details.

Elgg 1.8 Social Networking

Mouse and Pointer Settings. Technical Brief

Getting Started with Tizen SDK : How to develop a Web app. Hong Gyungpyo 洪 競 杓 Samsung Electronics Co., Ltd

Wiki Server. Innovative tools for workgroup collaboration and communication. Features

Installing and Configuring Adobe LiveCycle 9.5 Connector for Microsoft SharePoint

Parallels Plesk Panel

SECURE YOUR NETWORK WITH FIREWALL BUILDER

Developing Web Services with Eclipse and Open Source. Claire Rogers Developer Resources and Partner Enablement, HP February, 2004

What Is NetBeans? Free and open-source based > Open source since June, 2000 > Large community of users and developers

SCCM Plug-in User Guide. Version 3.41

Dr. Marco Hugentobler, Sourcepole QGIS from a geodata viewer to a GIS platform

Source Code Translation

Microsoft Office Small Business 2007

Fred Hantelmann LINUX. Start-up Guide. A self-contained introduction. With 57 Figures. Springer

Practical Eclipse Rich Client Platform Projects

caqtdm Tutorial Jim Stevens APS Controls Group October 9, 2014

Using the Eclipse Data Tools Platform with SQL Anywhere 10. A whitepaper from Sybase ianywhere

Introduction CMake Language Specific cases. CMake Tutorial. How to setup your C/C++ projects? Luis Díaz Más.

With a single download, the ADT Bundle includes everything you need to begin developing apps:

Creating Home Directories for Windows and Macintosh Computers

Introduction to Python

WebRatio 5: An Eclipse-based CASE tool for engineering Web applications

Liblouis a universal solution for Braille transcription services

Quick start. A project with SpagoBI 3.x

Managing Access Control in PresSTORE

Cross-Platform Software Considerations for Internet of Things

WW HMI SCADA-11 System Platform Best Practices 1: Engineering Efficiencies

WebSphere Business Monitor

MayaVi: A free tool for CFD data visualization

Data Quality Monitoring for High Energy Physics (DQM4HEP) Module interfaces

Functions of NOS Overview of NOS Characteristics Differences Between PC and a NOS Multiuser, Multitasking, and Multiprocessor Systems NOS Server

Extending the Survey123 for ArcGIS Mobile App

Qt/Embedded Whitepaper. Trolltech

Developing with Android Studio

Transcription:

Creating GUI Applications with PyQt and Qt Designer David Boddie dboddie@trolltech.com PyCon UK 2007, Birmingham Qt, Qtopia and Trolltech are registered trademarks of Trolltech ASA

Contents 1. What are Qt, PyQt and Qt Designer? 2. PyQt Basics 3. A Simple Example Widgets and layouts Signals and slots 4. A More Useful Example Actions and resources Auto-connection of signals and slots 5. Custom Widgets

What is Qt? Cross-platform framework Used for (but not limited to) GUI applications Supported on Windows, Mac OS X, Linux and other Unix platforms Dual licensed: Available under the GNU GPL Also available under a Commercial License for closed source applications Mature, well-used, well-tested (KDE, Qtopia, commercial applications)

What is PyQt? Python bindings to the Qt libraries Comprehensive API coverage Dual licensed in the same way as Qt Community mailing list with around 500 members Wiki at http://www.diotavelli.net/pyqtwiki A solid foundation for other projects (PyQwt, PyKDE, etc.) Used a lot in scientific/visualisation domains

What is Qt Designer? Graphical form designer (not an IDE) Preview facilities Generates XML descriptions You can also use pyuic4 to convert them to Python Or you can use the Python uic module to generate the GUI at run-time This presentation was created with Qt Designer. The GUI is shown using PyQt4.

PyQt Basics Widgets and layouts Signals and slots

A Simple Example (PyPI Information) We will Create a form Generate some code Write the application logic Run the application

A Simple Example (PyPI Information) from PyQt4.QtCore import Qt, SIGNAL from PyQt4.QtGui import * from ui_window import Ui_Window import pypi class Window(QWidget, Ui_Window): terms = ["name", "version", "author", "author_email", "maintainer", "maintainer_email", "home_page", "license", "summary", "description", "keywords", "platform", "download_url"] def init (self, parent = None): QWidget. init (self, parent) self.setupui(self) self.connect(self.searchbutton, SIGNAL("clicked()"), self.search) def search(self): self.treewidget.clear() qapp.setoverridecursor(qt.waitcursor) server = pypi.packageserver("http://pypi.python.org/pypi") matches = server.search( { unicode(self.terms[self.fieldcombo.currentindex()]): unicode(self.termsedit.text()) }, "and" ) qapp.restoreoverridecursor() if len(matches) == 0: QMessageBox.information(self, self.tr("pypi Information"), self.tr("no results found.")) return for match in matches: item = QTreeWidgetItem() if not match["name"]: continue item.settext(0, match["name"]) if match["summary"]: item.settext(1, match["summary"]) self.treewidget.addtoplevelitem(item)

A Simple Example (PyPI Information) Form creation We placed widgets first Then applied layouts Connected signals and slots (close, return pressed) Source code We ran pyuic4 to generate code Then imported the module into our code We mixed in the generated class

A More Useful Example (MathTran Equation Editor) As before, we will Create a form Generate some code Write the application logic Run the application

A More Useful Example (MathTran Equation Editor) from PyQt4.QtCore import * from PyQt4.QtGui import * from PyQt4.QtNetwork import * from ui_mainwindow import Ui_MainWindow class MainWindow(QMainWindow, Ui_MainWindow): def init (self, parent = None): QMainWindow. init (self, parent) self.setupui(self) self.path = QString() self.mathsize = 3 self.http = QHttp() self.connect(self.http, SIGNAL("done(bool)"), self.updateform) self.connect(self.exitaction, SIGNAL("triggered()"), qapp, SLOT("quit()")) self.connect(self.aboutqtaction, SIGNAL("triggered()"), qapp, SLOT("aboutQt()")) # See example code for more details.

A More Useful Example (MathTran Equation Editor) We added some actions (decrease math size, about Qt) Some of these used images listed in a resource file We created a toolbar and some menus The actions were placed in the menus and toolbar We ran pyuic4 to generate code We ran pyrcc4 to generate a resource module We used decorators to indicate which methods were slots Signals were auto-connected to slots

Custom Widgets (Logo Maker) Two custom widgets: 1. EffectWidget One signal Lots of properties Lots of slots 2. ColorButton One signal: colorchanged(qcolor) One slot: setcolor() One property: color

Custom Widgets (Logo Maker)

Custom Widgets (Logo Maker) from PyQt4.QtCore import * from PyQt4.QtGui import * class ColorButton(QToolButton): pyqtsignals = ("colorchanged(qcolor)",) def init (self, parent = None): QToolButton. init (self, parent) self.connect(self, SIGNAL("clicked()"), self.choosecolor) self._color = QColor() def choosecolor(self): rgba, valid = QColorDialog.getRgba( self._color.rgba(), self.parentwidget()) if valid: color = QColor.fromRgba(rgba) self.setcolor(color) def color(self): return self._color @pyqtsignature("qcolor") def setcolor(self, color): if color!= self._color: self._color = color self.emit(signal("colorchanged(qcolor)"), self._color) pixmap = QPixmap(self.iconSize()) pixmap.fill(color) self.seticon(qicon(pixmap)) color = pyqtproperty("qcolor", color, setcolor)

Custom Widgets (Logo Maker) pyqtsignals declares signals to other components: class ColorButton(QToolButton): pyqtsignals = ("colorchanged(qcolor)",) @pyqtsignature() marks methods as slots and declares type information to Qt: @pyqtsignature("qcolor") def setcolor(self, color): if color!= self._color: self._color = color pyqtproperty() creates a Qt property: color = pyqtproperty("qcolor", color, setcolor)

Custom Widgets (Logo Maker) from PyQt4 import QtGui, QtDesigner from colorbutton import ColorButton class ColorButtonPlugin(QtDesigner.QPyDesignerCustomWidgetPlugin): def init (self, parent = None): QtDesigner.QPyDesignerCustomWidgetPlugin. init (self) self.initialized = False def initialize(self, core): if self.initialized: return self.initialized = True def isinitialized(self): return self.initialized def createwidget(self, parent): return ColorButton(parent) def name(self): return "ColorButton" def group(self): return "PyQt Examples" def icon(self): return QtGui.QIcon(_logo_pixmap) def tooltip(self): return "" def whatsthis(self): return "" def iscontainer(self): return False def domxml(self): return '<widget class="colorbutton" name=\"colorbutton\" />\n' def includefile(self): return "colorbutton"

Custom Widgets (Logo Maker) createwidget() returns a new instance of the widget: def createwidget(self, parent): return ColorButton(parent) name() returns the class name of the custom widget (for making new copies): def name(self): return "ColorButton" includefile() returns the custom widget's module path: def includefile(self): return "colorbutton"

Installing custom widgets Custom Widgets (Logo Maker) Or use environment variables: Set PYQTDESIGNERPATH to refer to the plugins directory Add the widget directory to the PYTHONPATH

Resources Trolltech: http://www.trolltech.com Riverbank Computing: http://www.riverbankcomputing.com/ PyQt Wiki at http://www.diotavelli.net/pyqtwiki