Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKirk Winans <winansk@penne.union.edu>2010-08-02 19:42:43 (GMT)
committer Kirk Winans <winansk@penne.union.edu>2010-08-02 19:42:43 (GMT)
commit58434112491ef108dfc9d036c43d10cbbc2ba5ff (patch)
treef74e3c9e61df1c41ece2b6d6c3a4bc21d1a15fc2
First import of code.
-rw-r--r--AUTHORS1
-rw-r--r--COPYING12
-rw-r--r--FlashcardActivity.py284
-rw-r--r--MANIFEST17
-rw-r--r--NEWS8
-rw-r--r--activity/Sugar-iconify.py678
-rw-r--r--activity/activity-flashcard.svg22
-rw-r--r--activity/activity.info8
-rw-r--r--browseeditpanel.py235
-rw-r--r--creationpanel.py253
-rw-r--r--flashcarddtd.dtd17
-rw-r--r--icons/pair-update.svg110
-rw-r--r--port/COPYING340
-rw-r--r--port/README18
-rw-r--r--port/__init__.py0
-rw-r--r--port/widgets.py403
-rw-r--r--reviewpanel.py308
-rw-r--r--reviewselection.py161
-rwxr-xr-xsetup.py5
-rw-r--r--testfile.xml51
20 files changed, 2931 insertions, 0 deletions
diff --git a/AUTHORS b/AUTHORS
new file mode 100644
index 0000000..b4efe22
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1 @@
+Kirk Winans - winansk@garnet.union.edu
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..d15f2da
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,12 @@
+Copyright (c) 2010, Kirk Winans
+
+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.
+
diff --git a/FlashcardActivity.py b/FlashcardActivity.py
new file mode 100644
index 0000000..a78ef87
--- /dev/null
+++ b/FlashcardActivity.py
@@ -0,0 +1,284 @@
+# -*- coding: utf-8 -*-
+#Copyright (c) 2010, Kirk Winans
+#Code originally based on Walter Bender's Abacus Activity
+
+# 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 pygtk
+pygtk.require('2.0')
+import gtk
+import gobject
+
+import sugar
+from sugar.activity import activity
+from sugar.bundle.activitybundle import ActivityBundle
+from sugar.activity.widgets import ActivityToolbarButton
+from sugar.activity.widgets import StopButton
+from sugar.graphics.toolbarbox import ToolbarBox
+from sugar.graphics.toolbarbox import ToolbarButton
+from sugar.graphics.toolbutton import ToolButton
+from sugar.graphics import style
+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 logging
+_logger = logging.getLogger("test-activity")
+
+from sugar import profile
+import creationpanel
+import browseeditpanel
+import reviewselection
+import reviewpanel
+
+_REVIEW_MODE = 1
+_CREATE_MODE = 2
+_BROWSE_MODE = 3
+
+_EMPTY = ""
+
+#
+# Sugar Flashcard Activity
+#
+
+class FlashcardActivity(activity.Activity):
+
+ def __init__(self, handle):
+ """ Initiate activity. """
+ super(FlashcardActivity,self).__init__(handle)
+
+ toolbar_box = ToolbarBox()
+
+ # Buttons added to the Activity toolbar
+ activity_button = ActivityToolbarButton(self)
+ toolbar_box.toolbar.insert(activity_button, 0)
+ activity_button.show()
+
+
+ separator = gtk.SeparatorToolItem()
+ separator.props.draw = True
+ separator.set_expand(False)
+ separator.show()
+ toolbar_box.toolbar.insert(separator, -1)
+
+ ## other buttons
+
+ # Review Button
+ self.review_button = ToolButton( "emblem-question" )
+ self.review_button.set_tooltip(_('Review'))
+ self.review_button.props.sensitive = True
+ self.review_button.connect('clicked',self._review_cb)
+ toolbar_box.toolbar.insert(self.review_button, -1)
+ self.review_button.show()
+
+ separator = gtk.SeparatorToolItem()
+ separator.props.draw = True
+ separator.set_expand(False)
+ separator.show()
+ toolbar_box.toolbar.insert(separator, -1)
+
+ # Create Button
+ self.create_button = ToolButton( "add" )
+ self.create_button.set_tooltip(_('Create!'))
+ self.create_button.props.sensitive = True
+ self.create_button.connect('clicked', self._create_cb)
+ toolbar_box.toolbar.insert(self.create_button, -1)
+ self.create_button.show()
+
+ separator = gtk.SeparatorToolItem()
+ separator.props.draw = True
+ separator.set_expand(False)
+ separator.show()
+ toolbar_box.toolbar.insert(separator, -1)
+
+ # Browse/Edit Button
+ self.browse_edit_button = ToolButton( "search" )
+ self.browse_edit_button.set_tooltip(_('Browse/Edit'))
+ self.browse_edit_button.props.sensitive = True
+ self.browse_edit_button.connect('clicked', self._browse_edit_cb)
+ toolbar_box.toolbar.insert(self.browse_edit_button, -1)
+ self.browse_edit_button.show()
+
+ separator = gtk.SeparatorToolItem()
+ separator.props.draw = False
+ separator.set_expand(True)
+ separator.show()
+ toolbar_box.toolbar.insert(separator, -1)
+
+ separator = gtk.SeparatorToolItem()
+ separator.props.draw = True
+ separator.set_expand(False)
+ separator.show()
+ toolbar_box.toolbar.insert(separator, -1)
+
+ # The ever-present Stop Button
+ stop_button = StopButton(self)
+ stop_button.props.accelerator = _('<Ctrl>Q')
+ toolbar_box.toolbar.insert(stop_button, -1)
+ stop_button.show()
+
+ self.set_toolbar_box(toolbar_box)
+ toolbar_box.show()
+
+ self.canvas = gtk.HBox(False)
+ self.set_canvas(self.canvas)
+
+ self.canvas.show()
+ self.show_all()
+ self.mode = 0
+ self.review_mode()
+
+
+ # Places Activity into Review Mode, to review flashcards
+ def review_mode(self):
+
+ self.remove_all()
+
+ self.button_box = gtk.VButtonBox()
+
+ self.reviewpanel = reviewselection.ReviewSelection(
+ self.get_activity_root())
+
+ self.canvas.pack_start(self.reviewpanel, True, True)
+
+ self.reviewpanel.show()
+
+ # Select what to review
+ self._selectbutton = ToolButton(tooltip=_('Select'))
+ self._selectbutton.connect('clicked', self._select_button_cb)
+ self._selectbutton.set_icon_widget(
+ self.make_label('next', ' ' + _('Select')))
+ self.button_box.pack_start(self._selectbutton)
+ self.canvas.pack_start(self.button_box, False)
+ self._selectbutton.show()
+ self.button_box.show()
+
+ self.mode = _REVIEW_MODE
+
+ # Places Activity into Create Mode, parameters are for editing,
+ # otherwise, empty is passes into the method to create a new flashcard
+ def create_mode(self, front, back, catagory, editing):
+
+ self.remove_all()
+
+ self.creationpanel = creationpanel.CreationPanel(
+ self.get_activity_root(), front, back, catagory, editing)
+
+ self.canvas.pack_start(self.creationpanel, True, True)
+
+ self.creationpanel.show()
+ self.canvas.show()
+ self.mode = _CREATE_MODE
+
+ # Places Activity into Browse/Edit Mode, browse through flashcards
+ def browse_edit_mode(self):
+ self.remove_all()
+
+ self.button_box = gtk.VButtonBox()
+
+ self.browseeditpanel = browseeditpanel.BrowseEditPanel(
+ self.get_activity_root())
+
+ self.canvas.pack_start(self.browseeditpanel, True, True)
+ self.browseeditpanel.show()
+
+ # Allows the current flashcard being viewed to be edited
+ self._editbutton = ToolButton(tooltip=_('Edit Card'))
+ self._editbutton.connect('clicked', self._edit_button_cb)
+ self._editbutton.set_icon_widget(
+ self.make_label('toolbar-edit', ' ' + _('Edit Card')))
+ self.button_box.pack_start(self._editbutton)
+ self.canvas.pack_start(self.button_box, False)
+ self._editbutton.show()
+ self.button_box.show()
+
+ self.mode = _BROWSE_MODE
+
+
+
+
+ # Removes current screen from the canvas
+ def remove_all(self):
+ if self.mode == _REVIEW_MODE:
+ self.canvas.remove(self.reviewpanel)
+ self.canvas.remove(self.button_box)
+ elif self.mode == _CREATE_MODE:
+ self.canvas.remove(self.creationpanel)
+ elif self.mode == _BROWSE_MODE:
+ self.canvas.remove(self.browseeditpanel)
+ self.canvas.remove(self.button_box)
+
+ # Review button callback
+ def _review_cb(self, button):
+ _logger.error("Clicked the review button.")
+ if self.mode != _REVIEW_MODE:
+ self.review_mode()
+ else:
+ self.canvas.remove(self.reviewpanel)
+ self.canvas.remove(self.button_box)
+ self.review_mode()
+
+ # Create button callback
+ def _create_cb(self, button):
+ _logger.error("Clicked the create button.")
+ if self.mode != _CREATE_MODE:
+ self.create_mode(_EMPTY, _EMPTY, _EMPTY, False)
+
+ # Browse/Edit button callback
+ def _browse_edit_cb(self, button):
+ _logger.error("Clicked the browse/edit button. ")
+ if self.mode != _BROWSE_MODE:
+ self.browse_edit_mode()
+
+ # Edit button callback, passes flashcard information to create panel
+ # so that it can be edited
+ def _edit_button_cb(self, button):
+
+ editing_card_text = self.browseeditpanel.get_card_text()
+ self.create_mode(editing_card_text[0], editing_card_text[1], editing_card_text[2], True)
+
+ # Select button callback, passes the selected category and box to the
+ # review panel
+ def _select_button_cb(self, button):
+ selected_box = self.reviewpanel.get_selected_box()
+ selected_catagory = self.reviewpanel.get_selected_catagory()
+ expired_only = self.reviewpanel.get_expired_only()
+ self.canvas.remove(self.reviewpanel)
+ self.canvas.remove(self.button_box)
+ self.reviewpanel = reviewpanel.ReviewPanel(selected_box, selected_catagory, expired_only)
+ self.canvas.pack_start(self.reviewpanel, True, True)
+ self.reviewpanel.show()
+
+
+ # Writes to logger
+ def write_file(self, file_path):
+ """ Write the bead positions to the Journal """
+ _logger.debug("Saving current abacus to Journal: %s " % ("test"))
+
+
+ # Gets icons for button and makes the label
+ # Written by Simon Schampijer
+ def make_label(self, icon_name, label):
+ label_box = gtk.HBox()
+ icon = Icon(
+ icon_name=icon_name,
+ icon_size=gtk.ICON_SIZE_LARGE_TOOLBAR)
+ label_box.pack_start(icon, False)
+ label = gtk.Label(label)
+ label.modify_fg(gtk.STATE_NORMAL,
+ style.COLOR_TOOLBAR_GREY.get_gdk_color())
+ label_box.pack_start(label)
+ label_box.show_all()
+ return label_box
+
diff --git a/MANIFEST b/MANIFEST
new file mode 100644
index 0000000..431595c
--- /dev/null
+++ b/MANIFEST
@@ -0,0 +1,17 @@
+AUTHORS
+NEWS
+COPYING
+FlashcardActivity.py
+browseeditpanel.py
+creationpanel.py
+reviewpanel.py
+reviewselection.py
+setup.py
+flashcarddtd.dtd
+testfile.xml
+activity/activity-flashcard.svg
+activity/activity.info
+icons/pair-update.svg
+port/COPYING
+port/README
+port/widgets.py
diff --git a/NEWS b/NEWS
new file mode 100644
index 0000000..ce64481
--- /dev/null
+++ b/NEWS
@@ -0,0 +1,8 @@
+1
+
+* Flashcard activity
+* Rough initial interface
+* Review, Create, Browse, Edit
+* Review by Leitner System
+
+
diff --git a/activity/Sugar-iconify.py b/activity/Sugar-iconify.py
new file mode 100644
index 0000000..7d7b017
--- /dev/null
+++ b/activity/Sugar-iconify.py
@@ -0,0 +1,678 @@
+#!/usr/bin/python
+
+import sys
+import xml.dom.minidom
+import getopt
+import re
+import os
+import string
+
+#define help output
+def usage():
+ print '\nUsage: sugar-iconify.py [options] input.svg\n'
+ print 'Options:\n'
+ print '\t -c\t\tApply default color entities (#666666, #ffffff) to output'
+ print '\t -d directory\tThe preferred output directory'
+ print '\t -e\t\tDo not insert entities for strokes and fills'
+ print '\t -f hex\t\tHex value to replace with fill entity'
+ print '\t -g\t\tAutomatically accept guesses for stroke and fill entities'
+ print '\t -h\t\tDisplay this help message'
+ print '\t -i\t\tInsert "isolated stroke" entities'
+ print '\t -m\t\tMultiple export; export top level groups as separate icons'
+ print '\t -o\t\tOverwrite the input file; overridden by -m'
+ print '\t -p pattern\tOnly export icons whose name matches pattern; for use with -m'
+ print '\t -s hex\t\tHex value to replace with stroke entity'
+ print '\t -x\t\tOutput example SVGs, for previewing their appearance in Sugar; ignored with -m'
+ print '\t -v\t\tverbose'
+
+#check for valid arguments
+try:
+ opts,arg = getopt.getopt(sys.argv[1:], "s:f:gcd:imp:oehvx")
+except:
+ usage()
+ sys.exit(2)
+
+if len(arg) < 1:
+ usage()
+ sys.exit(2)
+
+#declare variables and constants
+default_stroke_color = '#666666'
+default_fill_color = '#ffffff'
+transparent_color = '#00000000'
+stroke_color = default_stroke_color
+fill_color = default_fill_color
+stroke_entity = "stroke_color"
+fill_entity = "fill_color"
+iso_stroke_entity = "iso_stroke_color"
+
+output_path = ''
+pattern = ''
+entities_passed = 0
+use_default_colors = False
+confirm_guess = True
+use_entities = True
+multiple = False
+verbose = False
+overwrite_input = False
+output_examples = False
+use_iso_strokes = False
+
+#interpret arguments
+for o, a in opts:
+
+ if o == '-s':
+ stroke_color = '#' + a.lstrip('#').lower()
+ entities_passed += 1
+ elif o == '-f':
+ fill_color = '#' + a.lstrip('#').lower()
+ entities_passed += 1
+ elif o == '-g':
+ confirm_guess = False
+ elif o == '-c':
+ use_default_colors = True
+ elif o == '-o':
+ overwrite_input = True
+ elif o == '-d':
+ output_path = a.rstrip('/') + '/'
+ elif o == '-e':
+ use_entities = False
+ elif o == '-v':
+ verbose = True
+ elif o == '-p':
+ pattern = a
+ elif o == '-h':
+ usage()
+ sys.exit(2)
+ elif o == '-m':
+ multiple = True
+ elif o == '-x':
+ output_examples = True
+ elif o == '-i':
+ use_iso_strokes = True
+
+#isolate important parts of the input path
+svgfilepath = arg[0].rstrip('/')
+svgdirpath, sep, svgfilename = svgfilepath.rpartition('/')
+svgbasename = re.sub(r'(.*)\.([^.]+)', r'\1', svgfilename)
+
+#load the SVG as text
+try:
+ svgfile = open(svgfilepath, 'r')
+except:
+ sys.exit('Error: Could not locate ' + svgfilepath)
+
+try:
+ svgtext = svgfile.read()
+ svgfile.close()
+except:
+ svgfile.close()
+ sys.exit('Error: Could not read ' + svgfilepath)
+
+#determine the creator of the SVG (we only care about Inkscape and Illustrator)
+creator = 'unknown'
+
+if re.search('illustrator', svgtext, re.I):
+ creator = 'illustrator'
+elif re.search('inkscape', svgtext, re.I):
+ creator = 'inkscape'
+
+if verbose:
+ print 'The creator of this svg is ' + creator + '.'
+
+#hack the entities into the readonly DTD
+if use_entities:
+
+ #before replacing them, we read the stroke/fill values out, should they have previously been defined,
+ #to prevent needing to make guesses for them later
+ stroke_match = re.search(r'stroke_color\s*\"([^"]*)\"', svgtext)
+ fill_match = re.search(r'fill_color\s*\"([^"]*)\"', svgtext)
+ if stroke_match is not None:
+ stroke_color = stroke_match.group(1).lower()
+ entities_passed += 1
+ if fill_match is not None:
+ fill_color = fill_match.group(1).lower()
+ entities_passed += 1
+
+ #define the entities
+ if fill_match and stroke_match:
+ entities = '\t<!ENTITY ' + stroke_entity + ' "' + stroke_color + '">\n'
+ entities += '\t<!ENTITY ' + fill_entity + ' "' + fill_color + '">\n'
+ if use_iso_strokes:
+ entities += '\t<!ENTITY ' + iso_stroke_entity + ' "' + stroke_color + '">\n'
+ else:
+ entities = '\t<!ENTITY ' + stroke_entity + ' "' + default_stroke_color + '">\n'
+ entities += '\t<!ENTITY ' + fill_entity + ' "' + default_fill_color + '">\n'
+ if use_iso_strokes:
+ entities += '\t<!ENTITY ' + iso_stroke_entity + ' "' + default_stroke_color + '">\n'
+
+ #for simplicity, we simply replace the entire entity declaration block; this obviously would remove
+ #any other custom entities declared within the SVG, but we assume that's an extreme edge case
+
+ svgtext, n = re.subn(r'(<!DOCTYPE[^>\[]*)(\[[^\]]*\])*\>', r'\1 \n[\n' + entities + ']>\n', svgtext)
+
+ #add a doctype if none already exists, adding the appropriate entities as well
+ if n == 0:
+ svgtext,n = re.subn("<svg", "<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd' [\n" + entities + "]>\n<svg", svgtext)
+ if n == 0:
+ sys.exit('Error: Could not insert entities into DTD')
+
+#convert entities to references
+stroke_entity = '&' + stroke_entity + ';'
+fill_entity = '&' + fill_entity + ';'
+
+#create the SVG DOM
+try:
+ svgxml = xml.dom.minidom.parseString(svgtext);
+except Exception, e:
+ sys.exit('Error: Could not parse ' + svgfilename + str(e))
+
+#extract top level nodes
+i = 0
+svgindex = 0;
+docindex = 0;
+for element in svgxml.childNodes:
+ if element.nodeType == 10:
+ docindex = i;
+ elif element.localName == 'svg':
+ svgindex = i;
+ break;
+ i += 1;
+
+doctype = svgxml.childNodes[docindex]
+svg = svgxml.childNodes[svgindex]
+icons = svg.childNodes;
+
+#validate canvas size
+w = svg.getAttribute('width')
+h = svg.getAttribute('height')
+
+if w != '55px' or h != '55px':
+ print "Warning: invalid canvas size (%s, %s); Should be (55px, 55px)" % (w, h)
+
+#define utility functions
+def getStroke(node):
+ s = node.getAttribute('stroke')
+ if s:
+ return s.lower()
+ else:
+ if re.search(r'stroke:', node.getAttribute('style')):
+ s = re.sub(r'.*stroke:\s*(#*[^;]*).*', r'\1', node.getAttribute('style'))
+ return s.lower()
+ else:
+ return 'none'
+
+def setStroke(node, value):
+ s = node.getAttribute('stroke')
+ if s:
+ node.setAttribute('stroke', value)
+ else:
+ s = re.sub(r'stroke:\s*#*[^;]*', 'stroke:' + value, node.getAttribute('style'))
+ node.setAttribute('style', s)
+
+def getFill(node):
+ f = node.getAttribute('fill')
+ if f:
+ return f.lower()
+ else:
+ if re.search(r'fill:', node.getAttribute('style')):
+ f = re.sub(r'.*fill:\s*(#*[^;]*).*', r'\1', node.getAttribute('style'))
+ return f.lower()
+ else:
+ return 'none'
+
+def setFill(node, value):
+ f = node.getAttribute('fill')
+ if f:
+ node.setAttribute('fill', value)
+ else:
+ s = re.sub(r'fill:\s*#*[^;]*', 'fill:' + value, node.getAttribute('style'))
+ node.setAttribute('style', s)
+
+def replaceEntities(node, indent=''):
+
+ strokes_replaced = 0
+ fills_replaced = 0
+
+ if node.localName:
+ str = indent + node.localName
+
+ if node.nodeType == 1: #only element nodes have attrs
+
+ #replace entities for matches
+ if getStroke(node) == stroke_color:
+ setStroke(node, stroke_entity)
+ strokes_replaced += 1
+
+ if getStroke(node) == fill_color:
+ setStroke(node, fill_entity)
+ strokes_replaced += 1
+
+ if getFill(node) == fill_color:
+ setFill(node, fill_entity)
+ fills_replaced += 1
+
+ if getFill(node) == stroke_color:
+ setFill(node, stroke_entity)
+ fills_replaced += 1
+
+ str = str + " (" + getStroke(node) + ", " + getFill(node) + ")"
+ if verbose:
+ print str
+
+ #recurse on DOM
+ for n in node.childNodes:
+ sr, fr = replaceEntities(n, indent + " ")
+ strokes_replaced += sr
+ fills_replaced += fr
+
+ #return the number of replacements made
+ return (strokes_replaced, fills_replaced)
+
+def fix_isolated_strokes(node):
+
+ strokes_fixed = 0
+ #recurse on DOM
+ last_n = None
+ for n in node.childNodes:
+ sf = fix_isolated_strokes(n)
+ strokes_fixed += sf
+
+ if node.nodeType == 1: #only element nodes have attrs
+
+ #find strokes with no associated fill
+ if getStroke(node) != 'none' and getFill(node) == 'none':
+ strokes_fixed += 1
+ setStroke(node, "&iso_stroke_color;")
+
+ #return the number of strokes fixed
+ return strokes_fixed
+
+
+#these functions attempt to guess the hex values for the stroke and fill entities
+
+def getColorPairs(node, pairs=[]):
+
+ if node.nodeType == 1:
+
+ #skip masks
+ if node.localName == 'mask':
+ return pairs
+
+ node_name = ''
+ try:
+ if creator == 'inkscape' and node.attributes.getNamedItem('inkscape:label'):
+ node_name = node.attributes.getNamedItem('inkscape:label').nodeValue
+ else:
+ node_name = node.attributes.getNamedItem('id').nodeValue
+ except:
+ pass
+
+ #skip the template layers
+ if node_name.startswith('_'):
+ return pairs
+
+ pair = (getStroke(node), getFill(node))
+ if pair[0] != pair[1]:
+ pairs.append(pair)
+
+ #recurse on DOM
+ for n in node.childNodes:
+ getColorPairs(n, pairs)
+
+ return pairs
+
+def guessEntities(node):
+
+ guesses = getColorPairs(node)
+ #print guesses
+
+ stroke_guess = 'none'
+ fill_guess = 'none'
+
+ for guess in guesses:
+ if stroke_guess == 'none':
+ stroke_guess = guess[0]
+ if fill_guess == 'none' and stroke_guess != guess[1]:
+ fill_guess = guess[1]
+ if guess[0] == fill_guess and guess[1] != 'none':
+ fill_guess = stroke_guess
+ stroke_guess = guess[0]
+ if fill_guess == 'none':
+ fill_guess = guess[1]
+
+ return (stroke_guess, fill_guess)
+
+
+#guess the entity values, if they aren't passed in
+
+if use_entities:
+ if entities_passed < 2:
+ stroke_color, fill_color = guessEntities(svg)
+
+ if confirm_guess or verbose:
+ print '\nentity definitions:'
+ print ' stroke_entity = ' + stroke_color
+ print ' fill_entity = ' + fill_color
+
+ if entities_passed < 2:
+ if confirm_guess:
+ response = raw_input("\nAre these entities correct? [y/n] ")
+ if response.lower() != 'y':
+ print 'Please run this script again, passing the proper colors with the -s and -f flags.'
+ sys.exit(1)
+
+#define the HTML for preview output
+
+previewHTML = "\
+<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\"\n\
+\t\"http://www.w3.org/TR/html4/strict.dtd\">\n\
+<html>\n\
+<head>\n\
+\t<meta http-equiv=\"Content-type\" content=\"text/html; charset=utf-8\">\n\
+\t<title>Sugar Icon Preview: ~~~</title>\n\
+\t<script type=\"text/javascript\" charset=\"utf-8\">\n\
+\t\tvar bordered = false;\n\
+\t\tvar bgcolor = \"#FFF\"\n\
+\n\
+\t\tfunction toggleIconBorder(reset)\n\
+\t\t{\n\
+\t\t\tif(!reset) bordered = !bordered;\n\
+\t\t\t\n\
+\t\t\tvar objects = document.getElementsByTagName('object')\n\
+\t\t\tfor(var i = 0; i < objects.length; i++)\n\
+\t\t\t{\n\
+\t\t\t\tif(bordered) objects[i].style.border = 'solid 1px gray';\n\
+\t\t\t\telse objects[i].style.border = 'solid 1px ' + bgcolor;\n\
+\t\t\t}\n\
+\t\t}\n\
+\t\tfunction setBackgroundColor(color)\n\
+\t\t{\n\
+\t\t\tbgcolor = color;\n\
+\t\t\tvar objects = document.getElementsByTagName('div');\n\
+\t\t\tfor(var i = 0; i < objects.length; i++)\n\
+\t\t\t\tif(objects[i].className == 'cell')\n\
+\t\t\t\t\tobjects[i].style.backgroundColor = color;\n\
+\t\t\t\n\
+\t\t\ttoggleIconBorder(true)\n\
+\t\t}\n\
+\t</script>\n\
+\t<style type=\"text/css\" media=\"screen\">\n\
+\t\thtml, body {\n\
+\t\t\tmargin: 0px;\n\
+\t\t\tborder: 0px;\n\
+\t\t\tbackground-color: white;\n\
+\t\t\t\n\
+\t\t\tfont: 14px Helvetica;\n\
+\t\t\tcolor: gray;\n\
+\t\t}\n\
+\t\t.cell {\n\
+\t\t\twidth: 57px;\n\
+\t\t\theight: 57px;\n\
+\t\t\tpadding: 8px;\n\
+\t\t\tborder: solid 1px gray;\n\
+\t\t}\n\
+\t\t.icon {\n\
+\t\t\tmargin: 0px;\n\
+\t\t\tpadding: 0px;\n\
+\t\t\tborder: solid 1px #FFF;\n\
+\t\t\twidth: 55px;\n\
+\t\t\theight: 55px;\n\
+\t\t}\n\
+\t\t#icons {\n\
+\t\t\tmargin-top: 30px;\n\
+\t\t}\n\
+\n\
+\t\t#icons > li {\n\
+\t\t\tdisplay: block;\n\
+\t\t\tmargin: 0px;\n\
+\t\t\tmargin-bottom: 20px;\n\
+\t\t}\n\
+\t\t#description {\n\
+\t\t\twidth: 300px;\n\
+\t\t\tposition: absolute;\n\
+\t\t\ttop: 0px;\n\
+\t\t\tleft: 200px;\n\
+\t\t\tborder-left: solid 1px gray;\n\
+\t\t\tmargin-top: 30px;\n\
+\t\t\tpadding-left: 30px;\n\
+\t\t\tfont-size: 11px;\n\
+\t\t}\n\
+\t\t#description ul {\n\
+\t\t\tmargin: 0px;\n\
+\t\t\tpadding: 0px;\n\
+\t\t\tdisplay: block;\n\
+\t\t\tlist-style: square;\n\
+\t\t}\n\
+\t\tli { margin-bottom: 10px; }\n\
+\t\ta, a:visited { color: gray; }\n\
+\t\ta:hover { color: black; }\n\
+\t</style>\n\
+</head>\n\
+<body>\n\
+\t\t<ul id='icons'>\n\
+\t\t<li><div class='cell'><object class='icon' id='stroke' data=\"~~~.stroke.svg\" type=\"image/svg+xml\"></object></div><br>stroke\n\
+\t\t<li><div class='cell'><object class='icon' id='fill' data=\"~~~.fill.svg\" type=\"image/svg+xml\"></object></div><br>fill\n\
+\t\t<li><div class='cell'><object class='icon' id='both' data=\"~~~.both.svg\" type=\"image/svg+xml\"></object></div><br>both\n\
+\t\t</ul>\n\
+\t\t<div id='description'>\n\
+\t\t\t<h3>Icon Validation</h3>\n\
+\t\t\t<ul>\n\
+\t\t\t\t<li>Ensure that your icons appear to be centered within their boxes.\n\
+\t\t\t\t\tIf they appear off-center or cropped, you may have created your icon on canvas other than the required 55px square.\n\
+\t\t\t\t\tClick to <a href='javascript:toggleIconBorder();'>toggle</a> the 55px canvas border.\n\
+\t\t\t\t<li>If your icon appears off-center but has the correct 55px canvas, it may simply have uneven visual balance.\n\
+\t\t\t\t\tThis means, though it may be technically centered, differences in the distribution of \"mass\" cause it to appear otherwise. \n\
+\t\t\t\t\tTry shifting the icon slightly on your canvas, while ensuring that you don't accidentally exceed the 55px boundary.\n\
+\t\t\t\t<!--li>Click to see your icon on <a href=\"javascript:setBackgroundColor('#000');\">black</a>, \n\
+\t\t\t\t\t<a href=\"javascript:setBackgroundColor('#FFF');\">white</a>, <a href=\"javascript:setBackgroundColor('#282828');\">gray</a>.<!-->\n\
+\t\t\t\t<li>Ensure that the first two icons appear entirely in gray, and that all of the third icon is colored blue and green, with the latter being the fill color.\n\
+\t\t\t\t\tIf any fail to meet these requirements, your icon does not have proper stroke and/or fill entities defined.\n\
+\t\t\t\t\tInvestigate the <b>-s</b> and <b>-f</b> options of sugar-iconify, and be sure that your input SVG doesn't have extra colors in its palette.\n\
+\t\t\t\t<li>Ensure that your icon reads clearly when viewed only as strokes.\n\
+\t\t\t\t\tThis visual style will be used to represent activities/objects which are inactive, or uninstantiated.\n\
+\t\t\t\t\tConsider applying outlining strokes to any filled shapes that do not already have them.\n\
+\t\t\t\t<li>Ensure that your icon reads clearly when viewed only as fills.\n\
+\t\t\t\t\tThis visual style will be used for representing activity types within other icons, such as invitations, transfers, and objects. \n\
+\t\t\t\t\tIf you have strokes which are isolated from fills, neither outlining them nor sitting against a filled background, please \n\
+\t\t\t\t\tinvestigate the <b>-i</b> option of the sugar-iconify script.\n\
+\t\t\t</ul>\n\
+\t\t\t<i>For more information, please see the OLPC wiki page on <a href='http://wiki.laptop.org/go/Making_Sugar_Icons' target='_blank'>making sugar icons</a>.</i>\n\
+\t\t</div>\n\
+</body>\n\
+</html>\n\
+"
+
+#finally, do the icon conversion and export
+
+if multiple:
+ #export each icon as a separate file by top level group
+ n_icons_exported = 0
+ n_warnings = 0
+ for icon in icons:
+
+ try:
+ #skip whitespace and unnamed icons
+ if icon.localName == 'g' and icon.attributes:
+
+ icon_name = ''
+ try:
+ if creator == 'inkscape' and icon.attributes.getNamedItem('inkscape:label'):
+ icon_name = icon.attributes.getNamedItem('inkscape:label').nodeValue
+ else:
+ icon_name = icon.attributes.getNamedItem('id').nodeValue
+ except:
+ pass
+
+ #skip the template layers
+ if not icon_name.startswith('_'):
+
+ #skip non-matches
+ if pattern == '' or re.search(pattern, icon_name):
+
+ if verbose:
+ print '\nExporting ' + icon_name + '.svg...'
+ icon_xml = xml.dom.minidom.Document();
+
+ #construct the SVG
+ icon_xml.appendChild(doctype)
+ icon_xml.appendChild(svg.cloneNode(0))
+
+ icon_xml.childNodes[1].appendChild(icon)
+ icon_xml.childNodes[1].childNodes[0].setAttribute('display', 'block')
+
+ if use_entities:
+ strokes_replaced, fills_replaced = replaceEntities(icon_xml.childNodes[1])
+
+ if not strokes_replaced and not fills_replaced:
+ print 'Warning: no entity replacements were made in %s' % icon_name
+ elif not strokes_replaced:
+ print 'Warning: no stroke entity replacements were made in %s' % icon_name
+ elif not fills_replaced:
+ print 'Warning: no fill entity replacements were made in %s' % icon_name
+
+ if not strokes_replaced or not fills_replaced:
+ n_warnings += 1
+
+ #write the file
+ try:
+ f = open(output_path + icon_name + '.svg', 'w')
+ except:
+ sys.exit('Error: Could not locate directory ' + output_path)
+
+ try:
+ #had to hack here to remove the automatic encoding of '&' by toxml() in entity refs
+ #I'm sure there is a way to prevent need for this if I knew the XML DOM better
+ icon_svgtext = icon_xml.toxml()
+ icon_svgtext = re.sub('&amp;', '&', icon_svgtext)
+ if not use_default_colors:
+ icon_svgtext = re.sub(r'ENTITY stroke_color "[^"]*"', r'ENTITY stroke_color "' + stroke_color + '"', icon_svgtext)
+ icon_svgtext = re.sub(r'ENTITY fill_color "[^"]*"', r'ENTITY fill_color "' + fill_color + '"', icon_svgtext)
+ f.write(icon_svgtext)
+ f.close()
+ except:
+ sys.exit('Error: Could not write file ' + icon_name + '.svg')
+
+ n_icons_exported += 1
+ except:
+ #catch any errors we may have missed, so the rest of the icons can export normally
+ if(icon_name):
+ print 'Error: Could not export' + icon_name + '.svg'
+
+ if verbose:
+ if n_icons_exported == 1:
+ print 'Successfully exported 1 icon'
+ else:
+ print 'Successfully exported %d icons' % n_icons_exported
+
+ if n_warnings == 1:
+ print 'Warnings were reported for 1 icon'
+ elif n_warnings > 1:
+ print 'Warnings were reported for %d icons' % n_warnings
+
+else:
+ #output a single converted icon
+
+ if not overwrite_input:
+ outfilename = re.sub(r'(.*\.)([^.]+)', r'\1sugar.\2', svgfilename)
+ if verbose:
+ print 'Exporting ' + outfilename + ' ...'
+ else:
+ outfilename = svgfilename
+ if verbose:
+ print 'Overwriting ' + outfilename + ' ...'
+
+ #remove the template layers
+ for node in svg.childNodes:
+
+ #only check named nodes
+ if node.localName == 'g' and node.attributes:
+ try:
+ if creator == 'inkscape' and node.attributes.getNamedItem('inkscape:label'):
+ node_name = node.attributes.getNamedItem('inkscape:label').nodeValue
+ else:
+ node_name = node.attributes.getNamedItem('id').nodeValue
+
+ if node_name.startswith('_'):
+ node.parentNode.removeChild(node)
+ except:
+ pass
+
+ if use_entities:
+ strokes_replaced, fills_replaced = replaceEntities(svgxml)
+ if not strokes_replaced and not fills_replaced:
+ print 'Warning: no entity replacements were made'
+ elif not strokes_replaced:
+ print 'Warning: no stroke entity replacements were made'
+ elif not fills_replaced:
+ print 'Warning: no fill entity replacements were made'
+
+ if use_iso_strokes:
+ strokes_fixed = fix_isolated_strokes(svgxml)
+ if strokes_fixed > 0 and verbose:
+ print "%d isolated strokes fixed" % strokes_fixed
+
+ #create the output file(s)
+ if output_examples:
+
+ example_path = output_path + re.sub(r'(.*\.)([^.]+)', r'\1preview', svgfilename) + '/'
+ try:
+ os.mkdir(example_path)
+ except:
+ pass
+
+ try:
+ f = open(example_path + 'preview.html', 'w')
+ except:
+ print "Error: could not create HTML preview file"
+
+ try:
+ f.write(re.sub(r'~~~', svgbasename, previewHTML))
+ f.close()
+ except:
+ sys.exit('Error: could not write to HTML preview file')
+
+ example_colors = [(default_stroke_color, "#FFFFFF", default_stroke_color),
+ ("#FFFFFF", default_stroke_color, default_stroke_color),
+ ("#0000AA", "#00DD00", "#0000AA")]
+ example_filenames = [re.sub(r'(.*\.)([^.]+)', r'\1stroke.\2', svgfilename),
+ re.sub(r'(.*\.)([^.]+)', r'\1fill.\2', svgfilename),
+ re.sub(r'(.*\.)([^.]+)', r'\1both.\2', svgfilename) ]
+
+ icon_svgtext = svgxml.toxml()
+ icon_svgtext = re.sub('&amp;', '&', icon_svgtext)
+
+ for i in range(0, len(example_filenames)):
+ try:
+ f = open(example_path + example_filenames[i], 'w')
+ except:
+ sys.exit('Error: Could not save to ' + example_path + example_filenames[i])
+ try:
+ icon_svgtext = re.sub(r'ENTITY stroke_color "[^"]*"', r'ENTITY stroke_color "' + example_colors[i][0] + '"', icon_svgtext)
+ icon_svgtext = re.sub(r'ENTITY fill_color "[^"]*"', r'ENTITY fill_color "' + example_colors[i][1] + '"', icon_svgtext)
+ if use_iso_strokes:
+ icon_svgtext = re.sub(r'ENTITY iso_stroke_color "[^"]*"', r'ENTITY iso_stroke_color "' + example_colors[i][2] + '"', icon_svgtext)
+ f.write(icon_svgtext)
+ f.close()
+ except:
+ sys.exit('Error: Could not write file ' + output_path + example_filenames[i])
+
+ try:
+ f = open(output_path + outfilename, 'w')
+ except:
+ sys.exit('Error: Could not save to ' + output_path + outfilename)
+
+ try:
+ icon_svgtext = svgxml.toxml()
+ icon_svgtext = re.sub('&amp;', '&', icon_svgtext)
+ if not use_default_colors:
+ icon_svgtext = re.sub(r'ENTITY stroke_color "[^"]*"', r'ENTITY stroke_color "' + stroke_color + '"', icon_svgtext)
+ icon_svgtext = re.sub(r'ENTITY fill_color "[^"]*"', r'ENTITY fill_color "' + fill_color + '"', icon_svgtext)
+ if use_iso_strokes:
+ icon_svgtext = re.sub(r'ENTITY iso_stroke_color "[^"]*"', r'ENTITY iso_stroke_color "' + stroke_color + '"', icon_svgtext)
+ f.write(icon_svgtext)
+ f.close()
+
+ except:
+ sys.exit('Error: Could not write file ' + output_path + outfilename)
+
diff --git a/activity/activity-flashcard.svg b/activity/activity-flashcard.svg
new file mode 100644
index 0000000..9096878
--- /dev/null
+++ b/activity/activity-flashcard.svg
@@ -0,0 +1,22 @@
+<?xml version="1.0" ?><!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd' [
+ <!ENTITY stroke_color "#666666">
+ <!ENTITY fill_color "#ffffff">
+]><svg height="45" id="svg2" inkscape:version="0.46+devel" sodipodi:docname="activity-abacus.svg" version="1.1" width="45" xmlns="http://www.w3.org/2000/svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:svg="http://www.w3.org/2000/svg">
+ <metadata id="metadata43">
+ <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="defs41">
+ <inkscape:perspective id="perspective45" inkscape:persp3d-origin="22.5 : 15 : 1" inkscape:vp_x="0 : 22.5 : 1" inkscape:vp_y="0 : 1000 : 0" inkscape:vp_z="45 : 22.5 : 1" sodipodi:type="inkscape:persp3d"/>
+ <inkscape:perspective id="perspective2859" inkscape:persp3d-origin="0.5 : 0.33333333 : 1" inkscape:vp_x="0 : 0.5 : 1" inkscape:vp_y="0 : 1000 : 0" inkscape:vp_z="1 : 0.5 : 1" sodipodi:type="inkscape:persp3d"/>
+ </defs>
+ <sodipodi:namedview bordercolor="#666666" borderopacity="1" gridtolerance="10" guidetolerance="10" id="namedview39" inkscape:current-layer="svg2" inkscape:cx="22.5" inkscape:cy="22.118644" inkscape:pageopacity="0" inkscape:pageshadow="2" inkscape:window-height="495" inkscape:window-maximized="0" inkscape:window-width="640" inkscape:window-x="150" inkscape:window-y="117" inkscape:zoom="5.2444444" objecttolerance="10" pagecolor="#ffffff" showgrid="false"/>
+ <rect height="43" id="rect4" style="fill:&fill_color;;stroke:&stroke_color;;stroke-width:2" transform="matrix(0,-1,1,0,0,0)" width="37.959229" x="-41.478813" y="1"/>
+ <line id="line10-4" style="fill:&fill_color;;stroke:&stroke_color;;stroke-width:2" x1="43.203743" x2="0.27083594" y1="32.305088" y2="32.305088"/>
+ <line id="line10-4-1" style="fill:&fill_color;;stroke:&stroke_color;;stroke-width:2" x1="44.157131" x2="1.2242244" y1="13.919493" y2="13.919493"/>
+</svg> \ No newline at end of file
diff --git a/activity/activity.info b/activity/activity.info
new file mode 100644
index 0000000..b9a2dd4
--- /dev/null
+++ b/activity/activity.info
@@ -0,0 +1,8 @@
+[Activity]
+name = Flashcard
+activity_version = 1
+license = GPLv3
+bundle_id = FlashcardActivity
+exec = sugar-activity FlashcardActivity.FlashcardActivity
+icon = activity-flashcard
+show_launcher = yes
diff --git a/browseeditpanel.py b/browseeditpanel.py
new file mode 100644
index 0000000..71e9871
--- /dev/null
+++ b/browseeditpanel.py
@@ -0,0 +1,235 @@
+# -*- coding: utf-8 -*-
+#Copyright (c) 2010, Kirk Winans
+
+# 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
+from os import environ
+from os.path import join, basename
+import hippo
+
+import shutil
+import tempfile
+from gettext import gettext as _
+import logging
+from gobject import SIGNAL_RUN_FIRST, TYPE_PYOBJECT
+from sugar.graphics import style
+from sugar.graphics.toolbutton import ToolButton
+from sugar.graphics.icon import Icon
+from sugar.graphics.palette import Palette
+from port.widgets import ToggleToolButton
+from port.widgets import CanvasRoundBox, ToolComboBox
+#from port import chooser
+
+from sugar.datastore import datastore
+import xml.etree.ElementTree
+from datetime import date
+import time
+
+import FlashcardActivity
+
+#
+# Browse/Edit panel for Flashcard Activity
+#
+class BrowseEditPanel(gtk.VBox):
+
+ def __init__(self, activity_root):
+ gtk.VBox.__init__(self)
+
+ self.activity_root = activity_root
+
+ # Loading in tree of cards
+ self.testfile = "testfile.xml"
+ self.tree = xml.etree.ElementTree.parse(self.testfile)
+
+ self.deck_element = self.tree.getroot()
+ self.deck = self.deck_element.findall("card")
+ self.current_card_index = 0
+
+ next_card_tuple = self.next_card()
+
+ self.viewcard_box = gtk.VBox()
+
+ # Boxes to view the different parts of the cards
+ self.viewfront_box = gtk.HBox()
+ self.viewback_box = gtk.HBox()
+ self.viewcatagory_box = gtk.HBox()
+ self.viewstage_box = gtk.HBox()
+ self.viewdate_box = gtk.HBox()
+
+ self.front_label = gtk.Label(_('Front:'))
+
+ self.viewfront = gtk.TextView()
+ self.frontbuffer = self.viewfront.get_buffer()
+ self.viewfront.set_editable(False)
+ self.viewfront.set_wrap_mode(gtk.WRAP_WORD)
+ self.viewfront.set_justification(gtk.JUSTIFY_CENTER)
+ self.viewfront.set_pixels_below_lines(0)
+ self.viewfront.set_pixels_above_lines(40)
+
+ self.back_label = gtk.Label(_('Back:'))
+
+ self.viewback = gtk.TextView()
+ self.backbuffer = self.viewback.get_buffer()
+ self.viewback.set_editable(False)
+ self.viewback.set_wrap_mode(gtk.WRAP_WORD)
+ self.viewback.set_justification(gtk.JUSTIFY_CENTER)
+ self.viewback.set_pixels_below_lines(0)
+ self.viewback.set_pixels_above_lines(40)
+
+ self.catagory_label = gtk.Label(_('Category:'))
+
+ self.viewcatagory = gtk.TextView()
+ self.catagorybuffer = self.viewcatagory.get_buffer()
+ self.viewcatagory.set_editable(False)
+ self.viewcatagory.set_wrap_mode(gtk.WRAP_WORD)
+ self.viewcatagory.set_justification(gtk.JUSTIFY_CENTER)
+ self.viewcatagory.set_pixels_below_lines(0)
+ self.viewcatagory.set_pixels_above_lines(40)
+
+ self.stage_label = gtk.Label(_('Stage:'))
+
+ self.viewstage = gtk.TextView()
+ self.stagebuffer = self.viewstage.get_buffer()
+ self.viewstage.set_editable(False)
+ self.viewstage.set_wrap_mode(gtk.WRAP_WORD)
+ self.viewstage.set_justification(gtk.JUSTIFY_CENTER)
+ self.viewstage.set_pixels_below_lines(0)
+ self.viewstage.set_pixels_above_lines(40)
+
+ self.date_label = gtk.Label(_('Last Reviewed:'))
+
+ self.viewdate = gtk.TextView()
+ self.datebuffer = self.viewdate.get_buffer()
+ self.viewdate.set_editable(False)
+ self.viewdate.set_wrap_mode(gtk.WRAP_WORD)
+ self.viewdate.set_justification(gtk.JUSTIFY_CENTER)
+ self.viewdate.set_pixels_below_lines(0)
+ self.viewdate.set_pixels_above_lines(40)
+
+ self.nextbutton_bar = gtk.HButtonBox()
+
+
+ # Next Card Button
+ self._nextbutton = ToolButton(tooltip=_('Next Card'))
+ self._nextbutton.connect('clicked', self._next_card_cb)
+ self._nextbutton.set_icon_widget(
+ self.make_label('go-next', ' ' + _('Next Card')))
+
+ self.viewfront_box.pack_start(self.front_label)
+ self.viewfront_box.pack_start(self.viewfront)
+
+ self.viewback_box.pack_start(self.back_label)
+ self.viewback_box.pack_start(self.viewback)
+
+ self.viewcatagory_box.pack_start(self.catagory_label)
+ self.viewcatagory_box.pack_start(self.viewcatagory)
+
+ self.viewstage_box.pack_start(self.stage_label)
+ self.viewstage_box.pack_start(self.viewstage)
+
+ self.viewdate_box.pack_start(self.date_label)
+ self.viewdate_box.pack_start(self.viewdate)
+
+
+ self.viewcard_box.pack_start(self.viewfront_box)
+ self.viewcard_box.pack_start(self.viewback_box)
+ self.viewcard_box.pack_start(self.viewcatagory_box)
+ self.viewcard_box.pack_start(self.viewstage_box)
+ self.viewcard_box.pack_start(self.viewdate_box)
+
+ self.nextbutton_bar.pack_start(self._nextbutton)
+
+ self.add(self.viewcard_box)
+ self.add(self.nextbutton_bar)
+
+ self.frontbuffer.set_text(next_card_tuple[0])
+ self.backbuffer.set_text(next_card_tuple[1])
+ self.catagorybuffer.set_text(next_card_tuple[2])
+ self.stagebuffer.set_text(next_card_tuple[3])
+ self.datebuffer.set_text(next_card_tuple[4])
+
+ self.front_label.show()
+ self.back_label.show()
+ self.catagory_label.show()
+ self.stage_label.show()
+ self.date_label.show()
+
+ self.viewfront.show()
+ self.viewback.show()
+ self.viewcatagory.show()
+ self.viewstage.show()
+ self.viewdate.show()
+
+ self.viewfront_box.show()
+ self.viewback_box.show()
+ self.viewcatagory_box.show()
+ self.viewstage_box.show()
+ self.viewdate_box.show()
+
+ self.viewcard_box.show()
+ self._nextbutton.show()
+ self.nextbutton_bar.show()
+
+ # Returns the info from the next card
+ def next_card(self):
+ card = self.deck[self.current_card_index]
+ self.front = card.find("front").text
+ self.back = card.find("back").text
+ last = self.convert_date(card.find("last_reviewed").text)
+ stage = card.find("stage").text
+ self.catagory = card.find("catagory").text
+
+ if (self.current_card_index+1) < len(self.deck):
+ self.current_card_index += 1
+ else:
+ self.current_card_index = 0
+
+ return (self.front, self.back, self.catagory, stage, last)
+
+ # Converts the date from timestamp format to dd/mm/yyyy
+ def convert_date(self, timestamp_string):
+ timestamp = float(timestamp_string)
+ time_structure = time.gmtime(timestamp)
+ return (str(time_structure.tm_mday) + "/" + str(time_structure.tm_mon)
+ + "/" + str(time_structure.tm_year))
+
+ # Next Card button callback, gets next card and sets the text buffers
+ def _next_card_cb(self, button):
+ next_card_tuple = self.next_card()
+ self.frontbuffer.set_text(next_card_tuple[0])
+ self.backbuffer.set_text(next_card_tuple[1])
+ self.catagorybuffer.set_text(next_card_tuple[2])
+ self.stagebuffer.set_text(next_card_tuple[3])
+ self.datebuffer.set_text(next_card_tuple[4])
+
+ # Returns card text
+ def get_card_text(self):
+ return [self.front, self.back, self.catagory]
+
+ # Makes the icons for button and makes the label
+ # Written by Simon Schampijer
+ def make_label(self, icon_name, label):
+ label_box = gtk.HBox()
+ icon = Icon(
+ icon_name=icon_name,
+ icon_size=gtk.ICON_SIZE_LARGE_TOOLBAR)
+ label_box.pack_start(icon, False)
+ label = gtk.Label(label)
+ label.modify_fg(gtk.STATE_NORMAL,
+ style.COLOR_TOOLBAR_GREY.get_gdk_color())
+ label_box.pack_start(label)
+ label_box.show_all()
+ return label_box
+
+
+
+
+
diff --git a/creationpanel.py b/creationpanel.py
new file mode 100644
index 0000000..542569d
--- /dev/null
+++ b/creationpanel.py
@@ -0,0 +1,253 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2010, Kirk Winans
+# Code originally based on Simon Schampijer's code for the Memorize
+# Activity
+
+
+# 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
+from os import environ
+from os.path import join, basename
+import hippo
+
+import shutil
+import tempfile
+from gettext import gettext as _
+import logging
+from gobject import SIGNAL_RUN_FIRST, TYPE_PYOBJECT
+from sugar.graphics import style
+from sugar.graphics.toolbutton import ToolButton
+from sugar.graphics.icon import Icon
+from sugar.graphics.palette import Palette
+from port.widgets import ToggleToolButton
+from port.widgets import CanvasRoundBox, ToolComboBox
+#from port import chooser
+
+from sugar.datastore import datastore
+import xml.etree.ElementTree
+from datetime import date
+import time
+_logger = logging.getLogger("test-activity")
+
+#
+# Creation Panel for Flashcard Activity
+#
+class CreationPanel(gtk.VBox):
+
+ def __init__(self, activity_root, front_text, back_text, catagory_text, editing):
+ gtk.VBox.__init__(self)
+
+ self.activity_root = activity_root
+
+ self.main_box = gtk.VBox()
+ self.side_entries_box = gtk.VBox()
+ self.catagory_box = gtk.HBox()
+
+ # Text Entries
+ self.s1e_label = gtk.Label(_('Front:'))
+ self.side_1_entry = gtk.Entry()
+ self.s2e_label = gtk.Label(_('Back:'))
+ self.side_2_entry = gtk.Entry()
+ self.ce_label = gtk.Label(_('Category:'))
+ self.catagory_entry = gtk.Entry()
+
+ self.side_1_entry.set_text(front_text)
+ self.side_2_entry.set_text(back_text)
+ self.catagory_entry.set_text(catagory_text)
+
+ self.side_entries_box.pack_start(self.s1e_label, True, True)
+ self.side_entries_box.pack_start(self.side_1_entry, True, True)
+ self.side_entries_box.pack_start(self.s2e_label, True, True)
+ self.side_entries_box.pack_start(self.side_2_entry, True, True)
+ self.main_box.pack_start(self.side_entries_box, True, True)
+ self.catagory_box.pack_start(self.ce_label, True, True)
+ self.catagory_box.pack_start(self.catagory_entry, True, True)
+ self.main_box.pack_start(self.catagory_box, True, True)
+
+ self.add(self.main_box)
+
+
+ self.s1e_label.show()
+ self.side_1_entry.show()
+ self.s2e_label.show()
+ self.side_2_entry.show()
+ self.side_entries_box.show()
+ self.ce_label.show()
+ self.catagory_entry.show()
+ self.catagory_box.show()
+ self.main_box.show()
+
+
+ self.button_bar = gtk.HButtonBox()
+ self.button_bar.props.border_width = 10
+
+ if editing:
+ # Save Changes to card button
+ _save_changes = ToolButton(tooltip=_('Save Changes'))
+ _save_changes.connect('clicked', self._save_changes_cb)
+ _save_changes.set_icon_widget(
+ self.make_label('pair-update', ' ' + _('Update')))
+ self.button_bar.pack_start(_save_changes, False, False)
+ _save_changes.show()
+
+ # Delete Card button
+ _deletebutton = ToolButton(tooltip=_('Delete'))
+ _deletebutton.connect('clicked', self._delete_card_cb)
+ _deletebutton.set_icon_widget(
+ self.make_label('remove', ' ' + _('Delete')))
+ self.button_bar.pack_start(_deletebutton, True, True, 25)
+ _deletebutton.show()
+
+ else:
+ # Add Card button
+ _addbutton = ToolButton(tooltip=_('Add'))
+ _addbutton.connect('clicked', self._save_card_cb)
+ _addbutton.set_icon_widget(
+ self.make_label('add', ' ' + _('Add')))
+ self.button_bar.pack_start(_addbutton, False, False)
+ _addbutton.show()
+
+ self.pack_start(self.button_bar, False, False)
+ self.button_bar.show()
+
+
+ self.testfile = "testfile.xml"
+
+
+ self.tree = xml.etree.ElementTree.parse(self.testfile)
+
+ self.deck = self.tree.getroot()
+
+ self.front_text = front_text
+
+ # Add button callback, saves card if it has a front, back, and category
+ def _save_card_cb(self, button):
+ if (self.card_complete()):
+ self._save_card()
+
+ # Returns if the card is complete with a front, back, and category
+ def card_complete(self):
+ side1complete = self.side_1_entry.get_text() != ""
+ side2complete = self.side_2_entry.get_text() != ""
+ catagorycomplete = self.catagory_entry.get_text() != ""
+
+ return side1complete and side2complete and catagorycomplete
+
+ # Save Changes callback
+ def _save_changes_cb(self, button):
+ self._save_changes()
+
+ # Delete Card callback
+ def _delete_card_cb(self, button):
+ self.delete_card()
+
+ # Saves the new card, creates a new card element and addes it to the
+ # deck, then it is written automatically into the xml file
+ def _save_card(self):
+
+ new_card = xml.etree.ElementTree.Element("card")
+
+ n_c_front = xml.etree.ElementTree.Element("front")
+
+ n_c_back = xml.etree.ElementTree.Element("back")
+
+ n_c_last = xml.etree.ElementTree.Element("last_reviewed")
+
+ n_c_stage = xml.etree.ElementTree.Element("stage")
+
+ n_c_catagory = xml.etree.ElementTree.Element("catagory")
+
+ n_c_front.text = self.side_1_entry.get_text()
+
+ n_c_back.text = self.side_2_entry.get_text()
+
+ n_c_last.text = str(time.time())
+
+ n_c_stage.text = "0"
+
+ n_c_catagory.text = self.catagory_entry.get_text()
+
+
+ new_card.append(n_c_front)
+
+ new_card.append(n_c_back)
+
+ new_card.append(n_c_last)
+
+ new_card.append(n_c_stage)
+
+ new_card.append(n_c_catagory)
+
+ self.deck.append(new_card)
+
+
+ self.tree.write(self.testfile)
+
+ return file_dsobject
+
+ # Saves changes to the edited card, and writes the change to the xml file
+ def _save_changes(self):
+
+ edited_card = self.get_edited_card()
+
+
+ edited_card_front = edited_card.find("front")
+ edited_card_back = edited_card.find("back")
+ edited_card_catagory = edited_card.find("catagory")
+
+ edited_card_front.text = self.side_1_entry.get_text()
+ edited_card_back.text = self.side_2_entry.get_text()
+ edited_card_catagory.text = self.catagory_entry.get_text()
+
+ self.tree.write(self.testfile)
+
+ # Deletes the card from the file, removes the card from the deck,
+ # then writes the changed deck to the xml file
+ def delete_card(self):
+ edited_card = self.get_edited_card()
+ self.deck.remove(edited_card)
+ self.tree.write(self.testfile)
+
+
+ self.clear_entry_text()
+
+ # Returns the card to edit
+ def get_edited_card(self):
+
+ cards = self.deck.findall("card")
+ length = str(len(cards))
+
+ for c in cards:
+
+ front = c.find("front")
+ if front.text == self.front_text:
+ return c
+
+ # Clears the text in the text entries so that new cards can be made
+ def clear_entry_text(self):
+ self.side_1_entry.set_text("")
+ self.side_2_entry.set_text("")
+ self.catagory_entry.set_text("")
+
+ # Gets the icon for button and makes the label
+ # Written by Simon Schampijer
+ def make_label(self, icon_name, label):
+ label_box = gtk.HBox()
+ icon = Icon(
+ icon_name=icon_name,
+ icon_size=gtk.ICON_SIZE_LARGE_TOOLBAR)
+ label_box.pack_start(icon, False)
+ label = gtk.Label(label)
+ label.modify_fg(gtk.STATE_NORMAL,
+ style.COLOR_TOOLBAR_GREY.get_gdk_color())
+ label_box.pack_start(label)
+ label_box.show_all()
+ return label_box
diff --git a/flashcarddtd.dtd b/flashcarddtd.dtd
new file mode 100644
index 0000000..ed32880
--- /dev/null
+++ b/flashcarddtd.dtd
@@ -0,0 +1,17 @@
+<?xml version = "1.0" encoding = "utf-8"?>
+
+<!-- flashcarddtd.dtd - a document type definition for the flashcard.xml document -->
+
+<!ELEMENT deck (card+)>
+
+<!ELEMENT card (front, back, last_reviewed, stage, catagory)>
+
+<!ELEMENT front (#PCDATA)>
+
+<!ELEMENT back (#PCDATA)>
+
+<!ELEMENT last_reviewed (#PCDATA)>
+
+<!ELEMENT stage (#PCDATA)>
+
+<!ELEMENT catagory (#PCDATA)>
diff --git a/icons/pair-update.svg b/icons/pair-update.svg
new file mode 100644
index 0000000..d251be5
--- /dev/null
+++ b/icons/pair-update.svg
@@ -0,0 +1,110 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://web.resource.org/cc/"
+ 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:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+ width="42"
+ height="42"
+ id="svg2"
+ sodipodi:version="0.32"
+ inkscape:version="0.45.1"
+ version="1.0"
+ sodipodi:docname="pair-update.svg"
+ sodipodi:docbase="/home/msgodoi/olpc/workspace/Memorize.activity/images"
+ inkscape:output_extension="org.inkscape.output.svg.inkscape">
+ <defs
+ id="defs4" />
+ <sodipodi:namedview
+ id="base"
+ pagecolor="#ffffff"
+ bordercolor="#666666"
+ borderopacity="1.0"
+ gridtolerance="10000"
+ guidetolerance="10"
+ objecttolerance="10"
+ inkscape:pageopacity="0.0"
+ inkscape:pageshadow="2"
+ inkscape:zoom="1"
+ inkscape:cx="21"
+ inkscape:cy="21"
+ inkscape:document-units="px"
+ inkscape:current-layer="layer1"
+ width="42px"
+ height="42px"
+ inkscape:window-width="1432"
+ inkscape:window-height="871"
+ inkscape:window-x="4"
+ inkscape:window-y="25" />
+ <metadata
+ id="metadata7">
+ <rdf:RDF>
+ <cc:Work
+ rdf:about="">
+ <dc:format>image/svg+xml</dc:format>
+ <dc:type
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+ </cc:Work>
+ </rdf:RDF>
+ </metadata>
+ <g
+ inkscape:label="Layer 1"
+ inkscape:groupmode="layer"
+ id="layer1">
+ <rect
+ style="fill:#4c4d4f;fill-opacity:1;fill-rule:evenodd;stroke:#ffffff;stroke-width:3.5;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ id="rect7017"
+ width="30.046175"
+ height="30.046175"
+ x="1.9769126"
+ y="1.9769124"
+ ry="4.5299301" />
+ <rect
+ style="fill:#4c4d4f;fill-opacity:1;fill-rule:evenodd;stroke:#ffffff;stroke-width:3.5;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ id="rect3133"
+ width="30.046175"
+ height="30.046175"
+ x="9.9769125"
+ y="9.9769125"
+ ry="4.5299301" />
+ <g
+ id="g7384"
+ transform="matrix(0.7398804,-0.1417707,0.1417707,0.7398804,3.1769353,8.481073)">
+ <g
+ id="g8361"
+ style="fill:none;fill-opacity:1;stroke:#ffffff;stroke-width:1.32742107;stroke-linecap:round;stroke-opacity:1"
+ transform="matrix(-0.9813845,-0.1920532,0.1920532,-0.9813845,45.325983,56.360102)">
+ <path
+ style="fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#ffffff;stroke-width:2.65484214;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ d="M 17.241246,23.778211 C 18.873784,13.334226 32.631006,13.66595 33.910507,23.614787"
+ id="path8363"
+ sodipodi:nodetypes="cc" />
+ <path
+ style="fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#ffffff;stroke-width:2.65484214;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ d="M 14.571628,18.545494 L 17.02506,23.922425 L 22.654737,22.143297 L 22.654737,22.143297"
+ id="path8365" />
+ </g>
+ </g>
+ <g
+ id="g8380"
+ transform="matrix(-0.7454146,0.108991,-0.108991,-0.7454146,47.363957,41.428291)">
+ <g
+ id="g8382"
+ style="fill:none;fill-opacity:1;stroke:#ffffff;stroke-width:1.32742107;stroke-linecap:round;stroke-opacity:1"
+ transform="matrix(-0.9813845,-0.1920532,0.1920532,-0.9813845,45.325983,56.360102)">
+ <path
+ style="fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#ffffff;stroke-width:2.65484214;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ d="M 17.241246,23.778211 C 18.873784,13.334226 32.631006,13.66595 33.910507,23.614787"
+ id="path8384"
+ sodipodi:nodetypes="cc" />
+ <path
+ style="fill:none;fill-opacity:1;fill-rule:evenodd;stroke:#ffffff;stroke-width:2.65484214;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ d="M 14.571628,18.545494 L 17.02506,23.922425 L 22.654737,22.143297 L 22.654737,22.143297"
+ id="path8386" />
+ </g>
+ </g>
+ </g>
+</svg>
diff --git a/port/COPYING b/port/COPYING
new file mode 100644
index 0000000..623b625
--- /dev/null
+++ b/port/COPYING
@@ -0,0 +1,340 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ 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 Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) year name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ <signature of Ty Coon>, 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Library General
+Public License instead of this License.
diff --git a/port/README b/port/README
new file mode 100644
index 0000000..256200d
--- /dev/null
+++ b/port/README
@@ -0,0 +1,18 @@
+About
+-----
+
+A set of sugar components/libraries/etc to simplify writing activities.
+
+Cornerstone purposes for this project:
+* Total backwards compatibility for sugar-port API
+* Run on all sugar platforms beginning from 0.82
+
+In most cases sugar-port could be embedded to activity's directory tree.
+There is no need to include the whole sugar-port project only top level
+files/directories you are using directly - sugar-port's top level entities
+don't import each other.
+
+Get it
+------
+
+http://wiki.sugarlabs.org/go/Development_Team/sugar-port
diff --git a/port/__init__.py b/port/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/port/__init__.py
diff --git a/port/widgets.py b/port/widgets.py
new file mode 100644
index 0000000..9531c97
--- /dev/null
+++ b/port/widgets.py
@@ -0,0 +1,403 @@
+# 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
+import hippo
+import gobject
+import logging
+import math
+
+from sugar.graphics import style
+from sugar.graphics import palette
+from sugar.graphics import toolbutton
+from sugar.graphics import radiotoolbutton
+from sugar.graphics import icon
+from sugar.graphics import toggletoolbutton
+from sugar.graphics import combobox
+from sugar.graphics import roundbox
+
+def labelize(text, widget):
+ box = hippo.CanvasBox()
+ box.props.spacing = style.DEFAULT_SPACING
+
+ text = hippo.CanvasText(text=text)
+ text.props.color = style.COLOR_SELECTION_GREY.get_int()
+ if gtk.widget_get_default_direction() == gtk.TEXT_DIR_RTL:
+ text.props.xalign = hippo.ALIGNMENT_END
+ else:
+ text.props.xalign = hippo.ALIGNMENT_START
+ box.append(text)
+
+ box.append(widget, hippo.PACK_EXPAND)
+
+ return box
+
+class Entry(hippo.CanvasWidget):
+ def __init__(self, text=None, frame_color=style.COLOR_WHITE.get_gdk_color(),
+ **kwargs):
+ hippo.CanvasWidget.__init__(self, **kwargs)
+
+ self.entry = gtk.Entry()
+ self.entry.modify_bg(gtk.STATE_INSENSITIVE, frame_color)
+
+ self.props.widget = self.entry
+
+ if text:
+ self.text = text
+
+ def get_text(self):
+ return self.entry.props.text
+
+ def set_text(self, value):
+ self.entry.props.text = value
+
+ text = gobject.property(type=str, setter=set_text, getter=get_text)
+ text = property(get_text, set_text)
+
+class TextView(hippo.CanvasWidget):
+ def __init__(self, text=None, **kwargs):
+ hippo.CanvasWidget.__init__(self, **kwargs)
+
+ self.view = gtk.TextView()
+ self.view.props.left_margin = style.DEFAULT_SPACING
+ self.view.props.right_margin = style.DEFAULT_SPACING
+ self.view.props.wrap_mode = gtk.WRAP_WORD
+ self.view.props.accepts_tab = False
+ self.view.show()
+
+ scrolled_window = gtk.ScrolledWindow()
+ scrolled_window.set_shadow_type(gtk.SHADOW_OUT)
+ scrolled_window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
+ scrolled_window.add(self.view)
+
+ self.props.widget = scrolled_window
+
+ if text:
+ self.text = text
+
+ def get_text(self):
+ return self.view.props.buffer.props.text
+
+ def set_text(self, value):
+ self.view.props.buffer.props.text = value or ''
+
+ text = gobject.property(type=str, setter=set_text, getter=get_text)
+ text = property(get_text, set_text)
+
+class Image(hippo.CanvasWidget):
+ def __init__(self, pal=None, tooltip=None, pixbuf=None, **kwargs):
+ self.image = gtk.Image()
+ self._invoker = palette.CanvasInvoker()
+
+ hippo.CanvasBox.__init__(self, widget=self.image)
+
+ self._invoker._position_hint = self._invoker.AT_CURSOR
+ self._invoker.attach(self)
+
+ self.palette_class = None
+
+ self.connect('destroy', self._destroy_cb)
+
+ if pal:
+ self.palette = pal
+ if tooltip:
+ self.tooltip = tooltip
+ if pixbuf:
+ self.pixbuf = pixbuf
+
+ def _destroy_cb(self, widget):
+ if self._invoker is not None:
+ self._invoker.detach()
+
+ def create_palette(self):
+ if self.palette_class is None:
+ return None
+ if isinstance(self.palette_class, tuple):
+ return self.palette_class[0](*self.palette_class[1:])
+ else:
+ return self.palette_class()
+
+ def get_palette(self):
+ return self._invoker.palette
+
+ def set_palette(self, palette):
+ self._invoker.palette = palette
+
+ palette = gobject.property(type=object,
+ setter=set_palette, getter=get_palette)
+ palette = property(get_palette, set_palette)
+
+ def get_tooltip(self):
+ return self._invoker.palette and self._invoker.palette.primary_text
+
+ def set_tooltip(self, text):
+ self.set_palette(palette.Palette(text))
+
+ tooltip = gobject.property(type=str, setter=set_tooltip, getter=get_tooltip)
+ tooltip = property(get_tooltip, set_tooltip)
+
+ def set_pixbuf(self, value):
+ self.image.set_from_pixbuf(value)
+ self.props.box_width = value.get_width()
+ self.props.box_height = value.get_height()
+
+ pixbuf = gobject.property(type=object, setter=set_pixbuf, getter=None)
+ pixbuf = property(None, set_pixbuf)
+
+class ToolButton(toolbutton.ToolButton):
+ def __init__(self,
+ icon_name,
+ size=gtk.ICON_SIZE_SMALL_TOOLBAR,
+ padding=None,
+ **kwargs):
+
+ toolbutton.ToolButton.__init__(self, **kwargs)
+
+ image = icon.Icon(icon_name=icon_name, icon_size=size)
+ image.show()
+
+ # The alignment is a hack to work around gtk.ToolButton code
+ # that sets the icon_size when the icon_widget is a gtk.Image
+ alignment = gtk.Alignment(0.5, 0.5)
+ alignment.show()
+ alignment.add(image)
+
+ self.set_icon_widget(alignment)
+
+ sizes = { gtk.ICON_SIZE_SMALL_TOOLBAR: style.SMALL_ICON_SIZE,
+ gtk.ICON_SIZE_LARGE_TOOLBAR: style.STANDARD_ICON_SIZE }
+
+ if padding is not None and sizes.has_key(size):
+ button_size = sizes[size] + style.DEFAULT_SPACING + padding
+ self.set_size_request(button_size, button_size)
+
+class RadioToolButton(radiotoolbutton.RadioToolButton):
+ def __init__(self,
+ icon_name,
+ size=gtk.ICON_SIZE_SMALL_TOOLBAR,
+ padding=None,
+ **kwargs):
+
+ radiotoolbutton.RadioToolButton.__init__(self, **kwargs)
+
+ image = icon.Icon(icon_name=icon_name, icon_size=size)
+ image.show()
+
+ # The alignment is a hack to work around gtk.ToolButton code
+ # that sets the icon_size when the icon_widget is a gtk.Image
+ alignment = gtk.Alignment(0.5, 0.5)
+ alignment.show()
+ alignment.add(image)
+
+ self.set_icon_widget(alignment)
+
+ sizes = { gtk.ICON_SIZE_SMALL_TOOLBAR: style.SMALL_ICON_SIZE,
+ gtk.ICON_SIZE_LARGE_TOOLBAR: style.STANDARD_ICON_SIZE }
+
+ if padding is not None and sizes.has_key(size):
+ button_size = sizes[size] + style.DEFAULT_SPACING + padding
+ self.set_size_request(button_size, button_size)
+
+class ToolWidget(gtk.ToolItem):
+ def __init__(self, widget):
+ gtk.ToolItem.__init__(self)
+ self.add(widget)
+ widget.show()
+
+class ToggleToolButton(toggletoolbutton.ToggleToolButton):
+ def __init__(self, named_icon=None, tooltip=None, palette=None, **kwargs):
+ toggletoolbutton.ToggleToolButton.__init__(self, named_icon, **kwargs)
+
+ if tooltip:
+ self.set_tooltip(tooltip)
+ if palette:
+ self.set_palette(palette)
+
+class Palette(palette.Palette):
+ def __init__(self, **kwargs):
+ palette.Palette.__init__(self, **kwargs)
+
+ def popup(self, immediate=False, state=None):
+ if not self.props.invoker:
+ if _none_invoker.palette:
+ _none_invoker.palette.popdown(immediate=True)
+ _none_invoker.palette = self
+ self.props.invoker = _none_invoker
+ palette.Palette.popup(self, immediate, state)
+
+class _NoneInvoker(palette.Invoker):
+ def __init__(self):
+ palette.Invoker.__init__(self)
+ self._position_hint = palette.Invoker.AT_CURSOR
+
+ def get_rect(self):
+ return gtk.gdk.Rectangle(0, 0, 0, 0)
+
+ def get_toplevel(self):
+ return None
+
+_none_invoker = _NoneInvoker()
+
+class ComboBox(combobox.ComboBox):
+ def __init__(self, **kwargs):
+ combobox.ComboBox.__init__(self, **kwargs)
+
+ def select(self, id=None, name=None):
+ if id is not None:
+ column = 0
+ value = id
+ elif name is not None:
+ column = 1
+ value = name
+ else:
+ return
+
+ for i, item in enumerate(self.get_model()):
+ if item[column] != value:
+ continue
+ self.set_active(i)
+ break
+
+ def append_item(self, action_id, text, icon_name=None, file_name=None):
+ item = self._item_new(action_id, text, icon_name, file_name)
+ self.get_model().append(item)
+
+ def set_item(self, action_id, text=None, icon_name=None, file_name=None):
+ for i, value in enumerate(self.get_model()):
+ if value[0] == action_id:
+ item = self._item_new(action_id, text, icon_name, file_name)
+ iter = self.get_model().iter_nth_child(None, i)
+ if text is not None:
+ self.get_model().set(iter, 1, item[1])
+ if icon_name is not None or file_name is not None:
+ self.get_model().set(iter, 2, item[2])
+ return True
+ return False
+
+ def _item_new(self, action_id, text, icon_name, file_name):
+ if not self._icon_renderer and (icon_name or file_name):
+ self._icon_renderer = gtk.CellRendererPixbuf()
+
+ settings = self.get_settings()
+ w, h = gtk.icon_size_lookup_for_settings(
+ settings, gtk.ICON_SIZE_MENU)
+ self._icon_renderer.props.stock_size = max(w, h)
+
+ self.pack_start(self._icon_renderer, False)
+ self.add_attribute(self._icon_renderer, 'pixbuf', 2)
+
+ if not self._text_renderer and text:
+ self._text_renderer = gtk.CellRendererText()
+ self.pack_end(self._text_renderer, True)
+ self.add_attribute(self._text_renderer, 'text', 1)
+
+ if icon_name or file_name:
+ if text:
+ size = gtk.ICON_SIZE_MENU
+ else:
+ size = gtk.ICON_SIZE_LARGE_TOOLBAR
+ width, height = gtk.icon_size_lookup(size)
+
+ if icon_name:
+ file_name = self._get_real_name_from_theme(icon_name, size)
+
+ pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(
+ file_name, width, height)
+ else:
+ pixbuf = None
+
+ return (action_id, text, pixbuf, False)
+
+class ToolComboBox(gtk.ToolItem):
+ __gproperties__ = {
+ 'label-text' : (str, None, None, None,
+ gobject.PARAM_WRITABLE),
+ }
+
+ def __init__(self, combo=None, **kwargs):
+ self.label = None
+ self._label_text = ''
+
+ gobject.GObject.__init__(self, **kwargs)
+
+ self.set_border_width(style.DEFAULT_PADDING)
+
+ hbox = gtk.HBox(False, style.DEFAULT_SPACING)
+
+ self.label = gtk.Label(self._label_text)
+ hbox.pack_start(self.label, False)
+ self.label.show()
+
+ if combo:
+ self.combo = combo
+ else:
+ self.combo = ComboBox()
+
+ hbox.pack_start(self.combo)
+ self.combo.show()
+
+ self.add(hbox)
+ hbox.show()
+
+ def do_set_property(self, pspec, value):
+ if pspec.name == 'label-text':
+ self._label_text = value
+ if self.label:
+ self.label.set_text(self._label_text)
+
+class CanvasRoundBox(roundbox.CanvasRoundBox):
+ def __init__(self, radius=style.zoom(10), **kwargs):
+ hippo.CanvasBox.__init__(self, **kwargs)
+ self.set_radius(radius)
+
+ def get_radius(self):
+ return self._radius
+
+ def set_radius(self, radius):
+ self._radius = radius
+ self.props.border_left = radius
+ self.props.border_right = radius
+
+ radius = property(get_radius, set_radius)
+
+ def do_paint_background(self, cr, damaged_box):
+ [width, height] = self.get_allocation()
+
+ cr.rectangle(0, 0, width, height)
+ hippo.cairo_set_source_rgba32(cr, self.props.background_color)
+ cr.fill()
+
+ x = self.props.border_top/2
+ y = self.props.border_top/2
+ width -= self.props.border_top
+ height -= self.props.border_top
+
+ cr.move_to(x + self._radius, y)
+ cr.arc(x + width - self._radius, y + self._radius,
+ self._radius, math.pi * 1.5, math.pi * 2)
+ cr.arc(x + width - self._radius, x + height - self._radius,
+ self._radius, 0, math.pi * 0.5)
+ cr.arc(x + self._radius, y + height - self._radius,
+ self._radius, math.pi * 0.5, math.pi)
+ cr.arc(x + self._radius, y + self._radius, self._radius,
+ math.pi, math.pi * 1.5)
+
+ hippo.cairo_set_source_rgba32(cr, self.props.background_color)
+ cr.fill_preserve()
+
+ # TODO: we should be more consistent here with the border properties.
+ if self.props.border_color:
+ hippo.cairo_set_source_rgba32(cr, self.props.border_color)
+ cr.set_line_width(self.props.border_top)
+ cr.stroke()
diff --git a/reviewpanel.py b/reviewpanel.py
new file mode 100644
index 0000000..a65c855
--- /dev/null
+++ b/reviewpanel.py
@@ -0,0 +1,308 @@
+# -*- coding: utf-8 -*-
+#Copyright (c) 2010, Kirk Winans
+
+# 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
+from os import environ
+from os.path import join, basename
+import hippo
+
+import shutil
+import tempfile
+from gettext import gettext as _
+import logging
+from gobject import SIGNAL_RUN_FIRST, TYPE_PYOBJECT
+from sugar.graphics import style
+from sugar.graphics.toolbutton import ToolButton
+from sugar.graphics.icon import Icon
+from sugar.graphics.palette import Palette
+from port.widgets import ToggleToolButton
+from port.widgets import CanvasRoundBox, ToolComboBox
+#from port import chooser
+
+from sugar.datastore import datastore
+import xml.etree.ElementTree
+from datetime import date
+import time
+_logger = logging.getLogger("test-activity")
+
+_1_DAY = 60 * 60 * 24
+_2_DAYS = _1_DAY * 2
+_4_DAYS = _2_DAYS * 2
+_1_WEEK = _1_DAY * 7
+_2_WEEKS = _1_WEEK * 2
+_1_MONTH = _2_WEEKS * 2
+
+#
+# Review Panel for the Flashcard Activity
+#
+class ReviewPanel(gtk.VBox):
+
+ def __init__(self, box, catagory, expired_only):
+ gtk.VBox.__init__(self)
+
+ self.catagory = catagory
+ self.box_number = self.get_box_number(box)
+ self.expired_only = expired_only
+
+ self.view_box = gtk.HBox()
+ self.entry_box = gtk.HBox()
+ self.button_box = gtk.HButtonBox()
+ self.answer_box = gtk.HBox()
+
+ self.frontlabel = gtk.Label(_('Front:'))
+
+ self.viewcard = gtk.TextView()
+ self.textbuffer = self.viewcard.get_buffer()
+ self.viewcard.set_editable(False)
+ self.viewcard.set_wrap_mode(gtk.WRAP_WORD)
+ self.viewcard.set_justification(gtk.JUSTIFY_CENTER)
+ self.viewcard.set_pixels_above_lines(40)
+
+ self.entrylabel = gtk.Label(_('Back:'))
+
+ self.answer_entry = gtk.Entry()
+
+ self.answerlabel = gtk.Label(_('The answer was:'))
+
+ self.correct = gtk.TextView()
+ self.correcttextbuffer = self.correct.get_buffer()
+ self.correct.set_editable(False)
+ self.correct.set_wrap_mode(gtk.WRAP_WORD)
+ self.correct.set_justification(gtk.JUSTIFY_CENTER)
+ self.correct.set_pixels_above_lines(40)
+
+ _checkbutton = ToolButton(tooltip=_('Check Answer!'))
+ _checkbutton.connect('clicked', self._check_answer_cb)
+ _checkbutton.set_icon_widget(
+ self.make_label('next', ' ' + _('Check Answer!')))
+
+ self.view_box.pack_start(self.frontlabel)
+ self.view_box.pack_start(self.viewcard)
+
+ self.entry_box.pack_start(self.entrylabel)
+ self.entry_box.pack_start(self.answer_entry)
+
+ self.button_box.pack_start(_checkbutton)
+
+ self.answer_box.pack_start(self.answerlabel)
+ self.answer_box.pack_start(self.correct)
+
+
+ self.pack_start(self.view_box)
+ self.pack_start(self.entry_box)
+ self.pack_start(self.answer_box)
+ self.pack_start(self.button_box)
+
+ self.frontlabel.show()
+ self.viewcard.show()
+
+ self.entrylabel.show()
+ self.answer_entry.show()
+
+ self.answerlabel.show()
+ self.correct.show()
+
+ _checkbutton.show()
+
+ self.view_box.show()
+ self.entry_box.show()
+ self.answer_box.show()
+ self.button_box.show()
+
+ self.current_date = time.time()
+
+ self.testfile = "testfile.xml"
+
+ self.tree = xml.etree.ElementTree.parse(self.testfile)
+
+ self.deck = self.get_selected_deck()
+
+ self.current_card_index = 0
+
+ self.card = self.next_card()
+
+ self.textbuffer.set_text(self.card.find("front").text)
+
+ # Returns the box number of the selected box
+ def get_box_number(self, box):
+ if box == "Every Day":
+ return "0"
+ elif box == "Every 2 Days":
+ return "1"
+ elif box == "Every 4 Days":
+ return "2"
+ elif box == "Every Week":
+ return "3"
+ elif box == "Every 2 Weeks":
+ return "4"
+ elif box == "Every Month":
+ return "5"
+ else:
+ return box
+
+
+ # Check answer callback
+ def _check_answer_cb(self, button):
+ self.correcttextbuffer.set_text(self.check_answer())
+ self.answer_entry.set_text("")
+ self.card = self.next_card()
+ self.textbuffer.set_text(self.card.find("front").text)
+
+
+ # Checks the answer submitted, returns "Correct" or the back of the card
+ def check_answer(self):
+ if self.answer_entry.get_text() == self.card.find("back").text:
+ if self.expired_only:
+ new_stage = int(self.card.find("stage").text) + 1
+ self.update_card(new_stage)
+ return "Correct!"
+
+ else:
+ if self.expired_only:
+ self.update_card(0)
+ return self.card.find("back").text
+
+ # Returns the selected deck, based on expiration,
+ # the box, and the category
+ def get_selected_deck(self):
+ if self.expired_only:
+ selected_deck = self.get_all_expired()
+
+ else:
+ selected_deck = self.tree.getroot()
+
+ selected_deck = self.get_selected_box(selected_deck)
+
+ selected_deck = self.get_selected_catagory(selected_deck)
+
+ return selected_deck
+
+
+ # Returns all the expired cards
+ def get_all_expired(self):
+ deck = self.tree.getroot()
+ expired_deck = []
+ for card in deck:
+ if self.card_is_expired(card):
+ expired_deck = expired_deck + [card]
+ return expired_deck
+
+ # Returns True if the card is expired
+ def card_is_expired(self, card):
+ card_stage = card.find("stage").text
+ card_date = float(card.find("last_reviewed").text)
+ date_difference = self.current_date - card_date
+ if (card_stage == "0") and (date_difference > _1_DAY):
+ return True
+
+ elif (card_stage == "1") and (date_difference > _2_DAYS):
+ return True
+
+ elif (card_stage == "2") and (date_difference > _4_DAYS):
+ return True
+
+ elif (card_stage == "3") and (date_difference > _1_WEEK):
+ return True
+
+ elif (card_stage == "4") and (date_difference > _2_WEEKS):
+ return True
+
+ elif (card_stage == "5") and (date_differnce > _1_MONTH):
+ return True
+
+ else:
+ return False
+
+ # Modifies the deck for the selected box, returns the deck
+ def get_selected_box(self, selected_deck):
+ if self.box_number != "All":
+ selected_box = []
+ for card in selected_deck:
+ if card.find("stage").text == self.box_number:
+ selected_box = selected_box + [card]
+ return selected_box
+ else:
+ return selected_deck
+
+ # Modifies the deck for teh selected category, returns the deck
+ def get_selected_catagory(self, selected_deck):
+ catagory_deck = []
+ if self.catagory != "All":
+ for card in selected_deck:
+ if card.find("catagory").text == self.catagory:
+ catagory_deck = catagory_deck + [card]
+ return catagory_deck
+ else:
+ return selected_deck
+
+ # returns the next card to be reviewed, if there are no more,
+ # returns an empty card
+ def next_card(self):
+ if len(self.deck) > 0 and self.current_card_index < len(self.deck):
+ next_card = self.deck[self.current_card_index]
+
+ self.current_card_index += 1
+
+ return next_card
+
+ else:
+ return self.gen_empty_card()
+
+
+ # Returns an empty card that states there are no Cards to Review
+ def gen_empty_card(self):
+
+ empty_card = xml.etree.ElementTree.Element("card")
+
+ e_c_front = xml.etree.ElementTree.Element("front")
+ e_c_back = xml.etree.ElementTree.Element("back")
+ e_c_last = xml.etree.ElementTree.Element("last_reviewed")
+ e_c_stage = xml.etree.ElementTree.Element("stage")
+ e_c_catagory = xml.etree.ElementTree.Element("catagory")
+
+ e_c_front.text = "No Cards to Review!"
+ e_c_back.text = "None"
+ e_c_last.text = str(time.time())
+ e_c_stage.text = "0"
+ e_c_catagory.text = "None"
+
+ empty_card.append(e_c_front)
+ empty_card.append(e_c_back)
+ empty_card.append(e_c_last)
+ empty_card.append(e_c_stage)
+ empty_card.append(e_c_catagory)
+
+ return empty_card
+
+ # updates the card after it has been reviewed to reflect
+ # the new box and its last reviewed date
+ def update_card(self, stage):
+
+ self.card.find("last_reviewed").text = str(time.time())
+ self.card.find("stage").text = str(stage)
+
+ self.tree.write(self.testfile)
+
+ # Gets the icon for the button and makes the label
+ # Written by Simon Schampijer
+ def make_label(self, icon_name, label):
+ label_box = gtk.HBox()
+ icon = Icon(
+ icon_name=icon_name,
+ icon_size=gtk.ICON_SIZE_LARGE_TOOLBAR)
+ label_box.pack_start(icon, False)
+ label = gtk.Label(label)
+ label.modify_fg(gtk.STATE_NORMAL,
+ style.COLOR_TOOLBAR_GREY.get_gdk_color())
+ label_box.pack_start(label)
+ label_box.show_all()
+ return label_box
diff --git a/reviewselection.py b/reviewselection.py
new file mode 100644
index 0000000..b3c2307
--- /dev/null
+++ b/reviewselection.py
@@ -0,0 +1,161 @@
+# -*- coding: utf-8 -*-
+#Copyright (c) 2010, Kirk Winans
+
+# 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
+from os import environ
+from os.path import join, basename
+import hippo
+
+import shutil
+import tempfile
+from gettext import gettext as _
+import logging
+from gobject import SIGNAL_RUN_FIRST, TYPE_PYOBJECT
+from sugar.graphics import style
+from sugar.graphics.toolbutton import ToolButton
+from sugar.graphics.icon import Icon
+from sugar.graphics.palette import Palette
+from port.widgets import ToggleToolButton
+from port.widgets import CanvasRoundBox, ToolComboBox
+#from port import chooser
+
+from sugar.datastore import datastore
+import xml.etree.ElementTree
+from datetime import date
+import time
+_logger = logging.getLogger("test-activity")
+
+from gettext import gettext as _
+
+
+
+#
+# Review Selection Panel for Flashcard Activity
+#
+class ReviewSelection(gtk.VBox):
+
+ def __init__(self, activity_root):
+ gtk.VBox.__init__(self)
+
+ self.activity_root = activity_root
+
+ self.box_selection_box = gtk.HBox()
+
+ self.catagory_selection_box = gtk.HBox()
+
+ self.box_label = gtk.Label(_('Select Box:'))
+
+ self.box_selection = gtk.ComboBoxEntry()
+
+ self.box_selection = gtk.combo_box_new_text()
+
+ self.catagory_label = gtk.Label(_('Select Category:'))
+
+ self.catagory_selection = gtk.ComboBoxEntry()
+
+ self.catagory_selection = gtk.combo_box_new_text()
+
+ self.expired = gtk.CheckButton(_("Review Only Expired Cards"))
+
+ self.expired.set_active(True)
+
+ self.cardfile = "testfile.xml"
+
+ self.tree = xml.etree.ElementTree.parse(self.cardfile)
+
+ boxes = self.get_boxes()
+
+ catagories = self.get_catagories()
+
+ # Sets text for dropdown menus
+ for text in boxes:
+ self.box_selection.append_text(text)
+
+ for text in catagories:
+ self.catagory_selection.append_text(text)
+
+ self.box_selection.set_active(0)
+
+ self.catagory_selection.set_active(0)
+
+ self.box_selection_box.pack_start(self.box_label)
+
+ self.box_selection_box.pack_start(self.box_selection)
+
+ self.catagory_selection_box.pack_start(self.catagory_label)
+
+ self.catagory_selection_box.pack_start(self.catagory_selection)
+
+ self.add(self.box_selection_box)
+
+ self.add(self.catagory_selection_box)
+
+ self.add(self.expired)
+
+ self.box_selection.show()
+
+ self.catagory_selection.show()
+
+ self.box_selection_box.show()
+
+ self.box_label.show()
+
+ self.catagory_selection_box.show()
+
+ self.catagory_label.show()
+
+ self.expired.show()
+
+ # Returns name of selected box
+ def get_selected_box(self):
+ return self.box_selection.get_active_text()
+
+ # Returns name of selected category
+ def get_selected_catagory(self):
+ return self.catagory_selection.get_active_text()
+
+ # Returns the time boxes
+ def get_boxes(self):
+ boxes = ["All", "Every Day", "Every 2 Days", "Every 4 Days",
+ "Every Week", "Every 2 Weeks", "Every Month"]
+ return boxes
+
+ # Returns the categories available
+ def get_catagories(self):
+ deck = self.tree.getroot()
+ card_catagories = []
+ card_catagories = card_catagories + ["All"]
+ for card in deck:
+ card_catagories = card_catagories + [card.find("catagory").text]
+
+ card_catagories = set(card_catagories)
+ card_catagories = list(card_catagories)
+
+ card_catagories = self.move_all(sorted(card_catagories))
+
+ return card_catagories
+
+ # Returns True if only the expired cards are seleceted
+ def get_expired_only(self):
+ return self.expired.get_active()
+
+ # Moves the All option to top of the list and default selected
+ def move_all(self, catagories):
+
+ for idx in range(len(catagories)):
+ if catagories[idx] == "All":
+ catagories[idx] = catagories[0]
+ catagories[0] = "All"
+
+ return catagories
+
+
diff --git a/setup.py b/setup.py
new file mode 100755
index 0000000..bd1e319
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,5 @@
+#!/usr/bin/env python
+from sugar.activity import bundlebuilder
+if __name__ == "__main__":
+ bundlebuilder.start()
+
diff --git a/testfile.xml b/testfile.xml
new file mode 100644
index 0000000..1b2f3d3
--- /dev/null
+++ b/testfile.xml
@@ -0,0 +1,51 @@
+<deck> Test Deck
+ <card>
+ <front>date</front>
+ <back>work</back>
+ <last_reviewed>1280767905.54</last_reviewed>
+ <stage>0</stage>
+ <catagory>thanks</catagory>
+ </card>
+ <card>
+ <front>Edit</front>
+ <back>works</back>
+ <last_reviewed>1280767937.74</last_reviewed>
+ <stage>0</stage>
+ <catagory>thanks</catagory>
+ </card>
+ <card>
+ <front>Clearing</front>
+ <back>Text Boxes</back>
+ <last_reviewed>1280767944.82</last_reviewed>
+ <stage>0</stage>
+ <catagory>Works</catagory>
+ </card>
+ <card>
+ <front>Clear</front>
+ <back>Entry</back>
+ <last_reviewed>1280767951.73</last_reviewed>
+ <stage>0</stage>
+ <catagory>test</catagory>
+ </card>
+ <card>
+ <front>front</front>
+ <back>back</back>
+ <last_reviewed>1280253050.31</last_reviewed>
+ <stage>3</stage>
+ <catagory>catagory</catagory>
+ </card>
+ <card>
+ <front>time</front>
+ <back>stamp</back>
+ <last_reviewed>1279823320.53</last_reviewed>
+ <stage>2</stage>
+ <catagory>works</catagory>
+ </card>
+ <card>
+ <front>timestap</front>
+ <back>becomes date</back>
+ <last_reviewed>1280767959.74</last_reviewed>
+ <stage>0</stage>
+ <catagory>why?</catagory>
+ </card>
+</deck> \ No newline at end of file