# -*- coding: utf-8 -*- # # 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. # # 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 logging logger = logging.getLogger('hnd') import os import subprocess from gi.repository import Gtk from gi.repository import GdkPixbuf from gi.repository import WebKit from sugar3.activity import activity from sugar3.activity.widgets import StopButton from sugar3.activity.widgets import ActivityToolbarButton from sugar3.graphics.toolbarbox import ToolbarBox from sugar3.graphics.toolbutton import ToolButton from sugar3.graphics.combobox import ComboBox from sugar3.graphics import style RUNSERVER = os.path.join(os.environ['SUGAR_BUNDLE_PATH'], 'runserver.sh') SERVERDIR = os.path.join(os.environ['SUGAR_BUNDLE_PATH'], 'hnd_webapp') IMAGESDIR = os.path.join(SERVERDIR, 'images') subprocess.Popen([RUNSERVER, SERVERDIR]) ACTIVITIES_URL = 'http://0.0.0.0:8000/lesson.html?name=' grades = [('Tercer grado', [('unidad2', 'Perpendicularidad'), ('unidad3', 'Adición'), ('unidad4', 'Sustracción'), ('unidad11', 'Longitud'), ('unidad12', 'Operaciones combinadas'), ('unidad13', 'Peso'), ('unidad14', 'Simetría'), ('unidad17', 'Moneda'), ('tiempo', 'Tiempo')]), ('Cuarto grado', [('cuadrilateros', 'Cuadriláteros'), ('M010407decimales_4g', 'Decimales'), ('M020407longitud_4grado', 'Longitud'), ('M080407elementos', 'Sólidos geométricos'), ('4_moneda', 'Moneda'), ('Hora_y_tiempo', 'Hora y tiempo'), ('4_peso', 'Peso'), ('M010408capacidad', 'La ruleta del saber')]), ('Quinto Grado', [('5u1', 'Potencias'), ('5u2', 'Ángulos'), ('5u3', 'Múltiplos'), ('5u4', 'Superficies'), ('U5', 'Fracciones'), ('5u6', 'Gráficas lineares'), ('5U7', 'Decimales'), ('5U9', 'Áreas'), ('5u10', 'Círculos y circunferencias')]), ('Sexto grado', [('U6', 'Sólidos geométricos'), ('U7', 'Multiplicación y división de fracciones'), ('M010607_volumen6', 'Volumen'), ('mayas', 'Sistema de numeración maya'), ('U10', 'Calendario maya')]), ('Otras', [('sintaxis', 'Sintáxis'), ('tom_sawlyer', 'Tom Sawlyer')]) ] class UnitBrowser(activity.Activity): buffers = {} def __init__(self, handle): activity.Activity.__init__(self, handle, True) self.max_participants = 1 self._wait_for_complete = False # Toolbar toolbarbox = ToolbarBox() activity_button = ActivityToolbarButton(self) toolbarbox.toolbar.insert(activity_button, 0) separator = Gtk.SeparatorToolItem() toolbarbox.toolbar.insert(separator, -1) self.combobox = ComboBox() self.combobox.connect('changed', self._combo_changed) self.combobox.show() item = Gtk.ToolItem() item.add(self.combobox) item.show() toolbarbox.toolbar.insert(item, -1) separator = Gtk.SeparatorToolItem() separator.props.draw = False toolbarbox.toolbar.insert(separator, -1) self._show_activities_btn = ToolButton() self._show_activities_btn.set_tooltip('Ver lista de Unidades') self._show_activities_btn.props.icon_name = 'activities-list' self._show_activities_btn.connect('clicked', self._show_activities_list) toolbarbox.toolbar.insert(self._show_activities_btn, -1) separator = Gtk.SeparatorToolItem() separator.set_expand(True) separator.set_draw(False) toolbarbox.toolbar.insert(separator, -1) stopbtn = StopButton(self) toolbarbox.toolbar.insert(stopbtn, -1) self.set_toolbar_box(toolbarbox) # Canvas self._notebook = Gtk.Notebook() self._notebook.set_show_tabs(False) self._iconview = Gtk.IconView() self.load_buffers() self.combobox.set_active(0) scrollwnd = Gtk.ScrolledWindow() scrollwnd.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) self._iconview.set_model(self.buffers['Tercer grado']) self._iconview.set_markup_column(0) self._iconview.set_pixbuf_column(1) self._iconview.connect('selection-changed', self._select_fn) scrollwnd.add(self._iconview) self._notebook.append_page(scrollwnd, Gtk.Label()) self._browser = WebKit.WebView() self._browser.connect('load-finished', self._load_finished_cb) self._browser.set_full_content_zoom(True) self._browser.set_zoom_level( self._browser.get_zoom_level() + 0.3) self._notebook.append_page(self._browser, Gtk.Label()) self.set_canvas(self._notebook) self.show_all() self._show_activities_list() def _show_activities_list(self, *args): self._notebook.set_current_page(0) self._show_activities_btn.set_sensitive(False) self.combobox.set_sensitive(True) def _combo_changed(self, widget): active = widget.get_active_item() logger.warning(active[0]) self._iconview.set_model(self.buffers[active[0]]) def read_file(self, file_path): return def write_file(self, file_path): return def load_buffers(self): for i in grades: grade_buffer = Gtk.ListStore(str, GdkPixbuf.Pixbuf, str) for lesson in i[1]: imagepath = os.path.join(IMAGESDIR, lesson[0], 'portada.gif') if os.path.exists(imagepath): image = GdkPixbuf.Pixbuf.new_from_file_at_size( imagepath, style.XLARGE_ICON_SIZE * 1.5, style.XLARGE_ICON_SIZE * 1.5) else: # We don't found the image image = GdkPixbuf.Pixbuf.new_from_file_at_size( 'icons/activities-list.svg', style.XLARGE_ICON_SIZE * 1.5, style.XLARGE_ICON_SIZE * 1.5) name = lesson[1] grade_buffer.append(['%s' % name, image, lesson[0]]) logger.debug(i[0]) self.buffers[i[0]] = grade_buffer self.combobox.append_item(i[0], i[0]) def _select_fn(self, widget): self.combobox.set_sensitive(False) self._show_activities_btn.set_sensitive(True) iter_ = widget.get_model().get_iter(widget.get_selected_items()[0]) unit = widget.get_model().get(iter_, 2)[0] self._browser.open(ACTIVITIES_URL + unit) self._wait_for_complete = True def _load_finished_cb(self, widget, frame): if widget.props.uri.endswith('index.html'): self._show_activities_list() else: if self._wait_for_complete: self._notebook.set_current_page(1) self._wait_for_complete = False