Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/XOEditorActivity.py
diff options
context:
space:
mode:
Diffstat (limited to 'XOEditorActivity.py')
-rw-r--r--XOEditorActivity.py148
1 files changed, 66 insertions, 82 deletions
diff --git a/XOEditorActivity.py b/XOEditorActivity.py
index 3358872..11dc180 100644
--- a/XOEditorActivity.py
+++ b/XOEditorActivity.py
@@ -10,24 +10,24 @@
# along with this library; if not, write to the Free Software
# Foundation, 51 Franklin Street, Suite 500 Boston, MA 02110-1335 USA
+from gi.repository import Gtk, Gdk, GConf
-import gtk
-import gconf
-
-from sugar.activity import activity
-from sugar import profile
+from sugar3.activity import activity
+from sugar3 import profile
+client = GConf.Client.get_default()
try:
- from sugar.graphics.toolbarbox import ToolbarBox
+ from sugar3.graphics.toolbarbox import ToolbarBox
_have_toolbox = True
except ImportError:
_have_toolbox = False
if _have_toolbox:
- from sugar.activity.widgets import ActivityToolbarButton
- from sugar.activity.widgets import StopButton
-from sugar.graphics.objectchooser import ObjectChooser
-from sugar.graphics.alert import ConfirmationAlert, NotifyAlert
-from sugar.graphics.xocolor import colors
+ from sugar3.activity.widgets import ActivityToolbarButton
+ from sugar3.activity.widgets import StopButton
+from sugar3.graphics.objectchooser import ObjectChooser
+from sugar3.graphics.colorbutton import ColorToolButton
+from sugar3.graphics.alert import ConfirmationAlert, NotifyAlert
+from sugar3.graphics.xocolor import colors
from toolbar_utils import button_factory, radio_factory, separator_factory
@@ -37,8 +37,6 @@ from game import Game
import logging
_logger = logging.getLogger('xo-editor-activity')
-
-
class XOEditorActivity(activity.Activity):
""" Change the XO colors """
@@ -60,9 +58,9 @@ class XOEditorActivity(activity.Activity):
self._setup_toolbars(_have_toolbox)
# Create a canvas
- canvas = gtk.DrawingArea()
- canvas.set_size_request(gtk.gdk.screen_width(), \
- gtk.gdk.screen_height())
+ canvas = Gtk.DrawingArea()
+ canvas.set_size_request(Gdk.Screen.width(), \
+ Gdk.Screen.height())
self.set_canvas(canvas)
canvas.show()
self.show_all()
@@ -77,53 +75,7 @@ class XOEditorActivity(activity.Activity):
if 'xox' in self.metadata and 'xoy' in self.metadata:
self._game.move_xo_man(int(self.metadata['xox']),
int(self.metadata['xoy']))
-
- def _setup_toolbars(self, have_toolbox):
- """ Setup the toolbars. """
-
- self.max_participants = 1 # No sharing
-
- if have_toolbox:
- toolbox = ToolbarBox()
-
- # Activity toolbar
- activity_button = ActivityToolbarButton(self)
-
- toolbox.toolbar.insert(activity_button, 0)
- activity_button.show()
-
- self.set_toolbar_box(toolbox)
- toolbox.show()
- self.toolbar = toolbox.toolbar
-
- else:
- # Use pre-0.86 toolbar design
- games_toolbar = gtk.Toolbar()
- toolbox = activity.ActivityToolbox(self)
- self.set_toolbox(toolbox)
- toolbox.add_toolbar(_('Game'), games_toolbar)
- toolbox.show()
- toolbox.set_current_toolbar(1)
- self.toolbar = games_toolbar
-
- '''
- _rotate_button = button_factory(
- 'view-refresh', self.toolbar, self._rotate_cb,
- tooltip=_('Rotate colors'))
- '''
-
- if _have_toolbox:
- separator_factory(toolbox.toolbar, True, False)
-
- self._save_colors_button = button_factory(
- 'save-colors', self.toolbar, self._save_colors_cb,
- tooltip=_('Save colors'))
-
- if _have_toolbox:
- stop_button = StopButton(self)
- stop_button.props.accelerator = '<Ctrl>q'
- toolbox.toolbar.insert(stop_button, -1)
- stop_button.show()
+
def _save_colors_cb(self, button=None):
''' Save the new XO colors. '''
@@ -131,39 +83,34 @@ class XOEditorActivity(activity.Activity):
alert = ConfirmationAlert()
alert.props.title = _('Saving colors')
alert.props.msg = _('Do you want to save these colors?')
-
- def _change_colors_alert_response_cb(alert, response_id, self):
- if response_id is gtk.RESPONSE_OK:
- _logger.debug('saving colors')
- self.remove_alert(alert)
- self._confirm_save()
- elif response_id is gtk.RESPONSE_CANCEL:
- _logger.debug('cancel save')
- self.remove_alert(alert)
-
- alert.connect('response', _change_colors_alert_response_cb, self)
- self.add_alert(alert)
- alert.show()
+ def _change_colors_alert_response_cb(alert, response_id, self):
+ if response_id is Gtk.ResponseType.OK:
+ _logger.debug('saving colors')
+ self.remove_alert(alert)
+ self._confirm_save()
+ elif response_id is Gtk.ResponseType.CANCEL:
+ _logger.debug('cancel save')
+ self.remove_alert(alert)
+ alert.connect('response', _change_colors_alert_response_cb, self)
+ self.add_alert(alert)
+ alert.show()
def _confirm_save(self):
''' Called from confirmation alert '''
- client = gconf.client_get_default()
+
client.set_string('/desktop/sugar/user/color', '%s,%s' % (
self._game.colors[0], self._game.colors[1]))
alert = NotifyAlert()
alert.props.title = _('Saving colors')
alert.props.msg = _('A restart is required before your new colors will appear.')
- def _notification_alert_response_cb(alert, response_id, self):
- self.remove_alert(alert)
-
+ def _notification_alert_response_cb(alert, response_id, self):
+ self.remove_alert(alert)
alert.connect('response', _notification_alert_response_cb, self)
self.add_alert(alert)
alert.show()
-
def _rotate_cb(self, button=None):
self._game.rotate()
-
def write_file(self, file_path):
for i in range(len(colors)):
x, y = self._game.get_dot_xy(i)
@@ -173,3 +120,40 @@ class XOEditorActivity(activity.Activity):
x, y = self._game.get_xo_man_xy()
self.metadata['xox'] = str(x)
self.metadata['xoy'] = str(y)
+
+
+ def _setup_toolbars(self, have_toolbox):
+ """ Setup the toolbars. """
+
+ self.max_participants = 1 # No sharing
+
+ if have_toolbox:
+ toolbox = ToolbarBox()
+ # Activity toolbar
+ activity_button = ActivityToolbarButton(self)
+ toolbox.toolbar.insert(activity_button, 0)
+ activity_button.show()
+
+ self.set_toolbar_box(toolbox)
+ toolbox.show()
+ self.toolbar = toolbox.toolbar
+ else:
+ # Use pre-0.86 toolbar design
+ games_toolbar = Gtk.Toolbar()
+ toolbox = activity.ActivityToolbox(self)
+ self.set_toolbox(toolbox)
+ toolbox.add_toolbar(_('Game'), games_toolbar)
+ toolbox.show()
+ toolbox.set_current_toolbar(1)
+ self.toolbar = games_toolbar
+
+ if _have_toolbox:
+ separator_factory(toolbox.toolbar, True, False)
+ self._save_colors_button = button_factory(
+ 'save-colors', self.toolbar, self._save_colors_cb,
+ tooltip=_('Save colors'))
+ if _have_toolbox:
+ stop_button = StopButton(self)
+ stop_button.props.accelerator = '<Ctrl>q'
+ toolbox.toolbar.insert(stop_button, -1)
+ stop_button.show()