Skip to content

Commit 9dce033

Browse files
committed
Merge pull request #463 from cchampet/fix_samDoDisplayHelpSecretParams
sam do: * do not skip secret params when display node help * display parameters which are enabled + not secret in bold when get help of a node * fix compatibility with clint v0.3.2
2 parents 30d4821 + 4e57bc5 commit 9dce033

File tree

2 files changed

+115
-72
lines changed

2 files changed

+115
-72
lines changed

applications/sam/common/samDoUtils.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
# python module to get colors, indent text...
99
from clint.textui import colored, puts, progress
10+
from clint import __version__ as clintVersion
1011

1112
# parser of sequence
1213
from pySequenceParser import sequenceParser
@@ -294,18 +295,32 @@ class ProgressHandle(tuttle.IProgressHandle):
294295
"""
295296
def __init__(self, ranges):
296297
super(ProgressHandle, self).__init__()
298+
299+
# Get number of frames to compute
297300
nbFramesToCompute = 0
298-
for range in ranges:
299-
nbFramesToCompute += (range._end - range._begin + 1) / range._step
300-
self._progress = progress.Bar(expected_size=(nbFramesToCompute if nbFramesToCompute < samUtils.getMaxInt() else 1))
301-
self._counter = 1
301+
for timeRange in ranges:
302+
nbFramesToCompute += (timeRange._end - timeRange._begin + 1) / timeRange._step
303+
expectedSize = (nbFramesToCompute if nbFramesToCompute < samUtils.getMaxInt() else 1)
304+
305+
# Create progress bar
306+
if clintVersion >= '0.3.5':
307+
self._progress = progress.Bar(expected_size=expectedSize)
308+
self._counter = 1
309+
else:
310+
self._it = list(range(0, expectedSize+1))
311+
self._progress = progress.bar(self._it, expected_size=expectedSize)
312+
self._progress.next()
302313

303314
def processAtTime(self):
304-
self._progress.show(self._counter)
305-
self._counter += 1
315+
if clintVersion >= '0.3.5':
316+
self._progress.show(self._counter)
317+
self._counter += 1
318+
else:
319+
self._progress.next()
306320

307321
def endSequence(self):
308-
self._progress.done()
322+
if clintVersion >= '0.3.5':
323+
self._progress.done()
309324

310325

311326
def samDoCompleter(prefix, parsed_args, **kwargs):

applications/sam/sam_do.py

Lines changed: 93 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import itertools
77

88
from clint.textui import colored, puts, indent
9+
from clint import __version__ as clintVersion
910

1011
# openFX host
1112
from pyTuttle import tuttle
@@ -28,13 +29,30 @@ def __init__(self):
2829
Use the separator // to pipe images between nodes.
2930
sam do [options]... [// node [node-options]... [[param=]value]...]... [options]
3031
'''))
32+
33+
self._pluginOption = colored.blue('Plugins options')
34+
self._generatorsAndViewers = colored.blue('Generators and viewers')
35+
self._imgSeqConversion = colored.blue('Image sequence conversion and creation')
36+
self._geometryPorcessing = colored.blue('Geometry processing during conversion')
37+
self._colorProcessing = colored.blue('Color processing during conversion')
38+
self._imgSeqNumbering = colored.blue('Image Sequence Numbering')
39+
self.processingOptions = colored.blue('Processing options')
40+
if clintVersion >= '0.3.3':
41+
self._pluginOption.bold=True
42+
self._generatorsAndViewers.bold=True
43+
self._imgSeqConversion.bold=True
44+
self._geometryPorcessing.bold=True
45+
self._colorProcessing.bold=True
46+
self._imgSeqNumbering.bold=True
47+
self.processingOptions.bold=True
48+
3149
self.epilog = '''
32-
'''+colored.blue('Plugins options', bold=True)+'''
50+
''' + self._pluginOption + '''
3351
Plugin list: sam do --nodes
3452
Supported file formats list: sam do --file-formats
3553
Plugin help: sam do blur -h
3654
37-
'''+colored.blue('Generators and viewers', bold=True)+'''
55+
''' + self._generatorsAndViewers + '''
3856
Viewer: sam do reader [email protected] // viewer
3957
Print: sam do reader [email protected] // print color=full16ansi
4058
Constant generator: sam do constant // viewer
@@ -45,32 +63,32 @@ def __init__(self):
4563
Checkerboard generator: sam do checkerboard width=1920 ratio=2.35 // viewer
4664
Text writing: sam do constant // text text="hello" size=80 // viewer
4765
48-
'''+colored.blue('Image sequence conversion and creation', bold=True)+'''
66+
''' + self._imgSeqConversion + '''
4967
Convert Image: sam do reader in.dpx // writer out.jpg
5068
Convert Sequence: sam do reader in.####.dpx // writer out.####.jpg
5169
Select a range: sam do reader in.####.dpx // writer out.####.jpg --ranges 10 100
5270
Select several ranges: sam do reader in.####.dpx // writer out.####.jpg --ranges 10 100 150 200
5371
'r' and 'w' are shortcuts for 'reader' and 'writer'
5472
55-
'''+colored.blue('Geometry processing during conversion', bold=True)+'''
73+
''' + self._geometryPorcessing + '''
5674
Crop: sam do reader in.dpx // crop x1=20 x2=1000 y1=10 y2=300 // writer out.jpg
5775
Fill: sam do reader in.dpx // crop y1=10 y2=1060 mode=fill color=0.43,0.67,0.50,1 // writer out.jpg
5876
Resize: sam do reader in.####.dpx // resize size=1920,1080 // writer out.####.jpg
5977
Upscaling: sam do reader in.####.dpx // resize size=1920,1080 filter=lanczos // writer out.####.jpg
6078
Downscaling: sam do reader in.####.dpx // resize size=720,576 filter=mitchell // writer out.####.jpg
6179
62-
'''+colored.blue('Color processing during conversion', bold=True)+'''
80+
''' + self._colorProcessing + '''
6381
Lut : sam do reader in.####.dpx // ocio.lut lutFile.3dl // writer out.jpg
6482
CTL: sam do reader in.####.dpx // ctl file=ctlCode.ctl // writer out.####.jpg
6583
Gamma: sam do reader in.####.dpx // gamma master=2.2 // writer out.####.jpg
6684
67-
'''+colored.blue('Image Sequence Numbering', bold=True)+'''
85+
''' + self._imgSeqNumbering + '''
6886
Frames with or without padding: [email protected]
6987
Frames 1 to 100 padding 4: image.####.jpg -or- [email protected]
7088
Frames 1 to 100 padding 5: image.#####.jpg
7189
Printf style padding 4: image.%04d.jpg
7290
73-
'''+colored.blue('Processing options', bold=True)+'''
91+
''' + self.processingOptions + '''
7492
Range process: sam do reader [email protected] // writer [email protected] --ranges 50 100
7593
Single process: sam do reader [email protected] // writer [email protected] --ranges 59
7694
Continues whatever happens: sam do reader [email protected] // writer [email protected] --continue-on-error
@@ -125,7 +143,10 @@ def _displayTitle(self, title):
125143
"""
126144
Display the given string with a title format.
127145
"""
128-
puts('\n' + colored.blue(title, bold=True))
146+
blueTitle = colored.blue(title)
147+
if clintVersion >= '0.3.3':
148+
blueTitle.bold=True
149+
puts('\n' + blueTitle)
129150

130151
def _displayPlugins(self):
131152
"""
@@ -170,85 +191,95 @@ def _displayParamHelp(self, param):
170191
"""
171192
Display help of the given OFXParameter.
172193
"""
194+
paramName = colored.green(param.getScriptName())
195+
if param.getEnabled() and not param.getSecret() and clintVersion >= '0.3.3':
196+
paramName.bold = True
197+
paramType = param.getParamTypeName()
198+
paramHint = param.getHint()
199+
paramDefaultValue = None
200+
paramChoiceValues = []
201+
paramChoiceLabel = []
202+
paramMinDisplayValue = []
203+
paramMaxDisplayValue = []
204+
paramHasMinMaxValues = False
205+
paramIsChoice = False
206+
173207
props = param.getProperties()
208+
174209
# Choice param
175210
if param.getParamType() == 'OfxParamTypeChoice':
176-
defaultValueIndex = None
211+
paramIsChoice = True
212+
# Get default choice value
177213
if props.hasProperty('OfxParamPropDefault'):
178214
propDefault = props.fetchProperty('OfxParamPropDefault')
179215
defaultValue = samUtils.getListValues(propDefault)
180216
if propDefault.getType() == tuttle.ePropTypeInt:
181-
defaultValueIndex = props.getIntProperty('OfxParamPropDefault', 0)
182-
183-
choiceValues = []
184-
choiceLabelValues = []
185-
hasLabel = False
217+
paramDefaultValue = props.getIntProperty('OfxParamPropDefault', 0)
218+
# Get choice values
186219
if props.hasProperty('OfxParamPropChoiceOption'):
187220
propChoiceOption = props.fetchProperty('OfxParamPropChoiceOption')
188-
choiceValues = samUtils.getListValues(propChoiceOption)
221+
paramChoiceValues = samUtils.getListValues(propChoiceOption)
222+
# Get label values
189223
if props.hasProperty('OfxParamPropChoiceLabelOption'):
190224
propChoiceLabel = props.fetchProperty('OfxParamPropChoiceLabelOption')
191-
choiceLabelValues = samUtils.getListValues(propChoiceLabel)
192-
hasLabel = (len(choiceValues) == len(choiceLabelValues))
225+
paramChoiceLabel = samUtils.getListValues(propChoiceLabel)
226+
hasLabel = (len(paramChoiceValues) == len(paramChoiceLabel))
193227

194-
# Print
195-
with indent(4):
196-
puts('{name!s:50}: {type:10} '.format(name=colored.green(param.getScriptName()), type=param.getParamTypeName()))
197-
if len(choiceValues):
198-
with indent(40):
199-
for choiceValue in choiceValues:
200-
puts('{value!s:50} {label}'.format(
201-
value=(colored.yellow(choiceValue) if choiceValues.index(choiceValue) == defaultValueIndex else colored.red(choiceValue)),
202-
label=(choiceLabelValues[choiceValues.index(choiceValue)] if hasLabel else '')))
203-
with indent(2):
204-
puts(param.getHint())
205228
# Other param types
206229
else:
207-
defaultValue = []
230+
# Get default value
208231
if props.hasProperty('OfxParamPropDefault'):
209232
propDefault = props.fetchProperty('OfxParamPropDefault')
210-
defaultValue = samUtils.getListValues(propDefault)
211-
212-
minDisplayValues = []
213-
maxDisplayValues = []
214-
# min/max values
233+
paramDefaultValue = samUtils.getListValues(propDefault)
234+
# Get min/max values
215235
if props.hasProperty('OfxParamPropDisplayMin'):
216236
propDisplayMin = props.fetchProperty('OfxParamPropDisplayMin')
217237
propDisplayMax = props.fetchProperty('OfxParamPropDisplayMax')
218-
minDisplayValues = samUtils.getListValues(propDisplayMin)
219-
maxDisplayValues = samUtils.getListValues(propDisplayMax)
220-
# check inf
221-
for i in range(0, len(maxDisplayValues)):
238+
paramMinDisplayValue = samUtils.getListValues(propDisplayMin)
239+
paramMaxDisplayValue = samUtils.getListValues(propDisplayMax)
240+
# check +inf
241+
for i in range(0, len(paramMaxDisplayValue)):
222242
if propDisplayMax.getType() == tuttle.ePropTypeInt:
223-
if int(maxDisplayValues[i]) >= samUtils.getMaxInt():
224-
maxDisplayValues[i] = 'inf'
243+
if int(paramMaxDisplayValue[i]) >= samUtils.getMaxInt():
244+
paramMaxDisplayValue[i] = 'inf'
225245
elif propDisplayMax.getType() == tuttle.ePropTypeDouble:
226-
if float(maxDisplayValues[i]) >= samUtils.getMaxInt():
227-
maxDisplayValues[i] = 'inf'
246+
if float(paramMaxDisplayValue[i]) >= samUtils.getMaxInt():
247+
paramMaxDisplayValue[i] = 'inf'
228248
# check -inf
229-
for i in range(0, len(minDisplayValues)):
249+
for i in range(0, len(paramMinDisplayValue)):
230250
if propDisplayMax.getType() == tuttle.ePropTypeInt:
231-
if int(minDisplayValues[i]) <= -samUtils.getMaxInt()-1:
232-
minDisplayValues[i] = '-inf'
251+
if int(paramMinDisplayValue[i]) <= -samUtils.getMaxInt()-1:
252+
paramMinDisplayValue[i] = '-inf'
233253
elif propDisplayMax.getType() == tuttle.ePropTypeDouble:
234-
if float(minDisplayValues[i]) <= -samUtils.getMaxInt()-1:
235-
minDisplayValues[i] = '-inf'
236-
hasMinMaxValues = len(minDisplayValues) > 0 and len(minDisplayValues) == len(maxDisplayValues)
237-
238-
# Print
239-
with indent(4):
240-
puts('{paramName!s:50}: {paramType!s:10} {default!s:9}'.format(
241-
paramName=colored.green(param.getScriptName()), paramType=param.getParamTypeName(),
242-
default=colored.yellow(','.join(defaultValue))),
243-
newline=(False if hasMinMaxValues else True))
254+
if float(paramMinDisplayValue[i]) <= -samUtils.getMaxInt()-1:
255+
paramMinDisplayValue[i] = '-inf'
256+
paramHasMinMaxValues = len(paramMinDisplayValue) > 0 and len(paramMinDisplayValue) == len(paramMaxDisplayValue)
244257

245-
if hasMinMaxValues:
246-
puts('[{minDisplay:5} --> {maxDisplay:5}]'.format(
247-
minDisplay=','.join(minDisplayValues),
248-
maxDisplay=','.join(maxDisplayValues)))
249-
250-
with indent(2):
251-
puts(param.getHint())
258+
# Print
259+
with indent(4):
260+
puts('{paramName!s:50}: {paramType!s:10}'.format(
261+
paramName=paramName,
262+
paramType=paramType),
263+
newline=paramIsChoice)
264+
265+
if paramIsChoice:
266+
with indent(40):
267+
for choiceValue in paramChoiceValues:
268+
puts('{choiceValue!s:50} {label}'.format(
269+
choiceValue=(colored.yellow(choiceValue) if paramChoiceValues.index(choiceValue) == paramDefaultValue else colored.red(choiceValue)),
270+
label=(paramChoiceLabel[paramChoiceValues.index(choiceValue)] if hasLabel else '')))
271+
else:
272+
puts('{defaultValue!s:9}'.format(
273+
defaultValue=colored.yellow(','.join(paramDefaultValue))),
274+
newline=(not paramHasMinMaxValues))
275+
276+
if paramHasMinMaxValues:
277+
puts('[{minDisplayValue:5} --> {maxDisplayValue:5}]'.format(
278+
minDisplayValue=','.join(paramMinDisplayValue),
279+
maxDisplayValue=','.join(paramMaxDisplayValue)))
280+
281+
with indent(2):
282+
puts(paramHint)
252283

253284
def _displayClipHelp(self, clip):
254285
"""
@@ -295,9 +326,6 @@ def _displayNodeHelp(self, nodeFullName, node):
295326
if node.getParams():
296327
self._displayTitle('PARAMETERS')
297328
for param in node.getParams():
298-
# Skip secret params
299-
if param.getSecret():
300-
continue
301329
paramType = param.getParamType()
302330
# Skip Group / PushButton / Page params
303331
if paramType == 'OfxParamTypeGroup' or paramType == 'OfxParamTypePushButton' or paramType == 'OfxParamTypePage':

0 commit comments

Comments
 (0)