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   
  4  import nuke 
  5   
  6   
7 -class FlipbookApplication(object):
8 """An interface, for so far as Python supports it. To add support for a 9 flipbook this needs to be subclassed and the 3 methods implemented. The 10 default implementation just raises an exception so any sub implementer 11 will soon find out whether his implementation works."""
12 - def __init__(self):
13 return
14
15 - def name(self):
16 """ Return the name of the flipbook. 17 @return: String""" 18 raise NotImplementedError
19
20 - def path(self):
21 """Return the executable path required to run a flipbook. 22 @return: String""" 23 raise NotImplementedError
24
25 - def cacheDir(self):
26 """Return the preferred directory for rendering. 27 @return: String""" 28 raise NotImplementedError
29
30 - def runFromNode(self, nodeToFlipbook, frameRanges, views, options):
31 """Execute the flipbook on a node. 32 This method will use the node's filename to call run() 33 @param node: The node to run the flipbook 34 @param frameRanges: A FrameRanges object representing the range that should be flipbooked. Note that in 6.2v1-2 this was a FrameRange object. 35 @param views: A list of strings comprising of the views to flipbook. Willnot be more than the maximum supported by the flipbook. 36 @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. 37 @return: None""" 38 39 filename = nuke.filename(nodeToFlipbook) 40 if filename is None or filename == "": 41 raise RuntimeError("Cannot run a flipbook on '%s', expected to find a filename and there was none." % (nodeToFlipbook.fullName(),)) 42 self.run( filename, frameRanges, views, options)
43 44
45 - def run(self, path, frameRanges, views, options):
46 """Execute the flipbook on a path. 47 @param path: The path to run the flipbook on. This will be similar to /path/to/foo%03d.exr 48 @param frameRanges: A FrameRanges object representing the range that should be flipbooked. Note that in 6.2v1-2 this was a FrameRange object. 49 @param views: A list of strings comprising of the views to flipbook. Willnot be more than the maximum supported by the flipbook. 50 @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. 51 @return: None""" 52 raise NotImplementedError
53
54 - def capabilities(self):
55 """Return the capabilities of the flipbook application. Currently used are: 56 proxyScale: bool, whether the flipbook supports proxies 57 crop: bool, whether the flipbook supports crops 58 canPreLaunch: bool, whether the flipbook can display a frames that are still being rendered by Nuke. 59 maximumViews: int, the number of views supported by this flipbook, should be 1 or higher. 60 fileTypes: list, the extensions of the file types supported by this format. Must all be lowercase, e.g ["exr", "jpg", ...] 61 @return: dict with the capabilities above.""" 62 raise NotImplementedError
63
64 - def dialogKnobs(self, dialog):
65 """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. 66 @param dialog: The FlipbookDialog that has requested the knobs to be added to it, e.g. dialog.addKnob(...) 67 @return: None""" 68 raise NotImplementedError
69
70 - def dialogKnobChanged(self, dialog, knob):
71 """Called whenever this flipbook is selected and one of the knobs added in dialogKnobs was changed. 72 @param dialog: The FlipbookDialog that contains the knob 73 @param knob: The knob added in dialogKnobs that was modified. 74 @return: None""" 75 raise NotImplementedError
76
77 - def getExtraOptions(self, flipbookDialog, nodeToFlipbook):
78 """Called whenever this flipbook is selected to retrieve extra options from the node selected to flipbook 79 and the flipbook dialog. 80 @param flipbookDialog: the flipbook dialog 81 @param nodeToFlipbook: node selected to flipbook 82 @return: a dictionary with the extra options """ 83 return dict()
84
85 -class FlipbookFactory(object):
86 - def __init__(self):
87 self._flipbookApplications = {}
88
89 - def isRegistered(self, flipbook):
90 """ Return whether a flipbook app with that name has already been registered. 91 @param flipbook: FlipBookApplication object that's tested for. 92 @return: bool""" 93 return self._flipbookApplications.has_key(flipbook.name())
94
95 - def register(self, flipbookApplication):
96 """Register a flipbook app. It will fail if the flipbook app name isn't unique. 97 @param flipbook: FlipBookApplication object to register 98 @return: None""" 99 if not self.isRegistered(flipbookApplication): 100 self._flipbookApplications[flipbookApplication.name()] = flipbookApplication 101 else: 102 raise RuntimeError("Already registered a flipbook application with this name")
103
104 - def getNames(self):
105 """Returns a list of the names of all available flipbook apps. 106 @return: list""" 107 return self._flipbookApplications.keys()
108
109 - def getApplication(self, name):
110 """Returns the flipbook app implementation with the given name, raises an exception if none could be found. 111 @param name: The name of a flipbook that was registered. 112 @return: FlipBookApplication""" 113 if self._flipbookApplications.has_key(name): 114 return self._flipbookApplications[name] 115 else: 116 raise RuntimeError("Requested flipbook not registered")
117
118 -class FlipbookLUTPathRegistry(object):
119 """A registery of all LUT files against LUTs for each specific flipbook."""
120 - def __init__(self):
121 self._luts = {}
122
123 - def registerLUTPathForFlipbook(self, flipbook, lut, path):
124 """Register the given LUT file. 125 @param flipbook: The unique name of the flipbook 126 @param lut: The unique name for the LUT, e.g. 'sRGB' and 'rec709' 127 @param path: Location of the flipbook specific file.""" 128 if not self._luts.has_key(flipbook): 129 self._luts[flipbook] = {} 130 self._luts[flipbook][lut] = path
131
132 - def getLUTPathForFlipbook(self, flipbook, lut):
133 """Return the path for the given flipbook and lut. May return an empty string if none registered. 134 @param flipbook: The unique name of the flipbook 135 @param lut: The unique name for the LUT, e.g. 'sRGB' and 'rec709'""" 136 return self._luts.get(flipbook, {}).get(lut, "")
137 138 # Global registry of flipbooks. 139 gFlipbookFactory = FlipbookFactory() 140 # Global registry of user specified LUTs 141 gFlipbookLUTPathRegistry = FlipbookLUTPathRegistry() 142 143 # Convenience functions that make access to the globals a few key strokes less.
144 -def register(flipbookApplication):
145 """Register a flipbook. Convenience function that simple calls register() on the FlipbookFactory.""" 146 gFlipbookFactory.register(flipbookApplication)
147
148 -def registerLUTPath(flipbookApplication, lut, path):
149 """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. 150 @param flipbook: The unique name of the flipbook 151 @param lut: The unique name for the LUT, e.g. 'sRGB' and 'rec709' 152 @param path: Location of the flipbook specific file.""" 153 gFlipbookLUTPathRegistry.registerLUTPathForFlipbook(flipbookApplication, lut, path)
154
155 -def getLUTPath(flipbookAppliction, lut):
156 """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. 157 @param flipbook: The unique name of the flipbook 158 @param lut: The unique name for the LUT, e.g. 'sRGB' and 'rec709'""" 159 return gFlipbookLUTPathRegistry.getLUTPathForFlipbook(flipbookAppliction, lut)
160