100% found this document useful (3 votes)
11 views

Rapid GUI Programming with Python and Qt 1st Edition Mark Summerfield pdf download

The document provides information about the book 'Rapid GUI Programming with Python and Qt' by Mark Summerfield, which serves as a definitive guide to PyQt programming. It includes links to various related programming books and resources, as well as details about the book's content, structure, and publisher. The document also mentions the availability of instant digital downloads in multiple formats.

Uploaded by

asmeeriliea37
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (3 votes)
11 views

Rapid GUI Programming with Python and Qt 1st Edition Mark Summerfield pdf download

The document provides information about the book 'Rapid GUI Programming with Python and Qt' by Mark Summerfield, which serves as a definitive guide to PyQt programming. It includes links to various related programming books and resources, as well as details about the book's content, structure, and publisher. The document also mentions the availability of instant digital downloads in multiple formats.

Uploaded by

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

Rapid GUI Programming with Python and Qt 1st

Edition Mark Summerfield pdf download

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

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


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

GUI Programming with Python QT Edition Boudewijn Rempt

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

Programming in Python 3 A Complete Introduction to the


Python Language 2nd Edition Summerfield

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

Programming Python 4th Edition Mark Lutz

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

The Making of a Human Bomb An Ethnography of


Palestinian Resistance Nasser Abufarha

https://ebookname.com/product/the-making-of-a-human-bomb-an-
ethnography-of-palestinian-resistance-nasser-abufarha/
Medicine Creek Seventy Years of Archaeological
Investigations 1st Edition Donna C. Roper

https://ebookname.com/product/medicine-creek-seventy-years-of-
archaeological-investigations-1st-edition-donna-c-roper/

Swaziland Bradt Travel Guides 1st Edition Mike Unwin

https://ebookname.com/product/swaziland-bradt-travel-guides-1st-
edition-mike-unwin/

Voices from the Vietnam War Xiaobing Li

https://ebookname.com/product/voices-from-the-vietnam-war-
xiaobing-li/

Marx in Movement Operaismo in Context 1st Edition


Antonio Negri

https://ebookname.com/product/marx-in-movement-operaismo-in-
context-1st-edition-antonio-negri/

Encyclopedia of CAMPS AND GHETTOS 1933 1945 Vol 1 Part


B Early Camps Youth Camps and Concentration Camps and
Subcamps under the SS Business Administration Main
Office WVHA 1st Edition Geoffrey P. Megargee
https://ebookname.com/product/encyclopedia-of-camps-and-
ghettos-1933-1945-vol-1-part-b-early-camps-youth-camps-and-
concentration-camps-and-subcamps-under-the-ss-business-
Trade Unions and Migrant Workers New Contexts and
Challenges in Europe 1st Edition Stefania Marino

https://ebookname.com/product/trade-unions-and-migrant-workers-
new-contexts-and-challenges-in-europe-1st-edition-stefania-
marino/
Rapid GUI Programming
with Python and Qt
The Definitive Guide to PyQt Programming

Mark Summerfield

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


New York · Toronto · Montreal · London · Munich · Paris · Madrid
Capetown · Sydney · Tokyo · Singapore · Mexico City
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as
trademarks. Where those designations appear in this book, and the publisher was aware of a trademark
claim, the designations have been printed with initial capital letters or in all capitals.
The author and publisher have taken care in the preparation of this book, but make no expressed or implied
warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for
incidental or consequential damages in connection with or arising out of the use of the information or
programs contained herein.
The publisher offers excellent discounts on this book when ordered in quantity for bulk purchases or
special sales, which may include electronic versions and/or custom covers and content particular to your
business, training goals, marketing focus, and branding interests. For more information, please contact:
U.S. Corporate and Government Sales
(800) 382-3419
[email protected]
For sales outside the United States, please contact:
International Sales
[email protected]
Visit us on the Web: www.prenhallprofessional.com

Library of Congress Cataloging-in-Publication Data


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

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

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

Part I: Python Programming

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


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

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


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

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

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


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

Part II: Basic GUI Programming

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


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

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


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

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


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

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

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


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

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


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

Part III: Intermediate GUI Programming

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


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

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

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

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


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

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


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

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


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

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

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


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

Part IV: Advanced GUI Programming

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


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

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


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

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


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

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

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


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

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

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

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

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

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

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

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

1
2 Introduction

Figure 1 The Eric4 IDE—a PyQt4 application

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


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

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

The Structure of the Book

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


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

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

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

Acknowledgments

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

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


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

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

Data Types and Data Structures


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

Figure 1.1 The IDLE Python Shell window

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

9
10 Chapter 1. Data Types and Data Structures
Introduction

The IDLE Development Environment


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

Executing Python Code


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

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

print "Hello World"

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


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


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

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

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

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

% python hello.py

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

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

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


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

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


whenever a Python application that uses them is run.

Variables and Objects


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

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

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


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

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

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


This is similar to the Java assignment, Integer x = new Integer(71); for C++ a near-equivalent
would be int xd = 71; int &x = xd;.
Exploring the Variety of Random
Documents with Different Content
The signs have been divided into four triplicities, thus: fiery , ,
; earthy, , , ; airy, , , ; and watery, , , .

The bicorporal, or double-bodied, signs are , , and the first half


of . The fruitful signs are , , ; the barren signs are ,
, and .

These descriptions are useful in showing the modifications brought


to bear (by the sign ascending) on the planet's influence. But, when
no planets are in or near the ascendant at birth, the following
descriptions of the temperament and form of body produced by each
sign ascending at birth should be used.

Aries ( ) is a hot and fiery sign and produces a lean body, spare
and strong, large bones, grey eyes, with a quick glance and sandy or
red-coloured hair. The temper is violent. It governs the head and
face; its colour is white.

Taurus ( ) differs greatly, in its effects, from the preceding sign; it


is cold and dry, and gives a broad brow and thick lips. A person born
under it is melancholy and slow to anger but, when roused, furious
and difficult to be appeased. It governs the neck and throat; its
colour is red.

Gemini ( ) is in nature hot and moist and produces a person of


straight, tall body, sanguine complexion, brilliant eyes and light
brown hair. The temperament of those born under Gemini is lively
and the understanding good. This sign governs the arms and
shoulders; its colours are red and white.
Cancer ( ) is by nature cold and moist; it produces a native fair
and pale, short in stature, with a round face, sand-coloured brown
hair and grey eyes. Those born under it are phlegmatic, indolent and
gentle tempered. Women born under this sign generally have many
children. It governs the breast and stomach; its colours are green
and russet-brown.

Leo ( ) is a fiery, hot and dry sign. When it rises at birth without
any planet being near the ascendant, the native will be of tall
stature, with yellow hair, ruddy complexion and oval face, and he will
have a quick glance and a strong voice. It governs the heart, the
back and the neck; its colours are red and green.

Virgo ( ) is an earthy, cold, barren, feminine sign. When it


ascends, it shows a well-formed body, slender and tall, straight,
dark-brown hair and a round face. The mind of the native is
ingenious, but rather inconstant. It governs the belly; its colour is
black speckled with blue.

Libra ( ) is an aërial, sanguine, masculine, hot and moist sign.


Rising at birth it produces a well-made body, with long limbs, an oval
and beautiful face, sanguine complexion, straight flaxen hair and
grey eyes. Those born under it are courteous, just and honourable.
It governs the loins; and the colours under its rule are black,
crimson and tawny.

Scorpio ( ) is a moist, phlegmatic, feminine sign. It gives a strong,


corpulent body, low stature, thick legs, hair growing low on the
forehead and heavy eyebrows. Those born under this sign are
reserved, thoughtful, subtle and malicious. It governs the lower
parts of the body; the colour under its rule is brown.
Sagittarius ( ) is a fiery, masculine sign. The person born under its
rule is handsome, with a rather long face and features, chestnut hair,
inclined to baldness and ruddy complexion; the body strong and
active. Those born under this sign are fond of field sports, are good
riders, and are lovers of animals. They are kindly, generous and
careless of danger. This sign governs the thighs and hips, and rules
yellow and green.

Capricorn ( ) is an earthy, cold, dry, feminine sign. It produces a


person of slender stature, with a long neck, narrow chest and dark
hair. The mind is quick, witty and subtle. It governs the knees and
hams and, in colours, it rules black or dark brown.

Aquarius ( ) is an airy, moist, masculine sign. In a nativity where


no planets are in or near the ascendant, it would produce a person
of a well-set, strong body, long face and delicate complexion, with
brown hair. It governs the legs and ankles and rules the sky-colour
or blue.

Pisces ( ) is a watery, cold and feminine sign. It produces a person


of short stature and fleshy body, with a rather stooping gait. Those
born under its influence are indolent and phlegmatic. It governs the
feet and toes and presides over the pure white colour. It is needful
to remember the colours belonging to the signs, as they are
especially useful in horary questions.
CHAPTER IV.

OF THE NATURES OF THE SEVEN PLANETS AND OF THEIR ESSENTIAL AND


ACCIDENTAL DIGNITIES

Of the seven planets Jupiter and Venus, because of the heat and
moisture predominant in them, are considered by the ancients as
benefics or causers of good. The Moon is so considered for the same
reasons, though in a less degree.

Saturn and Mars are causers of evil or malefic; the first from his
excess of cold, and the other from his excess of heat. The Sun and
Mercury are deemed of common influence—that is, either of good or
evil, according to the planets with which they are connected.

The planets have particular familiarity with certain places in the


zodiac by means of parts designated as their houses, and also by
their triplicities, exaltations and terms.

The nature of their familiarity by houses is as follows:—

Cancer and Leo are the most northerly of all the twelve signs; they
approach nearer than the other signs to the zenith of this part of the
earth, and thereby cause warmth and heat; they are consequently
appropriated as houses for the two principal and greater luminaries;
Leo for the Sun, as being masculine; and Cancer for the Moon, as
being feminine.

Saturn, since he is cold and inimical to heat, moving also in a


superior orbit most remote from the luminaries, occupies the signs
opposite to Cancer and Leo; these are Aquarius and Capricorn, and
they are assigned to him in consideration of their cold and wintry
nature.
Jupiter has a favourable temperament, and is situated beneath the
sphere of Saturn; he, therefore, occupies the next two signs,
Sagittarius and Pisces.

Mars is dry in nature and beneath the sphere of Jupiter; he takes the
next two signs, of a nature similar to his own, viz., Aries and Scorpio,
whose relative distances from the houses of the luminaries are
injurious and discordant.

Venus, possessing a favourable temperament, and, placed beneath


the sphere of Mars, takes the next two signs, Taurus and Libra.
These are of a fruitful nature and preserve harmony by the sextile
distance; this planet is never more than two signs distant from the
Sun.

Mercury never has greater distance from the Sun than the space of
one sign, and is beneath all the other planets; hence he is nearest to
both luminaries, and the remaining two signs, Gemini and Virgo, are
allotted to him.

The "houses" of the planets are readily shown by the following table.
It is exactly the same as that found in the mummy-case of the
Archon of Thebes, in ancient Egypt, as may be seen at the British
Museum:
It will be seen, at once, from this table that the Sun and Moon have
each only one house assigned them. All planets are most powerful in
that sign which constitutes one of their houses. Planets receive
detriment in the signs opposite to those of their houses. Thus,
Saturn would receive detriment in Cancer and Leo, which are the
signs opposite to his houses, Capricornus and Aquarius. There are
some signs in which the planets are found to be very powerful,
though not to the same extent as when in their own houses; these
are called the "exaltations" of the planets, and the signs opposite to
these are those in which they receive their "fall" when they are
considered to be weak in power. Saturn has his exaltation in Libra;
his "fall" would therefore be in Aries. He governs the airy triplicity,
which is composed of the signs Gemini, Libra and Aquarius by day,
and in all the twelve signs he has these degrees (zodiacal signs)
allotted him by Ptolemy for his Terms:

In Aries 27, 28, 29, 30.


In Taurus 23, 24, 25, 26.
In Gemini 22, 23, 24, 25.
In Cancer 28, 29, 30.
In Leo 1, 2, 3, 4, 5, 6.
In Virgo 19, 20, 21, 22, 23, 24.
In Libra 1, 2, 3, 4, 5, 6.
In Scorpio 28, 29, 30.
In Sagittarius 21, 22, 23, 24, 25.
In Capricornus 26, 27, 28, 29, 30.
In Aquarius 1, 2, 3, 4, 5, 6.
In Pisces 27, 28, 29, 30.

The meaning of which is that if Saturn should rise in any of these


degrees it is a sign that he is not void of essential dignities; or, if he
is posited in any of the following degrees (which he is allowed for his
Face or Decanate) he is still not devoid of dignities. This is to be
understood of all the planets.

Saturn is allotted for his Face these degrees:

In Taurus 21, 22, 23, 24, 25, 26, 27, 28, 29, 30.
In Leo 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.
In Libra 11, 12, 13, 14, 15, 16, 17, 18, 19, 20.
In Sagittarius 21, 22, 23, 24, 25, 26, 27, 28, 29, 30.
In Pisces 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.

Jupiter has his exaltation in Cancer and his fall in Capricornus. He


rules the fiery triplicity, Aries, Leo and Sagittarius, by night.

He has these degrees allotted for his Terms:

In Aries 1, 2, 3, 4, 5, 6.
In Taurus 16, 17, 18, 19, 20, 21, 22.
In Gemini 8, 9, 10, 11, 12, 13, 14.
In Cancer 7, 8, 9, 10, 11, 12, 13.
In Leo 20, 21, 22, 23, 24, 25.
In Virgo 14, 15, 16, 17, 18.
In Libra 12, 13, 14, 15, 16, 17, 18, 19.
In Scorpio 7, 8, 9, 10, 11, 12, 13, 14.
In Sagittarius 1, 2, 3, 4, 5, 6, 7, 8.
In Capricornus 13, 14, 15, 16, 17, 18, 19.
In Aquarius 21, 22, 23, 24, 25.
In Pisces 9, 10, 11, 12, 13, 14.

He has for his Face, or Decanate:

Of Gemini 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.
Of Leo 11, 12, 13, 14, 15, 16, 17, 18, 19, 20.
Of Libra 21, 22, 23, 24, 25, 26, 27, 28, 29, 30.
Of Capricornus 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.
Of Pisces 11, 12, 13, 14, 15, 16, 17, 18, 19, 20.

Mars has Aries for his day-house and Scorpio for his night-house. He
is exalted in Capricornus, and has his fall in Cancer.

He governs the watery Triplicity, viz., Cancer, Scorpio and Pisces, and
he has these degrees in each sign for his Terms:

In Aries 22, 23, 24, 25, 26.


In Taurus 27, 28, 29, 30.
In Gemini 26, 27, 28, 29, 30.
In Cancer 1, 2, 3, 4, 5, 6.
In Leo 26, 27, 28, 29, 30.
In Virgo 25, 26, 27, 28, 29, 30.
In Scorpio 1, 2, 3, 4, 5, 6.
In Aquarius 26, 27, 28, 29, 30.
In Pisces 21, 22, 23, 24, 25, 26.

He has allotted to him for his Face these degrees:

In Aries 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.
In Gemini 11, 12, 13, 14, 15, 16, 17, 18, 19, 20.
In Leo 21, 22, 23, 24, 25, 26, 27, 28, 29, 30.
In Virgo 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.
In Pisces 21, 22, 23, 24, 25, 26, 27, 28, 29, 30.

The Sun rules the fiery Triplicity—Aries, Leo and Sagittarius—by day.
He is exalted in the sign of Aries, and receives his fall in Libra.

He has no degrees admitted him for his Terms, but in the twelve
signs he has the following degrees for his Face:

In Aries 11, 12, 13, 14, 15, 16, 17, 18, 19, 20.
In Gemini 21, 22, 23, 24, 25, 26, 27, 28, 29, 30.
In Virgo 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.
In Scorpio 11, 12, 13, 14, 15, 16, 17, 18, 19, 20.
In Capricornus 21, 22, 23, 24, 25, 26, 27, 28, 29, 30.

Venus governs the earthy Triplicity—Taurus, Virgo and Capricornus—


by day. She is exalted in Pisces, and has her fall in Virgo. She has
the following degrees for her Terms:

In Aries 7, 8, 9, 10, 11, 12, 13, 14.


In Taurus 1, 2, 3, 4, 5, 6, 7, 8.
In Gemini 15, 16, 17, 18, 19. 20.
In Cancer 21, 22, 23, 24, 25, 26, 27.
In Leo 14, 15, 16, 17, 18, 19.
In Virgo 8, 9, 10, 11, 12, 13.
In Libra 7, 8, 9, 10, 11.
In Scorpio 15, 16, 17, 18, 19, 20, 21.
In Sagittarius 9, 10, 11, 12, 13, 14.
In Capricornus 1, 2, 3, 4, 5, 6.
In Aquarius 13, 14, 15, 16, 17, 18, 19, 20.
In Pisces 1, 2, 3, 4, 5, 6, 7, 8.

The following degrees are allowed for her Face:

In Aries 21, 22, 23, 24, 25, 26, 27, 28, 29, 30.
In Cancer 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.
In Virgo 11, 12, 13, 14, 15, 16, 17, 18, 19, 20.
In Scorpio 21, 22, 23, 24, 25, 26, 27, 28, 29, 30.
In Pisces 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.

Mercury governs the airy Triplicity, viz., Gemini, Libra and Aquarius,
by night. He has his exaltation in Virgo, and his fall in Pisces. He has
the following degrees for his Terms:

In Aries 15, 16, 17, 18, 19, 20, 21.


In Taurus 9, 10, 11, 12, 13, 14, 15.
In Gemini 1, 2, 3, 4, 5, 6, 7.
In Cancer 14, 15, 16, 17, 18, 19, 20.
In Leo 7, 8, 9, 10, 11, 12, 13.
In Virgo 1, 2, 3, 4, 5, 6, 7.
In Libra 20, 21, 22, 23, 24.
In Scorpio 22, 23, 24, 25, 26, 27.
In Sagittarius 15, 16, 17, 18, 19, 20.
In Capricornus 7, 8, 9, 10, 11, 12.
In Pisces 15, 16, 17, 18, 19, 20.

These degrees are assigned him for his Face:

In Taurus 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.
In Cancer 11, 12, 13, 14, 15, 16, 17, 18, 19, 20.
In Virgo 21, 22, 23, 24, 25, 26, 27, 28, 29, 30.
In Sagittarius 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.
In Aquarius 11, 12, 13, 14, 15, 16, 17, 18, 19, 20.

The Moon governs the earthy Triplicity, viz., Taurus, Virgo and
Capricornus, by night.

She is exalted in Taurus, and has her fall in Scorpio. The Sun and the
Moon have no terms assigned them.

In the twelve signs she has these degrees assigned her for her Face:

In Taurus 11, 12, 13, 14, 15, 16, 17, 18, 19, 20.
In Cancer 21, 22, 23, 24, 25, 26, 27, 28, 29, 30.
In Libra 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.
In Sagittarius 11, 12, 13, 14, 15, 16, 17, 18, 19, 20.
In Aquarius 21, 22, 23, 24, 25, 26, 27, 28, 29, 30.
A planet in his fall is very weak in his influence. The Houses count
first in dignity, then the Exaltation; afterwards the Triplicity, the
Terms, and the Faces.

The meaning of this is, if a planet is in any of the signs we call his
house or houses, he is essentially strong, and he is allowed five
dignities.

If he is in the sign in which he is said to be exalted, he is allowed


four dignities.

If he should be placed in any of the signs allowed him for his


Triplicity, he is allowed three dignities.

If in any of the degrees in the signs which are given as his Terms, he
has two dignities.

If in any of the degrees of the sign given to him as his Face, he is


allowed one essential dignity. Accidental dignities are when a planet
is swift in motion, angular or in sextile aspect with Jupiter or Venus.

There was a great difference between the Arabian, Indian, and


Greek methods in the disposing of the degrees of the sign to each
planet until the time of Ptolemy. Since then almost all astrologers
followed the method he left, which is that which has been given in
this chapter.
CHAPTER V.

OF THE INFLUENCES OF THE SEVEN PLANETS

The planet Saturn is the most remote of the seven planetary orbs
recognised by the ancient writers on astrology. He is of a pale ash
colour, slow in motion, only finishing his course through the twelve
signs of the zodiac in 29 years and about 157 days. His greatest
north latitude from the ecliptic is 2 degrees 48 minutes; his south
latitude is 2 degrees 49 minutes.

Those born with this planet well-dignified [4] are studious, grave,
economical, prudent, patient and in all their actions sober and
somewhat austere. They are not much given to the love of women,
but they are persons of much depth of feeling, and, when they do
love, they are very constant. They are given to the study of occult
matters, [5] and are of a melancholic, suspicious and jealous
temperament. In person when well-dignified Saturn gives a rather
tall stature and long limbs. The hair is dark, the eyebrows much
marked and generally meeting between the eyes, which are dark
brown, deep set and close together. The nose is long and generally
somewhat bent over the lips and the under jaw slightly protrudes.
The complexion is sallow, the ears large and the hands and feet are
generally long, but not fleshy.

Those born under the potent aspect of Saturn are generally slow of
speech and their voices are harsh; when Saturn rises in a horoscope
devoid of dignities, the native is envious, covetous, malicious, subtle,
untruthful and of a discontented disposition. In person frequently
deformed, with long and irregular features, the eyes and hair dark
and the skin yellow and harsh.
In man's body this planet rules the spleen, the right ear, the lips and
the teeth. In illness he gives ague, palsy, ruptures (especially should
he rule in the sign of Scorpio), jaundice, toothache and all affections
of the sight, of the ear, of the teeth and jaws and of the legs.

The herbs he governs are the hemlock, hellebore, burdock, sage,


henbane, rue, nightshade and mandrake.

The trees under his rule are the willow, the yew, the cypress, the
box-tree and the pine.

The beasts he governs are the elephant, the wolf, the bear, the dog,
[6] the basilisk, the crocodile, the scorpion, the serpent, the rat, the
mouse and all manner of creeping things; among birds, the crow,
the cuckoo, the raven, the owl and the bat.

Of fish he rules the eel, the tortoise and all shell fish.

The minerals he governs are lead and the dross of all metals.

His stones are jet, onyx and all dark stones which are incapable of
polish. The colour he rules is black.

He rules Saturday—the first hour after sunrise, and the eighth hour
of the same day. His number is 55. In gathering the herbs under his
rule the ancients were particular to do so in his hours, as this
rendered the medicament more powerful. This is to be observed
regarding the herbs ruled by all the planets.

Saturn's orb is nine degrees before and after any aspect; that is, his
influence begins to operate when either he applies to any planet or it
applies to him within nine degrees of his perfect aspect, and his
influence continues in force until he is separated nine degrees from
the aspect. His angel is Cassiel. His friends are Jupiter, Venus,
Mercury and the Moon; his enemies are Mars and the Sun.
Jupiter is the next planet below Saturn and is of a bright, clear, azure
colour. He much exceeds Saturn in motion, as he finishes his course
through the twelve signs in twelve years. His greatest north latitude
is 1 degree 38 minutes, and his greatest south latitude 1 degree 40
minutes. When he rises at birth well-dignified he gives an erect, tall
stature, sanguine complexion, oval face, large grey eyes, thick
brown hair, full lips and good teeth. In temperament those born
under the good influence of this planet are honourable, generous
and hospitable, but loving material pleasures, kind and affectionate
to wife and family, charitable, desiring to be well thought of and
hating all mean and sordid actions. The voices of those born under
Jupiter are clear and sonorous. When this planet rises devoid of
dignities the native will be gluttonous, profligate, vain, and boastful,
of mean abilities and shallow understanding, easily seduced to
extravagance and a tyrant to those of his family and household.

In man's body he rules the lungs and the blood, and of diseases he
gives apoplexy, gout, inflammation of the lungs, pleurisy and all
illnesses proceeding from corruption of the blood.

The herbs he governs are cloves, mace, nutmeg, gilliflower,


marjoram, mint, borage and saffron.

Of trees, he rules the mulberry, the olive, the vine, the fig, the beech
and the pear-tree.

Of beasts, the sheep, the hart, the ox and all those animals that are
useful to man.

Of birds, the stork, the snipe, the lark, the eagle, the pheasant, the
partridge and the peacock.

Of fishes, the whale, the dolphin and the sword-fish.

His metal is tin.

His stones are the sapphire, the amethyst and the emerald.
Of colours he rules red mixed with green.

His day is Thursday and he rules the first hour after sunrise and the
eighth hour. His number is 78.

His orb is 9 degrees before and after any aspect.

All the planets except Mars are his friends.

His angel is Zadkiel.

Mars in order succeeds Jupiter. He appears of a red colour, and


finishes his course through the zodiac in 1 year 321 days. His
greatest north latitude is 4 degrees 31 minutes. His south latitude is
6 degrees 47 minutes. When he is well-dignified in a horoscope, the
native is courageous, confident, loving war and all that belongs to it,
jealous of honour, hot-tempered and a great lover of field-sports. In
person he will be of middle stature, broad-shouldered and with big
bones; the complexion of a red fairness; the hair is crisp or curly and
also red, but this varies slightly according to the sign rising at birth;
in watery signs the hair is not so red, and in earthy signs it is more
chestnut; the eyes are grey and have a bold, fixed glance like that of
a hawk.

When he is ill-dignified at birth, the native is turbulent, cruel,


boastful, a promoter of sedition, ungracious in manners and
unscrupulous in his actions, with no fear of either God or man. He
rules the head and face, the gall, the throat and intestines; and the
diseases he gives are fevers, carbuncles, smallpox, all throat
affections, all hurts to the head and face (especially by iron), and all
diseases which arise from too much heat of blood; also accidents
from four-footed beasts.

The herbs over which he rules are the nettle, the thistle, onions,
scammony, garlic, horehound, cardamons, mustard and all herbs
giving heat.
Of trees, all those which are of a prickly nature, such as the holly,
the thorn and the chestnut.

Of beasts, all fierce animals—the tiger, the panther, the wolf, the
horse, the leopard, the wild ass and the bear.

The dog is sometimes assigned to Mars on account of its courage


and combativeness. This delightful animal is probably ruled by both
Saturn and Mars; the former giving it the quality of fidelity which it
possesses in a degree beyond all other creatures.

Of fish, the pike, the barbel and the sword-fish.

Of birds, the hawk, the vulture, the kite, the eagle, the magpie and
the cock, all of which are combative.

The metal he rules is iron. The colour he rules is red.

The stones, the carbuncle, the ruby and the blood-stone.

His orb is 7 degrees before and after any aspect.

He governs Tuesday—the first hour after sunrise, and the eighth. His
number is 39.

His friend among the planets is Venus, all the others are his
enemies.

His angel is Samael.

The Sun passes through all the twelve signs of the zodiac in one
year and a few hours over the 365 days which constitute the year.
He has no latitude.

When the Sun rises at a birth well-dignified, the native is of an


honourable disposition, but always desiring to rule, loving pomp, yet
affable, speaking with gravity and without too many words and
possessing much self-reliance and dignity of manner. In person he
will be tall, well made, with golden hair, yellowish skin, large and
piercing eyes and long, straight and well-formed features.

When ill-aspected the native is arrogant, boastful, a spendthrift,


proud, yet in poverty hanging on other men's charity, very
loquacious, restless and without judgment.

He governs the heart, the brain, the right eye and the arms; and the
diseases he causes are all illnesses of the heart, such as swoons,
palpitations, cramps, also diseases of the mouth, the brain, and the
eyes.

Of colours he rules the yellow and orange colour.

The plants subject to the Sun are all those of pungent odours, such
as the marigold, heliotrope, rosemary, balsam, peony, spikenard,
musk, St. John's wort, and ginger.

Of trees he rules the palm, the laurel, the cedar, the orange-tree and
the citron-tree.

Of beasts, the lion, the ram, the goat.

Of birds, the eagle, the cock, the buzzard.

Of fish, the star-fish, the crab-fish and the sea-fox.

He governs Sunday. His number is 34.

Of metals, gold.

Of colours he rules the yellow.

Of stones, the topaz, amber, chrysolite and all yellow stones.

His orb is 15 degrees before any aspect, and as many after


separation.

His friends are all the planets except Saturn and Mars.
His angel is Michael.

After the Sun the planet Venus succeeds in order; she is of a bright
shining colour. Her greatest north or south latitude is 2 degrees and
2 minutes. When she rises well-dignified in a nativity the person
born will be of middle stature, rather inclining to shortness, with a
beautiful complexion, light brown hair, the eyes large, of a blue or
grey colour and with a slow and rather languishing movement, red
lips, and dimples in the cheeks, chin and about the mouth. In
disposition, gracious, very tender, inclined to love-making; easy of
belief and not given to labour about anything; fond of music, plays,
and all sorts of merry-makings.

When ill-dignified at birth Venus causes the native to be over-fat,


with thick lips, and much flesh about the chin and cheeks. In
disposition, sensual, riotous and immoral.

Venus governs the lower parts of the body, and the illnesses she
gives are cancer and all affections of the womb.

All the herbs she governs have a sweet smell and, generally, have
smooth leaves and white flowers, such as the lily, both white and
yellow, and the lily of the valley, also the water lily, the myrtle,
maidenhair, violets and roses.

The trees she rules are the walnut, the almond, the apple-tree, the
box-tree, the sycamore, the ash and myrtle.

Of beasts, the hart, the rabbit, the calf and all small cattle.

Of birds, the dove, the sparrow, the nightingale, the swan, the
pelican and the swallow.

Her metal is copper.

Her stones, white and red coral, rubies, the beryl, turquoise and
lapis lazuli, because it expels melancholy.
Her colours are white and purple.

Her orb is 7 degrees before and after any aspect.

Her day of the week is Friday, of which she rules the first and eighth
hour after sunrise. Her number is 45.

Her friends are all the planets, but Saturn is the least sympathetic to
her.

Her angel is Anael.

Mercury is of a soft silver colour. His greatest north latitude is 3


degrees 33 minutes. His greatest south latitude is 3 degrees 33
minutes.

When he rises well-dignified at a birth the native is a person of


subtle intellect, an excellent logician, and possessing much
eloquence in his speech; sharp and witty, of admirable memory,
curious in occult knowledge, given to divination, and, if he should
turn his attention to trade, no man would exceed him in the
invention of new ways to gain wealth.

In person, when Mercury rises well-dignified, the native is of rather


small stature, but elegantly formed, very active and supple in his
limbs, and with long arms; he will have a long, narrow face, a high
forehead, rather swelling at the temples, grey eyes with brown spots
in them, delicate mouth, straight eyebrows, a skin of a pale yellow
or olive colour, the hair of a red-brown, commonly called auburn.

When ill-dignified at birth Mercury gives a person of very small


stature, with small, insignificant features and very small and quickly-
moving eyes; and in character he is shifty, a boaster, foolishly
loquacious and a great liar.

He rules the liver, the tongue and the nerves, and the illnesses he
gives are epilepsy, giddiness, dry cough, any affection of the tongue,
and all nervous affections.

The herbs attributed to him are generally those having a subtle


smell, and having effect on the tongue, brain, lungs, or memory;
they are vervain, adder's-tongue, aniseed, dragon-wort, and the
reed.

The trees are the elder and the filbert-tree.

The animals are the squirrel, the weasel, the spider, the greyhound,
the fox, the ape and all cunning and quickly-moving creatures.

The birds, the parrot, the magpie, the crane, the linnet and the
swallow.

Of fish, the jack-fish and the mullet.

His metal is quicksilver.

His stones all those of divers colours, white and red carnelian and
marcasite, or fire-stone.

In colours he rules azure, and all light blue colours.

His orb is 7 degrees before and after any aspect.

He governs Wednesday—the first hour and the eighth after sunrise.


His number is 114. The Moon, Venus, Jupiter, the Sun and Saturn
are his friends; Mars is his enemy.

His angel is Raphael.

The Moon is the nearest to the earth of all the seven planets. She
finishes her course through the whole twelve signs in 27 days 7
hours and 36 seconds. Her greatest north latitude is 5 degrees and
about 17 minutes, her greatest south latitude 5 degrees and 12
minutes.
When she rises well-placed in a horoscope, she signifies a person of
soft and gentle manners, timid, imaginative, loving pleasure and
ease, yet fond of moving from place to place, rather capricious, but
of a poetic and romantic turn of mind. In person, those born under
good aspects of the Moon are of middle height, with a round head
and face, pale, soft skin, large light eyes, usually one a little larger
than the other. The whole body inclined to be fleshy, the lips full,
and the hair of a dull, light colour, but not at all inclined to gold.

When the Moon is ill-aspected at birth the native is indolent,


sometimes a drunkard and vagabond, generally a liar, and, as Lilly
puts it, "a muddling creature."

The Moon governs the left side and the bladder. She gives dropsy, all
cold and rheumatic diseases, colds or hurts in the eyes, convulsive
fits, hysteria, and feminine weaknesses.

The plants she governs are all those which have soft, juicy leaves,
such as the lettuce, the melon, the gourd, the poppy, mushroom,
cabbage and colewort. Of trees, all those which have round,
spreading leaves, such as the lime-tree and the sycamore.

The beasts she rules are those which love the water, as the otter
and the seal.

She rules all sea fowl and also the goose, the duck and the night
owl.

Of fish, the oyster, the cockle and the lobster.

Her colours are light greenish-blue mixed with white.

Her metal is silver.

Her stones, pearls, diamonds, opals, crystals and selenite.

Her orb is 12 degrees before and after any aspect.


Her day is Monday; the first hour and the eighth after sunrise are
hers. Her number is 45.

Her friends are Venus, Jupiter, the Sun, Saturn and Mercury.

Her enemy among the planets is Mars.

Her angel is Gabriel.

To face Chapter VI.


CHAPTER VI.

CONCERNING THE TWELVE HOUSES OF HEAVEN AND THEIR POWERS

The ancient astrologers divided the heavens into twelve houses.

The First House.—This is called the Ascendant, and the planet rising
therein—whether well or ill-dignified—will materially affect the mind,
bodily appearance and fate of the native through his whole
existence. This house is masculine, and governs the head and face
of man and, if the planet Mars be in this house at the time of birth,
there will always be some blemish or mole in the face of the native;
if a few out of the degrees have ascended the scar or blemish is,
without fail, on the upper part of the head; if the middle part of the
sign ascends the mark is in the middle of the face; if the latter part
of the sign is ascending the mark is near the chin. This house
represents the head, the tongue and the memory, and it governs in
colours white.

The Second House.—This house has signification of the native's


wealth and worldly goods. The house is feminine, ruling the neck,
and the colour is green.

The Third House.—This governs brothers and sisters, short journeys,


neighbours, letters and writings. It is masculine and governs the
hands, arms and shoulders; its colours are red and yellow mixed.

The Fourth House.—This rules the father, inheritances or property of


the native, and shows his condition at the close of life. It is feminine,
and rules the stomach, breast and lungs; its colour is red.

The Fifth House.—This signifies the children of the native, also his
success in speculation and hazardous games, the pleasures he
enjoys and the wealth of the father. It rules the heart, back and liver,
is masculine, and represents in colour black and white mixed.

The Sixth House.—This concerns the native's servants, sheep, goats


and small cattle. It also signifies the father's kindred. This house is
feminine. It rules the belly and intestines and its colour is black.

The Seventh House gives judgment of marriage and describes the


man or woman in all love questions. It is masculine, it rules the
haunches, and its colour is black.

The Eighth House argues of death, of legacies and wills, also of the
kind of death a man shall die; it is a feminine house. It rules the
lower parts of the trunk of the body; its colours are green and black.

The Ninth House gives judgment on voyages and long journeys, and
also on events happening to the wife's kindred. It rules the hips and
thighs. It is a masculine house; its colours are green and white.

The Tenth House is called the Mid-heaven, and is feminine. This


concerns the native's mother, and also his calling. It rules the knees
and hams, and its colours are red and white.

The Eleventh House represents friends and friendship. It is


masculine and rules the legs.

The Twelfth House.—This house is often called the Evil Dæmon, for
it is the house of sorrow, self-undoing, enemies and imprisonment.
It governs great cattle. It is feminine, and rules the feet and toes,
and in colour it governs green.

The strongest houses are the first (the Ascendant) and the tenth
(the Mid-heaven). The first, fourth, seventh, and tenth are called
Angular Houses, and represent the four cardinal points of the
compass; thus the first is east, the seventh west, the fourth is north,
and the tenth south. The second, fifth, eighth, and eleventh houses
are called Succedent Houses; the third, sixth, ninth, and twelfth
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