diff options
Diffstat (limited to 'activity.py')
-rw-r--r-- | activity.py | 76 |
1 files changed, 41 insertions, 35 deletions
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 <http://www.gnu.org/licenses/>. 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")) |