(Ebook) Rapid GUI Programming with Python and Qt. Definitive Guide to PyQt by Mark Summerfield ISBN 9780132354189, 0132354187 - Download the ebook now to never miss important information
(Ebook) Rapid GUI Programming with Python and Qt. Definitive Guide to PyQt by Mark Summerfield ISBN 9780132354189, 0132354187 - Download the ebook now to never miss important information
(Ebook) Rapid GUI Programming with Python and Qt: The Definitive Guide
to PyQt Programming (paperback) by Summerfield, Mark ISBN
9780134393339, 0134393333
https://ebooknice.com/product/rapid-gui-programming-with-python-and-
qt-the-definitive-guide-to-pyqt-programming-paperback-36002214
https://ebooknice.com/product/c-gui-programming-with-qt-4-1268078
https://ebooknice.com/product/c-gui-programming-with-qt-4-4098382
https://ebooknice.com/product/gui-programming-with-python-qt-
edition-5644898
(Ebook) Programming in Python 3: A Complete Introduction to the Python
Language by Summerfield, Mark ISBN 9780321680563, 0321680561
https://ebooknice.com/product/programming-in-python-3-a-complete-
introduction-to-the-python-language-36002018
https://ebooknice.com/product/beginning-pyqt-a-hands-on-approach-to-
gui-programming-with-pyqt6-2nd-edition-42052272
https://ebooknice.com/product/beginning-pyqt-a-hands-on-approach-to-
gui-programming-11088500
https://ebooknice.com/product/beginning-pyqt-a-hands-on-approach-to-
gui-programming-24240602
https://ebooknice.com/product/beginning-pyqt-a-hands-on-approach-to-
gui-programming-24240606
Rapid GUI Programming
with Python and Qt
The Definitive Guide to PyQt Programming
Mark Summerfield
Foreword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
vii
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
viii
Creating and Using Actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
Restoring and Saving the Main Window’s State . . . . . . . . . . . . . . 181
Handling User Actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
Handling File Actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
Handling Edit Actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
Handling Help Actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
ix
Multiple Document Interface (MDI) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300
Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301
Chapter 10. Events, the Clipboard, and Drag and Drop . . . . . . . . . 303
The Event-Handling Mechanism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303
Reimplementing Event Handlers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305
Using the Clipboard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310
Drag and Drop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312
Handling Custom Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317
Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318
x
Chapter 14. Model/View Programming . . . . . . . . . . . . . . . . . . . . . . . . . . 413
Using the Convenience Item Widgets . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415
Creating Custom Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 423
Implementing the View Logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 424
Implementing the Custom Model . . . . . . . . . . . . . . . . . . . . . . . . . . . 427
Creating Custom Delegates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 436
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 442
Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 443
xi
Chapter 19. Multithreading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 537
Creating a Threaded Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 539
Creating and Managing Secondary Threads . . . . . . . . . . . . . . . . . . . . . 544
Implementing a Secondary Thread . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 552
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 557
Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 558
This Is Not Quite the End . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 559
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 585
xii
Foreword
As PyQt’s creator, I’m delighted to see that this book has been written. Al-
though I served as one of the book’s technical reviewers, I’m happy to confess
that I learned a few things myself.
The PyQt documentation covers the APIs of all the PyQt classes. This book
shows you how to use all those classes, how to combine them to create dialogs,
main windows, and entire applications—all of which look good and work well,
with no arbitrary limits, and using a programming language that is a joy
to use.
What I particularly like about the book is that the examples aren’t trivial ones
designed to illustrate a simple point, but are potentially useful in their own
right. The way that different approaches are considered will reward the reader
who wants to develop a deeper understanding of how to apply PyQt to the
development of large scale, production quality applications.
I began the PyQt story back in the late 1990s. I had been using Tcl/Tk for
some time, but I felt that Tk applications looked ugly, especially when I saw
what had been achieved with the first version of KDE. I had wanted to switch
to Python, and so I thought I would combine the change of language with a
change of GUI library.
Initially I used some wrappers that had been written using SWIG, but I con-
cluded that I could produce a more suitable wrapper tool myself. I set to work
creating SIP, and released PyQt 0.1 supporting Qt 1.41 in November 1998.
Development has continued regularly ever since, both to keep up with new re-
leases of Qt and to broaden the scope of PyQt with, for example, the addition
of support tools and improved documentation. By 2000, PyQt 2.0 supported
Qt 2.2 on both Linux and Windows. Qt 3 support appeared in 2001, and
Mac OS X support in 2002. The PyQt4 series began with PyQt 4.0 in June 2006
with support for Qt 4.
My primary goal has always been to allow Python and Qt to work together in
a way that feels natural to Python programmers, while allowing them to do
anything they want in Python that can be done in C++. The key to achieving
this was the development of SIP. This gave me a specialized code generator
over which I had complete control and ensures that Python and Qt will always
fit snugly together.
The essential process of developing and maintaining PyQt is now well estab-
lished. Much of the work is now automated, which means that keeping up with
xiii
new releases of Qt from Trolltech is no longer the problem it once was, and en-
surs that PyQt will continue for years to come.
It’s been very gratifying to watch the growth of the PyQt community over the
years. If this book is part of your introduction to PyQt, then welcome!
— Phil Thompson
Wimborne, Dorset, U.K.
August 25, 2007
xiv
Introduction
This book teaches how to write GUI applications using the Python program-
ming language and the Qt application development framework. The only
essential prior knowledge is that you can program in some object-oriented pro-
gramming language, such as C++, C#, Java, or of course, Python itself. For the
rich text chapter, some familiarity with HTML and with regular expressions is
assumed, and the databases and threading chapters assume some basic knowl-
edge of those topics. A knowledge of GUI programming is not required, since
all the key concepts are covered.
The book will be useful to people who program professionally as part of their
job, whether as full-time software developers, or those from other disciplines,
including scientists and engineers, who need to do some programming in sup-
port of their work. It is also suitable for undergraduate and post-graduate stu-
dents, particularly those doing courses or research that includes a substantial
computing element. The exercises (with solutions) are provided especially to
help students.
Python is probably the easiest to learn and nicest scripting language in
widespread use, and Qt is probably the best library for developing GUI applica-
tions. The combination of Python and Qt, “PyQt”, makes it possible to develop
applications on any supported platform and run them unchanged on all the
supported platforms—for example, all modern versions of Windows, Linux,
Mac OS X, and most Unix-based systems. No compilation is required thanks
to Python being interpreted, and no source code changes to adapt to different
operating systems are required thanks to Qt abstracting away the platform-
specific details. We only have to copy the source file or files to a target machine
that has both Python and PyQt installed and the application will run.
If you are new to Python: Welcome! You are about to discover a language that
is clear to read and write, and that is concise without being cryptic. Python
supports many programming paradigms, but because our focus is on GUI
programming, we will take an object-oriented approach everywhere except in
the very early chapters.
Python is a very expressive language, which means that we can usually write
far fewer lines of Python code than would be required for an equivalent appli-
cation written in, say, C++ or Java. This makes it possible to show some small
but complete examples throughout the text, and makes PyQt an ideal tool for
rapidly and easily developing GUI applications, whether for prototyping or for
production use.
1
2 Introduction
programming teams varying in size from just one person to more than a dozen
people. Many in-house tools are written using PyQt, but because these are of-
ten used to gain competitive advantage, the companies involved generally do
not permit their use of PyQt to be made public. PyQt is also widely used in the
open source world, with games, utilities, visualization tools, and IDEs all writ-
ten using it.
This book is specifically about PyQt4, the Python bindings for the Qt 4 C++
application development framework.★ PyQt4 is provided in the form of ten
Python modules which between them contain around 400 classes and about
6 000 methods and functions. All the example programs have been tested on
Windows, Linux, and Mac OS X, using Python 2.5, Qt 4.2, and PyQt 4.2, and
additionally on Windows and Linux using Qt 4.3 and PyQt 4.3. Backporting to
earlier versions is possible in some cases, but we recommend using the most
up-to-date versions of Python, Qt, and PyQt.
Python, PyQt, and Qt can be used free of charge for noncommercial purposes,
but the license used by Python is different from that used by PyQt and Qt.
Python is available with a very liberal license that allows it to be used to de-
velop both commercial and noncommercial applications. Both PyQt and Qt are
dual-licensed: This essentially allows them to be used to develop noncommer-
cial applications—which must in turn be licensed using an acceptable open
source license such as the GNU General Public License (GPL); or to be used to
develop commercial applications—in this case, a commercial PyQt license and
a commercial Qt license must be purchased.
The book is divided into four parts. Part I is primarily a rapid conversion course
aimed at non-Python programmers who are familiar with an object-oriented
language, although it also has some (clearly marked) PyQt content. Because
the core Python language is mostly simple and is quite small, these chapters
can teach the basics of Python to a sufficient extent that real Python applica-
tions can be written.
If you think that you can pick up the Python syntax simply through reading
it, you might be tempted to skip Part I and dive straight into the GUI pro-
gramming that begins in Part II. The early chapters in Part II include back-
references to the relevant pages in Part I to support readers who choose this
approach. However, even for readers familiar with Python, we recommend
reading about QString in Chapter 1. If you are unfamiliar with partial function
application (currying), it is important to read the subsection that covers this in
Chapter 2, since this technique is sometimes used in GUI programming.
★
There are also Python bindings for the older Qt 3 library, but there is no reason to use that library
for new projects, especially since Qt 4 offers far more functionality and is easier to use.
4 Introduction
Part II begins by showing three tiny PyQt GUI applications to give an initial
impression of what PyQt programming is like. It also explains some of the
fundamental concepts involved in GUI programming, including PyQt’s high-
level signals and slots communication mechanism. Chapter 5 shows how to
create dialogs and how to create and lay out widgets (“controls” in Windows-
speak—the graphical elements that make up a user interface such as buttons,
listboxes, and such) in a dialog. Dialogs are central to GUI programming: Most
GUI applications have a single main window, and dozens or scores of dialogs,
so this topic is covered in depth.
After the dialogs chapter comes Chapter 6, which covers main windows,
including menus, toolbars, dock windows, and keyboard shortcuts, as well as
loading and saving application settings. Part II’s final chapters show how to
create dialogs using Qt Designer, Qt’s visual design tool, and how to save data
in binary, text, and XML formats.
Part III gives deeper coverage of some of the topics covered in Part II, and in-
troduces many new topics. Chapter 9 shows how to lay out widgets in quite
sophisticated ways, and how to handle multiple documents. Chapter 10 covers
low-level event handlers, and how to use the clipboard as well as drag and drop,
text, HTML, and binary data. Chapter 11 shows how to modify and subclass
existing widgets, and how to create entirely new widgets from scratch, with
complete control over their appearance and behavior. This chapter also shows
how to do basic graphics. Chapter 12 shows how to use Qt 4.2’s new graphics
view architecture, which is particularly suited to handling large numbers of in-
dependent graphical objects. Qt’s HTML-capable rich text engine is covered in
Chapter 13. This chapter also covers printing both to paper and to PDF files.
Part III concludes with two chapters on model/view programming: Chapter 14
introduces the subject and shows how to use Qt’s built-in views and how to
create custom data models and custom delegates, and Chapter 15 shows how
to use the model/view architecture to perform database programming.
Part IV continues the model/view theme, with coverage of three different
advanced model/view topics in Chapter 16. The first section of Chapter 17
describes the techniques that can be used for providing online help, and the
second section explains how to internationalize an application, including how
to use Qt’s translation tools to create translation files. The Python standard
library provides its own classes for networking and for threading, but in the
last two chapters of Part IV we show how to do networking and threading us-
ing PyQt’s classes.
Appendix A explains where Python, PyQt, and Qt can be obtained, and how to
install them on Windows, Mac OS X, and Linux. PyQt is much easier to learn
if you install it and try out some of the exercises, and if you inspect some of
the example code. Appendix B presents screenshots and brief descriptions
of selected PyQt widgets; this is helpful for those new to GUI programming.
Appendix C presents diagrams of some of PyQt’s key class hierarchies; this
Introduction 5
is useful for getting to know what classes PyQt has to offer and how they
are related.
If you have never used Python before, you should begin by reading Chapters
1–6 in order. If you already know Python, at least read the string policy (in
bullet points on page 28), and skim the material in Chapter 2 (apart from the
first section, which you’ll know well). Make sure that you are comfortable with
lambda and partial function application, both of which are covered in Chapter 2.
It is probably also worth skimming Chapter 3 as well. Then read Chapters 4,
5, and 6 in order.
Once you have covered the first six chapters, you have covered the essentials
of Python and the fundamentals of PyQt.
Chapter 7 is useful if you want to know how to create dialogs using a visual
design tool rather than purely by hand coding, something that can save a lot
of time. For file handling, at least read the first three sections of Chapter 8. If
you plan to write and read text files, also read Chapter 8’s fourth section, and
similarly the fifth section if you are going to use XML files.
For Part III, at the least read Chapter 10’s first section, on event handling, and
all of Chapter 11. Chapter 12 and the first section of Chapter 13 assume that
you have read about PyQt’s event handling, and that you have read Chapter 11.
Chapters 9 and 14 can be read stand-alone in this part, but Chapter 15 assumes
that you have read Chapter 14.
In Part IV, Chapter 16 assumes that you have read Chapters 14 and 15, but the
other chapters can be read independently.
If you find errors in the text or in the examples, or have other comments,
please write to mark@qtrac.eu quoting “PyQt book” in the subject line. The
book’s home page, where any corrections will be published, and from where the
examples and exercise solutions can be downloaded, is http://www.qtrac.eu/
pyqtbook.html.
If you want to participate in the PyQt community, it is worthwhile joining the
mailing list. Go to http://www.riverbankcomputing.com/mailman/listinfo/pyqt to
find a link to the archive, so that you can see what the mailing list is like, and
also for a form for joining. Python also has mailing lists and other community
activities. For these, go to http://www.python.org/community.
Acknowledgments
I have many people to thank, and I will begin with those who have been
intimately involved with the book.
Jasmin Blanchette is a senior software developer at Trolltech, a Qt expert, and
a fine editor and writer in his own right. I have cowritten two C++/Qt books
with him. Jasmin has made a huge number of suggestions and criticisms that
have immensely improved the quality of this book.
6 Introduction
Python Programming
Random documents with unrelated
content Scribd suggests to you:
If you have been thus far successful, go to the hat, and, calling
attention to the fact, drop the half-dollar into it; then, as if you imagined
some one was doubtful whether the coin was really in the hat, make
some remark to the effect that if they do not believe you dropped it you
will do so again, at the same moment thrusting your hand down to the
crown to take it in sight again.
At the moment the hand is in this position, carefully place the six half-
dollars on the bottom, and let one remain in the palm. Pick up one of
these six, and holding it high, let it drop, being careful, however, that it
does not hit the other five.
The coin in your hand you proceed to take from any unusual place
which may occur to you—the window curtain, portière, a gentleman’s
beard, or a lady’s coiffure, are those most naturally suggested. As soon
as you take a half-dollar from its hiding-place, you pretend to place it in
your left hand, and from there command it to pass to the hat, but in
reality you palm it in your right where it is ready for the next position
from which you desire to take it. Proceed in this way until you have
gathered in six half-dollars.
As these have been lying quietly in the hat during all this time, you have
no anxiety about sending them there, and must simply avoid going near
it while apparently filling it with the money. When the last silver piece
has been sent to its destination, request the audience to select some
one of its members to count the money in the hat, and see that none
has been lost in its flight hence. It will, of course, be found all right, and
great will be the curiosity to know how you placed it there; but do not
allow yourself to be influenced into trying it a second time, for with the
close watching you will undergo your secret will be discovered.
The hat may well be called “inexhaustible,” for all manner of things may
be made to come from its prolific crown, and in such profusion, that a
receptacle of double its size would hardly contain them.
If two boys have learned the art of palming well, they may assist each
other, and, if at all ingenious, invent a variety of tricks for an evening’s
amusement.
The following is but a suggestion, which may be varied by different
materials:
Let them borrow from the audience two tall silk hats, and place them
upon chairs standing some distance from each other. Each having
provided himself with a small rubber ball—the one resembling the other
as nearly as possible—they are ready to proceed. The hats were of
course empty when passed to the stage, but as the first boy takes his
place, back of the chair which contains a hat, he should glance down
into it, and with surprise, draw out a ball which he has had concealed in
his right hand, show it to the audience and then pretend to put it in his
left hand, but instead palm it in the right; at the same time extending
his left toward his partner. The second boy stretches out his right arm as
if to receive the ball, and at the moment his hand touches the fingers of
No. 1, he lets that which he has been palming in his right hand slip
down to his fingers, as if he had just received it from his friend. Now,
pretending to change it to his left, he palms it, as No. 1 has done, and
finally drops his left hand, which is supposed to hold the ball, into the
hat in front of him, at the same time giving the side or crown a rap with
one of his fingers, to imitate the falling of the ball. This same thing may
be repeated indefinitely, until you have balls enough to stock the village.
When you see the audience is beginning to tire, let No. 1 say, “My hat is
empty; shall I help you count the balls in yours?” No. 2 nods assent, and
looks down, as if expecting the hat to be full. He must then pretend
great surprise, and taking up the hat must turn it upside down, gently
shake it—remembering it is borrowed—and with the audience wonder
what has become of all the balls.
Eggs, small lemons or oranges, little china dolls, and a number of small
toys may be substituted for the rubber balls above given.
This trick is one of the easiest, while at the same time one of the most
pleasing, of the magician’s arts. In it an egg, apparently without any
impulse beyond that which resides within itself, travels over a hat, and
after reconnoitering it in its every nook and corner, passes gracefully
over to another, and commences its journey of discovery around the
second in much the same manner it has traversed the first.
Two hats are borrowed from the audience, and a dish of eggs is placed
upon the table by their side, when the performer requests the lady
stationed at the piano to give some music, and the exhibition
commences. The egg which is used is merely a shell, the inside having
been sucked or blown out through tiny holes made at either end. A
slender silken thread is tied to the upper button of the performer’s
waistcoat, while attached to the other end is a small piece of wax or
other sticky substance. Just before the performance commences, show
the dish of eggs, and then pass away from them and back of your
audience, to show that they (the eggs) are in no way attached to your
person.
As the music strikes up, walk to the table, take the shell from the dish,
making it appear that you had no choice, but took the first one you
chanced to touch, and place it inside the hat, at the same moment
pressing the bit of wax to its side.
As the egg is in the hat it is necessary for it to pass out upon the
outside surface. To do this the hat is slowly moved downward until the
egg is even with the brim; then by careful management and a little
practice, the effect is produced of the egg walking up the hat instead of
the hat being lowered to the egg. You may now take the egg in your
hand and, holding the hat with the crown upward in a horizontal
position, place it beneath the egg, and turn it slowly away from yourself.
The effect will be that the egg is traveling up hill. By placing the other
hat close to the one upon which you are performing, and slowly drawing
it under the egg, the latter will appear to pass over to the crown of the
second hat, and very much the same movements may be repeated on
this as on the first.
Borrow a quarter or half-dollar from your audience, and ask the owner
to place some mark upon it by which it may be identified. Wrap this in
the corner of a handkerchief, and give it to some one to hold. Next take
a ball of yarn, and having placed it in a tumbler, ask some other person
in your audience to hold his hand over the top of the tumbler in such a
way that the ball will be kept in place, and the yarn will run smoothly
through the fingers. Hold one end of the yarn some distance from the
tumbler, or near where the coin is held, and inform your audience that,
as your dispatcher is in good working order, you will proceed to send the
coin your friend has in his hand into the very center of the ball of yarn.
Take the opposite corner of the handkerchief from the one holding the
money in your right hand, and having counted one, two, three,
command the coin to pass, at the same instant snatching the
handkerchief from your friend’s hand. Next commence to unwind the
ball, being careful to keep some distance from the tumbler while so
doing.
As the yarn is nearing its end, the silver piece will drop upon the bottom
of the tumbler, and nothing is left for you to do but to request the owner
of it to step forward and see if it is the one he lent you.
In this, as in many of the tricks you have already learned, very little
preparation is required. First, a coin of the same denomination as the
one borrowed is sewed in a corner of the handkerchief. The ball is
wound upon a stick of a particular shape, which is drawn out when the
coin is to be substituted in its place. This stick should be about two and
a half inches long, one and a quarter inches wide, and an eighth of an
inch thick, rounded off at one end, and scraped until it is perfectly
smooth.
When winding your ball, be careful to have the rounded end of the stick
in the center of the ball, and the other end projecting slightly on one
side.
After you have procured your coin, palmed it, and given the
handkerchief containing the other into the hands of some person to
hold, go for your ball, which should be at some distance from your
audience, that you may have time to draw out the stick and insert the
coin in its place, while you are walking back to the table upon which is
your tumbler.
The trick is now done, but the audience must be kept ignorant of the
fact, while your conversation and subsequent acting should shroud it in
all the mystery possible.
A few years ago I had the good fortune to see a famous magician
perform. Many and wonderful were the things he did, and at times it
seemed as if other than human skill must be aiding him in his craft.
Among others, he gave the following trick, which was as enthusiastically
applauded as many of the others. It had for me no element of
strangeness, as I was already initiated into its secret. Since it has ever
been a favorite in the little amateur performances we have from time to
time been in the habit of giving, I hope it may gain a wider popularity in
the larger circle of friends to whom I am about to disclose it.
To the public it appears as follows: A plain gold ring is borrowed, placed
in a handkerchief, and given to a person to hold. A small stick is held by
two others, in such a position that its center is hidden by the
handkerchief; each person holds an end. The magician commands the
ring to pass, at the same moment snatching the handkerchief, a corner
of which he has taken, away from the one holding it—when behold! the
ring, which a moment ago was in the spectator’s hand, is now whirling
around the stick, which it evidently has just reached.
It is performed as follows: When the ring is taken from its owner, it is
palmed, and not placed in the handkerchief, as one is led to suppose,
the handkerchief being supplied, as you probably have already guessed,
with a ring which is sewed in its end. In passing the stick to the holders,
you have simply to pass it through the right hand, in the center of which
your ring is palmed, and, of course, through the ring itself. Then,
holding it until it is hidden by the handkerchief, is not difficult to do.
When you first take up the stick, be sure and use your left hand, so that
you will have it ready to pass through your ring without any awkward or
suspicious movements. Finally, pulling the handkerchief suddenly and
quickly across the stick, causes the ring to whirl upon it very much as if
it had just dropped in its place. It is always well, when performing with
the handkerchief, to have a second and similar one in your pocket, to
show in case suspicion should be aroused concerning it.
The young performer will find but little difficulty in performing this
simple sleight-of-hand trick successfully. A lighted candle, a small stick,
or magic wand, and a piece of thin cambric or muslin about six inches
square, are the materials required.
Place the lighted candle on your table, and the wand on another table or
shelf some distance from the former with the bit of cambric behind it.
Now borrow of some lady present a handkerchief, a gentleman’s being
inconveniently large. Take the handkerchief by the center, pull it
carefully between the fingers and thumb of left hand, and advance
toward the candle.
Just as you are about to burn it, stop and say, as if in answer to some
remark overheard, “Oh, no, I have not changed the handkerchief. See!”
and at the same time allow another inspection of it.
Suggest now to its owner, if, in case her handkerchief is burned, she
would like it restored again to its proper condition; and, upon her
answering in the affirmative, announce the necessity of the magic wand
for that purpose. Walk to the spot where the wand is lying, and take it
up, managing to pick up at the same time between the left thumb and
forefinger the bit of cambric; the center of this piece should be pointed
outward so that it may be readily pulled out at the desired moment, the
remainder being neatly rolled up and palmed under the thumb. This
piece should have been rolled up with the central point slightly
projecting when first placed on the shelf, and the performer should
manage to turn his back toward the audience for a few moments when
taking up the wand.
Place the wand in one of your coat pockets as you advance toward your
candle, and again take the handkerchief, putting it this time into the left
hand, and pull up the small piece of material, completely hiding the
center of the real handkerchief between the second and third fingers
and the palm of the hand.
The portion of the cambric extending beyond the thumb and forefinger
may now be safely burned, and the audience may be sure the
handkerchief is burned, as you can make some display of rolling it up in
a ball, taking care, however, to separate the burned piece from the real
article. Now take the wand from the pocket, and at the same time
manage to drop the small semi-burned piece of muslin unperceived into
the pocket; touch the handkerchief with the wand, and, after some
magic word or words, return the handkerchief to the owner to be
examined, remarking that you hope not even an odor of smoke is
noticeable about it.
Whenever displaying feats in magic, it is better for the performer to go
forward among the audience if he has anything to show or have
examined, than to allow the latter to come to his portion of the room.
His table has often some things upon it which if seen near by would do
much toward dispelling the mystery connected with his works.
A wide space should be left between his table and the front row of
spectators, as he often has occasion to step between the two in some of
his feats.
The lights also should be judiciously arranged, so as not to shine too
directly upon his hands or person, or even upon his table. Always have
everything you can possibly need in some easily accessible place, and in
just the position most convenient to be taken.
Decide beforehand what tricks you will perform, and in just what order
they are to be given. Of course, all the materials are not to be spread on
the table at the commencement of the entertainment, as they would be
in the way, and confuse you in your first acts; but they should all be at
hand, and while articles are being examined which have passed through
the various vicissitudes in a former trick, you can utilize the time when
the attention is thus carried away from yourself to gather together and
properly place the materials for your next feat.
Never be induced to perform a trick a second time, unless nearly a
whole evening’s performance intervenes. Even then it is pretty sure to
be detected.
Take a piece of clothes-line, six or seven yards long, and pass it among
your audience for inspection. While it is going its rounds, have your
hands securely tied with a handkerchief, which should be passed around
the wrists and knotted on one side.
When the rope is returned to you, drop one end between your arms, or
inside the handkerchief, and request some one to take both ends of the
rope and pull, to make sure your hands are firmly tied. It would now
seem impossible to get the rope off, unless the hands were untied or the
ends released. After two or three rapid motions, however, the rope
drops to the floor, while your hands remain tied as at first.
First, do not have your hands tied so tightly that you cannot move
them; this can be arranged by holding them slightly apart while they are
being tied. After the rope has been pulled by the holder, it is somewhat
relaxed; and then, by rubbing it between the wrists a loop may be
formed, into which the second finger may be slipped. The whole hand is
now readily thrust through, and only a jerk is necessary to send the
rope upon the floor. In performing this trick, work as quickly as possible,
that your movements may not be easily followed.
A CAMPING-OUT COOKING-STOVE.
Although the winter season is now well upon us, and its reigning king,
Jack Frost, jealous if we but mention the “camp-fire,” has covered its
very site with ice and snow, we need not fear incurring his displeasure
by the following exhibition.
Procure an old silk hat if possible, and pass it among your audience for
inspection. Have upon the stage, or at your end of the room, a table,
with a drawer open at the back. In this drawer have a small cake in the
tin in which it was baked. Let it be made in a patty-pan if convenient.
Beside this cake have a small tin cup, which will fit rather tightly into the
mouth of a china jar you have also provided. On the top of the table
have an unlighted candle, the jar, which should be porcelain if possible,
a basket containing a few eggs, a pitcher of water, some flour, and a box
marked sugar. The hat, after having been examined, is returned to you;
and the cake, along with the cup which is to receive the eggs and flour,
are put into it. This is effected as follows: Take the cake and cup in your
left hand, keeping it down behind the table, and your hat in the right
hand; bring the cake and cup up to the edge, and immediately cover it
with the hat, which you begin brushing with your right. Keep up a
running discourse all the time, so that the movement will seem natural,
and not be suspected. In a moment or two partly withdraw the left
hand, and grasping the brim of the hat, turn it upside down upon the
table. If the tin is not in a good position to catch the eggs and flour
which you are to drop into it, palm a penny and pretend to find it in the
hat, chiding your audience for carelessly overlooking it, remarking that
although a useful thing to have, it is not exactly a proper ingredient for
cake. Of course, while pretending to pick up the coin, you can arrange
the tin cup on top of your cake in the middle of the hat. Be sure that it
stands firm.
Now proceed to break one or more eggs, and drop the contents into the
hat, taking especial care that they drop into the cup. Next throw in a
spoonful of sugar, and then pour a few drops of water and one or two
spoonfuls of flour into the jar, and stir well with a spoon. Pour the
contents of the jar into the cup, and then, under pretense of draining
the last drop into the hat, force the jar down over the cup, and work it
around until the cup is well pushed up into the mouth of the jar. It is
needless to add that you must pretend all the while that you are
scraping or shaking out the mixture. The jar can now be taken out and
carelessly placed behind the sugar-pail or any other object, to prevent
the edge of the tin cup from being seen.
The trick is now completed, the only necessary thing to do is to keep up
the acting until the cake is supposed to be finished.
First, stir it well by moving the spoon around quite actively in the hat;
then light the candle, and, informing your audience that the cake is
ready for baking, take the hat in one hand and hold it over the candle
for a minute or two, occasionally glancing in to see if it is doing well.
In a short time announce that it is baked; and after blowing out the
candle, take the cake from the hat, turn it out upon a plate, and placing
a knife by its side, pass it to some one to cut, and politely request your
friends to try it, and judge upon the efficacy of your camp-stove. If the
hat was borrowed, return it with thanks to its owner, and congratulate
him upon having such a useful article always on hand.
Of course, the whole secret of this trick depends upon the arrangement
of the ropes, which are of themselves perfect. After they have been
examined, and are returned to the performer, he pretends to measure
them, and while so doing manages to bend each rope double; that is,
he brings the two ends of each together; while still holding them he
contrives to slip a small elastic band over the center of one, and
bringing the middle of the other alongside of it, he slips the band over
both, thus tying them together, as shown in the illustration.
Now holding this juncture carelessly in his left hand, over which arm a
coil or two of the rope is thrown, he passes the ends marked A through
one sleeve of the coat, and the end marked B through the other, and
these are the ends he gives to the two persons to hold.
If he now slips off the rubber band, the coat will fall; but each person
will have both ends of the same rope in his hand, and the mystery
would be easily solved. To remedy this, however, the performer, under
pretense of making the trick still more difficult, takes an end from each
of the holders, and proceeds to tie a single loop, as seen in the
illustration, thus reversing the ends, which he then returns to them.
Of course, when the band is taken off, each person has but one end of
either rope in his hand.
Tie together the ends of a piece of string about two feet long; pass it
thus tied through a button-hole of your coat. Hitch the two ends on your
thumbs, and catch up with each little finger the upper string on the
thumb of the opposite hand; then, stretching the hands apart, the string
will appear in a very complicated tangle. If the hold of the right thumb
and left little finger, or vice versâ, be then loosed, and the hands quickly
separated, the string will come away from, and appear as if it had
passed through, the outside edge of the button-hole.
Take a piece of string about four feet long; hold the ends, pointed
upward, between the first and second finger and thumb of the left hand,
and the first finger and thumb of the right hand, letting the remainder
of the string hang down in a loop. Now bring the right hand close to the
left, crossing at right angles that end of the cord held in the left hand,
and continue to pull until half the length of the string has passed the left
hand, at the same time slipping the third finger of the left hand between
the two parts of the string.
The first finger and thumb of the right hand should then seize the string
at a point just below the little finger of the left hand, the third finger of
that hand at the same time drawing back the string toward the palm of
the hand.
The part of the string now held horizontally between the two hands is
only the continuation of the end held in the left hand, though it will
appear to be the middle of the string.
This piece of the string some one of the audience should be invited to
cut, and thus apparently divide the string in halves, although in fact he
only cuts off two or three inches.
Place all the ends of the string between the teeth, withdraw the short
piece with the tongue, and show the remainder, apparently as the string
was at the commencement.
Of course, the string must not be measured, or the trick will be
detected.
―――――◀▶―――――
A MINERAL GARDEN.
Fill a clear glass jar—a fruit jar will answer the purpose—with sand, to
the depth of two or three inches; insert a few pieces of sulphate of iron,
sulphate of copper, and sulphate of aluminum, so that they will be
barely covered with the sand.
Now fill the jar to within about three inches of the top with a solution of
silicate of soda, commonly known as “water-glass,” which can be
procured at most large city drug stores. This should be diluted with
three times its bulk of water before it is poured in; and care should be
taken not to stir up the sand and disarrange the chemicals.
After standing about a week, the silicates of the various bases will
appear in a luxuriant and variously colored growth, resembling
vegetation.
Now the silicate solution may be displaced with clear water, which
should be poured in very carefully, so as not to break or disturb the
vegetation. This permanent miniature forest will be found to present a
very attractive appearance, and as no pruning or weeding are required,
the young gardener will probably feel that his trouble is well repaid. Its
development from day to day will be watched with interest by all the
members of the household, although it will be of especial value to the
invalid, to whom any new and interesting object to watch is a blessing
indeed.
Another pleasing and ingenious device I insert for the benefit of this
class of my readers, wishing, in the meantime, that it might be in my
power to make their in-door life so bright and full of interest, that they
would forget the more active sports of their sturdy brothers and sisters,
or at least cease to regret their enforced confinement. This little affair I
shall call
―――――◀▶―――――
THREE CHRISTMAS OR BIRTHDAY GIFTS.
When speaking of Christmas presents in an earlier portion of this book, I
unintentionally omitted three quite interesting and easily made puzzles,
which are always pleasing sources of amusement to the young folks,
and sure to while away many half-hours on stormy days. Such presents
are always valuable additions to the nursery closet, and in an indirect
way are as gratifying to mamma and nurse as to the little recipient
himself. The first of these is called the
OCTAGON PUZZLE.
In this, as in the Octagon, the pieces composing the cross may be made
of pasteboard, but are better and stronger if made of the white holly or
other thin “bracket wood.”
Cut three pieces—with the jig-saw, of course—in shape like Fig. 1, one
piece like Fig. 2, and one like Fig. 3.
These pieces may be of any size, but relatively each one must
correspond with the sizes and shapes indicated in the diagram.
Paint as fancy may dictate, after smoothing the edges off with sand-
paper. Pack in a box treated like that used for the “Octagon Puzzle.”
The last of these interesting puzzles is known as the
SQUARE PUZZLE.
Of the pasteboard or white holly cut out eight squares of whatever size
desired; divide four of them into halves by cutting them from corner to
corner, so there are in all twelve pieces.
The puzzle is to form a square of these twelve pieces. The illustration
shows how this is done.
When these puzzles are given to the little folks, no “key” should
accompany them, but the children should try to put them together
without help. If, however, you find they begin to lose interest, show
them the first step, and encourage them to try to finish it by
themselves.
There are great differences in children in this respect; some persevering
and unwilling to be helped at all, while others become discouraged at
the smallest obstacles and refuse to try. The latter should be
encouraged by a little help, care being taken, however, that they do a
considerable portion of the work themselves.
No doubt this “indolence,” as it is sometimes erroneously called, is
generally due to a weak physical condition, rather than to inferior
mental powers. A child of this temperament, instead of being ridiculed
by his more vigorous companions, should be encouraged and stimulated
to action; and such games or puzzles as those contained in this book
are just the things to accomplish this end.
―――――◀▶―――――
A SIMPLE FOUNTAIN.
Take a bottle holding eight or ten ounces, and insert a tube in the cork.
A fine glass tube or even a pipe-stem will answer.
The tube should reach nearly but not quite to the bottom of the bottle,
and should fit air-tight in the cork.
Fill the bottle about three-fourths full of water, and blow with
considerable force down the tube. Upon removing the mouth, the water
will spurt out, forming a miniature fountain; which will continue to play
as long as any water remains in the bottle.
―――――◀▶―――――
THE FAN FROM NAGASAKI.
A few months ago, a friend who had been for several years a resident of
Japan, came home to America for a visit, and brought with her a bright
little son and daughter, neither of whom had ever set foot on our
American shores before. The children were delighted with their
American cousins; and evidently could not find words strong enough to
sound the praises of the new games and sports which they were
constantly learning.
Their lives had been spent with Chinese or Japanese nurses; and
although kind-hearted and devoted as my friend assured me these
people were, the little exiles must have had a sorry time of it in their
foreign play-room, when compared with our own boys and girls. The
respect and almost reverence with which they regarded Jack, the most
daring scapegrace in our family, would have been very amusing had it
not been pathetic. What Jack did was always marvelous in their eyes,
and into many an unsuspected trap they were beguiled by his
mischievous pranks. They were what most of you boys and girls would
call very green, when they first reached us, but under Jack’s tuition, I
fear that next winter—in fact, at the very time you are reading this—
perhaps they will be trying the same tricks upon their innocent Japanese
nurse that Jack tried upon them.
It will not be strange if that long-suffering personage does not in his
secret heart have less respect for this illustrious nation than he has been
wont to have before.
But if so ignorant in most things, these children were very ingenious and
uncommonly happy in making things of paper.
One rainy morning, about a week after they came to us, I had occasion
to go into the nursery for something, and was quite surprised to find the
children busily engaged in folding paper. Edith had brought down some
rice-paper from her trunk, and with the help of her brother, was
fashioning all sorts of odd things from it; while the younger members of
my own family were looking on with intense interest.
I left the room, after watching them for a few minutes, but an hour
later, upon entering it again, found them still employed in the same
amusement.
It seems that their nurse had been in the habit of teaching them many
Japanese arts to keep them still while under his charge. Their nurse was
a man, strange to say, as very few female servants are employed in
either China or Japan, and now they in their turn were teaching these to
us. I confess the graceful, pretty things they were making had quite a
fascination for me, and I even left off what I had been doing, and
became a pupil with the youngsters. I took up the article which they
were just beginning to learn, and, following my little teacher’s directions,
I made what I have styled “The Fan from Nagasaki,” because my little
instructress was born and lived in that city, and learned her art from a
native Jap, and not because the fan itself, if it can strictly be called a
fan, came from that region.
The children called it by a delightfully odd Japanese name, which you
would find it hard to pronounce even if I should invent a way of spelling
it.
Edith used Japanese or rice paper for those she made; but we found a
stout quality of brown wrapping-paper, not too stiff, answers nearly as
well.
If brown paper is used, a rectangular piece about two feet long, by one
and a half feet wide, is a good-shaped piece to use.
Mark off each of the edges which measure eighteen inches into six
equal parts, each division being of course three inches long (see Fig. 1).
Now double the paper on the line at x, and you have a shape like Fig. 2.
Fold the uppermost half under at the line a a, and again outward at the
line b b; then fold the under half in precisely the same manner, and your
paper is like Fig. 3.
Upon examining the edge a a a, two openings between the folds will be
seen; whereas at the edge b b b, three openings will be found. The
hand has next to be placed in the middle of these three openings, and
the paper spread out toward the right and toward the left; that middle
fold lying flat or unfolded for the time being. Another figure is now
made like Fig. 4. Now commencing at one end of this long strip, crinkle
it the whole length as you would a lamplighter top, making the folds
even, about a quarter or half an inch wide. Be careful not to make these
folds wider than this, as the fan does not work as well when they are
wide. Yon have now a figure like that seen in Fig. 5; and if your folds
have been carefully and firmly creased, your paper is prepared to make
all sorts of strange shapes. I think Edith told me her nurse could make
sixty-five different forms from a similarly folded bit, and most of these
she was able to reproduce; but as it is some time since the children left
us to visit other friends, and I have not given the subject a second
thought till now, I find I have forgotten how many of the more intricate
ones were formed. Perhaps with the directions for these my readers will
catch the knack, as we Yankees call it, and can improvise some forms
unlike any of these, for themselves. Whatever you succeed in making,
you may be quite certain that the Nagasakian nurse, away off on the
other side of the earth, is ahead of you, and has made the same form
before; for his sixty-five must include about everything one could
possibly fashion from its folds.
In Fig. 6, the lower edge of Fig. 5 is held between the thumb and
forefinger of the left hand, while the top is spread out like a fan. For Fig.
7, take Fig. 6, insert the fingers at a, and pass them round to b, raising
the paper outward. Fig. 8 is a continuation of 6 and 7, as the upper
layer of the overhanging edge in Fig. 7 is raised by passing the finger
under it at c, and bringing it out at d.
Fig. 9 is a reverse of Fig. 8. Catch the paper by the part now uppermost,
pinch that part well together, and loosen the part which was confined in
Fig. 8.
It must be remembered that every time the fan is changed, the paper
must be pinched into its original form, Fig. 5. It will now be necessary to
make that change. After creasing the folds firmly in place (Fig. 5), lift up
the upper part a, bring the lower plaits b well together, and hold them
for the handle. With the disengaged hand, arrange the upper part in the
form of a sunshade. Another form may be got by raising the upper layer
of the sunshade cover, a species of cup or goblet. By drawing out b until
it is at right angles with the upright, the goblet form is nearer correct.
Now reverse the paper, and spread out the lower part so that it may
represent the body of a wine-glass; that which in Fig. 10 was the top of
the sunshade, is now the foot of the glass, as seen in Fig. 11.
The Chinese lantern (Fig. 12) is as easily made. Open out all the paper,
and twist it around; catch it now by the central part, and by
compressing the central folds well together, these wheels are produced
(Fig. 13).
The hat, or cup and saucer (Fig. 14), is readily made by opening the
paper out again, and catching it at the two ends.
We now come to a new form of subjects, so the original form (Fig. 5),
must once more be reverted to. If the paper is caught at both ends, it
can easily be folded so as to form Fig. 15, and a table-mat may be made
by drawing it out like Fig. 16.
A “nappie” dish, oval in form, and resembling Fig. 17, may be made
from Fig. 16, by simply raising up the sides a and b. By pressing the
paper inward, Fig. 18 is obtained. Fig. 19 is made by drawing the paper
out again, and letting it loose at the end. Thus you see, by pulling out
some parts and drawing in others, a quantity of things could be made
other than these I have shown. It would be quite interesting if every
boy and girl who reads this, would try on some rainy day to see how
near to the sixty-five he or she could come. If two or three friends in the
same neighborhood should unite their forces, and count all which are
unlike, without reference to the maker, they might not fall so far short of
the illustrious Japanese—I wish I could remember his name—after all.
―――――◀▶―――――
THE MINIATURE YACHT AND HOW TO RIG HER.
Boat making and sailing are most fascinating pursuits, and we do not
know but the old saying, “When a man has taken to boat-sailing, he is a
sailor to the end of his days,” is to a certain degree applicable to the boy
who intelligently fits out his tiny craft, and sends her on little voyages
across the neighboring pond.
If the sailing is to be done on water of any depth, there is one caution
we should like to give at the very outset: Learn to swim before you sail
her. No mere pleasure is worth risking one’s life for, and accidents will
happen even to the most careful boys.
After this, you may play on or near the water with as much safety as on
the land.
Aside from the pleasure, one learns an extremely useful lesson in
making a miniature model yacht, and in sailing her. A certain familiarity
with the rigging, and the looks of the thing, will thus be obtained, and if
your fingers have patiently set up shrouds and stays, and rove the
mimic halyards, they will be less at sea with the ropes and stays of a
real vessel.
Many boys living near the sea, and accustomed every day to see vessels
lying at anchor, or sailing in and out of the harbor, have very hazy ideas
concerning the rigging of any kind of craft. Well I remember in my early
days of being obliged to run down to the wharf to see where to attach
my topmast. Whether it belonged forward or aft of my mast I had not
the slightest remembrance, and yet scarcely a day went by without my
seeing a vessel in some form or other.
Boys are not the only persons, however, who look at things and do not
see them. The power of minute and careful observation is a rare quality,
and the majority of people go through life without forming the habit, or
indeed dreaming they have not made the best use of their sight.
For the benefit of the boys who belong to this class, and those less
fortunate ones living inland where yachts are unknown, I write this
chapter.
In several of our large cities, ponds are set apart for the especial
purpose of sailing toy vessels. They are the exclusive property of the
boys, and any fine afternoon in season, and frequently out of season, if
the ice does not interfere, crowds of boys may be seen sitting on the
edges of these “lakes,” intently watching the graceful fleet as it skims
lightly over the water. The sixty-acre lake in Prospect Park, Brooklyn,
and Conservatory Lake, Central Park, New York, are both set apart for
the owners of these miniature yachts; and it is wonderful how many
older people, as well as the boys themselves, take interest in this
amusement.
a Keel.
b Bowsprit.
c Stern.
d Mast.
e Topmast.
f Boom.
g Gaff.
h Forestay.
i Shrouds.
j Jib-stay.
k Topmast-stay.
l Topping lift.
m Main-sheet.
n Ensign.
o Throat halyards.
p Peak halyards.
q Burgee.
r Reef points.
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.
ebooknice.com