
    G@dD                        d Z ddlZddlmZ ddlmZmZmZmZ ddl	m
Z
 ddlmZmZmZmZmZmZmZmZmZmZmZ ddlmZmZmZmZ ddlmZ dd	lmZm Z m!Z! dd
l"m#Z# ddl$m%Z% ddl&m'Z'm(Z(m)Z) ddl*m+Z+ ddl,m-Z- ddl.m/Z/ ddl0m1Z1 ddl2m3Z3m4Z4 ddl5m6Z6 dZ7dZ8 G d de6          Z9 G d de4e%e3          Z: G d dee          Z;d Z<e=dk    r e<             dS dS )zReport Error Dialog.    N)quote)QtQUrl	QUrlQuerySignal)QDesktopServices)QApplication	QCheckBoxQDialogQFormLayoutQHBoxLayoutQLabel	QLineEditQMessageBoxQPlainTextEditQPushButtonQVBoxLayout)__project_url____trouble_url__dependenciesget_versions_text)SpyderConfigurationAccessor)_
is_pynsistrunning_in_mac_app)get_font)ConsoleBaseWidget)is_conda_envget_conda_env_path
find_conda)ima)run_program)restore_keyevent)GithubBackend)BaseEditMixinTracebackLinksMixin)SimpleCodeEditor   2   c                   J     e Zd ZdZd	 fd	Zd Z fdZ fdZd Zd Z	 xZ
S )
DescriptionWidgetz"Widget to enter error description.Nc                 Z   t                                          |           |                     dt                      ddd           d| _        |                     | j                   |                     t          | j                             |                     d          | _	        d S )NmdTF)languagefontwraplinenumbershighlight_current_linezR### What steps will reproduce the problem?

<!--- You can use Markdown here --->

eof)
super__init__setup_editorr   headerset_textmove_cursorlenget_positionheader_end_pos)selfparent	__class__s     :lib/python3.11/site-packages/spyder/widgets/reporterror.pyr5   zDescriptionWidget.__init__/   s        	#( 	 	
 	
 	
7 	 	dk"""T[))***"//66    c                 b    |                      | j                   |                                  dS )zRemove text.N)truncate_selectionr<   remove_selected_textr=   s    r@   remove_textzDescriptionWidget.remove_textD   s1     3444!!#####rA   c                     |                      | j                   |                                 r"t                                                       dS dS )zCut textN)rC   r<   has_selected_textr4   cut)r=   r?   s    r@   rI   zDescriptionWidget.cutI   sM     3444!!## 	GGKKMMMMM	 	rA   c                    t          |          \  }}}}}|                     d          }|| j        k     r|                     | j        d           dS |t          j        k    rM|                                 r|                                  dS | j        |k    rdS |                                  dS |t          j	        k    r|r| 
                                 dS t                                          |           dS )z5Reimplemented Qt Method to avoid removing the header.cursorr3   N)r#   r;   r<   restrict_cursor_positionr   Key_BackspacerH   rF   stdkey_backspaceKey_XrI   r4   keyPressEvent)r=   eventtextkeyctrlshiftcursor_positionr?   s          r@   rP   zDescriptionWidget.keyPressEventO   s    (8(?(?%tS$++H55T000))$*=uEEEEEB$$$%%'' (  """""$77%%'''''BH___HHJJJJJGG!!%(((((rA   c                     |                      d          }|| j        k     r|                     | j        d           dS |                                 r|                                  dS |                                  dS )z+Reimplemented to avoid removing the header.rK   r3   N)r;   r<   rL   rH   rF   stdkey_clear)r=   rV   s     r@   deletezDescriptionWidget.deleteb   s    ++H55T000))$*=uEEEEE##%% 	 rA   c                     dS )z5Reimplemented Qt Method to not show the context menu.N )r=   rQ   s     r@   contextMenuEventz"DescriptionWidget.contextMenuEventm   s    rA   N)__name__
__module____qualname____doc__r5   rF   rI   rP   rY   r\   __classcell__)r?   s   @r@   r+   r+   ,   s        ,,7 7 7 7 7 7*$ $ $
    ) ) ) ) )&	  	  	       rA   r+   c                   4    e Zd ZdZeZ ee          ZddZ	dS )ShowErrorWidgetz=Widget to show errors as they appear in the Internal console.Nc                     t          j        | |           t          j        |            t          j        |            |                     d           d S )NT)r   r5   r%   r&   setReadOnly)r=   r>   s     r@   r5   zShowErrorWidget.__init__w   sQ    "4000t$$$$T***rA   r]   )
r^   r_   r`   ra   r   QT_CLASSr   strsig_go_to_error_requestedr5   r[   rA   r@   rd   rd   r   sA        GGH &s     rA   rd   c                       e Zd ZdZddZedd            Zedd            Zd Z	d	 Z
d
 Zd Zd Zd Zd Zd Zd ZdS )SpyderErrorDialogz(Custom error dialog for error reporting.NFc                    t          j        | |           || _        d| _        |                     t          d                     d| _        d| _        d| _        | j        rt          d          }nt          d          }t          t          d          
                    |t          t          	                    | _        | j                            d
           | j                            d
           | j                            t"          j                   | j                            d           t)                      | _        | j        j                            | j                   t          t          d          
                    t2                              | _        t7                      }|                    t6          j                   d}t          t          d          
                    |                    }|                    dt6          j        |           |                    dt6          j         | j                   t          t          d          
                    |                    }t          t          d                    | _!        | j!                            d
           | j!                            t"          j                   | j!                            d           tE          |           | _#        | j#        j                            | j                   tI          |           | _%        | j%        &                    tO                                 | j%        (                                 tR          | _*        d
| _+        tY          | j#        -                                          | _.        t          t          d          
                    | j*                            | _/        ta          t          d                    | _1        ta          t          d                    | _2        tg          j4        d          }tk          |t          d                    | _6        | j6        7                    d           | j6        j8                            | j9                   tk          t          d                    | _:        | j:        j8                            | j;                   | j        r| j:        (                                 tk          t          d                    | _<        | j<        j8                            | j=                   t}                      }	|	?                    | j6                   |	?                    | j:                   |	?                    | j<                   t                      }
|
?                    | j                   |
A                    d           |
B                    |           |
?                    | j                   |
A                    d           |
?                    |           |
A                    d           |
?                    | j!                   |
A                    d           |
?                    | j#                   |
?                    | j%                   |
?                    | j/                   |
A                    d           | j        s|
?                    | j1                   t                      st                      r| E                    dd          s/|
?                    | j2                   |
A                    d           |
B                    |	           |
F                    d dd d!           | G                    |
           | H                    d"d#           | j        I                                 | J                    | j        | j#                   d S )$NFzIssue reporterz
spyder-idespyder z%Please fill the following informationz+Spyder has encountered an internal problem!a<  <h3>{title}</h3>Before reporting this problem, <i>please</i> consult our comprehensive <b><a href="{trouble_url}">Troubleshooting Guide</a></b> which should help solve most issues, and search for <b><a href="{project_url}">known bugs</a></b> matching your error message or problem description for a quicker solution.)titletrouble_urlproject_urlTzfont-size: 12px;z{} more characters to go...z<font color="Red">*</font>z<b>Title</b>: {}r   z<b>Steps to reproduce:</b> {}zPlease enter a detailed step-by-step description (in English) of what led up to the problem below. Issue reports without a clear way to reproduce them will be closed.z*Hide all future errors during this sessionz#Include IPython console environmentgithubzSubmit to GithubShow detailsClose         r(   defaultmain_interpretersection   
   :  iX  )Kr   r5   	is_report_testingsetWindowTitler   _github_org_github_repoerror_tracebackr   formatr   r   
main_labelsetOpenExternalLinkssetWordWrapsetAlignmentr   AlignJustifysetStyleSheetr   ro   textChangedconnect_contents_changedTITLE_MIN_CHARStitle_chars_labelr   setFieldGrowthPolicyExpandingFieldsGrow	setWidget	LabelRole	FieldRole
steps_textr+   input_descriptionrd   detailsset_pythonshell_fontr   hideDESC_MIN_CHARSdescription_minimum_lengthrequire_minimum_lengthr:   toPlainTextinitial_charsdesc_chars_labelr
   dismiss_boxinclude_envr!   iconr   
submit_btn
setEnabledclicked_submit_to_githubdetails_btn_show_details	close_btnrejectr   	addWidgetr   
addSpacing	addLayoutr   r   get_confsetContentsMargins	setLayoutresizesetFocussetTabOrder)r=   r>   r   ro   form_layoutred_asterisktitle_labelsteps_headergh_iconbuttons_layoutlayouts              r@   r5   zSpyderErrorDialog.__init__   s   v&&&" A.//000'$  " > 	E=>>EECDDE  "   U#2  4 4
5 
5 	,,T222##D)))$$R_555%%&8999 [[

&&t'=>>>!' +5 )6 )66<f_6M6M"O "O!mm(()HIII3Q12299,GGHHa!6DDDa!6
CCC -..55lCCE E  < = =
 
 	##D)))$$R_555%%&8999 "34!8!8 	*2243IJJJ 't,,))(**555*8'&*# !!7!C!C!E!EFF &q *4 (5 (55;V-1-L6N 6N!O !O
 %Q (1 &2 &2 3 3 %Q'L%M%MNN (8$$%gq1C/D/DEE""5)))''(>???&q'8'899 (();<<<> 	$!!###$QwZZ00&&t{333 %  111  !1222  000 )))"%%%/000"&&&")))!/000&&&.///"~ 	/T-... 	"!3!5!5	"==4F=GG	" T-...b!!!(((!!"b"b111vC
 	T%;<<<<<rA   rn   c           	      ,   t           j        s%	 t          j                     n# t          $ r Y nw xY w|sd}|rd                    |          }nd}t                      }d| d| d| dt          j                     d	}|r|                     | d	d
          }t          |          r#t          |          }t                      }	dd|g}
n|}	g d}
t          |	|
          }|                                \  }}|d|                                 dz  }|S )a1  
        Render issue content.

        Parameters
        ----------
        description: str
            Description to include in issue message.
        traceback: str
            Traceback text.
        include_env: bool (False)
            Whether to include the IPython console environment.
        z%### What steps reproduce the problem?z(### Traceback
```python-traceback
{}
```rn   z## Description

z

z

## Versions

z
### Dependencies

```
z
```

executablerz   r{   )pyexeclistz--prefix)z-mpipr   )argsz?
### Environment

<details><summary>Environment</summary>

```
z
```
</details>
)r   DEPENDENCIESdeclare_dependencies
ValueErrorr   r   statusr   r   r   r    r"   communicatedecode)clsdescription	tracebackr   error_sectionversions_textissue_templatepyexepathexer   procext_envstderrs                 r@   render_issuezSpyderErrorDialog.render_issue  s    ( 	13333     	BAK  	# $*6)#4#4 M
 M)++  
       $  	LLl<NLOOE5))) -)%00 ll
D1,,,s...D"..00OGV 	 		 	 	 	N s   " 
//c                 2   t          t          dz             }t                      }|                    dt	          |                      |r#|                    dt	          |                     |                    |           t          j        |           dS )a  
        Open a new issue on Github with prefilled information.

        Parameters
        ----------
        body: str
            The body content of the report.
        title: str or None, optional
            The title of the report. Default is None.
        z/issues/newbodyro   N)r   r   r   addQueryItemr   setQueryr   openUrl)r   ro   urlquerys       r@   open_web_reportz!SpyderErrorDialog.open_web_reportb  s     ?]23365;;/// 	6we555U %%%%%rA   c                 x    || _         |r|                                  dS | j                            d           dS )z*Remove the requirement for minimum length.rn   N)r   r   r   setText)r=   states     r@   set_require_minimum_lengthz,SpyderErrorDialog.set_require_minimum_lengthx  sG    &+# 	.""$$$$$!))"-----rA   c                 R    |                     d          \  }}|| _        || _        dS )z2Set the report Github organization and repository./N)splitr   r   )r=   repo_fullnameorgrepos       r@   set_github_repo_orgz%SpyderErrorDialog.set_github_repo_org  s/    !'',,	T rA   c                    | j                                         }| j                                        }| j        dd         }|                     ||| j                                                  }	 | j        s| j	        nd}| j
        }t          |||           }|                    ||          }|r|                                  dS dS # t          $ r t          j        | t#          d          t#          d                    }	|	t          j        t          j        fv rBt)          j                                        |           d}
|                     |
|	           Y dS Y dS w xY w)
z/Action to take when pressing the submit button.Nrw   )r   r   r   
ccordoba12)parent_widgetErrora  An error occurred while trying to send the issue to Github automatically. Would you like to open it manually?<br><br>If so, please make sure to paste your clipboard into the issue report box that will appear in a new browser tab before clicking <i>Submit</i> on that page.zZ 
<!---   *** BEFORE SUBMITTING: PASTE CLIPBOARD HERE TO COMPLETE YOUR REPORT ***   ---!>
)r   ro   )ro   rR   r   r   r   r   r   	isCheckedr   r   r   r$   send_reportclose	Exceptionr   questionr   YesOkr	   	clipboardr   r   )r=   ro   r   r   
issue_textr   r   github_backendgithub_reportret
issue_bodys              r@   r   z#SpyderErrorDialog._submit_to_github  s    
!!,88::("-	 &&#y(2244 ' 6 6
	C*.-I$""\C$D*3DIIIN*66ujIIM 

  	C 	C 	C&'

   
 
C {777&((00<<<<  $$*E$BBBBBB 877	Cs   2AC BE%$E%c                 &    | xj         |z  c_         dS )z9Append text to the traceback, to be displayed in details.N)r   )r=   rR   s     r@   append_tracebackz"SpyderErrorDialog.append_traceback  s    $rA   c                    | j                                         rB| j                                          | j                            t          d                     d	S |                     dd           | j                                                             d           | j         	                    | j
        dd           | j                                          | j                            t          d                     d	S )
z Show traceback on its own dialogrs   r   i  rn   TF)errorpromptzHide detailsN)r   	isVisibler   r   r   r   r   documentsetPlainTextappend_text_to_shellr   showrE   s    r@   r   zSpyderErrorDialog._show_details  s    <!!## 
	8L$$Q~%6%677777KKS!!!L!!##00444L--d.B485: . < < < L$$Q~%6%677777rA   c                    | j         sdS t          | j                                                  | j        z
  }|| j        k     rD| j                            d                    | j        |z
  t          d                               n'| j                            t          d                     t          | j
                                                  }|t          k     rD| j                            d                    t          |z
  t          d                               n'| j                            t          d                     || j        k    o
|t          k    }| j                            |           dS )zActivate submit_btn.Nz{} {}zmore characters to go...zDescription complete; thanks!zTitle complete; thanks!)r   r:   r   r   r   r   r   r   r   r   ro   rR   r   r   r   r   )r=   
desc_charstitle_charssubmission_enableds       r@   r   z#SpyderErrorDialog._contents_changed  s|   * 	F$0<<>>??()
777!)) ?* L !"< = =? ?@ @ @ @ !))!,K*L*LMMM$*//++,,(("**+ = !"< = =? ?@ @ @ @ "**1-F+G+GHHH(D,KK =)_< 	""#566666rA   c                 :    | j                             |           dS )zSet the title for the report.N)ro   r   )r=   ro   s     r@   	set_titlezSpyderErrorDialog.set_title  s    
5!!!!!rA   c                 :    | j                             |           dS )z#Set the description for the report.N)r   r  )r=   r   s     r@   set_descriptionz!SpyderErrorDialog.set_description  s    ++K88888rA   c                 :    | j                             |           dS )z/Set the color scheme for the description input.N)r   set_color_scheme)r=   color_schemes     r@   r  z"SpyderErrorDialog.set_color_scheme  s    //=====rA   )NF)rn   rn   Fr]   )r^   r_   r`   ra   r5   classmethodr   staticmethodr   r   r   r   r   r   r   r	  r  r  r[   rA   r@   rk   rk   ~   s       22O= O= O= O=b M M M [M^ & & & \&*. . .! ! !&C &C &CP% % %8 8 87 7 72" " "9 9 9> > > > >rA   rk   c                      ddl m}   |             }t                      }d|_        |                                 t          j        |                                           d S )Nr   )qapplicationT)spyder.utils.qthelpersr  rk   r   r  sysexitexec_)r  appdlgs      r@   testr    s\    333333
,..C


CCLHHJJJHSYY[[rA   __main__)>ra   r  urllib.parser   qtpy.QtCorer   r   r   r   
qtpy.QtGuir   qtpy.QtWidgetsr	   r
   r   r   r   r   r   r   r   r   r   rm   r   r   r   r   spyder.api.config.mixinsr   spyder.config.baser   r   r   spyder.config.guir   &spyder.plugins.console.widgets.consoler   spyder.utils.condar   r   r    spyder.utils.icon_managerr!   spyder.utils.programsr"   r  r#   spyder.widgets.github.backendr$   spyder.widgets.mixinsr%   r&   spyder.widgets.simplecodeeditorr'   r   r   r+   rd   rk   r  r^   r[   rA   r@   <module>r)     s     


       4 3 3 3 3 3 3 3 3 3 3 3 ' ' ' ' ' 'F F F F F F F F F F F F F F F F F F F F F F F F F F
' ' ' ' ' ' ' ' ' ' ' ' @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ & & & & & & D D D D D D K K K K K K K K K K ) ) ) ) ) ) - - - - - - 3 3 3 3 3 3 7 7 7 7 7 7 D D D D D D D D < < < < < <
 C C C C C( C C CL	 	 	 	 	)+<m 	 	 	e> e> e> e> e>!< e> e> e>P   zDFFFFF rA   