Ticket #3715: 0001-Port-to-Gtk3-SL-3715.patch
File 0001-Port-to-Gtk3-SL-3715.patch, 37.2 KB (added by humitos, 12 years ago) |
---|
-
anim.py
From 6bd1ccef661420a352e0b0127d6ff6c3415ca2b9 Mon Sep 17 00:00:00 2001 From: Manuel Kaufmann <humitos@gmail.com> Date: Mon, 6 Aug 2012 17:26:11 -0300 Subject: [PATCH Implode] Port to Gtk3 SL #3715 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@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 b 16 16 # along with this program; if not, write to the Free Software 17 17 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 18 19 import gobject19 from gi.repository import GObject 20 20 21 21 # Animation timer interval (in msec) 22 22 _TIMER_INTERVAL = 20 … … class Anim(object): 34 34 def start(self): 35 35 self._animating = True 36 36 self._update_func() 37 gobject.timeout_add(_TIMER_INTERVAL, self._timer)37 GObject.timeout_add(_TIMER_INTERVAL, self._timer) 38 38 39 39 def stop(self): 40 40 if self._animating: -
gridwidget.py
diff --git a/gridwidget.py b/gridwidget.py index 8ee3aad..c3b6596 100644
a b import logging 20 20 _logger = logging.getLogger('implode-activity.gridwidget') 21 21 22 22 import cairo 23 import gobject 24 import gtk 23 from gi.repository import GObject 24 from gi.repository import Gtk 25 from gi.repository import Gdk 25 26 import math 26 27 import random 27 28 import time … … _ANIM_SCALE = 0.04 93 94 def _log_errors(func): 94 95 return func 95 96 96 class GridWidget( gtk.DrawingArea):97 class GridWidget(Gtk.DrawingArea): 97 98 """Gtk widget for rendering the game board.""" 98 99 99 100 __gsignals__ = { 100 'piece-selected' : (gobject.SIGNAL_RUN_LAST, None, (int, int)), 101 'undo-key-pressed': (gobject.SIGNAL_RUN_LAST, None, (int,)), 102 'redo-key-pressed': (gobject.SIGNAL_RUN_LAST, None, (int,)), 103 'new-key-pressed' : (gobject.SIGNAL_RUN_LAST, None, (int,)), 104 'button-press-event': 'override', 105 'key-press-event': 'override', 106 'expose-event': 'override', 107 'size-allocate': 'override', 108 'motion-notify-event': 'override', 101 'piece-selected': (GObject.SignalFlags.RUN_LAST, None, (int, int)), 102 'undo-key-pressed': (GObject.SignalFlags.RUN_LAST, None, (int,)), 103 'redo-key-pressed': (GObject.SignalFlags.RUN_LAST, None, (int,)), 104 'new-key-pressed': (GObject.SignalFlags.RUN_LAST, None, (int,)), 109 105 } 110 106 111 107 def __init__(self, *args, **kwargs): 112 108 super(GridWidget, self).__init__(*args, **kwargs) 113 self.set_events( gtk.gdk.BUTTON_PRESS_MASK114 | gtk.gdk.POINTER_MOTION_MASK115 | gtk.gdk.KEY_PRESS_MASK)116 self.set_ flags(gtk.CAN_FOCUS)109 self.set_events(Gdk.EventMask.BUTTON_PRESS_MASK 110 | Gdk.EventMask.POINTER_MOTION_MASK 111 | Gdk.EventMask.KEY_PRESS_MASK) 112 self.set_can_focus(True) 117 113 118 114 self._board_drawer = BoardDrawer(self._get_size, self._invalidate_rect) 119 115 self._win_drawer = WinDrawer(self._get_size, self._invalidate_rect) 120 116 self._removal_drawer = RemovalDrawer(self._get_size, self._invalidate_rect) 121 117 self._set_current_drawer(self._board_drawer) 122 118 119 self.connect('draw', self._draw_event_cb) 120 self.connect('configure-event', self._configure_event_cb) 121 self.connect('button-press-event', self._button_press_event_cb) 122 123 123 def _get_size(self): 124 return (self. allocation.width, self.allocation.height)124 return (self.get_allocated_width(), self.get_allocated_height()) 125 125 126 126 def _invalidate_rect(self, rect): 127 if self. window:128 self. window.invalidate_rect(rect, True)127 if self.get_window(): 128 self.get_window().invalidate_rect(rect, True) 129 129 130 130 def set_board(self, board): 131 131 self._board_drawer.set_board(board) … … class GridWidget(gtk.DrawingArea): 141 141 142 142 def _invalidate_board(self): 143 143 (width, height) = self._get_size() 144 self._invalidate_rect(gtk.gdk.Rectangle(0, 0, width, height)) 144 rect = Gdk.Rectangle() 145 rect.x, rect.y, rect.width, rect.height = (0, 0, width, height) 146 self._invalidate_rect(rect) 145 147 146 148 def get_win_draw_flag(self): 147 149 return (self._current_drawer is self._win_drawer) … … class GridWidget(gtk.DrawingArea): 160 162 self._board_drawer.select_center_cell() 161 163 162 164 @_log_errors 163 def do_button_press_event(self, event):165 def _button_press_event_cb(self, widget, event): 164 166 # Ignore mouse clicks while animating. 165 167 if self._is_animating(): 166 168 return True 167 169 # Ignore double- and triple-clicks. 168 if event.type != gtk.gdk.BUTTON_PRESS:170 if event.type != Gdk.EventType.BUTTON_PRESS: 169 171 return True 170 172 self.grab_focus() 171 173 self._board_drawer.set_mouse_selection(event.x, event.y) … … class GridWidget(gtk.DrawingArea): 219 221 else: 220 222 x = event.x 221 223 y = event.y 222 state = event. state224 state = event.get_state() 223 225 self._board_drawer.set_mouse_selection(x, y) 224 226 225 @_log_errors 226 def do_expose_event(self, event): 227 cr = self.window.cairo_create() 228 cr.rectangle(event.area.x, 229 event.area.y, 230 event.area.width, 231 event.area.height) 232 cr.clip() 233 (width, height) = self.window.get_size() 234 self._current_drawer.draw(cr, width, height) 227 def _draw_event_cb(self, widget, cr): 228 alloc = self.get_allocation() 229 self._current_drawer.draw(cr, alloc.width, alloc.height) 235 230 236 231 @_log_errors 237 def do_size_allocate(self, allocation): 238 super(GridWidget, self).do_size_allocate(self, allocation) 239 self._current_drawer.resize(allocation.width, allocation.height) 232 def _configure_event_cb(self, widget, event): 233 self._current_drawer.resize(event.width, event.height) 240 234 241 235 def _set_current_drawer(self, drawer): 242 236 self._current_drawer = drawer … … class BoardDrawer(object): 382 376 383 377 def _invalidate_board(self): 384 378 (width, height) = self._get_size_func() 385 rect = gtk.gdk.Rectangle(0, 0, width, height) 379 rect = Gdk.Rectangle() 380 rect.x, rect.y, rect.width, rect.height = (0, 0, width, height) 386 381 self._invalidate_rect_func(rect) 387 382 388 383 def _invalidate_selection(self, selection_coord): … … class BoardDrawer(object): 407 402 max_x2 = math.ceil( max(pt1[0], pt2[0])) + 1 408 403 min_y2 = math.floor(min(pt1[1], pt2[1])) - 1 409 404 max_y2 = math.ceil( max(pt1[1], pt2[1])) + 1 410 rect = gtk.gdk.Rectangle(int(min_x2),411 int(min_y2),412 int(max_x2 - min_x2),413 405 rect = Gdk.Rectangle() 406 rect.x, rect.y, rect.width, rect.height = ( 407 int(min_x2), int(min_y2), 408 int(max_x2 - min_x2), int(max_y2 - min_y2)) 414 409 self._invalidate_rect_func(rect) 415 410 416 411 def _display_to_cell(self, x, y): … … class BoardDrawer(object): 426 421 self._board_transform = _BoardTransform() 427 422 else: 428 423 self._board_transform = _BoardTransform() 429 self._board_transform.setup(width, 430 height, 431 self._board_width, 432 self._board_height) 424 self._board_transform.setup(width, height, self._board_width, 425 self._board_height) 433 426 434 427 def draw(self, cr, width, height): 435 428 # Draws the widget. … … class RemovalDrawer(object): 564 557 565 558 def _invalidate_board(self): 566 559 (width, height) = self._get_size_func() 567 rect = gtk.gdk.Rectangle(0, 0, width, height) 560 rect = Gdk.Rectangle() 561 rect.x, rect.y, rect.width, rect.height = (0, 0, width, height) 568 562 self._invalidate_rect_func(rect) 569 563 570 564 def _recalc_game_anim_frames(self): … … class WinDrawer(object): 810 804 811 805 def _invalidate_board(self): 812 806 (width, height) = self._get_size_func() 813 rect = gtk.gdk.Rectangle(0, 0, width, height) 807 rect = Gdk.Rectangle() 808 rect.x, rect.y, rect.width, rect.height = (0, 0, width, height) 814 809 self._invalidate_rect_func(rect) 815 810 816 811 def _get_win_tiles(self): -
helpwidget.py
diff --git a/helpwidget.py b/helpwidget.py index af205e6..3d89908 100644
a b from __future__ import with_statement 21 21 from gettext import gettext as _ 22 22 23 23 import cairo 24 import gobject 25 import gtk 24 25 from gi.repository import Gtk 26 from gi.repository import Gdk 27 from gi.repository import Rsvg 28 26 29 import math 27 30 import os 28 import rsvg29 31 import time 30 32 31 33 import board … … from anim import Anim 33 35 from gridwidget import BoardDrawer, RemovalDrawer, WinDrawer 34 36 35 37 if 'SUGAR_BUNDLE_PATH' in os.environ: 36 from sugar .graphics import style38 from sugar3.graphics import style 37 39 _DEFAULT_SPACING = style.DEFAULT_SPACING 38 40 _DEFAULT_PADDING = style.DEFAULT_PADDING 39 41 _BG_COLOR = tuple(style.COLOR_SELECTION_GREY.get_rgba()[:3]) … … _CLICK_SPEED = 0.2 75 77 # Speed of the mouse, in units (4x3 per screen) per second. 76 78 _MOUSE_SPEED = 0.5 77 79 78 class HelpWidget( gtk.EventBox):80 class HelpWidget(Gtk.EventBox): 79 81 def __init__(self, icon_file_func, *args, **kwargs): 80 82 super(HelpWidget, self).__init__(*args, **kwargs) 81 83 82 vbox = gtk.VBox()84 vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) 83 85 self.add(vbox) 84 86 85 87 self._stages = [ … … class HelpWidget(gtk.EventBox): 90 92 _HelpStage5(icon_file_func), 91 93 ] 92 94 self._stage_index = 0 93 self._notebook = gtk.Notebook()95 self._notebook = Gtk.Notebook() 94 96 self._notebook.set_show_tabs(False) 95 97 for stage in self._stages: 96 self._notebook.append_page(stage )97 vbox.pack_start(self._notebook )98 self._notebook.append_page(stage, None) 99 vbox.pack_start(self._notebook, True, True, 0) 98 100 99 101 self._reset_current_stage() 100 102 … … class HelpWidget(gtk.EventBox): 128 130 self._stages[self._stage_index].reset() 129 131 130 132 131 class _HelpStage( gtk.EventBox):133 class _HelpStage(Gtk.EventBox): 132 134 # An abstract parent class for objects that represent an animated help 133 135 # screen widget with a description. 134 136 def __init__(self, icon_file_func, *args, **kwargs): 135 137 super(_HelpStage, self).__init__(*args, **kwargs) 136 138 137 hbox = gtk.HBox()139 hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) 138 140 self.add(hbox) 139 141 140 vbox = gtk.VBox() 141 hbox.pack_start(vbox, expand=True, padding=_DEFAULT_SPACING) 142 vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) 143 hbox.pack_start(vbox, expand=True, fill=True, 144 padding=_DEFAULT_SPACING) 142 145 143 146 self.preview = _PreviewWidget(icon_file_func) 144 vbox.pack_start(self.preview, expand=True, padding=_DEFAULT_PADDING) 147 vbox.pack_start(self.preview, expand=True, fill=False, 148 padding=_DEFAULT_PADDING) 145 149 146 label = gtk.Label(self.get_message())150 label = Gtk.Label(label=self.get_message()) 147 151 label.set_line_wrap(True) 148 vbox.pack_start(label, expand=False, padding=_DEFAULT_PADDING) 152 vbox.pack_start(label, expand=False, fill=False, 153 padding=_DEFAULT_PADDING) 149 154 150 155 self.board = None 151 156 self.undo_stack = [] … … def _undo(): 552 557 stage.next_action() 553 558 return action 554 559 555 class _PreviewWidget(gtk.DrawingArea): 556 __gsignals__ = { 557 'expose-event': 'override', 558 'size-allocate': 'override', 559 } 560 560 class _PreviewWidget(Gtk.DrawingArea): 561 561 def __init__(self, icon_file_func, *args, **kwargs): 562 562 super(_PreviewWidget, self).__init__(*args, **kwargs) 563 563 … … class _PreviewWidget(gtk.DrawingArea): 573 573 574 574 self._icon_file_func = icon_file_func 575 575 576 self._preview_rect = gtk.gdk.Rectangle(0, 0, 0, 0) 577 self._toolbar_rect = gtk.gdk.Rectangle(0, 0, 0, 0) 578 self._drawer_rect = gtk.gdk.Rectangle(0, 0, 0, 0) 576 self._preview_rect = Gdk.Rectangle() 577 self._preview_rect.x = self._preview_rect.y = \ 578 self._preview_rect.width = self._preview_rect.height = 0 579 580 self._toolbar_rect = Gdk.Rectangle() 581 self._toolbar_rect.x = self._toolbar_rect.y = \ 582 self._toolbar_rect.width = self._toolbar_rect.height = 0 583 584 self._drawer_rect = Gdk.Rectangle() 585 self._drawer_rect.x = self._drawer_rect.y = \ 586 self._drawer_rect.width = self._drawer_rect.height = 0 579 587 580 588 self._drawer = self.board_drawer 581 589 … … class _PreviewWidget(gtk.DrawingArea): 589 597 self._click_visible = False 590 598 self._cursor_visible = False 591 599 600 self.connect('draw', self._draw_event_cb) 601 self.connect('configure-event', self._configure_event_cb) 602 # self.connect('size-allocate', self._configure_event_cb) 603 592 604 def _get_drawer_size(self): 593 605 return (self._drawer_rect.width, self._drawer_rect.height) 594 606 595 607 def _invalidate_drawer_rect(self, rect): 596 if self. window:608 if self.get_window(): 597 609 (x, y) = (self._drawer_rect.x, self._drawer_rect.y) 598 offset_rect = gtk.gdk.Rectangle(rect.x + x, 599 rect.y + y, 600 rect.width, 601 rect.height) 602 self.window.invalidate_rect(offset_rect, True) 610 offset_rect = Gdk.Rectangle() 611 offset_rect.x, offset_rect.y, = (rect.x + x, rect.y + y) 612 offset_rect.width, offset_rect.height = (rect.width, rect.height) 613 self.get_window().invalidate_rect(offset_rect, True) 603 614 604 615 def set_drawer(self, drawer): 605 616 self._drawer = drawer … … class _PreviewWidget(gtk.DrawingArea): 667 678 self._invalidate_client_rect(pixel_x - r, pixel_y - r, r2, r2) 668 679 669 680 def _invalidate_client_rect(self, x, y, width, height): 670 if self.window: 671 rect = gtk.gdk.Rectangle( 681 if self.get_window(): 682 rect = Gdk.Rectangle() 683 rect.x, rect.y, rect.width, rect.height = ( 672 684 int(math.floor(x)) + self._preview_rect.x, 673 685 int(math.floor(y)) + self._preview_rect.y, 674 686 int(math.ceil(width)) + 1, 675 687 int(math.ceil(height)) + 1) 676 self.window.invalidate_rect(rect, True) 688 689 self.get_window().invalidate_rect(rect, True) 677 690 678 691 def _update_mouse_position(self): 679 692 (pixel_x, pixel_y) = self._get_cursor_pixel_coords() 680 693 (x, y) = (pixel_x, pixel_y - self._toolbar_rect.height) 681 694 self.board_drawer.set_mouse_selection(x, y) 682 695 683 def do_expose_event(self, event): 684 cr = self.window.cairo_create() 685 cr.rectangle(event.area.x, 686 event.area.y, 687 event.area.width, 688 event.area.height) 689 cr.clip() 690 (width, height) = self.window.get_size() 691 self._draw(cr, width, height) 696 def _size_allocate_cb(self, widget, rect): 697 self.width = rect.width 698 self.height = rect.height 699 700 def _draw_event_cb(self, widget, cr): 701 alloc = self.get_allocation() 702 cr.rectangle(0, 0, alloc.width, alloc.height) 703 self._draw(cr, alloc.width, alloc.height) 692 704 693 705 def _draw(self, cr, width, height): 694 706 cr.set_source_rgb(*_BG_COLOR) … … class _PreviewWidget(gtk.DrawingArea): 737 749 def _draw_grid(self, cr): 738 750 cr.save() 739 751 cr.translate(self._drawer_rect.x, self._drawer_rect.y) 740 self._drawer.draw(cr, self._drawer_rect.width, self._drawer_rect.height) 752 self._drawer.draw(cr, self._drawer_rect.width, 753 self._drawer_rect.height) 741 754 cr.restore() 742 755 743 756 def _draw_click(self, cr): … … class _PreviewWidget(gtk.DrawingArea): 803 816 804 817 cr.restore() 805 818 806 def do_size_allocate(self, allocation): 807 super(_PreviewWidget, self).do_size_allocate(self, allocation) 808 (width, height) = (allocation.width, allocation.height) 819 def _configure_event_cb(self, widget, event): 820 (width, height) = (event.width, event.height) 809 821 810 a vail_width = width - _DEFAULT_SPACING * 2811 other_height = avail_width * 3 / 4822 actual_width = width - style.GRID_CELL_SIZE * 4 823 actual_height = actual_width * 3 / 4 812 824 813 avail_height = height - _DEFAULT_SPACING * 2 814 other_width = avail_height * 4 / 3 815 816 if other_height < avail_height: 817 actual_width = avail_width 818 actual_height = other_height 819 else: 820 actual_width = other_width 821 actual_height = avail_height 825 self.set_size_request(actual_width, actual_height) 822 826 823 827 icon_height = int(math.ceil(actual_height * _ICON_HEIGHT)) 824 828 board_height = actual_height - icon_height … … class _PreviewWidget(gtk.DrawingArea): 826 830 x_offset = (width - actual_width) / 2 827 831 y_offset = (height - actual_height) / 2 828 832 829 old_width = self._preview_rect.width 830 old_height = self._preview_rect.height 831 832 self._preview_rect = gtk.gdk.Rectangle(x_offset, 833 y_offset, 834 actual_width, 835 actual_height) 836 self._toolbar_rect = gtk.gdk.Rectangle(x_offset, 837 y_offset, 838 actual_width, 839 icon_height) 840 self._drawer_rect = gtk.gdk.Rectangle(x_offset, 841 y_offset + icon_height, 842 actual_width, 843 board_height) 833 self._preview_rect = Gdk.Rectangle() 834 self._preview_rect.x = x_offset 835 self._preview_rect.y = y_offset 836 self._preview_rect.width = actual_width 837 self._preview_rect.height = actual_height 838 839 self._toolbar_rect = Gdk.Rectangle() 840 self._toolbar_rect.x = x_offset 841 self._toolbar_rect.y = y_offset 842 self._toolbar_rect.width = actual_width 843 self._toolbar_rect.height = icon_height 844 845 self._drawer_rect = Gdk.Rectangle() 846 self._drawer_rect.x = x_offset 847 self._drawer_rect.y = y_offset + icon_height 848 self._drawer_rect.width = actual_width 849 self._drawer_rect.height = board_height 850 844 851 self.board_drawer.resize(actual_width, board_height) 845 852 self.removal_drawer.resize(actual_width, board_height) 846 853 self.win_drawer.resize(actual_width, board_height) … … def _get_icon_handle(file_path): 886 893 if file_path not in _icon_handles: 887 894 with open(file_path, 'r') as f: 888 895 data = f.read() 889 _icon_handles[file_path] = rsvg.Handle(data=data)896 _icon_handles[file_path] = Rsvg.Handle.new_from_data(data) 890 897 891 898 return _icon_handles[file_path] -
implodeactivity.py
diff --git a/implodeactivity.py b/implodeactivity.py index 3e4cb2f..c03d7fe 100644
a b _logger = logging.getLogger('implode-activity') 21 21 22 22 from gettext import gettext as _ 23 23 24 from sugar.activity.activity import Activity, get_bundle_path 25 from sugar.graphics import style 26 from sugar.graphics.icon import Icon 27 from sugar.graphics.radiotoolbutton import RadioToolButton 28 from sugar.graphics.toolbutton import ToolButton 29 30 try: 31 # 0.86+ toolbar widgets 32 from sugar.activity.widgets import ActivityToolbarButton, StopButton 33 from sugar.graphics.toolbarbox import ToolbarBox, ToolbarButton 34 _USE_OLD_TOOLBARS = False 35 except ImportError: 36 # Pre-0.86 toolbar widgets 37 from sugar.activity.activity import ActivityToolbox 38 _USE_OLD_TOOLBARS = True 24 from sugar3.activity.activity import Activity, get_bundle_path 25 from sugar3.graphics import style 26 from sugar3.graphics.icon import Icon 27 from sugar3.graphics.radiotoolbutton import RadioToolButton 28 from sugar3.graphics.toolbutton import ToolButton 29 30 from sugar3.activity.widgets import ActivityToolbarButton, StopButton 31 from sugar3.graphics.toolbarbox import ToolbarBox, ToolbarButton 39 32 40 33 from implodegame import ImplodeGame 41 34 from helpwidget import HelpWidget 42 35 43 36 import os 44 37 45 try: 46 import json 47 json.dumps 48 except (ImportError, AttributeError): 49 import simplejson as json 38 import json 50 39 from StringIO import StringIO 51 import gtk 52 import gobject 40 from gi.repository import Gtk 41 from gi.repository import GObject 42 from gi.repository import Gdk 53 43 54 44 from keymap import KEY_MAP 55 45 … … class ImplodeActivity(Activity): 63 53 64 54 self._game = ImplodeGame() 65 55 66 game_box = gtk.VBox()67 game_box.pack_start(self._game )56 game_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) 57 game_box.pack_start(self._game, True, True, 0) 68 58 self._stuck_strip = _StuckStrip() 69 59 70 60 self._configure_toolbars() … … class ImplodeActivity(Activity): 73 63 74 64 # Show everything except the stuck strip. 75 65 self.show_all() 76 game_box.pack_end(self._stuck_strip, expand=False )66 game_box.pack_end(self._stuck_strip, expand=False, fill=False, padding=0) 77 67 78 68 self._game.connect('show-stuck', self._show_stuck_cb) 79 69 self._stuck_strip.connect('undo-clicked', self._stuck_undo_cb) … … class ImplodeActivity(Activity): 96 86 file_data = json.load(io) 97 87 f.close() 98 88 99 print file_data100 _logger.debug(file_data)89 # print file_data 90 # _logger.debug(file_data) 101 91 (file_type, version, game_data) = file_data 102 92 if file_type == 'Implode save game' and version <= [1, 0]: 103 93 self._game.set_game_state(game_data) … … class ImplodeActivity(Activity): 121 111 if data: 122 112 self._stuck_strip.show_all() 123 113 else: 124 if self._stuck_strip. focus_child:114 if self._stuck_strip.get_focus_child(): 125 115 self._game.grab_focus() 126 116 self._stuck_strip.hide() 127 117 … … class ImplodeActivity(Activity): 133 123 action = KEY_MAP.get(event.keyval, None) 134 124 if action is None: 135 125 return False 136 if not self._stuck_strip. flags() & gtk.VISIBLE:126 if not self._stuck_strip.get_state_flags() & Gtk.AccelFlags.VISIBLE: 137 127 return True 138 if self._game. focus_child:128 if self._game.get_focus_child(): 139 129 if action == 'down': 140 130 self._stuck_strip.button.grab_focus() 141 131 return True 142 elif self._stuck_strip. focus_child:132 elif self._stuck_strip.get_focus_child(): 143 133 if action == 'up': 144 134 self._game.grab_focus() 145 135 elif action == 'select': … … class ImplodeActivity(Activity): 152 142 controls, difficulty selector, help button, and stop button. All 153 143 callbacks are locally defined.""" 154 144 155 if _USE_OLD_TOOLBARS: 156 toolbox = ActivityToolbox(self) 157 toolbar = gtk.Toolbar() 158 else: 159 toolbar_box = ToolbarBox() 160 toolbar = toolbar_box.toolbar 145 toolbar_box = ToolbarBox() 146 toolbar = toolbar_box.toolbar 161 147 162 163 164 148 activity_button = ActivityToolbarButton(self) 149 toolbar_box.toolbar.insert(activity_button, 0) 150 activity_button.show() 165 151 166 toolbar.add(gtk.SeparatorToolItem())152 toolbar.add(Gtk.SeparatorToolItem()) 167 153 168 154 def add_button(icon_name, tooltip, func): 169 155 def callback(source): … … class ImplodeActivity(Activity): 176 162 add_button('new-game' , _("New") , self._game.new_game) 177 163 add_button('replay-game', _("Replay"), self._game.replay_game) 178 164 179 toolbar.add( gtk.SeparatorToolItem())165 toolbar.add(Gtk.SeparatorToolItem()) 180 166 181 167 add_button('edit-undo' , _("Undo") , self._game.undo) 182 168 add_button('edit-redo' , _("Redo") , self._game.redo) 183 169 184 toolbar.add( gtk.SeparatorToolItem())170 toolbar.add(Gtk.SeparatorToolItem()) 185 171 186 172 self._levels_buttons = [] 187 173 def add_level_button(icon_name, tooltip, numeric_level): … … class ImplodeActivity(Activity): 217 203 # right now, however. 218 204 add_button('help-icon', _("Help"), _help_clicked_cb) 219 205 220 if _USE_OLD_TOOLBARS: 221 toolbox.add_toolbar(_("Game"), toolbar) 222 toolbox.set_current_toolbar(1) 206 stop_button = StopButton(self) 207 stop_button.props.accelerator = '<Ctrl><Shift>Q' 208 toolbar_box.toolbar.insert(stop_button, -1) 209 stop_button.show() 223 210 224 self.set_toolbox(toolbox) 225 toolbox.show() 226 else: 227 stop_button = StopButton(self) 228 stop_button.props.accelerator = '<Ctrl><Shift>Q' 229 toolbar_box.toolbar.insert(stop_button, -1) 230 stop_button.show() 231 232 self.set_toolbar_box(toolbar_box) 233 toolbar_box.show() 211 self.set_toolbar_box(toolbar_box) 212 toolbar_box.show() 234 213 235 214 def _add_expander(self, toolbar, expand=True): 236 215 """Insert a toolbar item which will expand to fill the available 237 216 space.""" 238 separator = gtk.SeparatorToolItem()217 separator = Gtk.SeparatorToolItem() 239 218 separator.props.draw = False 240 219 separator.set_expand(expand) 241 220 toolbar.insert(separator, -1) 242 221 separator.show() 243 222 244 223 245 class _DialogWindow( gtk.Window):224 class _DialogWindow(Gtk.Window): 246 225 # A base class for a modal dialog window. 247 226 def __init__(self, icon_name, title): 248 227 super(_DialogWindow, self).__init__() 249 228 250 229 self.set_border_width(style.LINE_WIDTH) 251 230 offset = style.GRID_CELL_SIZE 252 width = gtk.gdk.screen_width() / 2253 height = gtk.gdk.screen_height() / 2231 width = Gdk.Screen.width() / 2 232 height = Gdk.Screen.height() / 2 254 233 self.set_size_request(width, height) 255 self.set_position( gtk.WIN_POS_CENTER_ALWAYS)234 self.set_position(Gtk.WindowPosition.CENTER_ALWAYS) 256 235 self.set_decorated(False) 257 236 self.set_resizable(False) 258 237 self.set_modal(True) 259 238 260 vbox = gtk.VBox()239 vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) 261 240 self.add(vbox) 262 241 263 242 toolbar = _DialogToolbar(icon_name, title) 264 243 toolbar.connect('stop-clicked', self._stop_clicked_cb) 265 vbox.pack_start(toolbar, False)244 vbox.pack_start(toolbar, expand=False, fill=False, padding=0) 266 245 267 self.content_vbox = gtk.VBox()246 self.content_vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) 268 247 self.content_vbox.set_border_width(style.DEFAULT_SPACING) 269 248 vbox.add(self.content_vbox) 270 249 … … class _DialogWindow(gtk.Window): 274 253 self.destroy() 275 254 276 255 def _realize_cb(self, source): 277 self. window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG)278 self. window.set_accept_focus(True)256 self.set_type_hint(Gdk.WindowTypeHint.DIALOG) 257 self.get_window().set_accept_focus(True) 279 258 280 259 281 260 class _HelpWindow(_DialogWindow): … … class _HelpWindow(_DialogWindow): 284 263 super(_HelpWindow, self).__init__('help-icon', _("Help")) 285 264 286 265 offset = style.GRID_CELL_SIZE 287 width = gtk.gdk.screen_width() - offset * 2288 height = gtk.gdk.screen_height() - offset * 2266 width = Gdk.Screen.width() - offset * 2 267 height = Gdk.Screen.height() - offset * 2 289 268 self.set_size_request(width, height) 290 269 291 270 self._help_widget = HelpWidget(self._icon_file) 292 self.content_vbox.pack_start(self._help_widget )271 self.content_vbox.pack_start(self._help_widget, True, True, 0) 293 272 294 273 self._help_nav_bar = _HelpNavBar() 295 self.content_vbox.pack_end(self._help_nav_bar, 296 expand=False, 297 padding=style.DEFAULT_SPACING) 274 self.content_vbox.pack_end(self._help_nav_bar, expand=False, 275 fill=False, padding=style.DEFAULT_SPACING) 298 276 299 277 for (signal_name, callback) in [ 300 278 ('forward-clicked', self._forward_clicked_cb), … … class _HelpWindow(_DialogWindow): 316 294 self._help_widget.replay_stage() 317 295 318 296 def _icon_file(self, icon_name): 319 theme = gtk.icon_theme_get_default()297 theme = Gtk.IconTheme.get_default() 320 298 info = theme.lookup_icon(icon_name, 0, 0) 321 299 return info.get_filename() 322 300 … … class _HelpWindow(_DialogWindow): 326 304 self._help_nav_bar.set_can_next_stage(hw.can_next_stage()) 327 305 328 306 329 class _DialogToolbar( gtk.Toolbar):307 class _DialogToolbar(Gtk.Toolbar): 330 308 # Displays a dialog window's toolbar, with title, icon, and close box. 331 309 __gsignals__ = { 332 'stop-clicked' : ( gobject.SIGNAL_RUN_LAST, None, ()),310 'stop-clicked' : (GObject.SignalFlags.RUN_LAST, None, ()), 333 311 } 334 312 def __init__(self, icon_name, title): 335 313 super(_DialogToolbar, self).__init__() 336 314 337 315 icon = Icon() 338 icon.set_from_icon_name(icon_name, gtk.ICON_SIZE_LARGE_TOOLBAR)316 icon.set_from_icon_name(icon_name, Gtk.IconSize.LARGE_TOOLBAR) 339 317 self._add_widget(icon) 340 318 341 319 self._add_separator() 342 320 343 label = gtk.Label(title)321 label = Gtk.Label(label=title) 344 322 self._add_widget(label) 345 323 346 324 self._add_separator(expand=True) … … class _DialogToolbar(gtk.Toolbar): 351 329 self.add(stop) 352 330 353 331 def _add_separator(self, expand=False): 354 separator = gtk.SeparatorToolItem()332 separator = Gtk.SeparatorToolItem() 355 333 separator.set_expand(expand) 356 334 separator.set_draw(False) 357 335 self.add(separator) 358 336 359 337 def _add_widget(self, widget): 360 tool_item = gtk.ToolItem()338 tool_item = Gtk.ToolItem() 361 339 tool_item.add(widget) 362 340 self.add(tool_item) 363 341 … … class _DialogToolbar(gtk.Toolbar): 365 343 self.emit('stop-clicked') 366 344 367 345 368 class _HelpNavBar( gtk.HButtonBox):346 class _HelpNavBar(Gtk.HButtonBox): 369 347 # A widget to display the navigation controls at the bottom of the help 370 348 # dialog. 371 349 __gsignals__ = { 372 'forward-clicked' : ( gobject.SIGNAL_RUN_LAST, None, ()),373 'back-clicked' : ( gobject.SIGNAL_RUN_LAST, None, ()),374 'reload-clicked' : ( gobject.SIGNAL_RUN_LAST, None, ()),350 'forward-clicked' : (GObject.SignalFlags.RUN_LAST, None, ()), 351 'back-clicked' : (GObject.SignalFlags.RUN_LAST, None, ()), 352 'reload-clicked' : (GObject.SignalFlags.RUN_LAST, None, ()), 375 353 } 376 354 377 355 def __init__(self): 378 356 super(_HelpNavBar, self).__init__() 379 357 380 self.set_layout( gtk.BUTTONBOX_SPREAD)358 self.set_layout(Gtk.ButtonBoxStyle.SPREAD) 381 359 382 360 def add_button(icon_name, tooltip, signal_name): 383 361 icon = Icon() 384 icon.set_from_icon_name(icon_name, gtk.ICON_SIZE_LARGE_TOOLBAR)385 button = gtk.Button()362 icon.set_from_icon_name(icon_name, Gtk.IconSize.LARGE_TOOLBAR) 363 button = Gtk.Button() 386 364 button.set_image(icon) 387 365 button.set_tooltip_text(tooltip) 388 366 self.add(button) … … class _HelpNavBar(gtk.HButtonBox): 404 382 self._forward_button.set_sensitive(can_next_stage) 405 383 406 384 407 class _StuckStrip( gtk.HBox):385 class _StuckStrip(Gtk.Box): 408 386 __gsignals__ = { 409 'undo-clicked' : ( gobject.SIGNAL_RUN_LAST, None, ()),387 'undo-clicked' : (GObject.SignalFlags.RUN_LAST, None, ()), 410 388 } 411 389 def __init__(self, *args, **kwargs): 412 390 super(_StuckStrip, self).__init__(*args, **kwargs) 413 391 414 spacer1 = gtk.Label('') 415 self.pack_start(spacer1, expand=True) 392 self.orientation = Gtk.Orientation.HORIZONTAL 393 394 spacer1 = Gtk.Label(label='') 395 self.pack_start(spacer1, True, True, 0) 416 396 417 spacer2 = gtk.Label('')418 self.pack_end(spacer2, expand=True )397 spacer2 = Gtk.Label(label='') 398 self.pack_end(spacer2, expand=True, fill=False, padding=0) 419 399 420 400 self.set_spacing(10) 421 401 422 402 self.set_border_width(10) 423 403 424 label = gtk.Label(_("Stuck? You can still solve the puzzle."))425 self.pack_start(label, expand=False)404 label = Gtk.Label(label=_("Stuck? You can still solve the puzzle.")) 405 self.pack_start(label, False, True, 0) 426 406 427 407 icon = Icon() 428 icon.set_from_icon_name('edit-undo', gtk.ICON_SIZE_LARGE_TOOLBAR)429 self.button = gtk.Button(stock=gtk.STOCK_UNDO)408 icon.set_from_icon_name('edit-undo', Gtk.IconSize.LARGE_TOOLBAR) 409 self.button = Gtk.Button(stock=Gtk.STOCK_UNDO) 430 410 self.button.set_image(icon) 431 411 self.button.set_label(_("Undo some moves")) 432 self.pack_end(self.button, expand=False )412 self.pack_end(self.button, expand=False, fill=False, padding=0) 433 413 434 414 def callback(source): 435 415 self.emit('undo-clicked') -
implodegame.py
diff --git a/implodegame.py b/implodegame.py index 60c507c..7841d69 100644
a b _logger = logging.getLogger('implode-activity.implodegame') 21 21 22 22 from gettext import gettext as _ 23 23 24 import gtk25 import gobject24 from gi.repository import Gtk 25 from gi.repository import GObject 26 26 import random 27 27 import time 28 28 … … _STUCK_DELAY = 0.5 39 39 # state after the player gets stuck, in seconds. 40 40 _UNDO_DELAY = 0.3 41 41 42 class ImplodeGame( gtk.EventBox):42 class ImplodeGame(Gtk.EventBox): 43 43 """Gtk widget for playing the implode game.""" 44 44 45 45 __gsignals__ = { 46 'show-stuck': ( gobject.SIGNAL_RUN_LAST, None, (int,)),46 'show-stuck': (GObject.SignalFlags.RUN_LAST, None, (int,)), 47 47 } 48 48 49 49 def __init__(self, *args, **kwargs): -
keymap.py
diff --git a/keymap.py b/keymap.py index b420ace..0322b22 100644
a b 16 16 # along with this program; if not, write to the Free Software 17 17 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 18 19 import gtk19 from gi.repository import Gdk 20 20 21 21 KEY_MAP = { 22 gtk.keysyms.KP_Up : 'up',23 gtk.keysyms.KP_Down : 'down',24 gtk.keysyms.KP_Left : 'left',25 gtk.keysyms.KP_Right : 'right',26 27 gtk.keysyms.w : 'up',28 gtk.keysyms.s : 'down',29 gtk.keysyms.a : 'left',30 gtk.keysyms.d : 'right',31 32 gtk.keysyms.KP_8 : 'up',33 gtk.keysyms.KP_2 : 'down',34 gtk.keysyms.KP_4 : 'left',35 gtk.keysyms.KP_6 : 'right',36 37 gtk.keysyms.Up : 'up',38 gtk.keysyms.Down : 'down',39 gtk.keysyms.Left : 'left',40 gtk.keysyms.Right : 'right',41 42 gtk.keysyms.uparrow : 'up',43 gtk.keysyms.downarrow : 'down',44 gtk.keysyms.leftarrow : 'left',45 gtk.keysyms.rightarrow : 'right',46 47 gtk.keysyms.Return : 'select',48 gtk.keysyms.KP_Space : 'select',49 gtk.keysyms.KP_Enter : 'select',50 gtk.keysyms.space : 'select',51 gtk.keysyms.End : 'select',52 gtk.keysyms.KP_End : 'select',53 gtk.keysyms.KP_1 : 'select',54 gtk.keysyms.q : 'select',55 56 gtk.keysyms.Home : 'new',57 gtk.keysyms.KP_Home : 'new',58 gtk.keysyms.Page_Down : 'redo',59 gtk.keysyms.KP_Page_Down : 'redo',60 gtk.keysyms.Page_Up : 'undo',61 gtk.keysyms.KP_Page_Up : 'undo',22 Gdk.KEY_KP_Up : 'up', 23 Gdk.KEY_KP_Down : 'down', 24 Gdk.KEY_KP_Left : 'left', 25 Gdk.KEY_KP_Right : 'right', 26 27 Gdk.KEY_w : 'up', 28 Gdk.KEY_s : 'down', 29 Gdk.KEY_a : 'left', 30 Gdk.KEY_d : 'right', 31 32 Gdk.KEY_KP_8 : 'up', 33 Gdk.KEY_KP_2 : 'down', 34 Gdk.KEY_KP_4 : 'left', 35 Gdk.KEY_KP_6 : 'right', 36 37 Gdk.KEY_Up : 'up', 38 Gdk.KEY_Down : 'down', 39 Gdk.KEY_Left : 'left', 40 Gdk.KEY_Right : 'right', 41 42 Gdk.KEY_uparrow : 'up', 43 Gdk.KEY_downarrow : 'down', 44 Gdk.KEY_leftarrow : 'left', 45 Gdk.KEY_rightarrow : 'right', 46 47 Gdk.KEY_Return : 'select', 48 Gdk.KEY_KP_Space : 'select', 49 Gdk.KEY_KP_Enter : 'select', 50 Gdk.KEY_space : 'select', 51 Gdk.KEY_End : 'select', 52 Gdk.KEY_KP_End : 'select', 53 Gdk.KEY_KP_1 : 'select', 54 Gdk.KEY_q : 'select', 55 56 Gdk.KEY_Home : 'new', 57 Gdk.KEY_KP_Home : 'new', 58 Gdk.KEY_Page_Down : 'redo', 59 Gdk.KEY_KP_Page_Down : 'redo', 60 Gdk.KEY_Page_Up : 'undo', 61 Gdk.KEY_KP_Page_Up : 'undo', 62 62 } -
setup.py
diff --git a/setup.py b/setup.py index 211f104..cbdf097 100644
a b 1 1 #!/usr/bin/env python 2 2 3 from sugar .activity import bundlebuilder3 from sugar3.activity import bundlebuilder 4 4 if __name__ == "__main__": 5 5 bundlebuilder.start()