How to use the filetype.ImageFile function in filetype

To help you get started, we’ve selected a few filetype examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Driftwood2D / Driftwood / src / resourcemanager.py View on Github external
except CheckFailure as e:
            self.driftwood.log.msg("ERROR", "Resource", "request_duplicate_image", "bad argument", e)
            return None

        obj = None

        if filename in self.__duplicate_file_counts:
            self.__duplicate_file_counts[filename] += 1
        else:
            self.__duplicate_file_counts[filename] = 1

        cache_name = "{} duplicate {}".format(filename, self.__duplicate_file_counts[filename])

        data = self.request_raw(filename, binary=True)
        if data:
            obj = filetype.ImageFile(self.driftwood, data, self.driftwood.window.renderer)
            if obj:
                self.driftwood.cache.upload(cache_name, obj, keep_for_ttl=False)

        return obj
github Driftwood2D / Driftwood / src / resourcemanager.py View on Github external
Returns:
            Image filetype abstraction if succeeded, None if failed.
        """
        # Input Check
        try:
            CHECK(filename, str)
        except CheckFailure as e:
            self.driftwood.log.msg("ERROR", "Resource", "request_image", "bad argument", e)
            return None

        if filename in self.driftwood.cache:
            return self.driftwood.cache[filename]
        data = self.request_raw(filename, binary=True)
        if data:
            obj = filetype.ImageFile(self.driftwood, data, self.driftwood.window.renderer)
            self.driftwood.cache.upload(filename, obj)
            return obj
        else:
            self.driftwood.cache.upload(filename, None)
            return None
github Driftwood2D / Driftwood / src / lightmanager.py View on Github external
file: Filename of the JSON light descriptor whose insertions should be killed, or ImageFile of the lightmap.

        Returns:
            True if succeeded, False if failed.
        """
        # Input Check
        try:
            CHECK(file, str)
        except CheckFailure as e:
            self.driftwood.log.msg("ERROR", "Light", "killall", "bad argument", e)
            return False

        to_kill = []

        # Collect a list of lights to kill, searching by lightmap ImageFile.
        if isinstance(file, filetype.ImageFile):
            for lid in self.lights:
                if self.lights[lid].lightmap == file:
                    to_kill += lid

        # Collect a list of lights to kill, searching by lightmap filename.
        else:
            for lid in self.lights:
                if self.lights[lid].filename == file:
                    to_kill += lid

        # Kill the lights in the list.
        for lid in to_kill:
            del self.lights[lid]

        self.driftwood.area.changed = True