From 8c849b54fd06592b7a581fc086fc6fff0f70b8b7 Mon Sep 17 00:00:00 2001 From: Ignacio Rodriguez Date: Fri, 13 Dec 2013 00:52:11 +0000 Subject: Gtk3 port --- diff --git a/activity.py b/activity.py index 79e32bd..95c6544 100644 --- a/activity.py +++ b/activity.py @@ -5,6 +5,7 @@ # Copyright (C) 2012-13 Walter Bender # Copyright (C) 2013 Sai Vineet # Copyright (C) 2012-13 Sugar Labs +# Copyright (C) 2013 Ignacio Rodriguez # 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 @@ -20,7 +21,6 @@ # along with this program. If not, see . import os -import gtk import csv import tempfile import json @@ -32,16 +32,20 @@ import pygame import sugargame import sugargame.canvas -from sugar.activity import activity -from sugar.activity.widgets import ActivityToolbarButton -from sugar.activity.widgets import StopButton -from sugar.graphics.radiotoolbutton import RadioToolButton -from sugar.graphics.toolbutton import ToolButton -from sugar.graphics.alert import ConfirmationAlert -from sugar.graphics.toolbarbox import ToolbarBox -from sugar.graphics.toolbarbox import ToolbarButton -from sugar.graphics.style import GRID_CELL_SIZE -from sugar.datastore import datastore +from gi.repository import Gtk +from gi.repository import Gdk +from gi.repository import GdkPixbuf + +from sugar3.activity import activity +from sugar3.activity.widgets import ActivityToolbarButton +from sugar3.activity.widgets import StopButton +from sugar3.graphics.radiotoolbutton import RadioToolButton +from sugar3.graphics.toolbutton import ToolButton +from sugar3.graphics.alert import ConfirmationAlert +from sugar3.graphics.toolbarbox import ToolbarBox +from sugar3.graphics.toolbarbox import ToolbarButton +from sugar3.graphics.style import GRID_CELL_SIZE +from sugar3.datastore import datastore import tools import physics @@ -51,8 +55,8 @@ class PhysicsActivity(activity.Activity): def __init__(self, handle): super(PhysicsActivity, self).__init__(handle) self.metadata['mime_type'] = 'application/x-physics-activity' - self.add_events(gtk.gdk.ALL_EVENTS_MASK | - gtk.gdk.VISIBILITY_NOTIFY_MASK) + self.add_events(Gdk.EventMask.ALL_EVENTS_MASK | + Gdk.EventMask.VISIBILITY_NOTIFY_MASK) self.connect('visibility-notify-event', self._focus_event) self.connect('window-state-event', self._window_event) @@ -63,8 +67,8 @@ class PhysicsActivity(activity.Activity): self.build_toolbar() self.set_canvas(self._canvas) - gtk.gdk.screen_get_default().connect('size-changed', - self.__configure_cb) + Gdk.Screen.get_default().connect('size-changed', + self.__configure_cb) logging.debug(os.path.join( activity.get_activity_root(), 'data', 'data')) @@ -74,8 +78,8 @@ class PhysicsActivity(activity.Activity): ''' Screen size has changed ''' self.write_file(os.path.join( activity.get_activity_root(), 'data', 'data')) - pygame.display.set_mode((gtk.gdk.screen_width(), - gtk.gdk.screen_height() - 2 * GRID_CELL_SIZE), + pygame.display.set_mode((Gdk.Screen.width(), + Gdk.Screen.height() - 2 * GRID_CELL_SIZE), pygame.RESIZABLE) self.read_file(os.path.join( activity.get_activity_root(), 'data', 'data')) @@ -93,12 +97,12 @@ class PhysicsActivity(activity.Activity): return self.preview surface = pygame.display.get_surface() width, height = surface.get_width(), surface.get_height() - pixbuf = gtk.gdk.pixbuf_new_from_data(pygame.image.tostring(surface, - "RGB"), - gtk.gdk.COLORSPACE_RGB, 0, 8, + string_surface = pygame.image.tostring(surface, "RGB") + pixbuf = GdkPixbuf.Pixbuf.new_from_data(string_surface, + GdkPixbuf.Colorspace.RGB, 0, 8, width, height, 3 * width) - pixbuf = pixbuf.scale_simple(300, 225, gtk.gdk.INTERP_BILINEAR) + pixbuf = pixbuf.scale_simple(300, 225, GdkPixbuf.InterpType.BILINEAR) preview_data = [] @@ -118,7 +122,7 @@ class PhysicsActivity(activity.Activity): activity_button.show() create_toolbar = ToolbarButton() - create_toolbar.props.page = gtk.Toolbar() + create_toolbar.props.page = Gtk.Toolbar() create_toolbar.props.icon_name = 'magicpen' create_toolbar.props.label = _('Create') toolbar_box.toolbar.insert(create_toolbar, -1) @@ -126,13 +130,13 @@ class PhysicsActivity(activity.Activity): self._insert_stop_play_button(toolbar_box.toolbar) - separator = gtk.SeparatorToolItem() + separator = Gtk.SeparatorToolItem() toolbar_box.toolbar.insert(separator, -1) separator.show() self._insert_clear_all_button(toolbar_box.toolbar) - separator = gtk.SeparatorToolItem() + separator = Gtk.SeparatorToolItem() separator.props.draw = False separator.set_size_request(0, -1) separator.set_expand(True) @@ -143,7 +147,7 @@ class PhysicsActivity(activity.Activity): toolbar_box.toolbar.insert(stop, -1) stop.show() - separator = gtk.SeparatorToolItem() + separator = Gtk.SeparatorToolItem() activity_button.props.page.insert(separator, -1) separator.show() @@ -196,18 +200,20 @@ class PhysicsActivity(activity.Activity): # Make + add the component buttons self.radioList = {} - firstButton = None + radioButtons = [] + for c in tools.allTools: - button = RadioToolButton(named_icon=c.icon) - if firstButton: - button.set_group(firstButton) + if len(radioButtons) >= 1: + button = RadioToolButton(icon_name=c.icon, + group=radioButtons[0]) + radioButtons.append(button) else: - button.set_group(None) - firstButton = button + button = RadioToolButton(icon_name=c.icon) + radioButtons.append(button) if c.name == tools.EraseAllTool.name: # Add a separator - Erase all tool is a dangerous tool - separator = gtk.SeparatorToolItem() + separator = Gtk.SeparatorToolItem() _insert_item(create_toolbar, separator, -1) separator.show() @@ -233,7 +239,7 @@ class PhysicsActivity(activity.Activity): def clear_all_cb(self, button): def clear_all_alert_cb(alert, response_id): self.remove_alert(alert) - if response_id is gtk.RESPONSE_OK: + if response_id is Gtk.ResponseType.OK: pygame.event.post(pygame.event.Event(pygame.USEREVENT, action="clear_all")) @@ -254,7 +260,7 @@ class PhysicsActivity(activity.Activity): if not self.game.pygame_started: logging.debug('focus_event: pygame not yet initialized') return - if data.state == gtk.gdk.VISIBILITY_FULLY_OBSCURED: + if data.state == Gdk.VisibilityState.FULLY_OBSCURED: pygame.event.post(pygame.event.Event(pygame.USEREVENT, action="focus_out")) else: @@ -300,6 +306,6 @@ class PhysicsActivity(activity.Activity): def _window_event(self, window, event): """ Send focus out event to pygame when switching to a desktop view. """ - if event.changed_mask & gtk.gdk.WINDOW_STATE_ICONIFIED: + if event.changed_mask & Gdk.WindowState.ICONIFIED: pygame.event.post(pygame.event.Event(pygame.USEREVENT, action="focus_out")) diff --git a/physics.py b/physics.py index b0cad5e..e75ef84 100644 --- a/physics.py +++ b/physics.py @@ -2,6 +2,7 @@ """ Physics, a 2D Physics Playground for Kids Copyright (C) 2008 Alex Levenson and Brian Jordan + Copyright (C) 2013 Ignacio Rodriguez 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 @@ -28,7 +29,6 @@ Code: git://git.sugarlabs.org/physics/mainline.git import os import sys import math -import gtk import logging import pygame @@ -36,6 +36,9 @@ from pygame.locals import * from pygame.color import * import sugargame +from gi.repository import Gtk +from gi.repository import Gdk + sys.path.append("lib/") import pkg_resources # If your architecture is different, comment these lines and install @@ -105,8 +108,8 @@ 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) self.world = elements.Elements(self.screen.get_size()) self.world.renderer.set_surface(self.screen) @@ -118,8 +121,8 @@ class PhysicsGame: self.world.json_load(path) while self.loop: - while gtk.events_pending(): - gtk.main_iteration() + while Gtk.events_pending(): + Gtk.main_iteration() if not self.loop: pygame.quit() diff --git a/setup.py b/setup.py index 6ed89aa..d290fe6 100755 --- a/setup.py +++ b/setup.py @@ -1,4 +1,4 @@ #!/usr/bin/env python -from sugar.activity import bundlebuilder +from sugar3.activity import bundlebuilder bundlebuilder.start() diff --git a/tools.py b/tools.py index af515b8..b92ed1e 100644 --- a/tools.py +++ b/tools.py @@ -2,6 +2,7 @@ """ Physics, a 2D Physics Playground for Kids Copyright (C) 2008 Alex Levenson and Brian Jordan + Copyright (C) 2013 Ignacio Rodriguez 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 @@ -28,8 +29,8 @@ from pygame.locals import * from helpers import * from inspect import getmro from gettext import gettext as _ -from sugar.graphics.alert import ConfirmationAlert -import gtk +from sugar3.graphics.alert import ConfirmationAlert +from gi.repository import Gtk # Tools that can be superlcassed @@ -658,9 +659,9 @@ class EraseAllTool(Tool): def alert_info(self, alert, response_id, event): self.activity.remove_alert(alert) - if response_id is gtk.RESPONSE_OK: + if response_id is Gtk.ResponseType.OK: self.response_alert = True - elif response_id is gtk.RESPONSE_CANCEL: + elif response_id is Gtk.ResponseType.CANCEL: self.response_alert = False self.handleToolEvent(event, True) -- cgit v0.9.1