
    Je                         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 ddlmZ ddlmZ dd	lmZ dd
lmZ  G d de      Z e       Zd ZddZd Zedk(  r e        yy)z
Generic object editor dialog
    N)QObject)
FakeObjectnumpypandasPIL)is_known_type)is_text_string)ArrayEditor)DataFrameEditor)
TextEditor)CollectionsEditorc                   *    e Zd Zd Zd Zd Zd Zd Zy)DialogKeeperc                 J    t        j                  |        i | _        d | _        y N)r   __init__dialogs	namespaceselfs    V/usr/lib/python3/dist-packages/spyder/plugins/variableexplorer/widgets/objecteditor.pyr   zDialogKeeper.__init__   s        c                     || _         y r   )r   )r   r   s     r   set_namespacezDialogKeeper.set_namespace#   s	    "r   c                 @    |||f j                   t        |      <   |j                  j                  t        |      f fd	       |j                  j                  t        |      f fd	       |j                          |j                          |j                          y )Nc                 &    j                  |       S r   )editor_acceptedeidr   s    r   <lambda>z,DialogKeeper.create_dialog.<locals>.<lambda>)       D,@,@,E r   c                 &    j                  |       S r   )editor_rejectedr   s    r   r    z,DialogKeeper.create_dialog.<locals>.<lambda>+   r!   r   )r   idacceptedconnectrejectedshowactivateWindowraise_)r   dialogrefnamefuncs   `   r   create_dialogzDialogKeeper.create_dialog&   st    #)7D#8RZ  "6
E	G "6
E	Gr   c                     | j                   |   \  }}} ||      | j                  |<   | j                   j                  |       y r   )r   r   pop)r   	dialog_idr+   r,   r-   s        r   r   zDialogKeeper.editor_accepted0   s;     $Y 7"&v,w#r   c                 :    | j                   j                  |       y r   )r   r0   )r   r1   s     r   r#   zDialogKeeper.editor_rejected5   s    #r   N)__name__
__module____qualname__r   r   r.   r   r#    r   r   r   r      s    
#$
$r   r   c                     d t                }t         t        j                        r6t        j                  t        ur t               }|j                   ||      syt         t        j                  j                        rft        j                  t        urPt        j                  t        ur:t               }t        j                         }|j                  |||      sy fdnt         t        j                  t        j                  f      r2t        j                  t        urt               }|j                         s9yt               rt         ||      }nt!               }|j#                   ||       fd}||fS )as  Creates the editor dialog and returns a tuple (dialog, func) where func
    is the function to be called with the dialog instance as argument, after
    quitting the dialog box

    The role of this intermediate function is to allow easy monkey-patching.
    (uschmitt suggested this indirection here so that he can monkey patch
    oedit to show eMZed related data)
    c                     | S r   r6   )datas    r   r    zcreate_dialog.<locals>.<lambda>E   s    T r   )titlereadonlyNc                 Z    t         j                  j                  | j                        S )N)mode)r   Image	fromarrayr=   )r9   objs    r   r    zcreate_dialog.<locals>.<lambda>S   s    !4!4T!4!I r   c                 0     | j                               S r   )	get_value)r+   	conv_funcs    r   end_funczcreate_dialog.<locals>.end_func_   s    ))+,,r   )r   
isinstancenpndarrayr   r
   setup_and_checkr   r>   arraypd	DataFrameSeriesr   r	   r   r   setup)r@   obj_namer;   r+   r9   rD   rC   s   `     @r   r.   r.   ;   s1    "I %%H#rzz"rzz'C%%c/7 & 9
S#))//
*syy
/J

*,xx}%%d(/7 & 9I	
S2<<3
4LL
* "%%c*		Cx(C"$S8<- 8r   c                 \   |rd}n:t        |       sJ | }|
t               }t        j                  |       ||   } ||d<   t	        | |      }|y|\  }}|r|j                         r ||      S yt        j	                  |||       ddl}|j                  dk(  r|r|j                          yyy)aY  Edit the object 'obj' in a GUI-based editor and return the edited copy
    (if Cancel is pressed, return None)

    The object 'obj' is a container

    Supported container types:
    dict, list, set, tuple, str/unicode or numpy.array

    (instantiate a new QApplication if necessary,
    so it can be called directly from the interpreter)
     N__qapp__r   nt)r	   globalskeeperr   r.   exec_osname)	r@   modalr   apprN   resultr+   rD   rV   s	            r   oeditr[   e   s     c"""	IY'! #	*3)F~FH<<>F##  	VXx877d?sIIK  #?r   c                     ddl m}   |        }t        j                  j	                  ddd      j                  d      }t        j                  j                  |      }dg d	h d
dt        j                  j                  dd      ddgddt        j                  j                  dd      |t        j                  ddd      t        j                  ddd      d	}t        |      } G d dt              } |       }t        t        ||             t        t        ||             t        t        t        j                  j                  dd      |             t        t        t        j                  |             t        |       y)zRun object editor testr   )qapplication      )d   r`   )sizeuint8zkjkj kj k j j kj k jkj)r^         kjkjN>   FNABCr^      rc   
   ri   )dabg&S?i        )	strlistsetdictfloatrI   imagedatedatetimec                       e Zd Zd Zy)test.<locals>.Foobarc                     d| _         y )Ntoto)textr   s    r   r   ztest.<locals>.Foobar.__init__   s	    DIr   N)r3   r4   r5   r   r6   r   r   Foobarry      s    	r   r}   )rY   N)spyder.utils.qthelpersr]   rF   randomrandintastyper   r>   r?   randrw   rv   r[   objectprint__doc__)r]   rY   r9   ru   exampler}   foobars          r   testr      s%    4
.C99Q*5<<WEDII%E..DRYY^^B%;1a&I		r2.}}T1a0#,,T1a8	G %LE  XF	%C
 !	%S
!"	%		r2&C
01	%3
'(	'Nr   __main__)TNN)r   rw   qtpy.QtCorer    spyder_kernels.utils.lazymodulesr   r   rF   r   rJ   r   spyder_kernels.utils.nsviewr   spyder.py3compatr	   3spyder.plugins.variableexplorer.widgets.arrayeditorr
   7spyder.plugins.variableexplorer.widgets.dataframeeditorr   2spyder.plugins.variableexplorer.widgets.texteditorr    spyder.widgets.collectionseditorr   r   rT   r.   r[   r   r3   r6   r   r   <module>r      sn   
   0 0 5 , K I >$7 $6 
'T$T> zF r   