Rapid GUI Programming with Python and Qt 1st Edition Mark Summerfield pdf download
Rapid GUI Programming with Python and Qt 1st Edition Mark Summerfield pdf download
https://ebookname.com/product/rapid-gui-programming-with-python-
and-qt-1st-edition-mark-summerfield/
https://ebookname.com/product/gui-programming-with-python-qt-
edition-boudewijn-rempt/
https://ebookname.com/product/programming-in-python-3-a-complete-
introduction-to-the-python-language-2nd-edition-summerfield/
https://ebookname.com/product/programming-python-4th-edition-
mark-lutz/
https://ebookname.com/product/the-making-of-a-human-bomb-an-
ethnography-of-palestinian-resistance-nasser-abufarha/
Medicine Creek Seventy Years of Archaeological
Investigations 1st Edition Donna C. Roper
https://ebookname.com/product/medicine-creek-seventy-years-of-
archaeological-investigations-1st-edition-donna-c-roper/
https://ebookname.com/product/swaziland-bradt-travel-guides-1st-
edition-mike-unwin/
https://ebookname.com/product/voices-from-the-vietnam-war-
xiaobing-li/
https://ebookname.com/product/marx-in-movement-operaismo-in-
context-1st-edition-antonio-negri/
https://ebookname.com/product/trade-unions-and-migrant-workers-
new-contexts-and-challenges-in-europe-1st-edition-stefania-
marino/
Rapid GUI Programming
with Python and Qt
The Definitive Guide to PyQt Programming
Mark Summerfield
Foreword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
vii
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
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
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
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
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
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
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 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 mark@qtrac.eu 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
Python Programming
This page intentionally left blank
1
● Executing Python Code
● Variables and Objects
● Numbers and Strings
● Collections
● Built-in Functions
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 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
>>> x = 71
>>> y = "Dove"
>>> 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;.
Discovering Diverse Content Through
Random Scribd Documents
accident some time since; the King, Lord Mayor and Sheriffs, being
there with great banquet.
11th June, 1666. Trinity Monday, after a sermon, applied to the
remeeting of the Corporation of the Trinity-House, after the late
raging and wasting pestilence: I dined with them in their new room
in Deptford, the first time since it was rebuilt.
15th June, 1666. I went to Chatham.—16th. In the Jemmy yacht
(an incomparable sailer) to sea, arrived by noon at the fleet at the
Buoy at the Nore, dined with Prince Rupert and the General.
17th June, 1666. Came his Majesty, the Duke, and many
Noblemen. After Council, we went to prayers. My business being
dispatched, I returned to Chatham, having lain but one night in the
Royal Charles; we had a tempestuous sea. I went on shore at
Sheerness, where they were building an arsenal for the fleet, and
designing a royal fort with a receptacle for great ships to ride at
anchor; but here I beheld the sad spectacle, more than half that
gallant bulwark of the kingdom miserably shattered, hardly a vessel
entire, but appearing rather so many wrecks and hulls, so cruelly
had the Dutch mangled us. The loss of the Prince, that gallant
vessel, had been a loss to be universally deplored, none knowing for
what reason we first engaged in this ungrateful war; we lost besides
nine or ten more, and near 600 men slain and 1,100 wounded,
2,000 prisoners; to balance which, perhaps we might destroy
eighteen or twenty of the enemy's ships, and 700 or 800 poor men.
18th June, 1666. Weary of this sad sight, I returned home.
2d July, 1666. Came Sir John Duncomb and Mr. Thomas
Chicheley, both Privy Councillors and Commissioners of His Majesty's
Ordnance, to visit me, and let me know that his Majesty had in
Council, nominated me to be one of the Commissioners for
regulating the farming and making of saltpetre through the whole
kingdom, and that we were to sit in the Tower the next day. When
they were gone, came to see me Sir John Cotton, heir to the famous
antiquary, Sir Robert Cotton: a pretended great Grecian, but had by
no means the parts, or genius of his grandfather.
3d July, 1666. I went to sit with the Commissioners at the Tower,
where our commission being read, we made some progress in
business, our Secretary being Sir George Wharton, that famous
mathematician who wrote the yearly Almanac during his Majesty's
troubles. Thence, to Painters' Hall, to our other commission, and
dined at my Lord Mayor's.
4th July, 1666. The solemn Fast-day. Dr. Meggot preached an
excellent discourse before the King on the terrors of God's
judgments. After sermon, I waited on my Lord Archbishop of
Canterbury and Bishop of Winchester, where the Dean of
Westminster spoke to me about putting into my hands the disposal
of fifty pounds, which the charitable people of Oxford had sent to be
distributed among the sick and wounded seamen since the battle.
Hence, I went to the Lord Chancellor's to joy him of his Royal
Highness's second son, now born at St. James's; and to desire the
use of the Star-chamber for our Commissioners to meet in, Painters'
Hall not being so convenient.
12th July, 1666. We sat the first time in the Star-chamber. There
was now added to our commission Sir George Downing (one that
had been a great ... against his Majesty, but now insinuated into his
favor; and, from a pedagogue and fanatic preacher, not worth a
groat, had become excessively rich), to inspect the hospitals and
treat about prisons.
14th July, 1666. Sat at the Tower with Sir J. Duncomb and Lord
Berkeley, to sign deputations for undertakers to furnish their
proportions of saltpetre.
17th July, 1666. To London, to prepare for the
LONDON
next engagement of the fleets, now gotten to sea
again.
22d July, 1666. Our parish still infected with the contagion.
25th July, 1666. The fleets engaged. I dined at Lord Berkeley's, at
St. James's, where dined my Lady Harrietta Hyde, Lord Arlington,
and Sir John Duncomb.
29th July, 1666. The pestilence now fresh increasing in our parish,
I forbore going to church. In the afternoon came tidings of our
victory over the Dutch, sinking some, and driving others aground,
and into their ports.
1st August, 1666. I went to Dr. Keffler, who married the daughter
of the famous chemist, Drebbell,4 inventor of the bodied scarlet. I
went to see his iron ovens, made portable (formerly) for the Prince
of Orange's army: supped at the Rhenish Wine-House with divers
Scots gentlemen.
6th August, 1666. Dined with Mr. Povey, and then went with him
to see a country house he had bought near Brentford; returning by
Kensington; which house stands to a very graceful avenue of trees,
but it is an ordinary building, especially one part.
8th August, 1666. Dined at Sir Stephen Fox's with several friends
and, on the 10th, with Mr. Odart, Secretary of the Latin tongue.
17th August, 1666. Dined with the Lord Chancellor, whom I
entreated to visit the Hospital of the Savoy, and reduce it (after the
great abuse that had been continued) to its original institution for
the benefit of the poor, which he promised to do.
25th August, 1666. Waited on Sir William D'Oyly, now recovered,
as it were, miraculously. In the afternoon, visited the Savoy Hospital,
where I stayed to see the miserably dismembered and wounded
men dressed, and gave some necessary orders. Then to my Lord
Chancellor, who had, with the Bishop of London and others in the
commission, chosen me one of the three surveyors of the repairs of
Paul's, and to consider of a model for the new building, or, if it might
be, repairing of the steeple, which was most decayed.
26th August, 1666. The contagion still continuing, we had the
Church service at home.
27th August, 1666. I went to St. Paul's church, where, with Dr.
Wren, Mr. Pratt, Mr. May, Mr. Thomas Chicheley, Mr. Slingsby, the
Bishop of London, the Dean of St. Paul's, and several expert
workmen, we went about to survey the general decays of that
ancient and venerable church, and to set down in writing the
particulars of what was fit to be done, with the charge thereof,
giving our opinion from article to article. Finding the main building to
recede outward it was the opinion of Chicheley and Mr. Pratt that it
had been so built ab origine for an effect in perspective, in regard of
the height; but I was, with Dr. Wren, quite of another judgment, and
so we entered it; we plumbed the uprights in several places. When
we came to the steeple, it was deliberated whether it were not well
enough to repair it only on its old foundation, with reservation to the
four pillars; this Mr. Chicheley and Mr. Pratt were also for, but we
totally rejected it, and persisted that it required a new foundation,
not only in regard of the necessity, but for that the shape of what
stood was very mean, and we had a mind to build it with a noble
cupola, a form of church-building not as yet known in England, but
of wonderful grace. For this purpose, we offered to bring in a plan
and estimate, which after much contest, was at last assented to, and
that we should nominate a committee of able workmen to examine
the present foundation. This concluded, we drew all up in writing,
and so went with my Lord Bishop to the Dean's.
28th August, 1666. Sat at the Star-chamber. Next day, to the
Royal Society, where one Mercator, an excellent mathematician,
produced his rare clock and new motion to perform the equations,
and Mr. Rooke, his new pendulum.
2d September, 1666. This fatal night, about ten,
LONDON
began the deplorable fire, near Fish street, in
London.
3d September, 1666. I had public prayers at home. The fire
continuing, after dinner, I took coach with my wife and son, and
went to the Bankside in Southwark, where we beheld that dismal
spectacle, the whole city in dreadful flames near the waterside; all
the houses from the Bridge, all Thames street, and upward toward
Cheapside, down to the Three Cranes, were now consumed; and so
returned, exceedingly astonished what would become of the rest.
The fire having continued all this night (if I may call that night
which was light as day for ten miles round about, after a dreadful
manner), when conspiring with a fierce eastern wind in a very dry
season, I went on foot to the same place; and saw the whole south
part of the city burning from Cheapside to the Thames, and all along
Cornhill (for it likewise kindled back against the wind as well as
forward), Tower street, Fenchurch street, Gracious street, and so
along to Baynard's Castle, and was now taking hold of St. Paul's
church, to which the scaffolds contributed exceedingly. The
conflagration was so universal, and the people so astonished, that,
from the beginning, I know not by what despondency, or fate, they
hardly stirred to quench it; so that there was nothing heard, or seen,
but crying out and lamentation, running about like distracted
creatures, without at all attempting to save even their goods; such a
strange consternation there was upon them, so as it burned both in
breadth and length, the churches, public halls, Exchange, hospitals,
monuments, and ornaments; leaping after a prodigious manner,
from house to house, and street to street, at great distances one
from the other. For the heat, with a long set of fair and warm
weather, had even ignited the air, and prepared the materials to
conceive the fire, which devoured, after an incredible manner,
houses, furniture, and every thing. Here, we saw the Thames
covered with goods floating, all the barges and boats laden with
what some had time and courage to save, as, on the other side, the
carts, etc., carrying out to the fields, which for many miles were
strewn with movables of all sorts, and tents erecting to shelter both
people and what goods they could get away. Oh, the miserable and
calamitous spectacle! such as haply the world had not seen since the
foundation of it, nor can be outdone till the universal conflagration
thereof. All the sky was of a fiery aspect, like the top of a burning
oven, and the light seen above forty miles round about for many
nights. God grant mine eyes may never behold the like, who now
saw above 10,000 houses all in one flame! The noise and cracking
and thunder of the impetuous flames, the shrieking of women and
children, the hurry of people, the fall of towers, houses, and
churches, was like a hideous storm; and the air all about so hot and
inflamed, that at the last one was not able to approach it, so that
they were forced to stand still, and let the flames burn on, which
they did, for near two miles in length and one in breadth. The clouds
also of smoke were dismal, and reached, upon computation, near
fifty miles in length. Thus, I left it this afternoon burning, a
resemblance of Sodom, or the last day. It forcibly called to my mind
that passage—"non enim hic habemus stabilem civitatem"; the ruins
resembling the picture of Troy. London was, but is no more! Thus, I
returned.
4th September, 1666. The burning still rages, and it is now gotten
as far as the Inner Temple. All Fleet street, the Old Bailey, Ludgate
hill, Warwick lane, Newgate, Paul's chain, Watling street, now
flaming, and most of it reduced to ashes; the stones of Paul's flew
like grenados, the melting lead running down the streets in a
stream, and the very pavements glowing with fiery redness, so as no
horse, nor man, was able to tread on them, and the demolition had
stopped all the passages, so that no help could be applied. The
eastern wind still more impetuously driving the flames forward.
Nothing but the Almighty power of God was able to stop them; for
vain was the help of man.
5th September, 1666. It crossed toward Whitehall; but oh! the
confusion there was then at that Court! It pleased his Majesty to
command me, among the rest, to look after the quenching of Fetter-
lane end, to preserve (if possible) that part of Holborn, while the
rest of the gentlemen took their several posts, some at one part, and
some at another (for now they began to bestir themselves, and not
till now, who hitherto had stood as men intoxicated, with their hands
across), and began to consider that nothing was likely to put a stop
but the blowing up of so many houses as might make a wider gap
than any had yet been made by the ordinary method of pulling them
down with engines. This some stout seamen proposed early enough
to have saved near the whole city, but this some tenacious and
avaricious men, aldermen, etc., would not permit, because their
houses must have been of the first. It was, therefore, now
commended to be practiced; and my concern being particularly for
the Hospital of St. Bartholomew, near Smithfield, where I had many
wounded and sick men, made me the more diligent to promote it;
nor was my care for the Savoy less. It now pleased God, by abating
the wind, and by the industry of the people, when almost all was
lost infusing a new spirit into them, that the fury of it began sensibly
to abate about noon, so as it came no farther than the Temple
westward, nor than the entrance of Smithfield, north: but continued
all this day and night so impetuous toward Cripplegate and the
Tower, as made us all despair. It also broke out again in the temple;
but the courage of the multitude persisting, and many houses being
blown up, such gaps and desolations were soon made, as, with the
former three days' consumption, the back fire did not so vehemently
urge upon the rest as formerly. There was yet no standing near the
burning and glowing ruins by near a furlong's space.
The coal and wood wharfs, and magazines of oil, rosin, etc., did
infinite mischief, so as the invective which a little before I had
dedicated to his Majesty and published,5 giving warning what
probably might be the issue of suffering those shops to be in the city
was looked upon as a prophecy.
The poor inhabitants were dispersed about St. George's Fields,
and Moorfields, as far as Highgate, and several miles in circle, some
under tents, some under miserable huts and hovels, many without a
rag, or any necessary utensils, bed or board, who from delicateness,
riches, and easy accommodations in stately and well-furnished
houses, were now reduced to extreme misery and poverty.
In this calamitous condition, I returned with a sad heart to my
house, blessing and adoring the distinguishing mercy of God to me
and mine, who, in the midst of all this ruin, was like Lot, in my little
Zoar, safe and sound.
6th September, 1666. Thursday. I represented to his Majesty the
case of the French prisoners at war in my custody, and besought him
that there might be still the same care of watching at all places
contiguous to unseized houses. It is not indeed imaginable how
extraordinary the vigilance and activity of the King and the Duke
was, even laboring in person, and being present to command, order,
reward, or encourage workmen; by which he showed his affection to
his people, and gained theirs. Having, then, disposed of some under
cure at the Savoy, I returned to Whitehall, where I dined at Mr.
Offley's, the groom-porter, who was my relation.
7th September, 1666. I went this morning on
LONDON
foot from Whitehall as far as London Bridge,
through the late Fleet street, Ludgate hill by St. Paul's, Cheapside,
Exchange, Bishops-gate, Aldersgate, and out to Moorfields, thence
through Cornhill, etc., with extraordinary difficulty, clambering over
heaps of yet smoking rubbish, and frequently mistaking where I
was; the ground under my feet so hot, that it even burnt the soles of
my shoes. In the meantime, his Majesty got to the Tower by water,
to demolish the houses about the graff, which, being built entirely
about it, had they taken fire and attacked the White Tower, where
the magazine of powder lay, would undoubtedly not only have
beaten down and destroyed all the bridge, but sunk and torn the
vessels in the river, and rendered the demolition beyond all
expression for several miles about the country.
At my return, I was infinitely concerned to find that goodly
Church, St. Paul's—now a sad ruin, and that beautiful portico (for
structure comparable to any in Europe, as not long before repaired
by the late King) now rent in pieces, flakes of large stones split
asunder, and nothing remaining entire but the inscription in the
architrave showing by whom it was built, which had not one letter of
it defaced! It was astonishing to see what immense stones the heat
had in a manner calcined, so that all the ornaments, columns,
friezes, capitals, and projectures of massy Portland stone, flew off,
even to the very roof, where a sheet of lead covering a great space
(no less than six acres by measure) was totally melted. The ruins of
the vaulted roof falling, broke into St. Faith's, which being filled with
the magazines of books belonging to the Stationers, and carried
thither for safety, they were all consumed, burning for a week
following. It is also observable that the lead over the altar at the
east end was untouched, and among the divers monuments the
body of one bishop remained entire. Thus lay in ashes that most
venerable church, one of the most ancient pieces of early piety in
the Christian world, besides near one hundred more. The lead,
ironwork, bells, plate, etc., melted, the exquisitely wrought Mercers'
Chapel, the sumptuous Exchange, the august fabric of Christ Church,
all the rest of the Companies' Halls, splendid buildings, arches,
entries, all in dust; the fountains dried up and ruined, while the very
waters remained boiling; the voragos of subterranean cellars, wells,
and dungeons, formerly warehouses, still burning in stench and dark
clouds of smoke; so that in five or six miles traversing about I did
not see one load of timber unconsumed, nor many stones but what
were calcined white as snow.
The people, who now walked about the ruins, appeared like men
in some dismal desert, or rather, in some great city laid waste by a
cruel enemy; to which was added the stench that came from some
poor creatures' bodies, beds, and other combustible goods. Sir
Thomas Gresham's statue, though fallen from its niche in the Royal
Exchange, remained entire, when all those of the Kings since the
Conquest were broken to pieces. Also the standard in Cornhill, and
Queen Elizabeth's effigies, with some arms on Ludgate, continued
with but little detriment, while the vast iron chains of the city streets,
hinges, bars, and gates of prisons, were many of them melted and
reduced to cinders by the vehement heat. Nor was I yet able to pass
through any of the narrow streets, but kept the widest; the ground
and air, smoke and fiery vapor, continued so intense, that my hair
was almost singed, and my feet insufferably surbated. The by-lanes
and narrow streets were quite filled up with rubbish; nor could one
have possibly known where he was, but by the ruins of some
Church, or Hall, that had some remarkable tower, or pinnacle
remaining.
I then went towards Islington and Highgate, where one might
have seen 200,000 people of all ranks and degrees dispersed, and
lying along by their heaps of what they could save from the fire,
deploring their loss; and, though ready to perish for hunger and
destitution, yet not asking one penny for relief, which to me
appeared a stranger sight than any I had yet beheld. His Majesty
and Council indeed took all imaginable care for their relief, by
proclamation for the country to come in, and refresh them with
provisions.
In the midst of all this calamity and confusion, there was, I know
not how, an alarm begun that the French and Dutch, with whom we
were now in hostility, were not only landed, but even entering the
city. There was, in truth, some days before, great suspicion of those
two nations joining; and now that they had been the occasion of
firing the town. This report did so terrify, that on a sudden there was
such an uproar and tumult that they ran from their goods, and,
taking what weapons they could come at, they could not be stopped
from falling on some of those nations whom they casually met,
without sense or reason. The clamor and peril grew so excessive,
that it made the whole Court amazed, and they did with infinite
pains and great difficulty, reduce and appease the people, sending
troops of soldiers and guards, to cause them to retire into the fields
again, where they were watched all this night. I left them pretty
quiet, and came home sufficiently weary and broken. Their spirits
thus a little calmed, and the affright abated, they now began to
repair into the suburbs about the city, where such as had friends, or
opportunity, got shelter for the present to which his Majesty's
proclamation also invited them.
Still, the plague continuing in our parish, I could not, without
danger, adventure to our church.
10th September, 1666. I went again to the ruins; for it was now
no longer a city.
13th September, 1666. I presented his Majesty with a survey of
the ruins, and a plot for a new city, with a discourse on it;
whereupon, after dinner, his Majesty sent for me into the Queen's
bed-chamber, her Majesty and the Duke only being present. They
examined each particular, and discoursed on them for near an hour,
seeming to be extremely pleased with what I had so early thought
on. The Queen was now in her cavalier riding-habit, hat and feather,
and horseman's coat, going to take the air.
16th September, 1666. I went to Greenwich Church, where Mr.
Plume preached very well from this text: "Seeing, then, all these
things shall be dissolved," etc.: taking occasion from the late
unparalleled conflagration to remind us how we ought to walk more
holy in all manner of conversation.
27th September, 1666. Dined at Sir William D'Oyly's, with that
worthy gentleman, Sir John Holland, of Suffolk.
10th October, 1666. This day was ordered a general Fast through
the Nation, to humble us on the late dreadful conflagration, added to
the plague and war, the most dismal judgments that could be
inflicted; but which indeed we highly deserved for our prodigious
ingratitude, burning lusts, dissolute court, profane and abominable
lives, under such dispensations of God's continued favor in restoring
Church, Prince, and People from our late intestine calamities, of
which we were altogether unmindful, even to astonishment. This
made me resolve to go to our parish assembly, where our Doctor
preached on Luke xix. 41: piously applying it to the occasion. After
which, was a collection for the distressed losers in the late fire.
18th October, 1666. To Court. It being the first time his Majesty
put himself solemnly into the Eastern fashion of vest, changing
doublet, stiff collar, bands and cloak, into a comely dress, after the
Persian mode, with girdles or straps, and shoestrings and garters
into buckles, of which some were set with precious stones6 resolving
never to alter it, and to leave the French mode, which had hitherto
obtained to our great expense and reproach. Upon which, divers
courtiers and gentlemen gave his Majesty gold by way of wager that
he would not persist in this resolution. I had sometime before
presented an invective against that unconstancy, and our so much
affecting the French fashion, to his Majesty; in which I took occasion
to describe the comeliness and usefulness of the Persian clothing, in
the very same manner his Majesty now clad himself. This pamphlet I
entitled "Tyrannus, or the Mode," and gave it to the King to read. I
do not impute to this discourse the change which soon happened,
but it was an identity that I could not but take notice of.
This night was acted my Lord Broghill's tragedy, called
"Mustapha," before their Majesties at Court, at which I was present;
very seldom going to the public theatres for many reasons now, as
they were abused to an atheistical liberty; foul and indecent women
now (and never till now) permitted to appear and act, who inflaming
several young noblemen and gallants, became their misses, and to
some, their wives. Witness the Earl of Oxford, Sir R. Howard, Prince
Rupert, the Earl of Dorset, and another greater person than any of
them, who fell into their snares, to the reproach of their noble
families, and ruin of both body and soul.7 I was invited by my Lord
Chamberlain to see this tragedy, exceedingly well written, though in
my mind I did not approve of any such pastime in a time of such
judgments and calamities.
21st October, 1666. This season, after so long and extraordinary a
drought in August and September, as if preparatory for the dreadful
fire, was so very wet and rainy as many feared an ensuing famine.
28th October, 1666. The pestilence, through God's mercy, began
now to abate considerably in our town.
30th October, 1666. To London to our office, and
LONDON
now had I on the vest and surcoat, or tunic, as it
was called, after his Majesty had brought the whole court to it. It
was a comely and manly habit, too good to hold, it being impossible
for us in good earnest to leave the Monsieurs' vanities long.
31st October, 1666. I heard the signal cause of my Lord Cleveland
pleaded before the House of Lords; and was this day forty-six years
of age, wonderfully protected by the mercies of God, for which I
render him immortal thanks.
14th November, 1666. I went my winter circle through my district,
Rochester and other places, where I had men quartered, and in
custody.
15th November, 1666. To Leeds Castle.
16th November, 1666. I mustered the prisoners, being about 600
Dutch and French, ordered their proportion of bread to be
augmented and provided clothes and fuel. Monsieur Colbert,
Ambassador at the Court of England, this day sent money from his
master, the French King, to every prisoner of that nation under my
guard.
17th November, 1666. I returned to Chatham, my chariot
overturning on the steep of Bexley Hill, wounded me in two places
on the head; my son, Jack, being with me, was like to have been
worse cut by the glass; but I thank God we both escaped without
much hurt, though not without exceeding danger.
18th November, 1666. At Rochester.
19th November, 1666. Returned home.
23d November, 1666. At London, I heard an extraordinary case
before a Committee of the whole House of Commons, in the
Commons' House of Parliament, between one Captain Taylor and my
Lord Viscount Mordaunt, where, after the lawyers had pleaded and
the witnesses been examined, such foul and dishonorable things
were produced against his Lordship, of tyranny during his
government of Windsor Castle, of which he was Constable,
incontinence, and suborning witnesses (of which last, one Sir
Richard Breames was most concerned), that I was exceedingly
interested for his Lordship, who was my special friend, and husband
of the most virtuous lady in the world. We sat till near ten at night,
and yet but half the counsel had done on behalf of the plaintiff. The
question then was put for bringing in of lights to sit longer. This
lasted so long before it was determined, and raised such a confused
noise among the members, that a stranger would have been
astonished at it. I admire that there is not a rationale to regulate
such trifling accidents, which consume much time, and is a reproach
to the gravity of so great an assembly of sober men.
27th November, 1666. Sir Hugh Pollard, Comptroller of the
Household, died at Whitehall, and his Majesty conferred the white
staff on my brother Commissioner for sick and wounded, Sir Thomas
Clifford, a bold young gentleman, of a small fortune in Devon, but
advanced by Lord Arlington, Secretary of State, to the great
astonishment of all the Court. This gentleman was somewhat related
to me by the marriage of his mother to my nearest kinsman,
Gregory Coale, and was ever my noble friend, a valiant and daring
person, but by no means fit for a supple and flattering courtier.
28th November, 1666. Went to see Clarendon House, now almost
finished, a goodly pile to see, but had many defects as to the
architecture, yet placed most gracefully. After this, I waited on the
Lord Chancellor, who was now at Berkshire House, since the burning
of London.
2d December, 1666. Dined with me Monsieur Kiviet, a Dutch
gentleman-pensioner of Rotterdam, who came over for protection,
being of the Prince of Orange's party, now not welcome in Holland.
The King knighted him for some merit in the Prince's behalf. He
should, if caught, have been beheaded with Monsieur Buat, and was
brother-in-law to Van Tromp, the sea-general. With him came Mr.
Gabriel Sylvius, and Mr. Williamson, secretary to Lord Arlington;
M. Kiviet came to examine whether the soil about the river of
Thames would be proper to make clinker bricks, and to treat with
me about some accommodation in order to it.
9th January, 1666-67. To the Royal Society, which since the sad
conflagration were invited by Mr. Howard to sit at Arundel-House in
the Strand, who at my instigation likewise bestowed on the Society
that noble library which his grandfather especially, and his ancestors
had collected. This gentleman had so little inclination to books, that
it was the preservation of them from embezzlement.
24th January, 1667. Visited my Lord Clarendon, and presented my
son, John, to him, now preparing to go to Oxford, of which his
Lordship was Chancellor. This evening I heard rare Italian voices,
two eunuchs and one woman, in his Majesty's green chamber, next
his cabinet.
29th January, 1667. To London, in order to my
LONDON
son's Oxford journey, who, being very early
entered both in Latin and Greek, and prompt to learn beyond most
of his age, I was persuaded to trust him under the tutorage of Mr.
Bohun, Fellow of New College, who had been his preceptor in my
house some years before; but, at Oxford, under the inspection of Dr.
Bathurst, President of Trinity College, where I placed him, not as yet
thirteen years old. He was newly out of long coats.8
15th February, 1667. My little book, in answer to Sir George
Mackenzie on Solitude, was now published, entitled "Public
Employment, and an active Life with its Appanages, preferred to
Solitude."9
18th February, 1667. I was present at a magnificent ball, or
masque, in the theatre at the Court, where their Majesties and all
the great lords and ladies danced, infinitely gallant, the men in their
richly embroidered, most becoming vests.
19th February, 1667. I saw a comedy acted at Court. In the
afternoon, I witnessed a wrestling match for £1,000 in St. James's
Park, before his Majesty, a vast assemblage of lords and other
spectators, between the western and northern men, Mr. Secretary
Morice and Lord Gerard being the judges. The western men won.
Many great sums were betted.
6th March, 1667. I proposed to my Lord Chancellor, Monsieur
Kiviet's undertaking to wharf the whole river of Thames, or quay,
from the Temple to the Tower, as far as the fire destroyed, with
brick, without piles, both lasting and ornamental.—Great frosts,
snow and winds, prodigious at the vernal equinox; indeed it had
been a year of prodigies in this nation, plague, war, fire, rain,
tempest and comet.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookname.com