;i7ddlZddlZddlZddlZddlmZddlmZmZddl m Z ddl m Z Gdd ej ZdS) N)getConfigOption)QtCore QtWidgets) ReplWidget)ExceptionHandlerWidgetcneZdZdZddZdZddZddZddZd Z d Z d Z d Z d Z dZdZdZdZdS) ConsoleWidgeta Widget displaying console output and accepting command input. Implements: - eval python expressions / exec python statements - storable history of commands - exception handling allowing commands to be interpreted in the context of any level in the exception stack frame Why not just use python in an interactive shell (or ipython) ? There are a few reasons: - pyside does not yet allow Qt event processing and interactive shell at the same time - on some systems, typing in the console _blocks_ the qt event loop until the user presses enter. This can be baffling and frustrating to users since it would appear the program has frozen. - some terminals (eg windows cmd.exe) have notoriously unfriendly interfaces - ability to add extra features like exception stack introspection - ability to have multiple interactive prompts, including for spawned sub-processes Ncltj||||i}||d<||_||_|jj|_|jj|_|j ||j |||_ | }n8#t$r+}tjtjd}Yd}~nd}~wwxYw|3dg|z|j_|j|dddd|_dS)a ============== ============================================================================= **Arguments:** namespace dictionary containing the initial variables present in the default namespace historyFile optional file for storing command history text initial text to display in the console window editor optional string for invoking code editor (called when stack trace entries are double-clicked). May contain {fileName} and {lineNum} format keys. Example:: editorCommand --loadfile {fileName} --gotoline {lineNum} ============== ============================================================================= N __console__)rQWidget__init___setupUilocalNamespaceeditorreploutputinputsetFocus setPlainText historyFile loadHistory Exceptionsys excepthookexc_infohistory historyListaddItemscurrentTraceback)selfparent namespacertextrr excs MC:\PYTHON\MyICR_Workspace\venv\Lib\site-packages\pyqtgraph/console/Console.pyrzConsoleWidget.__init__s= ""4000   I#' - ' i& Y_     K $ $T * * *& &&((GG    NCLNN + +GGGGGG   "$DJ    % %gdddm 4 4 4 $s+C C5 !C00C5ctj||_||j|jdddd|jdtjtjj j ||_ |j |j ddt|j|j||_|j |jtj||_|j|j |jtjd||_|jd|jj |j|jj|j|jj|jt;||_|j|j |jtjd||_|jd|jj |j|jj |j!|jj"|jj#|jj"|jj#|jj$|j%|jj&|j'dS)NrHistoryTz Exceptions..)(r QGridLayoutlayout setLayoutsetContentsMargins setSpacing QSplitterrQt OrientationVerticalsplitter addWidgetrglobalslocalsr QListWidgetr!hide QPushButton historyBtn setCheckable inputLayoutsigCommandEnteredconnect_commandEnteredsigCommandRaisedException_commandRaisedExceptionr excHandler exceptionBtnsigStackItemDblClicked_stackItemDblClickedtoggled setVisible itemClicked cmdSelecteditemDoubleClicked cmdDblClicked)r$s r)rzConsoleWidget._setupUiJs+D11  t{### &&q!Q222 q!!!!+FI,A,JDQQ  dmQ222t|T[$??   ***$066   0111#/ 4@@ $$T*** ''888 #++D,@AAA +33D4PQQQ066  000%1.$GG &&t,,, ''(9::: .66t7PQQQ !))$/*DEEE ''(8(CDDD $,,T-=>>> *2243EFFFFFTcr|r|jd|j|dSNT)rE setCheckedrDcatchAllExceptionsr$catchs r)rRz ConsoleWidget.catchAllExceptionso=  /   ( ( . . . **511111rNcr|r|jd|j|dSrP)rErQrDcatchNextExceptionrSs r)rWz ConsoleWidget.catchNextExceptiontrUrNc:|j|dSN)rDsetStackr$frames r)rZzConsoleWidget.setStackys   '''''rNc|jgtj|jrEt |jd5}t j|cdddS#1swxYwYdSdSdS)z@Return the list of previously-invoked command strings (or None).Nrb)rospathexistsopenpickleload)r$pfs r)rzConsoleWidget.loadHistory|s   'BGNN4;K,L,L 'd&-- '{2 ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ( ' ' 'sA""A&)A&c|jEt|jd5}tj||ddddS#1swxYwYdSdS)z5Store the list of previously-invoked command strings.Nwb)rrbrcdump)r$r res r) saveHistoryzConsoleWidget.saveHistorys   'd&-- ) GR((( ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ( 'sAAAc|j|||jjdd|j}||dS)Nrd)r!addItemrirr verticalScrollBarsetValuemaximum)r$rcmdsbs r)rAzConsoleWidget._commandEnteredso   %%% +AcE2333   / / 1 1 BJJLL!!!!!rNc:|j|dSrY)rDexceptionHandler)r$rr(s r)rCz%ConsoleWidget._commandRaisedExceptions ((-----rNc|j}|%|jjr|jS|jSrY)rD selectedFramerunSelectedFrameCheck isChecked f_globalsrr[s r)r7zConsoleWidget.globalssB--//  !F!P!P!R!R ? "& &rNc|j}|%|jjr|jS|jSrY)rDrurvrwf_localsrr[s r)r8zConsoleWidget.localssB--//  !F!P!P!R!R > !& &rNc|j|dz }|j||jdSNr)r!rowr setHistoryrr$itemindexs r)rKzConsoleWidget.cmdSelectedsP"&&t,,Q./ e$$$ rNc|j|dz }|j||jdSr|)r!r}rr~execCmdrs r)rMzConsoleWidget.cmdDblClickedsP"&&t,,Q./ e$$$ rNc|j}|td}|dS|j}|j}|jj}tj|j ||ddS)N editorCommand)fileNamelineNumT)shell) rrrDruf_linenof_code co_filename subprocessPopenformat)r$handlerrrtbrrs r)rGz"ConsoleWidget._stackItemDblClickeds{ >$_55F > F _ * * , ,+9(++Xw+OOW[\\\\\\rN)NNNNN)TrY)__name__ __module__ __qualname____doc__rrrRrWrZrrirArCr7r8rKrMrGrNr)r r s"*%*%*%*%X#G#G#GJ2222 2222 ((((''' ))) """ ...''''''  ] ] ] ] ]rNr )r_rrcrrrr2rr repl_widgetrexception_widgetr rr rrNr)rs """"""""######444444f]f]f]f]f]I%f]f]f]f]f]rN