Skip to content

open_in_djv

OpenInDJV

Bases: LoaderPlugin

Open Image Sequence with system default

Source code in client/ayon_djv/plugins/load/open_in_djv.py
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
class OpenInDJV(load.LoaderPlugin):
    """Open Image Sequence with system default"""

    _executable_cache = DJVExecutableCache()
    product_types = ["*"]
    representations = ["*"]
    extensions = {
        ext.lstrip(".")
        for ext in set(IMAGE_EXTENSIONS) | set(VIDEO_EXTENSIONS)
    }

    label = "Open in DJV"
    order = -10
    icon = "play-circle"
    color = "orange"

    @classmethod
    def get_djv_path(cls):
        return cls._executable_cache.get_path()

    @classmethod
    def is_compatible_loader(cls, context):
        if not cls.get_djv_path():
            return False
        return super().is_compatible_loader(context)

    def load(self, context, name, namespace, data):

        path = self.filepath_from_context(context)
        directory = os.path.dirname(path)

        pattern = clique.PATTERNS["frames"]
        files = os.listdir(directory)
        collections, remainder = clique.assemble(
            files,
            patterns=[pattern],
            minimum_items=1
        )

        if not remainder:
            sequence = collections[0]
            first_image = list(sequence)[0]
        else:
            first_image = path
        filepath = os.path.normpath(os.path.join(directory, first_image))

        self.log.info("Opening : {}".format(filepath))

        executable = self.get_djv_path()
        cmd = [
            # DJV path
            str(executable),
            # PATH TO COMPONENT
            filepath
        ]

        try:
            # Run DJV with these commands
            run_detached_process(cmd)
            # Keep process in memory for some time
            time.sleep(0.1)

        except FileNotFoundError:
            self.log.error(
                f"File \"{os.path.basename(filepath)}\" was not found."
            )