自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(0)
  • 资源 (7)
  • 收藏
  • 关注

空空如也

AUTOSAR Adaptive R22-11标准规范(全)

1.AUTOSAR最新发布的AUTOSAR Adaptive 22-11版本 /home/shefei/Downloads/AP_R22_11.png

2024-03-15

Python Tutorial Python 入门指南

1 Whetting Your Appetite mè 1 2 Using the Python Interpreter ¦^Python)ºì 5 2.1 Invoking the Interpreter N^)ºì . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 2.2 The Interpreter and Its Environment )ºì9ق¸ . . . . . . . . . . . . . . . . . . . . . . . . . 7 3 More Control Flow Tools \6§›› 11 3.1 if Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 3.2 for Statements for Šé . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 3.3 The range() Function range()¼ê . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 3.4 break and continue Statements, and else Clauses on Loops breakÚcontinueŠé,±9 ̂¥else fé . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 3.5 pass Statements pass Šé . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 3.6 Defining Functions ½Â¼ê . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 3.7 More on Defining Functions \¼ê½Â . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 4 Data Structures êâ( 23 4.1 More on Lists \óL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 4.2 The del statement delŠé . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 4.3 Tuples and Sequences |ÚS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 4.4 Sets 8Ü . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 4.5 Dictionaries i; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 4.6 Looping Techniques ̂Eâ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 4.7 More on Conditions \^‡›› . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 4.8 Comparing Sequences and Other Types ØÓSa.' . . . . . . . . . . . . . . . . . . . . . 34 5 Modules ¬ 37 5.1 More on Modules \¬ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 5.2 Standard Modules IO¬ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 5.3 The dir() Function dir() ¼ê . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 5.4 Packages  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 6 Input and Output Ñ\ÚÑÑ 49 6.1 Fancier Output Formatting OÑтª . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 6.2 Reading and Writing Files Ö©‡ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 7 Errors and Exceptions †ØÚÉ~ 57 7.1 Syntax Errors Š{†Ø . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 7.2 Exceptions É~ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 7.3 Handling Exceptions ?nÉ~ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 i 7.4 Raising Exceptions ÑÉ~ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 7.5 User-defined Exceptions ^rg½ÂÉ~ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 7.6 Defining Clean-up Actions ½Â˜n1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 7.7 Predefined Clean-up Actions ý½Â˜n1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 8 Classes 67 8.1 A Word About Terminology âŠû! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 8.2 Python Scopes and Name Spaces Š^Ú·¶˜m . . . . . . . . . . . . . . . . . . . . . . . . . 68 8.3 A First Look at Classes Уa . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 8.4 Random Remarks ˜ `² . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 8.5 Inheritance U« . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 8.6 Private Variables hkCþ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 8.7 Odds and Ends Ö¿ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 8.8 Exceptions Are Classes Too É~´a . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 8.9 Iterators S“ì . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 8.10 Generators )¤ì . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 8.11 Generator Expressions )¤ìLˆª . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 9 Brief Tour of the Standard Library IO¥VA 83 9.1 Operating System Interface öŠXڝ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 9.2 File Wildcards ©‡ÏÎ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84 9.3 Command Line Arguments ·-1ëê . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84 9.4 Error Output Redirection and Program Termination †ØÑÑ­½•Ú§SªŽ . . . . . . . . . . 84 9.5 String Pattern Matching iÎGKš . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 9.6 Mathematics êÆ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 9.7 Internet Access pé–¯ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 9.8 Dates and Times FÏڞm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 9.9 Data Compression êâØ  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 9.10 Performance Measurement 5UÝþ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 9.11 Quality Control Ÿþ›› . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 9.12 Batteries Included . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 10 Brief Tour of the Standard Library – Part II IO¥VA 91 10.1 Output Formatting ‚ªzÑÑ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 10.2 Templating ‡ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 10.3 Working with Binary Data Record Layouts ¦^?›P¹

2011-01-26

Rapid GUI Programming with Python and Qt

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 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 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 TabWidgets and StackedWidgets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272 Extension Dialogs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276 Splitters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280 Single Document Interface (SDI) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283 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 CompositeWidgets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325 Subclassing Built-inWidgets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 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 Chapter 14. Model/View Programming . . . . . . . . . . . . . . . . . . . . . . . . . . 413 Using the Convenience ItemWidgets . . . . . . . . . . . . . . . . . . . . . . . . . . . . 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 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

2011-01-26

wxPython in Action

PART 1 INTRODUCTION TO WXPYTHON .............................. 1 1 ■ Welcome to wxPython 3 2 ■ Giving your wxPython program a solid foundation 29 3 ■ Working in an event-driven environment 56 4 ■ Making wxPython easier to handle with PyCrust 83 5 ■ Creating your blueprint 116 6 ■ Working with the basic building blocks 146 PART 2 ESSENTIAL WXPYTHON ....................................... 183 7 ■ Working with the basic controls 185 8 ■ Putting widgets in frames 224 9 ■ Giving users choices with dialogs 258 10 ■ Creating and using wxPython menus 293 11 ■ Placing widgets with sizers 323 12 ■ Manipulating basic graphical images 356 brief contents viii BRIEF CONTENTS PART 3 ADVANCED WXPYTHON ....................................... 391 13 ■ Building list controls and managing items 393 14 ■ Coordinating the grid control 425 15 ■ Climbing the tree control 460 16 ■ Incorporating HTML into your application 485 17 ■ The wxPython printing framework 504 18 ■ Using other wxPython functionality 521 ix preface xix acknowledgments xxii about this book xxiv PART 1 INTRODUCTION TO WXPYTHON................................... 1 1 Welcome to wxPython 3 1.1 Getting started with wxPython 5 1.2 Creating the bare-minimum wxPython program 7 Importing wxPython 9 ■ Working with applications and frames 11 1.3 Extending the bare-minimum wxPython program 12 1.4 Creating the final hello.py program 15 1.5 What can wxPython do? 17 1.6 Why choose wxPython? 19 Python programmers 19 ■ wxWidget users 20 ■ New users 20 contents x CONTENTS 1.7 How wxPython works 21 The Python language 21 ■ The wxWidgets toolkit 22 Putting it together: the wxPython toolkit 25 1.8 Summary 27 2 Giving your wxPython program a solid foundation 29 2.1 What do I need to know about the required objects? 30 2.2 How do I create and use an application object? 31 Creating a wx.App subclass 31 ■ Understanding the application object lifecycle 34 2.3 How do I direct output from a wxPython program? 35 Redirecting output 35 ■ Modifying the default redirect behavior 37 2.4 How do I shut down my wxPython application? 38 Managing a normal shutdown 38 ■ Managing an emergency shutdown 39 2.5 How do I create and use the top-level window object? 39 Working with wx.Frame 40 ■ Working with wxPython IDs 42 Working with wx.Size and wx.Point 43 ■ Working with wx.Frame styles 44 2.6 How do I add objects and subwindows to a frame? 47 Adding widgets to a frame 47 ■ Adding a menubar, toolbar, or status bar to a frame 49 2.7 How can I use common dialogs? 51 2.8 What are some common errors with application objects and frames? 53 2.9 Summary 54 3 Working in an event-driven environment 56 3.1 What terminology do I need to understand events? 57 3.2 What is event-driven programming? 58 Coding event handlers 60 ■ Designing for event-driven programs 61 ■ Event triggers 62 3.3 How do I bind an event to a handler? 63 Working with the wx.EvtHandler methods 65 CONTENTS xi 3.4 How are events processed by wxPython? 68 Understanding the event handling process 69 ■ Using the Skip() method 75 3.5 What other event properties are contained in the application object? 77 3.6 How can I create my own events? 77 Defining a custom event for a custom widget 78 3.7 Summary 81 4 Making wxPython easier to handle with PyCrust 83 4.1 How do I interact with a wxPython program? 84 4.2 What are the useful features of PyCrust? 86 Autocompletion 87 ■ Calltips and parameter defaults 88 Syntax highlighting 89 ■ Python help 90 ■ Command recall 91 ■ Cut and paste 92 ■ Standard shell environment 93 ■ Dynamic updating 94 4.3 What do the PyCrust notebook tabs do? 95 Namespace tab 95 ■ Display tab 97 ■ Calltip tab 97 Session tab 98 ■ Dispatcher tab 98 4.4 How can I wrap PyCrust around my wxPython application? 99 4.5 What else is in the Py package? 104 Working with the GUI programs 104 ■ Working with the support modules 105 4.6 How can I use modules from the Py package in my wxPython programs? 112 4.7 Summary 115 5 Creating your blueprint 116 5.1 How can refactoring help me improve my code? 117 A refactoring example 118 ■ Starting to refactor 121 More refactoring 122 5.2 How do I keep the Model and View separate in my program? 126 What is a Model-View-Controller system? 126 ■ A wxPython model: PyGridTableBase 128 ■ A custom model 136 xii CONTENTS 5.3 How do you unit-test a GUI program? 140 The unittest module 140 ■ A unittest sample 141 Testing user events 143 5.4 Summary 145 6 Working with the basic building blocks 146 6.1 Drawing to the screen 148 How do I draw on the screen? 148 6.2 Adding window decorations 155 How do I add and update a status bar? 155 ■ How do I include a submenu or checked menu? 158 ■ How do I include a toolbar? 161 6.3 Getting standard information 165 How do I use standard file dialogs? 165 ■ How do I use a standard color picker? 169 6.4 Making the application look nice 170 How do I lay out widgets? 170 ■ How do I build an about box? 178 ■ How do I build a splash screen? 180 6.5 Summary 181 PART 2 ESSENTIAL WXPYTHON.............................................183 7 Working with the basic controls 185 7.1 Displaying text 186 How do I display static text? 186 ■ How can I get the user to enter text? 189 ■ How do I change the text without user input? 192 ■ How do I create a multi-line or styled text control? 193 ■ How do I create a font? 196 ■ Can I have styled text if my platform doesn’t support rich text? 197 ■ What if my text control doesn’t match my string? 198 ■ How do I respond to text events? 199 7.2 Working with buttons 199 How do I make a button? 200 ■ How do I make a button with a bitmap? 201 ■ How do I create a toggle button? 202 What’s a generic button, and why should I use one? 203 CONTENTS xiii 7.3 Entering and displaying numbers 205 How do I make a slider? 205 ■ How can I get those neat up/down arrow buttons? 208 ■ How can I make a progress bar? 210 7.4 Giving the user choices 211 How do I create a checkbox? 211 ■ How can I create a group of radio buttons? 212 ■ How can I create a list box? 216 ■ Can I combine a checkbox and a list box? 219 ■ What if I want a pull-down choice? 220 ■ Can I combine text entry and a list? 221 7.5 Summary 222 8 Putting widgets in frames 224 8.1 The life of a frame 225 How do I create a frame? 225 ■ What are some different frame styles? 227 ■ How do I create a frame with extra style information? 230 ■ What happens when I close a frame? 232 8.2 Using frames 234 What are the methods and properties of wx.Frame? 234 How do I find a subwidget of a frame? 237 ■ How do I create a frame with a scrollbar? 238 8.3 Alternative frame types 242 How do I create an MDI frame? 242 ■ What’s a mini-frame and why would I use it? 244 ■ How do I make a non-rectangular frame? 245 ■ How can I drag a frame without a title bar? 248 8.4 Using splitter windows 250 Creating a splitter window 250 ■ A splitter example 251 Changing the appearance of the splitter 253 ■ Manipulating the splitter programmatically 254 ■ Responding to splitter events 255 8.5 Summary 256 9 Giving users choices with dialogs 258 9.1 Working with modal dialogs 259 How do I create a modal dialog? 259 ■ How do I create an alert box? 261 ■ How do I get short text from the user? 264 xiv CONTENTS How can I display a list of choices in a dialog? 266 ■ How can I display progress? 267 9.2 Using standard dialogs 269 How can I use a file picker? 269 ■ How can I use a font picker? 273 ■ How can I use a color picker? 275 Can I allow the user to browse images? 277 9.3 Creating a wizard 278 9.4 Showing startup tips 281 9.5 Using validators to manage data in a dialog 282 How do I use a validator to ensure correct data? 282 ■ How do I use a validator to transfer data? 286 ■ How do I validate data as it is entered? 288 9.6 Summary 291 10 Creating and using wxPython menus 293 10.1 Creating Menus 294 How do I create a menu bar and attach it to a frame? 295 How do I create a menu and attach it to the menu bar? 295 How do I add items to a pull-down menu? 297 ■ How do I respond to a menu event? 301 10.2 Working with menu items 303 How do I find a specific menu item in a menu? 303 ■ How do I enable or disable a menu item? 306 ■ How do I associate a menu item with a keyboard shortcut? 307 ■ How do I create a toggle menu item with a checkbox or radio button? 311 10.3 Sprucing up your menus 313 How do I create a submenu? 313 ■ How do I create a pop-up menu? 315 ■ How can I create fancier menus? 317 10.4 Usability guidelines for menus 319 Keeping menus uniform in length 319 ■ Creating logical item groups 319 10.5 Summary 321 11 Placing widgets with sizers 323 11.1 What’s a sizer? 324 11.2 Basic sizers with the grid sizer 326 What is a grid sizer? 327 ■ How do you add or remove children from a sizer? 329 ■ How do sizers manage the size and CONTENTS xv alignment of their children? 331 ■ Can I specify a minimum size for my sizer or its children? 334 ■ How do sizers manage the border around each child? 336 11.3 Using the other sizer types 337 What’s a flex grid sizer? 337 ■ What’s a grid bag sizer? 341 What’s a box sizer? 345 ■ What’s a static box sizer? 349 11.4 Can I see a real-world example of sizers in action? 350 11.5 Summary 354 12 Manipulating basic graphical images 356 12.1 Working with images 357 How do I load images? 357 ■ What can I do with an image? 361 ■ How can I change cursors? 364 12.2 Dealing with device contexts 367 What is a device context, and how can I create one? 367 How do I draw to a device context? 371 ■ How do I draw images to the context? 376 ■ How can I draw text to the context? 379 12.3 Graphics manipulation 381 How do I manage the foreground drawing pen? 381 How do I manage the background drawing brush? 384 How can I manage logical and physical device coordinates? 385 What color names are predefined? 387 12.4 Summary 388 PART 3 ADVANCED WXPYTHON ............................................ 391 13 Building list controls and managing items 393 13.1 Building a list control 394 What is icon mode? 394 ■ What is small icon mode? 395 What is list mode? 396 ■ What is report mode? 397 How do I create a list control? 398 13.2 Managing items in a list 400 What is an image list and how do I add images to it? 400 How can I add and delete items from a list? 402 13.3 Responding to users 405 How can I respond to a user selection in a list? 405 ■ How can I respond to a user selection in a column header? 407 xvi CONTENTS 13.4 Editing and sorting list controls 411 How can I edit a label? 411 ■ How can I sort my list? 413 How can I learn more about list controls? 416 13.5 Creating a virtual list control 420 13.6 Summary 423 14 Coordinating the grid control 425 14.1 Creating your grid 426 How do I create a simple grid? 426 ■ How do I create a grid with a grid table? 429 14.2 Working with your grid 432 How do I add and delete rows, columns, and cells? 432 How do I manage the row and column headers of a grid? 433 How can I manage the size of grid elements? 436 How can I manage which cells are selected or visible? 440 How do I change the color or font of a grid cell? 442 14.3 Custom renderers and editors 445 How do I use a custom cell renderer? 445 ■ How do I edit a cell? 449 ■ How do I use a custom cell editor? 450 14.4 Capturing user events 455 How can I capture user mouse selections? 455 ■ How can I capture user keyboard navigation? 457 14.5 Summary 458 15 Climbing the tree control 460 15.1 Creating tree controls and adding items 461 How do I add a root? 463 ■ How do I add more items to the tree? 463 ■ How do I manage items? 464 15.2 What styles control the display of the tree control? 465 15.3 Sorting elements of a tree control 467 15.4 Controlling the image for each item 468 15.5 Navigating the tree programmatically 471 15.6 Managing the tree selection 472 15.7 Controlling which items are visible 473 15.8 Making a tree control user editable 477 CONTENTS xvii 15.9 Responding to other user events from a tree control 478 15.10 Using a tree list control 480 15.11 Summary 482 16 Incorporating HTML into your application 485 16.1 Displaying HTML 486 How can I display HTML in a wxPython window? 486 How can I display HTML from a file or URL? 488 16.2 Manipulating the HTML window 490 How can I respond to a user click on an active link? 490 How can I change an HTML window programmatically? 491 How can I display the page title in a frame’s title bar? 493 How can I print an HTML page? 495 16.3 Extending the HTML window 496 How does the HTML parser work? 496 ■ How can I add support for new tags? 498 ■ How can I support other file formats? 501 ■ How can I get a more fully featured HTML Widget? 502 16.4 Summary 503 17 The wxPython printing framework 504 17.1 How do I print in wxPython? 505 Understanding the printout lifecycle 506 ■ Print framework in action 507 ■ Working with wx.Printout methods 511 17.2 How do I display the print dialog? 512 Creating a print dialog 512 17.3 How do I display the page setup dialog? 515 Creating a page setup dialog 515 ■ Working with page setup properties 516 17.4 How do I print something? 518 17.5 How can I perform a print preview? 519 17.6 Summary 520 18 Using other wxPython functionality 521 18.1 Putting objects on the clipboard 522 Getting data in the clipboard 522 ■ Manipulating data in the clipboard 523 ■ Retrieving text data from the xviii CONTENTS clipboard 524 ■ The clipboard in action 524 ■ Passing other data formats 526 18.2 Being the source of a drag and drop 527 Dragging in action 529 18.3 Being the target of a drag and drop 530 Using your drop target 531 ■ Dropping in action 533 18.4 Transferring custom objects 534 Transferring a custom data object 534 ■ Retrieving a custom object 535 ■ Transferring an object in multiple formats 535 18.5 Setting timed events using wx.Timer 536 Generating EVT_TIMER events 536 ■ Learning other timer uses 539 18.6 Creating a multithreaded wxPython application 539 Working with the global function wx.CallAfter() 540 Managing thread communication with the queue object 543 Developing your own solution 543 18.7 Summary 544 index 545 xix

2011-01-26

TreeControl 控件三态 实例源码

TreeControl 控件三态 实例源码

2010-11-02

VC++多线程编程实例讲解

VC++多线程编程实例讲解

2010-11-02

新编Windows API参考大全

word 文档 作为Microsoft 32位平台的应用程序编程接口,Win32 API是从事Windows应用程序开发所必备的。本书首先对Win32 API函数做完整的概述;然后收录五大类函数:窗口管理、图形设备接口、系统服务、国际特性以及网络服务;在附录部分,讲解如何在Visual Basic和Delphi中对其调用。 本书是从事Windows应用程序开发的软件工程师的必备参考手册。

2010-01-06

Visual C++MFC编程实例

PDF 文件 第一部分基础知识 第2章类 第3章消息处理 第4章绘图 第二部分用户界面实例 第6章菜单 第7章工具栏和状态栏 第8章视图 第9章对话框和对话条 第10章控件窗口 第11章绘图 第三部分内部处理实例 第13章文件、串行化和数据库 第14章杂类 第四部分打包实例 第五部分附录 附录B 消息、控件通知和消息映像宏 附录C 访问其他应用程序类 附录D 开发中注意事项 附录E MFC快速参考指南

2010-01-06

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除