diff options
author | Agustin Zubiaga <aguz@sugarlabs.org> | 2012-12-28 04:33:25 (GMT) |
---|---|---|
committer | Agustin Zubiaga <aguz@sugarlabs.org> | 2012-12-28 04:33:25 (GMT) |
commit | 6963aafc04dede116505cd4f236b6b97642a68ce (patch) | |
tree | 074b35fd64f48f2b5230de5539445e2ae93b0e3d | |
parent | c39a7d7b85600f294c023e0267fee8e2e0fa704b (diff) |
Utilizando iconview en lugar de treeview
-rw-r--r-- | activity.py | 93 | ||||
-rw-r--r-- | icons/activities-list.svg | 101 |
2 files changed, 163 insertions, 31 deletions
diff --git a/activity.py b/activity.py index eb53983..21510da 100644 --- a/activity.py +++ b/activity.py @@ -21,18 +21,21 @@ 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', @@ -81,6 +84,9 @@ class HNDViewer(activity.Activity): 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() @@ -90,6 +96,17 @@ class HNDViewer(activity.Activity): 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) @@ -100,48 +117,44 @@ class HNDViewer(activity.Activity): self.set_toolbar_box(toolbarbox) # Canvas - paned = Gtk.Paned() - paned.set_orientation(Gtk.Orientation.HORIZONTAL) - - self._treeview = Gtk.TreeView() - column = Gtk.TreeViewColumn('Unidades') - cellrenderer = Gtk.CellRendererText() - column.pack_start(cellrenderer, True) - self._treeview.append_column(column) - column.add_attribute(cellrenderer, 'text', 1) + self._notebook = Gtk.Notebook() + self._notebook.set_show_tabs(False) + + self._iconview = Gtk.IconView() self.load_buffers() self.combobox.set_active(0) - self._treeview.set_model(self.buffers['Tercer grado']) - self._treeview.show() - paned.pack1(self._treeview) + scrollwnd = Gtk.ScrolledWindow() + scrollwnd.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) - # When selecting a Unit - self._selection = self._treeview.get_selection() - self._selection.set_select_function(self._select_fn, None) + 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.set_full_content_zoom(True) - self._browser.set_zoom_level( + self._browser.set_zoom_level( self._browser.get_zoom_level() + 0.3) - paned.pack2(self._browser) + self._notebook.append_page(self._browser, Gtk.Label()) - paned.show() - self.set_canvas(paned) - - # TODO: Create a IconView - # iconview = Gtk.IconView() - # self._notebook.append_page(iconview) - -# self._browser.open('http://www.google.com.uy/') + 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._treeview.set_model(self.buffers[active[0]]) + self._iconview.set_model(self.buffers[active[0]]) def read_file(self, file_path): return @@ -151,13 +164,31 @@ class HNDViewer(activity.Activity): def load_buffers(self): for i in grades: - grade_buffer = Gtk.ListStore(str, str) + grade_buffer = Gtk.ListStore(str, GdkPixbuf.Pixbuf, str) for lesson in i[1]: - grade_buffer.append(lesson) + 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 * 2, + style.XLARGE_ICON_SIZE * 2) + else: + # We don't found the image + image = GdkPixbuf.Pixbuf.new_from_file_at_size( + '/home/aguz/hey.png', + style.XLARGE_ICON_SIZE * 2, + style.XLARGE_ICON_SIZE * 2) + + grade_buffer.append(['<b>%s</b>' % lesson[1], image, lesson[0]]) self.buffers[i[0]] = grade_buffer self.combobox.append_item(i[0], i[0]) - def _select_fn(self, selection, model, path, currently_selected, data): - unit = model.get_value(model.get_iter(path), 0) + def _select_fn(self, widget): + self._notebook.set_current_page(1) + 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) return True + diff --git a/icons/activities-list.svg b/icons/activities-list.svg new file mode 100644 index 0000000..48c53bd --- /dev/null +++ b/icons/activities-list.svg @@ -0,0 +1,101 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> + +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:xlink="http://www.w3.org/1999/xlink" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + version="1.1" + width="55" + height="55" + viewBox="0 0 55 55" + id="svg2" + xml:space="preserve" + inkscape:version="0.48.3.1 r9886" + sodipodi:docname="activities-list.svg"><sodipodi:namedview + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1" + objecttolerance="10" + gridtolerance="10" + guidetolerance="10" + inkscape:pageopacity="0" + inkscape:pageshadow="2" + inkscape:window-width="1024" + inkscape:window-height="541" + id="namedview5593" + showgrid="false" + inkscape:zoom="4.4363636" + inkscape:cx="27.5" + inkscape:cy="31.671281" + inkscape:window-x="0" + inkscape:window-y="27" + inkscape:window-maximized="1" + inkscape:current-layer="svg2" /><metadata + id="metadata25"><rdf:RDF><cc:Work + rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title /></cc:Work></rdf:RDF></metadata><defs + id="defs33"><linearGradient + inkscape:collect="always" + id="linearGradient6103"><stop + style="stop-color:#ffffff;stop-opacity:1;" + offset="0" + id="stop6105" /><stop + style="stop-color:#ffffff;stop-opacity:0;" + offset="1" + id="stop6107" /></linearGradient> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +<linearGradient + inkscape:collect="always" + xlink:href="#linearGradient6103" + id="linearGradient6113" + x1="-77.199659" + y1="39.804963" + x2="-43.648659" + y2="39.804963" + gradientUnits="userSpaceOnUse" /></defs><path + style="fill:#ffffff;fill-opacity:1;stroke:none" + d="m 7.5193333,53.42547 c -2.012162,-0.589963 -4.297822,-3.099694 -5.11573,-5.617242 -0.762927,-2.348311 -0.851693,-4.831734 -0.771347,-21.580048 0.07084,-14.767395 0.117708,-16.5345771 0.470385,-17.7370942 0.567103,-1.9336426 1.455637,-3.4662098 2.754181,-4.750482 2.060272,-2.037629 0.636613,-1.918213 22.8685867,-1.918213 22.231974,0 20.808315,-0.119416 22.868588,1.918213 1.336538,1.3218505 2.214805,2.8670253 2.768082,4.8700198 0.364891,1.3209948 0.398166,2.9107654 0.398166,19.0234234 0,14.115816 -0.06076,17.826375 -0.308221,18.821722 -0.736378,2.961923 -2.468616,5.454976 -4.568933,6.575642 l -0.983502,0.524768 -19.836065,0.03846 C 16.508989,53.617039 7.9318173,53.546409 7.5193333,53.42547 l 0,0 z M 24.047543,47.209952 c 0.432167,-0.205078 1.056104,-0.788326 1.386525,-1.296107 l 0.600767,-0.92324 0.06968,-6.012494 c 0.07532,-6.499319 -0.02825,-7.364563 -1.023072,-8.546843 -1.086764,-1.291544 -1.369692,-1.332057 -9.302752,-1.332057 -7.9330597,0 -8.2159877,0.04051 -9.3027517,1.332057 -0.994821,1.18228 -1.098392,2.047524 -1.023073,8.546843 l 0.06968,6.012494 0.59835,0.91941 c 1.073904,1.650138 1.141658,1.66188 9.6237317,1.66767 6.533446,0.0045 7.61999,-0.04366 8.302921,-0.367733 z m 23.311541,-0.136125 c 0.421252,-0.279946 0.994143,-0.960762 1.273087,-1.512926 0.489498,-0.968947 0.507173,-1.220994 0.507173,-7.232196 0,-6.083352 -0.0122,-6.251372 -0.524083,-7.221705 -0.32672,-0.619327 -0.85726,-1.183041 -1.408811,-1.496909 -0.865917,-0.492759 -1.042902,-0.503536 -8.323254,-0.506822 -8.439937,-0.0038 -8.456498,-9.02e-4 -9.686877,1.761916 l -0.681976,0.977036 -0.0776,5.428575 c -0.04268,2.985715 -0.01066,5.964342 0.07115,6.619169 0.171129,1.369666 0.816211,2.446729 1.904783,3.180316 0.75426,0.508295 0.824353,0.512537 8.470523,0.512537 7.62729,0 7.718184,-0.0055 8.475888,-0.508991 l 0,0 z M 24.099845,25.727761 c 0.475572,-0.24262 1.105496,-0.825868 1.399831,-1.296107 0.531934,-0.849831 0.535159,-0.895158 0.535159,-7.521035 l 0,-6.666052 -0.599761,-0.9063022 C 24.356161,7.7079197 24.224037,7.6852763 15.78978,7.6852763 c -8.1748677,0 -8.1955057,0.00299 -9.3300877,1.3513631 -0.932299,1.1079736 -1.047908,1.9987356 -1.038705,8.0031456 0.01047,6.830348 0.174687,7.501775 2.130242,8.70971 0.622814,0.384709 1.268956,0.41777 8.1800857,0.418545 7.004992,6.77e-4 7.561341,-0.02848 8.36853,-0.440279 l 0,0 z m 23.410381,-0.197736 c 0.405726,-0.289386 0.963615,-0.94871 1.239754,-1.465166 0.484216,-0.90562 0.502069,-1.159419 0.502069,-7.137779 0,-6.196582 -1.99e-4,-6.199122 -0.563525,-7.1931474 -1.132962,-1.999186 -0.785698,-1.9272965 -9.663333,-2.0004772 l -7.827709,-0.064526 -0.778044,0.5240693 c -0.427925,0.2882381 -1.031631,0.9765985 -1.34157,1.52969 -0.563053,1.0047793 -0.563525,1.0108083 -0.563525,7.2043913 0,5.906493 0.02278,6.241284 0.483187,7.10041 0.552732,1.031412 1.088461,1.568832 1.888251,1.894209 0.346097,0.140802 3.476884,0.209687 8.222825,0.180925 7.63352,-0.04626 7.666862,-0.04853 8.40162,-0.572599 z" + id="path3007" + inkscape:connector-curvature="0" /></svg>
\ No newline at end of file |