From 6b6d0f70637c922c9576366d38e5a05dc07c8aa5 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Savard Date: Sat, 25 Apr 2009 02:36:54 +0000 Subject: [LP 341760] Serializer : Completed XML serializer and working save/load tests in serializertests.py --- (limited to 'src') diff --git a/src/sugar/activity/activity.py b/src/sugar/activity/activity.py index a5188fd..3e2d3d4 100644 --- a/src/sugar/activity/activity.py +++ b/src/sugar/activity/activity.py @@ -77,6 +77,7 @@ from sugar.datastore import datastore from sugar.session import XSMPClient from sugar import wm from sugar.tutorius.services import ObjectStore +from sugar.tutorius.tutoserialize import TutoSerializer _ = lambda msg: gettext.dgettext('sugar-toolkit', msg) @@ -128,15 +129,14 @@ class ActivityToolbar(gtk.Toolbar): self.tutorials.combo.connect('changed', self.__tutorial_changed_cb) # Get tutorial list by file logging.debug("************************************ before creating serialize") -## serialize = TutoSerializer() -## logging.debug("************************************ before calling load_tuto_list()") -## -## #tutorials = self._activity.get_tutorials() -## if getattr(self._activity,"_tutorials",None) is None: -## tutorials = serialize.load_tuto_list() + serialize = TutoSerializer() + logging.debug("************************************ before calling load_tuto_list()") + + #tutorials = self._activity.get_tutorials() + if getattr(self._activity,"_tutorials",None) is None: + tutorials = serialize.load_tuto_list() self._current_tutorial = None - tutorials = None if tutorials: for key, tutorial in tutorials.items(): # self.tutorials.combo.append_item(key, _(tutorial.name)) diff --git a/src/sugar/tutorius/Makefile.am b/src/sugar/tutorius/Makefile.am index 8805314..0632e47 100644 --- a/src/sugar/tutorius/Makefile.am +++ b/src/sugar/tutorius/Makefile.am @@ -1,3 +1,5 @@ +SUBDIRS = uam + sugardir = $(pythondir)/sugar/tutorius sugar_PYTHON = \ __init__.py \ @@ -9,5 +11,8 @@ sugar_PYTHON = \ services.py \ overlayer.py \ editor.py \ - linear_creator.py\ + linear_creator.py \ + constraints.py \ + properties.py \ + tutoserialize.py \ bundler.py diff --git a/src/sugar/tutorius/actions.py b/src/sugar/tutorius/actions.py index 2dca6c7..2d630be 100644 --- a/src/sugar/tutorius/actions.py +++ b/src/sugar/tutorius/actions.py @@ -23,12 +23,13 @@ from dialog import TutoriusDialog import overlayer from sugar.tutorius.editor import WidgetIdentifier from sugar.tutorius.services import ObjectStore - +from sugar.tutorius.properties import * class Action(object): """Base class for Actions""" def __init__(self): object.__init__(self) + self.properties = None def do(self, **kwargs): """ @@ -43,12 +44,17 @@ class Action(object): pass #Should raise NotImplemented? def get_properties(self): - if not hasattr(self, "_props") or self._props is None: - self._props = [] - for i in dir(self.__class__): - if type(getattr(self.__class__,i)) is property: - self._props.append(i) - return self._props + """ + Fills self.property with a dict of TutoriusProperty and return the list + of property names. get_properties has to be called before accessing + self.property + """ + if self.properties is None: + self.properties = {} + for i in dir(self): + if isinstance(getattr(self,i), TutoriusProperty): + self.properties[i] = getattr(self,i) + return self.properties.keys() class OnceWrapper(object): """ @@ -89,36 +95,21 @@ class DialogMessage(Action): @param message A string to display to the user @param pos A list of the form [x, y] """ - def __init__(self, message, pos=[0,0]): + def __init__(self, message, pos=None): super(DialogMessage, self).__init__() - self._message = message - self._position = pos self._dialog = None - - def set_message(self, msg): - self._message = msg - def get_message(self): - return self._message - - message = property(fget=get_message, fset=set_message) - - def set_pos(self, x, y): - self._position = [x, y] - - def get_pos(self): - return self._position - - position = property(fget=get_pos, fset=set_pos) + self.message = TStringProperty(message) + self.position = TArrayProperty(pos or [0, 0], 2, 2) def do(self): """ Show the dialog """ - self._dialog = TutoriusDialog(self._message) + self._dialog = TutoriusDialog(self.message.value) self._dialog.set_button_clicked_cb(self._dialog.close_self) self._dialog.set_modal(False) - self._dialog.move(self.position[0], self.position[1]) + self._dialog.move(self.position.value[0], self.position.value[1]) self._dialog.show() def undo(self): @@ -137,34 +128,20 @@ class BubbleMessage(Action): @param message A string to display to the user @param pos A list of the form [x, y] @param speaker treeish representation of the speaking widget + @param tailpos The position of the tail of the bubble; useful to point to + specific elements of the interface """ def __init__(self, message, pos=[0,0], speaker=None, tailpos=None): Action.__init__(self) - self._message = message - self._position = pos - + self.message = TStringProperty(message) + # Create the position as an array of fixed-size 2 + self.position = TArrayProperty(pos, 2, 2) + # Do the same for the tail position + self.tail_pos = TArrayProperty(tailpos, 2, 2) + self.overlay = None self._bubble = None self._speaker = None - self._tailpos = tailpos - - def set_message(self, msg): - self._message = msg - def get_message(self): - return self._message - message = property(fget=get_message, fset=set_message, doc="Message displayed to the user") - - def set_pos(self, x, y): - self._position = [x, y] - def get_pos(self): - return self._position - position = property(fget=get_pos, fset=set_pos, doc="Position in [x, y] on the screen") - - def set_tail_pos(self, x, y): - self._tailpos = [x, y] - def get_tail_pos(self): - return self._tailpos - tail_pos = property(fget=get_tail_pos, fset=set_tail_pos, doc="Position the tail of the bubble must point to") def do(self): """ @@ -245,53 +222,54 @@ class DisableWidgetAction(Action): self._widget = gtkutils.find_widget(os.activity, self._target) if self._widget: self._widget.set_sensitive(False) - - def undo(self): + + def undo(self): """Action undo""" if self._widget: self._widget.set_sensitive(True) - + + class TypeTextAction(Action): - """ + """ Simulate a user typing text in a widget Work on any widget that implements a insert_text method - + @param widget The treehish representation of the widget @param text the text that is typed - """ + """ def __init__(self, widget, text): Action.__init__(self) - + self._widget = widget self._text = text - + def do(self, **kwargs): - """ - Type the text - """ + """ + Type the text + """ widget = gtkutils.find_widget(ObjectStore().activity, self._widget) if hasattr(widget, "insert_text"): widget.insert_text(self._text, -1) - - def undo(self): - """ - no undo - """ - pass - + + def undo(self): + """ + no undo + """ + pass + class ClickAction(Action): - """ + """ Action that simulate a click on a widget Work on any widget that implements a clicked() method - + @param widget The threehish representation of the widget - """ + """ def __init__(self, widget): Action.__init__(self) self._widget = widget - - def do(self): - """ + + def do(self): + """ click the widget """ widget = gtkutils.find_widget(ObjectStore().activity, self._widget) @@ -303,3 +281,4 @@ class ClickAction(Action): No undo """ pass + diff --git a/src/sugar/tutorius/bundler.py b/src/sugar/tutorius/bundler.py index d9d06bb..58288ca 100644 --- a/src/sugar/tutorius/bundler.py +++ b/src/sugar/tutorius/bundler.py @@ -24,7 +24,6 @@ import logging import os import uuid import xml.dom.minidom -#import xml.dom.ext from sugar.tutorius import gtkutils, overlayer from sugar.tutorius.core import Tutorial, State, FiniteStateMachine diff --git a/src/sugar/tutorius/tests/run-tests.py b/src/sugar/tutorius/tests/run-tests.py index 6f22fee..97665f7 100755 --- a/src/sugar/tutorius/tests/run-tests.py +++ b/src/sugar/tutorius/tests/run-tests.py @@ -10,10 +10,17 @@ sys.path.insert(0, ) FULL_PATH = os.path.join(INSTALL_PATH,"sugar/tutorius") +SUBDIRS = ["uam"] GLOB_PATH = os.path.join(FULL_PATH,"*.py") import unittest from glob import glob +def report_files(): + ret = glob(GLOB_PATH) + for dir in SUBDIRS: + ret += glob(os.path.join(FULL_PATH,dir,"*.py")) + return ret + import sys if __name__=='__main__': if "--coverage" in sys.argv: @@ -28,26 +35,41 @@ if __name__=='__main__': import gtkutilstests import overlaytests import linear_creatortests + import actiontests + import uamtests + import filterstests + import constraintstests + import propertiestests import serializertests - suite = unittest.TestSuite() suite.addTests(unittest.findTestCases(coretests)) suite.addTests(unittest.findTestCases(servicestests)) suite.addTests(unittest.findTestCases(gtkutilstests)) suite.addTests(unittest.findTestCases(overlaytests)) suite.addTests(unittest.findTestCases(linear_creatortests)) - suite.addTests(unittest.findTestCases(serializertests)) - + suite.addTests(unittest.findTestCases(actiontests)) + suite.addTests(unittest.findTestCases(uamtests)) + suite.addTests(unittest.findTestCases(filterstests)) + suite.addTests(unittest.findTestCases(constraintstests)) + suite.addTests(unittest.findTestCases(propertiestests)) + suite.addTests(unittest.findTestCases(serializertests)) runner = unittest.TextTestRunner() runner.run(suite) coverage.stop() - coverage.report(glob(GLOB_PATH)) + coverage.report(report_files()) coverage.erase() else: from coretests import * from servicestests import * from gtkutilstests import * from overlaytests import * + from actiontests import * + from linear_creatortests import * + from uamtests import * + from filterstests import * + from constraintstests import * + from propertiestests import * + from actiontests import * from serializertests import * unittest.main() -- cgit v0.9.1