1 2 3 4 5 6 7 8 9 10 11 12 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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
from functools import wraps
import pyqtgraph as pg
from pyqtgraph.Qt import QtWidgets
from pyqtgraph.parametertree import (
Parameter,
ParameterTree,
RunOptions,
InteractiveFunction,
Interactor,
)
app = pg.mkQApp()
class LAST_RESULT:
"""Just for testing purposes"""
value = None
def printResult(func):
@wraps(func)
def wrapper(*args, **kwargs):
LAST_RESULT.value = func(*args, **kwargs)
QtWidgets.QMessageBox.information(
QtWidgets.QApplication.activeWindow(),
"Function Run!",
f"Func result: {LAST_RESULT.value}",
)
return wrapper
host = Parameter.create(name="Interactive Parameter Use", type="group")
interactor = Interactor(parent=host, runOptions=RunOptions.ON_CHANGED)
@interactor.decorate()
@printResult
def easySample(a=5, b=6):
return a + b
@interactor.decorate()
@printResult
def stringParams(a="5", b="6"):
return a + b
@interactor.decorate(a=10)
@printResult
def requiredParam(a, b=10):
return a + b
@interactor.decorate(ignores=["a"])
@printResult
def ignoredAParam(a=10, b=20):
return a * b
@interactor.decorate(runOptions=RunOptions.ON_ACTION)
@printResult
def runOnButton(a=10, b=20):
return a + b
x = 5
@printResult
def accessVarInDifferentScope(x, y=10):
return x + y
func_interactive = InteractiveFunction(
accessVarInDifferentScope, closures={"x": lambda: x}
)
# Value is redeclared, but still bound
x = 10
interactor(func_interactive)
with interactor.optsContext(titleFormat=str.upper):
@interactor.decorate()
@printResult
def capslocknames(a=5):
return a
@interactor.decorate(
runOptions=(RunOptions.ON_CHANGED, RunOptions.ON_ACTION),
a={"type": "list", "limits": [5, 10, 20]},
)
@printResult
def runOnBtnOrChange_listOpts(a=5):
return a
@interactor.decorate(nest=False)
@printResult
def onlyTheArgumentsAppear(thisIsAFunctionArg=True):
return thisIsAFunctionArg
tree = ParameterTree()
tree.setParameters(host)
tree.show()
if __name__ == "__main__":
pg.exec()
|