diff options
Diffstat (limited to 'physics.py')
-rw-r--r-- | physics.py | 34 |
1 files changed, 29 insertions, 5 deletions
@@ -25,6 +25,9 @@ Code: git://git.sugarlabs.org/physics/mainline.git """ +import logging +logger = logging.getLogger('physics') + import sys import math import pygame @@ -40,7 +43,9 @@ import Box2D as box2d import elements import tools from helpers import * -import gtk +from gi.repository import Gtk +from gi.repository import Gdk + class PhysicsGame: def __init__(self, activity): @@ -73,6 +78,7 @@ class PhysicsGame: self.opening_queue = path def run(self): + logger.debug('Run') self.screen = pygame.display.get_surface() pygame.display.init() self.world = elements.Elements(self.screen.get_size()) @@ -91,12 +97,25 @@ class PhysicsGame: self.switch_on_fake_pygame_cursor_cb) self.canvas.connect("leave_notify_event", self.switch_off_fake_pygame_cursor_cb) - self.canvas.add_events(gtk.gdk.ENTER_NOTIFY_MASK - | gtk.gdk.LEAVE_NOTIFY_MASK) + self.canvas.add_events(Gdk.EventMask.ENTER_NOTIFY_MASK + | Gdk.EventMask.LEAVE_NOTIFY_MASK) while True: - while gtk.events_pending(): - gtk.main_iteration() + logger.debug('Loop') + + #FIXME: I crash :P + while True: + logger.debug('Need to iterate in GTK!') + pending = Gtk.events_pending() + logger.debug('Pending, I can crash...') + if pending: + Gtk.main_iteration() + logger.debug('Main iteration, I wont crash now') + else: + logger.debug('No more iteration') + break + + logger.debug('GTK OK') if self.opening_queue: self.world.json_load(self.opening_queue) @@ -107,6 +126,8 @@ class PhysicsGame: if event.button == 1: self.show_fake_cursor = True + logger.debug('Events detected') + if self.in_focus: # Drive motors if self.world.run_physics: @@ -136,8 +157,11 @@ class PhysicsGame: # Flip Display pygame.display.flip() + logger.debug('No focus') + # Stay < 30 FPS to help keep the rest of the platform responsive self.clock.tick(30) # Originally 50 + logger.debug('Running again') def setTool(self, tool): self.currentTool.cancel() |