diff options
author | mike <michael.jmontcalm@gmail.com> | 2009-12-01 20:11:43 (GMT) |
---|---|---|
committer | mike <michael.jmontcalm@gmail.com> | 2009-12-01 20:11:43 (GMT) |
commit | 2c8fe66c0f7490c8aaaae27b4977b987001c6b71 (patch) | |
tree | 32d4ce390d853fb5a8405e71cfb37b6b52988e3b /tutorius/properties.py | |
parent | b7586af9d127e7954674d13ea185a0e84d197c37 (diff) | |
parent | 50ec9ae6ebc7ecc088b5e0a6b79688a717271955 (diff) |
Merge branch 'master' of git://git.sugarlabs.org/tutorius/simpoirs-clone
Conflicts:
src/extensions/tutoriusremote.py
tutorius/TProbe.py
tutorius/creator.py
Diffstat (limited to 'tutorius/properties.py')
-rw-r--r-- | tutorius/properties.py | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/tutorius/properties.py b/tutorius/properties.py index 01cd2c0..cc76748 100644 --- a/tutorius/properties.py +++ b/tutorius/properties.py @@ -25,7 +25,9 @@ from copy import copy, deepcopy from .constraints import Constraint, \ UpperLimitConstraint, LowerLimitConstraint, \ MaxSizeConstraint, MinSizeConstraint, \ - ColorConstraint, FileConstraint, BooleanConstraint, EnumConstraint + ColorConstraint, FileConstraint, BooleanConstraint, EnumConstraint, \ + ResourceConstraint + from .propwidgets import PropWidget, \ StringPropWidget, \ UAMPropWidget, \ @@ -99,6 +101,21 @@ class TPropContainer(object): except AttributeError: return object.__setattr__(self, name, value) + def replace_property(self, prop_name, new_prop): + """ + Changes the content of a property. This is done in order to support + the insertion of executable properties in the place of a portable + property. The typical exemple is that a resource property needs to + be changed into a file property with the correct file name, since the + installation location will be different on every platform. + + @param prop_name The name of the property to be changed + @param new_prop The new property to insert + @raise AttributeError of the mentionned property doesn't exist + """ + props = object.__getattribute__(self, "_props") + props.__setitem__(prop_name, new_prop) + def get_properties(self): """ Return the list of property names. @@ -289,6 +306,37 @@ class TFileProperty(TutoriusProperty): self.default = self.validate(path) +class TResourceProperty(TutoriusProperty): + """ + Represents a resource in the tutorial. A resource is a file with a specific + name that exists under the tutorials folder. It is distributed alongside the + tutorial itself. + + When the system encounters a resource, it knows that it refers to a file in + the resource folder and that it should translate this resource name to an + absolute file name before it is executed. + + E.g. An image is added to a tutorial in an action. On doing so, the creator + adds a resource to the tutorial, then saves its name in the resource + property of that action. When this tutorial is executed, the Engine + replaces all the TResourceProperties inside the action by their equivalent + TFileProperties with absolute paths, so that they can be used on any + machine. + """ + def __init__(self, resource_name=""): + """ + Creates a new resource pointing to an existing resource. + + @param resource_name The file name of the resource (should be only the + file name itself, no directory information) + """ + TutoriusProperty.__init__(self) + self.type = "resource" + + self.resource_cons = ResourceConstraint() + + self.default = self.validate("") + class TEnumProperty(TutoriusProperty): """ Represents a value in a given enumeration. This means that the value will |