W. David Ashley
AUSTIN, TX, USA
Andrew Krause
Leesburg, VA, USA
Any source code or other supplementary material referenced by the author in this book is available to readers on GitHub via the books product page, located at www.apress.com/978-1-4842-4178-3 . For more detailed information, please visit http://www.apress.com/source-code .
ISBN 978-1-4842-4178-3 e-ISBN 978-1-4842-4179-0
https://doi.org/10.1007/978-1-4842-4179-0
Library of Congress Control Number: 2018966864
W. David Ashley and Andrew Krause 2019
This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein.
Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-sbm.com, or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.
Introduction
One of the most important aspects of an application is the interface that is provided to interact with the user. With the unprecedented popularity of computers in society today, people have come to expect those user interfaces to be graphical, and the question of which graphical toolkit to use quickly arises for any developer. For many, the cross-platform, feature-rich GTK+ library is the obvious choice.
Learning GTK+ can be a daunting task, because many features lack documentation and others are difficult to understand even with the API documentation. Foundations of PyGTK Development aims to decrease the learning curve and set you on your way to creating cross-platform graphical user interfaces for your applications.
Each chapter in this book contains multiple examples that help you further your understanding. In addition to these examples, the final chapter of this book provides five complete applications that incorporate topics from the previous chapters. These applications show you how to bring together what you have learned to accomplish in various projects.
Each chapter starts with an overview, so that you are able to skip around if you want. Most chapters also contain exercises to test your understanding of the material. I recommend that you complete all the exercises before continuing, because the best way to learn GTK+ is to use it.
At the end of this book, there are multiple appendixes that serve as references for various aspects of GTK+. These appendixes include tables listing signals, styles, and properties for every widget in GTK+. These appendixes will remain a useful reference after you have finished reading the book and begin creating your own applications. In addition, Appendix D explains the solutions to all the exercises in the book.
Who Should Read This Book
Because this book begins with the basics and works up to more difficult concepts, you do not need any previous knowledge of GTK+ development to use this book. This book does assume that you have a decent grasp of the Python programming language. You should also be comfortable with running commands and terminating applications (Ctrl+C) in a Linux terminal.
In addition to a grasp of the Python programming language, some parts of this book may be difficult to understand without some further knowledge about programming for Linux in general. You will get more out of this book if you already comprehend basic object-oriented concepts. It is also helpful to know how Linux handles processes.
You can still use this book if you do not already know how to implement object orientation or manage processes in Linux, but you may need to supplement this book with one or more online resources. A list of helpful links and tutorials can be found on the books web site, which is located at www.gtkbook.com . You can also find more information about the book at www.apress.com .
How This Book Is Organized
Foundations of PyGTK Development is composed of 14 chapters. Each chapter gives you a broad understanding of its topic. For example, Chapter covers container widgets and introduces many of the most important widgets derived from the Gtk.Container class.
Because of this structure, some chapters are somewhat lengthy. Do not feel as though you have to complete a whole chapter in one sitting, because it can be difficult to remember all the information presented. Also, because many examples span multiple pages, consider focusing on just a few examples at a time; try to understand their syntax and intent.
Each chapter provides important information and unique perspectives that help you to become a proficient PyGTK developer.
Chapter teaches you how to install the GTK+ libraries and their dependencies on your Linux system. It also gives an overview of each of the GTK+ libraries, including GObject, GDK, GdkPixbuf, Pango, and ATK.
Chapter introduces the Gtk.Application and Gtk.ApplicationWindow classes. These classes are fundamental classes that wrap the program logic and provide some useful features for your application. While a GTK+ program can be written without utilizing these classes, you will find the creation process much easier and more object-oriented if you utilize these classes.
Chapter steps through two Hello World applications. The first shows you the basic essentials that are required by every GTK+ application. The second expands on the first while also covering signals, callback functions, events, and child widgets. You then learn about widget properties and the Gtk.Button and Gtk.Label widgets.
Chapter begins by introducing the Gtk.Container class. Next, it teaches you about horizontal and vertical boxes, grids, fixed containers, horizontal and vertical panes, notebooks, and event boxes.