0% found this document useful (0 votes)
2 views

GUI Programming with Python QT Edition Boudewijn Rempt instant download

The document is a comprehensive guide on GUI programming using Python and the Qt framework, authored by Boudewijn Rempt. It covers installation, interface design, and various programming concepts, including signals and slots, debugging, and application frameworks. The book is intended for both beginners and experienced developers looking to enhance their skills in Python GUI development.

Uploaded by

masseinolber
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

GUI Programming with Python QT Edition Boudewijn Rempt instant download

The document is a comprehensive guide on GUI programming using Python and the Qt framework, authored by Boudewijn Rempt. It covers installation, interface design, and various programming concepts, including signals and slots, debugging, and application frameworks. The book is intended for both beginners and experienced developers looking to enhance their skills in Python GUI development.

Uploaded by

masseinolber
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 62

GUI Programming with Python QT Edition Boudewijn

Rempt pdf download

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

Get Instant Ebook Downloads – Browse at https://ebookname.com


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

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/

Programming ArcGIS with Python Cookbook 2nd Edition


Eric Pimpler

https://ebookname.com/product/programming-arcgis-with-python-
cookbook-2nd-edition-eric-pimpler/

Game Programming With Python Game Development Series


1st Edition Riley

https://ebookname.com/product/game-programming-with-python-game-
development-series-1st-edition-riley/

Empire of Ancient Egypt Wendy Christensen

https://ebookname.com/product/empire-of-ancient-egypt-wendy-
christensen/
The Atmosphere and Ocean A Physical Introduction Third
Edition Neil C. Wells(Auth.)

https://ebookname.com/product/the-atmosphere-and-ocean-a-
physical-introduction-third-edition-neil-c-wellsauth/

Global Health Watch 3 An Alternative World Health


Report 3rd Edition Amit Sengupta

https://ebookname.com/product/global-health-watch-3-an-
alternative-world-health-report-3rd-edition-amit-sengupta/

All s Well That Ends Well Webster s French Thesaurus


Edition William Shakespeare

https://ebookname.com/product/all-s-well-that-ends-well-webster-
s-french-thesaurus-edition-william-shakespeare/

Irish Politics and Social Conflict in the Age of the


American Revolution 1st Edition Maurice R. O'Connell

https://ebookname.com/product/irish-politics-and-social-conflict-
in-the-age-of-the-american-revolution-1st-edition-maurice-r-
oconnell/

Self Healing Composites Shape Memory Polymer Based


Structures 1st Edition Guoqiang Li

https://ebookname.com/product/self-healing-composites-shape-
memory-polymer-based-structures-1st-edition-guoqiang-li/
Encyclopedia of law enforcement 1st Edition Larry E.
Sullivan

https://ebookname.com/product/encyclopedia-of-law-
enforcement-1st-edition-larry-e-sullivan/
GUI Programming with Python:
QT Edition

Boudewijn Rempt
GUI Programming with Python: QT Edition
by Boudewijn Rempt

GUI Programming with Python: QT Edition Edition


Published July 2001
Copyright © 2001 by Commandprompt, Inc

Copyright (c) 2001 by Command Prompt, Inc. This material may be distributed only subject to the terms and
conditions set forth in the Open Publication License, v1.0 or later (the latest version is presently available at
http://www.opencontent.org/openpub/).
‘Distribution of substantively modified versions of this document is prohibited without the explicit permission of the
copyright holder.’ to the license reference or copy.
‘Distribution of the work or derivative of the work in any standard (paper) book form is prohibited unless prior
permission is obtained from the copyright holder.’ to the license reference or copy.

Although every reasonable effort has been made to incorporate accurate and useful information into this book, the
copyright holders make no representation about the suitability of this book or the information therein for any purpose.
It is provided “as is” without expressed or implied warranty.
Dedication
This book is dedicated to Irina.
6
Table of Contents
Preface.....................................................................................................................23
1. Who is using PyQt .......................................................................................24
2. For whom is this book intended...................................................................24
3. How to read this book ..................................................................................25
4. Conventions .................................................................................................26
5. Acknowledgments........................................................................................27
1. Introduction ........................................................................................................29
1.1. Python .......................................................................................................30
1.2. GUI programming with Python ................................................................33
1.3. About the BlackAdder IDE.......................................................................35
I. Introduction to the BlackAdder IDE................................................................37
2. Installation....................................................................................................39
2.1. Installing BlackAdder .......................................................................39
2.1.1. Windows ................................................................................39
2.1.2. Linux ......................................................................................40
2.2. Installing sip and PyQt without BlackAdder ....................................41
2.2.1. Building from source on Linux..............................................42
2.2.1.1. Problems with compilation .........................................43
2.2.2. Windows ................................................................................44
3. Interface .......................................................................................................47
3.1. Menubar ............................................................................................48
3.2. Toolbars.............................................................................................48
3.2.1. File toolbar .............................................................................49
3.2.2. Edit toolbar.............................................................................49
3.2.3. Execution toolbar ...................................................................49
3.2.4. Layout manager toolbar .........................................................50
3.2.5. Widgets ..................................................................................50
3.2.6. Help........................................................................................50
3.2.7. Pointer toolbar........................................................................50
3.2.8. More widget toolbars .............................................................51
3.3. Project management..........................................................................51
3.4. BlackAdder Configuration ................................................................53
3.5. Editing...............................................................................................55
3.6. Python shell.......................................................................................55

7
3.7. Conclusion ........................................................................................56
4. Introduction to Python .................................................................................57
4.1. Programming fundamentals ..............................................................57
4.2. The Rules ..........................................................................................61
4.2.1. Objects and references ...........................................................61
4.2.2. Formatting..............................................................................62
4.2.3. Keywords ...............................................................................63
4.2.4. Literals ...................................................................................64
4.2.5. Methods and functions...........................................................64
4.2.6. High level datatypes...............................................................65
4.3. Constructions ....................................................................................66
4.3.1. Looping ..................................................................................66
4.3.2. Branching...............................................................................69
4.3.3. Exceptions..............................................................................70
4.3.4. Classes....................................................................................71
4.4. Conclusion ........................................................................................72
5. Debugging....................................................................................................73
5.1. Running scripts .................................................................................76
5.2. Setting breakpoints............................................................................76
5.3. Stepping along ..................................................................................78
5.4. Debugging Techniques......................................................................81
5.4.1. Avoid changing your code .....................................................81
5.4.2. Gather data .............................................................................81
5.4.3. Minimal examples..................................................................82
5.5. If all else fails....................................................................................82
II. PyQt fundamentals ...........................................................................................85
6. Qt Concepts..................................................................................................87
6.1. Python, Qt and PyQt .........................................................................87
6.2. As simple as they come.....................................................................88
6.3. A better Hello World.........................................................................91
6.4. Designing forms................................................................................96
6.5. Conclusion ......................................................................................101
7. Signals and Slots in Depth .........................................................................103
7.1. The concept of signals and slots .....................................................103
7.1.1. Callbacks..............................................................................104
7.1.2. Action registry .....................................................................106
7.1.3. Signals and slots...................................................................108

8
7.2. Connecting with signals and slots...................................................110
7.3. Disconnecting .................................................................................120
7.4. A parser-formatter using signals and slots......................................127
7.5. Conclusion ......................................................................................137
8. String Objects in Python and Qt ................................................................139
8.1. Introduction.....................................................................................139
8.2. String conversions...........................................................................140
8.3. QCString — simple strings in PyQt ...............................................142
8.4. Unicode strings ...............................................................................146
8.4.1. Introduction to Unicode .......................................................147
8.4.2. Python and Unicode.............................................................148
8.4.2.1. String literals.............................................................149
8.4.2.2. Reading from files.....................................................151
8.4.2.3. Other ways of getting Unicode characters into Python
string objects ..................................................................153
8.4.3. Qt and Unicode ....................................................................156
9. Python Objects and Qt Objects ..................................................................159
9.1. Pointers and references ...................................................................159
9.2. Circular references ..........................................................................160
9.3. Qt objects, Python objects and shadow objects ..............................161
9.4. References and ownership ..............................................................163
9.5. Other C++ objects...........................................................................173
9.6. Connecting signals and slots...........................................................173
9.7. Object and class introspection ........................................................175
10. Qt Class Hierarchy...................................................................................177
10.1. Hierarchy.......................................................................................177
10.2. Base classes...................................................................................179
10.3. Application classes........................................................................182
10.3.1. Multiple document windows with QWorkspace................185
10.4. Widget foundations: QWidget ......................................................187
10.4.1. QColor................................................................................189
10.4.2. QPixmap, QBitmap and QImage .......................................190
10.4.3. QPainter .............................................................................191
10.4.4. QFont .................................................................................193
10.5. Basic widgets ................................................................................195
10.5.1. QFrame ..............................................................................197
10.5.2. QPushButton ......................................................................197

9
10.5.3. QLabel................................................................................199
10.5.4. QRadioButton ....................................................................202
10.5.5. QCheckBox........................................................................203
10.5.6. QListBox............................................................................204
10.5.7. QComboBox ......................................................................206
10.5.8. QLineEdit...........................................................................207
10.5.9. QMultiLineEdit..................................................................207
10.5.10. QPopupMenu ...................................................................207
10.5.11. QProgressBar ...................................................................207
10.5.12. QSlider and other small fry..............................................208
10.6. Advanced widgets .........................................................................209
10.6.1. QSimpleRichText, QTextView and QTextBrowser ...........209
10.6.2. QTextEdit ...........................................................................209
10.6.3. QListView and QListViewItem..........................................210
10.6.4. QIconView and QIconViewItem........................................211
10.6.5. QSplitter .............................................................................212
10.6.6. QCanvas, QCanvasView and QCanvasItems .....................212
10.6.7. QTable, QTableItem and QTableView (or QGridView).....213
10.7. Layout managers...........................................................................213
10.7.1. Widget sizing: QSizePolicy ...............................................215
10.7.2. Groups and frames .............................................................216
10.7.2.1. QHBox ....................................................................216
10.7.2.2. QVBox ....................................................................216
10.7.2.3. QGrid ......................................................................216
10.7.2.4. QGroupBox.............................................................216
10.7.3. QLayout .............................................................................217
10.7.4. QBoxLayout and children..................................................217
10.7.5. QGridLayout ......................................................................217
10.7.6. setGeometry .......................................................................220
10.8. Dialogs and Standard Dialogs.......................................................221
10.8.1. QDialog..............................................................................221
10.8.2. QMessageBox....................................................................221
10.8.3. QTabDialog........................................................................227
10.8.4. QWizard .............................................................................227
10.8.5. QFileDialog........................................................................227
10.8.6. QFontDialog ......................................................................228
10.8.7. QColorDialog.....................................................................229

10
10.8.8. QInputDialog .....................................................................230
10.8.9. QProgressDialog ................................................................230
10.9. Qt Utility classes and their Python equivalents ............................230
10.9.1. High level data structures...................................................235
10.9.2. Files and other IO...............................................................238
10.9.3. Date and time .....................................................................239
10.9.4. Mime ..................................................................................240
10.9.5. Text handling......................................................................241
10.9.6. Threads...............................................................................242
10.9.7. URL’s .................................................................................244
10.9.8. Qt modules that overlap with Python modules ..................245
11. Qt Designer, BlackAdder and uic ............................................................249
11.1. Introduction...................................................................................249
11.1.1. Starting out with the designer module ...............................249
11.1.2. Creating a design................................................................253
11.1.2.1. Grouping widgets....................................................253
11.1.2.2. Layout management................................................254
11.1.2.3. Tab order and accelerators ......................................254
11.2. Advanced Designer topics ............................................................256
11.2.1. Defining signals and slots in Designer...............................256
11.2.2. Adding your own widgets ..................................................259
11.2.3. Layout management...........................................................262
11.2.3.1. The Horizontal Layout Manager.............................264
11.2.3.2. The Vertical Layout Manager .................................264
11.2.3.3. The Grid Layout Manager ......................................264
11.2.3.4. The Spacer object....................................................265
11.2.3.5. What widgets can do to get the space they want.....265
11.2.3.6. Creating a complex form ........................................266
11.2.4. Generating and using Python code with pyuic ..................268
11.2.5. Generating C++ code with uic ...........................................270
III. Creating real applications with PyQt ..........................................................273
12. Application Frameworks..........................................................................275
12.1. Architecture: models, documents and views.................................275
12.1.1. A document-view framework ............................................277
12.2. Macro languages ...........................................................................284
12.3. Project layout ................................................................................284
13. Actions: menus, toolbars and accelerators...............................................287

11
13.1. Actions ..........................................................................................287
13.2. Menus............................................................................................291
13.3. Toolbars.........................................................................................292
13.4. Keyboard accelerators...................................................................294
13.5. Setting an application icon............................................................295
14. Automatic testing with PyUnit ................................................................297
14.1. About unittests ..............................................................................297
14.2. Starting out....................................................................................299
14.3. A first testcase ...............................................................................300
14.4. Collecting tests in a test suite........................................................302
14.5. A more complicated test ...............................................................303
14.6. Large projects................................................................................306
14.7. Testing signals and slots................................................................309
14.8. Conclusion ....................................................................................312
15. A More Complex Framework: Multiple Documents, Multiple Views ....315
15.1. Introduction...................................................................................315
15.2. Document/View Manager .............................................................319
15.3. The Document Manager ...............................................................325
15.4. Document......................................................................................332
15.5. View ..............................................................................................334
15.6. The actual application ...................................................................335
15.7. Conclusion ....................................................................................348
16. User Interface Paradigms .........................................................................349
16.1. Tabbed documents ........................................................................349
16.2. Back to the MDI windows ............................................................353
16.3. A row of split windows.................................................................354
16.4. A stack of documents....................................................................355
16.5. A more complex view management solution................................357
16.6. Conclusion ....................................................................................360
17. Creating Application Functionality..........................................................363
17.1. Introduction...................................................................................363
17.1.1. Giving the project a name ..................................................363
17.2. The view........................................................................................363
17.3. The document................................................................................368
17.4. Saving and loading documents .....................................................370
17.4.1. Loading ..............................................................................370
17.4.2. Saving ................................................................................371

12
17.5. Undo, redo and other editing functions.........................................372
17.6. Conclusion ....................................................................................378
18. Application Configuration .......................................................................379
18.1. Platform differences......................................................................379
18.2. The Python way of handling configuration settings .....................380
18.3. Implementing configurations settings for Kalam..........................381
18.3.1. Handling configuration data in your application ...............381
18.3.2. Saving and loading the configuration data.........................384
18.3.3. Using configuration data from the application...................386
18.3.3.1. Font settings ............................................................387
18.3.3.2. Window geometry ...................................................387
18.3.3.3. Determining the widget style ..................................389
18.3.3.4. Setting the viewmanager.........................................391
18.3.4. Catching the changes when the application closes ............393
18.4. Settings in Qt 3.0 ..........................................................................394
18.5. Conclusion ....................................................................................397
19. Using Dialog Windows ............................................................................399
19.1. Modal: a preferences dialog..........................................................399
19.1.1. Designing the dialog ..........................................................399
19.1.2. Creating the settings dialog window..................................401
19.1.3. Calling the settings dialog window....................................412
19.2. Non-modal: Search and replace ....................................................418
19.2.1. Design ................................................................................418
19.2.2. Integration in the application .............................................419
19.2.3. Implementation of the functionality...................................422
19.3. Conclusion ....................................................................................435
20. A Macro Language for Kalam .................................................................437
20.1. Executing Python code from Python ............................................437
20.1.1. Playing with eval() .........................................................439
20.1.2. Playing with exec..............................................................440
20.1.3. Playing with execfile() .................................................442
20.2. Integrating macros with a GUI .....................................................443
20.2.1. Executing the contents of a document ...............................443
20.2.2. startup macros ....................................................................452
20.3. Creating a macro API from an application ...................................453
20.3.1. Accessing the application itself .........................................454
20.3.2. Accessing application data.................................................456

13
20.3.3. Accessing and extending the GUI......................................456
20.3.4. Kalam rivals Emacs: an Eliza macro .................................457
20.4. Conclusion ....................................................................................460
21. Drawing on Painters and Canvases ..........................................................461
21.1. Working with painters and paint devices ......................................461
21.1.1. A painting example ............................................................462
21.2. QCanvas ........................................................................................471
21.2.1. A simple Unicode character picker....................................473
21.2.1.1. The canvas...............................................................476
21.2.1.2. The view on the canvas ...........................................478
21.2.1.3. Tying the canvas and view together ........................480
21.3. Conclusion ....................................................................................484
22. Gui Design in the Baroque Age ...............................................................485
22.1. Types of gui customization ...........................................................485
22.2. Faking it with bitmaps ..................................................................486
22.3. Creating themes with QStyle ........................................................491
22.3.1. Designing the style.............................................................491
22.3.2. Setting up ...........................................................................492
22.3.3. A Qt 2 custom style............................................................493
22.3.4. Using styles from PyQt......................................................505
23. Drag and drop ..........................................................................................521
23.1. Handling drops..............................................................................521
23.2. Initiating drags ..............................................................................523
23.3. Conclusion ....................................................................................525
24. Printing.....................................................................................................527
24.1. The QPrinter class .....................................................................527
24.2. Adding printing to Kalam .............................................................528
24.3. Putting ink to paper.......................................................................530
24.4. Conclusion ....................................................................................531
25. Internationalizing an Application ............................................................533
25.1. Translating screen texts.................................................................533
26. Delivering your Application ....................................................................541
26.1. Introduction...................................................................................541
26.2. Packaging source ..........................................................................542
26.3. Starting with distutils. ...................................................................544
26.3.1. setup.py ..............................................................................544
26.3.2. MANIFEST.in....................................................................546

14
26.3.3. setup.cfg .............................................................................547
26.3.4. Creating the source distribution .........................................547
26.3.5. Installing a source archive..................................................550
26.4. Creating Unix RPM packages.......................................................550
26.5. Windows installers ........................................................................551
26.6. Desktop integration .......................................................................552
27. Envoi ........................................................................................................553
IV. Appendices .....................................................................................................555
A. Reading the Qt Documentation.................................................................557
B. PyQwt: Python Bindings for Qwt .............................................................563
B.1. NumPy............................................................................................563
B.2. PyQwt.............................................................................................568
C. First Steps with Sip ...................................................................................573
C.1. Introduction ....................................................................................573
C.2. How sip works................................................................................574
C.3. Creating .sip files............................................................................574
C.4. Things sip can’t do automatically ..................................................577
C.4.1. Handwritten code ................................................................577
C.4.2. Other limitations..................................................................580
C.5. Where to look to start writing your own wrappers/bindings..........580
C.6. Sip usage and syntax ......................................................................581
C.6.1. Usage...................................................................................581
C.6.1.1. Invocation, Command Line ......................................581
C.6.1.2. Limitations ...............................................................582
C.6.1.3. Files ..........................................................................582
C.6.1.3.1. Source Files ...................................................582
C.6.1.3.2. Files containing the wrapping .......................582
C.6.1.3.3. Intermediate Files..........................................583
C.6.1.3.4. Auxilliary Files..............................................584
C.6.1.4. .sip File Syntax.........................................................585
C.6.1.4.1. General rules .................................................585
C.6.1.4.2. Macros...........................................................585
C.7. Directives........................................................................................586
C.7.1. Documentation ....................................................................586
%Copying ..............................................................................586
%Doc......................................................................................587
%ExportedDoc.......................................................................587

15
C.7.2. Modules...............................................................................588
%Module................................................................................588
%Include ................................................................................589
%Import .................................................................................590
C.7.3. Conditional Elements ..........................................................590
%If..........................................................................................591
%End......................................................................................591
Version().................................................................................592
%Version ................................................................................593
%PrimaryVersions..................................................................594
%VersionCode........................................................................594
C.7.4. C++ and Header Code Sections ..........................................595
%HeaderCode ........................................................................595
%ExportedHeaderCode..........................................................596
%ExposeFunction ..................................................................596
%C++Code.............................................................................597
%MemberCode ......................................................................597
%VirtualCode.........................................................................598
%VariableCode ......................................................................598
C.7.5. Python Code Sections .........................................................599
%PythonCode ........................................................................599
%PrePythonCode ...................................................................599
C.7.6. Mapped Classes...................................................................600
%ConvertFromClassCode......................................................600
%ConvertToClassCode ..........................................................601
%CanConvertToClassCode....................................................601
%ConvertToSubClassCode ....................................................602
C.7.7. Special Python methods ......................................................602
PyMethods .............................................................................603
PyNumberMethods ................................................................604
PySequenceMethods ..............................................................604
PyMappingMethods...............................................................605
C.7.8. Other....................................................................................606
%Makefile ..............................................................................606
C.8. Accepted C++ / Qt constructs ........................................................606
C.9. SIPLIB Functions...........................................................................609
C.9.1. Public Support Functions ....................................................609

16
C.9.2. Information functions..........................................................609
sipGetCppPtr..........................................................................610
sipGetComplexCppPtr ...........................................................610
sipGetThisWrapper ................................................................611
sipIsSubClassInstance............................................................612
C.9.3. Conversions and argument parsing .....................................613
sipParseArgs...........................................................................614
sipConvertToCpp ...................................................................617
sipMapCppToSelf ..................................................................618
sipConvertToVoidPtr ..............................................................619
sipConvertFromVoidPtr .........................................................620
sipConvertFromBool..............................................................621
sipCheckNone ........................................................................622
sipBadVirtualResultType .......................................................623
sipBadSetType .......................................................................624
C.9.4. Ressource handling .............................................................625
sipReleaseLock ......................................................................625
sipAcquireLock......................................................................625
sipCondReleaseLock..............................................................626
sipCondAcquireLock .............................................................627
sipMalloc................................................................................628
sipFree....................................................................................629
C.9.5. Calling Python.....................................................................629
sipEvalMethod .......................................................................630
sipCallHook ...........................................................................630
C.9.6. Functions specifically for signals/slots................................631
sipEmitSignal.........................................................................631
sipConvertRx .........................................................................632
sipConnectRx.........................................................................634
sipGetRx ................................................................................635
sipDisconnectRx ....................................................................636
C.9.7. Private Functions .................................................................638
Bibliography .........................................................................................................639

17
18
List of Tables
1-1. GUI Toolkits for Python ...................................................................................33
7-1. Matrix of QObject.connect() combinations..............................................119
10-1. Qt and Python high-level datastructures.......................................................235
10-2. Qt and Python network classes.....................................................................245
C-1. C++ access specifiers and sip.........................................................................576

List of Figures
10-1. Qt Inheritance Hierarchy (only the most important classes) ........................177
10-2. Object Ownership Hierarchy ........................................................................179
20-1. Playing with eval() ....................................................................................439
20-2. Playing with exec ........................................................................................441
20-3. Playing with execfile() ...........................................................................442

List of Examples
1-1. Bootstrapping a Python application..................................................................31
6-1. hello1.py — hello world ...................................................................................89
6-2. hello2.py — a better hello world ......................................................................91
6-3. fragment from hello3.py ...................................................................................94
6-4. Fragment from hello5.py ..................................................................................94
6-5. Fragment from hello4.py ..................................................................................95
6-6. frmconnect.py ...................................................................................................97
6-7. dlgconnect.py — the subclass of the generated form .....................................100
7-1. A stupid button which is not reusable ............................................................103
7-2. A simple callback system ...............................................................................104
7-3. A central registry of connected widgets .........................................................106
7-4. Connecting a signal to a slot...........................................................................111
7-5. Connection a dial to a label with signals and slots .........................................113
7-6. Python signals and slots..................................................................................116
7-7. Python signals and slots with arguments ........................................................117
7-8. datasource.py — connecting and disconnecting signals and slots .................122

19
7-9. An XML parser with signals and slots ...........................................................128
8-1. qstring1.py — conversion from QString to a Python string.........................140
8-2. qstring2.py - second try of saving a QString to a file...................................141
8-3. empty.py - feeding zero bytes to a QCString..................................................143
8-4. null.py - empty and null QCStrings and Python strings .................................144
8-5. emptyqstring.py - feeding zero bytes to a QString .........................................146
8-6. Loading an utf-8 encoded text ........................................................................151
8-7. Building a string from single Unicode characters ..........................................153
8-10. uniqstring1.py - coercing Python strings into and from QStrings ................156
8-11. uniqstring2.py - coercing Python strings into and from QStrings ................157
9-1. refs.py - showing object references ................................................................160
9-2. circular.py - circululululular references..........................................................161
9-3. qtrefs1.py — about Qt reference counting .....................................................163
9-4. qtrefs2.py - keeping a Qt widget alive............................................................164
9-5. qtrefs3.py - Qt parents and children ...............................................................165
9-6. Eradicating a widget .......................................................................................166
9-7. children.py - getting the children from a single parent...................................167
9-8. Iterating over children.....................................................................................169
9-9. sigslot.py - a simple signals/slots implementation in Python, following the
Observer pattern.............................................................................................173
9-10. Object introspection using Qt .......................................................................175
9-11. Object introspection using Python................................................................176
10-1. event1.py - handling mouse events in PyQt..................................................180
10-2. action.py - Using a QAction to group data associated with user commands183
10-3. fragment from mdi.py - ten little scribbling windows..................................186
10-4. event2.py - using QWidget to create a custom, double-buffered drawing
widget.............................................................................................................187
10-5. snippet from event3.py - a peach puff drawing board ..................................190
10-6. fragment from action2.py - You cannot create a QPixmap before a
QApplication..................................................................................................192
10-7. buttons.py - Four pushbuttons saying ‘hello’. ..............................................198
10-8. label.py - a label associated with an edit control ..........................................199
10-9. radio.py - a group of mutually exclusive options .........................................202
10-10. listbox.py - A listbox where data can be associated with an entry .............204
10-11. tree.py - building a tree...............................................................................210
10-12. layout.py - two box layouts and adding and removing buttons dynamically to
a layout...........................................................................................................218

20
10-13. geometry.py - setting the initial size of an application ...............................220
10-14. dialogs.py - opening message and default dialogs boxes ...........................222
10-15. fragment from dialogs.py - opening a file dialog .......................................228
10-16. fragment from dialogs.py - opening a font dialog ......................................229
10-17. fragment from dialogs.py - opening a color dialog ....................................229
10-18. from dv_qt.py - using Qt utility classes......................................................231
10-19. fragment from db_python.py - using Python utility classes.......................233
10-20. Using QMimeSourceFactory (application.py)............................................241
10-21. thread1.py — Python threads without gui ..................................................242
10-22. Python threads and a PyQt gui window......................................................243
11-1. dlgcomplex.py — a subclass of frmcomplex.py ..........................................268
11-2. Setting default values....................................................................................270
12-1. A simple document-view framework ...........................................................277
12-2. Scripting an application is easy ....................................................................284
13-1. Defining a complex toggle action .................................................................288
15-1. A testcase for a document manager..............................................................319
15-2. The document manager class........................................................................325
15-3. The document class ......................................................................................332
15-4. The view class ..............................................................................................334
15-5. The application class ....................................................................................336
21-1. typometer.py - A silly type-o-meter that keeps a running count of how many
characters are added to a certain document and shows a chart of the typerate...
462
21-2. charmap.py - a Unicode character selection widget .....................................475
22-1. remote.py - remote control application.........................................................488
22-2. view.py - the main view of the remote control application ..........................489
22-3. button.py - the class that implements the pixmapped buttons ......................490
22-4. A Qt 2 custom style - a minimalist implementation of the classic Mac style in
PyQt. ..............................................................................................................493
22-5. Testing styles ................................................................................................506
23-1. Handling drop events....................................................................................521
23-2. Drag and drop ...............................................................................................524
25-1. Installing the translator .................................................................................538
26-1. README .....................................................................................................543
26-2. setup.py - a sample setup script ....................................................................544
26-3. MANIFEST.in ..............................................................................................546
C-1. Interface for QRegExp::match .......................................................................616

21
22
Preface
The main topic of this book is application development using PyQt, a library
extension to the Python programming language — a library that is meant to form
the basis for GUI programming. PyQt is free software, but there is also a
commercial IDE available, BlackAdder, that is specially written to assist working
with PyQt. I will show you the ins and outs of PyQt by developing a complete and
complex application.
Like most thirty–somethings who started programming in their teens, I’ve worked
with a lot of different technologies. I started with Sinclair Basic, going on to Turbo
Pascal and SNOBOL — I have developed for Windows in pure C, with Borland
Pascal and with Visual Basic. I’ve done my stretch with Oracle Forms, and served
as a Java developer. On Linux, I’ve wet my feet with Free Pascal, with C++, using
XForms and Qt. And just when I was getting fond of Qt and C++, I found out about
Python — a few years ago now. I found programming with PyQt to be a lot more
fun than anything else, and productive fun, too.
For sheer productivity, nothing beats Python and PyQt. And while there’s always
something new to learn or explore in Python, if you’re in the mood, it’s easy and
pleasant to write useful applications from the first day. No other programming
language or library has ever given me that.
So, when Cameron Laird, during a discussion on the comp.lang.python newsgroup
suggested that I’d write a book on this particular way of developing GUI
applications with Python, I started to think — and more than think. I started to
contact publishers, until one day Shawn Gordon of TheKompany brought me into
contact with Joshua Drake of Opendocs. I started writing text and code almost
immediately.
Joshua’s patience has been monumental — I should have written this book between
February and May, but it took me until November. All I can say for myself is that a
lot of effort has gone into the book. I discuss most of the concepts and classes of the
Qt library, which might be useful not only to Python developers, but also to C++
developers, and I have written a lot of example scripts.
Where Bruce Eckel (of Thinking in Java fame) favors small example programs
because they clearly illustrate the matter in hand, John Grayson in Python and
Tkinter argues that larger real-life applications are more useful because they don’t

23
Preface

hide the complexity that is a part of any programming effort.


Both are right, of course, so I decided to give you both small examples and one
really large one. Part I and II of this book concern themselves with concepts: here
the examples are small, often amounting to less than one page of code. Part III takes
you through the development of a complete, complex application. In this case an
editor, but one with a lot of extra features. I think it’s a very good way of learning
what developing complex applications entails - I spare you none of the nasty details
that software development entails.
I have tried to keep to a very clear style of coding, with few or none of the clever
hacks that are possible in Python — like adding the methods of one class to another,
or creating lists of function objects. The purpose is to tell you about writing real
applications using Python and Qt. Clever hacking has its place, but is best savored
on its own.
The emphasis of the book is also firmly on application development, not on creating
graphics per se — although several techniques are mentioned here and there that
have to do with creating charts and graphs.

1. Who is using PyQt


The combination of Python and Qt is extremely powerful, and is used in a wide
variety of applications. People are scripting OpenGL applications with it, creating
complex 3D models, animation applications, writing database applications, games,
utilities and hardware monitoring applications. It is used in open source projects,
but also by large companies, like Disney Television and Media. If you’re not
working on embedded software, hardware drivers or a new operating system,
chances are that PyQt is the right choice for you, too.

2. For whom is this book intended


This is the first book on Python and Qt. There have been quite a few books on C++
and Qt, but you would need to be fairly adept at mentally searching and replacing
C++ language constructs to be able to use those books for pleasure and profit if

24
Preface

your chosen language is Python. The same holds for the extensive html
documentation that comes with the C++ Qt library.
With the growing popularity of Python, PyQt and BlackAdder, people will start
using these tools who don’t want to translate C++ to Python to figure out what they
are supposed to do.
This is the first group of people for whom I’ve written this book: beginning software
developers who have chosen Python because it allows them to become productive
quickly with a language and an environment that have been designed to
accommodate ‘subject specialists’. That is, people who need to get an application
done to help them with their work, but who are not developers by profession.
Then there are the experienced developers, people who have been coding in Visual
Basic, Delphi or Java, and who, like the first group, now need something a lot more
productive and portable. They will be able to grasp the concepts quickly, but may
find a lot of use in the advanced code examples and the in-depth discussion of issues
particular to PyQt.
Another group of possible readers consists of C++ developers who have turned to
Python as a rapid prototyping language. Prototyping with the same GUI library they
will use for their final C++ application will give them a definite advantage, as most
of the prototype code will remain useful.
Finally there are people who are more experienced in Python than I am, but who
want to get acquainted with one of the best-designed GUI toolkits available for the
language—there is a lot of interesting content to be found in this book for them, too.
My aim in writing this book was to create a genuine vademecum for Python, PyQt
and GUI programming. If you keep referring to this book a year after you’ve
acquired it, if you can find the answer to most of your daily and quite a few of your
exceptional problems, and if you tend to keep this book in the vicinity of your desk,
then I will have succeeded.

3. How to read this book


Like ancient Gaul, this book is divided in three parts. The first part details the
installation of PyQt and of BlackAdder. Then the book takes you through a tour of
the interface of BlackAdder. You might want to read this part in order. There is also

25
Another Random Document on
Scribd Without Any Related Topics
shall find, that in different animals, nature operates in different
ways, in order to produce the same general end.
The human female, and the female of quadrupeds, are possessed of
a temperate cherishing warmth; this fits them for easy gestation,
and enables them to afford proper nourishment to their young, till
the time of birth.
Birds are intended to soar in the air, or to flit from place to place in
search of food. Gestation, therefore, would be burdensome to them.
For this reason, they lay eggs, covered with a hard shell: these, by
natural instinct, they sit upon, and cherish till the young be
excluded. The ostrich and the cassowary are said to be exempt from
this law; as they commit their eggs to the sand, where the intense
heat of the sun hatches them.
Fishes inhabit the waters, and most of them have cold blood, unfit
for nourishing their young. The all-wise Creator, therefore, has
ordained that most of them should lay their eggs near the shore;
where, by means of the solar rays, the water is warmer, and also
fitter for that purpose; and also because water insects abound more
there, which afford nourishment to the young fry.
Salmon, when they are about to deposit their eggs, are led by
instinct to ascend the stream, where purity and freshness are to be
found in the waters: and to procure such a situation for its young,
this fish will endure incredible toil and hazard.
The butterfly-fish is an exception to this general law, for that brings
forth its young alive. The species of fish whose residence is in the
middle of the ocean, are also exempt. Providence has given to these,
eggs that swim; so that they are hatched among the sea-weeds,
which also swim on the surface.
The various kinds of whales have warm blood, and therefore bring
forth their young alive, and suckle them with their teats.
Some amphibious animals also bring forth their young alive, as the
viper, &c. But such species as lay eggs, deposit them in places where
the heat of the sun supplies the want of warmth in the parent. Thus
the frog, and the lizard, drop their’s in shallow waters, which soon
receive a genial heat by the rays of the sun; the common snake, in
dunghills, or other warm places. The crocodile and sea-tortoise go
ashore to lay their eggs in the sand; in these cases, Nature, as a
provident nurse, takes care of all.
The multiplication of animals is not restrained to the same rule in all;
for some have a remarkable power of increase, while others are, in
this respect, confined within very narrow limits. Yet, in general, we
find, that nature observes this order, that the least animals, and
those which are most useful for food to others, usually increase with
the greatest rapidity. The mite, and many other insects, will multiply
to a thousand within the compass of a few days; while the elephant
hardly produces a young one in two years.
Birds of the hawk-kind seldom lay more than two eggs; while poultry
will produce from fifteen to thirty. The diver, or loon, which is eaten
by few animals, lays also only two eggs; but the duck-kind, moor
game, partridges, &c. and small birds in general, lay a great many.
Most of the insect tribes neither bear young nor hatch eggs; yet they
are the most numerous of all living creatures; and were their bulk
proportionable to their numbers, there would not be room on the
earth for any other animals. The Creator has wisely ordained the
preservation of these minute creatures. The females lay not their
eggs indiscriminately, but are endued with instinct to choose such
places as may supply their infant offspring with proper nourishment:
in their case, this is absolutely necessary, for the mother dies as
soon as she has deposited her eggs, the male parent having died
before this event takes place; so that no parental care ever falls to
the lot of this orphan race. And indeed, were the parents to live, it
does not appear that they would possess any power to assist their
young. Butterflies, weevils, tree-bugs, gall-insects, and many others,
lay their eggs on the leaves of plants; and every different tribe
chooses its own species of plants. Nay, there is scarce any plant
which does not afford nourishment to some insect; and still more,
there is hardly any part of a plant which is not preferred by some of
them. Thus one feeds upon the flower; another upon the leaves;
another upon the trunk; and still another upon the root. But it is
particularly curious to observe how the leaves of some trees of
plants are formed into dwellings for the convenience of these
creatures. Thus the gall-insect, fixes her eggs in the leaves of an
oak; the wounded leaf swells, and a knob arises like an apple, which
includes, protects, and nourishes the embryo. In the same manner
are the galls produced, which are brought from Asiatic Turkey, and
which are used both as a medicine, and as a dye in several of our
manufactories.
When the tree-bug has deposited its eggs in the boughs of the fir-
tree, excrescences arise, shaped like pearls. When another insect of
the same species has deposited its eggs in the mouse-ear, chick-
weed, or speedwell plants, the leaves contract in a wonderful
manner into the shape of a head. The water spider excludes eggs
either on the extremities of juniper, which from thence forms a
lodging that resembles the arrow-headed grass; or on the leaves of
the poplar, from whence a red globe is produced. The tree-louse lays
its eggs on the leaves of the black poplar, which turn into a kind of
inflated bag; and so in many other instances.
Nor is it only upon plants that insects live and lay their eggs. The
gnat commits her’s to stagnant waters; the flesh-fly, in putrified
flesh; another kind of insect deposits her’s in the cracks of cheese.
Some insects exclude their eggs on certain animals; the mill-beetle,
between the scales of fishes; a species of the gadfly, on the back of
bullocks; another of the same species, on the back of the rein-deer;
another, in the noses of sheep; another still, in the intestinal tube, or
the throat of horses. Nay, even insects themselves are generally
surrounded with the eggs of other insects; so that there is, perhaps,
no animal to be found, but what affords both lodging, and
nourishment, and food, to other animals: even man himself, the
haughty lord of this lower world, is not exempt from this general
law.

We shall next call the reader’s attention to some particulars


respecting the Formation of Animals.
Whatever matter may be in itself as to its essence, it is certain that it
appears to our senses as various and heterogeneous: however, the
modus of the formation of animals is still unknown. The inspired
writers express themselves here, at least, according to the capacity
of the learned, as well as the vulgar, when they acknowledge the
ignorance of mankind,—how the bones do at first grow in their
embryo state,—and that we are fearfully and wonderfully made,
when we are fashioned secretly in the lower parts of the earth.
However, it seems not probable, that one part of matter acting upon
another, should produce animal existence, though we grant it may
have a strange and unaccountable power in the alteration of matter
purely insensible or inanimate. Fermentation may dilate, and
extremely alter the parts of animated matter, when they are
delineated and marked out by the finger of the Almighty; but still,
matter being a principle purely passive and irrational, we cannot
conceive how it should become an animal, any more than a world, it
being much more easy for stones to leap out of a quarry, and make
an Escurial, without asking the architect’s leave, or calling for the
mason, with his mortar and trowel, to assist them.
Nor seems it necessary, or rational, that the first seed of every
creature should formally include all those seeds that should be
afterwards produced from it; since it is, we think, sufficient that it
should potentially include them, just as Abraham did Levi; or as one
kernel does all those indeterminate kernels that may be thence
afterwards raised; the first seeds being doubtless of the same nature
with those that now exist, after so many thousand years, the order
of time making only an accidental difference; which if we do not
grant, we must run into this absurdity, that every thing does not
produce its like,—a bird a bird, or a horse a horse,—which would be
to fill all the world with monsters, which nature does so much abhor.
But every vegetable seed, or kernel, for example, does now actually
and formally contain all the seeds or kernels which may be at any
time afterwards produced from them. A kernel has indeed, as we
have found by microscopes, a pretty fair and distinct delineation of
the tree and branches into which it may be afterwards formed by the
fermentation of its parts, and addition of suitable matter; as in the
tree are potentially contained all the thousands and millions of
kernels, and so of trees, that shall or may be thence raised
afterwards: and some are apt to believe it must be similar in the first
animals; whereas the finest glasses, which are brought to an almost
incredible perfection, cannot discover actual seeds in seeds, or
kernels in kernels; though, if there were any such thing as an actual
least atom, they might, one would think, be discovered by them,
since they have shewn us not only seeds, but even new animals, in
many parts of matter where we never suspected them, and even in
some of the smallest animals themselves, whereof our naked sight
can take no cognizance. As for the parts of matter, be they how they
will, finite or infinite, it makes no great alteration; for, if these parts
are not all seminal, we are no nearer. Nay, at best, an absurdity
seems to be the consequence of this hypothesis; because, if those
parts are infinite, and include all successive generations of animals,
it would follow that the number of animals too should be infinite;
and, instead of one, we should have a thousand infinites; and it
would be strange too if they should not, some of them, be greater or
less than one another.
For that pleasant fancy, that all the seeds of animals were distinctly
created at the beginning of time and things, that they are mingled
with all the elements, that we take them in with our food, and the
he and she atoms either fly off or stay, as they like their lodgings;
we hope there is no need of being serious to confute it. And we may
ask of this, as well as the former hypothesis,—what need of them,
when the work may be done without them? The kernel, as before,
contains the tree, the tree a thousand other fruits, and ten thousand
kernels; the first animal several others; and as many of them as
Nature can dispose of, and provide fit nourishment for, are produced
into what we may call actual being, in comparison to what they
before enjoyed. If it be asked, whether these imperfect creatures
have all distinct souls while lurking yet in their parent? we answer,
that there is no need of it; they are not yet so much as well-defined
bodies, but rather parts of the parent: there is required yet a great
deal more of the chemistry and mechanism of nature, and that in
both sexes, to make one or more of these embryo beings, the
offspring of man, capable of receiving a rational soul; but when that
capacity comes, and wherein it consists, perhaps he only knows,
who is the Father of spirits, as well as the former of the universe.

On the Preservation of Animals.—With respect to the preservation of


animals, it maybe observed, that in tender age, while the young are
unable to provide for themselves, the parent possesses the most
anxious care for them. The lioness, the tigress, and every other
savage of the wilderness, are gentle and tender towards their
offspring; they spare no pains, no labour, for their helpless progeny;
they scour the forest with indescribable rage; destruction marks their
path; they bear their victim to the covert, and teach their whelps to
quaff the blood of the slain. There is one great law, which the all-
wise Creator has implanted in animals towards their offspring, which
is, that, according to their nature, they should provide for their
nourishment, defence, and comfort.
All quadrupeds give suck to their young, and support them by a
liquor of a most delicate taste, and perfectly easy of digestion, till
they are capable of receiving nourishment from more solid food.
Birds build their nests in the most artificial manner, and line them as
soft as possible, that the eggs or young may not be injured. Nor do
they build promiscuously, but chuse such places as are most
concealed, and likely to be free from the attacks of their enemies:
thus the hanging-bird of the tropical countries, makes its nest of the
fibres of withered plants lined with down, and fixes it at the
extremity of some bough hanging over the water, that it may be out
of reach; and the diver places its swimming nest upon the water
itself, among the rushes.
The male rooks and crows, during the time of incubation, bring food
to the females. Pigeons, and most of the small birds which pair, sit
by turns; but where polygamy prevails, the males scarcely take any
care of the young.
Birds of the duck kind pluck the feathers off their breast, and cover
their eggs with them, lest they should be injured by cold when they
quit their nest for food; and when the young are hatched, they shew
the utmost solicitude in providing for them, till they are able to fly,
and shift for themselves.
Young pigeons are fed with hard seeds, which the parents first have
prepared in their own crops, that so the infant bird may digest them
easily. And the eagle makes its nest on the highest precipices of
mountains, and in the warmest spot, facing the sun; here the prey
which it brings is corrupted by the heat, and made digestible to the
young.
There is, indeed, an exception to this fostering care of animals in the
cuckoo, which lays its eggs in the nest of some small bird, generally
the wagtail, yellow-hammer, or white-throat, and leaves both the
incubation and preservation of the young to them. But naturalists
inform us that this apparent want of instinct in the cuckoo proceeds
from the structure and situation of its stomach, which disqualifies it
for incubation; still its care is conspicuous in providing a proper,
though a foreign situation, for its eggs.
Amphibious animals, fishes, and insects, which cannot come under
the care of their parents, yet owe this to them, that they are
deposited in places where they easily find proper nourishment.
When animals come to that maturity as no longer to want parental
care, they exercise the utmost labour and industry for the
preservation of their own lives. But the different species are many,
and the individuals of each species are very numerous. In order,
therefore, that all may be supported, the Creator has assigned to
each class its proper food, and set bounds and limits to their
appetites. Some live on particular species of plants, which are
produced only in particular animalcula; others on carcases, and
some even on mud and dung. For this reason, Providence has
ordained that some should swim in certain regions of the watery
element; that others should fly; and that some should inhabit the
torrid, the frigid, or the temperate zones. Different animals also are
confined to certain spots in the same zone: some frequent the
deserts, others the meadows, or the cultivated grounds; thus the
mountains, the woods, the pools, the gardens, have their proper
inhabitants. By this means there is no terrestrial tract, no sea, no
river, no country, but what teems with life. Hence one species of
animals does not injuriously invade the aliment of another; and
hence the world at all times affords support to so many, and such
various inhabitants, and nothing which it produces is in vain.
We ought to remark, also, the wisdom and goodness of Providence
in forming the structure of the bodies of animals for their peculiar
manner of life, and in giving them clothing which is suitable both to
the country and element in which they live.
Thus the elephant, the rhinoceros, and the various kinds of
monkeys, are destined to live in the torrid regions, where the sun
darts its fiercest rays; their skins are therefore naked, for were they
covered with hair, they would perish with heat. They are also of such
conformation of body as to suit their different manner of life. The
rein-deer has his habitation in the coldest parts of Lapland; his food
is the liverwort, which grows nowhere else so abundantly; and as
the cold is in that country intense, this useful animal is covered with
hair of the densest kind; by this means he easily defies the keenness
of the arctic regions. The rough-legged partridge passes its life in
the Lapland Alps, where it feeds on the seeds of the dwarf birch:
while, to withstand the cold, and to enable it to run freely among
the snow, even its feet are thickly beset with feathers.
The camel is a native of the arid sandy deserts, which, with their
dreadful sterility, are yet capable of yielding him support. How wisely
has the Creator formed him! his foot is made to traverse the burning
sands; and as the place of his habitation affords but little water, he is
made capable of enduring long journeys, and going many days
without quenching his thirst; for he is furnished with a natural
reservoir, in which, when he drinks, he stores up a quantity of water,
and has the power of using it in a frugal and sparing manner, when,
for his food, he crops the dry thistle of the desert. The bullock
delights in low rich grounds, because there he finds the food which
is most palatable to him. The wild horse chiefly resorts to woods,
and feeds upon leafy plants. Sheep prefer hills of moderate
elevation, where they find a short sweet grass, of which they are
very fond. Goats climb up the precipices of mountains, that they
may brouse on the tender shrubs; and, in order to fit them for their
situation, their feet are made for jumping.
Swine chiefly get provision by turning up the earth; for which
purpose their snouts are peculiarly formed. In this employment they
find succulent roots, insects, and reptiles.
So various is the appetite of animals, that there is scarcely any plant
which is not chosen by some, and left untouched by others. Thus
the horse refuses the water hemlock, which the goat will eat: the
goat will not feed on monkshood, but the horse eats it with avidity.
The long-leafed water hemlock is avoided by the bullock; yet the
sheep is fond of it. The spurge is poisonous to man; but the
caterpillar finds it a wholesome nourishment. Some animals live on
the leaves of certain plants, others on the stalks, and others still on
the rind, or even the roots of the same vegetable.
It should seem from hence, that no plant is absolutely poisonous,
but only relatively so: that is, there is no plant but what is
wholesome food to some animal or other. Thus divine wisdom has
assigned an use for all its productions.
The care of Providence is further evident in giving to each animal an
instinctive knowledge of its proper aliment; but that delicacy of taste
and smell, by which they accurately distinguish the wholesome from
the pernicious, is not so evident in domestic animals as in those
which are in a state of nature.
All birds of the goose kind pass great part of their lives in water,
feeding on water-insects, fishes, and their eggs. It is evident that
they are calculated for this mode of existence; their beaks, their
necks, their feet, and their feathers, are formed for it. All other birds
are as aptly fitted for their manner of life as these.
The sea-swallow is said to get his food in a very singular way. Fish
are his support, but he is not capable of diving in order to catch
them like other aquatic birds; the sea-gull, therefore, is his caterer:
when this last has gorged himself, he is pursued by the former, who
buffets him till he casts up a part of his prey, which the other
catches before it reaches the water; but in those seasons when the
fishes hide themselves in deep water, the merganser supplies even
the gull himself with food, being capable of plunging deeper into the
sea.
Small birds are generally supposed to live principally upon the
berries of ivy and hawthorn; but modern naturalists contradict this,
and affirm that their winter food is the knot-grass, which bears
heavy seeds, like those of the black bind-weed. This is a very
common plant, not easily destroyed; it grows in great abundance by
the sides of roads, and trampling on it will not kill it; it is extremely
plentiful in corn-fields after harvest, and gives a reddish hue to them
by the multitude of its seeds. Wherever the husbandman ploughs,
this plant will grow, nor can all his art prevent it: thus a part of his
labours are necessarily destined for the propagation of a plant which
our heavenly Father has designed immediately for the support of the
“fowls of the air;” for though “they sow not, neither gather into
barns,” yet are they fed by him.
Some birds who live on insects, migrate every year to foreign
regions, in order to seek food in a milder climate; while all the
northern countries, where they live well in summer, are covered with
snow. Some naturalists reckon the different species of the Hirundo,
or swallow, among the birds of passage; while others affirm that
they do not migrate, but, at the approach of winter, seek an asylum
from the cold in the clefts of rocks, with which our island is
surrounded, or take refuge in the bottom of pools and lakes, among
the reeds and rushes; others still, who have made their observations
with more attention and patience than either of the former, allow
that the old swallows with their early brood do migrate; but that the
latter hatches, which are incapable of distant flight, lay themselves
up, and become torpid during the winter; and at the approach of
spring, by the wonderful appointment of Nature, they come forth
again with renewed life and activity. In these, and all other animals
which become torpid in the winter, the peristaltic motion of the
bowels ceases while they are dormant, so that they do not suffer by
hunger. Dr. Lister remarks, concerning this class of animals, that
their blood, when poured into a vessel, does not coagulate, like that
of all other animals; and therefore is no less fit for circulation when
they revive, than before.
The birds called moor-fowl, during great snows, work out paths for
themselves under its surface, where they live in safety, and get their
food. They moult in summer, so that about the latter end of August
they cannot fly, and are therefore obliged to run in the woods; but
then the blackberries and bilberries are ripe, from whence they are
abundantly supplied with food: but the young do not moult the first
year, and therefore, though they cannot run so well, are enabled to
escape danger by flight.
The migration of birds is not only a fact, but, as it relates to many
kinds of them, is an useful fact to mankind. This remark applies to
such of them as feed on insects, the number of which is so great,
that if these birds did not destroy them, it would be almost
impossible for us to live.
Of the various kinds of water-fowl that are known in Europe, there is
hardly any but what, in the spring, are found to repair to Lapland.
This is a country of lakes, rivers, swamps, and mountains, covered
with thick and gloomy forests, that afford shelter during summer to
these birds.
In these arctic regions, by reason of the thickness of the woods, the
ground remains moist and penetrable, and the waters contain the
larvæ of the gnat in innumerable quantities. The days there are
long, and the beautiful and splendid meteors of the night indulge
them with every opportunity of collecting so minute a food; at the
same time, men are very sparingly scattered over that vast northern
waste. Yet, Linnæus, that great explorer of nature, in his excursion
to Lapland, was astonished at the myriads of water-fowl that
migrated with him out of that country, which exceeded in multitude
the army of Xerxes, covering, for eight whole days and nights, the
surface of the river Calix! The surprise of Linnæus was occasioned
by his supposing their support to be furnished chiefly by the
vegetable kingdom, almost denied to the Lapland waters; not
knowing that the all-bountiful Creator had plenteously provided
insect food for them in that dreary wilderness.
Certain beasts, also, as well as birds, become torpid, or at least
inactive, when they are, by the rigour of the season, excluded from
the necessaries of life. Thus the bear, at the end of autumn, collects
a quantity of moss, into which he creeps, and there lies all the
winter, subsisting upon no other nourishment than his fat, collected
during the summer in the cellulous membrane, and which, without
doubt, during his fast, circulates through his vessels, and supplies
the place of food.
The hedge-hog, badger, and some kinds of mice, fill their winter
quarters with vegetables, which they eat during mild weather in the
winter, and sleep during the frosts. The bat seems cold and quite
dead, but revives in the spring: while most of the amphibious
animals get into dens, or the bottom of lakes and pools.
Among other instances of the preservation of animals, we ought to
mention that of the pole-cat of America, commonly called the squash
or skink. This is a small animal of the weasel kind, which some of
the planters of that country keep about their premises to perform
the office of a cat. This creature has always a very strong and
disagreeable smell, but when affrighted or enraged, it emits so
horrible a stench, as to prevent any other creature from approaching
it: even dogs in pursuit of it, when they find this extraordinary mode
of defence made use of, will instantly turn, and leave him undisputed
master of the field; nor can any attempts ever bring them to rally
again. Kalm, as quoted by Buffon, says, “One of these animals came
near the farm where I lived in the year 1749. It was in the winter
season, during the night; and the dogs that were upon the watch,
pursued it for some time, until it discharged against them. Although
I was in bed a good way off, I thought I should have been
suffocated; and the cows and oxen themselves, by their lowings,
shewed how much they were affected by the stench.”
Nor is even the serpent, in its various kinds, destitute of the care of
the common Father of nature. This reptile, which has neither wings
to fly, nor the power to run with much speed, would not have the
means to take its prey, were it not endowed with superior cunning to
most other creatures. In favour of the serpent, also, there is a terror
attending its appearance, which operates with such power upon
birds and other small animals, as often to cause them to fall an easy
prey to it. Hence, probably, has arisen the fiction of the power of
fascination, which has been confidently ascribed to the rattlesnake
and some other serpents.

On the Destruction of Animals.


In considering the destruction of animals, we may observe that
Nature is continually operating: she produces, preserves for a time,
and then destroys all her productions. Man himself is subject to this
general order; for he also, like other creatures, returns to the dust
from whence he was taken.
This process of nature is marked even in the vicissitudes of the
seasons. Spring, like the jovial, playful infancy of all living creatures,
represents childhood and youth; for then plants spread forth their
flowers, fishes play in the waters, birds sing, and universal nature
rejoices. Summer, like middle age, exhibits plants and trees full
clothed in green; fruits ripen; and every thing is full of life. But
autumn is comparatively gloomy; for then the leaves fall from the
trees, and plants begin to wither, insects grow torpid, and many
animals retire to their winter quarters.
The day proceeds with steps similar to the year. In the morning
every thing is fresh and playful; at noon all is energy and action;
evening follows, and every thing is inert and sluggish.
Thus the age of man begins from the cradle; pleasing childhood
succeeds; then sprightly youth; afterwards manhood, firm, severe,
and intent on self-preservation; lastly, old age creeps on, debilitates,
and, at length, totally destroys our tottering bodies.
But we must consider the destruction of animals more at large. We
have before observed, that all animals do not live on vegetables, but
there are some which feed on animalcula; others on insects. Nay,
some there are which subsist only by rapine, and daily destroy some
or other of the peaceable kind.
The destruction of animals by each other, is generally in progression,
—the strong prevailing against the weak. Thus, the tree-louse lives
on plants; the fly called musca amphidivora, lives on the tree-louse;
the hornet and wasp-fly, on the musca amphidivora; the dragon-fly,
on the hornet and wasp-fly; the larger spider, on the dragon-fly;
small birds feed on the spider; and lastly, the hawk kind on the small
birds.
In like manner, the monoculus delights in putrid waters; the gnat
eats the monoculus; the frog eats the gnat; the pike eats the frog;
and the sea-calf eats the pike.
The bat and the goat-sucker make their excursions only at night,
that they may catch the moths, which at that time fly about in great
quantities.
The woodpecker pulls out the insects which lie hid in the trunks of
trees. The swallow pursues those which fly about in the open air.
The mole feeds on worms and grubs in the earth. The large fishes
devour the small ones. And perhaps there is not an animal in
existence, which has not an enemy to contend with.
Among quadrupeds, wild beasts are most remarkably pernicious and
dangerous to others. But that they may not, by their cruelty, destroy
a whole species, these are circumscribed within certain bounds: as
to the fiercest of them, they are few in number, when compared with
other animals; sometimes they fall upon and destroy each other;
and it is remarked also, that they seldom live to a great age, for they
are subject, from the nature of their diet, to various diseases, which
bring them sooner to an end than those animals which live on
vegetables. It has been asked, why has the Supreme Being
constituted such an order in nature, that, it should seem, some
animals are created only to be destroyed by others? To this it has
been answered, that Providence not only aimed at sustaining, but
also keeping a just proportion amongst all the species, and so
preventing any one of them from increasing too much, to the
detriment of men and other animals. For if it be true, as it assuredly
is, that the surface of the earth can support only a certain number of
creatures, they must all perish, if the same number were doubled or
trebled.
There are many kinds of flies, which bring forth so abundantly, that
they would soon fill the air, and, like clouds, intercept the light of the
sun, unless they were devoured by birds, spiders, and other animals.
Storks and cranes free Egypt from frogs, which, after the inundation
of the Nile, cover the whole country. Falcons clear Palestine from
mice. Bellonius, on this subject, says, “The storks come to Egypt in
such abundance, that the fields and meadows are quite white with
them. Yet the Egyptians are not displeased with them, as frogs are
generated in such numbers, that, did not the storks devour them,
they would over-run every thing. Besides, they also catch and eat
serpents. Between Belba and Gaza, the fields of Palestine are often
injured by mice and rats; and were these vermin not destroyed by
the falcons, that come here by instinct, the inhabitants could have
no harvest.”
The white fox is of equal advantage in the Lapland Alps; as he
destroys the Norway rat, which, by its prodigious increase, would
otherwise entirely destroy vegetation in that country.
It is sufficient for us to believe that Providence is wise in all its
works, and that nothing is made in vain. When rapacious animals do
us mischief, let us not think that the Creator planned the order of
nature according to our private principles of economy; for the
Laplander has one way of living, the European husbandman another,
and the Hottentot differs from them both; whereas the stupendous
Deity is one throughout the globe; and if Providence do not always
calculate according to our method of reckoning, we ought to
consider this affair in the same light as when different seamen wait
for a fair wind, every one with respect to the port to which he is
bound: these we plainly see cannot all be satisfied.
We shall conclude this branch, by turning once more to Man, and
tracing him through his progressive stages of decay, until death puts
a final period to his earthly existence.
The human form has no sooner arrived at its state of perfection,
than it begins to decline. The alteration is at first insensible, and
often several years are elapsed before we find ourselves grown old.
The news of this unwelcome change too generally comes from
without; and we learn from others that we grow old, before we are
willing to believe the report.
When the body is come to its full height, and is extended into its just
dimensions, it then also begins to receive an additional bulk, which
rather loads than assists it. This is formed of fat, which, generally, at
about the age of forty, covers all the muscles, and interrupts their
activity. Every exertion is then performed with greater labour, and
the increase of size only serves as the forerunner of decay.
The bones also become every day more solid. In the embryo they
are almost as soft as the muscles and the flesh, but by degrees they
harden, and acquire their proper vigour; but still, for the purpose of
circulation, they are furnished through all their substance with their
proper canals. Nevertheless, these canals are of very different
capacities during the different stages of life. In infancy they are
capacious, and the blood flows almost as freely through the bones
as through any other part of the body; in manhood their size is
greatly diminished, the vessels are almost imperceptible, and the
circulation is proportionably slow. But in the decline of life, the blood
which flows through the bones, no longer contributing to their
growth, must necessarily serve to increase their hardness. The
channels which run through the human frame may be compared to
those pipes that we see crusted on the inside, by the water, for a
long continuance, running through them. Both every day grow less
and less, by the small rigid particles which are deposited within
them. Thus, as the vessels are by degrees diminished, the juices
also, which circulate through them, are diminished in proportion; till
at length, in old age, these props of the human frame are not only
more solid, but more brittle.
The cartilages, likewise, grow more rigid; the juices circulating
through them, every day contribute to make them harder, so that
those parts which in youth are elastic and pliant, in age become
hard and bony, consequently the motion of the joints must become
more difficult. Thus, in old age, every action of the body is
performed with labour, and the cartilages, formerly so supple, will
now sooner break than bend.
As the cartilages acquire hardness, and unfit the joints for motion,
so also that mucous liquor, which is always secreted between the
joints, and which serves, like oil to a hinge, to give them an easy
and ready play, is now grown more scanty. It becomes thicker and
more clammy, more unfit for answering the purposes of motion, and
from thence, in old age every joint is stiff and awkward. At every
motion this clammy liquor is heard to crack; and it is not without a
great effort of the muscles, that its resistance is overcome. Old
persons have been known, that seldom moved a single joint without
thus giving notice of the violence that was done to it.
The membranes that cover the bones, joints, and the rest of the
body, become, as we grow old, more dense and more dry. Those
which surround the bones soon cease to be ductile. The fibres, of
which the muscles or flesh is composed, become every day more
rigid; and while, to the touch, the body seems, as we advance in
years, to grow softer, it is in reality increasing in hardness. It is the
skin, and not the flesh, that we feel on such occasions. The fat, and
the flabbiness of it, seem to give an appearance of softness, which
the flesh itself is very far from having. None can doubt this after
trying the difference between the flesh of young and old animals.
The first is soft and tender, the last is hard and dry.
The skin is the only part of the body that age does not harden; that
stretches to every degree of tension; and we have often frightful
instances of its pliancy, in many disorders which are incident to
humanity. In youth, while the body is vigorous and increasing, it
continues to give way to its growth. But although it thus adapts itself
to our increase, its does not in the same manner conform to our
decay. The skin, in youth and health, is plump, glossy, veined, and
clear; but when the body begins to decline, it has not elasticity
enough to shrink entirely with its diminution; it becomes dark or
yellow, and hangs in wrinkles, which no cosmetic can remove. The
wrinkles of the body in general proceed from this cause; but those of
the face seem to proceed from another, namely, from that variety of
positions into which it is put by the speech, the food, or the
passions. Every grimace, every passion, and every gratification of
appetite, puts the visage into different forms. These are visible
enough in young persons; but what at first was accidental or
transitory, becomes, by habit, unalterably fixed in the visage as it
grows older.
Hence, as we advance in age, the bones, the cartilages, the
membranes, the flesh, and every fibre of the body, becomes more
solid, more dry, and more brittle. Every part shrinks, motion
becomes more slow, the circulation of the fluids is performed with
less freedom; perspiration diminishes; the secretions alter; the
digestion becomes laborious; and the juices no longer serve to
convey their accustomed nourishment. Thus the body dies by little
and little, and all its functions are diminished by degrees; life is
driven from one part of the frame to another; universal rigidity
prevails; and death, at last, seizes upon the remnant that is left.
As the bones, the cartilages, the muscles, and all other parts of the
body, are softer in women than in men, these parts must, of
consequence, require a longer time to arrive at that state of
hardness which occasions death. Women, therefore, ought to be
longer in growing old than men, and this is, generally speaking, the
case. If we consult the tables which have been drawn up respecting
human life, we shall find that, after a certain age, they are more
long-lived than men, all other circumstances the same. Thus a
woman of sixty has a greater probability, than a man of the same
age, of living till eighty.

We shall close this chapter with an account of Animal Reproductions.


Here we discover a new field of wonders, that seems entirely to
contradict the principles that we had adopted concerning the
formation of organized bodies. It was long thought that animals
could only be multiplied by eggs, or by young ones. But it is now
found that there are some exceptions to this general rule, since
certain animal bodies have been discovered, that may be divided
into as many complete bodies as you please; for each part thus
separated from the parent body, soon repairs what is deficient, and
becomes a complete animal. It is now no longer doubtful that the
polypus belongs to the class of animals, though it much resembles
plants, both in form, and in its mode of propagating. The bodies of
these creatures may be either cut across or longitudinally, and the
pieces will become so many complete polypi. Even from the skin, or
least part, cut off from the body, one or more polypi will be
produced; and if several pieces cut off be joined together by the
extremities, they will perfectly unite, nourish each other, and become
one body. This discovery has given rise to other experiments, and it
has been found that polypi are not the only animals which live and
grow after being cut in pieces. The earth-worm will multiply after
being cut in two; to the tail there grows a head, and the two pieces
then become two worms. After having been divided, they cannot be
joined together again; they remain for some time in the same state,
or grow rather smaller; we then see at the extremity which was cut,
a little white button begin to appear, which increases and gradually
lengthens. Soon after, we may observe rings at first very close
together, but insensibly extending on all sides; a new stomach, and
other organs, are then formed. We may at any time make the
following experiment with snails: cut off their heads close by the
horns, and in a certain space of time the head will be reproduced. A
similar circumstance takes place in crabs; if one of their claws is torn
off, it will again be entirely reproduced.
A very remarkable experiment was made by Duhamel, on the thigh
of a chicken. After the thigh-bone which had been broken was
perfectly restored, and a callus completely formed, he stripped off
the flesh down to the bone;—the parts were gradually reproduced,
and the bone, and the circulation of the blood, again renewed. We
know then that some animals may be multiplied by dividing them
into pieces; and we no longer doubt that the young of certain
insects may be produced in the same manner as a branch is from a
tree; that, being cut in pieces, they will live again in the smallest
piece; that they may be turned inside out like a glove, divided into
pieces, then turned again, and yet live, eat, grow, and multiply. Here
a question offers itself, which perhaps no naturalist can resolve in a
satisfactory manner: How does it happen that the parts thus cut off,
can be again reproduced? We must suppose that germs are
distributed to every part of the body; whilst in other animals they
are only contained in certain parts. These germs unfold themselves
when they receive proper nourishment. Thus, when an animal is cut
in pieces, the germ is supplied with the necessary juices, which
would have been conveyed to other parts, if they had not been
diverted into a different channel. The superfluous juices develop
those parts which without them would have continued attached to
each other. Every part of the polypus and worm, contains in itself, as
the bud does the rudiments of a tree, all the viscera necessary to
the animal. The parts essential to life are distributed throughout the
body, and the circulation is carried on even in the smallest particles.
As we do not understand all the means that the Author of nature
makes use of to distribute life and feeling to such a number of
animals, we have no reason to maintain, that the creatures of which
we have been speaking, are the only ones that are exceptions to the
general rule in their mode of propagating. The fecundity of nature,
and the infinite wisdom of the Creator, always surpass our feeble
conceptions. The same hand that has formed the polypus and the
worm, has shewn us that it is able to simplify the structure of
animals.
CHAP. XIII.
CURIOSITIES RESPECTING ANIMALS.—(Continued.)
The Beaver, and its Habitations—The
Mole—The Frog—The Toad—The
Rhinoceros—Crocodiles and
Alligators—Fossil Crocodile—The
Ornithorhynchus Paradoxus—The
Marmot, or Mountain Rat, of
Switzerland.

Nature’s unnumber’d family combine


In one beneficent, one vast design;
E’en from inanimates to breathing man,—
A heaven-conceiv’d, heaven-executed plan;
Onward, from those who soar or lowly creep,
The wholesome equipoise through all to keep,
As faithful agents in earth, sea, and air,
The lower world to watch with constant care;
Her due proportion wisely to conserve:—
A wondrous trust, from which they never swerve.
Pratt.

It would not be consistent with the plan of this work to embrace the
whole natural history of the animal and vegetable kingdom. This is a
Book of Curiosities; and it is our intention to present the reader with
a sketch of the most remarkable things in the universe: our present
subject, therefore, being curiosities respecting animals, we shall
commence with—
The Beaver.—This animal was known to the ancients for its
possession of that sebaceous matter called castor, secreted by two
large glands near its genitals and anus, and of which each animal
has about two ounces; but they appear to have been unacquainted
with its habits and economy, with that mental contrivance and
practical dexterity, which in its natural state so strikingly distinguish
it. Beavers are found in the most northern latitudes of Europe and
Asia, but are most abundant in North America.
In the months of June and July, they assemble in large companies to
the number of two hundred, on the banks of some water, and
proceed to the formation of their establishment. If the water be
subject to risings and fallings, they erect a dam, to preserve it at a
constant level; where this level is naturally preserved, this labour is
superseded. The length of this dam is occasionally eight feet. In the
preparation of it, they begin with felling some very high, but not
extremely thick tree, on the border of a river, which can be made to
fall into the water; and, in a short time, this is effected by the united
operation of many, with their fore-teeth, the branches being
afterwards cleared by the same process. A multitude of smaller trees
are found necessary to complete the fabric, and many of these are
dragged from some distance by land, and formed into stakes; the
fixing of which is a work of extreme difficulty and perseverance,
some of the beavers with their teeth raising their large ends against
the crossbeam, while others at the bottom dig with their fore-feet
the holes in which the points are to be sunk. A series of these
stakes, in several rows, is established from one bank of the river to
the other, in connection with the cross-tree, and the intervals
between them are filled up by vast quantities of earth, brought from
a distance, and plashed with materials adapted to give it tenacity,
and prevent its being carried off. The bark is formed at the bottom,
of about the width of twelve feet, diminishing as it approaches the
surface of the water, to two or three; being thus judiciously
constructed to resist its weight and efforts by the inclined plane
instead of perpendicular opposition.
These preparations, of such immense magnitude and toil, being
completed, they proceed to the construction of their mansions,
which are raised on piles near the margin of the stream or lake, and
have one opening from the land, and another by which they have
instant access to the water. These buildings are usually of an
orbicular form, in general about the diameter of ten feet, and
comprehending frequently several stories. The foundation walls are
nearly two feet in thickness, resting upon planks or stakes, which
constitute also their floors. In the houses of one story only, the
walls, which in all cases are plastered with extreme neatness both
externally and within, after rising about two feet perpendicularly,
approach each other, so as at length to constitute, in closing, a
species of dome. In the application of the mortar to their
habitations, the tails as well as feet of the beavers are of essential
service. Stone, wood, and a sandy kind of earth, are employed in
their structures, which, by their compactness and strength,
completely preclude injury from winds and rain. The alder, poplar,
and willow, are the principal trees which they employ; and they
always begin their operations on the trunk, at nearly two feet above
the ground; nor do they ever desist from the process till its fall is
completed. They sit instead of stand, at this labour, and while
reducing the tree to the ground, derive a pleasure at once from the
success of their toils, and from the gratification of their palate and
appetite by the bark, which is a favourite species of food to them, as
well as the young and tender parts of the wood itself.
For their support in winter, ample stores are laid up near each
separate cabin; and occasionally to give variety and luxury to their
repasts during a long season, in which their stores must have
become dry and nearly tasteless, they will make excursions into the
neighbouring woods for fresh supplies. Depredations by the tenants
of one cabin on the magazines of another are unknown, and the
strictest notions of property and honesty are universal. Some of their
habitations will contain six only, others twelve, and some even
twenty or thirty inhabitants; and the whole village or township
contains in general about twelve or fourteen habitations. Strangers
are not permitted to intrude on the vicinity; but, amidst the different
members of the society itself, there appears to prevail that
attachment and that friendship which are the natural result of
mutual co-operation, and of active and successful struggles against
difficulty. The approach of danger is announced by the violent
striking of their tails against the surface of the water, which extends
the alarm to a great distance; and, while some throw themselves for
security into the water, others retire within the precincts of their
cabins, where they are safe from every enemy but man.
The neatness as well as the security of their dwellings is remarkable,
the floors being strewed over with box and fir, and displaying the
most admirable cleanness and order. Their general position is that of
sitting, the upper part of the body, with the head, being considerably
raised, while the lower touches, and is somewhat indeed immersed
in, the water. This element is not only indispensable to them in the
same way as to other quadrupeds, but they carefully preserve
access to it even when the ice is of very considerable depth, for the
purpose of regaling themselves by excursions to a great extent
under the frozen surface. The most general method of taking them
is by attacking their cabins during these rambles, and watching their
approach to a hole dug in the ice at a small distance, to which they
are obliged, after a certain time, to resort for respiration.
If a man, who had never been informed of the industry of beavers
and their manner of building, were shewn the edifices that they
construct, he would suppose them to be the work of most eminent
architects. Every thing is wonderful in the labours of these
amphibious animals; the regular plan, the size, the solidity, and the
admirable art of these buildings, must fill every attentive observer
with astonishment.
The works of beavers have a great resemblance to those of men;
and upon their first appearance we may imagine them to be
produced by rational and thinking beings; but when we examine
them nearer, we shall find that in all their proceedings, these animals
do not act upon the principles of reason, but by an instinct which is
implanted in them by nature. If reason guided their labours, we
should naturally conclude that the buildings which they now
construct would be very different from those they formerly made,
and that they would gradually advance towards perfection. But we
find that they never vary in the least from the rules of their
forefathers, never deviate from the circle prescribed to them by
nature, and the beavers of to-day build exactly after the same plan
as those which lived before the deluge. But they are not the less
worthy of our admiration. In these sagacious creatures we have an
example of the great diversity there is in the instinct of animals—
how superior is the instinct of the beaver to that of the sheep!
The flesh of the anterior part of the bodies of beavers resembles
that of land animals in substance and flavour; while that of the lower
possesses the taste, and smell, and lightness of fish.
The sexual union among these animals is connected with
considerable individual choice, sentiment, and constancy.—Every
couple pass together the autumn and winter, with the most perfect
comfort and affection. About the close of winter, the females, after a
gestation of four months, produce, in general, each two or three
young, and soon after this period they are quitted by the males, who
ramble into the country to enjoy the return of spring; occasionally
returning to their cabins, but no longer dwelling in them. When the
females have reared their young, which happens in the course of a
few weeks, to a state in which they can follow their dams, these also
quit their winter residence, and resort to the woods, to enjoy the
opening bloom and renovated supplies of nature. If their habitations
on the water should be impaired by floods, or winds, or enemies, the
beavers assemble with great rapidity to repair the damage. If no
alarm of this nature occurs, the summer is principally spent by them
in the woods, and on the advance of autumn they assemble in the
scene of their former labours and friendships, and prepare with
assiduity for the confinement and rigours of approaching winter.
When taken young, the beaver may be tamed without difficulty; but
it exhibits few or no indications of superior intelligence. Some
beavers are averse to that association which so strikingly
characterizes these animals in general, and satisfy themselves with
digging holes in the banks of rivers, instead of erecting elaborate
habitations. The fur of these is comparatively of little value.

Another subject of animal curiosity is, The Mole.—This animal is


about six inches in length, without the tail. Its body is large and
cylindrical, and its snout strong and cartilaginous. Its skin is of
extraordinary thickness, and covered with a fur, short, but yielding to
that of no other animal in fineness. It hears with particular
acuteness, and, notwithstanding the popular opinion to the contrary,
possesses eyes, which it is stated to be able to withdraw or project
at pleasure. It lives partly on the roots of vegetables, but principally
on animal food, such as worms and insects, and is extremely
voracious and fierce. Shaw relates, from Sir Thomas Brown, that a
mole, a toad, and a serpent, have been repeatedly inclosed in a
large glass vase, and that the mole has not only killed the others,
but has devoured a very considerable part of them. It abounds in
soft ground, in which it can dig with ease, and which furnishes it
with a great supply of food. It forms its subterraneous apartments
with great facility by its snout and feet, and with a very judicious
reference to escape and comfort. It produces four or five young in
the spring, in a nest a little beneath the surface, composed of moss
and herbage. It is an animal injurious to the grounds of the farmer,
by throwing up innumerable hills of mould, in the construction of its
habitation, or the pursuit of its food, and many persons obtain their
subsistence from the premiums, which are, on this account, given
for their destruction. Moles can swim with considerable dexterity,
and are thus furnished with the means of escape in sudden
inundations, to which they are frequently exposed. In Ireland, the
mole is unknown.

The Common Frog.—This is an animal so well known, that it needs no


description: but some of its properties are very singular. Its spring,
or power of taking large leaps, is remarkably great, and it is the best
swimmer of all four-footed animals. Its parts are finely adapted for
those ends, the fore members of the body being very lightly made,
the hind legs and thighs very long, and furnished with very strong
muscles. While in a tadpole state, it is entirely a water animal, for in
this element the spawn is cast. As soon as frogs are released from
their tadpole state, they immediately take to land; and if the
weather has been hot, and there fall any refreshing showers, the
ground for a considerable space is perfectly blackened by myriads of
these animalcules, seeking for some secure lurking places. Some
persons not taking time to examine into this phenomenon, imagined
them to have been generated in the clouds, and showered on the
earth: but had they, like Mr. Derham, traced them to the next pool,
they would have found a better solution of the difficulty. As frogs
adhere closely to the backs of their own species, so we know they
will do the same by fish. That they will injure, if not entirely kill carp,
is a fact indisputable, from the following relation.
Not many years ago, on fishing a pond belonging to Mr. Pitt, of
Encomb, Dorsetshire, great numbers of the carp were found, each
with a frog mounted on it, the hind legs clinging to the back, and
the fore legs fixed to the corner of each eye of the fish, which were
thin and greatly wasted, teased by carrying so disagreeable a load.
The croaking of frogs is well known; and from that, in fenny
countries, they are distinguished by ludicrous titles,—thus they are
styled Dutch nightingales, and Boston waites. Yet there is a time of
the year when they become mute, neither croaking nor opening
their mouths for a whole month; this happens in the hot season, and
that is in many places known to the country people by the name of
the paddock-moon. It is said, that during that period their mouths
are so closed, that no force (without killing the animal) will be
capable of opening them. These, as well as other reptiles, feed but a
small space of the year. Their food is flies, insects, and snails. During
winter, frogs and toads remain in a torpid state; the last of which will
dig into the earth, and cover themselves with almost the same agility
as the mole.

Not less remarkable is The Common Toad.—This is the most deformed


and hideous of all animals. The body is broad, the back flat, and
covered with a pimply dusky hide; the belly large, swagging, and
swelling out; the legs short, and its pace laboured and crawling; its
retreat gloomy and filthy: in short, its general appearance is such as
to strike one with disgust and horror. Yet it is said that its eyes are
fine. Ælian and other ancient writers tell many ridiculous fables of
the poison of the toad.
This animal was believed by some old writers to have a stone in its
head fraught with great virtues, medical and magical: it was
distinguished by the term of, the reptile, and called the toad-stone,
bufonites, krottenstern, and other names, but all its fancied powers
vanished on the discovery of its being nothing but the fossil tooth of
the sea-wolf, or of some other flat-toothed fish, not unfrequent in
our island, as well as several other countries. But these fables have
been long exploded. And as to the notion of its being a poisonous
animal, it is probable that its excessive deformity, joined to the
faculty it has of emitting a juice from its pimples, and a dusky liquid
from its hind parts, is the foundation of the report. That it has any
noxious qualities, there seem to be no proofs in the smallest degree
satisfactory, though we have heard many strange relations on that
point. On the contrary, many have taken them in their naked hands,
and held them long without receiving the least injury. It is also well
known that quacks have eaten them, and have squeezed their juices
into a glass, and drank them with impunity. They are also a common
food to many animals; to buzzards, owls, Norfolk plovers, ducks, and
snakes, which would not touch them, were they in any degree
noxious.
The fullest information concerning the nature and qualities of this
animal is contained in letters from Mr. Arscott and Mr. Pitfield to Dr.
Milles, communicated to Mr. Pennant; concerning a toad that lived
above thirty-six years with them, was completely tame, and became
so great a favourite that most of the ladies in the neighbourhood got
the better of their prejudices so far as to be anxious to see it fed. Its
food was insects, such as millepedes, spiders, ants, flies, &c. but it
was particularly fond of flesh worms, which were bred on purpose
for it. It never appeared in winter, but regularly made its appearance
in the spring, when the warm weather commenced, climbing up a
few steps, and waiting to be taken up, carried into the house, and
fed upon a table. Before it attacked the insects, it fixed its eyes on
them, and remained motionless for a quarter of a minute, when it
attacked them by an instantaneous motion of its tongue, darted on
the insect with such rapidity that the eye could not follow it,
whereby the insect stuck to the tip of its tongue, and was instantly
conveyed to its mouth. This favourite toad at last lost its life, in
consequence of being attacked by a tame raven, which picked out
one of its eyes; and although the toad was rescued, and lived a year
longer, it never recovered its health or spirit. It never showed any
signs of rage, being never provoked.

Our next subject is an animal of great bulk, The Rhinoceros.—This


quadruped is exceeded in size only by the elephant. Its usual length,
not including the tail, is twelve feet, and the circumference of its
body nearly the same. Its nose is armed with a horny substance,
projecting, in the full-grown animal, nearly three feet, and is a
weapon of defence, which almost secures it from every attack. Even
the tiger, with all his ferocity, is but very rarely daring enough to
assail the rhinoceros. Its upper lip is of considerable length and
pliability, acting like a species of snout, grasping the shoots of trees
and various substances, and conveying them to the mouth; and it is
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

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.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookname.com

You might also like