Pygtk 2.0 Tutorial
Total Page:16
File Type:pdf, Size:1020Kb
PyGTK 2.0 Tutorial John Finlay October 7, 2012 PyGTK 2.0 Tutorial by John Finlay Published March 2, 2006 ii Contents 1 Introduction 1 1.1 Exploring PyGTK . .2 2 Getting Started 5 2.1 Hello World in PyGTK . .7 2.2 Theory of Signals and Callbacks . .9 2.3 Events . 10 2.4 Stepping Through Hello World . 11 3 Moving On 15 3.1 More on Signal Handlers . 15 3.2 An Upgraded Hello World . 15 4 Packing Widgets 19 4.1 Theory of Packing Boxes . 19 4.2 Details of Boxes . 20 4.3 Packing Demonstration Program . 22 4.4 Packing Using Tables . 27 4.5 Table Packing Example . 28 5 Widget Overview 31 5.1 Widget Hierarchy . 31 5.2 Widgets Without Windows . 34 6 The Button Widget 35 6.1 Normal Buttons . 35 6.2 Toggle Buttons . 38 6.3 Check Buttons . 40 6.4 Radio Buttons . 42 7 Adjustments 45 7.1 Creating an Adjustment . 45 7.2 Using Adjustments the Easy Way . 45 7.3 Adjustment Internals . 46 8 Range Widgets 49 8.1 Scrollbar Widgets . 49 8.2 Scale Widgets . 49 8.2.1 Creating a Scale Widget . 49 8.2.2 Methods and Signals (well, methods, at least) . 50 8.3 Common Range Methods . 50 8.3.1 Setting the Update Policy . 50 8.3.2 Getting and Setting Adjustments . 51 8.4 Key and Mouse Bindings . 51 8.5 Range Widget Example . 51 9 Miscellaneous Widgets 57 9.1 Labels . 57 9.2 Arrows . 60 9.3 The Tooltips Object . 61 9.4 Progress Bars . 63 9.5 Dialogs . 67 9.5.1 Message Dialogs . 68 9.6 Images . 68 9.6.1 Pixmaps . 71 iii CONTENTS 9.7 Rulers . 77 9.8 Statusbars . 79 9.9 Text Entries . 81 9.10 Spin Buttons . 83 9.11 Combo Widget . 89 9.12 Calendar . 90 9.13 Color Selection . 96 9.14 File Selections . 100 9.15 Font Selection Dialog . 102 10 Container Widgets 105 10.1 The EventBox . 105 10.2 The Alignment widget . 106 10.3 Fixed Container . 107 10.4 Layout Container . 108 10.5 Frames . 111 10.6 Aspect Frames . 113 10.7 Paned Window Widgets . 115 10.8 Viewports . 118 10.9 Scrolled Windows . 118 10.10Button Boxes . 120 10.11Toolbar . 124 10.12Notebooks . 128 10.13Plugs and Sockets . 133 10.13.1 Plugs . 133 10.13.2 Sockets . 134 11 Menu Widget 137 11.1 Manual Menu Creation . 137 11.2 Manual Menu Example . 139 11.3 Using ItemFactory . 141 11.4 Item Factory Example . 141 12 Drawing Area 145 12.1 Graphics Context . 145 12.2 Drawing Methods . 149 13 TextView Widget 155 13.1 TextView Overview . 155 13.2 TextViews . 155 13.3 Text Buffers . 160 13.3.1 TextBuffer Status Information . 161 13.3.2 Creating TextIters . 161 13.3.3 Text Insertion, Retrieval and Deletion . 162 13.3.4 TextMarks . 163 13.3.5 Creating and Applying TextTags . 163 13.3.6 Inserting Images and Widgets . 164 13.4 Text Iters . 165 13.4.1 TextIter Attributes ..