Mark Summerfield - Rapid GUI Programming with Python and Qt.pdf
(
6878 KB
)
Pobierz
Rapid GUI Programming with Python and Qt: The Definitive Guide to PyQt Programming
Table of Contents
Copyright..................................................................................................... 1
About the Author........................................................................................ 2
Production.................................................................................................. 2
Introduction............................................................................................... 3
The Structure of the Book............................................................................................................................................................... 5
Acknowledgements......................................................................................................................................................................... 7
Python Programming.................................................................................. 8
Data Types and Data Structures..................................................................................................................................................... 8
Executing Python Code............................................................................................................................................................... 8
Variables and Objects................................................................................................................................................................ 12
Numbers and Strings................................................................................................................................................................. 16
Collections................................................................................................................................................................................. 32
Built-in Functions..................................................................................................................................................................... 42
Summary.................................................................................................................................................................................... 45
Exercises.................................................................................................................................................................................... 46
Control Structures......................................................................................................................................................................... 48
Conditional Branching.............................................................................................................................................................. 49
Looping...................................................................................................................................................................................... 52
Functions................................................................................................................................................................................... 58
Exception Handling................................................................................................................................................................... 70
Summary.................................................................................................................................................................................... 76
Exercises.................................................................................................................................................................................... 77
Classes and Modules..................................................................................................................................................................... 80
Creating Instances..................................................................................................................................................................... 82
Methods and Special Methods.................................................................................................................................................. 84
Inheritance and Polymorphism............................................................................................................................................... 105
Modules and Multi-File Applications....................................................................................................................................... 111
Summary.................................................................................................................................................................................. 114
Exercises................................................................................................................................................................................... 115
Basic GUI Programming.......................................................................... 116
Introduction to GUI Programming............................................................................................................................................. 116
A Pop-up Alert in 25 Lines....................................................................................................................................................... 117
An Expression Evaluator in 30 Lines...................................................................................................................................... 122
A Currency Converter in 70 Lines........................................................................................................................................... 129
Signals and Slots...................................................................................................................................................................... 134
Summary.................................................................................................................................................................................. 144
Exercise.................................................................................................................................................................................... 145
Dialogs......................................................................................................................................................................................... 145
Dumb Dialogs........................................................................................................................................................................... 147
Standard Dialogs...................................................................................................................................................................... 154
Smart Dialogs........................................................................................................................................................................... 161
Summary.................................................................................................................................................................................. 169
Exercise.................................................................................................................................................................................... 170
Main Windows............................................................................................................................................................................. 172
Creating a Main Window......................................................................................................................................................... 174
Handling User Actions............................................................................................................................................................ 201
Summary.................................................................................................................................................................................. 212
Exercise.................................................................................................................................................................................... 214
Using Qt Designer........................................................................................................................................................................ 215
Designing User Interfaces........................................................................................................................................................ 217
Implementing Dialogs............................................................................................................................................................. 228
Testing Dialogs........................................................................................................................................................................ 233
Summary................................................................................................................................................................................. 234
Exercise.................................................................................................................................................................................... 235
Data Handling and Custom File Formats................................................................................................................................... 236
Rapid GUI Programming with Python and Qt: The Definitive Guide to PyQt Programming
Rapid GUI Programming with Python and Qt: The Definitive Guide to PyQt Programming
Prepared for Paul Waddell, Safari ID: pwaddell@u.washington.edu
By Mark Summerfield ISBN: 9780132354189 Publisher: Prentice Hall
Print Publication Date: 2007/10/19
User number: 905221 Copyright 2007, Safari Books Online, LLC.
This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior
written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that
otherwise violates the Safari Terms of Service is strictly prohibited.
Rapid GUI Programming with Python and Qt: The Definitive Guide to PyQt Programming
Main Window Responsibilities............................................................................................................................................... 239
Data Container Responsibilities............................................................................................................................................. 244
Saving and Loading Binary Files............................................................................................................................................ 250
Saving and Loading Text Files................................................................................................................................................ 258
Saving and Loading XML Files............................................................................................................................................... 266
Summary.................................................................................................................................................................................. 275
Exercise.................................................................................................................................................................................... 276
Intermediate GUI Programming............................................................. 276
Layouts and Multiple Documents............................................................................................................................................... 277
Layout Policies......................................................................................................................................................................... 278
Tab Widgets and Stacked Widgets.......................................................................................................................................... 279
Splitters................................................................................................................................................................................... 288
Single Document Interface (SDI)............................................................................................................................................ 291
Multiple Document Interface (MDI)...................................................................................................................................... 298
Summary................................................................................................................................................................................. 308
Exercise................................................................................................................................................................................... 309
Events, the Clipboard, and Drag & Drop.................................................................................................................................... 310
The Event Handling Mechanism............................................................................................................................................. 310
Reimplementing Event Handlers............................................................................................................................................ 312
Using the Clipboard................................................................................................................................................................. 318
Drag and Drop......................................................................................................................................................................... 319
Summary................................................................................................................................................................................. 325
Exercise.................................................................................................................................................................................... 326
Custom Widgets.......................................................................................................................................................................... 327
Using Widget Style Sheets...................................................................................................................................................... 328
Creating Composite Widgets................................................................................................................................................... 331
Subclassing Built-in Widgets.................................................................................................................................................. 333
Subclassing QWidget............................................................................................................................................................... 335
Summary.................................................................................................................................................................................. 351
Exercise.................................................................................................................................................................................... 352
Item-Based Graphics................................................................................................................................................................... 353
Custom and Interactive Graphics Items................................................................................................................................. 355
Animation and Complex Shapes............................................................................................................................................. 373
Summary................................................................................................................................................................................. 382
Exercise................................................................................................................................................................................... 384
Rich Text and Printing................................................................................................................................................................ 384
Rich Text Editing..................................................................................................................................................................... 386
Printing Documents................................................................................................................................................................ 402
Summary.................................................................................................................................................................................. 415
Exercise.................................................................................................................................................................................... 416
Model/View Programming.......................................................................................................................................................... 417
Using the Convenience Item Widgets..................................................................................................................................... 419
Creating Custom Models......................................................................................................................................................... 427
Creating Custom Delegates..................................................................................................................................................... 439
Summary................................................................................................................................................................................. 446
Exercise.................................................................................................................................................................................... 447
Databases.................................................................................................................................................................................... 447
Connecting to the Database.................................................................................................................................................... 448
Executing SQL Queries........................................................................................................................................................... 449
Using Database Form Views................................................................................................................................................... 454
Using Database Table Views................................................................................................................................................... 460
Summary.................................................................................................................................................................................. 473
Exercise.................................................................................................................................................................................... 474
Advanced GUI Programming................................................................... 475
Advanced Model/View Programming........................................................................................................................................ 475
Custom Views.......................................................................................................................................................................... 476
Generic Delegates.................................................................................................................................................................... 483
Representing Tabular Data in Trees....................................................................................................................................... 492
Summary................................................................................................................................................................................. 506
Exercise................................................................................................................................................................................... 506
Rapid GUI Programming with Python and Qt: The Definitive Guide to PyQt Programming
Rapid GUI Programming with Python and Qt: The Definitive Guide to PyQt Programming
Prepared for Paul Waddell, Safari ID: pwaddell@u.washington.edu
By Mark Summerfield ISBN: 9780132354189 Publisher: Prentice Hall
Print Publication Date: 2007/10/19
User number: 905221 Copyright 2007, Safari Books Online, LLC.
This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior
written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that
otherwise violates the Safari Terms of Service is strictly prohibited.
Rapid GUI Programming with Python and Qt: The Definitive Guide to PyQt Programming
Online Help and Internationalization........................................................................................................................................ 508
Online Help............................................................................................................................................................................. 509
Internationalization................................................................................................................................................................. 512
Summary................................................................................................................................................................................. 520
Exercise.................................................................................................................................................................................... 521
Networking.................................................................................................................................................................................. 521
Creating a TCP Client.............................................................................................................................................................. 523
Creating a TCP Server............................................................................................................................................................. 529
Summary................................................................................................................................................................................. 534
Exercise.................................................................................................................................................................................... 535
Multithreading............................................................................................................................................................................ 536
Creating a Threaded Server..................................................................................................................................................... 538
Creating and Managing Secondary Threads........................................................................................................................... 543
Implementing a Secondary Thread......................................................................................................................................... 552
Summary.................................................................................................................................................................................. 557
Exercise.................................................................................................................................................................................... 558
This Is Not Quite The End....................................................................................................................................................... 559
Installing................................................................................................. 560
Installing on Windows................................................................................................................................................................ 560
Installing on Mac OS X............................................................................................................................................................... 565
Installing on Linux and Unix...................................................................................................................................................... 570
Selected PyQt Widgets............................................................................. 574
Selected PyQt Class Hierarchies.............................................................. 579
Rapid GUI Programming with Python and Qt: The Definitive Guide to PyQt Programming
Rapid GUI Programming with Python and Qt: The Definitive Guide to PyQt Programming
Prepared for Paul Waddell, Safari ID: pwaddell@u.washington.edu
By Mark Summerfield ISBN: 9780132354189 Publisher: Prentice Hall
Print Publication Date: 2007/10/19
User number: 905221 Copyright 2007, Safari Books Online, LLC.
This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior
written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that
otherwise violates the Safari Terms of Service is strictly prohibited.
Rapid GUI Programming with Python and Qt: The Definitive Guide to PyQt Programming
Contents
Page 1
Return to Table of
Copyright
Many of the designations used by manufacturers and sellers to distinguish their products
are claimed as trademarks. Where those designations appear in this book, and the
publisher was aware of a trademark claim, the designations have been printed with initial
capital letters or in all capitals.
The author and publisher have taken care in the preparation of this book, but make no
expressed or implied warranty of any kind and assume no responsibility for errors or
omissions. No liability is assumed for incidental or consequential damages in connection
with or arising out of the use of the information or programs contained herein.
The publisher offers excellent discounts on this book when ordered in quantity for bulk
purchases or special sales, which may include electronic versions and/or custom covers
and content particular to your business, training goals, marketing focus, and branding
interests. For more information, please contact:
U.S. Corporate and Government Sales
(800) 382-3419
corpsales@pearsontechgroup.com
For sales outside the United States, please contact:
International Sales
international@pearsoned.com
Visit us on the Web:
www.prenhallprofessional.com
Library of Congress Cataloging-in-Publication Data
Summerfield, Mark
Rapid GUI programming with Python and Qt / Mark Summerfield.
p. cm.
Includes bibliographical references and index.
ISBN 0-13-235418-7 (pbk.: alk. paper)
1. Graphical user interfaces (Computer systems) 2. C++ (Computer program language)
QA76.9.????? 2006
005.4'37—dc22
?????
Copyright © 2007 Pearson Education, Inc.
All rights reserved. Printed in the United States of America.
Rapid GUI Programming with Python and Qt: The Definitive Guide to PyQt Programming
Rapid GUI Programming with Python and Qt: The Definitive Guide to PyQt Programming
Prepared for Paul Waddell, Safari ID: pwaddell@u.washington.edu
By Mark Summerfield ISBN: 9780132354189 Publisher: Prentice Hall
Print Publication Date: 2007/10/19
User number: 905221 Copyright 2007, Safari Books Online, LLC.
This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior
written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that
otherwise violates the Safari Terms of Service is strictly prohibited.
Copyright Safari Books Online #905221
Plik z chomika:
cho-mik9613
Inne pliki z tego folderu:
Antony Polukhin - Boost C++ Application Development Cookbook.pdf
(3669 KB)
Beej - Guide to Network Programming.pdf
(734 KB)
Ben Lynn - Git Magic.pdf
(382 KB)
Bruce Eckel - Thinking in Java 4th Edition.pdf
(6273 KB)
Charles Petzold - Programming Windows (5th Edition, WinAPI).pdf
(6950 KB)
Inne foldery tego chomika:
Zgłoś jeśli
naruszono regulamin