
    JeD                        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<        yy)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.c                    t         |   |       | j                  dt               ddd       d| _        | j                  | j                         | j                  t        | j                               | j                  d      | _	        y )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     </usr/lib/python3/dist-packages/spyder/widgets/reporterror.pyr5   zDescriptionWidget.__init__/   s~      	#( 	 	
7 	 	dkk"T[[)*"//6    c                 Z    | j                  | j                         | j                          y)zRemove text.N)truncate_selectionr<   remove_selected_textr=   s    r@   remove_textzDescriptionWidget.remove_textD   s"     3 34!!#rA   c                 z    | j                  | j                         | j                         rt        |           yy)zCut textN)rC   r<   has_selected_textr4   cut)r=   r?   s    r@   rI   zDescriptionWidget.cutI   s1     3 34!!#GKM $rA   c                    t        |      \  }}}}}| j                  d      }|| j                  k  r| j                  | j                  d       y|t        j
                  k(  rB| j                         r| j                          y| j                  |k(  ry| j                          y|t        j                  k(  r|r| j                          yt        | 1  |       y)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T000))$*=*=uEB$$$%%'  "$$7%%'BHH_HHJG!%(rA   c                     | j                  d      }|| j                  k  r| j                  | j                  d       y| j                         r| j	                          y| j                          y)z+Reimplemented to avoid removing the header.rK   r3   N)r;   r<   rL   rH   rF   stdkey_clear)r=   rV   s     r@   deletezDescriptionWidget.deleteb   sZ    ++H5T000))$*=*=uE##%rA   c                      y)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*$
)&	 rA   r+   c                   ,    e Zd ZdZeZ ee      ZddZ	y)ShowErrorWidgetz=Widget to show errors as they appear in the Internal console.Nc                     t        j                  | |       t        j                  |        t        j                  |        | j	                  d       y )NT)r   r5   r%   r&   setReadOnly)r=   r>   s     r@   r5   zShowErrorWidget.__init__w   s<    ""40t$$$T*rA   r]   )
r^   r_   r`   ra   r   QT_CLASSr   strsig_go_to_error_requestedr5   r[   rA   r@   rd   rd   r   s    GH &srA   rd   c                   r    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y)SpyderErrorDialogz(Custom error dialog for error reporting.Nc                 :   t        j                  | |       || _        d| _        | j	                  t        d             d| _        d| _        d| _        | j                  rt        d      }nt        d      }t        t        d      j                  |t        t        	            | _        | j                  j                  d
       | j                  j                  d
       | j                  j!                  t"        j$                         | j                  j'                  d       t)               | _        | j*                  j,                  j/                  | j0                         t        t        d      j                  t2                    | _        t7               }|j9                  t6        j:                         d}t        t        d      j                  |            }|j=                  dt6        j>                  |       |j=                  dt6        j@                  | j*                         t        t        d      j                  |            }t        t        d            | _!        | jB                  j                  d
       | jB                  j!                  t"        j$                         | jB                  j'                  d       tE        |       | _#        | jF                  j,                  j/                  | j0                         tI        |       | _%        | jJ                  jM                  tO                      | jJ                  jQ                          tR        | _*        d
| _+        tY        | jF                  j[                               | _.        t        t        d      j                  | jT                              | _/        ta        t        d            | _1        ta        t        d            | _2        tg        jh                  d      }tk        |t        d            | _6        | jl                  jo                  d       | jl                  jp                  j/                  | jr                         tk        t        d            | _:        | jt                  jp                  j/                  | jv                         | j                  r| jt                  jQ                          tk        t        d            | _<        | jx                  jp                  j/                  | jz                         t}               }	|	j                  | jl                         |	j                  | jt                         |	j                  | jx                         t               }
|
j                  | j                         |
j                  d       |
j                  |       |
j                  | j4                         |
j                  d       |
j                  |       |
j                  d       |
j                  | jB                         |
j                  d       |
j                  | jF                         |
j                  | jJ                         |
j                  | j^                         |
j                  d       | j                  s|
j                  | jb                         t               s
t               r| j                  dd      s,|
j                  | jd                         |
j                  d       |
j                  |	       |
j                  d dd d!       | j                  |
       | j                  d"d#       | j*                  j                          | j                  | j*                  | jF                         y )$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'$  " >>=>ECDE  "  U#2  4
5 	,,T2##D)$$R__5%%&89 [


&&t'='=>!' +5 )66<f_6M"O!m(()H)HI3Q1299,GHa!6!6Da!6!6

C -.55lCE  < =
 	##D)$$R__5%%&89 "34!8 	**2243I3IJ 't,))(*5*8'&*# !!7!7!C!C!EF &q *4 (55;V-1-L-L6N!O
 %Q (1 &2 3 %Q'L%MN ((8$%gq1C/DE""5)''(>(>?&q'89  ((););<>>!!#$QwZ0&&t{{3 %  1  !1!12  0 )"%//0"&")!//0&../"~~T--. !3!5==4F=GT--.b!(!!"b"b1vC

 	T%;%;<rA   c           	         t         j                  s	 t        j                          |sd}|rdj	                  |      }nd}t               }d| d| d| dt        j                          d	}|rx| j                  | d	d
      }t        |      rt        |      }t               }	dd|g}
n|}	g d}
t        |	|
      }|j                         \  }}|d|j                          dz  }|S # t        $ r Y w xY w)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  sB    ((113
 AK # $*6)#4 
 M)+        $ LLl<NLOE5))%0 l
D1,s.D"..0OGV # 	  	 	N y  s   C' '	C32C3c                     t        t        dz         }t               }|j                  dt	        |              |r|j                  dt	        |             |j                  |       t        j                  |       y)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65;/we5U  %rA   c                 n    || _         |r| j                          y| j                  j                  d       y)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  s-    &+#""$!!))"-rA   c                 H    |j                  d      \  }}|| _        || _        y)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                  j                         }| j                  dd }| j                  ||| j                  j                               }	 | j                  s| j                  nd}| j                  }t        |||       }|j                  ||      }|r| j                          yy# t        $ r t        j                   | t#        d      t#        d            }	|	t        j$                  t        j&                  fv r:t)        j*                         j-                  |       d}
| j/                  |
|	       Y yY y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  sG    

!,,88:(("-	 &&#y((224 ' 6
	C*.--$""\C$$D*3DIN*66ujIM

  	C&&'
  
C {77&&(00<<  $$*E$B 8	Cs   1AC BEEc                 .    | xj                   |z  c_         y)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                   j                         r?| j                   j                          | j                  j	                  t        d             y	| j                  dd       | j                   j                         j                  d       | j                   j                  | j                  dd       | j                   j                          | j                  j	                  t        d             y	)
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    <<!!#LL$$Q~%67KKS!LL!!#004LL--d.B.B485: . < LL$$Q~%67rA   c                    | j                   syt        | j                  j                               | j                  z
  }|| j
                  k  rB| j                  j                  dj                  | j
                  |z
  t        d                   n$| j                  j                  t        d             t        | j                  j                               }|t        k  r<| j                  j                  dj                  t        |z
  t        d                   n$| j                  j                  t        d             || j
                  k\  xr	 |t        k\  }| j                  j                  |       y)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  s3   **$00<<>?(()
777!!)) ? ?* L !"< =?@ !!))!,K*LM$**//+,(""**+ = !"< =?@ ""**1-F+GH(D,K,KK =)_< 	""#56rA   c                 :    | j                   j                  |       y)zSet the title for the report.N)ro   r   )r=   ro   s     r@   	set_titlezSpyderErrorDialog.set_title  s    

5!rA   c                 :    | j                   j                  |       y)z#Set the description for the report.N)r   r  )r=   r   s     r@   set_descriptionz!SpyderErrorDialog.set_description  s    ++K8rA   c                 :    | j                   j                  |       y)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   ~   sf    2O=b M M^ & &*.!&CP%872"9>rA   rk   c                      ddl m}   |        }t               }d|_        |j	                          t        j                  |j                                y )Nr   )qapplicationT)spyder.utils.qthelpersr  rk   r   r  sysexitexec_)r  appdlgs      r@   testr    s6    3
.C

CCLHHJHHSYY[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 'F F F F
' ' @ @ @ & D K K ) - 3 7 D <
 C( CL	)+<m 	e>!< e>P zF rA   