Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7093645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:27:55+00:00 2026-05-28T08:27:55+00:00

Intro I am new to GTK+ programming and am having difficulty understanding why the

  • 0

Intro

I am new to GTK+ programming and am having difficulty understanding why the following does not block.

if self.journal:
    # Pump GTK messages.
    while gtk.events_pending(): gtk.main_iteration()

According to the PyGtk reference on gtk.main_iteration(), the default value for block is True, which should, seemingly, prevent the local code from running until events have been processed.

Yet, I don’t see this happening. Perhaps, a clue is in the # Pump GTK messages. comment. But I don’t understand what the comment is trying to convey to me.

My Question

So, my question is What does it mean to “Pump GTK messages?” Please be as low-level as possible. I understand that GTK is my widget toolkit and is designed to handle events.

Background

I am following a Sugar tutorial at flossmanuals using the SimCom activity. This is the section of code (to provide context) from which the snippet above is pulled.

#!/usr/bin/python
# SimCom.py
"""
    Copyright (C) 2011  Peter Hewitt

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

"""
import g,pygame,utils,sys,buttons,slider,load_save
try:
    import gtk
except:
    pass
import sim

class SimCom:

    def __init__(self):
        self.journal=True # set to False if we come in via main()
        self.canvas=None # set to the pygame canvas if we come in via activity.py
.
.
.

    def run(self):
        g.init()
        if not self.journal: utils.load()
        self.sim=sim.Sim()
        load_save.retrieve()
        self.buttons_setup()
        if g.saved_n==0: buttons.off('cyan')
        self.slider=slider.Slider(g.sx(23.4),g.sy(20.2),5,utils.GREEN)
        if self.canvas<>None: self.canvas.grab_focus()
        ctrl=False
        pygame.key.set_repeat(600,120); key_ms=pygame.time.get_ticks()
        going=True
        while going:
            if self.journal:
                # Pump GTK messages.
                while gtk.events_pending(): gtk.main_iteration()

            # Pump PyGame messages.
            for event in pygame.event.get():
                if event.type==pygame.QUIT:
                    if not self.journal: utils.save()
                    going=False
                elif event.type == pygame.MOUSEMOTION:
                    g.pos=event.pos
                    g.redraw=True
                    if self.canvas<>None: self.canvas.grab_focus()
                elif event.type == pygame.MOUSEBUTTONDOWN:
                    g.redraw=True
                    if g.help_on: g.help_on=False 
                    elif event.button==1:
                        if self.do_click():
                            pass
                        elif self.slider.mouse():
                            pass # level changed
                        else:
                            bu=buttons.check()
                            if bu!='': self.do_button(bu); self.flush_queue()
                    elif event.button==3:
                        self.right_click()
                elif event.type == pygame.KEYDOWN:
                    # throttle keyboard repeat
                    if pygame.time.get_ticks()-key_ms>110:
                        key_ms=pygame.time.get_ticks()
                        if ctrl:
                            if event.key==pygame.K_q:
                                if not self.journal: utils.save()
                                going=False; break
                            else:
                                ctrl=False
                        if event.key in (pygame.K_LCTRL,pygame.K_RCTRL):
                            ctrl=True; break
                        self.do_key(event.key); g.redraw=True
                        self.flush_queue()
                elif event.type == pygame.KEYUP:
                    ctrl=False
            if not going: break
            self.update()
            if g.redraw:
                self.display()
                if g.version_display: utils.version_display()
                g.screen.blit(g.pointer,g.pos)
                pygame.display.flip()
                g.redraw=False
            g.clock.tick(40)

if __name__=="__main__":
    pygame.init()
    pygame.display.set_mode()
    game=SimCom()
    game.journal=False
    game.run()
    pygame.display.quit()
    pygame.quit()
    sys.exit(0)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T08:27:55+00:00Added an answer on May 28, 2026 at 8:27 am

    According to the PyGtk reference on gtk.main_iteration(), the default value for block is True,
    which should, seemingly, prevent the local code from running until events have been processed.

    Right, But the code:

    while gtk.events_pending(): gtk.main_iteration()
    

    first checks if there are any events, and only runs gtk.main_iteration() if there are. So there’s always at least one event to process, which means it will never block.

    gtk.main_iteration() does one iteration of the gtk main loop, which will process and handle the pending events (mouse events, screen redraw requests, key input, audio input/output, whatever gtk needs to do to drive the UI and handle requests from the operating system/graphics interface(The X11 server in case of *nix)). Often such events results in dispatching callbacks that you, or a library like pygame, have registred.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Almost every new website seems to have an intro video that tells prospective new
So I'm new to rails and am actually following a video tutorial from Lynda.com
In the following code block, I create a pointer to a struct so I
http://developer.apple.com/library/ios/#samplecode/Touches/Introduction/Intro.html I'm new to IOS development, and have been playing around with the IOS
I'm quite new to vim. I'm trying tuning vim up by following a book
I have a configuration file (feedbar.cfg), having the following content: [last_session] last_position_x=10 last_position_y=10 After
Working on joining up two legacy DB systems into new database where I can
Im new into that asp.net thing, but here goes. I got at ImageButton, and
Currently looking into learn new technology and silverlight is on the potential list. However,
I have loaded image into a new, initialized Oracle ORDImage object and am processing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.