B
    b_q                 @   sJ   d Z dZddlmZ ddlZddlZddlZddlmZ G dd dZ	dS )	zBuffer class.z(Patrick K. O'Brien <pobrien@orbtech.com>   )Interpreter    N)documentc               @   s^   e Zd ZdZdZdddZdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd ZdS )BufferzBuffer class.r   Nc             C   s   t  jd7  _t j| _ti d| _d| _i | _d| _ttj	| _	tj
dd | _x,y| jd W qR tk
rx   P Y qRX qRW x,y| jd W q tk
r   P Y qX qW | | dS )zCreate a Buffer instance.r   )locals N.)r   idr   interpnameeditorseditorlistsysmodulespathsyspathremove
ValueErroropen)selffilename r   +lib/python3.7/site-packages/wx/py/buffer.py__init__   s&    zBuffer.__init__c             C   s   || _ || j|j< dS )zAdd an editor.N)r   r   r	   )r   r   r   r   r   	addEditor(   s    zBuffer.addEditorc             C   s   | j r| j  S dS dS )z:Return True if text in editor has changed since last save.FN)r   
hasChanged)r   r   r   r   r   -   s    
zBuffer.hasChangedc             C   s,   |sdS t j|r"| || _nd| _dS )zNew empty buffer.NT)osr   existsoverwriteConfirm	confirmed)r   filepathr   r   r   new4   s
    z
Buffer.newc             C   s   t || _| jjp dt| j | _| jj| _| jj	rV| jj	| j
krV| j
d| jj	 | jjrttj| jjrtd| _| jr| j }| jj| |d dS )zOpen file into buffer.z	Untitled:r   T)buffertextN)r   Documentdocr   strr	   r   filebase
modulenameZfiledirr   insertr!   r   r   r   r    r   readZ
_setBuffer)r   r   r$   r   r   r   r   =   s    

zBuffer.openc             C   s   dS )z%Confirm overwriting an existing file.Fr   )r   r!   r   r   r   r   M   s    zBuffer.overwriteConfirmc             C   s`   | j j}|sdS tj|s"d| _| js4| || _| jr\| j | j	  | jr\| j
  dS )zSave buffer.NT)r&   r!   r   r   r   r    r   writer   getTextZsetSavePoint)r   r!   r   r   r   saveQ   s    zBuffer.savec             C   s,   t || _| jj| _| jj| _|   dS )zSave buffer.N)r   r%   r&   r   r   r(   r)   r.   )r   r   r   r   r   saveAs_   s    

zBuffer.saveAsc          	   C   s   | j rt| jdsdS tj}| jt_| j }|dd}|dd}| jpP| j	}t
|}|j }z`yt||d}W n    Y nX yt|| W n    Y n X | j j  | j j| dS W d|t_x tjD ]}|| jkrtj|= qW X dS )	zsUpdate the namespace for autocompletion and calltips.

        Return True if updated, False if there was an error.r-   Fz

execTN)r
   hasattrr   r   r   r   r-   replacer)   r   types
ModuleType__dict__copycompiler2   r   clearupdater   )r   r   r$   r   moduleZnewspacecodemr   r   r   updateNamespacef   s4    



zBuffer.updateNamespace)N)__name__
__module____qualname____doc__r	   r   r   r   r"   r   r   r.   r/   r?   r   r   r   r   r      s   
	r   )
rC   
__author__Zinterpreterr   r5   r   r   r   r   r   r   r   r   r   <module>   s   