Rapid GUI Programming with Python and Qt: the Definitive Guide to Pyqt Programming
Total Page:16
File Type:pdf, Size:1020Kb
Rapid GUI Programming with Python and Qt: The Definitive Guide to PyQt Programming Table of Contents Copyright..................................................................................................... 1 About the Author........................................................................................ 2 Production.................................................................................................. 2 Introduction............................................................................................... 3 The Structure of the Book............................................................................................................................................................... 5 Acknowledgements......................................................................................................................................................................... 7 Python Programming.................................................................................. 8 Data Types and Data Structures..................................................................................................................................................... 8 Executing Python Code............................................................................................................................................................... 8 Variables and Objects................................................................................................................................................................ 12 Numbers and Strings................................................................................................................................................................. 16 Collections................................................................................................................................................................................. 32 Built-in Functions..................................................................................................................................................................... 42 Summary.................................................................................................................................................................................... 45 Exercises.................................................................................................................................................................................... 46 Control Structures......................................................................................................................................................................... 48 Conditional Branching.............................................................................................................................................................. 49 Looping...................................................................................................................................................................................... 52 Functions................................................................................................................................................................................... 58 Exception Handling................................................................................................................................................................... 70 Summary.................................................................................................................................................................................... 76 Exercises.................................................................................................................................................................................... 77 Classes and Modules..................................................................................................................................................................... 80 Creating Instances..................................................................................................................................................................... 82 Methods and Special Methods.................................................................................................................................................. 84 Inheritance and Polymorphism............................................................................................................................................... 105 Modules and Multi-File Applications....................................................................................................................................... 111 Summary.................................................................................................................................................................................. 114 Exercises................................................................................................................................................................................... 115 Basic GUI Programming.......................................................................... 116 Introduction to GUI Programming............................................................................................................................................. 116 A Pop-up Alert in 25 Lines....................................................................................................................................................... 117 An Expression Evaluator in 30 Lines...................................................................................................................................... 122 A Currency Converter in 70 Lines........................................................................................................................................... 129 Signals and Slots...................................................................................................................................................................... 134 Summary.................................................................................................................................................................................. 144 Exercise.................................................................................................................................................................................... 145 Dialogs......................................................................................................................................................................................... 145 Dumb Dialogs........................................................................................................................................................................... 147 Standard Dialogs...................................................................................................................................................................... 154 Smart Dialogs........................................................................................................................................................................... 161 Summary.................................................................................................................................................................................. 169 Exercise.................................................................................................................................................................................... 170 Main Windows............................................................................................................................................................................. 172 Creating a Main Window......................................................................................................................................................... 174 Handling User Actions............................................................................................................................................................ 201 Summary.................................................................................................................................................................................. 212 Exercise.................................................................................................................................................................................... 214 Using Qt Designer........................................................................................................................................................................ 215 Designing User Interfaces........................................................................................................................................................ 217 Implementing Dialogs............................................................................................................................................................. 228 Testing Dialogs........................................................................................................................................................................ 233 Summary................................................................................................................................................................................. 234 Exercise...................................................................................................................................................................................