[Sugar-devel] [PATCH Implode] Port to Gtk3 SL #3715
Manuel Kaufmann
humitos at gmail.com
Mon Aug 6 16:35:56 EDT 2012
This commit ports the Implode Activity to its Gtk3 version.
The sugarless.py version is not ported on this commit.
Signed-off-by: Manuel Kaufmann <humitos at gmail.com>
---
anim.py | 4 +-
gridwidget.py | 89 +++++++++++++--------------
helpwidget.py | 155 ++++++++++++++++++++++++-----------------------
implodeactivity.py | 174 ++++++++++++++++++++++++-----------------------------
implodegame.py | 8 +--
keymap.py | 82 ++++++++++++-------------
setup.py | 2 +-
7 files changed, 248 insertions(+), 266 deletions(-)
diff --git a/anim.py b/anim.py
index 2c19a15..f34406e 100644
--- a/anim.py
+++ b/anim.py
@@ -16,7 +16,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-import gobject
+from gi.repository import GObject
# Animation timer interval (in msec)
_TIMER_INTERVAL = 20
@@ -34,7 +34,7 @@ class Anim(object):
def start(self):
self._animating = True
self._update_func()
- gobject.timeout_add(_TIMER_INTERVAL, self._timer)
+ GObject.timeout_add(_TIMER_INTERVAL, self._timer)
def stop(self):
if self._animating:
diff --git a/gridwidget.py b/gridwidget.py
index 8ee3aad..c3b6596 100644
--- a/gridwidget.py
+++ b/gridwidget.py
@@ -20,8 +20,9 @@ import logging
_logger = logging.getLogger('implode-activity.gridwidget')
import cairo
-import gobject
-import gtk
+from gi.repository import GObject
+from gi.repository import Gtk
+from gi.repository import Gdk
import math
import random
import time
@@ -93,39 +94,38 @@ _ANIM_SCALE = 0.04
def _log_errors(func):
return func
-class GridWidget(gtk.DrawingArea):
+class GridWidget(Gtk.DrawingArea):
"""Gtk widget for rendering the game board."""
__gsignals__ = {
- 'piece-selected' : (gobject.SIGNAL_RUN_LAST, None, (int, int)),
- 'undo-key-pressed': (gobject.SIGNAL_RUN_LAST, None, (int,)),
- 'redo-key-pressed': (gobject.SIGNAL_RUN_LAST, None, (int,)),
- 'new-key-pressed' : (gobject.SIGNAL_RUN_LAST, None, (int,)),
- 'button-press-event': 'override',
- 'key-press-event': 'override',
- 'expose-event': 'override',
- 'size-allocate': 'override',
- 'motion-notify-event': 'override',
+ 'piece-selected': (GObject.SignalFlags.RUN_LAST, None, (int, int)),
+ 'undo-key-pressed': (GObject.SignalFlags.RUN_LAST, None, (int,)),
+ 'redo-key-pressed': (GObject.SignalFlags.RUN_LAST, None, (int,)),
+ 'new-key-pressed': (GObject.SignalFlags.RUN_LAST, None, (int,)),
}
def __init__(self, *args, **kwargs):
super(GridWidget, self).__init__(*args, **kwargs)
- self.set_events(gtk.gdk.BUTTON_PRESS_MASK
- | gtk.gdk.POINTER_MOTION_MASK
- | gtk.gdk.KEY_PRESS_MASK)
- self.set_flags(gtk.CAN_FOCUS)
+ self.set_events(Gdk.EventMask.BUTTON_PRESS_MASK
+ | Gdk.EventMask.POINTER_MOTION_MASK
+ | Gdk.EventMask.KEY_PRESS_MASK)
+ self.set_can_focus(True)
self._board_drawer = BoardDrawer(self._get_size, self._invalidate_rect)
self._win_drawer = WinDrawer(self._get_size, self._invalidate_rect)
self._removal_drawer = RemovalDrawer(self._get_size, self._invalidate_rect)
self._set_current_drawer(self._board_drawer)
+ self.connect('draw', self._draw_event_cb)
+ self.connect('configure-event', self._configure_event_cb)
+ self.connect('button-press-event', self._button_press_event_cb)
+
def _get_size(self):
- return (self.allocation.width, self.allocation.height)
+ return (self.get_allocated_width(), self.get_allocated_height())
def _invalidate_rect(self, rect):
- if self.window:
- self.window.invalidate_rect(rect, True)
+ if self.get_window():
+ self.get_window().invalidate_rect(rect, True)
def set_board(self, board):
self._board_drawer.set_board(board)
@@ -141,7 +141,9 @@ class GridWidget(gtk.DrawingArea):
def _invalidate_board(self):
(width, height) = self._get_size()
- self._invalidate_rect(gtk.gdk.Rectangle(0, 0, width, height))
+ rect = Gdk.Rectangle()
+ rect.x, rect.y, rect.width, rect.height = (0, 0, width, height)
+ self._invalidate_rect(rect)
def get_win_draw_flag(self):
return (self._current_drawer is self._win_drawer)
@@ -160,12 +162,12 @@ class GridWidget(gtk.DrawingArea):
self._board_drawer.select_center_cell()
@_log_errors
- def do_button_press_event(self, event):
+ def _button_press_event_cb(self, widget, event):
# Ignore mouse clicks while animating.
if self._is_animating():
return True
# Ignore double- and triple-clicks.
- if event.type != gtk.gdk.BUTTON_PRESS:
+ if event.type != Gdk.EventType.BUTTON_PRESS:
return True
self.grab_focus()
self._board_drawer.set_mouse_selection(event.x, event.y)
@@ -219,24 +221,16 @@ class GridWidget(gtk.DrawingArea):
else:
x = event.x
y = event.y
- state = event.state
+ state = event.get_state()
self._board_drawer.set_mouse_selection(x, y)
- @_log_errors
- def do_expose_event(self, event):
- cr = self.window.cairo_create()
- cr.rectangle(event.area.x,
- event.area.y,
- event.area.width,
- event.area.height)
- cr.clip()
- (width, height) = self.window.get_size()
- self._current_drawer.draw(cr, width, height)
+ def _draw_event_cb(self, widget, cr):
+ alloc = self.get_allocation()
+ self._current_drawer.draw(cr, alloc.width, alloc.height)
@_log_errors
- def do_size_allocate(self, allocation):
- super(GridWidget, self).do_size_allocate(self, allocation)
- self._current_drawer.resize(allocation.width, allocation.height)
+ def _configure_event_cb(self, widget, event):
+ self._current_drawer.resize(event.width, event.height)
def _set_current_drawer(self, drawer):
self._current_drawer = drawer
@@ -382,7 +376,8 @@ class BoardDrawer(object):
def _invalidate_board(self):
(width, height) = self._get_size_func()
- rect = gtk.gdk.Rectangle(0, 0, width, height)
+ rect = Gdk.Rectangle()
+ rect.x, rect.y, rect.width, rect.height = (0, 0, width, height)
self._invalidate_rect_func(rect)
def _invalidate_selection(self, selection_coord):
@@ -407,10 +402,10 @@ class BoardDrawer(object):
max_x2 = math.ceil( max(pt1[0], pt2[0])) + 1
min_y2 = math.floor(min(pt1[1], pt2[1])) - 1
max_y2 = math.ceil( max(pt1[1], pt2[1])) + 1
- rect = gtk.gdk.Rectangle(int(min_x2),
- int(min_y2),
- int(max_x2 - min_x2),
- int(max_y2 - min_y2))
+ rect = Gdk.Rectangle()
+ rect.x, rect.y, rect.width, rect.height = (
+ int(min_x2), int(min_y2),
+ int(max_x2 - min_x2), int(max_y2 - min_y2))
self._invalidate_rect_func(rect)
def _display_to_cell(self, x, y):
@@ -426,10 +421,8 @@ class BoardDrawer(object):
self._board_transform = _BoardTransform()
else:
self._board_transform = _BoardTransform()
- self._board_transform.setup(width,
- height,
- self._board_width,
- self._board_height)
+ self._board_transform.setup(width, height, self._board_width,
+ self._board_height)
def draw(self, cr, width, height):
# Draws the widget.
@@ -564,7 +557,8 @@ class RemovalDrawer(object):
def _invalidate_board(self):
(width, height) = self._get_size_func()
- rect = gtk.gdk.Rectangle(0, 0, width, height)
+ rect = Gdk.Rectangle()
+ rect.x, rect.y, rect.width, rect.height = (0, 0, width, height)
self._invalidate_rect_func(rect)
def _recalc_game_anim_frames(self):
@@ -810,7 +804,8 @@ class WinDrawer(object):
def _invalidate_board(self):
(width, height) = self._get_size_func()
- rect = gtk.gdk.Rectangle(0, 0, width, height)
+ rect = Gdk.Rectangle()
+ rect.x, rect.y, rect.width, rect.height = (0, 0, width, height)
self._invalidate_rect_func(rect)
def _get_win_tiles(self):
diff --git a/helpwidget.py b/helpwidget.py
index af205e6..3d89908 100644
--- a/helpwidget.py
+++ b/helpwidget.py
@@ -21,11 +21,13 @@ from __future__ import with_statement
from gettext import gettext as _
import cairo
-import gobject
-import gtk
+
+from gi.repository import Gtk
+from gi.repository import Gdk
+from gi.repository import Rsvg
+
import math
import os
-import rsvg
import time
import board
@@ -33,7 +35,7 @@ from anim import Anim
from gridwidget import BoardDrawer, RemovalDrawer, WinDrawer
if 'SUGAR_BUNDLE_PATH' in os.environ:
- from sugar.graphics import style
+ from sugar3.graphics import style
_DEFAULT_SPACING = style.DEFAULT_SPACING
_DEFAULT_PADDING = style.DEFAULT_PADDING
_BG_COLOR = tuple(style.COLOR_SELECTION_GREY.get_rgba()[:3])
@@ -75,11 +77,11 @@ _CLICK_SPEED = 0.2
# Speed of the mouse, in units (4x3 per screen) per second.
_MOUSE_SPEED = 0.5
-class HelpWidget(gtk.EventBox):
+class HelpWidget(Gtk.EventBox):
def __init__(self, icon_file_func, *args, **kwargs):
super(HelpWidget, self).__init__(*args, **kwargs)
- vbox = gtk.VBox()
+ vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
self.add(vbox)
self._stages = [
@@ -90,11 +92,11 @@ class HelpWidget(gtk.EventBox):
_HelpStage5(icon_file_func),
]
self._stage_index = 0
- self._notebook = gtk.Notebook()
+ self._notebook = Gtk.Notebook()
self._notebook.set_show_tabs(False)
for stage in self._stages:
- self._notebook.append_page(stage)
- vbox.pack_start(self._notebook)
+ self._notebook.append_page(stage, None)
+ vbox.pack_start(self._notebook, True, True, 0)
self._reset_current_stage()
@@ -128,24 +130,27 @@ class HelpWidget(gtk.EventBox):
self._stages[self._stage_index].reset()
-class _HelpStage(gtk.EventBox):
+class _HelpStage(Gtk.EventBox):
# An abstract parent class for objects that represent an animated help
# screen widget with a description.
def __init__(self, icon_file_func, *args, **kwargs):
super(_HelpStage, self).__init__(*args, **kwargs)
- hbox = gtk.HBox()
+ hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
self.add(hbox)
- vbox = gtk.VBox()
- hbox.pack_start(vbox, expand=True, padding=_DEFAULT_SPACING)
+ vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
+ hbox.pack_start(vbox, expand=True, fill=True,
+ padding=_DEFAULT_SPACING)
self.preview = _PreviewWidget(icon_file_func)
- vbox.pack_start(self.preview, expand=True, padding=_DEFAULT_PADDING)
+ vbox.pack_start(self.preview, expand=True, fill=False,
+ padding=_DEFAULT_PADDING)
- label = gtk.Label(self.get_message())
+ label = Gtk.Label(label=self.get_message())
label.set_line_wrap(True)
- vbox.pack_start(label, expand=False, padding=_DEFAULT_PADDING)
+ vbox.pack_start(label, expand=False, fill=False,
+ padding=_DEFAULT_PADDING)
self.board = None
self.undo_stack = []
@@ -552,12 +557,7 @@ def _undo():
stage.next_action()
return action
-class _PreviewWidget(gtk.DrawingArea):
- __gsignals__ = {
- 'expose-event': 'override',
- 'size-allocate': 'override',
- }
-
+class _PreviewWidget(Gtk.DrawingArea):
def __init__(self, icon_file_func, *args, **kwargs):
super(_PreviewWidget, self).__init__(*args, **kwargs)
@@ -573,9 +573,17 @@ class _PreviewWidget(gtk.DrawingArea):
self._icon_file_func = icon_file_func
- self._preview_rect = gtk.gdk.Rectangle(0, 0, 0, 0)
- self._toolbar_rect = gtk.gdk.Rectangle(0, 0, 0, 0)
- self._drawer_rect = gtk.gdk.Rectangle(0, 0, 0, 0)
+ self._preview_rect = Gdk.Rectangle()
+ self._preview_rect.x = self._preview_rect.y = \
+ self._preview_rect.width = self._preview_rect.height = 0
+
+ self._toolbar_rect = Gdk.Rectangle()
+ self._toolbar_rect.x = self._toolbar_rect.y = \
+ self._toolbar_rect.width = self._toolbar_rect.height = 0
+
+ self._drawer_rect = Gdk.Rectangle()
+ self._drawer_rect.x = self._drawer_rect.y = \
+ self._drawer_rect.width = self._drawer_rect.height = 0
self._drawer = self.board_drawer
@@ -589,17 +597,20 @@ class _PreviewWidget(gtk.DrawingArea):
self._click_visible = False
self._cursor_visible = False
+ self.connect('draw', self._draw_event_cb)
+ self.connect('configure-event', self._configure_event_cb)
+ # self.connect('size-allocate', self._configure_event_cb)
+
def _get_drawer_size(self):
return (self._drawer_rect.width, self._drawer_rect.height)
def _invalidate_drawer_rect(self, rect):
- if self.window:
+ if self.get_window():
(x, y) = (self._drawer_rect.x, self._drawer_rect.y)
- offset_rect = gtk.gdk.Rectangle(rect.x + x,
- rect.y + y,
- rect.width,
- rect.height)
- self.window.invalidate_rect(offset_rect, True)
+ offset_rect = Gdk.Rectangle()
+ offset_rect.x, offset_rect.y, = (rect.x + x, rect.y + y)
+ offset_rect.width, offset_rect.height = (rect.width, rect.height)
+ self.get_window().invalidate_rect(offset_rect, True)
def set_drawer(self, drawer):
self._drawer = drawer
@@ -667,28 +678,29 @@ class _PreviewWidget(gtk.DrawingArea):
self._invalidate_client_rect(pixel_x - r, pixel_y - r, r2, r2)
def _invalidate_client_rect(self, x, y, width, height):
- if self.window:
- rect = gtk.gdk.Rectangle(
+ if self.get_window():
+ rect = Gdk.Rectangle()
+ rect.x, rect.y, rect.width, rect.height = (
int(math.floor(x)) + self._preview_rect.x,
int(math.floor(y)) + self._preview_rect.y,
int(math.ceil(width)) + 1,
int(math.ceil(height)) + 1)
- self.window.invalidate_rect(rect, True)
+
+ self.get_window().invalidate_rect(rect, True)
def _update_mouse_position(self):
(pixel_x, pixel_y) = self._get_cursor_pixel_coords()
(x, y) = (pixel_x, pixel_y - self._toolbar_rect.height)
self.board_drawer.set_mouse_selection(x, y)
- def do_expose_event(self, event):
- cr = self.window.cairo_create()
- cr.rectangle(event.area.x,
- event.area.y,
- event.area.width,
- event.area.height)
- cr.clip()
- (width, height) = self.window.get_size()
- self._draw(cr, width, height)
+ def _size_allocate_cb(self, widget, rect):
+ self.width = rect.width
+ self.height = rect.height
+
+ def _draw_event_cb(self, widget, cr):
+ alloc = self.get_allocation()
+ cr.rectangle(0, 0, alloc.width, alloc.height)
+ self._draw(cr, alloc.width, alloc.height)
def _draw(self, cr, width, height):
cr.set_source_rgb(*_BG_COLOR)
@@ -737,7 +749,8 @@ class _PreviewWidget(gtk.DrawingArea):
def _draw_grid(self, cr):
cr.save()
cr.translate(self._drawer_rect.x, self._drawer_rect.y)
- self._drawer.draw(cr, self._drawer_rect.width, self._drawer_rect.height)
+ self._drawer.draw(cr, self._drawer_rect.width,
+ self._drawer_rect.height)
cr.restore()
def _draw_click(self, cr):
@@ -803,22 +816,13 @@ class _PreviewWidget(gtk.DrawingArea):
cr.restore()
- def do_size_allocate(self, allocation):
- super(_PreviewWidget, self).do_size_allocate(self, allocation)
- (width, height) = (allocation.width, allocation.height)
+ def _configure_event_cb(self, widget, event):
+ (width, height) = (event.width, event.height)
- avail_width = width - _DEFAULT_SPACING * 2
- other_height = avail_width * 3 / 4
+ actual_width = width - style.GRID_CELL_SIZE * 4
+ actual_height = actual_width * 3 / 4
- avail_height = height - _DEFAULT_SPACING * 2
- other_width = avail_height * 4 / 3
-
- if other_height < avail_height:
- actual_width = avail_width
- actual_height = other_height
- else:
- actual_width = other_width
- actual_height = avail_height
+ self.set_size_request(actual_width, actual_height)
icon_height = int(math.ceil(actual_height * _ICON_HEIGHT))
board_height = actual_height - icon_height
@@ -826,21 +830,24 @@ class _PreviewWidget(gtk.DrawingArea):
x_offset = (width - actual_width) / 2
y_offset = (height - actual_height) / 2
- old_width = self._preview_rect.width
- old_height = self._preview_rect.height
-
- self._preview_rect = gtk.gdk.Rectangle(x_offset,
- y_offset,
- actual_width,
- actual_height)
- self._toolbar_rect = gtk.gdk.Rectangle(x_offset,
- y_offset,
- actual_width,
- icon_height)
- self._drawer_rect = gtk.gdk.Rectangle(x_offset,
- y_offset + icon_height,
- actual_width,
- board_height)
+ self._preview_rect = Gdk.Rectangle()
+ self._preview_rect.x = x_offset
+ self._preview_rect.y = y_offset
+ self._preview_rect.width = actual_width
+ self._preview_rect.height = actual_height
+
+ self._toolbar_rect = Gdk.Rectangle()
+ self._toolbar_rect.x = x_offset
+ self._toolbar_rect.y = y_offset
+ self._toolbar_rect.width = actual_width
+ self._toolbar_rect.height = icon_height
+
+ self._drawer_rect = Gdk.Rectangle()
+ self._drawer_rect.x = x_offset
+ self._drawer_rect.y = y_offset + icon_height
+ self._drawer_rect.width = actual_width
+ self._drawer_rect.height = board_height
+
self.board_drawer.resize(actual_width, board_height)
self.removal_drawer.resize(actual_width, board_height)
self.win_drawer.resize(actual_width, board_height)
@@ -886,6 +893,6 @@ def _get_icon_handle(file_path):
if file_path not in _icon_handles:
with open(file_path, 'r') as f:
data = f.read()
- _icon_handles[file_path] = rsvg.Handle(data=data)
+ _icon_handles[file_path] = Rsvg.Handle.new_from_data(data)
return _icon_handles[file_path]
diff --git a/implodeactivity.py b/implodeactivity.py
index 3e4cb2f..c03d7fe 100644
--- a/implodeactivity.py
+++ b/implodeactivity.py
@@ -21,35 +21,25 @@ _logger = logging.getLogger('implode-activity')
from gettext import gettext as _
-from sugar.activity.activity import Activity, get_bundle_path
-from sugar.graphics import style
-from sugar.graphics.icon import Icon
-from sugar.graphics.radiotoolbutton import RadioToolButton
-from sugar.graphics.toolbutton import ToolButton
-
-try:
- # 0.86+ toolbar widgets
- from sugar.activity.widgets import ActivityToolbarButton, StopButton
- from sugar.graphics.toolbarbox import ToolbarBox, ToolbarButton
- _USE_OLD_TOOLBARS = False
-except ImportError:
- # Pre-0.86 toolbar widgets
- from sugar.activity.activity import ActivityToolbox
- _USE_OLD_TOOLBARS = True
+from sugar3.activity.activity import Activity, get_bundle_path
+from sugar3.graphics import style
+from sugar3.graphics.icon import Icon
+from sugar3.graphics.radiotoolbutton import RadioToolButton
+from sugar3.graphics.toolbutton import ToolButton
+
+from sugar3.activity.widgets import ActivityToolbarButton, StopButton
+from sugar3.graphics.toolbarbox import ToolbarBox, ToolbarButton
from implodegame import ImplodeGame
from helpwidget import HelpWidget
import os
-try:
- import json
- json.dumps
-except (ImportError, AttributeError):
- import simplejson as json
+import json
from StringIO import StringIO
-import gtk
-import gobject
+from gi.repository import Gtk
+from gi.repository import GObject
+from gi.repository import Gdk
from keymap import KEY_MAP
@@ -63,8 +53,8 @@ class ImplodeActivity(Activity):
self._game = ImplodeGame()
- game_box = gtk.VBox()
- game_box.pack_start(self._game)
+ game_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
+ game_box.pack_start(self._game, True, True, 0)
self._stuck_strip = _StuckStrip()
self._configure_toolbars()
@@ -73,7 +63,7 @@ class ImplodeActivity(Activity):
# Show everything except the stuck strip.
self.show_all()
- game_box.pack_end(self._stuck_strip, expand=False)
+ game_box.pack_end(self._stuck_strip, expand=False, fill=False, padding=0)
self._game.connect('show-stuck', self._show_stuck_cb)
self._stuck_strip.connect('undo-clicked', self._stuck_undo_cb)
@@ -96,8 +86,8 @@ class ImplodeActivity(Activity):
file_data = json.load(io)
f.close()
- print file_data
- _logger.debug(file_data)
+ # print file_data
+ # _logger.debug(file_data)
(file_type, version, game_data) = file_data
if file_type == 'Implode save game' and version <= [1, 0]:
self._game.set_game_state(game_data)
@@ -121,7 +111,7 @@ class ImplodeActivity(Activity):
if data:
self._stuck_strip.show_all()
else:
- if self._stuck_strip.focus_child:
+ if self._stuck_strip.get_focus_child():
self._game.grab_focus()
self._stuck_strip.hide()
@@ -133,13 +123,13 @@ class ImplodeActivity(Activity):
action = KEY_MAP.get(event.keyval, None)
if action is None:
return False
- if not self._stuck_strip.flags() & gtk.VISIBLE:
+ if not self._stuck_strip.get_state_flags() & Gtk.AccelFlags.VISIBLE:
return True
- if self._game.focus_child:
+ if self._game.get_focus_child():
if action == 'down':
self._stuck_strip.button.grab_focus()
return True
- elif self._stuck_strip.focus_child:
+ elif self._stuck_strip.get_focus_child():
if action == 'up':
self._game.grab_focus()
elif action == 'select':
@@ -152,18 +142,14 @@ class ImplodeActivity(Activity):
controls, difficulty selector, help button, and stop button. All
callbacks are locally defined."""
- if _USE_OLD_TOOLBARS:
- toolbox = ActivityToolbox(self)
- toolbar = gtk.Toolbar()
- else:
- toolbar_box = ToolbarBox()
- toolbar = toolbar_box.toolbar
+ toolbar_box = ToolbarBox()
+ toolbar = toolbar_box.toolbar
- activity_button = ActivityToolbarButton(self)
- toolbar_box.toolbar.insert(activity_button, 0)
- activity_button.show()
+ activity_button = ActivityToolbarButton(self)
+ toolbar_box.toolbar.insert(activity_button, 0)
+ activity_button.show()
- toolbar.add(gtk.SeparatorToolItem())
+ toolbar.add(Gtk.SeparatorToolItem())
def add_button(icon_name, tooltip, func):
def callback(source):
@@ -176,12 +162,12 @@ class ImplodeActivity(Activity):
add_button('new-game' , _("New") , self._game.new_game)
add_button('replay-game', _("Replay"), self._game.replay_game)
- toolbar.add(gtk.SeparatorToolItem())
+ toolbar.add(Gtk.SeparatorToolItem())
add_button('edit-undo' , _("Undo") , self._game.undo)
add_button('edit-redo' , _("Redo") , self._game.redo)
- toolbar.add(gtk.SeparatorToolItem())
+ toolbar.add(Gtk.SeparatorToolItem())
self._levels_buttons = []
def add_level_button(icon_name, tooltip, numeric_level):
@@ -217,54 +203,47 @@ class ImplodeActivity(Activity):
# right now, however.
add_button('help-icon', _("Help"), _help_clicked_cb)
- if _USE_OLD_TOOLBARS:
- toolbox.add_toolbar(_("Game"), toolbar)
- toolbox.set_current_toolbar(1)
+ stop_button = StopButton(self)
+ stop_button.props.accelerator = '<Ctrl><Shift>Q'
+ toolbar_box.toolbar.insert(stop_button, -1)
+ stop_button.show()
- self.set_toolbox(toolbox)
- toolbox.show()
- else:
- stop_button = StopButton(self)
- stop_button.props.accelerator = '<Ctrl><Shift>Q'
- toolbar_box.toolbar.insert(stop_button, -1)
- stop_button.show()
-
- self.set_toolbar_box(toolbar_box)
- toolbar_box.show()
+ self.set_toolbar_box(toolbar_box)
+ toolbar_box.show()
def _add_expander(self, toolbar, expand=True):
"""Insert a toolbar item which will expand to fill the available
space."""
- separator = gtk.SeparatorToolItem()
+ separator = Gtk.SeparatorToolItem()
separator.props.draw = False
separator.set_expand(expand)
toolbar.insert(separator, -1)
separator.show()
-class _DialogWindow(gtk.Window):
+class _DialogWindow(Gtk.Window):
# A base class for a modal dialog window.
def __init__(self, icon_name, title):
super(_DialogWindow, self).__init__()
self.set_border_width(style.LINE_WIDTH)
offset = style.GRID_CELL_SIZE
- width = gtk.gdk.screen_width() / 2
- height = gtk.gdk.screen_height() / 2
+ width = Gdk.Screen.width() / 2
+ height = Gdk.Screen.height() / 2
self.set_size_request(width, height)
- self.set_position(gtk.WIN_POS_CENTER_ALWAYS)
+ self.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
self.set_decorated(False)
self.set_resizable(False)
self.set_modal(True)
- vbox = gtk.VBox()
+ vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
self.add(vbox)
toolbar = _DialogToolbar(icon_name, title)
toolbar.connect('stop-clicked', self._stop_clicked_cb)
- vbox.pack_start(toolbar, False)
+ vbox.pack_start(toolbar, expand=False, fill=False, padding=0)
- self.content_vbox = gtk.VBox()
+ self.content_vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
self.content_vbox.set_border_width(style.DEFAULT_SPACING)
vbox.add(self.content_vbox)
@@ -274,8 +253,8 @@ class _DialogWindow(gtk.Window):
self.destroy()
def _realize_cb(self, source):
- self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG)
- self.window.set_accept_focus(True)
+ self.set_type_hint(Gdk.WindowTypeHint.DIALOG)
+ self.get_window().set_accept_focus(True)
class _HelpWindow(_DialogWindow):
@@ -284,17 +263,16 @@ class _HelpWindow(_DialogWindow):
super(_HelpWindow, self).__init__('help-icon', _("Help"))
offset = style.GRID_CELL_SIZE
- width = gtk.gdk.screen_width() - offset * 2
- height = gtk.gdk.screen_height() - offset * 2
+ width = Gdk.Screen.width() - offset * 2
+ height = Gdk.Screen.height() - offset * 2
self.set_size_request(width, height)
self._help_widget = HelpWidget(self._icon_file)
- self.content_vbox.pack_start(self._help_widget)
+ self.content_vbox.pack_start(self._help_widget, True, True, 0)
self._help_nav_bar = _HelpNavBar()
- self.content_vbox.pack_end(self._help_nav_bar,
- expand=False,
- padding=style.DEFAULT_SPACING)
+ self.content_vbox.pack_end(self._help_nav_bar, expand=False,
+ fill=False, padding=style.DEFAULT_SPACING)
for (signal_name, callback) in [
('forward-clicked', self._forward_clicked_cb),
@@ -316,7 +294,7 @@ class _HelpWindow(_DialogWindow):
self._help_widget.replay_stage()
def _icon_file(self, icon_name):
- theme = gtk.icon_theme_get_default()
+ theme = Gtk.IconTheme.get_default()
info = theme.lookup_icon(icon_name, 0, 0)
return info.get_filename()
@@ -326,21 +304,21 @@ class _HelpWindow(_DialogWindow):
self._help_nav_bar.set_can_next_stage(hw.can_next_stage())
-class _DialogToolbar(gtk.Toolbar):
+class _DialogToolbar(Gtk.Toolbar):
# Displays a dialog window's toolbar, with title, icon, and close box.
__gsignals__ = {
- 'stop-clicked' : (gobject.SIGNAL_RUN_LAST, None, ()),
+ 'stop-clicked' : (GObject.SignalFlags.RUN_LAST, None, ()),
}
def __init__(self, icon_name, title):
super(_DialogToolbar, self).__init__()
icon = Icon()
- icon.set_from_icon_name(icon_name, gtk.ICON_SIZE_LARGE_TOOLBAR)
+ icon.set_from_icon_name(icon_name, Gtk.IconSize.LARGE_TOOLBAR)
self._add_widget(icon)
self._add_separator()
- label = gtk.Label(title)
+ label = Gtk.Label(label=title)
self._add_widget(label)
self._add_separator(expand=True)
@@ -351,13 +329,13 @@ class _DialogToolbar(gtk.Toolbar):
self.add(stop)
def _add_separator(self, expand=False):
- separator = gtk.SeparatorToolItem()
+ separator = Gtk.SeparatorToolItem()
separator.set_expand(expand)
separator.set_draw(False)
self.add(separator)
def _add_widget(self, widget):
- tool_item = gtk.ToolItem()
+ tool_item = Gtk.ToolItem()
tool_item.add(widget)
self.add(tool_item)
@@ -365,24 +343,24 @@ class _DialogToolbar(gtk.Toolbar):
self.emit('stop-clicked')
-class _HelpNavBar(gtk.HButtonBox):
+class _HelpNavBar(Gtk.HButtonBox):
# A widget to display the navigation controls at the bottom of the help
# dialog.
__gsignals__ = {
- 'forward-clicked' : (gobject.SIGNAL_RUN_LAST, None, ()),
- 'back-clicked' : (gobject.SIGNAL_RUN_LAST, None, ()),
- 'reload-clicked' : (gobject.SIGNAL_RUN_LAST, None, ()),
+ 'forward-clicked' : (GObject.SignalFlags.RUN_LAST, None, ()),
+ 'back-clicked' : (GObject.SignalFlags.RUN_LAST, None, ()),
+ 'reload-clicked' : (GObject.SignalFlags.RUN_LAST, None, ()),
}
def __init__(self):
super(_HelpNavBar, self).__init__()
- self.set_layout(gtk.BUTTONBOX_SPREAD)
+ self.set_layout(Gtk.ButtonBoxStyle.SPREAD)
def add_button(icon_name, tooltip, signal_name):
icon = Icon()
- icon.set_from_icon_name(icon_name, gtk.ICON_SIZE_LARGE_TOOLBAR)
- button = gtk.Button()
+ icon.set_from_icon_name(icon_name, Gtk.IconSize.LARGE_TOOLBAR)
+ button = Gtk.Button()
button.set_image(icon)
button.set_tooltip_text(tooltip)
self.add(button)
@@ -404,32 +382,34 @@ class _HelpNavBar(gtk.HButtonBox):
self._forward_button.set_sensitive(can_next_stage)
-class _StuckStrip(gtk.HBox):
+class _StuckStrip(Gtk.Box):
__gsignals__ = {
- 'undo-clicked' : (gobject.SIGNAL_RUN_LAST, None, ()),
+ 'undo-clicked' : (GObject.SignalFlags.RUN_LAST, None, ()),
}
def __init__(self, *args, **kwargs):
super(_StuckStrip, self).__init__(*args, **kwargs)
- spacer1 = gtk.Label('')
- self.pack_start(spacer1, expand=True)
+ self.orientation = Gtk.Orientation.HORIZONTAL
+
+ spacer1 = Gtk.Label(label='')
+ self.pack_start(spacer1, True, True, 0)
- spacer2 = gtk.Label('')
- self.pack_end(spacer2, expand=True)
+ spacer2 = Gtk.Label(label='')
+ self.pack_end(spacer2, expand=True, fill=False, padding=0)
self.set_spacing(10)
self.set_border_width(10)
- label = gtk.Label(_("Stuck? You can still solve the puzzle."))
- self.pack_start(label, expand=False)
+ label = Gtk.Label(label=_("Stuck? You can still solve the puzzle."))
+ self.pack_start(label, False, True, 0)
icon = Icon()
- icon.set_from_icon_name('edit-undo', gtk.ICON_SIZE_LARGE_TOOLBAR)
- self.button = gtk.Button(stock=gtk.STOCK_UNDO)
+ icon.set_from_icon_name('edit-undo', Gtk.IconSize.LARGE_TOOLBAR)
+ self.button = Gtk.Button(stock=Gtk.STOCK_UNDO)
self.button.set_image(icon)
self.button.set_label(_("Undo some moves"))
- self.pack_end(self.button, expand=False)
+ self.pack_end(self.button, expand=False, fill=False, padding=0)
def callback(source):
self.emit('undo-clicked')
diff --git a/implodegame.py b/implodegame.py
index 60c507c..7841d69 100644
--- a/implodegame.py
+++ b/implodegame.py
@@ -21,8 +21,8 @@ _logger = logging.getLogger('implode-activity.implodegame')
from gettext import gettext as _
-import gtk
-import gobject
+from gi.repository import Gtk
+from gi.repository import GObject
import random
import time
@@ -39,11 +39,11 @@ _STUCK_DELAY = 0.5
# state after the player gets stuck, in seconds.
_UNDO_DELAY = 0.3
-class ImplodeGame(gtk.EventBox):
+class ImplodeGame(Gtk.EventBox):
"""Gtk widget for playing the implode game."""
__gsignals__ = {
- 'show-stuck': (gobject.SIGNAL_RUN_LAST, None, (int,)),
+ 'show-stuck': (GObject.SignalFlags.RUN_LAST, None, (int,)),
}
def __init__(self, *args, **kwargs):
diff --git a/keymap.py b/keymap.py
index b420ace..0322b22 100644
--- a/keymap.py
+++ b/keymap.py
@@ -16,47 +16,47 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-import gtk
+from gi.repository import Gdk
KEY_MAP = {
- gtk.keysyms.KP_Up : 'up',
- gtk.keysyms.KP_Down : 'down',
- gtk.keysyms.KP_Left : 'left',
- gtk.keysyms.KP_Right : 'right',
-
- gtk.keysyms.w : 'up',
- gtk.keysyms.s : 'down',
- gtk.keysyms.a : 'left',
- gtk.keysyms.d : 'right',
-
- gtk.keysyms.KP_8 : 'up',
- gtk.keysyms.KP_2 : 'down',
- gtk.keysyms.KP_4 : 'left',
- gtk.keysyms.KP_6 : 'right',
-
- gtk.keysyms.Up : 'up',
- gtk.keysyms.Down : 'down',
- gtk.keysyms.Left : 'left',
- gtk.keysyms.Right : 'right',
-
- gtk.keysyms.uparrow : 'up',
- gtk.keysyms.downarrow : 'down',
- gtk.keysyms.leftarrow : 'left',
- gtk.keysyms.rightarrow : 'right',
-
- gtk.keysyms.Return : 'select',
- gtk.keysyms.KP_Space : 'select',
- gtk.keysyms.KP_Enter : 'select',
- gtk.keysyms.space : 'select',
- gtk.keysyms.End : 'select',
- gtk.keysyms.KP_End : 'select',
- gtk.keysyms.KP_1 : 'select',
- gtk.keysyms.q : 'select',
-
- gtk.keysyms.Home : 'new',
- gtk.keysyms.KP_Home : 'new',
- gtk.keysyms.Page_Down : 'redo',
- gtk.keysyms.KP_Page_Down : 'redo',
- gtk.keysyms.Page_Up : 'undo',
- gtk.keysyms.KP_Page_Up : 'undo',
+ Gdk.KEY_KP_Up : 'up',
+ Gdk.KEY_KP_Down : 'down',
+ Gdk.KEY_KP_Left : 'left',
+ Gdk.KEY_KP_Right : 'right',
+
+ Gdk.KEY_w : 'up',
+ Gdk.KEY_s : 'down',
+ Gdk.KEY_a : 'left',
+ Gdk.KEY_d : 'right',
+
+ Gdk.KEY_KP_8 : 'up',
+ Gdk.KEY_KP_2 : 'down',
+ Gdk.KEY_KP_4 : 'left',
+ Gdk.KEY_KP_6 : 'right',
+
+ Gdk.KEY_Up : 'up',
+ Gdk.KEY_Down : 'down',
+ Gdk.KEY_Left : 'left',
+ Gdk.KEY_Right : 'right',
+
+ Gdk.KEY_uparrow : 'up',
+ Gdk.KEY_downarrow : 'down',
+ Gdk.KEY_leftarrow : 'left',
+ Gdk.KEY_rightarrow : 'right',
+
+ Gdk.KEY_Return : 'select',
+ Gdk.KEY_KP_Space : 'select',
+ Gdk.KEY_KP_Enter : 'select',
+ Gdk.KEY_space : 'select',
+ Gdk.KEY_End : 'select',
+ Gdk.KEY_KP_End : 'select',
+ Gdk.KEY_KP_1 : 'select',
+ Gdk.KEY_q : 'select',
+
+ Gdk.KEY_Home : 'new',
+ Gdk.KEY_KP_Home : 'new',
+ Gdk.KEY_Page_Down : 'redo',
+ Gdk.KEY_KP_Page_Down : 'redo',
+ Gdk.KEY_Page_Up : 'undo',
+ Gdk.KEY_KP_Page_Up : 'undo',
}
diff --git a/setup.py b/setup.py
index 211f104..cbdf097 100644
--- a/setup.py
+++ b/setup.py
@@ -1,5 +1,5 @@
#!/usr/bin/env python
-from sugar.activity import bundlebuilder
+from sugar3.activity import bundlebuilder
if __name__ == "__main__":
bundlebuilder.start()
--
1.7.11.2
More information about the Sugar-devel
mailing list