Instant Access to Rapid GUI Programming with Python and Qt 1st Edition Mark Summerfield ebook Full Chapters

Download as pdf or txt
Download as pdf or txt
You are on page 1of 50

Download the full version of the ebook at ebookname.

com

Rapid GUI Programming with Python and Qt 1st


Edition Mark Summerfield

https://ebookname.com/product/rapid-gui-programming-with-
python-and-qt-1st-edition-mark-summerfield/

OR CLICK BUTTON

DOWNLOAD EBOOK

Download more ebook instantly today at https://ebookname.com


Instant digital products (PDF, ePub, MOBI) available
Download now and explore formats that suit you...

GUI Programming with Python QT Edition Boudewijn Rempt

https://ebookname.com/product/gui-programming-with-python-qt-edition-
boudewijn-rempt/

ebookname.com

Programming in Python 3 A Complete Introduction to the


Python Language 2nd Edition Summerfield

https://ebookname.com/product/programming-in-python-3-a-complete-
introduction-to-the-python-language-2nd-edition-summerfield/

ebookname.com

Programming Python 4th Edition Mark Lutz

https://ebookname.com/product/programming-python-4th-edition-mark-
lutz/

ebookname.com

Learning and Teaching in the Chinese Classroom Responding


to Individual Needs 1st Edition Shane N. Phillipson

https://ebookname.com/product/learning-and-teaching-in-the-chinese-
classroom-responding-to-individual-needs-1st-edition-shane-n-
phillipson/
ebookname.com
The Critique of Instrumental Reason from Weber to Habermas
1st Edition Darrow Schecter

https://ebookname.com/product/the-critique-of-instrumental-reason-
from-weber-to-habermas-1st-edition-darrow-schecter/

ebookname.com

Practical Obstetrics and Gynecology 2nd Edition Richa


Saxena

https://ebookname.com/product/practical-obstetrics-and-gynecology-2nd-
edition-richa-saxena/

ebookname.com

Water Encyclopedia Domestic Municipal and Industrial Water


Supply and Waste Disposal 1st Edition Jay H. Lehr

https://ebookname.com/product/water-encyclopedia-domestic-municipal-
and-industrial-water-supply-and-waste-disposal-1st-edition-jay-h-lehr/

ebookname.com

Discrete Mechanics 1st Edition Jean-Paul Caltagirone

https://ebookname.com/product/discrete-mechanics-1st-edition-jean-
paul-caltagirone/

ebookname.com

Imperial Ascent Mountaineering Masculinity and Empire


First Edition Peter L. Bayers

https://ebookname.com/product/imperial-ascent-mountaineering-
masculinity-and-empire-first-edition-peter-l-bayers/

ebookname.com
100 Q A About Alcoholism Drug Addiction 1st Edition
Charles Herrick

https://ebookname.com/product/100-q-a-about-alcoholism-drug-
addiction-1st-edition-charles-herrick/

ebookname.com
Rapid GUI Programming
with Python and Qt
The Definitive Guide to PyQt Programming

Mark Summerfield

Upper Saddle River, NJ · Boston · Indianapolis · San Francisco


New York · Toronto · Montreal · London · Munich · Paris · Madrid
Capetown · Sydney · Tokyo · Singapore · Mexico City
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
[email protected]
For sales outside the United States, please contact:
International Sales
[email protected]
Visit us on the Web: www.prenhallprofessional.com

Library of Congress Cataloging-in-Publication Data


Summerfield, Mark
Rapid GUI programming with Python and Qt : the definitive guide to PyQt programming / Mark
Summerfield.
p. cm.
Includes bibliographical references and index.
ISBN 978-0-13-235418-9 (hardcover : alk. paper)
1. Qt (Electronic resource) 2. Graphical user interfaces (Computer systems) 3. Python (Computer
program language) I. Title.
QA76.9.U83S89 2007
005.1’2—dc22
2007034852
Copyright © 2008 Pearson Education, Inc.
All rights reserved. Printed in the United States of America.
Trolltech®, Qt® and the Trolltech logo are registered trademarks of Trolltech ASA.
ISBN-13: 978-0-13-235418-9
ISBN-10: 0-13-235418-7
Text printed in the United States on recycled paper at Edwards Brothers in Ann Arbor, Michigan.
First printing, October 2007
This book is dedicated to
Andrea Summerfield
This page intentionally left blank
Contents

Foreword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii

Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

Part I: Python Programming

Chapter 1. Data Types and Data Structures . . . . . . . . . . . . . . . . . . . . . 9


Executing Python Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Variables and Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Numbers and Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Integers and Long Integers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Floats and Decimals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Bytestrings, Unicode Strings, and QStrings . . . . . . . . . . . . . . . . . . 20
Collections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Tuples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Dictionaries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Built-in Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42

Chapter 2. Control Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45


Conditional Branching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Looping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
List Comprehensions and Generators . . . . . . . . . . . . . . . . . . . . . . . 53
Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Generator Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Using Keyword Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
Lambda Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
Dynamic Function Creation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
Partial Function Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Exception Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66

vii
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72

Chapter 3. Classes and Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75


Creating Instances . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
Methods and Special Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Static Data, and Static Methods and Decorators . . . . . . . . . . . . . 85
Example: The Length Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
Collection Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
Example: The OrderedDict Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
Inheritance and Polymorphism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Modules and Multifile Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
Using the doctest Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108

Part II: Basic GUI Programming

Chapter 4. Introduction to GUI Programming . . . . . . . . . . . . . . . . . . 111


A Pop-Up Alert in 25 Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
An Expression Evaluator in 30 Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
A Currency Converter in 70 Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
Signals and Slots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137

Chapter 5. Dialogs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139


Dumb Dialogs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
Standard Dialogs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
Modal OK/Cancel-Style Dialogs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
Smart Dialogs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
Modeless Apply/Close-Style Dialogs . . . . . . . . . . . . . . . . . . . . . . . . . 155
Modeless “Live” Dialogs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163

Chapter 6. Main Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165


Creating a Main Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
Actions and Key Sequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
Resource Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172

viii
Creating and Using Actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
Restoring and Saving the Main Window’s State . . . . . . . . . . . . . . 181
Handling User Actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
Handling File Actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
Handling Edit Actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
Handling Help Actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202

Chapter 7. Using Qt Designer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205


Designing User Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
Implementing Dialogs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
Testing Dialogs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224

Chapter 8. Data Handling and Custom File Formats . . . . . . . . . . . . 227


Main Window Responsibilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229
Data Container Responsibilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
Saving and Loading Binary Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240
Writing and Reading Using QDataStream . . . . . . . . . . . . . . . . . . . 240
Writing and Reading Using the pickle Module . . . . . . . . . . . . . . . 246
Saving and Loading Text Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
Writing and Reading Using QTextStream . . . . . . . . . . . . . . . . . . . 250
Writing and Reading Using the codecs Module . . . . . . . . . . . . . . . 255
Saving and Loading XML Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
Writing XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
Reading and Parsing XML with PyQt’s DOM Classes . . . . . . . . 259
Reading and Parsing XML with PyQt’s SAX Classes . . . . . . . . . 262
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266

Part III: Intermediate GUI Programming

Chapter 9. Layouts and Multiple Documents . . . . . . . . . . . . . . . . . . . . 269


Layout Policies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
Tab Widgets and Stacked Widgets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272
Extension Dialogs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276
Splitters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280
Single Document Interface (SDI) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283

ix
Multiple Document Interface (MDI) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300
Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301

Chapter 10. Events, the Clipboard, and Drag and Drop . . . . . . . . . 303
The Event-Handling Mechanism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303
Reimplementing Event Handlers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305
Using the Clipboard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310
Drag and Drop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312
Handling Custom Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317
Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318

Chapter 11. Custom Widgets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321


Using Widget Style Sheets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322
Creating Composite Widgets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325
Subclassing Built-in Widgets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 326
Subclassing QWidget . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328
Example: A Fraction Slider . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331
Example: A Flow-Mixing Widget . . . . . . . . . . . . . . . . . . . . . . . . . . . 339
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345
Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346

Chapter 12. Item-Based Graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 349


Custom and Interactive Graphics Items . . . . . . . . . . . . . . . . . . . . . . . . . 351
Animation and Complex Shapes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 368
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 378
Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 379

Chapter 13. Rich Text and Printing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381


Rich Text Editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 382
Using QSyntaxHighlighter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 382
A Rich Text Line Edit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389
Printing Documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 398
Printing Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 400
Printing Documents Using HTML and QTextDocument . . . . . . 401
Printing Documents Using QTextCursor and QTextDocument 403
Printing Documents Using QPainter . . . . . . . . . . . . . . . . . . . . . . . . 407
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 411
Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412

x
Chapter 14. Model/View Programming . . . . . . . . . . . . . . . . . . . . . . . . . . 413
Using the Convenience Item Widgets . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415
Creating Custom Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 423
Implementing the View Logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 424
Implementing the Custom Model . . . . . . . . . . . . . . . . . . . . . . . . . . . 427
Creating Custom Delegates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 436
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 442
Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 443

Chapter 15. Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 445


Connecting to the Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 446
Executing SQL Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 446
Using Database Form Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 451
Using Database Table Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 457
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 470
Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 471

Part IV: Advanced GUI Programming

Chapter 16. Advanced Model/View Programming . . . . . . . . . . . . . . . 475


Custom Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 476
Generic Delegates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 483
Representing Tabular Data in Trees . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 492
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 505
Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 505

Chapter 17. Online Help and Internationalization . . . . . . . . . . . . . . 509


Online Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 510
Internationalization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 512
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 519
Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 520

Chapter 18. Networking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 521


Creating a TCP Client . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 523
Creating a TCP Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 529
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 534
Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 534

xi
Chapter 19. Multithreading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 537
Creating a Threaded Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 539
Creating and Managing Secondary Threads . . . . . . . . . . . . . . . . . . . . . 544
Implementing a Secondary Thread . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 552
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 557
Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 558
This Is Not Quite the End . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 559

Appendix A. Installing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 561


Installing on Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 561
Installing on Mac OS X . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 566
Installing on Linux and Unix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 570

Appendix B. Selected PyQt Widgets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 575

Appendix C. Selected PyQt Class Hierarchies . . . . . . . . . . . . . . . . . . . 581

Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 585

xii
Foreword
As PyQt’s creator, I’m delighted to see that this book has been written. Al-
though I served as one of the book’s technical reviewers, I’m happy to confess
that I learned a few things myself.
The PyQt documentation covers the APIs of all the PyQt classes. This book
shows you how to use all those classes, how to combine them to create dialogs,
main windows, and entire applications—all of which look good and work well,
with no arbitrary limits, and using a programming language that is a joy
to use.
What I particularly like about the book is that the examples aren’t trivial ones
designed to illustrate a simple point, but are potentially useful in their own
right. The way that different approaches are considered will reward the reader
who wants to develop a deeper understanding of how to apply PyQt to the
development of large scale, production quality applications.
I began the PyQt story back in the late 1990s. I had been using Tcl/Tk for
some time, but I felt that Tk applications looked ugly, especially when I saw
what had been achieved with the first version of KDE. I had wanted to switch
to Python, and so I thought I would combine the change of language with a
change of GUI library.
Initially I used some wrappers that had been written using SWIG, but I con-
cluded that I could produce a more suitable wrapper tool myself. I set to work
creating SIP, and released PyQt 0.1 supporting Qt 1.41 in November 1998.
Development has continued regularly ever since, both to keep up with new re-
leases of Qt and to broaden the scope of PyQt with, for example, the addition
of support tools and improved documentation. By 2000, PyQt 2.0 supported
Qt 2.2 on both Linux and Windows. Qt 3 support appeared in 2001, and
Mac OS X support in 2002. The PyQt4 series began with PyQt 4.0 in June 2006
with support for Qt 4.
My primary goal has always been to allow Python and Qt to work together in
a way that feels natural to Python programmers, while allowing them to do
anything they want in Python that can be done in C++. The key to achieving
this was the development of SIP. This gave me a specialized code generator
over which I had complete control and ensures that Python and Qt will always
fit snugly together.
The essential process of developing and maintaining PyQt is now well estab-
lished. Much of the work is now automated, which means that keeping up with

xiii
new releases of Qt from Trolltech is no longer the problem it once was, and en-
surs that PyQt will continue for years to come.
It’s been very gratifying to watch the growth of the PyQt community over the
years. If this book is part of your introduction to PyQt, then welcome!

— Phil Thompson
Wimborne, Dorset, U.K.
August 25, 2007

xiv
Introduction
This book teaches how to write GUI applications using the Python program-
ming language and the Qt application development framework. The only
essential prior knowledge is that you can program in some object-oriented pro-
gramming language, such as C++, C#, Java, or of course, Python itself. For the
rich text chapter, some familiarity with HTML and with regular expressions is
assumed, and the databases and threading chapters assume some basic knowl-
edge of those topics. A knowledge of GUI programming is not required, since
all the key concepts are covered.
The book will be useful to people who program professionally as part of their
job, whether as full-time software developers, or those from other disciplines,
including scientists and engineers, who need to do some programming in sup-
port of their work. It is also suitable for undergraduate and post-graduate stu-
dents, particularly those doing courses or research that includes a substantial
computing element. The exercises (with solutions) are provided especially to
help students.
Python is probably the easiest to learn and nicest scripting language in
widespread use, and Qt is probably the best library for developing GUI applica-
tions. The combination of Python and Qt, “PyQt”, makes it possible to develop
applications on any supported platform and run them unchanged on all the
supported platforms—for example, all modern versions of Windows, Linux,
Mac OS X, and most Unix-based systems. No compilation is required thanks
to Python being interpreted, and no source code changes to adapt to different
operating systems are required thanks to Qt abstracting away the platform-
specific details. We only have to copy the source file or files to a target machine
that has both Python and PyQt installed and the application will run.
If you are new to Python: Welcome! You are about to discover a language that
is clear to read and write, and that is concise without being cryptic. Python
supports many programming paradigms, but because our focus is on GUI
programming, we will take an object-oriented approach everywhere except in
the very early chapters.
Python is a very expressive language, which means that we can usually write
far fewer lines of Python code than would be required for an equivalent appli-
cation written in, say, C++ or Java. This makes it possible to show some small
but complete examples throughout the text, and makes PyQt an ideal tool for
rapidly and easily developing GUI applications, whether for prototyping or for
production use.

1
2 Introduction

Figure 1 The Eric4 IDE—a PyQt4 application

Since the emphasis of the book is on GUI programming, Part I provides a


fast-paced Python tutorial as well as some PyQt coverage. This material is
clearly marked (just like this paragraph, with “Qt” in the margin) to make
Qt it easy for experienced Python programmers to skip the Python they already
know. Parts II, III, and IV of the book are all PyQt-specific and assume that
readers can already program in Python, whether from previous experience or
from reading Part I.
Quite often in programming we reach decision points when there are several
possible approaches we could take. Reference books and the online documen-
tation identify what classes, methods, and functions are available, and in some
cases provide examples, but such documents rarely provide a broader context.
This book gives the necessary context, highlighting the key decision points for
GUI programming and offering insights into the pros and cons so that you can
decide for yourself what the right policy is for your particular circumstances.
For example, when you create a dialog, should it be modal or modeless? (See
Chapter 5 for an explanation and policy recommendations on this issue.)
PyQt is used to write all kinds of GUI applications, from accounting appli-
cations, to visualization tools used by scientists and engineers. Figure 1, for
example, shows Eric4, a powerful integrated development environment that is
written in PyQt. It is possible to write PyQt applications that are just tens of
lines long, and medium-size projects of 1 000 to 10 000 lines are very common.
Some commercial companies have built 100 000-line PyQt applications, with
Introduction 3

programming teams varying in size from just one person to more than a dozen
people. Many in-house tools are written using PyQt, but because these are of-
ten used to gain competitive advantage, the companies involved generally do
not permit their use of PyQt to be made public. PyQt is also widely used in the
open source world, with games, utilities, visualization tools, and IDEs all writ-
ten using it.
This book is specifically about PyQt4, the Python bindings for the Qt 4 C++
application development framework.★ PyQt4 is provided in the form of ten
Python modules which between them contain around 400 classes and about
6 000 methods and functions. All the example programs have been tested on
Windows, Linux, and Mac OS X, using Python 2.5, Qt 4.2, and PyQt 4.2, and
additionally on Windows and Linux using Qt 4.3 and PyQt 4.3. Backporting to
earlier versions is possible in some cases, but we recommend using the most
up-to-date versions of Python, Qt, and PyQt.
Python, PyQt, and Qt can be used free of charge for noncommercial purposes,
but the license used by Python is different from that used by PyQt and Qt.
Python is available with a very liberal license that allows it to be used to de-
velop both commercial and noncommercial applications. Both PyQt and Qt are
dual-licensed: This essentially allows them to be used to develop noncommer-
cial applications—which must in turn be licensed using an acceptable open
source license such as the GNU General Public License (GPL); or to be used to
develop commercial applications—in this case, a commercial PyQt license and
a commercial Qt license must be purchased.

The Structure of the Book

The book is divided into four parts. Part I is primarily a rapid conversion course
aimed at non-Python programmers who are familiar with an object-oriented
language, although it also has some (clearly marked) PyQt content. Because
the core Python language is mostly simple and is quite small, these chapters
can teach the basics of Python to a sufficient extent that real Python applica-
tions can be written.
If you think that you can pick up the Python syntax simply through reading
it, you might be tempted to skip Part I and dive straight into the GUI pro-
gramming that begins in Part II. The early chapters in Part II include back-
references to the relevant pages in Part I to support readers who choose this
approach. However, even for readers familiar with Python, we recommend
reading about QString in Chapter 1. If you are unfamiliar with partial function
application (currying), it is important to read the subsection that covers this in
Chapter 2, since this technique is sometimes used in GUI programming.


There are also Python bindings for the older Qt 3 library, but there is no reason to use that library
for new projects, especially since Qt 4 offers far more functionality and is easier to use.
4 Introduction

Part II begins by showing three tiny PyQt GUI applications to give an initial
impression of what PyQt programming is like. It also explains some of the
fundamental concepts involved in GUI programming, including PyQt’s high-
level signals and slots communication mechanism. Chapter 5 shows how to
create dialogs and how to create and lay out widgets (“controls” in Windows-
speak—the graphical elements that make up a user interface such as buttons,
listboxes, and such) in a dialog. Dialogs are central to GUI programming: Most
GUI applications have a single main window, and dozens or scores of dialogs,
so this topic is covered in depth.
After the dialogs chapter comes Chapter 6, which covers main windows,
including menus, toolbars, dock windows, and keyboard shortcuts, as well as
loading and saving application settings. Part II’s final chapters show how to
create dialogs using Qt Designer, Qt’s visual design tool, and how to save data
in binary, text, and XML formats.
Part III gives deeper coverage of some of the topics covered in Part II, and in-
troduces many new topics. Chapter 9 shows how to lay out widgets in quite
sophisticated ways, and how to handle multiple documents. Chapter 10 covers
low-level event handlers, and how to use the clipboard as well as drag and drop,
text, HTML, and binary data. Chapter 11 shows how to modify and subclass
existing widgets, and how to create entirely new widgets from scratch, with
complete control over their appearance and behavior. This chapter also shows
how to do basic graphics. Chapter 12 shows how to use Qt 4.2’s new graphics
view architecture, which is particularly suited to handling large numbers of in-
dependent graphical objects. Qt’s HTML-capable rich text engine is covered in
Chapter 13. This chapter also covers printing both to paper and to PDF files.
Part III concludes with two chapters on model/view programming: Chapter 14
introduces the subject and shows how to use Qt’s built-in views and how to
create custom data models and custom delegates, and Chapter 15 shows how
to use the model/view architecture to perform database programming.
Part IV continues the model/view theme, with coverage of three different
advanced model/view topics in Chapter 16. The first section of Chapter 17
describes the techniques that can be used for providing online help, and the
second section explains how to internationalize an application, including how
to use Qt’s translation tools to create translation files. The Python standard
library provides its own classes for networking and for threading, but in the
last two chapters of Part IV we show how to do networking and threading us-
ing PyQt’s classes.
Appendix A explains where Python, PyQt, and Qt can be obtained, and how to
install them on Windows, Mac OS X, and Linux. PyQt is much easier to learn
if you install it and try out some of the exercises, and if you inspect some of
the example code. Appendix B presents screenshots and brief descriptions
of selected PyQt widgets; this is helpful for those new to GUI programming.
Appendix C presents diagrams of some of PyQt’s key class hierarchies; this
Introduction 5

is useful for getting to know what classes PyQt has to offer and how they
are related.
If you have never used Python before, you should begin by reading Chapters
1–6 in order. If you already know Python, at least read the string policy (in
bullet points on page 28), and skim the material in Chapter 2 (apart from the
first section, which you’ll know well). Make sure that you are comfortable with
lambda and partial function application, both of which are covered in Chapter 2.
It is probably also worth skimming Chapter 3 as well. Then read Chapters 4,
5, and 6 in order.
Once you have covered the first six chapters, you have covered the essentials
of Python and the fundamentals of PyQt.
Chapter 7 is useful if you want to know how to create dialogs using a visual
design tool rather than purely by hand coding, something that can save a lot
of time. For file handling, at least read the first three sections of Chapter 8. If
you plan to write and read text files, also read Chapter 8’s fourth section, and
similarly the fifth section if you are going to use XML files.
For Part III, at the least read Chapter 10’s first section, on event handling, and
all of Chapter 11. Chapter 12 and the first section of Chapter 13 assume that
you have read about PyQt’s event handling, and that you have read Chapter 11.
Chapters 9 and 14 can be read stand-alone in this part, but Chapter 15 assumes
that you have read Chapter 14.
In Part IV, Chapter 16 assumes that you have read Chapters 14 and 15, but the
other chapters can be read independently.
If you find errors in the text or in the examples, or have other comments,
please write to [email protected] quoting “PyQt book” in the subject line. The
book’s home page, where any corrections will be published, and from where the
examples and exercise solutions can be downloaded, is http://www.qtrac.eu/
pyqtbook.html.
If you want to participate in the PyQt community, it is worthwhile joining the
mailing list. Go to http://www.riverbankcomputing.com/mailman/listinfo/pyqt to
find a link to the archive, so that you can see what the mailing list is like, and
also for a form for joining. Python also has mailing lists and other community
activities. For these, go to http://www.python.org/community.

Acknowledgments

I have many people to thank, and I will begin with those who have been
intimately involved with the book.
Jasmin Blanchette is a senior software developer at Trolltech, a Qt expert, and
a fine editor and writer in his own right. I have cowritten two C++/Qt books
with him. Jasmin has made a huge number of suggestions and criticisms that
have immensely improved the quality of this book.
6 Introduction

David Boddie, Trolltech’s documentation manager, is an active PyQt open


source developer who has made many contributions to PyQt itself. His input
has helped ensure that I have covered everything necessary, and done so in a
sensible order.
Richard Chamberlain is cofounder and chief technology officer of Jadu Ltd., a
content management company. His feedback and insights have helped ensure
that the book is as broadly accessible as possible. He has also helped refine and
improve the code used in the examples and exercises.
Trenton Schulz is a Trolltech developer who has been a valuable reviewer of
my previous books. For this book, he has brought his Python and Qt knowledge
to bear, giving considerable feedback on the manuscript. Along with Richard,
he also ensured that Mac OS X users were never forgotten. In addition, he
spotted many subtle errors that I had missed.
Phil Thompson is PyQt’s creator and maintainer. He has been supportive of
the book from the start, even adding features and improvements to PyQt as
a direct result of discussions we have had regarding the book. He has made
numerous suggestions for the book’s improvement, and corrected many
mistakes and misunderstandings.
Special thanks to Samuel Rolland, who let me loose on his Mac laptop, to install
PyQt, test the examples, and take screenshots.
Thanks are also due to Guido van Rossum, creator of Python, as well as to the
wider Python community who have contributed so much to make Python, and
especially its libraries, so useful and enjoyable to use.
Thanks also to Trolltech, for developing and maintaining Qt, and in particular
to the Trolltech developers both past and present, many of whom I have had
the pleasure of working with, and who ensure that Qt is the best cross-platform
GUI development framework in existence.
Particular thanks to Jeff Kingston, creator of the Lout typesetting language.
I use Lout for all my books and for most of my other writing projects. Over
the years, Jeff has made many improvements and added numerous features to
Lout in response to feedback from users, including many that I have asked for
myself. Thanks also to James Cloos who created the condensed version of the
DejaVu Sans Mono font (itself derived from Jim Lyles’ Vera font) from which
this book’s monospaced font is derived.
The publisher, in the person of Editor-in-Chief Karen Gettman, was supportive
of this book from the very beginning. And special thanks to my editor, Debra
Williams-Cauley, for her support, and for making the entire process as smooth
as possible. Thanks also to Lara Wysong who managed the production process
so well, and to the proofreader, Audrey Doyle, who did such fine work.
Last but not least, I want to acknowledge my wife, Andrea. Her love, loyalty,
and support always give me strength and hope.
Part I

Python Programming
This page intentionally left blank
1
● Executing Python Code
● Variables and Objects
● Numbers and Strings
● Collections
● Built-in Functions

Data Types and Data Structures


In this chapter, we begin a Python conversion course that shows non-Python
programmers how to program with Python. We introduce some fundamental
data types and data structures, as well as some of Python’s procedural syntax.
The approach taken throughout is to emphasize realistic code like that used
in practice, rather than giving the formal definitions and explanations that
are already available in the documentation that is supplied with Python and
available online at http://www.python.org.

Figure 1.1 The IDLE Python Shell window

If you have not already installed Python and PyQt, it would be a good idea to
do so: That way you will be able to try out the examples that accompany this
book (downloadable from http://www.qtrac.eu/pyqtbook.html). See Appendix A
for installation details. One advantage of installing the software is that the
IDLE integrated development environment is installed along with Python.

9
10 Chapter 1. Data Types and Data Structures
Introduction

The IDLE Development Environment


The full installation of Python includes IDLE, a basic but very use-
ful integrated development environment. When IDLE is launched (click
Start→All Programs→Python 2.x→IDLE on Windows, or click Finder→Applica-
tions→MacPython 2.x→IDLE on Mac OS X, or run idle & in a console on Linux),
it presents its Python Shell window.
As the screenshot in Figure 1.1 shows, IDLE has a rather retro Windows 95
look. This is because it is written in Tkinter rather than in PyQt. We’ve
chosen to use IDLE because IDLE comes as standard with Python and is
very simple to learn and use. If you want to use a much more powerful and
modern-looking IDE, you might prefer Eric4 which is written in PyQt, or
one of the other Python IDEs that are available. However, if you are new to
Python, we recommend that you start out with the simpler IDLE, and once
you are more experienced with PyQt, then trying the other IDEs to see if you
prefer one of them. And of course, you could simply use a plain text editor
and debug using print statements and not use an IDE at all.
IDLE provides three key facilities: the ability to enter Python expressions
and code and to see the results directly in the Python Shell; a code editor
that provides Python-specific color syntax highlighting; and a debugger
that can be used to step through code to help identify and kill bugs. The
Python Shell is especially useful for trying out simple algorithms, snippets
of code, and regular expressions, and can also be used as a very powerful and
flexible calculator.

Executing Python Code


Before we can really explore the Python language we need to know how to
execute Python code. We will show this by reviewing a tiny example program
that is just one line long.
We must use a plain text editor for working with Python files.★ On Windows it
is possible to use Notepad, but IDLE includes a suitable Python editor designed
specifically for editing Python code: Simply start IDLE and then click File→New
Window.

We will type the following line into a file, called hello.py:

print "Hello World"

Note that no semicolon is necessary: In Python newline acts as a statement


separator. Also, we do not need a newline, “\n”, in the string, since print
automatically adds a newline unless we suppress it with a trailing comma.


The programs in this book are written using ASCII characters, with escape sequences where Uni-
code is required. It is possible to use Latin-1, UTF-8, or other encodings for strings and comments
in Python programs, as explained in the documentation under “Encoding declarations”.
Executing Python Code 11

Assuming that we have saved the code in the file hello.py (in the directory
C:\pyqt\chap01 if using Windows), we can start up a console (click Start→All Pro-
grams→Accessories→Console on Windows XP—sometimes Console is called Com-
mand Prompt; or run Terminal.app from /Applications/Utilities on Mac OS X),
change to that directory, and execute the program like this:

C:\>cd c:\pyqt\chap01
C:\pyqt\chap01>hello.py

As long as Python is correctly installed, Windows will recognize the .py file
extension and give the file to python.exe to execute. The program will print
“Hello World” on the console as we would expect.★
On Mac OS X and Linux we must explicitly run the interpreter by typing its
name and the file’s name at the console’s prompt, like this:

% python hello.py

This will work providing that Python is installed and in your PATH. Alternative-
ly, for Linux and Mac OS X, we can add an additional “shebang” (shell execute)
comment line which tells the operating system to use a Python interpreter,
making the hello.py file two lines long:

#!/usr/bin/env python
print "Hello World"

For this to work on Mac OS X and Linux, the file’s permissions must be set
correctly. For example, at the console prompt in the same directory as the file,
enter chmod +x hello.py to make the file executable.
Python comments start with “#” and continue until the end of the line. This
means that it is perfectly safe to add the “shebang” line to all Python programs,
since the comment is ignored on Windows but on Linux it tells the operating
system to execute the file using a Python interpreter. Appendix A shows how
to associate the Python interpreter with .py and .pyw files on Mac OS X.
When we speak of executing a Python program, what happens behind the
scenes is that Python reads the .py (or .pyw) file into memory, and parses it, to
get a bytecode program that it then goes on to execute. For each module that is
imported by the program, Python first checks to see whether there is a precom-
piled bytecode version (in a .pyo or .pyc file) that has a timestamp which corre-
sponds to its .py file. If there is, Python uses the bytecode version; otherwise, it
parses the module’s .py file, saves it into a .pyc file, and uses the bytecode it just
generated. So, unlike Java, we don’t have to explicitly bytecode-compile any
modules, whether they are supplied with Python or are ones we have written
ourselves. And in most Python installations, the supplied modules are com-


Mac OS X users note that whenever we refer to a console, this is the same as a Mac Terminal.
12 Chapter 1. Data Types and Data Structures

piled as part of the installation process so as to avoid having to compile them


whenever a Python application that uses them is run.

Variables and Objects


In most programming languages, including C++ and Java, we must declare
each variable, specifying its type, before it can be used. This is called static
typing, because the compiler knows at compile time what type each variable is.
Python, like most very high level languages, uses a different approach: Vari-
ables have no type restrictions (dynamic typing), and they don’t need to be
declared.
We could learn about Python’s variables and identifiers by creating and
executing a file, as we did with hello.py in the preceding section. But for trying
out small code snippets we don’t need to create a file at all. We can just enter
the lines directly in the IDLE Python Shell window at the >>> prompt:

>>> x = 71
>>> y = "Dove"

The whitespace around the assignment operator = is optional but is included


because it makes the code easier to read. As a matter of style we will always
put one space before and after binary operators. On the other hand, it is
important that each statement occupies its own line and has no extraneous
leading whitespace. This is because Python uses indentation and line breaks
to signify its block structure, rather than the braces and semicolons used by
many other programming languages.
Now we are ready to review what the two lines actually do. The first line
creates an object of type int and binds the name x to it.★ The second line creates
an object of type str (an 8-bit string type) and binds the name y to it.
Some Python programmers refer to names (such as the x and y used earlier),
as object references since they refer to objects rather than being objects in their
own right. For basic data types like int and str it makes no difference whether
we see their variables as “objects” or as “object references”; they behave in the
same way as they do in other programming languages:

>>> x = 82
>>> x += 7
>>> x
89

Later on we will see cases where the fact that Python variables are object Lists
references makes a difference. ☞ 31


This is similar to the Java assignment, Integer x = new Integer(71); for C++ a near-equivalent
would be int xd = 71; int &x = xd;.
Random documents with unrelated
content Scribd suggests to you:
Abner truly told me I was beginning at the wrong end when I first
spoke to him long ago. I did not understand him then, but I begin to
do so now. I may never see things clearly, as you do, in the heavenly
light; but at least I do see that our first aim and object must be to do
God’s work on earth in His way; not blinded by our own wishes and
ambitions. The fate of poor Saul Tresithny will always be a warning
and a landmark to me. He might have grown as wild and reckless
without my teaching—with that I have nothing to do—but I did teach
him dangerous doctrines of all sorts, and his life and death are a
standing memorial to me of what such teaching may lead to. I trust
the lesson has not been learned in vain.”
“And I think his death was a very happy one,” said Bride softly. “I
think I am glad he died with us alone. He loved you, Eustace. And I
am sure if any of us had our choice, we should always choose to be
with the being we love best at the moment of our death. It was so
with him. I think it was rather beautiful and wonderful how he rose
and came to you when the hand of death was upon him. Poor Saul!
—but we need not grieve for him. Abner has ceased to grieve, and is
more peaceful and happy than I have seen him for many years. ‘To
depart and be with Christ’ was so much better for him than anything
he had to expect upon earth. He learned his lesson at the last—I am
sure his end was peace.”
After that there was no reserve on any subject between Eustace and
his betrothed wife. Bride was able to speak to him from the very
depths of her heart, and as she elevated and strengthened his
spiritual perceptions, so did he in another fashion impart to her such
knowledge of the things of this world as were beneficial to her in
forming her mind and character, and helping her to obtain a just and
accurate outlook upon the affairs of the nation and the events
moving the hearts of men. They acted as a check one upon the
other; helping, strengthening, teaching, and encouraging—growing
every day nearer in love and in spirit, finding fresh happiness and
closer unity of soul each day as it passed, and always upheld by the
thought that a few days more would see their union hallowed and
blessed in the sight of God—a thought so unspeakably sweet and
precious to both that they seldom spoke of it, though it was never
altogether out of their thoughts.
Mr. St. Aubyn was to perform the ceremony, with the cordial consent
of Mr. Tremodart, who was glad to be spared the task himself. The
Rector of St. Erme had been much at the castle when Eustace lay in
so critical a state, and the young man had profited much from his
instruction and counsel. Now he came frequently to see both Bride
and her betrothed husband, for he was one of those who rejoice to
see true spirituality in all its forms, and to be certain before hearing
pronounced any solemn and binding vows that they are spoken from
the very heart.
The Duke went about looking very happy in those days, and his
manner to his daughter was more gentle and fatherly than it had
ever been before. The whole castle was in a subdued state of
excitement, whilst a lawyer from London arrived, who was to remain
till the completion of the ceremony and see to all the needful papers.
But with these things Bride felt little concern, and went about with a
tranquil face, thankful to be spared the bustle of preparation which
would have been needful under ordinary circumstances, but which
was quite superfluous now.
A bridal dress and veil were, however, quickly provided, and Bride
was content that it should be so, knowing that her white would be
pleasing to the eye of the sick man. She herself was calmly and
tranquilly happy, spending much time beside the patient, and the rest
in earnest musings and meditation, or in visits to the poor, amongst
whom so much of her life had been passed.
It was a clear, sunny morning toward the end of January when Bride
awoke with the consciousness that it was her wedding-day—though
so quiet and uneventful a wedding as was to be hers perhaps no
Duke’s daughter had yet known. Even her name would not be
changed, as Eustace had playfully told her, nor would she leave the
shelter of her father’s roof. All the change that would take place
would be that she and her husband would take up their quarters in a
suite of rooms specially prepared for them, with Bride’s nurse and
Eustace’s man for their especial attendants. But the young wife
would continue to take her place at her father’s table when he took
his meals, waiting upon her husband and sharing his at different
hours, such hours as were prescribed by his medical man. Although
all this sounded strange to outsiders, who heard with amaze that
Lady Bride was going to marry her father’s heir while he was still
crippled and helpless, it did not seem strange to her. Others said it
was an obvious marriage of convenience and diplomacy, but never
had been a marriage of purer and truer affection. Bride robed herself
with a happy heart and a serene face, and was not surprised to
receive a message at the last that Abner would much like a few
words with his young mistress, if she could spare them for him.
He was in the great conservatory when she went down—the place
where so many talks had taken place between them, and where
Bride pictured Eustace lying in comfort and pleasure before very
long, surrounded by sweet scents and beautiful blossoms. Abner
held in his hand a beautiful bouquet of white flowers, and Bride
thanked him with one of her sweetest smiles as she took it from his
hands.
“I did want to see yu my own self, my Ladybird,” he said in a voice
that shook a little, “to wish yu every joy and a blessing on your new
life. I know there will be a blessing on it, for there’s One above as
has yu very near His heart; but yu’ll let an old man as has loved yu
ever since yu were a babe in the nurse’s arms give yu his blessing
to-day.”
Bride held out her slim white hand, which the old man took and
carried very tenderly to his lips; and her voice shook a little as she
said, “Thank you for that blessing, Abner. I feel my heart the warmer
for it. We know that this world’s happiness is but a small thing
compared to the glory that is to be revealed; but yet we must be
thankful when it does come to us, and take it as God’s best gift. I
think that your heart is at peace now, and that your worst trouble is
laid at rest.”
“Bless the Lord—it is so indeed. My boy died with His name on his
lips. I couldn’t ask more for myself.”
Bride could not linger. Mr. St. Aubyn had already arrived and wished
to speak with her alone. She found him pacing the room with slow
and thoughtful mien, but his eyes were very bright and glad.
“My child,” he said softly, “I wished to speak with you a few moments
before we go upstairs. I have just been seeing him you are to wed.
My dear, I think I need not say all that I feel about the change I find in
him since first I knew him. I can pronounce the benediction of holy
matrimony over you two with a glad and thankful heart. In the sight of
man and of God such a union as yours must be holy indeed.”
Bride’s eyes were softly bright.
“I know we love one another,” she said softly, “but I think that the
love of God comes first—indeed, I trust it is so.”
“I believe so truly,” he answered; “and, my child, I have been talking
to-day to Eustace. He has long been hindered by sickness from the
ordinances of the Church—the most blessed ordinance instituted by
our Lord for His faithful people to follow until His coming again.
Before that, as you know, he was something slack and doubtful, and
did not avail himself of the Christian privileges in their fullest
measure; and it is long since he has partaken of the bread and wine
blessed in the name of the Lord. And he wishes now that he may
receive this Holy Communion with you—his newly wedded wife—so
soon as you are made one. I indeed have thankfully and joyfully
assented to this, and even now the room is being prepared for the
simple ceremony which shall make you his, and then you can
together partake of that Body and Blood—the sign and symbol of the
Ineffable Love. I am sure, my child, that your heart will rejoice, as
mine does, over this return of the lost sheep to the fold. We have
known for long that that son has been turning homewards, and that
the Father has gone forth to meet him. Now we shall see him at the
Father’s table, partaking of the mystical feast which it is our Christian
privilege to enjoy. ‘Do this in remembrance of Me.’ It will, I know, be a
joyous thing for you that the following of this gracious and simple
command shall be the first act of your married life.”
Tears were standing in Bride’s soft eyes. She put out her hand and
laid it on Mr. St. Aubyn’s arm.
“I am too happy to talk about it,” she said; “it is the one thing to make
the day complete; but oh! Mr. St. Aubyn, I have so often wanted to
thank you for what you said to me that day long ago about the lost
son and the returning home. It was such a help. It was that which
made me begin to pray in hope for Eustace, instead of naming him
only in a sort of faithless despondency. I was in danger of being like
the elder brother, and looking upon him and many others as
altogether beyond the pale of the Father’s love. After that I could
always pray in hope; and I think—I believe, that my prayers did help
him. You know what you said about that being God’s way of leading
to Him some one who would not yet pray for himself.”
The clergyman smiled tenderly upon the girl.
“God bless you, my child,” he said softly. “I think you will be your
mother over again as the years go by. Such faith as hers I have
never seen in any one else, but I think I shall live to see it in you.”
“I have received so much,” answered Bride softly, “I should not be
able to doubt even if I wished.”
Only a few minutes later, and Bride entered the room where Eustace
lay, leaning on her father’s arm, her face shaded by her veil, but not
so concealed that its serene beauty and composure could not be
seen. Some dozen of the old servants of the castle, and two or three
old friends, were present to witness the simple ceremony; but Bride
only saw Eustace; and none who caught the glance that flashed from
one to the other ever forgot it. The room was decked with flowers,
everything was perfectly simple, yet perfectly appropriate, and Mr.
St. Aubyn’s rendering of the holy words was doubly impressive from
the peculiar circumstances of the case. Bride’s vows were spoken
with a steady sweetness which brought tears to many eyes; all the
faltering was on Eustace’s part, and was made through the depth of
his emotion. It was a strangely simple yet strangely impressive
wedding, never forgotten by those who saw it. When all was spoken
that was needed to make them man and wife, Bride stooped and
kissed her husband, without a thought of any who stood by, and they
heard the passionate intensity of love in the voice that responded—
“My Bride—my wife!”
CHAPTER XXIV
CONCLUSION
BRIDE was riding homewards from Pentreath to the castle on a
sunny day early in June. The sound of joy-bells was in the air, the
faces of men were glad and triumphant, all nature seemed in tune
with the general rejoicing which some recent event had plainly set on
foot; and the young wife’s face was glad, too, though thoughtfully
and temperately. For she knew that the news of which she was the
bearer would gladden the heart of her husband, though it would not
be to him now that source of triumphant exhilaration which it would
have been a year before.
Behind her rode the servant with a bag full of papers at his saddle-
bow. It was these letters and newspapers which had been the object
of Bride’s ride that day. Her husband had persuaded her to go
herself on the chance of news; he was always glad to make an
excuse to induce her to take the amount of needful air and exercise
which was good for her health, and she always found it so hard to
leave him.
But to-day she had been persuaded, and was now riding rapidly
homewards with her budget of news, knowing how impatiently her
husband and father at home would be awaiting her return.
Dismounting at the castle door, and taking the bag from the hands of
the servant, she passed hastily through hall and corridor into the
great conservatory, where Eustace was now daily wheeled upon his
couch. Since the beginning of May he had been taken down to a
ground-floor room in the wing which he and his wife occupied, in
order that, when possible, he might be taken out of doors, or into this
pleasant place of flowers. He had made as much progress as the
most sanguine could hope for during the past months, and recovery
was considered now only a matter of time and patience. Time and
patience were the only doctors for such a case as his, and Eustace
surprised all who came in contact with him by the extreme patience
and cheerfulness he showed under a condition of helplessness so
trying to youthful manhood; but he would say, with a smile, that Bride
made life too sweet for him for any repining to be possible. Each day
he found filled with happiness—the happiness of her presence, and
of that full community of soul which made their union what it was.
Every day brought its own measure of temporal happiness and
spiritual growth; and though the young man looked forward with
ardent expectation to the hope of being able to fight the battle of life
once more, and work in the service of his fellow-men, he recognised
fully and freely that this period of enforced idleness had been sent
him by the Father in mercy and love, and was resolved that the
lesson it was sent to teach him should not be learnt in vain.
The way in which his face kindled at the sight of his wife was a sight
good to see. She came quickly forward, bent over and kissed him,
and said softly—
“It is good news, Eustace. The Lords have passed the bill!”
“Ah!” he said, and drew a long breath. “I felt it would be so when the
King was obliged to recall Lord Grey. All parties must have known
then that the mind of the country was made up, and that the thing
was right, and must be made law. Have you read the news?”
“No; I only heard what they were all saying in Pentreath. I met many
friends, and they all told me something. The Duke of Wellington,
when he found the King would create enough new peers to pass the
bill, if that was the only resource left, retired from his place in the
House, and, some say, will retire from public life altogether. Lord
Wharncliffe and his party of waverers came over at once to the side
of Lord Grey, and so the bill was passed at once. The people are
wild with delight, the bells are being rung, and bonfires are being
built up. I sometimes wonder whether they really understand what it
is that they rejoice at. They seem to think that some wonderfully
good time is coming for them. Poor creatures! I fear they will be
disappointed. An act of constitutional justice has been done; but the
troubles of England lie far, far deeper than an imperfect system of
constitutional representation.”
Eustace was eagerly skimming the contents of newspapers and
private letters, and from time to time giving bits of information to his
wife; but the sense of her words came home to his mind for all that,
and by-and-bye, laying down the papers, he said—
“That is only too true, Bride. That is the very point upon which my
eyes have been opened latterly. I used to think that good
government and pure government was the backbone of a nation’s
prosperity and well-being—as in one sense of the word it is. I mean,
that if all men were doing their utmost to walk in the ways appointed
by God, we should have a pure and good government, and the
nation would prosper. But I see only too clearly now that I was quite
deceived in my old belief that this country and the world can ever be
renovated and made good by any scheme of political reform
instituted by man. We may do our best to be just and temperate, to
act uprightly, and think impartially of the interests of all classes; but
that alone will never raise them, never give them true happiness,
never lift them out of the degradation into which they, as well as too
many of us so-called ‘superiors,’ have fallen. There is only one
Power which can do that, only one Power mighty enough for that
task, and that is the Power of which I fear that we, as a nation of
politicians and upright rulers, think singularly little. The time may
come when we shall awake to the remembrance that God must be
Ruler in the earth if right and justice and equity are to be done; but at
present, though we listen to such words with approval from the
pulpit, we are absolutely ignorant how to put them into daily practice,
and our profession and practice are utterly at variance. That is where
our failure comes in, and where I, for one, foresee failure all along
the line. This bill may be the inauguration of an enlightened and
liberal policy for the next generation; but my old hope of seeing the
world raised out of its misery, its degradation, its wickedness by any
such means, is fading fast within me.”
Bride was silent for a while, looking out before her with a sweet sad
smile upon her fair face.
“It will not be achieved by such means,” she said quietly at last; “and
yet, if men would but look to the Lord for help and deliverance, I truly
believe He would show us the perfect way, and restore to us those
things which are lacking in the order of our daily lives, of our worship,
of our government. We know that the powers that be are ordained of
God; but we have lost so much of His guidance. Yet I verily believe
that if men would with one voice and one heart cry to Him for light
and guidance, He would send it to them, even as in days of old. Is
He not the same yesterday, to-day, and for ever? Though we have
forsaken Him, yet He has not forsaken us. As He spoke by holy men
of old, moved by His Spirit, so I truly believe He would speak again
had men but faith to listen. But it is that which is always the
stumbling-block—the hindrance. Men have lost their faith; they will
not believe that God is still amongst them, even as of old—nay, far
more truly and nearly than of old; for Christ is the living Head of His
Church, and all who believe and are baptized are very members of
His mystical Body. And yet we say He is far away, He has passed
into the heavens, He is no more working with and amongst us, save
through the workings of the Spirit in our hearts. But I feel so very,
very sure that, would we let Him, He would fain be much more to us
than that, as indeed He will be one day—in the day when the
Kingdom shall be set up on earth.”
Eustace drew a long breath. He, too, lying there in helplessness, and
seeing much of the brightness of his early visions fade into dimness
as he watched the course of events and learned to see more of the
workings of this world, had come to think with a great longing of the
coming Kingdom, when all that is vile and evil shall be done away,
and when Christ Himself shall be revealed and rule in righteousness.
Once that thought had seemed to him as the veriest vision of the
mystic; now he had come to long for it himself with a great and
increasing longing. Loving his fellow-men as he did, he yet loved the
Lord more; and to see Him reigning over the world, and the misery
and the sin all done away, was a prospect too bright and happy not
to excite his ardent longings. Even in his satisfaction at the news just
brought, he could yet think with calm hopefulness of the time when
the crooked things should be made straight, and the rough places
plain, and men should live together in peace and love, and strivings
and hatred should be done away.
“And until that day comes,” he said softly at last, “we shall do more to
help our brethren by teaching them to look for the Kingdom of God
and of His Christ, than by stirring up in their hearts desires after
earthly good which perhaps may never be theirs.”
Bride looked up with a sweet smile.
“Ah! that is just what I feel about it, Eustace; let us do all that is right
for them, but teach them to strive after contentment and love of God
themselves. That is the only thing that will really raise them or make
them truly happy.”
“Seek ye first——” said Eustace musingly, not finishing the
quotation, for there was no need. “After all, that is the best and
highest wisdom, though for eighteen hundred years men have had
the answer to their strivings and heart-burnings under their hand,
and have not known how to use it. You must help me, sweet wife, in
the future, when I go forth, as I trust by God’s mercy I may, to take
my place in the battle of life, and stand up for the right and the truth,
as I may be called upon to do, to bear in mind that great precept, for
without it we can accomplish nothing.”
Bride gave him an eloquent glance, but made no reply, for her father
was coming in, anxious to know the news.
She told her tale once more, and the papers were read and
discussed between the two men with eager interest. It was strange
how, by almost imperceptible degrees, those two had drawn together
—not entirely in opinion, but in mutual understanding and sympathy,
so that differences of opinion seemed trifles. Now it was real
pleasure to both to be together; and though they still argued and
disputed, it was in a spirit of toleration and mutual respect and liking
which made such argument pleasant and stimulating rather than
irritating. The Duke took a more despondent view of the future of the
country than Eustace, and had far less confidence in the success of
the coming era of more liberal principles of government for
redressing wrongs and bringing about a lasting state of prosperity
and peace; but then Eustace was far less sanguine about the
coming Utopia, far more patient and reasonable when existing
wrongs were discussed, far less confident in the powers of
legislation for the elevation of mankind than he once had been. Like
many other ardent young dreamers in the forefront of the battle of
reform, he had practically left out of his calculations the mystery of
original sin—the inherent corruption of men’s hearts, and their
perversity of vision, their determination to do evil until their eyes are
opened to see God’s dealings in all things, and their hearts are
purified by the Holy Spirit. No system, however perfect, will ever
make men righteous that does not first lead them to God. It was this
that Eustace had never realised before when he sought to raise men
by increased prosperity, and wiser and more just legislation. Now he
had begun to see the futility of his former dreams, and insensibly he
grew to sympathise with the feelings of his kinsman, who had lived
through so many crises of the world’s history, but had found at the
end that human nature was never changed, and that no era of bliss
and joy followed upon the violent efforts made to secure a better
order of things.
Leaving them to talk thus together and to discuss the situation to
their hearts’ content, Bride stole away into the garden, and wandered
along some of the shady paths, thinking her own thoughts, and filled
with a sense of profound thankfulness and joy in the unity of spirit
now existing between herself and her husband. It was the same daily
joy to her that it was to him, and her heart was charged with a peace
and restful content that sometimes seemed to her to be a foretaste
of the Kingdom itself, towards which her heart was always turning.
In one of the alleys of the rose-garden she came upon Abner, who
was tying up the young shoots upon the arch, and picking off the
dead blossoms. He welcomed her with the smile that the sight of her
always called up in his eyes, and stood still with a face full of interest
whilst she told him the news.
“Well, well, well,” he said when she had done, “may be it’ll be a good
thing. It sounds just, and right, and reasonable; but I don’t
understand these big matters, and there’s a deal to be said on both
sides, so far as I can see. My poor boy would have been pleased.
He was terrible set on it; but I used to think that when he got it, he
would find himself as discontented as ever, and set off after some
new teacher who would tell him this was only the beginning of what
men must demand. May be he sees things clearer now. I sometimes
think we’ll know a deal better what to think of such matters once we
are free of the burden of the sinful flesh. But there’s always comfort
in the thought that the Lord’s working in one way or another in all
these things. He sees the fulfilment of His purpose all through,
though we can’t. That’s what I comfort myself with when things seem
blackest. The frost and the snow, the biting winds and the storms, all
seem against the gardener; but by-and-bye he sees they all have
their use, and his plants would not have done as well without them. I
always go back to that when I’m perplexed and worried. The great
Gardener will bring out His perfected garden on the earth in time;
and it should be enough for us to be trying to help Him on in our little
corner, without thinking He can’t rule the world without us.”
Bride smiled as she answered softly—
“Yes; though perhaps He wants to use some of us for great tasks, as
He uses us all for little ones. But I know what you mean, Abner, and I
feel with you. We can never fully understand God’s purposes till they
are revealed to us in His perfect Kingdom; but we can all strive to
live the life of the Kingdom here below, as far as our sinful natures
will let us, and try to make just the little corner about us bear flowers
and fruit, as a garden should. I do not think we shall be called upon
for any great work. I think our lot will lie here, away in the west, in
this little place. But, for my part, I shall be content if we can bring the
hope and the life of the Kingdom into just this little corner of the
vineyard—to our sisters and brothers of St. Bride’s Bay.”
THE END
TRANSCRIBER’S NOTES:
Obvious typographical errors have been corrected.
Inconsistencies in hyphenation have been
standardized.
Archaic or variant spelling has been retained.
The cover image for this eBook was created by the
transcriber using the original cover as the background
and is entered into the public domain.
*** END OF THE PROJECT GUTENBERG EBOOK EUSTACE
MARCHMONT: A FRIEND OF THE PEOPLE ***

Updated editions will replace the previous one—the old editions


will be renamed.

Creating the works from print editions not protected by U.S.


copyright law means that no one owns a United States copyright
in these works, so the Foundation (and you!) can copy and
distribute it in the United States without permission and without
paying copyright royalties. Special rules, set forth in the General
Terms of Use part of this license, apply to copying and
distributing Project Gutenberg™ electronic works to protect the
PROJECT GUTENBERG™ concept and trademark. Project
Gutenberg is a registered trademark, and may not be used if
you charge for an eBook, except by following the terms of the
trademark license, including paying royalties for use of the
Project Gutenberg trademark. If you do not charge anything for
copies of this eBook, complying with the trademark license is
very easy. You may use this eBook for nearly any purpose such
as creation of derivative works, reports, performances and
research. Project Gutenberg eBooks may be modified and
printed and given away—you may do practically ANYTHING in
the United States with eBooks not protected by U.S. copyright
law. Redistribution is subject to the trademark license, especially
commercial redistribution.

START: FULL LICENSE


THE FULL PROJECT GUTENBERG LICENSE
PLEASE READ THIS BEFORE YOU DISTRIBUTE OR USE THIS WORK

To protect the Project Gutenberg™ mission of promoting the


free distribution of electronic works, by using or distributing this
work (or any other work associated in any way with the phrase
“Project Gutenberg”), you agree to comply with all the terms of
the Full Project Gutenberg™ License available with this file or
online at www.gutenberg.org/license.

Section 1. General Terms of Use and


Redistributing Project Gutenberg™
electronic works
1.A. By reading or using any part of this Project Gutenberg™
electronic work, you indicate that you have read, understand,
agree to and accept all the terms of this license and intellectual
property (trademark/copyright) agreement. If you do not agree to
abide by all the terms of this agreement, you must cease using
and return or destroy all copies of Project Gutenberg™
electronic works in your possession. If you paid a fee for
obtaining a copy of or access to a Project Gutenberg™
electronic work and you do not agree to be bound by the terms
of this agreement, you may obtain a refund from the person or
entity to whom you paid the fee as set forth in paragraph 1.E.8.

1.B. “Project Gutenberg” is a registered trademark. It may only


be used on or associated in any way with an electronic work by
people who agree to be bound by the terms of this agreement.
There are a few things that you can do with most Project
Gutenberg™ electronic works even without complying with the
full terms of this agreement. See paragraph 1.C below. There
are a lot of things you can do with Project Gutenberg™
electronic works if you follow the terms of this agreement and
help preserve free future access to Project Gutenberg™
electronic works. See paragraph 1.E below.
1.C. The Project Gutenberg Literary Archive Foundation (“the
Foundation” or PGLAF), owns a compilation copyright in the
collection of Project Gutenberg™ electronic works. Nearly all the
individual works in the collection are in the public domain in the
United States. If an individual work is unprotected by copyright
law in the United States and you are located in the United
States, we do not claim a right to prevent you from copying,
distributing, performing, displaying or creating derivative works
based on the work as long as all references to Project
Gutenberg are removed. Of course, we hope that you will
support the Project Gutenberg™ mission of promoting free
access to electronic works by freely sharing Project
Gutenberg™ works in compliance with the terms of this
agreement for keeping the Project Gutenberg™ name
associated with the work. You can easily comply with the terms
of this agreement by keeping this work in the same format with
its attached full Project Gutenberg™ License when you share it
without charge with others.

1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside
the United States, check the laws of your country in addition to
the terms of this agreement before downloading, copying,
displaying, performing, distributing or creating derivative works
based on this work or any other Project Gutenberg™ work. The
Foundation makes no representations concerning the copyright
status of any work in any country other than the United States.

1.E. Unless you have removed all references to Project


Gutenberg:

1.E.1. The following sentence, with active links to, or other


immediate access to, the full Project Gutenberg™ License must
appear prominently whenever any copy of a Project
Gutenberg™ work (any work on which the phrase “Project
Gutenberg” appears, or with which the phrase “Project
Gutenberg” is associated) is accessed, displayed, performed,
viewed, copied or distributed:

This eBook is for the use of anyone anywhere in the United


States and most other parts of the world at no cost and with
almost no restrictions whatsoever. You may copy it, give it
away or re-use it under the terms of the Project Gutenberg
License included with this eBook or online at
www.gutenberg.org. If you are not located in the United
States, you will have to check the laws of the country where
you are located before using this eBook.

1.E.2. If an individual Project Gutenberg™ electronic work is


derived from texts not protected by U.S. copyright law (does not
contain a notice indicating that it is posted with permission of the
copyright holder), the work can be copied and distributed to
anyone in the United States without paying any fees or charges.
If you are redistributing or providing access to a work with the
phrase “Project Gutenberg” associated with or appearing on the
work, you must comply either with the requirements of
paragraphs 1.E.1 through 1.E.7 or obtain permission for the use
of the work and the Project Gutenberg™ trademark as set forth
in paragraphs 1.E.8 or 1.E.9.

1.E.3. If an individual Project Gutenberg™ electronic work is


posted with the permission of the copyright holder, your use and
distribution must comply with both paragraphs 1.E.1 through
1.E.7 and any additional terms imposed by the copyright holder.
Additional terms will be linked to the Project Gutenberg™
License for all works posted with the permission of the copyright
holder found at the beginning of this work.

1.E.4. Do not unlink or detach or remove the full Project


Gutenberg™ License terms from this work, or any files
containing a part of this work or any other work associated with
Project Gutenberg™.

You might also like