Beispiel #1
0
    def load(self, filepath=None):
        """
        Loads a session .io file.
        """
        if filepath is None and self.filepath:
            filepath = self.filepath
        elif filepath:
            self.filepath = filepath
        else:
            raise AbcViewError("File path not set")

        # metadata and properties
        state = json.load(open(filepath, "r"))
        self.name = state.get("name", os.path.basename(filepath))
        self.version = state.get("app").get("version")
        self.program = state.get("app").get("program")
        self.date = state.get("date")
        self.instance = state.get("instance", 1)
        self.frames_per_second = state.get("frames_per_second", 
                           self.frames_per_second)
        self.min_time = state.get("min_time", self.min_time)
        self.max_time = state.get("max_time", self.max_time)
        self.current_time = state.get("current_time", self.current_time)

        # cameras
        for camera in state.get("cameras"):
            if camera.get("type") == Camera.type():
                self.add_camera(Camera.deserialize(camera))
            elif camera.get("type") == ICamera.type():
                self.add_camera(ICamera.deserialize(camera))

        # items
        data = state.get("data")
        for d in data.get("items"):
            fp = str(d.get("filepath"))

            if fp.endswith(Scene.EXT):
                self.add_item(Scene.deserialize(d))

            # TODO: replace with deserialization for sessions
            elif fp.endswith(Session.EXT):
                item = Session(fp)
                item.name = d.get("name", item.name)
                item.uuid = d.get("uuid", item.uuid)
                item.loaded = d.get("loaded", item.loaded)
                item.overrides.update(d.get("overrides", {}))
                item.properties.update(d.get("properties", {}))
                self.add_item(item)
Beispiel #2
0
    def load(self, filepath=None):
        """
        Loads a session .io file.
        """
        if filepath is None and self.filepath:
            filepath = self.filepath
        elif filepath:
            self.filepath = filepath
        else:
            raise AbcViewError("File path not set")

        # metadata and properties
        state = json.load(open(filepath, "r"))
        self.name = state.get("name", os.path.basename(filepath))
        self.version = state.get("app").get("version")
        self.program = state.get("app").get("program")
        self.date = state.get("date")
        self.instance = state.get("instance", 1)
        self.frames_per_second = state.get("frames_per_second",
                                           self.frames_per_second)
        self.min_time = state.get("min_time", self.min_time)
        self.max_time = state.get("max_time", self.max_time)
        self.current_time = state.get("current_time", self.current_time)

        # cameras
        for camera in state.get("cameras"):
            if camera.get("type") == Camera.type():
                self.add_camera(Camera.deserialize(camera))
            elif camera.get("type") == ICamera.type():
                self.add_camera(ICamera.deserialize(camera))

        # items
        data = state.get("data")
        for d in data.get("items"):
            fp = str(d.get("filepath"))

            if fp.endswith(Scene.EXT):
                self.add_item(Scene.deserialize(d))

            # TODO: replace with deserialization for sessions
            elif fp.endswith(Session.EXT):
                item = Session(fp)
                item.name = d.get("name", item.name)
                item.uuid = d.get("uuid", item.uuid)
                item.loaded = d.get("loaded", item.loaded)
                item.overrides.update(d.get("overrides", {}))
                item.properties.update(d.get("properties", {}))
                self.add_item(item)