Pygtk 2.0 Tutorial

Total Page:16

File Type:pdf, Size:1020Kb

Pygtk 2.0 Tutorial PyGTK 2.0 Tutorial John Finlay PyGTK 2.0 Tutorial by John Finlay Published April 13, 2005 This tutorial describes the use of the Python PyGTK module. Table of Contents 1. Introduction ................................................................................. 1 1.1. Exploring PyGTK .................................................................... 2 2. Getting Started .............................................................................. 4 2.1. Hello World in PyGTK ................................................................ 6 2.2. Theory of Signals and Callbacks ....................................................... 8 2.3. Events ............................................................................. 10 2.4. Stepping Through Hello World ........................................................ 12 3. Moving On ................................................................................ 16 3.1. More on Signal Handlers ............................................................. 16 3.2. An Upgraded Hello World ............................................................ 16 4. Packing Widgets ........................................................................... 19 4.1. Theory of Packing Boxes ............................................................. 19 4.2. Details of Boxes ..................................................................... 19 4.3. Packing Demonstration Program ...................................................... 22 4.4. Packing Using Tables ................................................................ 27 4.5. Table Packing Example .............................................................. 29 5. Widget Overview ........................................................................... 32 5.1. Widget Hierarchy ................................................................... 32 5.2. Widgets Without Windows ........................................................... 35 6. The Button Widget ......................................................................... 36 6.1. Normal Buttons ..................................................................... 36 6.2. Toggle Buttons ...................................................................... 40 6.3. Check Buttons ...................................................................... 43 6.4. Radio Buttons ....................................................................... 45 7. Adjustments ............................................................................... 49 7.1. Creating an Adjustment .............................................................. 49 7.2. Using Adjustments the Easy Way ..................................................... 49 7.3. Adjustment Internals ................................................................. 50 8. Range Widgets ............................................................................. 52 8.1. Scrollbar Widgets ................................................................... 52 8.2. Scale Widgets ....................................................................... 52 8.2.1. Creating a Scale Widget ....................................................... 52 8.2.2. Methods and Signals (well, methods, at least) ................................... 53 8.3. Common Range Methods ............................................................ 53 8.3.1. Setting the Update Policy ..................................................... 53 8.3.2. Getting and Setting Adjustments ............................................... 54 8.4. Key and Mouse Bindings ............................................................. 54 8.5. Range Widget Example .............................................................. 55 9. Miscellaneous Widgets ...................................................................... 62 9.1. Labels .............................................................................. 62 9.2. Arrows ............................................................................. 66 9.3. The Tooltips Object .................................................................. 68 9.4. Progress Bars ....................................................................... 71 9.5. Dialogs ............................................................................. 76 9.6. Images ............................................................................. 76 9.6.1. Pixmaps ..................................................................... 80 9.7. Rulers .............................................................................. 87 9.8. Statusbars .......................................................................... 91 9.9. Text Entries ......................................................................... 93 9.10. Spin Buttons ....................................................................... 96 9.11. Combo Widget .................................................................... 103 9.12. Calendar ......................................................................... 105 iii PyGTK 2.0 Tutorial 9.13. Color Selection ................................................................... 113 9.14. File Selections .................................................................... 117 9.15. Font Selection Dialog .............................................................. 120 10. Container Widgets ........................................................................ 123 10.1. The EventBox .................................................................... 123 10.2. The Alignment widget ............................................................. 124 10.3. Fixed Container ................................................................... 125 10.4. Layout Container .................................................................. 127 10.5. Frames ........................................................................... 130 10.6. Aspect Frames .................................................................... 133 10.7. Paned Window Widgets ............................................................ 135 10.8. Viewports ........................................................................ 138 10.9. Scrolled Windows ................................................................. 139 10.10. Button Boxes .................................................................... 142 10.11. Toolbar ......................................................................... 146 10.12. Notebooks ...................................................................... 152 10.13. Plugs and Sockets ................................................................ 159 10.13.1. Plugs .................................................................... 159 10.13.2. Sockets .................................................................. 160 11. Menu Widget ............................................................................ 164 11.1. Manual Menu Creation ............................................................ 164 11.2. Manual Menu Example ............................................................ 167 11.3. Using ItemFactory ................................................................ 169 11.4. Item Factory Example ............................................................. 169 12. Drawing Area ............................................................................ 173 12.1. Graphics Context .................................................................. 174 12.2. Drawing Methods ................................................................. 178 13. TextView Widget ......................................................................... 187 13.1. TextView Overview ............................................................... 187 13.2. TextViews ........................................................................ 187 13.3. Text Buffers ...................................................................... 194 13.3.1. TextBuffer Status Information ............................................... 194 13.3.2. Creating TextIters .......................................................... 195 13.3.3. Text Insertion, Retrieval and Deletion ........................................ 196 13.3.4. TextMarks ................................................................. 197 13.3.5. Creating and Applying TextTags ............................................. 198 13.3.6. Inserting Images and Widgets ............................................... 199 13.4. Text Iters ......................................................................... 200 13.4.1. TextIter Attributes .......................................................... 201 13.4.2. Text Attributes at a TextIter ................................................. 201 13.4.3. Copying a TextIter ......................................................... 202 13.4.4. Retrieving Text and Objects ................................................. 202 13.4.5. Checking Conditions at a TextIter ............................................ 203 13.4.6. Checking Location in Text .................................................. 204 13.4.7. Moving Through Text ...................................................... 205 13.4.8. Moving to a Specific Location ............................................... 206 13.4.9. Searching in Text .......................................................... 206 13.5. Text Marks ....................................................................... 207 13.6. Text Tags and Tag Tables ........................................................... 208
Recommended publications
  • The Glib/GTK+ Development Platform
    The GLib/GTK+ Development Platform A Getting Started Guide Version 0.8 Sébastien Wilmet March 29, 2019 Contents 1 Introduction 3 1.1 License . 3 1.2 Financial Support . 3 1.3 Todo List for this Book and a Quick 2019 Update . 4 1.4 What is GLib and GTK+? . 4 1.5 The GNOME Desktop . 5 1.6 Prerequisites . 6 1.7 Why and When Using the C Language? . 7 1.7.1 Separate the Backend from the Frontend . 7 1.7.2 Other Aspects to Keep in Mind . 8 1.8 Learning Path . 9 1.9 The Development Environment . 10 1.10 Acknowledgments . 10 I GLib, the Core Library 11 2 GLib, the Core Library 12 2.1 Basics . 13 2.1.1 Type Definitions . 13 2.1.2 Frequently Used Macros . 13 2.1.3 Debugging Macros . 14 2.1.4 Memory . 16 2.1.5 String Handling . 18 2.2 Data Structures . 20 2.2.1 Lists . 20 2.2.2 Trees . 24 2.2.3 Hash Tables . 29 2.3 The Main Event Loop . 31 2.4 Other Features . 33 II Object-Oriented Programming in C 35 3 Semi-Object-Oriented Programming in C 37 3.1 Header Example . 37 3.1.1 Project Namespace . 37 3.1.2 Class Namespace . 39 3.1.3 Lowercase, Uppercase or CamelCase? . 39 3.1.4 Include Guard . 39 3.1.5 C++ Support . 39 1 3.1.6 #include . 39 3.1.7 Type Definition . 40 3.1.8 Object Constructor . 40 3.1.9 Object Destructor .
    [Show full text]
  • Free Pascal Runtime Library Reference Guide.Pdf
    Run-Time Library (RTL) : Reference guide. Free Pascal version 2.2.2: Reference guide for RTL units. Document version 2.1 June 2008 Michaël Van Canneyt Contents 0.1 Overview........................................ 93 1 Reference for unit ’BaseUnix’ 94 1.1 Used units........................................ 94 1.2 Overview........................................ 94 1.3 Constants, types and variables............................. 94 1.3.1 Constants.................................... 94 1.3.2 Types...................................... 116 1.4 Procedures and functions................................ 131 1.4.1 CreateShellArgV................................ 131 1.4.2 FpAccess.................................... 132 1.4.3 FpAlarm.................................... 132 1.4.4 FpChdir..................................... 133 1.4.5 FpChmod.................................... 133 1.4.6 FpChown.................................... 135 1.4.7 FpClose..................................... 136 1.4.8 FpClosedir................................... 136 1.4.9 FpDup..................................... 136 1.4.10 FpDup2..................................... 137 1.4.11 FpExecv.................................... 138 1.4.12 FpExecve.................................... 139 1.4.13 FpExit...................................... 140 1.4.14 FpFcntl..................................... 140 1.4.15 fpfdfillset.................................... 141 1.4.16 fpFD_CLR................................... 141 1.4.17 fpFD_ISSET.................................. 142 1.4.18 fpFD_SET..................................
    [Show full text]
  • Development Environment for the Raspberry Pi Using a Cross Compiling Toolchain and Eclipse | Hertaville 07.10.13 13:37
    Development Environment for the Raspberry Pi using a Cross Compiling Toolchain and Eclipse | Hertaville 07.10.13 13:37 Hertaville Welcome to Hertaville! Development Environment for the Raspberry Pi using a Cross Compiling Toolchain and Eclipse Posted on September 28, 2012 by halherta UPDATED July 15th 2013 In this blog entry the setup of a cross-compiling development environment for the Raspberry Pi will be demonstrated. This will include the Official Raspbian (armhf) cross compiling toolchain (available from github) Eclipse for C/C++ Developers (Linux) We will finally write a simple Hello World program on our development PC, compile it using the cross compiler and then deploy it onto our Raspberry Pi board to run it. I’m going to assume that you have already installed a Raspbian Wheezy image on your RPi board and that you have Linux installed on your desktop PC. For this tutorial I am using the Crunchbang 11 Linux OS (64-bit) on my PC. The instructions provided should work on most Debian/Ubuntu based Linux distributions running directly on a PC or as a a guest operating system via VMWare/ VirtualBox . A remote debugging tutorial; which I consider to be the continuation of this tutorial, can be found here. Finally, Derek Molloy has a great video tutorial on setting up a similar environment for the Beaglebone. Watching this video was incredibly informative and helped me set up this tutorial. So what is a cross compiling toolchain and why use one ? A native compiler such as the default gcc tool on the PC is a compiler that runs on an Intel machine, as well as creates binaries intended to be run on an Intel machine.
    [Show full text]
  • Drawing in GTK+
    CSci493.70 Graphical User Interface Programming Prof. Stewart Weiss Drawing in GTK+ Drawing in GTK+ Background In order to understand how to draw in GTK, you rst have to understand something about how GTK draws widgets, because how GTK draws widgets has an important role in how you design your drawing application. An understanding of how GTK draws widgets is also required if you ever plan to build your own custom widgets. Windows and Clipping Most windowing systems are designed around the idea that an application's visual display lies within a rectangular region on the screen called its window. The windowing system, e.g. Gnome or KDE or Explorer, does not automatically save the graphical content of an application's windows; instead it asks the application itself to repaint 1 its windows whenever it is needed. For example, if a window that is stacked below other windows gets raised to the top, then a client program has to repaint the area that was previously obscured. When the windowing system asks a client program to redraw part of a window, it sends an exposure event to the program that contains that window. An exposure event is simply an event sent from the underlying windowing system to a widget to notify it that it must redraw itself. In this context, a "window" means "a rectangular region with automatic clipping", not a top-level application window. Clipping is the act of removing portions of a window that do not need to be redrawn, or looked at the other way, it is determining which are the only regions of a window that must be redrawn.
    [Show full text]
  • Gtk Marries Ada: the GUI Technology Revolution
    GtkGtk MarriesMarries AdaAda:: TheThe GUIGUI TechnologyTechnology RevolutionRevolution [email protected] OverviewOverview History of GtkAda GtkAda Features Why Gtk Rather Than Other Toolkits? Why GtkAda rather than Gtk+? GtkAdaGtkAda -- HistoryHistory á The GIMP – GNU Photoshop clone á The Gtk+ library – Becomes independent á GtkGlade: a Gtk+ GUI builder á Gnome: a desktop manager á GVD: the GNU Visual Debugger GtkAdaGtkAda FeaturesFeatures ááHigh-level binding to the Gtk+ library – object-oriented – type safety – small and efficient ááHighly portable – Unixes: Linux, Solaris, … – Windows NT ááNative GtkAdaGtkAda FeaturesFeatures (2)(2) ááEvent handling ááDrawing services – Lines, rectangles, … – OpenGL (3D graphics) ááStyle support ááLarge set of widgets GtkAdaGtkAda -- WidgetWidget setset á Two types of widgets – containers and visual objects á About 100 widgets are provided á High-level widgets – notebook, text widget, tree, spin button, table, toolbar, ... GtkAdaGtkAda -- ScreenshotsScreenshots á Ctree GtkAdaGtkAda -- ScreenshotsScreenshots (2)(2) á OpenGL WhyWhy Gtk+?Gtk+? á Portable á Native á Extensible á Open Source á Actively developped á Thread-safe WhyWhy Gtk+?Gtk+? (2)(2) á High level widgets á Easy to use scrolling capabilities á Wide range of users á Very powerful layout capabilities – Complete set of containers á Powerful and easy to use GUI builder á Easy to bind TheThe GUIGUI BuilderBuilder ááMulti-language GUI builder – Language-independent save file (XML). – Code-generation specific to each language. – Dynamic loading
    [Show full text]
  • Programmer's Guide
    Free Pascal Programmer’s Guide Programmer’s Guide for Free Pascal, Version 3.0.0 Document version 3.0 November 2015 Michaël Van Canneyt Contents 1 Compiler directives 13 1.1 Introduction....................................... 13 1.2 Local directives..................................... 14 1.2.1 $A or $ALIGN : Align Data.......................... 14 1.2.2 $A1, $A2,$A4 and $A8 ............................ 14 1.2.3 $ASMMODE : Assembler mode (Intel 80x86 only)............... 15 1.2.4 $B or $BOOLEVAL : Complete boolean evaluation.............. 15 1.2.5 $C or $ASSERTIONS : Assertion support................... 15 1.2.6 $BITPACKING : Enable bitsize packing................... 16 1.2.7 $CALLING : Specify calling convention.................... 16 1.2.8 $CHECKPOINTER : Check pointer values................... 16 1.2.9 $CODEALIGN : Set the code alignment.................... 17 1.2.10 $COPERATORS : Allow C like operators................... 18 1.2.11 $DEFINE or $DEFINEC : Define a symbol.................. 18 1.2.12 $ELSE : Switch conditional compilation................... 18 1.2.13 $ELSEC : Switch conditional compilation................... 19 1.2.14 $ELSEIF or $ELIFC : Switch conditional compilation........... 19 1.2.15 $ENDC : End conditional compilation..................... 19 1.2.16 $ENDIF : End conditional compilation.................... 19 1.2.17 $ERROR or $ERRORC : Generate error message............... 20 1.2.18 $ENDREGION: End of a collapsible region.................. 20 1.2.19 $EXTENDEDSYM: Ignored........................... 20 1.2.20 $EXTERNALSYM: Ignored........................... 20 1.2.21 $F : Far or near functions........................... 20 1.2.22 $FATAL : Generate fatal error message.................... 21 1.2.23 $FPUTYPE : Select coprocessor type..................... 21 1.2.24 $GOTO : Support Goto and Label ...................... 22 1.2.25 $H or $LONGSTRINGS : Use AnsiStrings.................. 22 1.2.26 $HINT : Generate hint message.......................
    [Show full text]
  • FCL Reference Guide
    Free Component Library (FCL): Reference guide. Reference guide for FCL units. Document version 3.2.2 May 2021 Michaël Van Canneyt Contents 0.1 Overview........................................ 88 1 Reference for unit ’ascii85’ 89 1.1 Used units........................................ 89 1.2 Overview........................................ 89 1.3 Constants, types and variables............................. 89 1.3.1 Types...................................... 89 1.4 TASCII85DecoderStream................................ 90 1.4.1 Description................................... 90 1.4.2 Method overview................................ 90 1.4.3 Property overview............................... 90 1.4.4 TASCII85DecoderStream.Create........................ 90 1.4.5 TASCII85DecoderStream.Decode....................... 91 1.4.6 TASCII85DecoderStream.Close........................ 91 1.4.7 TASCII85DecoderStream.ClosedP....................... 91 1.4.8 TASCII85DecoderStream.Destroy....................... 91 1.4.9 TASCII85DecoderStream.Read........................ 92 1.4.10 TASCII85DecoderStream.Seek........................ 92 1.4.11 TASCII85DecoderStream.BExpectBoundary................. 92 1.5 TASCII85EncoderStream................................ 92 1.5.1 Description................................... 92 1.5.2 Method overview................................ 93 1.5.3 Property overview............................... 93 1.5.4 TASCII85EncoderStream.Create........................ 93 1.5.5 TASCII85EncoderStream.Destroy....................... 93 1.5.6 TASCII85EncoderStream.Write.......................
    [Show full text]
  • Clutter Version 1.10.0, Updated 9 May 2012
    Guile-GNOME: Clutter version 1.10.0, updated 9 May 2012 Matthew Allum and OpenedHand LTD Intel Corporation This manual is for (gnome clutter) (version 1.10.0, updated 9 May 2012) Copyright 2006,2007,2008 OpenedHand LTD Copyright 2009,2010,2011,2012 Intel Corporation Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. You may obtain a copy of the GNU Free Documentation License from the Free Software Foundation by visiting their Web site or by writing to: The Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA i Short Contents 1 Overview :::::::::::::::::::::::::::::::::::::::::::: 1 2 ClutterAction :::::::::::::::::::::::::::::::::::::::: 2 3 ClutterActorMeta ::::::::::::::::::::::::::::::::::::: 3 4 ClutterActor ::::::::::::::::::::::::::::::::::::::::: 5 5 ClutterAlignConstraint:::::::::::::::::::::::::::::::: 63 6 ClutterAlpha :::::::::::::::::::::::::::::::::::::::: 65 7 ClutterAnimatable ::::::::::::::::::::::::::::::::::: 68 8 Implicit Animations :::::::::::::::::::::::::::::::::: 69 9 ClutterAnimator ::::::::::::::::::::::::::::::::::::: 76 10 ClutterBackend :::::::::::::::::::::::::::::::::::::: 82 11 ClutterBinLayout :::::::::::::::::::::::::::::::::::: 84 12 ClutterBindConstraint :::::::::::::::::::::::::::::::: 87 13 Key Bindings:::::::::::::::::::::::::::::::::::::::: 90
    [Show full text]
  • 4.6.X Branch That Affect Python 2 Users
    pytest Documentation Release 4.6 holger krekel, trainer and consultant, http://merlinux.eu Nov 25, 2020 Contents 1 Installation and Getting Started3 1.1 Install pytest ..............................................3 1.2 Create your first test...........................................3 1.3 Run multiple tests............................................4 1.4 Assert that a certain exception is raised.................................4 1.5 Group multiple tests in a class......................................5 1.6 Request a unique temporary directory for functional tests........................5 1.7 Continue reading.............................................6 2 Usage and Invocations 7 2.1 Calling pytest through python -m pytest .............................7 2.2 Possible exit codes............................................7 2.3 Getting help on version, option names, environment variables.....................7 2.4 Stopping after the first (or N) failures..................................8 2.5 Specifying tests / selecting tests.....................................8 2.6 Modifying Python traceback printing..................................9 2.7 Detailed summary report.........................................9 2.8 Dropping to PDB (Python Debugger) on failures............................ 12 2.9 Dropping to PDB (Python Debugger) at the start of a test........................ 12 2.10 Setting breakpoints............................................ 12 2.11 Using the builtin breakpoint function.................................. 13 2.12 Profiling test
    [Show full text]
  • Pygtk GUI Programming Pygtk GUI Programming Table of Contents Pygtk GUI Programming
    PyGTK GUI programming PyGTK GUI programming Table of Contents PyGTK GUI programming...............................................................................................................................1 Chapter 1. Introduzione....................................................................................................................................2 1.1. Primo approccio...............................................................................................................................2 1.2. Il toolkit PyGTK..............................................................................................................................2 1.3. PyGTK e Glade................................................................................................................................2 1.4. IDE o editor......................................................................................................................................4 1.5. Installazione.....................................................................................................................................6 1.5.1. Installazione su piattaforma GNU/Linux...............................................................................6 1.5.2. Installazione su piattaforma Windows...................................................................................6 1.6. Supporto e help................................................................................................................................6 Chapter 2. I Widget, le classi ed un
    [Show full text]
  • Gnustep-Gui Improvements
    GNUstep-gui Improvements Author: Eric Wasylishen Presenter: Fred Kiefer Overview ● Introduction ● Recent Improvements ● Resolution Independence ● NSImage ● Text System ● Miscellaneous ● Work in Progress ● Open Projects 2012-02-04 GNUstep-gui Improvements 2 Introduction ● Cross-platform (X11, Windows) GUI toolkit, fills a role similar to gtk ● Uses cairo as the drawing backend ● License: LGPLv2+; bundled tools: GPLv3+ ● Code is copyright FSF (contributors must sign copyright agreement) ● Latest release: 0.20.0 (2011/04) ● New release coming out soon 2012-02-04 GNUstep-gui Improvements 3 Introduction: Nice Features ● Objective-C is a good compromise language ● Readable, Smalltalk-derived syntax ● Object-Oriented features easy to learn ● Superset of C ● OpenStep/Cocoa API, which GNUstep-gui follows, is generally well-designed 2012-02-04 GNUstep-gui Improvements 4 Recent Improvements: Resolution Independence ● Basic problem: pixel resolution of computer displays varies widely 2012-02-04 GNUstep-gui Improvements 5 Resolution Independence ● In GNUstep-gui we draw everything with Display PostScript commands and all graphics coordinates are floating-point, so it would seem to be easy to scale UI graphics up or down ● Drawing elements ● Geometry ● Images ● Text 2012-02-04 GNUstep-gui Improvements 6 Resolution Independence ● Challenges: ● Auto-sized/auto-positioned UI elements should be aligned on pixel boundaries ● Need a powerful image object which can select between multiple versions of an image depending on the destination resolution (luckily NSImage is capable) 2012-02-04 GNUstep-gui Improvements 7 Recent Improvements: NSImage ● An NSImage is a lightweight container which holds one or more image representations (NSImageRep) ● Some convenience code for choosing which representation to use, drawing it, caching..
    [Show full text]
  • Pygtk 2.0 Tutorial
    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 .
    [Show full text]