a „oeXOã@s*ddlZddlZddlZddlZddlZddlmZmZddlm Z dd„Z Gdd„dƒZ ddl Z ddl mZdd lmZe jjjZGd d „d eƒZGd d „d ejƒZGdd„dƒZGdd„de jeƒZddlZ Gdd„de jjjeƒZeZGdd„de j ƒZ!dd„Z"dd„Z#dd„Z$e%dkr&e$ƒdS)éN)ÚappÚwindow)ÚdocviewcCsdS©N©)ÚmsgrrúAC:\Program Files\Certbot\pkgs\pythonwin\pywin\framework\winout.pyÚ ór c@seZdZdZdZdZdS)ÚflagsrééN)Ú__name__Ú __module__Ú __qualname__ÚWQ_NONEÚWQ_LINEÚWQ_IDLErrrrr 'sr )Údefault_scintilla_encoding)Ú scintillaconc@seZdZdd„Zdd„ZdS)ÚWindowOutputDocumentcCsdS©Nr r©ÚselfrrrÚ SaveModified8sz!WindowOutputDocument.SaveModifiedc Cs^t dd¡z| |¡Wn4tyN}zt d|¡WYd}~dSd}~00t d¡dS)NzSaving file...r z!Error - could not save file %srZReady)Úwin32uiÚ SetStatusTextZSaveFileÚIOErrorZ MessageBox)rÚfileNameÚdetailsrrrÚOnSaveDocument;s  z#WindowOutputDocument.OnSaveDocumentN)rrrrr rrrrr7src@s6eZdZd dd„Zdd„Zdd„Zdd „Zd d „ZdS) ÚWindowOutputFrameNcCs2tj ||¡| |jtj¡| |jtj¡dSr)rÚ MDIChildWndÚ__init__Ú HookMessageÚ OnSizeMoveÚwin32conZWM_SIZEZWM_MOVE)rZwndrrrr#GszWindowOutputFrame.__init__cCs|j|_|j ||||¡Sr)ÚtemplateÚ_obj_Ú LoadFrame)rZ idResourceÚstyleZ wndParentÚcontextrrrr)LszWindowOutputFrame.LoadFramec Cst|j |¡}|jjrp|jjd|jjdkrpt |jj¡}|d|d|d|d||d|d|d|df }|S) Nrr r ééééé)r(ÚPreCreateWindowr'ÚdefSizerZRectToCreateStructRect)rZccZrectrrrr1Ps ÿþ6z!WindowOutputFrame.PreCreateWindowcCs| ¡}| | ¡¡|j_dSr)Ú GetParentZScreenToClientZ GetWindowRectr'r2)rrZ mdiClientrrrr%ZszWindowOutputFrame.OnSizeMovecCs|j |¡dSr)r'ÚOnFrameDestroy©rÚmessagerrrÚ OnDestroyas zWindowOutputFrame.OnDestroy)N)rrrr#r)r1r%r7rrrrr!Fs   r!c@s\eZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dd„Z dd„Z dS)ÚWindowOutputViewImplcCst d¡|_| ¡ ¡|_dS)Nz\W*File "(.*)", line ([0-9]+))ÚreÚcompileÚpatErrorMessageÚ GetDocumentZGetDocTemplater'rrrrr#gs zWindowOutputViewImpl.__init__cCs| |jtj¡dSr)r$ÚOnRClickr&ZWM_RBUTTONDOWNrrrrÚ HookHandlersksz!WindowOutputViewImpl.HookHandlerscCs|j |¡dSr)r'Ú OnViewDestroy©rrrrrr7oszWindowOutputViewImpl.OnDestroycCs| ¡| d¡dS©Néþÿÿÿ)ÚRestoreKillBufferÚSetSelrrrrÚOnInitialUpdatersz$WindowOutputViewImpl.OnInitialUpdatecCs8g}tjtjB}| |tjdf¡| |tjdf¡|S)Nz&Copyz &Select all)r&Z MF_STRINGZ MF_ENABLEDÚappendrZ ID_EDIT_COPYZID_EDIT_SELECT_ALL)rÚretr rrrÚGetRightMenuItemsvs  z&WindowOutputViewImpl.GetRightMenuItemscCsL| ¡}t ¡}|D]$}t|ƒtdƒkr.|f}|j|Žq| |d¡dS)Nrr-r)rHrZCreatePopupMenuÚtypeZ AppendMenuZTrackPopupMenu)rÚparamsZ paramsListZmenuZ appendParamsrrrr=€s zWindowOutputViewImpl.OnRClickc CsÈddlm}| ¡}|dd…dkrÜzjddl}ddl}t|| d¡dd… ¡ƒ}t  d¡ddlm }|  |d d |j |d d ¡WdS|j yÆ}zt  d |j¡WYd}~dSd}~0t  d ¡Yn0|j |¡}|dur| ¡} | dkr| | d¡}|j |¡}|durÄ| d¡} | ddkrNt  d¡dS| d ¡} | } | | ¡} | dur„t  d| d¡dSt  d| d| d¡| | t| ƒ¡sÀt  d| ¡dSdSdS)Nr )Ú scriptutilsé z com_error: rú:z!Opening help file on OLE error...)Úhelpr r,éz&The help file could not be opened - %sz9Line is a COM error, but no WinHelp details can be parsedúr7rErHr=r\r]rarbrrrrr8fs =r8c@s\eZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dd„Z dd„Z dS)ÚWindowOutputViewRTFcCstj ||¡t |¡dSr)rÚ RichEditViewr#r8©rÚdocrrrr#×szWindowOutputViewRTF.__init__cCst |¡tj |¡Sr)r8rErrdrrrrrEÛs z#WindowOutputViewRTF.OnInitialUpdatecCst ||¡tj ||¡dSr)r8r7rrdr@rrrr7ßs zWindowOutputViewRTF.OnDestroycCst |¡| |jtj¡dSr)r8r>r$ÚOnLDoubleClickr&ZWM_LBUTTONDBLCLKrrrrr>ãs z WindowOutputViewRTF.HookHandlerscCs| ¡r dSdS©Nrr ©r\)rrJrrrrgêsz"WindowOutputViewRTF.OnLDoubleClickcCs(t|jjƒr$| tj|j¡g|j_dSr)Úlenr'Ú killBufferZStreamInr&ZSF_RTFÚ _StreamRTFInrrrrrCïs z%WindowOutputViewRTF.RestoreKillBuffercCs| tj|j¡dSr)Z StreamOutr&Z SF_RTFNOOBJSÚ _StreamRTFOutrrrrÚSaveKillBufferôsz"WindowOutputViewRTF.SaveKillBuffercCs|jj |¡dSr)r'rkrF)rÚdatarrrrm÷sz!WindowOutputViewRTF._StreamRTFOutcCsNz4|jjd}|jj |¡|t|ƒkr0tdƒ|WStyHYdS0dS)Nrz'Warning - output buffer not big enough!)r'rkÚremoverjÚprintÚ IndexError)rÚbytesÚitemrrrrlûs   z WindowOutputViewRTF._StreamRTFIncCs| d¡| |¡dSrA)rDZ ReplaceSel)rÚstrrrrÚdowrites zWindowOutputViewRTF.dowriteN) rrrr#rEr7r>rgrCrnrmrlrvrrrrrcÖs rcc@s^eZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z ddd„Z dd„Z dS)ÚWindowOutputViewScintillacCs tjjj ||¡t |¡dSr)ÚpywinÚ scintillaÚviewÚCScintillaViewr#r8rerrrr#sz"WindowOutputViewScintilla.__init__cCs(tjjj |¡| d¡t |¡dS)Nr,)rxryrzr{rEZSCISetMarginWidthr8rrrrrEs z)WindowOutputViewScintilla.OnInitialUpdatecCs"t ||¡tjjj ||¡dSr)r8r7rxryrzr{r@rrrr7s z#WindowOutputViewScintilla.OnDestroycCs2t |¡tjjj |¡| ¡ |jt j ¡dSr) r8r>rxryrzr{r3Z HookNotifyÚOnScintillaDoubleClickrZSCN_DOUBLECLICKrrrrr>s  ÿz&WindowOutputViewScintilla.HookHandlerscCs | ¡dSrri)rZstdZextrarrrr|&sz0WindowOutputViewScintilla.OnScintillaDoubleClickcCs>t|jjƒdvsJdƒ‚|jjr2| |jjd¡g|j_dS)N)rr zUnexpected killbuffer contentsr)rjr'rkZ SCIAddTextrrrrrC,sz+WindowOutputViewScintilla.RestoreKillBuffercCs| dd¡g|j_dS)Nréÿÿÿÿ)Z GetTextRanger'rkrrrrrn2sz(WindowOutputViewScintilla.SaveKillBuffercCs:| ¡}|| ¡dk}| ||¡|r6| | ¡¡dS)Nr)Z GetTextLengthZGetSelZ SCIInsertTextrD)rruÚendZatEndrrrrv5s  z!WindowOutputViewScintilla.dowriter cCs |r tj}ntj}| |¡dSr)rZ SC_WRAP_WORDZ SC_WRAP_NONEZSCISetWrapMode)rZbWrapOnZ wrap_moderrrÚ SetWordWrap<sz%WindowOutputViewScintilla.SetWordWrapcCsdSrrrrrrÚ_MakeColorizerCsz(WindowOutputViewScintilla._MakeColorizerN)r ) rrrr#rEr7r>r|rCrnrvrr€rrrrrw s  rwc@sÄeZdZdZdZddejdddddfdd„Zdd„Zd*dd „Z d d „Z d d „Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zdd„Zdd„Zd+dd„Zd d!„Zd"d#„Zd$d%„Zd&d'„Zd(d)„ZdS),Ú WindowOutputz¥Looks like a general Output Window - text can be written by the 'write' method. Will auto-create itself on first write, and also on next write after being closedr Nc Csè|dur t}|durt}|dur$t}tj |tj|||¡| d¡t  ¡  |¡||_ d|_ g|_ ||_||_||_d|_d|_t|ƒtdƒkr®||_t |¡|_|j|_n d|_||_d|_t d¡|_t ¡|_d|_ | !¡dS)ainit the output window - Params title=None -- What is the title of the window defSize=None -- What is the default size for the window - if this is a string, the size will be loaded from the ini file. queueing = flags.WQ_LINE -- When should output be written bAutoRestore=1 -- Should a minimized window be restored. style -- Style for Window, or None for default. makeDoc, makeFrame, makeView -- Classes for frame, view and window respectively. Nz' Output Text Documents (*.txt) .txt rrQr})"rr!rwrÚ DocTemplater#rZIDR_PYTHONTYPEZ SetDocStringsÚGetAppZAddDocTemplateÚ writeQueueingÚerrorCantRecreaterkr*Ú bAutoRestoreÚtitleÚ bCreatingÚinterruptCountrIÚiniSizeSectionrZLoadWindowSizer2Ú loadedSizeÚ currentViewÚqueueÚQueueÚ outputQueuerRÚGetCurrentThreadIdÚ mainThreadIdÚidleHandlerSetÚSetIdleHandler) rr‡r2Úqueueingr†r*ZmakeDocZ makeFrameÚmakeViewrrrr#Ts< ÿ     zWindowOutput.__init__cCs | ¡dSr)ÚCloserrrrÚ__del__‰szWindowOutput.__del__cCsTd|_|r||_|r||_| ¡}|dur.dS| ¡|_d|_|jrP| |j¡dS©Nr r)rˆr‡r*ZOpenDocumentFileZ GetFirstViewrŒÚSetTitle)rr‡r*rfrrrÚCreateŒs zWindowOutput.Createc Cs>| ¡z|j ¡}Wnttjfy0YdS0| ¡dSr)ÚRemoveIdleHandlerrŒr3ÚAttributeErrorrrVZ DestroyWindow)rÚparentrrrr–šs zWindowOutput.ClosecCs"||_|jr|j ¡ |j¡dSr)r‡rŒr<r™)rr‡rrrr™¢szWindowOutput.SetTitlecCs|j ¡d|_dSr)rŒrn)rrzrrrr?§s zWindowOutput.OnViewDestroycCs.|jr*| ¡d}|j|kr*t |j|¡dS)NrO)rŠZGetWindowPlacementr‹rZSaveWindowSize)rÚframeZnewSizerrrr4«s  zWindowOutput.OnFrameDestroycCs(|js$tdƒt ¡ |j¡d|_dS)NzIdle handler set r )r’ÚdebugrrƒZAddIdleHandlerÚQueueIdleHandlerrrrrr“²szWindowOutput.SetIdleHandlercCs4|jr0tdƒt ¡ |j¡dkr*tdƒd|_dS)NzIdle handler reset rzError deleting idle handler )r’rŸrrƒZDeleteIdleHandlerr rrrrr›¸s zWindowOutput.RemoveIdleHandlerc CsZ|jrtdƒdSzt ¡ ¡| ¡WdStjtfyTd|_tdƒYdS0dS)NzError = not trying againrr z$Winout can not recreate the Window! )r…rŸrÚ GetMainFrameZ GetSafeHwndršrVrœrrrrÚRecreateWindow¿s zWindowOutput.RecreateWindowcCsdz| d¡}|rd|_WnDty\|jd|_|jdkrVt d¡|_tdƒd}n‚Yn0| S)Nérr r}z Interrupted.)Ú QueueFlushr‰ÚKeyboardInterruptrrŽrrq)rZhandlerÚcountZbEmptyrrrr Îs      zWindowOutput.QueueIdleHandlerc Cs<z|jdur|j ¡rWdSWntjtfy6Yn0dSrh)rŒZIsWindowrrVrœrrrrÚNeedRecreateWindowâs þ zWindowOutput.NeedRecreateWindowcCs,|jr dS| ¡sdS|jr(| ¡r(dSdSr˜)rˆr§r†r¢rrrrÚCheckRecreateWindowîsz WindowOutput.CheckRecreateWindowcCs¨|jr dSg}d}|dus"|dkrjz|j ¡}| |¡WntjyVd}YqjYn0|dur|d}qt|ƒdkr¤| ¡sŠtdƒdSt   ¡|j   d  |¡¡|S)Nr rz:Recreate failed! rQ)rˆrZ get_nowaitrFrZEmptyrjr¨rŸrZPumpWaitingMessagesrŒrvÚjoin)rÚmaxÚitemsÚrcrtrrrr¤øs(    zWindowOutput.QueueFlushcCs˜|j |¡t ¡|jkrnD|jtjkrH| d¡}|dkr`|  ¡dSn|jtj kr`|  ¡dSzt   ¡  tj¡Wnt jy’t |¡Yn0dS)NÚ r)rZputrRrr‘r„r rÚrfindr¤rrr¡Z PostMessager&ZWM_USERrVZOutputDebugString)rr6ÚposrrrÚ HandleOutputs"    ÿzWindowOutput.HandleOutputcCs|D]}| |¡qdSrr^r_rrrra*szWindowOutput.writelinescCs| |¡dSr)r°r5rrrr].szWindowOutput.writecCs | ¡dSr)r¤rrrrrb1szWindowOutput.flushcCs|j ¡dSr)rŒr\rrrrr\4szWindowOutput.HandleSpecialLine)NN)N)rrrÚ__doc__Z softspacer rr#r—ršr–r™r?r4r“r›r¢r r§r¨r¤r°rar]rbr\rrrrrNs:÷ 5   rcOst|d<t|i|¤ŽS)Nr•)rcr)ÚargsÚkwrrrÚRTFWindowOutput8sr´cCs.tdƒD] }| dt ¡¡t d¡qdS)Nr-zHi from thread %d éd)Úranger]rRrÚSleep)ÚoÚirrrÚ thread_test=s rºcCsjttjd}| d¡ddl}tdƒD]}| d¡| t|f¡q&tdƒD]}| d¡t  d¡qL|S)N)r”zFirst bit of text rr-zHello from the main thread r é2) rr rr]Ú_threadr¶Ú start_newrºrRr·)Úwr¼r¹rrrÚtestCs       r¿Ú__main__)&rr9rRr&rZpywin.frameworkrrZ pywin.mfcrrŸr Zpywin.scintilla.documentrxrZpywin.scintillarryZdocumentZCScintillaDocumentZWindowOutputDocumentParentrr"r!r8rdrcZpywin.scintilla.viewrzr{rwZWindowOutputViewr‚rr´rºr¿rrrrrÚs8      p4  ÿ:k