Skip to content

Commit

Permalink
select slider based input widget for floats if range is specified
Browse files Browse the repository at this point in the history
  • Loading branch information
IlgarLunin committed Sep 16, 2019
1 parent 32f6091 commit a5730ad
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 109 deletions.
1 change: 1 addition & 0 deletions PyFlow/Core/Common.py
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,7 @@ class PinSpecifires:
INPUT_WIDGET_VARIANT = "inputWidgetVariant"
DESCRIPTION = "Description"
VALUE_LIST = "ValueList"
VALUE_RANGE = "ValueRange"


class NodeMeta:
Expand Down
31 changes: 12 additions & 19 deletions PyFlow/Packages/PyFlowBase/Factories/PinInputWidgetFactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,13 @@

FLOAT_SINGLE_STEP = 0.01
FLOAT_DECIMALS = 5


def _configDoubleSpinBox(sb):
sb.setDecimals(FLOAT_DECIMALS)
sb.setRange(FLOAT_RANGE_MIN, FLOAT_RANGE_MAX)
sb.setSingleStep(FLOAT_SINGLE_STEP)
sb.setDisplayMinimun(0)
sb.setDisplayMaximum(10)
FLOAT_DEFAULT_RANGE = (FLOAT_RANGE_MIN, FLOAT_RANGE_MAX)


def _configIntSpinBox(sb):
sb.setRange(INT_RANGE_MIN, INT_RANGE_MAX)
sb.setDisplayMinimun(0)
sb.setDisplayMaximum(10)
# sb.setDisplayMinimun(0)
# sb.setDisplayMaximum(10)


class ExecInputWidget(InputWidgetSingle):
Expand All @@ -62,7 +55,6 @@ class FloatInputWidgetSimple(InputWidgetSingle):
def __init__(self, parent=None, **kwds):
super(FloatInputWidgetSimple, self).__init__(parent=parent, **kwds)
self.sb = valueBox("float", True)
self.sb.setDecimals(FLOAT_DECIMALS)
self.sb.setRange(FLOAT_RANGE_MIN, FLOAT_RANGE_MAX)
self.sb.setSingleStep(FLOAT_SINGLE_STEP)
self.setWidget(self.sb)
Expand All @@ -88,10 +80,11 @@ class FloatInputWidget(InputWidgetSingle):

def __init__(self, parent=None, **kwds):
super(FloatInputWidget, self).__init__(parent=parent, **kwds)
self.sb = pyf_Slider(self, "float", style=0)
_configDoubleSpinBox(self.sb)
self.sb.setDisplayMinimun(0)
self.sb.setDisplayMaximum(10)
valueRange = (FLOAT_RANGE_MIN, FLOAT_RANGE_MAX)
if "pinAnnotations" in kwds:
if "ValueRange" in kwds["pinAnnotations"]:
valueRange = kwds["pinAnnotations"]["ValueRange"]
self.sb = pyf_Slider(self, "float", style=0, sliderRange=valueRange)
self.setWidget(self.sb)
# when spin box updated call setter function
self.sb.valueChanged.connect(lambda val: self.dataSetCallback(val))
Expand Down Expand Up @@ -281,10 +274,10 @@ def getInputWidget(dataType, dataSetter, defaultValue, widgetVariant=DEFAULT_WID
factory method
'''
if dataType == 'FloatPin':
if widgetVariant == DEFAULT_WIDGET_VARIANT:
return FloatInputWidget(dataSetCallback=dataSetter, defaultValue=defaultValue, **kwds)
elif widgetVariant == "FloatInputWidgetSimple":
return FloatInputWidgetSimple(dataSetCallback=dataSetter, defaultValue=defaultValue, **kwds)
if kwds is not None and "pinAnnotations" in kwds:
if kwds["pinAnnotations"] is not None and "ValueRange" in kwds["pinAnnotations"]:
return FloatInputWidget(dataSetCallback=dataSetter, defaultValue=defaultValue, **kwds)
return FloatInputWidgetSimple(dataSetCallback=dataSetter, defaultValue=defaultValue, **kwds)
if dataType == 'IntPin':
if widgetVariant == DEFAULT_WIDGET_VARIANT:
return IntInputWidget(dataSetCallback=dataSetter, defaultValue=defaultValue, **kwds)
Expand Down
2 changes: 1 addition & 1 deletion PyFlow/Packages/PyFlowBase/FunctionLibraries/DefaultLib.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def makeInt(i=('IntPin', 0)):

@staticmethod
@IMPLEMENT_NODE(returns=('FloatPin', 0.0), meta={NodeMeta.CATEGORY: 'GenericTypes', NodeMeta.KEYWORDS: []})
def makeFloat(f=('FloatPin', 0.0)):
def makeFloat(f=('FloatPin', 0.0, {PinSpecifires.VALUE_RANGE: (-500.0, 500.0)})):
'''Make floating point number.'''
return f

Expand Down
2 changes: 1 addition & 1 deletion PyFlow/Packages/PyFlowBase/FunctionLibraries/FloatLib.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(self, packageName):
@staticmethod
@IMPLEMENT_NODE(returns=('FloatPin', 0.0), meta={NodeMeta.CATEGORY: 'Math|Float', NodeMeta.KEYWORDS: ['lerp']})
## Linear interpolate
def lerpf(a=('FloatPin', 0.0), b=('FloatPin', 0.0), alpha=('FloatPin', 0.0)):
def lerpf(a=('FloatPin', 0.0), b=('FloatPin', 0.0), alpha=('FloatPin', 0.0, {PinSpecifires.VALUE_RANGE: (0.0, 1.0)})):
'''
Linear interpolate
'''
Expand Down
Loading

0 comments on commit a5730ad

Please sign in to comment.