CoolFace
Apppublic

Aluode/PerceptionLabPortable

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
InteractiveParameter.py114 linesDownload Raw Back to examples
1from functools import wraps2 3import pyqtgraph as pg4from pyqtgraph.Qt import QtWidgets5from pyqtgraph.parametertree import (6    Parameter,7    ParameterTree,8    RunOptions,9    InteractiveFunction,10    Interactor,11)12 13app = pg.mkQApp()14 15 16class LAST_RESULT:17    """Just for testing purposes"""18 19    value = None20 21 22def printResult(func):23    @wraps(func)24    def wrapper(*args, **kwargs):25        LAST_RESULT.value = func(*args, **kwargs)26        QtWidgets.QMessageBox.information(27            QtWidgets.QApplication.activeWindow(),28            "Function Run!",29            f"Func result: {LAST_RESULT.value}",30        )31 32    return wrapper33 34 35host = Parameter.create(name="Interactive Parameter Use", type="group")36interactor = Interactor(parent=host, runOptions=RunOptions.ON_CHANGED)37 38 39@interactor.decorate()40@printResult41def easySample(a=5, b=6):42    return a + b43 44 45@interactor.decorate()46@printResult47def stringParams(a="5", b="6"):48    return a + b49 50 51@interactor.decorate(a=10)52@printResult53def requiredParam(a, b=10):54    return a + b55 56 57@interactor.decorate(ignores=["a"])58@printResult59def ignoredAParam(a=10, b=20):60    return a * b61 62 63@interactor.decorate(runOptions=RunOptions.ON_ACTION)64@printResult65def runOnButton(a=10, b=20):66    return a + b67 68 69x = 570 71 72@printResult73def accessVarInDifferentScope(x, y=10):74    return x + y75 76 77func_interactive = InteractiveFunction(78    accessVarInDifferentScope, closures={"x": lambda: x}79)80# Value is redeclared, but still bound81x = 1082interactor(func_interactive)83 84 85with interactor.optsContext(titleFormat=str.upper):86 87    @interactor.decorate()88    @printResult89    def capslocknames(a=5):90        return a91 92 93@interactor.decorate(94    runOptions=(RunOptions.ON_CHANGED, RunOptions.ON_ACTION),95    a={"type": "list", "limits": [5, 10, 20]},96)97@printResult98def runOnBtnOrChange_listOpts(a=5):99    return a100 101 102@interactor.decorate(nest=False)103@printResult104def onlyTheArgumentsAppear(thisIsAFunctionArg=True):105    return thisIsAFunctionArg106 107 108tree = ParameterTree()109tree.setParameters(host)110 111tree.show()112if __name__ == "__main__":113    pg.exec()114 
Aluode/PerceptionLabPortable · CoolFace