def do_shopping(): b = das.make_default("shopping.basket") b.items.append(das.make("shopping.item", name="carottes", value=110)) b.items.append(das.make("shopping.item", name="meat", value=320)) das.pprint(b) for c in ["yen", "euro", "dollar"]: print("%f %s(s)" % (b.value_in(c), c))
def print_types(): print("=== Print default for all 'hud' schema types") stl = das.list_schema_types("hud") for st in stl: print("=== %s" % st) v = das.make_default(st) print(type(v).__name__) das.pprint(v) if hasattr(v, "_schema_type"): print(v._schema_type)
def do_multior(): b = das.make_default("multior.Parameter") das.pprint(b) b.min = 1 b.max = 10.0 b.softMin = False b.softMax = "hello" try: b.min = [0] except: pass das.pprint(b) print(b._get_schema_type()) print(das.get_schema_type("multior.Value"))
def name_conflicts(): print("=== Name conflict resolution ===") d = das.make_default("conflicts.DictMethod") das.pprint(d) print("keys = %s" % d.keys) print("_keys() -> %s" % d._keys()) print("values = %s" % d.values) print("_values() -> %s" % d._values()) print("items() -> %s" % d.items()) for k, v in d.items(): print("%s = %s" % (k, v)) das.pprint(d) d._clear() das.pprint(d)
def test_mixin1(): print("=== Mixin tests using timeline.ClipSource schema type ===") class Range(das.Mixin): @classmethod def get_schema_type(klass): return "timeline.Range" def __init__(self, *args, **kwargs): super(Range, self).__init__(*args, **kwargs) def expand(self, start, end): cs, ce = self[0], self[1] if start < cs: cs = start if end > ce: ce = end self[0], self[1] = cs, ce class ClipSource(das.Mixin): @classmethod def get_schema_type(klass): return "timeline.ClipSource" def __init__(self, *args, **kwargs): super(ClipSource, self).__init__(*args, **kwargs) def set_media(self, path): _, ext = map(lambda x: x.lower(), os.path.splitext(path)) if ext == ".fbx": print("Get range from FBX file") elif ext == ".abc": print("Get range from Alembic file") elif ext == ".mov": print("Get range from Movie file") self.media = os.path.abspath(path).replace("\\", "/") def set_clip_offsets(self, start, end): data_start, data_end = self.dataRange clip_start = min(data_end, data_start + max(0, start)) clip_end = max(data_start, data_end + min(end, 0)) if clip_start == data_start and clip_end == data_end: self.clipRange = None else: self.clipRange = (clip_start, clip_end) das.register_mixins(Range, ClipSource) print("-- make def (1)") dv = das.make_default("timeline.ClipSource") print("-- write (1)") das.write(dv, "./out.tl") print("-- make def (2)") cs = das.make_default("timeline.ClipSource") print("-- read (1)") cs = das.read("./out.tl") das.pprint(cs) cs.dataRange = (100, 146) cs.dataRange.expand(102, 150) cs.set_media("./source.mov") cs.set_clip_offsets(1, -1) das.pprint(cs) print("-- write (2)") das.write(cs, "./out.tl") c = das.copy(cs) das.pprint(c) for k, v in c.iteritems(): print("%s = %s" % (k, v)) os.remove("./out.tl")
def pprint(self): das.pprint(self)