Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/PathsActivity.py
diff options
context:
space:
mode:
authorWalter Bender <walter.bender@gmail.com>2011-03-04 20:40:06 (GMT)
committer Walter Bender <walter.bender@gmail.com>2011-03-04 20:40:06 (GMT)
commitc3311778cd7237bdff59f9106eca3dc367737772 (patch)
tree2c677b7ed02e69fbd207ec0f96e74c65e8985357 /PathsActivity.py
new project
Diffstat (limited to 'PathsActivity.py')
-rw-r--r--PathsActivity.py139
1 files changed, 139 insertions, 0 deletions
diff --git a/PathsActivity.py b/PathsActivity.py
new file mode 100644
index 0000000..3e97940
--- /dev/null
+++ b/PathsActivity.py
@@ -0,0 +1,139 @@
+#Copyright (c) 2011 Walter Bender
+
+# 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
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the
+# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+import gtk
+import gobject
+
+import sugar
+from sugar.activity import activity
+try:
+ from sugar.graphics.toolbarbox import ToolbarBox
+ _have_toolbox = True
+except ImportError:
+ _have_toolbox = False
+
+if _have_toolbox:
+ from sugar.bundle.activitybundle import ActivityBundle
+ from sugar.activity.widgets import ActivityToolbarButton
+ from sugar.activity.widgets import StopButton
+ from sugar.graphics.toolbarbox import ToolbarButton
+
+from sugar.graphics.toolbutton import ToolButton
+from sugar.graphics.menuitem import MenuItem
+from sugar.graphics.icon import Icon
+from sugar.datastore import datastore
+
+from gettext import gettext as _
+import locale
+import os.path
+
+from game import Game
+
+SERVICE = 'org.sugarlabs.PathsActivity'
+IFACE = SERVICE
+PATH = '/org/augarlabs/PathsActivity'
+
+
+def _button_factory(icon_name, tooltip, callback, toolbar, cb_arg=None,
+ accelerator=None):
+ """Factory for making toolbar buttons"""
+ my_button = ToolButton(icon_name)
+ my_button.set_tooltip(tooltip)
+ my_button.props.sensitive = True
+ if accelerator is not None:
+ my_button.props.accelerator = accelerator
+ if cb_arg is not None:
+ my_button.connect('clicked', callback, cb_arg)
+ else:
+ my_button.connect('clicked', callback)
+ if hasattr(toolbar, 'insert'): # the main toolbar
+ toolbar.insert(my_button, -1)
+ else: # or a secondary toolbar
+ toolbar.props.page.insert(my_button, -1)
+ my_button.show()
+ return my_button
+
+
+def _label_factory(label, toolbar):
+ """ Factory for adding a label to a toolbar """
+ my_label = gtk.Label(label)
+ my_label.set_line_wrap(True)
+ my_label.show()
+ _toolitem = gtk.ToolItem()
+ _toolitem.add(my_label)
+ toolbar.insert(_toolitem, -1)
+ _toolitem.show()
+ return my_label
+
+
+def _separator_factory(toolbar, visible=True, expand=False):
+ """ Factory for adding a separator to a toolbar """
+ _separator = gtk.SeparatorToolItem()
+ _separator.props.draw = visible
+ _separator.set_expand(expand)
+ toolbar.insert(_separator, -1)
+ _separator.show()
+
+
+class PathsActivity(activity.Activity):
+ """ Path puzzle game """
+
+ def __init__(self, handle):
+ """ Initialize the toolbars and the game board """
+ super(PathsActivity,self).__init__(handle)
+
+ self._setup_toolbars(_have_toolbox)
+
+ # Create a canvas
+ canvas = gtk.DrawingArea()
+ canvas.set_size_request(gtk.gdk.screen_width(), \
+ gtk.gdk.screen_height())
+ self.set_canvas(canvas)
+ canvas.show()
+ self.show_all()
+
+ self.game = Game(canvas, self)
+ self.game.new_game()
+
+ def _setup_toolbars(self, have_toolbox):
+ """ Setup the toolbars.. """
+
+ 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()
+ 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)
+ toolbar = games_toolbar
+
+ if _have_toolbox:
+ _separator_factory(toolbox.toolbar, False, True)
+
+ stop_button = StopButton(self)
+ stop_button.props.accelerator = '<Ctrl>q'
+ toolbox.toolbar.insert(stop_button, -1)
+ stop_button.show()