From 6a390f667cca2b78ede0db7ca4877201462b886e Mon Sep 17 00:00:00 2001 From: mike Date: Thu, 19 Nov 2009 14:38:39 +0000 Subject: LP 448319 : Addition of resource properties, insertion of BubbleMessageWImg from Dave, modification of Engine to get action_addresses --- (limited to 'tutorius/properties.py') diff --git a/tutorius/properties.py b/tutorius/properties.py index aab6a0c..a462782 100644 --- a/tutorius/properties.py +++ b/tutorius/properties.py @@ -24,7 +24,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, \ @@ -96,6 +98,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. @@ -284,6 +301,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 -- cgit v0.9.1