;i!bddlZddlZddlZddlZddlmZddlmZddlm Z GddZ Gd d Z Gd d Z Gd dZ e ZdS)N) functions) Parameter)ActionGroupParameterceZdZdZdS) PARAM_UNSETz9Sentinel value for detecting parameters with unset valuesN)__name__ __module__ __qualname____doc__WC:\PYTHON\MyICR_Workspace\venv\Lib\site-packages\pyqtgraph/parametertree/interactive.pyr r sCCCCrr ceZdZdZ dZ dZdS) RunOptionsactionchangedchangingN)r r r ON_ACTION ON_CHANGED ON_CHANGINGrrrrrs1IJKrrceZdZUdZeed<eed<ddfd ZdZdZd Z d Z dd Z dd Z dZ dZdZdZdZdZdZxZS)InteractiveFunctionaZ ``interact`` can be used with regular functions. However, when they are connected to changed or changing signals, there is no way to access these connections later to i.e. disconnect them temporarily. This utility class wraps a normal function but can provide an external scope for accessing the hooked up parameter signals. r r N)closuresc ti|_||_||_|i}||_d|_d|_i|_tj ||ddS)a Wraps a callable function in a way that forwards Parameter arguments as keywords Parameters ---------- function: callable Function to wrap closures: dict[str, callable] Arguments that shouldn't be constant, but can't be represented as a parameter. See the rst docs for more information. extra: dict extra keyword arguments to pass to ``function`` when this wrapper is called NFr)updated) super__init__ parametersextrafunctionr _disconnectedparametersNeedRunKwargsparameterCache functoolsupdate_wrapper)selfr"rr! __class__s rrzInteractiveFunction.__init__.sz     H  "',$   x<<<<<||j|<dS)z This function is connected to ``sigChanged`` of every parameter associated with it. This way, those parameters don't have to be queried for their value every time InteractiveFunction is __call__'ed N)r%name)r(paramvalues rupdateCachedParameterValuesz/InteractiveFunction.updateCachedParameterValues[s -2EJJLL)))rc |} t||jD](}|j|||) |s|n#|s|wwxYwt|t|jzD]}|||j|<dS)z` Updates attached params from __call__ without causing additional function runs N) disconnectset intersectionr setValue reconnectr!)r(r/wasDisconnectedkwargextraKeys rr+z2InteractiveFunction._updateParametersFromRunKwargscs //++ !V11$/BB ? ?&//u >>>> ?# !   # !     !F c$*oo5 4 4H#)(#3DJx  4 4s AA>>Bc|j|j|j|jfD]}t j||jdSN)sigValueChangedr:r8sigValueChangingfnrunFromChangedOrChanging)r(r6signals r_disconnectParameterz(InteractiveFunction._disconnectParameterss\ (()IJJJ-u/DE A AF M&$"? @ @ @ @ A ArTc:|r||D]}||j|<|j|j|r|nd|j|<dS)a Binds a new set of parameters to this function. If ``clearOld`` is *True* ( default), previously bound parameters are disconnected. Parameters ---------- params: Sequence[Parameter] New parameters to listen for updates and optionally propagate keywords passed to :meth:`__call__` clearOld: bool If ``True``, previously hooked up parameters will be removed first N) removeParametersr r5rDconnectr8hasValuer7r%)r(paramsclearOldr6s rhookupParametersz$InteractiveFunction.hookupParametersxs  $  ! ! # # # \ \E,1DOEJJLL )  ! ) )$*J K K KAFAQAQ0[ W[D  - -  \ \rc|jD]}|||j|r|jdSdS)z Disconnects from all signals of parameters in ``self.parameters``. Also, optionally clears the old cache of param values N)r valuesrIclearr%)r( clearCacheps rrKz$InteractiveFunction.removeParameterssy '')) ) )A  % %a ( ( ( (   (   % % ' ' ' ' ' ( (rc|jrdS|j}d|_ |di||i}||_n #||_wxYw|S)NFr)r#r$r5)r(r6r7 oldPropagaterets rrGz,InteractiveFunction.runFromChangedOrChangingso   43 ',$ 8$//%**,,.//C+7D ( (zInteractiveFunction.reconnects* "rc t|jd|jjdtt |S)Nz(``) at )typer r"hexidr(s r__str__zInteractiveFunction.__str__s9t**%XX$-*@XXRPTXXXXXrc t|dt|jdt|jdt|jzS)Nz with keys: parameters=z, extra=z , closures=)strlistr r!rrhs r__repr__zInteractiveFunction.__repr__sa II.t//..$*%%..T]++.. . r)NT)T)r r r r rk__annotations__rr3r8r+rIrPrKrGr\r:rbr>rirm __classcell__)r)s@rrr"s?MMM-1=======:*** 222444 AAA \\\\* ( ( ( (     YYY       rrc eZdZejZdZdZdZdZ e ddZ gdZ dZ dZejd Zdeeeeeed d Zejed Zd ZddZdZedZdZdZddZdZdZ dZ!dZ"dZ#dS) InteractorNTrRun)re defaultName) runOptionsparent titleFormatnestexistOkrunActionTemplatec |jdi|dS)z Initializes an Interactor with initial keyword arguments which can be anything accepted by :meth:`setOpts` NrsetOptsr[s rrzInteractor.__init__s"  vrc N|}t|}t||}|rtd|d|i}i}|D]\}}||||<|||<|j||S)a[ Overrides the default options for this interactor. Note! This method should only be used if you spawn your own Interactor; do not call it on ``defaultInteractor``. Instead, use ``defaultInteractor.optsContext``, which is guaranteed to revert to the default options when the context expires. Parameters ---------- opts Keyword arguments to override the default options Returns ------- dict of previous options that were overridden. This is useful for resetting the options afterward. zUnrecognized options: z. Must be one of: )getOptsr; differenceKeyErrorr.__dict__r-) r(optsoldOptsallowederrorstoReturntoUser1r2s rr|zInteractor.setOptss$,,..g,,T%%g..  YWFWWgWWXX Xjjll  FB"2;HRLE"II U###rc+FK|jdi|}dV|jdi|dS)z Creates a new context for ``opts``, where each is reset to the old value when the context expires Parameters ---------- opts: Options to set, must be one of the keys in :attr:`_optNames` Nrr{)r(rrs r optsContextzInteractor.optsContextsF$,&&&&  wr)ignoresrtrurvrwryrxc |tur i|j|}tfd|jD} |jd i| } ~~~~~~||jjfi| } | dg} d| D}| | }gttj ztt|z}|D]?}| | |d}|jvr|tur |j|<@fd| D}|r#|jd i| tdd|d g}fd |D}|D]K}| | |}|||}|||L|t&j|jvrA||| d }|r|||jr|n|}|jd i| |S) a Interacts with a function by making Parameters for each argument. There are several potential use cases and argument handling possibilities depending on which values are passed to this function, so a more detailed explanation of several use cases is provided in the "Interactive Parameters" doc. if any non-defaults exist, a value must be provided for them in ``overrides``. If this value should *not* be made into a parameter, include its name in ``ignores``. Parameters ---------- function: Callable function with which to interact. Can also be a :class:`InteractiveFunction`, if a reference to the bound signals is required. runOptions: ``GroupParameter.`` value How the function should be run, i.e. when pressing an action, on sigValueChanged, and/or on sigValueChanging ignores: Sequence Names of function arguments which shouldn't have parameters created parent: GroupParameter Parent in which to add argument Parameters. If *None*, a new group parameter is created. titleFormat: str or Callable title of the group sub-parameter if one must be created (see ``nest`` behavior). If a function is supplied, it must be of the form (str) -> str and will be passed the function name as an input nest: bool If *True*, the interacted function is given its own GroupParameter, and arguments to that function are 'nested' inside as its children. If *False*, function arguments are directly added to this parameter instead of being placed inside a child GroupParameter runActionTemplate: dict Template for the action parameter which runs the function, used if ``runOptions`` is set to ``GroupParameter.RUN_ACTION``. Note that if keys like "name" or "type" are not included, they are inferred from the previous / default ``runActionTemplate``. This allows items that should only be set per-function to exist here, like a ``shortcut`` or ``icon``. existOk: bool Whether it is OK for existing parameter names to bind to this function. See behavior during 'Parameter.insertChild' overrides: Override descriptions to provide additional parameter options for each argument. Moreover, extra parameters can be defined here if the original function uses ``**`` to consume additional keyword arguments. Each override can be a value (e.g. 5) or a dict specification of a parameter (e.g. dict(type='list', limits=[0, 10, 20])) c@i|]}|tu||Sr)r ).0r1locss r z'Interactor.interact..Ys-XXXDHKz'Interactor.interact..as111"2f:111rNr7czg|]7}|dtur&|djvr|djv/|d8S)r7r5)r rr!)rrr"s rrz'Interactor.interact..qs[   '{k))6 ("3336 (.00 vJ100rzCannot interact with `z#` since it has required parameters z, with no default or closure values provided.cg|]}|v| Srr)rnrs rrz'Interactor.interact..s#===AAW,<,))e;.F.F',t$          DL # #7 # # #QQQ"QQQ   =======  ( (D t!4!45I77 9hWWE   '''!!),,,  4? 2 2++HieATATUUF )  ((( $ 899y wrc |j|fi|SrC)r)r(r"r/s rr3zInteractor.__call__st}X00000rc fd}|S)z Calls :meth:`interact` and returns the :class:`InteractiveFunction`. Parameters ---------- kwargs Keyword arguments to pass to :meth:`interact` clt|tst|}j|fi|SrC) isinstancerr)r"r/r(s r decoratorz&Interactor.decorate..decoratorsBh(;<< 9.x88 DM( - -f - - -Orr)r(r/rs`` rdecoratezInteractor.decorates*       rFch|j}t|t}||r|s|S|r|S||S)aO Converts a function name to a title based on ``self.titleFormat``. Parameters ---------- name: str Name of the function forwardStringTitle: bool If ``self.titleFormat`` is a string and ``forwardStrTitle`` is True, ``self.titleFormat`` will be used as the title. Otherwise, if ``self.titleFormat`` is *None*, the name will be returned unchanged. Finally, if ``self.titleFormat`` is a callable, it will be called with the name as an input and the output will be returned )rvrrk)r(r5forwardStringTitlervisStrings r _nameToTitlezInteractor._nameToTitlesO& k3//  8 4F K   {4   rc|j}|jrXtjdi|}|jr!|j||j}|j|j|S)z Returns parent parameter that holds function children. May be ``None`` if no top parent is provided and nesting is disabled. rxr) rurwrcreateaddChildrx sigActivatedrLr\)r( functionDictinteractiveFunctionrs rrz Interactor._resolveFunctionGroupst K 9 N!(88<88I{ R K00DL0QQ  " * *+>+L M M Mrct|tr|St|}tj|s|n|j}t |dr|j|n|g|_|S)NinteractiveRefs)rrinspectismethod__func__hasattrrr)r" interactiverefOwners rrz!Interactor._toInteractiveFunctions h 3 4 4 O *(33 #*#3H#=#=T888CT 8. / / 5  $ + +K 8 8 8 8(3}H $rc.|stjdi|}n|||j}tj|jvr|j|j tj |jvr|j |j |S)Nrr) rrrrxrrrtrDrLrGrrE)r( functionGrouprrrs rrz)Interactor.resolveAndHookupParameterChilds L$11y11EE!**9dl*KKE  DO 3 3  ! ) )*=*V W W W  !T_ 4 4  " * *+>+W X X X rc4t|tr|dd}ni||j|}t jdi|}|j|j |r| ||j |S)NT)visiblerr) rr setButtonOpts_makePopulatedActionTemplater rrrrLr\rrx)r(rr functionTipr createOptss rrzInteractor._resolveRunActions m%9 : : D  ' ' ' 5 5 5EE::#,kJ$22z22E   & &':'H I I I D&&udl&CCC rc|j}|dd}|jr|n|}|d||r|d||S)Nrsrrr5r)ryr,rrw setdefault)r( functionNamerrrsr5s rrz'Interactor._makePopulatedActionTemplatess+0022  nn]E:: "i9{{\fd+++  6  ! !% 5 5 5rc g}|j}tdi||ddi}t|d||}|j||d|d<t j|j}|jrPtj |j\}} |r2| d ||d  d |t|d | D} t jj} t jj} | | vr&d =fd |D} | | | vr| | =D]W}||}|||||i}||X|S)zJ Converts a function into a list of child parameter dicts rF _actiongroup)r5rerbuttonNT)rtitlerrcg|] }|j Sr)kind)rrUs rrz6Interactor.functionToParameterDict..s>>>Q!&>>>rcg|]}|v| Srr)rrrs rrz6Interactor.functionToParameterDict..'s#JJJAaz6I6Ia6I6I6Irr)r dictrrvrr signaturer r pydocsplitdocrrlrRrVAR_POSITIONAL VAR_KEYWORDextendrrcreateFunctionParameterr)r(r"rrr5btnOptsout funcParamssynopsis_parameterKinds _positional_keywordnotInSignaturer6pgDictrs @rrz"Interactor.functionToParameterDicts PP::4@@PP%PPP>HWUUU   ',,Td,KKCL&x00;   :.)9::KHa :uh///H ((999*%% >>**;*;*=*=>>>'6 $0 ~ % % 2JJJJJJJN   n - - - . ( (>// <<= $ $DNN4((E11$y}}TSU?V?VWWF OOF # # # # rc|-|j|jur|j}|t|jd}ni}|}t |t sd|i}||||d<|dt|j )|d| ||dt|dj|S)a~ Constructs a dict ready for insertion into a group parameter based on the provided information in the ``inspect.signature`` parameter, user-specified overrides, and true parameter name. Parameter signature information is considered the most "overridable", followed by documentation specifications. User overrides should be given the highest priority, i.e. not usurped by parameter default information. Parameters ---------- name : str Name of the parameter, comes from function signature signatureParameter : inspect.Parameter Information from the function signature, parsed by ``inspect`` overridesInfo : dict User-specified overrides for this parameter. Can be a dict of options accepted by :class:`~pyqtgraph.parametertree.Parameter` or a value N)r7rer7r5rre) defaultemptyrer r,rrr-rr rvr)r(r5signatureParameter overridesInfor signatureDictrs rrz"Interactor.createFunctionParameter6s(  *"*2D2JJJ )0G&-tG}}7MNNMMM##%%-.. 5$m4M m$$$v ';///   '   gt'8'8'>'> ? ? ?&$vg"7"7"@AAA rc0d|S)NzInteractor with opts: )r~rhs rrizInteractor.__str__gs8 888rc t|SrC)rkrhs rrmzInteractor.__repr__js4yyrc*fdjDS)Nc2i|]}|t|Sr)getattr)rattrr(s rrz&Interactor.getOpts..ns%HHHdgdD))HHHr)rrhs`rr~zInteractor.getOptsms HHHHd6GHHHHr)F)rN)$r r r rrrtrurvrwrxrryrrr| contextlibcontextmanagerrr rr&wrapsr3rrr staticmethodrrrrrrrirmr~rrrrqrqs%J FK DG(>>>L@     $ %BY_X111$!!!!0   \      ,,,\///b999IIIIIrrq)rr&rrrrrFrparameterTypesrr rrrqrrrrrs8 000000DDDDDDDD&i i i i i i i i X`I`I`I`I`I`I`I`IF :<<r