From a4701d57c5a44fe943d01391dcaeac09df109fdf Mon Sep 17 00:00:00 2001 From: Aleksey Lim Date: Sun, 01 Feb 2009 07:34:25 +0000 Subject: Add lessons --- diff --git a/Activity.py b/Activity.py index 878d427..bfa66a3 100644 --- a/Activity.py +++ b/Activity.py @@ -24,12 +24,13 @@ from gettext import gettext as _ from sugar.activity.activity import get_activity_root -from View import View -from Toolbar import Toolbar +import Montage +import Lessons import Document import Char import Ground import Sound +from Toolbars import * SERVICE = 'org.freedesktop.Telepathy.Tube.Connect' IFACE = SERVICE @@ -41,14 +42,33 @@ class CartoonBuilderActivity(activity.Activity): def __init__(self, handle): activity.Activity.__init__(self,handle) - self.app = View() + self.notebook = gtk.Notebook() + self.notebook.show() + self.notebook.props.show_border = False + self.notebook.props.show_tabs = False + self.notebook.connect_after('map', self._map_cb) + + self.montage = Montage.View() + self.notebook.append_page(self.montage) + self.lessons = Lessons.View() + self.lessons.show() + self.notebook.append_page(self.lessons) + toolbox = activity.ActivityToolbox(self) - bgtoolbar = Toolbar(self,self.app) - toolbox.add_toolbar(_('Background'),bgtoolbar) - bgtoolbar.show() - self.set_toolbox(toolbox) toolbox.show() - self.set_canvas(self.app.main) + 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) + self.set_canvas(self.notebook) """ # mesh stuff @@ -87,6 +107,20 @@ class CartoonBuilderActivity(activity.Activity): def write_file(self, filepath): Document.save(filepath) + def _map_cb(self, widget): + self.montage.restore() + + def _toolbar_changed_cb(self, widget, index): + if index == 2: + self.notebook.set_current_page(1) + else: + self.notebook.set_current_page(0) + + + + + + def _shared_cb(self,activity): self.initiating = True diff --git a/Char.py b/Char.py index 99c634e..d7c9efe 100644 --- a/Char.py +++ b/Char.py @@ -47,7 +47,7 @@ class Char: self._filenames = [] if type != CUSTOM: - for i in sorted(glob.glob(Theme.path(dir + '/*'))): + for i in sorted(glob.glob(Theme.path(dir, '*'))): self._filenames.append(os.path.join(dir, os.path.basename(i))) def filename(self, index): diff --git a/Lessons.py b/Lessons.py new file mode 100644 index 0000000..060db1e --- /dev/null +++ b/Lessons.py @@ -0,0 +1,76 @@ +# 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 os +import gtk +import locale +import logging +from glob import glob + +import Theme + +THEMES = [] + +class Lesson: + def __init__(self, index, filename): + self.index = index + self.name = os.path.splitext(os.path.basename(filename).lstrip( + '.-_1234567890').replace('_', ' '))[0] + self.text = file(filename, 'r').read() + + def change(self): + View.notebook.set_current_page(self.index) + +class View(gtk.EventBox): + notebook = None + + def __init__(self): + gtk.EventBox.__init__(self) + + View.notebook = gtk.Notebook() + View.notebook.props.show_border = False + View.notebook.props.show_tabs = False + self.add(View.notebook) + + for i in THEMES: + view = gtk.TextView() + view.get_buffer().set_text(i.text) + view.set_wrap_mode(gtk.WRAP_WORD) + view.set_editable(False) + + view_box = gtk.EventBox() + view_box.add(view) + view_box.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(Theme.WHITE)) + view_box.props.border_width = 10 + + border_box = gtk.EventBox() + border_box.add(view_box) + border_box.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(Theme.WHITE)) + + scrolled_window = gtk.ScrolledWindow() + scrolled_window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) + scrolled_window.add_with_viewport(border_box) + + View.notebook.append_page(scrolled_window) + + self.show_all() + +_lang = locale.getdefaultlocale()[0].split('_')[0] + +if not os.path.isdir(Theme.path('lessons', _lang)): + logging.info('Cannot find lessons for language %s, thus use en' % _lang) + _lang = 'en' + +for i, filename in enumerate(sorted(glob(Theme.path('lessons', _lang, '*')))): + THEMES.append(Lesson(i, filename)) diff --git a/View.py b/Montage.py index 15ddc76..e9608c1 100644 --- a/View.py +++ b/Montage.py @@ -18,13 +18,8 @@ ### author: Ed Stoner (ed@whsd.net) ### (c) 2007 World Wide Workshop Foundation -import time -import pygtk import gtk import gobject -import gettext -import os -import textwrap import Theme import Char @@ -33,47 +28,92 @@ import Sound from Document import Document from Utils import * -class FrameWidget(gtk.DrawingArea): - def __init__(self): - gtk.DrawingArea.__init__(self) - self.gc = None # initialized in realize-event handler - self.width = 0 # updated in size-allocate handler - self.height = 0 # idem - self.bgpixbuf = None - self.fgpixbuf = None - self.connect('size-allocate', self.on_size_allocate) - self.connect('expose-event', self.on_expose_event) - self.connect('realize', self.on_realize) - - def on_realize(self, widget): - self.gc = widget.window.new_gc() - - def on_size_allocate(self, widget, allocation): - self.height = self.width = min(allocation.width, allocation.height) - - def on_expose_event(self, widget, event): - # This is where the drawing takes place - if self.bgpixbuf: - pixbuf = self.bgpixbuf - if pixbuf.get_width != self.width: - pixbuf = Theme.scale(pixbuf, self.width) - widget.window.draw_pixbuf(self.gc, pixbuf, 0, 0, 0, 0, -1, -1, 0, 0) - - if self.fgpixbuf: - pixbuf = self.fgpixbuf - if pixbuf.get_width != self.width: - pixbuf = Theme.scale(pixbuf, self.width) - widget.window.draw_pixbuf(self.gc, pixbuf, 0, 0, 0, 0, -1, -1, 0, 0) - - def draw(self): - self.queue_draw() - -class View: +def play(): + View.play_tape_num = 0 + View.playing = gobject.timeout_add(View.delay, _play_tape) + +def stop(): + View.playing = None + +def set_tempo(tempo): + View.delay = 10 + (10-tempo) * 100 + if View.playing: + gobject.source_remove(View.playing) + View.playing = gobject.timeout_add(View.delay, _play_tape) + +def clear_tape(): + for i in range(TAPE_COUNT): + Document.tape[i].clean() + View.tape[i].child.set_from_pixbuf(Theme.EMPTY_THUMB) + + View.screen.fgpixbuf = Document.tape[View.tape_selected].orig + View.screen.draw() + +def _play_tape(): + if not View.playing: + return False + + View.screen.fgpixbuf = Document.tape[View.play_tape_num].orig + View.screen.draw() + + for i in range(Theme.TAPE_COUNT): + View.play_tape_num += 1 + if View.play_tape_num == TAPE_COUNT: + View.play_tape_num = 0 + if Document.tape[View.play_tape_num].orig == Theme.EMPTY_ORIG: + continue + return True + + stop() + return False + +class View(gtk.EventBox): + class Screen(gtk.DrawingArea): + def __init__(self): + gtk.DrawingArea.__init__(self) + self.gc = None # initialized in realize-event handler + self.width = 0 # updated in size-allocate handler + self.height = 0 # idem + self.bgpixbuf = None + self.fgpixbuf = None + self.connect('size-allocate', self.on_size_allocate) + self.connect('expose-event', self.on_expose_event) + self.connect('realize', self.on_realize) + + def on_realize(self, widget): + self.gc = widget.window.new_gc() + + def on_size_allocate(self, widget, allocation): + self.height = self.width = min(allocation.width, allocation.height) + + def on_expose_event(self, widget, event): + # This is where the drawing takes place + if self.bgpixbuf: + pixbuf = self.bgpixbuf + if pixbuf.get_width != self.width: + pixbuf = Theme.scale(pixbuf, self.width) + widget.window.draw_pixbuf(self.gc, pixbuf, 0, 0, 0, 0, -1, -1, 0, 0) + + if self.fgpixbuf: + pixbuf = self.fgpixbuf + if pixbuf.get_width != self.width: + pixbuf = Theme.scale(pixbuf, self.width) + widget.window.draw_pixbuf(self.gc, pixbuf, 0, 0, 0, 0, -1, -1, 0, 0) + + def draw(self): + self.queue_draw() + + screen = Screen() + play_tape_num = 0 + playing = None + delay = 3*150 + tape_selected = -1 + tape = [] + def __init__(self): - self._playing = None - self.waittime = 3*150 - self.tape = [] - self.frames = [] + gtk.EventBox.__init__(self) + + self._frames = [] self._prev_combo_selected = {} # frames table @@ -88,7 +128,7 @@ class View: for y in range(rows): for x in range(Theme.FRAME_COLS): image = gtk.Image() - self.frames.append(image) + self._frames.append(image) image_box = gtk.EventBox() image_box.set_events(gtk.gdk.BUTTON_PRESS_MASK) @@ -117,7 +157,7 @@ class View: yellow_frames.add(table_frames) yelow_arrow = gtk.Image() - yelow_arrow.set_from_file(Theme.path('icons/yellow_arrow.png')) + yelow_arrow.set_from_file(Theme.path('icons', 'yellow_arrow.png')) frames_box = gtk.VBox() frames_box.pack_start(yellow_frames, True, True) @@ -126,7 +166,6 @@ class View: # screen - self.screen = FrameWidget() screen_pink = gtk.EventBox() screen_pink.modify_bg(gtk.STATE_NORMAL,gtk.gdk.color_parse(PINK)) screen_box = gtk.EventBox() @@ -143,7 +182,7 @@ class View: frame_box = gtk.VBox() filmstrip_pixbuf = gtk.gdk.pixbuf_new_from_file_at_scale( - Theme.path('icons/filmstrip.png'), THUMB_SIZE, -1, False) + Theme.path('icons', 'filmstrip.png'), THUMB_SIZE, -1, False) filmstrip = gtk.Image() filmstrip.set_from_pixbuf(filmstrip_pixbuf); @@ -157,7 +196,7 @@ class View: frame.props.border_width = 2 frame.set_size_request(Theme.THUMB_SIZE, Theme.THUMB_SIZE) frame_box.pack_start(frame) - self.tape.append(frame) + View.tape.append(frame) frame_image = gtk.Image() frame_image.set_from_pixbuf(Theme.EMPTY_THUMB) @@ -169,8 +208,6 @@ class View: tape.pack_start(frame_box, False, False) - self.tape_selected = -1 - # left control box self.controlbox = gtk.VBox() @@ -179,7 +216,7 @@ class View: leftbox = gtk.VBox() logo = gtk.Image() - logo.set_from_file(Theme.path('icons/logo.png')) + logo.set_from_file(Theme.path('icons', 'logo.png')) leftbox.set_size_request(logo.props.pixbuf.get_width(), -1) leftbox.pack_start(logo, False, False) leftbox.pack_start(self.controlbox, True, True) @@ -205,7 +242,7 @@ class View: gtk.gdk.color_parse(BUTTON_BACKGROUND)) arrow = gtk.Image() - arrow.set_from_file(Theme.path('icons/pink_arrow.png')) + arrow.set_from_file(Theme.path('icons', 'pink_arrow.png')) animborder = gtk.EventBox() animborder.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(PINK)) animframe = gtk.EventBox() @@ -228,15 +265,11 @@ class View: greenbox.set_border_width(5) greenbox.add(desktop) - yellowbox = gtk.EventBox() - yellowbox.modify_bg(gtk.STATE_NORMAL,gtk.gdk.color_parse(YELLOW)) - yellowbox.add(greenbox) - yellowbox.show_all() + self.modify_bg(gtk.STATE_NORMAL,gtk.gdk.color_parse(YELLOW)) + self.add(greenbox) + self.show_all() - self.main = yellowbox - yellowbox.connect_after('map', self.restore) - - def restore(self, widget): + def restore(self): def new_combo(themes, cb, selname = None, closure = None): combo = ComboBox() sel = 0 @@ -265,89 +298,52 @@ class View: Document.sound_name, self._sound_cb), True, False) for i in range(Theme.TAPE_COUNT): - self.tape[i].child.set_from_pixbuf(Theme.scale(Document.tape[i].orig)) + View.tape[i].child.set_from_pixbuf(Theme.scale(Document.tape[i].orig)) self._tape_cb(None, None, 0) return False - def play(self): - self.play_tape_num = 0 - self._playing = gobject.timeout_add(self.waittime, self._play_tape) - - def stop(self): - self._playing = None - - def set_tempo(self, tempo): - self.waittime = 10 + (10-tempo) * 100 - if self._playing: - gobject.source_remove(self._playing) - self._playing = gobject.timeout_add(self.waittime, self._play_tape) - - def clear_tape(self): - for i in range(TAPE_COUNT): - Document.tape[i].clean() - self.screen.fgpixbuf = Document.tape[self.tape_selected].orig - self.screen.draw() - - def _play_tape(self): - if not self._playing: - return False - - self.screen.fgpixbuf = Document.tape[self.play_tape_num].orig - self.screen.draw() - - for i in range(Theme.TAPE_COUNT): - self.play_tape_num += 1 - if self.play_tape_num == TAPE_COUNT: - self.play_tape_num = 0 - if Document.tape[self.play_tape_num].orig == Theme.EMPTY_ORIG: - continue - return True - - self.stop() - return False - def _tape_cb(self, widget, event, index): if event and event.button == 3: Document.tape[index].clean() - self.tape[index].child.set_from_pixbuf(Theme.EMPTY_THUMB) + View.tape[index].child.set_from_pixbuf(Theme.EMPTY_THUMB) - tape = self.tape[index] + tape = View.tape[index] tape.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(YELLOW)) tape.modify_bg(gtk.STATE_PRELIGHT, gtk.gdk.color_parse(YELLOW)) - if self.tape_selected != index: - if self.tape_selected != -1: - old_tape = self.tape[self.tape_selected] + if View.tape_selected != index: + if View.tape_selected != -1: + old_tape = View.tape[View.tape_selected] old_tape.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(BLACK)) old_tape.modify_bg(gtk.STATE_PRELIGHT, gtk.gdk.color_parse(BLACK)) - self.tape_selected = index + View.tape_selected = index self.screen.fgpixbuf = Document.tape[index].orig self.screen.draw() def _frame_cb(self, widget, event, frame): if event.button == 3: self.char.clean(frame) - self.frames[frame].set_from_pixbuf(self.char.thumb(frame)) + self._frames[frame].set_from_pixbuf(self.char.thumb(frame)) else: orig = self.char.orig(frame) if not orig: return thumb = self.char.thumb(frame) - Document.tape[self.tape_selected].orig = orig - Document.tape[self.tape_selected].filename = self.char.filename(frame) + Document.tape[View.tape_selected].orig = orig + Document.tape[View.tape_selected].filename = self.char.filename(frame) - self.tape[self.tape_selected].child.set_from_pixbuf(thumb) - self.frames[frame].set_from_pixbuf(thumb) - self._tape_cb(None, None, self.tape_selected) + View.tape[View.tape_selected].child.set_from_pixbuf(thumb) + self._frames[frame].set_from_pixbuf(thumb) + self._tape_cb(None, None, View.tape_selected) def _char_cb(self, widget, closure): self.char = widget.props.value - for i in range(len(self.frames)): - self.frames[i].set_from_pixbuf(self.char.thumb(i)) + for i in range(len(self._frames)): + self._frames[i].set_from_pixbuf(self.char.thumb(i)) def _combo_cb(self, widget, cb): choice = widget.props.value.change() diff --git a/Theme.py b/Theme.py index 55a2073..c3b76f9 100644 --- a/Theme.py +++ b/Theme.py @@ -84,7 +84,9 @@ if os.path.isdir(SESSION_PATH): shutil.rmtree(SESSION_PATH) os.mkdir(SESSION_PATH) -def path(file): +def path(*args): + file = os.path.join(*args) + if os.path.isabs(file): return file else: diff --git a/Toolbar.py b/Toolbar.py deleted file mode 100644 index aedc607..0000000 --- a/Toolbar.py +++ /dev/null @@ -1,160 +0,0 @@ -# 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 os -import gtk -from gettext import gettext as _ - -from sugar.graphics.toolbutton import ToolButton -from sugar.graphics.toggletoolbutton import ToggleToolButton -from sugar.activity.activity import get_bundle_path - -import Sound -from Utils import * - -class Toolbar(gtk.Toolbar): - def __init__(self, activity, view): - gtk.Toolbar.__init__(self) - self.activity = activity - self.view = view - - self.playButton = ToggleToolButton('media-playback-start') - self.playButton.connect('toggled', self._play_cb) - self.insert(self.playButton, -1) - self.playButton.show() - self.playButton.set_tooltip(_('Play / Pause')) - - # Play button Image - self.playButtonImg = gtk.Image() - self.playButtonImg.set_from_icon_name('media-playback-start', gtk.ICON_SIZE_LARGE_TOOLBAR) - self.playButtonImg.show() - - # Pause button Image - self.pauseButtonImg = gtk.Image() - self.pauseButtonImg.set_from_icon_name('media-playback-pause', gtk.ICON_SIZE_LARGE_TOOLBAR) - self.pauseButtonImg.show() - - 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() - separator.set_draw(False) - self.insert(separator,-1) - - clear_tape = ToolButton('sl-reset') - clear_tape.connect('clicked', self._clear_tape_cb) - clear_tape.set_tooltip(_('')) - self.insert(clear_tape, -1) - - self.show_all() - - def _clear_tape_cb(self, widget): - self.view.clear_tape() - - def _tempo_cb(self, widget): - self.view.set_tempo(widget.value) - - def _play_cb(self, widget): - if widget.get_active(): - widget.set_icon_widget(self.pauseButtonImg) - Sound.play() - self.view.play() - else: - widget.set_icon_widget(self.playButtonImg) - Sound.stop() - self.view.stop() - -""" -SPANISH = u'Espa\xf1ol' -#SPANISH = 'Espanol' -LANGLIST = ['English',SPANISH] -LANG = {'English':{'character':'My Character', - 'sound':'My Sound', - 'background':'My Background', - 'lessonplan':'Lesson Plans', - 'lpdir':'lp-en'}, - SPANISH:{'character':u'Mi car\xe1cter', - 'sound':'Mi sonido', - 'background':'Mi fondo', - 'lessonplan':u'Planes de la lecci\xf3n', - 'lpdir':'lp-es'}} - - -def getwrappedfile(filepath,linelength): - text = [] - f = file(filepath) - for line in f: - if line == '\n': - text.append(line) - else: - for wline in textwrap.wrap(line.strip()): - text.append('%s\n' % wline) - return ''.join(text) - - - - - def showlessonplans(self, widget, data=None): - dia = gtk.Dialog(title='Lesson Plans', - parent=None, - flags=0, - buttons=None) - dia.set_default_size(500,500) - dia.show() - - #dia.vbox.pack_start(scrolled_window, True, True, 0) - notebook = gtk.Notebook() - # uncomment below to highlight tabs - notebook.modify_bg(gtk.STATE_NORMAL,gtk.gdk.color_parse(WHITE)) - notebook.set_tab_pos(gtk.POS_TOP) - #notebook.set_default_size(400,400) - notebook.show() - lessonplans = {} - lpdir = os.path.join(self.mdirpath,LANG[self.language]['lpdir']) - lpentries = os.listdir(lpdir) - for entry in lpentries: - fpath = os.path.join(lpdir,entry) - lessonplans[entry] = getwrappedfile(fpath,80) - lpkeys = lessonplans.keys() - lpkeys.sort() - for lpkey in lpkeys: - lpname = lpkey.replace('_',' ').replace('0','')[:-4] - label = gtk.Label(lessonplans[lpkey]) - #if self.insugar: - # label.modify_fg(gtk.STATE_NORMAL,gtk.gdk.color_parse(WHITE)) - eb = gtk.EventBox() - eb.modify_bg(gtk.STATE_NORMAL,gtk.gdk.color_parse(WHITE)) - #label.set_line_wrap(True) - label.show() - eb.add(label) - eb.show() - #tlabel = gtk.Label('Lesson Plan %s' % str(i+1)) - tlabel = gtk.Label(lpname) - tlabel.show() - scrolled_window = gtk.ScrolledWindow() - scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS) - scrolled_window.show() - scrolled_window.add_with_viewport(eb) - notebook.append_page(scrolled_window, tlabel) - #dia.action_area.pack_start(notebook, True, True, 0) - dia.vbox.pack_start(notebook, True, True, 0) - result = dia.run() - dia.destroy() - """ - diff --git a/Toolbars.py b/Toolbars.py new file mode 100644 index 0000000..406cc55 --- /dev/null +++ b/Toolbars.py @@ -0,0 +1,104 @@ +# 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 + +import Montage +import Lessons +import Sound +from Utils import * + +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(_('')) + 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 -- cgit v0.9.1