Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/activity.py
diff options
context:
space:
mode:
authorAleksey Lim <alsroot@member.fsf.org>2009-02-09 11:54:18 (GMT)
committer Aleksey Lim <alsroot@member.fsf.org>2009-02-09 11:54:18 (GMT)
commit3d3c113d02936f990e314c53be20d1af76c43a7c (patch)
tree5603fead50119a069d40d610041980479e1c7862 /activity.py
parent233c7bfbaafb73816af3404625fe909e7f067d15 (diff)
Merge screen_resolution_independent branch
- total refactoring of code; - support various screen resolutions; - use jobjects for characters, backgrounds and sounds; - add collaboration code
Diffstat (limited to 'activity.py')
-rw-r--r--activity.py164
1 files changed, 164 insertions, 0 deletions
diff --git a/activity.py b/activity.py
new file mode 100644
index 0000000..7832114
--- /dev/null
+++ b/activity.py
@@ -0,0 +1,164 @@
+# 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 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# 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 gettext import gettext as _
+
+from sugar.graphics.toolbutton import ToolButton
+from sugar.graphics.toggletoolbutton import ToggleToolButton
+from sugar.activity.activity import ActivityToolbox
+
+import montage
+import lessons
+import document
+import char
+import ground
+import sound
+from shared import SharedActivity
+from messenger import Messenger, SERVICE
+from utils import *
+
+class CartoonBuilderActivity(SharedActivity):
+ def __init__(self, handle):
+ self.notebook = gtk.Notebook()
+ SharedActivity.__init__(self, self.notebook, SERVICE, handle)
+
+ self.connect('init', self._init_cb)
+ self.connect('tube', self._tube_cb)
+
+ self.notebook.show()
+ self.notebook.props.show_border = False
+ self.notebook.props.show_tabs = False
+
+ self.montage = montage.View()
+ self.notebook.append_page(self.montage)
+ self.lessons = lessons.View()
+ self.lessons.show()
+ self.notebook.append_page(self.lessons)
+
+ toolbox = ActivityToolbox(self)
+ toolbox.show()
+ toolbox.connect('current-toolbar-changed', self._toolbar_changed_cb)
+ self.set_toolbox(toolbox)
+
+ montage_bar = MontageToolbar()
+ montage_bar.show()
+ toolbox.add_toolbar(_('Montage'), montage_bar)
+
+ lessons_bar = LessonsToolbar()
+ lessons_bar.show()
+ toolbox.add_toolbar(_('Lessons'), lessons_bar)
+
+ toolbox.set_current_toolbar(1)
+
+ def read_file(self, filepath):
+ document.load(filepath)
+ char.load()
+ ground.load()
+ sound.load()
+
+ def write_file(self, filepath):
+ document.save(filepath)
+
+ def _init_cb(self, widget):
+ self.montage.restore()
+
+ def _tube_cb(self, activity, tube_conn, initiating):
+ self.messenger = Messenger(tube_conn, initiating, self.montage)
+
+ def _toolbar_changed_cb(self, widget, index):
+ if index == 2:
+ self.notebook.set_current_page(1)
+ else:
+ self.notebook.set_current_page(0)
+
+class MontageToolbar(gtk.Toolbar):
+ def __init__(self):
+ gtk.Toolbar.__init__(self)
+
+ self.playButton = ToggleToolButton('media-playback-start')
+ self.playButton.connect('toggled', self._play_cb)
+ self.insert(self.playButton, -1)
+ self.playButton.set_tooltip(_('Play / Pause'))
+
+ # Play button Image
+ self.playButtonImg = gtk.Image()
+ self.playButtonImg.show()
+ self.playButtonImg.set_from_icon_name('media-playback-start', gtk.ICON_SIZE_LARGE_TOOLBAR)
+
+ # Pause button Image
+ self.pauseButtonImg = gtk.Image()
+ self.pauseButtonImg.show()
+ self.pauseButtonImg.set_from_icon_name('media-playback-pause', gtk.ICON_SIZE_LARGE_TOOLBAR)
+
+ tempo = TempoSlider(0, 10)
+ tempo.adjustment.connect("value-changed", self._tempo_cb)
+ tempo.set_size_request(250, -1)
+ tempo.set_value(5)
+ tempo_item = gtk.ToolItem()
+ tempo_item.add(tempo)
+ self.insert(tempo_item, -1)
+
+ separator = gtk.SeparatorToolItem()
+ self.insert(separator,-1)
+
+ clear_tape = ToolButton('sl-reset')
+ clear_tape.connect('clicked', self._clear_tape_cb)
+ clear_tape.set_tooltip(_('Reset'))
+ self.insert(clear_tape, -1)
+
+ self.show_all()
+
+ def _clear_tape_cb(self, widget):
+ montage.clear_tape()
+
+ def _tempo_cb(self, widget):
+ montage.set_tempo(widget.value)
+
+ def _play_cb(self, widget):
+ if widget.get_active():
+ widget.set_icon_widget(self.pauseButtonImg)
+ sound.play()
+ montage.play()
+ else:
+ widget.set_icon_widget(self.playButtonImg)
+ sound.stop()
+ montage.stop()
+
+class LessonsToolbar(gtk.Toolbar):
+ def __init__(self):
+ gtk.Toolbar.__init__(self)
+ self._mask = False
+
+ for lesson in lessons.THEMES:
+ button = gtk.ToggleToolButton()
+ button.set_label(lesson.name)
+ button.connect('clicked', self._lessons_cb, lesson)
+ self.insert(button, -1)
+
+ self.get_nth_item(0).set_active(True)
+ self.show_all()
+
+ def _lessons_cb(self, widget, lesson):
+ if self._mask:
+ return
+ self._mask = True
+
+ for i, j in enumerate(lessons.THEMES):
+ if j != lesson:
+ self.get_nth_item(i).set_active(False)
+
+ widget.props.active = True
+ lesson.change()
+ self._mask = False