Package nukescripts :: Module flipbooking
[hide private]
[frames] | no frames]

Source Code for Module nukescripts.flipbooking

  1  # Copyright (c) 2010 The Foundry Visionmongers Ltd.  All Rights Reserved. 
  2  ############################################################################### 
3 -class FlipbookApplication(object):
4 """An interface, for so far as Python supports it. To add support for a 5 flipbook this needs to be subclassed and the 3 methods implemented. The 6 default implementation just raises an exception so any sub implementer 7 will soon find out whether his implementation works."""
8 - def __init__(self):
9 return
10
11 - def name(self):
12 """ Return the name of the flipbook. 13 @return: String""" 14 raise NotImplementedError
15
16 - def path(self):
17 """Return the executable path required to run a flipbook. 18 @return: String""" 19 raise NotImplementedError
20
21 - def cacheDir(self):
22 """Return the preferred directory for rendering. 23 @return: String""" 24 raise NotImplementedError
25
26 - def run(self, path, frameRanges, views, options):
27 """Execute the flipbook on a path. 28 @param path: The path to run the flipbook on. This will be similar to /path/to/foo%03d.exr 29 @param frameRanges: A FrameRanges object representing the range that should be flipbooked. Note that in 6.2v1-2 this was a FrameRange object. 30 @param views: A list of strings comprising of the views to flipbook. Willnot be more than the maximum supported by the flipbook. 31 @param options: A dictionary of options to use. This may contain the keys pixelAspect, roi, dimensions, audio and lut. These contain a float, a dict with bounding box dimensions, a dict with width and height, a path to audio file and a string indicating the LUT conversion to apply. 32 @return: None""" 33 raise NotImplementedError
34
35 - def capabilities(self):
36 """Return the capabilities of the flipbook application. Currently used are: 37 proxyScale: bool, whether the flipbook supports proxies 38 crop: bool, whether the flipbook supports crops 39 canPreLaunch: bool, whether the flipbook can display a frames that are still being rendered by Nuke. 40 maximumViews: int, the number of views supported by this flipbook, should be 1 or higher. 41 fileTypes: list, the extensions of the file types supported by this format. Must all be lowercase, e.g ["exr", "jpg", ...] 42 @return: dict with the capabilities above.""" 43 raise NotImplementedError
44
45 - def dialogKnobs(self, dialog):
46 """This is called when the user has selected this flipbook application, and will be interested in any knobs that you might have to show for custom settings. 47 @param dialog: The FlipbookDialog that has requested the knobs to be added to it, e.g. dialog.addKnob(...) 48 @return: None""" 49 raise NotImplementedError
50
51 - def dialogKnobChanged(self, dialog, knob):
52 """Called whenever this flipbook is selected and one of the knobs added in dialogKnobs was changed. 53 @param dialog: The FlipbookDialog that contains the knob 54 @param knob: The knob added in dialogKnobs that was modified. 55 @return: None""" 56 raise NotImplementedError
57
58 -class FlipbookFactory(object):
59 - def __init__(self):
60 self._flipbookApplications = {}
61
62 - def isRegistered(self, flipbook):
63 """ Return whether a flipbook app with that name has already been registered. 64 @param flipbook: FlipBookApplication object that's tested for. 65 @return: bool""" 66 return self._flipbookApplications.has_key(flipbook.name())
67
68 - def register(self, flipbookApplication):
69 """Register a flipbook app. It will fail if the flipbook app name isn't unique. 70 @param flipbook: FlipBookApplication object to register 71 @return: None""" 72 if not self.isRegistered(flipbookApplication): 73 self._flipbookApplications[flipbookApplication.name()] = flipbookApplication 74 else: 75 raise RuntimeError("Already registered a flipbook application with this name")
76
77 - def getNames(self):
78 """Returns a list of the names of all available flipbook apps. 79 @return: list""" 80 return self._flipbookApplications.keys()
81
82 - def getApplication(self, name):
83 """Returns the flipbook app implementation with the given name, raises an exception if none could be found. 84 @param name: The name of a flipbook that was registered. 85 @return: FlipBookApplication""" 86 if self._flipbookApplications.has_key(name): 87 return self._flipbookApplications[name] 88 else: 89 raise RuntimeError("Requested flipbook not registered")
90
91 -class FlipbookLUTPathRegistry(object):
92 """A registery of all LUT files against LUTs for each specific flipbook."""
93 - def __init__(self):
94 self._luts = {}
95
96 - def registerLUTPathForFlipbook(self, flipbook, lut, path):
97 """Register the given LUT file. 98 @param flipbook: The unique name of the flipbook 99 @param lut: The unique name for the LUT, e.g. 'sRGB' and 'rec709' 100 @param path: Location of the flipbook specific file.""" 101 if not self._luts.has_key(flipbook): 102 self._luts[flipbook] = {} 103 self._luts[flipbook][lut] = path
104
105 - def getLUTPathForFlipbook(self, flipbook, lut):
106 """Return the path for the given flipbook and lut. May return an empty string if none registered. 107 @param flipbook: The unique name of the flipbook 108 @param lut: The unique name for the LUT, e.g. 'sRGB' and 'rec709'""" 109 return self._luts.get(flipbook, {}).get(lut, "")
110 111 # Global registry of flipbooks. 112 gFlipbookFactory = FlipbookFactory() 113 # Global registry of user specified LUTs 114 gFlipbookLUTPathRegistry = FlipbookLUTPathRegistry() 115 116 # Convenience functions that make access to the globals a few key strokes less.
117 -def register(flipbookApplication):
118 """Register a flipbook. Convenience function that simple calls register() on the FlipbookFactory.""" 119 gFlipbookFactory.register(flipbookApplication)
120
121 -def registerLUTPath(flipbookApplication, lut, path):
122 """Register a LUT for a specific flipbook. The path should refer to a file that contains the LUT for the given flipbook identified by the name in flipbookApplication. It is up to the flipbook subimplementation to actually use this file and the format may vary. 123 @param flipbook: The unique name of the flipbook 124 @param lut: The unique name for the LUT, e.g. 'sRGB' and 'rec709' 125 @param path: Location of the flipbook specific file.""" 126 gFlipbookLUTPathRegistry.registerLUTPathForFlipbook(flipbookApplication, lut, path)
127
128 -def getLUTPath(flipbookAppliction, lut):
129 """Returns a path to a LUT file for the given flipbook. The contents of the file will be different for each flipbook application. Please see the relevant documentation for the specific flipbook applications. 130 @param flipbook: The unique name of the flipbook 131 @param lut: The unique name for the LUT, e.g. 'sRGB' and 'rec709'""" 132 return gFlipbookLUTPathRegistry.getLUTPathForFlipbook(flipbookAppliction, lut)
133