
    Je                        d Z ddlZddlmZ ddlmZ ddlmZmZ ddl	m
Z
mZmZmZmZmZmZ ddlmZ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m Z m!Z!m"Z" dd	l#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l0m1Z1m2Z2m3Z3 ddl4m5Z5 ddl6m7Z7m8Z8m9Z9m:Z: ddl;m<Z< ddl=m>Z> e?e@e%j                  e%j                  fZCeDe%j                  e%j                  fZGg dZHdZIdZJdZKdZLdZMdZNdZOdZPdZQdZRdZSej                  ZUdZVd ZWd!ZXd" ZYd# ZZ G d$ d%e
      Z[ G d& d'ee)      Z\ G d( d)e
      Z] G d* d+e
      Z^ G d, d-e>e)      Z_d1d.Z`d/ Zaebd0k(  r ea        yy)2ae  
Pandas DataFrame Editor Dialog.

DataFrameModel is based on the class ArrayModel from array editor
and the class DataFrameModel from the pandas project.
Present in pandas.sandbox.qtpandas in v0.13.1.

DataFrameHeaderModel and DataFrameLevelModel are based on the classes
Header4ExtModel and Level4ExtModel from the gtabview project.
DataFrameModel is based on the classes ExtDataModel and ExtFrameModel, and
DataFrameEditor is based on gtExtTableView from the same project.

DataFrameModel originally based on pandas/sandbox/qtpandas.py of the
`pandas project <https://github.com/pandas-dev/pandas>`_.
The current version is qtpandas/models/DataFrameModel.py of the
`QtPandas project <https://github.com/draperjames/qtpandas>`_.

Components of gtabview from gtabview/viewer.py and gtabview/models.py of the
`gtabview project <https://github.com/TabViewer/gtabview>`_.
    N)perf_counter)parse)from_qvariantto_qvariant)QAbstractTableModelQEventQItemSelectionModelQModelIndexQtSignalSlot)QColorQCursor)QApplication	QCheckBoxQGridLayoutQHBoxLayoutQInputDialog	QLineEditQMenuQMessageBoxQPushButton
QTableView
QScrollBarQTableWidgetQFrameQItemDelegate)numpypandas)SpyderConfigurationAccessor)_)DEFAULT_SMALL_DELTA)get_font)is_text_stringis_type_text_stringto_text_string)ima)add_actionscreate_action
keybindingqapplication)get_idx_rect)
BaseDialog)falsef0z0.z0.0 z%.6gg    Ag     j@<   i  (   gQ?gQ?gffffff?      ?g333333?g?g?g333333?c                 6    | j                         t        v rd} | S )zl
    Used to convert bool entrance to false.

    Needed since any string in bool('') will return True.
     )lower_bool_false)values    Y/usr/lib/python3/dist-packages/spyder/plugins/variableexplorer/widgets/dataframeeditor.pybool_false_checkr;   ]   s     {{}#L    c                 r    | D cg c]  }||	 }}t        | \  }}t        |      t        |      fS c c}w )z'Returns the global maximum and minimum.)zipmaxmin)col_valsindexxcol_vals_without_Nonemax_colmin_cols         r:   
global_maxrG   h   sC    (0B1AMQBB12GWw<W%% Cs   44c                   :   e Zd ZdZedfdZd Zd Zd Ze	d        Z
e	d        Ze	d	        Zdd
Zd Zd Zd Zd Zd Zd Zd Zd Zej.                  fdZd Zej4                  fdZd Zej:                  dfdZd Z e        fdZ!ddZ" e        fdZ#d Z$y)DataFrameModelz
    DataFrame Table Model.

    Partly based in ExtDataModel and ExtFrameModel classes
    of the gtabview project.

    For more information please see:
    https://github.com/wavexx/gtabview/blob/master/gtabview/models.py
    Nc                    t        j                  |        || _        || _        d | _        d | _        || _        d | _        g | _        | j                  j                  d   | _
        | j                  j                  d   | _        | j                  | j                  z  }d | _        |t        k  r0| j                          d| _        d| _        | j#                  d       nd| _        d| _        | j#                  d       |t        kD  rt$        | _        t(        | _        y | j                  t,        kD  rt$        | _        n| j                  | _        | j                  t.        kD  rt(        | _        y | j                  | _        y )Nr      TF)r   __init__dialogdfdf_columns_listdf_index_list_formatcomplex_intrandisplay_error_idxsshape
total_rows
total_colsmax_min_col
LARGE_SIZEmax_min_col_updatecolum_avg_enabledbgcolor_enabled	colum_avgROWS_TO_LOADrows_loadedCOLS_TO_LOADcols_loadedLARGE_NROWS
LARGE_COLS)self	dataFrameformatparentsizes        r:   rL   zDataFrameModel.__init__z   s-   $$T*#!""$''--*''--*0*##%%)D"#'D NN1%*D"#(D NN1 *+D+D,#/ #'?? +#/ #'?? r<   c                 d    |dk(  r| j                   j                  S | j                   j                  S )z
        Return the corresponding labels taking into account the axis.

        The axis could be horizontal (0) or vertical (1).
        r   )rN   columnsrB   rc   axiss     r:   _axiszDataFrameModel._axis   s%     #'!)tww>>r<   c                    |dk(  rA| j                   )| j                  j                  j                         | _         | j                   S | j                  )| j                  j
                  j                         | _        | j                  S )z
        Return the corresponding labels as a list taking into account the axis.

        The axis could be horizontal (0) or vertical (1).
        r   )rO   rN   ri   tolistrP   rB   rj   s     r:   
_axis_listzDataFrameModel._axis_list   sm     19##+'+ww'='='?$'''!!)%)WW]]%9%9%;"%%%r<   c                 j    | j                  |      }t        |d      sdS t        |j                        S )z
        Return the number of levels in the labels taking into account the axis.

        Get the number of levels for the columns (0) or rows (1).
        levelsrK   )rl   hasattrlenrq   )rc   rk   axs      r:   _axis_levelszDataFrameModel._axis_levels   s.     ZZH-qA3ryy>Ar<   c                 .    | j                   j                  S )z"Return the shape of the dataframe.)rN   rT   rc   s    r:   rT   zDataFrameModel.shape   s     ww}}r<   c                 F    | j                  d      | j                  d      fS )z<Return the levels for the columns and rows of the dataframe.r   rK   )ru   rw   s    r:   header_shapezDataFrameModel.header_shape   s%     !!!$d&7&7&:;;r<   c                 .    t        | j                          S )z8Return the max value of the dimensions of the dataframe.)r?   rT   rw   s    r:   
chunk_sizezDataFrameModel.chunk_size   s     DJJL!!r<   c                     | j                  |      }t        |d      s| j                  |      }||   S |j                  |   |   S )z
        Return the values of the labels for the header of columns or rows.

        The value corresponds to the header of column or row x in the
        given level.
        rq   )rl   rr   ro   values)rc   rk   rC   levelrt   s        r:   headerzDataFrameModel.header   sF     ZZr8$&Ba5L99Q<&&r<   c                     | j                  |      }t        |d      r|j                  |   S |j                  r|j                  S y)z'Return the labels of the levels if any.rq   N)rl   rr   namesname)rc   rk   r~   rt   s       r:   r   zDataFrameModel.name   s=    ZZ2x 88E?"7777N r<   c                 2   | j                   j                  d   dk(  ryg | _        | j                   j                         D ]  \  }}	 |j                  t
        t        z   v r|j                  t
        v r%|j                  d      }|j                  d      }n@|j                         j                  d      }|j                         j                  d      }||k7  r||g}n
||dz
  g}nd}| j                  j                  |        y# t        $ r d}Y +w xY w)a  
        Determines the maximum and minimum number in each column.

        The result is a list whose k-th entry is [vmax, vmin], where vmax and
        vmin denote the maximum and minimum of the k-th column (ignoring NaN).
        This list is stored in self.max_min_col.

        If the k-th column has a non-numerical dtype, then the k-th entry
        is set to None. If the dtype is complex, then compute the maximum and
        minimum of the absolute values. If vmax equals vmin, then vmin is
        decreased by one.
        r   NT)skipnarK   )rN   rT   rW   itemsdtypeREAL_NUMBER_TYPESCOMPLEX_NUMBER_TYPESr?   r@   abs	TypeErrorappend)rc   __colvmaxvminmax_mins         r:   rY   z!DataFrameModel.max_min_col_update   s    77==q ww}} 	-GB99 14H HHyy$55"wwdw3"wwdw3"wwy}}D}9"wwy}}D}9t|#',#'"2"G ##G,)	-$  s   B$DDDc                     | j                   S )zReturn current format)rQ   rw   s    r:   
get_formatzDataFrameModel.get_format  s     ||r<   c                 2    || _         | j                          y)zChange display formatN)rQ   reset)rc   re   s     r:   
set_formatzDataFrameModel.set_format  s    

r<   c                 8    |dkD  | _         | j                          y)Toggle backgroundcolorr   N)r[   r   rc   states     r:   bgcolorzDataFrameModel.bgcolor  s    $qy

r<   c                 x    |dkD  | _         | j                   r	d | _        nt        | _        | j                          y)r   r   c                     | |   S N )rA   rB   s     r:   <lambda>z*DataFrameModel.colum_avg.<locals>.<lambda>   s
    huo r<   N)rZ   
return_maxrG   r   r   s     r:   r\   zDataFrameModel.colum_avg  s.    !&!!EDO(DO

r<   c                    |j                         }| j                  sy| j                  |j                         |      }| j                  |   t        j                  |      rHt        t              }t        |      r|j                  t               |S |j                  t               |S t        |t              rt        }nt         }| j#                  | j                  |      \  }}	 ||z
  dk(  rd}n||z
  }t&        t(        | ||      z
  z  |z  z   }	t!        t        |	            }	|	dkD  rd}	t        j*                  |	t,        t.        t0              }|S # t$        $ r Y yw xY w)z$Background color depending on value.Nr   r4   rK   )columnr[   	get_valuerowrW   pdisnar   BACKGROUND_NONNUMBER_COLORr$   	setAlphaFBACKGROUND_STRING_ALPHABACKGROUND_MISC_ALPHA
isinstancer   r   floatr   r   BACKGROUND_NUMBER_MINHUEBACKGROUND_NUMBER_HUERANGEfromHsvFBACKGROUND_NUMBER_SATURATIONBACKGROUND_NUMBER_VALUEBACKGROUND_NUMBER_ALPHA)
rc   rB   r   r9   color
color_funcr   r   vmax_vmin_diffhues
             r:   get_bgcolorzDataFrameModel.get_bgcolor%  sO   ##uyy{F3F#+rwwu~56Ee$ 78< 9  568 5 %!56 
"
)9)96BJD$
$;!#%(N%)D[N ,.H:e,,/.1?/A ACC/CQwOOC)E$;$;=E   s   'E 	E E c                 P   	 | j                   j                  ||f   }|S # t        j                  j                  j
                  $ rA | j                   j                  dd|f   j                  t              j                  |   }Y |S  | j                   j                  ||f   }Y |S xY w)z"Return the value of the DataFrame.N)	rN   iatr   _libstslibOutOfBoundsDatetimeilocastypestr)rc   r   r   r9   s       r:   r   zDataFrameModel.get_valueP  s    	.GGKKV,E
 	 xx~~11 	AGGLLF+2237;;C@E 	.GGLLf-Es    A$B%B%c                 <   |j                         s
t               S |t        j                  k(  s|t        j                  k(  r}|j                         }|j                         }| j                  ||      }t        |t              r	 t        | j                  |z        S t        |      r|S 	 t        t        |            S |t        j&                  k(  rt        | j)                  |            S |t        j*                  k(  rt        t-        t.                    S |t        j0                  k(  r|| j"                  v rt3        d      S t               S # t        t        f$ r t        t        |z        cY S w xY w# t         $ r | j"                  j%                  |       Y yw xY w)zCell contentzDisplay Error!)font_size_deltazWIt is not possible to display this value because
an error ocurred while trying to do it)isValidr   r   DisplayRoleEditRoler   r   r   r   r   rQ   
ValueErrorr   DEFAULT_FORMATr%   r&   	ExceptionrS   r   BackgroundColorRoler   FontRoler#   r"   ToolTipRoler!   )rc   rB   roler   r   r9   s         r:   datazDataFrameModel.data\  sb   }}= 2>>!TR[[%8\\^F))+CNN3/E%'?&t||e';<<
 %U+
 -&~e'<== R+++t//677R[[ x8KLMMR^^#/// B C C}1 #I. ? '~'=>>? ! -++2259,-s$   E *E4 !E10E14$FFc                 V    | j                   j                  j                         | _        y)zRecalcuate index information.N)rN   rB   rn   rP   rw   s    r:   recalculate_indexz DataFrameModel.recalculate_index  s    !WW]]113r<   c           	         | j                   K| j                   j                  d      j                  |   r"t        j                  | j
                  dd       y	 |t        j                  k(  }|dk\  r8	 | j                  j                  | j                  j                  |   |dd	       n-| j!                          | j                  j#                  d|       | j)                          y# t        $ r9 | j                  j                  | j                  j                  |   |dd
       Y Rt        $ r7}t        j                  | j
                  ddt        |      z         Y d}~d}~wt        $ r7}t        j                  | j
                  ddt        |      z         Y d}~d}~ww xY w# t$        $ r7}t        j                  | j
                  ddt'        |      z         Y d}~yd}~ww xY w)zOverriding sort methodNr   )rk   ErrorzDTypeError error: no ordering relation is defined for complex numbersFT	mergesort)by	ascendinginplacekind)ri   r   r   r   zValueError: %szSystemError: %s)r   r   zTypeError error: %s)rR   anyr   r   criticalrM   r   AscendingOrderrN   sort_valuesri   AttributeErrorsortr   r&   SystemErrorr   
sort_indexr   r   r   )rc   r   orderr   es        r:   r   zDataFrameModel.sort  s   *""&&A&.33F;$$T[['&OP 	!2!22I{PGG''477??6+B2;T-8 ( :( &&(""49"E 	

5 & 3GGLL)@+4d&1 ! 3 " O  ((g)9N1<M)MO O" P  ((g):^A=N)NP PP  	  g!6Q!?A	s`   F( 26C' (.F( '?F%&F( (F%0-E"F( "F%.-F F(  F%%F( (	G(1-G##G(c                     t        j                  t        t        j                  | |      t         j
                  z              S )z	Set flags)r   	ItemFlagsintr   flagsItemIsEditablerc   rB   s     r:   r   zDataFrameModel.flags  s8    ||C 3 9 9$ F " 1 1!2 3 4 	4r<   c           
         |j                         }|j                         }|| j                  v ry|g	 | j                  |t        j
                        }t        |t              }|t        u rt        |      } ||      | j                  j                  ||f<   nt        |t              }| j                  ||      }t        |t        t        j                   f      rt        |      }t        t        j                   ft"        z   }	t        ||	      st%        |      r,	 |j'                  |      | j                  j                  ||f<   nDt+        j,                  | j.                  ddj5                  t1        |      j2                               y| j7                          | j8                  j;                  ||       y# t        $ r$  |d      | j                  j                  ||f<   Y Yw xY w# t        t(        f$ rV}
t+        j,                  | j.                  dt        t1        |
      j2                        dz   t        |
      z          Y d}
~
yd}
~
ww xY w)	zCell content changeFN)r   r0   r   z: z&Editing dtype {0!s} not yet supported.T)r   r   rS   r   r   r   r   r   boolr;   rN   r   r   r   r   npbool_r   r$   	__class__OverflowErrorr   r   rM   type__name__re   rY   dataChangedemit)rc   rB   r9   r   change_typer   r   valcurrent_valuesupported_typesr   s              r:   setDatazDataFrameModel.setData  s   iikD+++"=		%bnn	=#E3/$&*3/C,7,<S&[)  s+C NN37M-$)9:&s+#RXX.1BBO=/:"=1!0=0G0G0LDGGLLf- $$T[['%M&,fT--@-I-I&JL !eU+/  =,7,<S&[)= #M2 !((g),T!W-=-=)>)EA)NP !s+   A%F7 *G' 7*G$#G$'I6AIIc                     | j                   S )zReturn data)rN   rw   s    r:   get_datazDataFrameModel.get_data  s    wwr<   c                     	 | j                   | j                  k  r| j                   S | j                  S # t        $ r Y yw xY w)zDataFrame row numberr   )rU   r^   r   r   s     r:   rowCountzDataFrameModel.rowCount  sA    
	$"2"22&''' 		s   $3 3 	??c                    |r| j                   | j                  kD  r| j                   | j                  z
  }t        |t              }| j	                  t               | j                  | j                  |z   dz
         | xj                  |z  c_        | j                          |r| j                  | j                  kD  r| j                  | j                  z
  }t        |t              }| j                  t               | j                  | j                  |z   dz
         | xj                  |z  c_        | j                          yyy)zGet more columns and/or rows.rK   N)rU   r^   r@   r]   beginInsertRowsr
   endInsertRowsrV   r`   r_   beginInsertColumnsendInsertColumnsrc   rowsri   reminderitems_to_fetchs        r:   
fetch_morezDataFrameModel.fetch_more  s   DOOd&6&66)9)99H <8N  0@0@!%!1!1N!BQ!FH. t)9)99)9)99H <8N##KM43C3C$($4$4~$E$IK.!!# :7r<   c                     	 t        | j                  j                        dk(  ry| j                  | j                  k  r| j                  S | j                  S # t
        $ r Y yw xY w)DataFrame column numberrK      r   )rs   rN   rT   rV   r`   r   r   s     r:   columnCountzDataFrameModel.columnCount  sY    
		477==!Q&D$4$44&''' 		s   "A $A 
A 	A"!A"c                 D    | j                          | j                          y r   )beginResetModelendResetModelrw   s    r:   r   zDataFrameModel.reset  s    r<   )r   FF)%r   
__module____qualname____doc__r   rL   rl   ro   ru   propertyrT   ry   r{   r   r   rY   r   r   r   r\   r   r   r   r   r   r   r   r   r   r   r   r   r
   r   r  r  r   r   r<   r:   rI   rI   o   s     *8 &3P?&B   < < " "'$-L


)V
  "~~ #J4 "$!2!2 )V4
 *,$ %N )] $" !,  r<   rI   c                       e Zd ZdZ e       Z e       Z e       ZdZd Z	d Z
d ZddZd Zd Zd	 Zd
 Z e       d        Zy)DataFrameViewz
    Data Frame view class.

    Signals
    -------
    sig_sort_by_column(): Raised after more columns are fetched.
    sig_fetch_more_rows(): Raised after more rows are fetched.
    variable_explorerc                    t        j                  | |       | j                  |       | j                  |       | j	                  |       | j                  t         j                         | j                  t         j                         dg| _        || _	        | j                  j                  j                  | j                         | j                         | _        | j                  | j                   d|        | j#                         j$                  j                  | j&                         | j)                         j$                  j                  | j*                         y)zConstructor.Ncopy)r   rL   setModelsetHorizontalScrollBarsetVerticalScrollBarsetHorizontalScrollModeScrollPerPixelsetVerticalScrollModesort_oldheader_classsectionClickedconnectsortByColumn
setup_menumenuconfig_shortcutr  horizontalScrollBarvalueChanged_load_more_columnsverticalScrollBar_load_more_rows)rc   rf   modelr   hscrollvscrolls         r:   rL   zDataFrameView.__init__"  s    D&)e##G,!!'*$$Z%>%>?"":#<#<="((001B1BCOO%	TYY5  "//77##	% --55d6J6JKr<   c                 J    	 | j                  |d       y# t        $ r Y yw xY w)zLoad more columns to display.Tri   Nload_more_data	NameErrorrc   r9   s     r:   r$  z DataFrameView._load_more_columns4  s,    	t4 		    	""c                 J    	 | j                  |d       y# t        $ r Y yw xY w)zLoad more rows to display.Tr   Nr,  r/  s     r:   r&  zDataFrameView._load_more_rows=  s,    	D1 		r0  c                    	 |r[|| j                         j                         k(  r:| j                         j                  |       | j                  j                          |r]|| j                         j                         k(  r;| j                         j                  |       | j                  j                          yyy# t        $ r Y yw xY w)z&Load more rows and columns to display.r2  r+  N)	r%  maximumr'  r  sig_fetch_more_rowsr   r"  sig_fetch_more_columnsr.  )rc   r9   r   ri   s       r:   r-  zDataFrameView.load_more_dataF  s    	!7!7!9!A!A!CC

''T'2((--/5D$<$<$>$F$F$HH

'''8++002 Iw  	 	s   B:B? ?	C
Cc                    | j                   dgk(  r| j                  j                  d       | j                  j                         }| j	                         j                  ||      skt        | j                         dk7  r| j                  j                  d       y| j                  j                  | j                   d   | j                   d          y|| j                  j                         g| _         | j                  j                          y)zImplement a column sort.NTr  Fr   rK   )
r  r  setSortIndicatorShownsortIndicatorOrderr'  r   rs   setSortIndicatorsig_sort_by_columnr   rc   rB   
sort_orders      r:   r  zDataFrameView.sortByColumnU  s    ==TF"33D9&&99;
zz|  
34==!Q&!!77>  !!224==3C37==3CE 1 1 D D FG$$&r<   c                 v    | j                   j                  |j                                |j                          y)zReimplement Qt method.N)r   popup	globalPosaccept)rc   events     r:   contextMenuEventzDataFrameView.contextMenuEventd  s"    		)*r<   c                     t         t        d      t        d      t        j                  d       j
                  t        j                        }t        d      t        ft        d      t        ft        d      t        ft        d      t        ft        d      t        ff}|g}|D ],  \  } fd	}|t         ||t        j                  
      gz  }. t               }t        ||       |S )zSetup context menu.Copyeditcopy)shortcuticon	triggeredcontextzTo boolz
To complexzTo intzTo floatzTo strc                  (    j                          y r   r   )funcrc   s   r:   slotz&DataFrameView.setup_menu.<locals>.slotu  s      &r<   )rI  rJ  )r)   r!   r*   r'   rH  r  r   WidgetShortcutr   complexr   r   r&   r   r(   )rc   copy_action	functionstypes_in_menur   rN  r   rM  s   `      @r:   r  zDataFrameView.setup_menui  s    #D!F)-7-?),*)=.2ii,.,=,=	?
 	lD)AlOW+Ek3'!J-)?k>24	 %# 	HJD$'mD$6:464E4EG H HM	H T{D-(r<   c                     | j                         }| j                         }|D cg c]  }|j                  |d|       c} yc c}w )z'A function that changes types of cells.r6   rL  N)r'  selectedIndexesr   )rc   rM  r'  
index_listis        r:   r   zDataFrameView.change_type~  s;    

))+
9CDAq"$	/DDs   Ac                 B   | j                         syt        | j                               \  }}}}dx}}| j                         j                  }|j                  t        ||dz         t        ||dz         f   }t        j                         }		 |j                  |	d||       |	j                         }
|	j                          t        j                          }|j#                  |
       y# t        $ r, t        j                  | t        d      t        d             Y zw xY w)zCopy text to clipboardNTrK   	)seprB   r   r   zText can't be copied.)rU  r,   r'  rN   r   sliceioStringIOto_csvUnicodeEncodeErrorr   r   r!   getvaluecloser   	clipboardsetText)rc   row_minrow_maxcol_mincol_maxrB   r   rN   objoutputcontentsrb  s               r:   r  zDataFrameView.copy  s    ##%)$*>*>*@A	'	' ZZ\__ggeGWq[1GWq[12 3	,JJv4uVJD ??$ **,	(# " 	,   '
)*,	,s   C) )2DDNr
  )r   r  r  r  r   r;  r6  r5  CONF_SECTIONrL   r$  r&  r-  r  rC  r  r   r   r  r   r<   r:   r  r    sf      #X (&LL$'
*E 
V$ $r<   r  c                   t     e Zd ZdZdZ fdZd
dZ e       fdZddZ	e
j                  fdZd Zd	 Z xZS )DataFrameHeaderModelz
    This class is the model for the header or index of the DataFrameEditor.

    Taken from gtabview project (Header4ExtModel).
    For more information please see:
    https://github.com/wavexx/gtabview/blob/master/gtabview/viewer.py
    c                 r   t         t        |           || _        || _        || _        | j                  j                  d   | _        | j                  j                  d   | _        | j                  | j                  z  }|t        kD  rt        | _        t        | _        n`| j                  t        kD  rt        | _        n| j                  | _        | j                  t        kD  rt        | _        n| j                  | _        | j                  dk(  rV| j                  j                  d   | _        | j                  j                   d   | j                  j                  d   f| _        y| j                  j                  d   | _        | j                  j                  d   | j                  j                   d   f| _        y)a  
        Header constructor.

        The 'model' is the QAbstractTableModel of the dataframe, the 'axis' is
        to acknowledge if is for the header (horizontal - 0) or for the
        index (vertical - 1) and the palette is the set of colors to use.
        r   rK   N)superrm  rL   r'  rk   _paletterT   rU   rV   rX   r]   r^   r_   r`   rb   ra   ry   _shape)rc   r'  rk   paletterg   r   s        r:   rL   zDataFrameHeaderModel.__init__  sK    	"D24
	****1-****1-0 *+D+D+#/ #'?? ,#/ #'?? 99>"jj..q1DO::2215tzz7G7G7JKDK"jj..q1DO::++A.

0G0G0JKDKr<   c                     | j                   dk(  rt        d| j                  d         S | j                  | j                  k  r| j                  S | j                  S )z!Get number of rows in the header.r   rK   )rk   r?   rr  rU   r^   r   s     r:   r   zDataFrameHeaderModel.rowCount  sJ    99>q$++a.))$"2"22&'''r<   c                     | j                   dk(  r1| j                  | j                  k  r| j                  S | j                  S t        d| j                  d         S )r  r   rK   )rk   rV   r`   r?   rr  r   s     r:   r  z DataFrameHeaderModel.columnCount  sJ    99>$"2"22&'''q$++a.))r<   c                    | j                   dk(  r| j                  | j                  kD  r| j                  | j                  z
  }t        |t              }| j                  t               | j                  | j                  |z   dz
         | xj                  |z  c_        | j                          | j                   dk(  r| j                  | j                  kD  r| j                  | j                  z
  }t        |t              }| j                  t               | j                  | j                  |z   dz
         | xj                  |z  c_	        | j                          yyy)z)Get more columns or rows (based on axis).rK   r   N)rk   rU   r^   r@   r]   r   r
   r   rV   r`   r_   r   r   r   s        r:   r  zDataFrameHeaderModel.fetch_more  s   IINt1A1AA)9)99H <8N  0@0@!%!1!1N!BQ!FH. 99>doo0@0@@)9)99H <8N##KM43C3C$($4$4~$E$IK.!!# A>r<   c                 x    |t         j                  k(  }| j                  j                  | j                  |       y)zOverriding sort method.)r   T)r   r   r'  r   COLUMN_INDEX)rc   r   r   r   s       r:   r   zDataFrameHeaderModel.sort  s/    R...	

));r<   c                 >   |t         j                  k(  rM|t         j                  k(  rt         j                  S t	        t         j
                  t         j                  z        S |t         j                  k7  r|t         j                  k7  ry| j                  dk(  r| j                  d   dk  ry|t         j                  k(  rdnd}| j                  j                  |   dkD  r|}|S | j                  j                  | j                  |      }t        |      st        |      }|S )z)Get the information to put in the header.NrK   r   )r   TextAlignmentRole
HorizontalAlignCenterr   
AlignRightAlignVCenterr   r   rk   rr  r'  ry   r   r%   r&   )rc   sectionorientationr   orient_axisr   s         r:   
headerDatazDataFrameHeaderModel.headerData  s    2'''bmm+~~%2==2??:;;2>>!dbnn&<99>dkk!n1&"--7aQ::"";/!3F  ZZ&&tyy':F 'v.'/r<   c                 2   |j                         r@|j                         | j                  d   k\  s |j                         | j                  d   k\  ry| j                  dk(  r |j                         |j                         fn|j                         |j                         f\  }}|t
        j                  k7  ry| j                  dk(  r| j                  d   dk  ry| j                  j                  | j                  ||      }t        |      st        |      }|S )z^
        Get the data for the header.

        This is used when a header has levels.
        r   rK   N)r   r   rr  r   rk   r   r   r'  r   r%   r&   )rc   rB   r   r   r   r   s         r:   r   zDataFrameHeaderModel.data  s     }}99;$++a.(<<>T[[^+59YY!^UYY[%,,.1,,.%))+6 	S2>>!99>dkk!n1""499c37 #6*#F+Fr<   r   r
  )r   r  r  r  rx  rL   r   r
   r  r  r   r   r   r  r   __classcell__r   s   @r:   rm  rm    sF     L$LL( !, *$" "$!2!2 4r<   rm  c                   >     e Zd ZdZ fdZddZddZd Zd Z xZ	S )DataFrameLevelModela  
    Data Frame level class.

    This class is used to represent index levels in the DataFrameEditor. When
    using MultiIndex, this model creates labels for the index/header as Index i
    for each section in the index/header

    Based on the gtabview project (Level4ExtModel).
    For more information please see:
    https://github.com/wavexx/gtabview/blob/master/gtabview/viewer.py
    c                 L   t         t        |           || _        |j	                         j                         | _        | j                  j                         dkD  r|j                         | _	        n|j                         | _	        || _        |j                  d       || _        y )N   T)rp  r  rL   r'  darkr   _background	lightnesstext_foregroundhighlightedTextrq  setBold_font)rc   r'  rs  fontr   s       r:   rL   zDataFrameLevelModel.__init__A  s    !413
"<<>//1%%'#-&||~D&668DT
r<   c                 H    t        d| j                  j                  d         S )z5Get number of rows (number of levels for the header).rK   r   r?   r'  ry   r   s     r:   r   zDataFrameLevelModel.rowCountM      1djj--a011r<   c                 H    t        d| j                  j                  d         S )z;Get the number of columns (number of levels for the index).rK   r  r   s     r:   r  zDataFrameLevelModel.columnCountQ  r  r<   c                    |t         j                  k(  rM|t         j                  k(  rt         j                  S t	        t         j
                  t         j                  z        S |t         j                  k7  r|t         j                  k7  ry| j                  j                  d   dk  rV|t         j                  k(  rC| j                  j                  d|      r| j                  j                  d|      S t        d      S | j                  j                  d   dk  ry| j                  j                  d   dk  r|t         j                  k(  ryt        d      dz   t        |      z   S )z
        Get the text to put in the header of the levels of the indexes.

        By default it returns 'Index i', where i is the section in the index
        Nr   rK   Indexr1   )r   rz  r{  r|  r   r}  r~  r   r   r'  ry   r   r!   Verticalr&   )rc   r  r  r   s       r:   r  zDataFrameLevelModel.headerDataU  s    2'''bmm+~~%2==2??:;;2>>!dbnn&<::""1%*{bmm/Kzzq)zzq11W:ZZ$$Q'1,ZZ$$Q'1,1KzC."999r<   c                    |j                         sy|t        j                  k(  r| j                  S d}|j	                         | j
                  j                  d   dz
  k(  r4t        | j
                  j                  d|j                                     }n`|j                         | j
                  j                  d   dz
  k(  r3t        | j
                  j                  d|j	                                     }|t        j                  k(  r|r|S |t        j                  k(  r| j                  S |t        j                  k(  r| j                  S |t        j                  k(  r| j                  j!                         S y)z"Get the information of the levels.Nr6   rK   r   )r   r   r   r  r   r'  ry   r   r   r   r   ForegroundRoler  BackgroundRoler  rq  window)rc   rB   r   labels       r:   r   zDataFrameLevelModel.datal  s   }}2;;::<<>TZZ44Q7!;;

599;78EYY[DJJ33A6::

5<<>:;E2>>!eLR&&&###R&&&###R&&&==''))r<   r   )
r   r  r  r  rL   r   r  r  r   r  r  s   @r:   r  r  4  s!    

22:.r<   r  c                   .    e Zd ZdZdZd$ fd	Zd%dZ eee      d        Z	d Z
d Zd Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd&dZd Zd$dZd Zd Zd Zd Zd Zd Zd Z  e       d        Z!d Z"d Z#d  Z$d! Z%d" Z& e       d#        Z' xZ(S )'DataFrameEditorz
    Dialog for displaying and editing DataFrame and related objects.

    Based on the gtabview project (ExtTableView).
    For more information please see:
    https://github.com/wavexx/gtabview/blob/master/gtabview/viewer.py
    r  c                 ~    t         |   |       | j                  t        j                         d| _        d | _        y )NF)rp  rL   setAttributer   WA_DeleteOnClose	is_serieslayout)rc   rf   r   s     r:   rL   zDataFrameEditor.__init__  s4      	"--.r<   c                 X   d| _         d| _        t               | _        | j                  j	                  d       | j                  j                  dddd       | j                  | j                         |r&t        |      d|j                  j                  z  z   }n"t        d      |j                  j                  z  }t        |t        j                        rd| _        |j                         }n/t        |t        j                         rt        j"                  |      }| j%                  |       t'        t(        j*                        | _        t'        t(        j.                        | _        | j3                          | j5                          | j7                          t9        ||       | _        | j:                  j<                  j?                  | j@                         | jC                          | j                  jE                  | j,                  d	dd
d	       | j                  jE                  | j0                  dd	d	d
       tG               | _$        d| _%        | jL                  jO                  |        | jQ                         jS                         }|dz  | _*        |dz  | _+        | j                  | j                         | jY                  t(        jZ                         t]               }|j	                  d       t_        t        d            }|jE                  |       |j`                  j?                  | jb                         t_        t        d            }|jE                  |       |j`                  j?                  | jd                         tg        t        d            }|ji                  | j:                  jj                         |jm                  | j:                  jj                         |jn                  j?                  | jp                         |jE                  |       tg        t        d            | _9        | jr                  ji                  | j:                  jt                         | jr                  jm                  | j                   xr | j:                  jj                         | jr                  jn                  j?                  | j:                  jv                         |jE                  | jr                         |jy                          t_        t        d            | _=        | jz                  j}                  d       | jz                  j`                  j?                  | j~                         |jE                  | jz                         t_        t        d            | _@        | j                  j                  d       | j                  j                  d       | j                  j`                  j?                  | j                         |jE                  | j                         |j                  dddd       | j                  j                  |ddd
d	       | j                  | j:                         | j                          d| j                  d      z   }| j:                  j                  |       y)z
        Setup DataFrameEditor:
        return False if data is not supported, True otherwise.
        Supported types for data are DataFrame, Series and Index.
        FNr      z - %sz	%s editorTrf   r  rK   i,     @      FormatResizezBackground colorzColumn min/maxzSave and CloseClose      %dataframe_format)I_selection_rec_modelr   r  
setSpacingsetContentsMargins	setLayoutr&   r   r   r!   r   r   Seriesr  to_framer  	DataFramesetWindowTitler   r   r{  r(  r  r)  create_table_levelcreate_table_headercreate_table_indexrI   	dataModelr   r  save_and_close_enablecreate_data_table	addWidgetset_autosized_cols_max_autosize_ms	dataTableinstallEventFilterfontMetricsaverageCharWidth	min_trunc	max_widthsetWindowFlagsWindowr   r   clickedchange_formatresize_to_contentsr   
setCheckedr[   
setEnabledstateChangedchange_bgcolor_enablebgcolor_globalrZ   r\   
addStretchbtn_save_and_closesetDisabledrA  	btn_closesetAutoDefault
setDefaultreject	addLayoutr  resizeColumnsToContentsget_confr   )	rc   r   title	avg_width
btn_layout
btn_format
btn_resizer   re   s	            r:   setup_and_checkzDataFrameEditor.setup_and_check  s    $!mq!&&r2r15t{{#"5)Gdnn6M6M,MMEkNT^^%<%<<EdBII&!DN==?Dbhh'<<%DE"!"--0!"++. 	! 	  " 	! (T:""**4+E+EF dllAq!Q7dllAq!Q7  #u !$))$/$$&779	"R"Rt{{#BII& ]
a  8-
Z(""4#5#56 8-
Z(""4#:#:;A0124>>99:4>>99:$$T%?%?@W%'*:(;<&&t~~'G'GH&&4>>'9 (F'+~~'E'E	G((001I1IJT001"-a0@.A"B++D1''//<T445$QwZ0%%d+!!$'&&t{{3T^^,%%aQ3j!Q15dnn%$$&t}}%788!!&)r<   c                     | j                   j                  d       | j                   j                  d       | j                   j                  d       y)zAHandle the data change event to enable the save and close button.TN)r  r  r  r  )rc   top_leftbottom_rights      r:   r  z%DataFrameEditor.save_and_close_enable  s@     	**40..t4**40r<   c                    t               | _        | j                  j                  t        j                         | j                  j                  t        j                         | j                  j                  t        j                         | j                  j                  t        j                         | j                  j                         j                  j                  | j                         | j                  j!                         j                  j                  | j"                         | j                  j%                  t'                      | j(                  j+                  | j                  dd       | j                  j-                  dddd       | j                  j                         j.                  j                  | j0                         y)z5Create the QTableView that will hold the level model.r   N)r   table_levelsetEditTriggersr   NoEditTriggerssetHorizontalScrollBarPolicyr   ScrollBarAlwaysOffsetVerticalScrollBarPolicysetFrameStyler   PlainhorizontalHeadersectionResizedr  _index_resizedverticalHeader_header_resizedsetItemDelegater   r  r  r  r  sortByIndexrw   s    r:   r  z"DataFrameEditor.create_table_level	  sE   %<(()D)DE55b6K6KL33B4I4IJ&&v||4))+::BB8<8K8K	M'')88@@8<8L8L	N((9d..15++Aq!Q7))+::BB<@<L<L	Nr<   c                 d   t               | _        | j                  j                         j                          | j                  j	                  t
        j                         | j                  j                  t        j                         | j                  j                  t        j                         | j                  j                  t         j                         | j                  j                  | j                         | j                  j                  t         j"                         | j                  j%                         j&                  j)                  | j*                         | j                  j-                  t/                      | j0                  j3                  | j                  dd       y)z6Create the QTableView that will hold the header model.r   rK   N)r   table_headerr  hider  r   r  r  r   r  r  r  r  r  r(  r  r   r  r  r  r  _column_resizedr  r   r  r  rw   s    r:   r  z#DataFrameEditor.create_table_header  s   &L((*//1)),*E*EF66r7L7LM44R5J5JK11*2K2KL00>''5**,;;CC8<8L8L	N))-/:d//A6r<   c                    t               | _        | j                  j                         j                          | j                  j	                  t
        j                         | j                  j                  t        j                         | j                  j                  t        j                         | j                  j                  t         j                         | j                  j                  | j                         | j                  j                  t         j"                         | j                  j%                         j&                  j)                  | j*                         | j                  j-                  t/                      | j0                  j3                  | j                  dd       | j                  j5                  dddd       y)z5Create the QTableView that will hold the index model.rK   r   N)r   table_indexr  r  r  r   r  r  r   r  r  r  r  r  r)  r  r   r  r  r  r  _row_resizedr  r   r  r  r  rw   s    r:   r  z"DataFrameEditor.create_table_index)  s8   %<))+002(()D)DE55b6K6KL33B4I4IJ..z/H/HI--dll;&&v||4'')88@@<@<M<M	O((9d..15++Aq!Q7r<   c                    t        | | j                  | j                  j                         | j                  | j
                        | _        | j                  j                         j                          | j                  j                         j                          | j                  j                  t        j                         | j                  j                  t        j                         | j                  j                  t        j                         | j                  j!                  t        j                         | j                  j#                  t$        j&                         | j                  j)                  t+                      | j,                  j/                  | j                  dd       | j1                  | j                         | j                  j2                  j5                  | j6                         | j                  j8                  j5                  | j:                         | j                  j<                  j5                  | j>                         y)z4Create the QTableView that will hold the data model.rK   N) r  r  r  r  r(  r)  r  r  r  r  r   r  r  r  r   r  r  r  r   r  r  r   r  r  setFocusProxyr;  r  _sort_updater6  _fetch_more_columnsr5  _fetch_more_rowsrw   s    r:   r  z!DataFrameEditor.create_data_table9  sz   &tT^^'+'8'8'I'I'K'+||T\\C 	%%',,.'')..033B4I4IJ11"2G2GH..z/H/HI,,Z-F-FG$$V\\2&&}7dnna34>>*))11$2C2CD--55d6N6NO**2243H3HIr<   c                    | j                   j                         j                  d       | j                   j                         j                         }| j                  j                         j                  ||       | j                          y)zImplement a Index sort.TN)r  r  r8  r9  r  r'  r   r  r<  s      r:   r  zDataFrameEditor.sortByIndexL  sg    ))+AA$G%%668KKM
 %%eZ8r<   c                     | j                   S )zGet the model of the dataframe.)r  rw   s    r:   r'  zDataFrameEditor.modelS  s    {{r<   c                 \    | j                   j                  ||       | j                          y)zUpdate the column width.N)r  setColumnWidth_update_layoutrc   r   	old_width	new_widths       r:   r  zDataFrameEditor._column_resizedW  s"    %%c95r<   c                 \    | j                   j                  ||       | j                          y)zUpdate the row height.N)r  setRowHeightr	  rc   r   
old_height
new_heights       r:   r  zDataFrameEditor._row_resized\  s"    ##C4r<   c                 \    | j                   j                  ||       | j                          y)z>Resize the corresponding column of the index section selected.N)r  r  r	  r
  s       r:   r  zDataFrameEditor._index_resizeda  s$    ''Y7r<   c                 \    | j                   j                  ||       | j                          y)z<Resize the corresponding row of the header section selected.N)r  r  r	  r  s       r:   r  zDataFrameEditor._header_resizedf  s$    &&sJ7r<   c                    t        | j                  j                         j                         j	                         | j
                  j                         j                         j	                               }| j                  j                         j                  |       | j
                  j                         j                  |       | j                  j                  d   dz
  }|dk  r)| j                  j                         j                         }n| j                  j                  |      | j                  j                  |      z   | j                  j                         j                         z   }|dk(  r8| j                  j                  dd       | j                  j                  dd       | j                  j                  |       | j                  j                  |       | j                  j                  d   dz
  }|dk  r)| j                  j                         j	                         }n`| j                  j!                  |      | j                  j#                  |      z   | j                  j                         j	                         z   }| j
                  j                  |       | j                  j                  |       | j%                          y)z:Set the width and height of the QTableViews and hide rows.r   rK   TN)r?   r  r  sizeHintwidthr  setFixedWidthr  ry   r  heightrowViewportPosition	rowHeightsetRowHiddenr  setFixedHeightcolumnViewportPositioncolumnWidth_resizeVisibleColumnsToContents)rc   h_widthlast_row
hdr_heightlast_col	idx_widths         r:   r	  zDataFrameEditor._update_layoutk  s;   d&&557@@BHHJ&&557@@BHHJL'')77@'')77@;;++A.2a<))::<CCEJ))==hG))33H=>))::<CCEFJ
 1}  --a6!!..q$7((4''
3;;++A.2a<((779??AI((??I((44X>?((779??ABI 	&&y1&&y1,,.r<   c                 N    |j                         }|j                  |       |r~yy)z!Set the model in the given table.N)selectionModelr  )rc   tabler'  old_sel_models       r:   _reset_modelzDataFrameEditor._reset_model  s'    ,,.u r<   c                     || _         y)z4Set maximum time to calculate size hint for columns.N)r  )rc   limit_mss     r:   setAutosizeLimitTimez$DataFrameEditor.setAutosizeLimitTime  s
     (r<   c           	         || _         | j                  j                         }|j                  j	                  | j
                         | j                  | j                  t        || j                         | j                                      | j                  | j                  t        |d| j                                      | j                  | j                  t        |d| j                                      |r| j                          yy)z9Set the model for the data, header/index and level views.r   rK   N)r  r  r&  currentColumnChangedr  _resizeCurrentColumnToContentsr)  r  r  rs  r  r  rm  r  r	  )rc   r'  relayout	sel_models       r:   r  zDataFrameEditor.setModel  s    NN113	&&..33	5
 	$**,?@D@D		-M 	N 	$++-A<A<=<@LLN.L 	M 	$**,@<A<=<@LLN-L 	M ! r<   c                     | j                   j                         j                  | j                   j                         j	                  ||      t
        j                         y)zSet current selection.N)r  r&  setCurrentIndexr'  rB   r	   ClearAndSelect)rc   yrC   s      r:   r3  zDataFrameEditor.setCurrentIndex  sC    %%'77NN  "((A...	0r<   c                    |j                         j                         }t               }|rdn|}| j                  }t	        |      D ]|  }|j                  |j                         j                  ||            }	t        ||	j                               }||kD  sRt               }
|
|z
  dz  }||k\  r |S t        ||z  |z        }~ |S )z0Get the size hint for a given column in a table.r  i  )
r'  r   r   r  rangesizeHintForIndexrB   r?   r  r   )rc   r'  r   r+  max_rowlm_startlm_rowr  r   vlm_now
lm_elapseds               r:   _sizeHintForColumnz"DataFrameEditor._sizeHintForColumn  s    ++-((*>WNN	> 	<C&&u{{}':':3'DEAIqwwy1IV|%$x/47
) cJ.(:;	< r<   c                 z   | j                  |||      }| j                  |||      }||kD  rt        | j                  |      }ng||dz  kD  r5t        t        || j                        t        | j                  |            }n*t        t        | j                  |      | j                        }|j                  ||       y)z Resize a column by its contents.r  N)r?  r@   r  r?   r  r  )rc   r   r   r   r+  	hdr_width
data_widthr  s           r:   _resizeColumnToContentsz'DataFrameEditor._resizeColumnToContents  s    ++FCB	,,T3A
	!
3Ea'It~~6DNN"9$ %E DNNI6GEc5)r<   c                     |j                         j                         }|d}n|t        d|      z  }t        |      D ]  }| j	                  ||||        y)z(Resize all the colummns to its contents.NrK   )r'  r  r?   r7  rC  )rc   r   r   r+  rE   
max_col_msr   s          r:   _resizeColumnsToContentsz(DataFrameEditor._resizeColumnsToContents  sZ    **,**,J!C7O3J> 	HC((sJG	Hr<   c                     || j                   k(  r1|j                         t        j                  k(  r| j	                          y)z+Override eventFilter to catch resize event.F)r  r   r   r  r  )rc   rh  rB  s      r:   eventFilterzDataFrameEditor.eventFilter  s.    $.. UZZ\V]]%B002r<   c                    | j                   j                         j                         j                         }| j                   j	                  |      x}}| j
                  j                  d   }| j                   j	                  | j                   j                         j                         j                               }|dk(  r|n|dz   }| j                  d}n| j                  t        d||z
        z  }||k  rd}|| j                  vrE| j                  j                  |       d}| j                  | j                  | j                   ||       |dz  }|r{| j                   j                         j                         j                         }| j                   j	                  |      }|dk(  r|n|dz   }|| j                  t        d||z
        z  }||k  ryy)z(Resize the columns that are in the view.rK   rn  NFT)r  recttopLeftrC   columnAtr  rT   bottomRightr  r?   r  addrC  r  )rc   index_columnstartr   r  endrE  resizeds           r:   r  z/DataFrameEditor._resizeVisibleColumnsToContents  s   ~~**,44688:nn--l;;!!!$nn%%dnn&9&9&;&G&G&I&K&K&MNbyecAg  (J..Qe1DDJCiG$...$$((-,,T->->-0*>1HC#~~224@@BDDFnn--l;"byecAg)!%!6!6Qe9L!LJ Cir<   c                     |j                         | j                  vr,| j                          | j                  j	                  |       yy)z*Resize the current column to its contents.N)r   r  r  r  scrollTo)rc   	new_index	old_indexs      r:   r/  z.DataFrameEditor._resizeCurrentColumnToContents  s<    T%9%99002NN##I. :r<   c                     t               | _        | j                  | j                  | j                  | j
                         | j                          y)z#Resize the columns to its contents.N)r  r  rF  r  r  r  r	  rw   s    r:   r  z'DataFrameEditor.resizeColumnsToContents  s@    "u%%d&6&6&*&6&68M8M	Or<   c                     | j                   j                  |       | j                  j                  | j                   xr |dkD         y)zV
        This is implementet so column min/max is only active when bgcolor is
        r   N)r  r   r  r  r  r   s     r:   r  z%DataFrameEditor.change_bgcolor_enable  s:     	u%&&4>>'9'GeaiHr<   c                 R   t        j                  | t        d      t        d      t        j                  | j
                  j                               \  }}|rt        |      }	 |dz   |j                  d      s;t        d      j                  |      }t        j                  | t        d      |       y| j
                  j                  |       |d	d }| j                  d
|       yy#  t        d      j                  |      }t        j                  | t        d      |       Y yxY w)zD
        Ask user for display format for floats and use it.
        r  zFloat formattingg?zFormat ({}) is incorrectr   Nr  z!Format ({}) should start with '%'rK   r  )r   getTextr!   r   Normalr  r   r   re   r   r   
startswithr   set_conf)rc   re   validmsgs       r:   r  zDataFrameEditor.change_format  s   
 %,,T1X;-./A-B-6-=-=-1^^-F-F-HJ [F
 $$S);<CCFK$$T1W:s;NN%%f-ABZFMM,f5 23::6B$$T1W:s;s   #C( (<D&c                 x    | j                   j                         }| j                  r|j                  dddf   S |S )z1Return modified Dataframe -- this is *not* a copyNr   )r  r   r  r   )rc   rN   s     r:   r   zDataFrameEditor.get_value.  s4     ^^$$&>>771a4= Ir<   c                    | j                   j                          | j                   j                         j                         }t	        d|      D ]}  }||k  ru| j
                  j                  |      }| j                   j                  |      }||kD  r| j                   j                  ||       `| j
                  j                  ||       } y y)z&Update the column width of the header.r   N)r  r  r'  r  r7  r  r  r  )rc   column_countrB   column_widthheader_widths        r:   _update_header_sizez#DataFrameEditor._update_header_size8  s    113((..0<<>1l+ 		E|##~~99%@#00<<UC,.%%44ULINN11%F		r<   c                     | j                   j                          | j                  | j                  j	                                y)zx
        Update the model for all the QTableView objects.

        Uses the model of the dataTable as the base.
        N)r  r   r  r  r'  rw   s    r:   r  zDataFrameEditor._sort_updateG  s-     	((*dnn**,-r<   c                 T    | j                   j                         j                          y)z)Fetch more data for the header (columns).N)r  r'  r  rw   s    r:   r  z#DataFrameEditor._fetch_more_columnsQ  s    !,,.r<   c                 T    | j                   j                         j                          y)z%Fetch more data for the index (rows).N)r  r'  r  rw   s    r:   r  z DataFrameEditor._fetch_more_rowsU  s     ++-r<   c                 D   t        j                  t        t        j                               | j
                  j                          | j                  j                  d       | j
                  j                          | j                          t        j                          y )NTr+  )r   setOverrideCursorr   r   
WaitCursorr  r  r  r  re  restoreOverrideCursorrw   s    r:   r  z"DataFrameEditor.resize_to_contentsY  sf    &&wr}}'=>..0!!$!/..0  "**,r<   r   )r6   )T))r   r  r  r  rk  rL   r  r   r
   r  r  r  r  r  r  r'  r  r  r  r  r	  r)  r,  r  r3  r?  rC  rF  rH  r  r/  r  r  r  r   re  r  r  r  r  r  r  s   @r:   r  r    s     'L	iV 
+{#1 $1N"78 J&



/B)"20"*HM6/I 
V6 62./. 
V- -r<   r  c                     t        |      }|j                  | |      r |j                          |j                         S ddl}|j                  d       y)zTest subroutiner  )r  r   NrK   )r  r  exec_r   sysexit)r   r  rf   dlgro  s        r:   	test_editrr  f  sB    

(C
4u-		}}r<   c                     ddl m}  t        t        j                        t        d      k\  r	ddlm}m} nddlm}m} t               }t        j                  ddgddgd	d
gddgddgt        j                  j                  dd      dgddgddggdd| | | dddg| dg      }t        |      } |||       t        j                  ddg| dgd      }t        |j                   d         } |||       t        j                  t        j                  j                  dd            }t        |      } |||       t        j                  t        j"                  d      d      }t        |      } |||       y )!zDataFrame editor testr   )nanz2.0.0)assert_frame_equalassert_series_equalTr   y      ?      ?rP  teststringg(\?r   rK   r      zUnkown typezLarge valued   u   áéíunicodeabczTest global maxdType)rB   ri   )rB   r   i 
   )r   N)r   rt  r   r   __version__pandas.testingru  rv  pandas.util.testingr+   r  r   randomrandrr  r  r   arange)rt  ru  rv  appdf1outresultseriess           r:   rw  rw  r  sN   R^^g.JJO
.C
,,6N9X7OJYY^^Aq!=1C y!		
 Cc3->DfC C.CsC YYf~c6]EF
CHHQK
 C$
,,ryy~~fb1
2C
C.CsC YYryy}1-F
F
C$r<   __main__)r6   N)cr  r\  timer   packaging.versionr   qtpy.compatr   r   qtpy.QtCorer   r   r	   r
   r   r   r   
qtpy.QtGuir   r   qtpy.QtWidgetsr   r   r   r   r   r   r   r   r   r   r   r   r   r    spyder_kernels.utils.lazymodulesr   r   r   r   spyder.api.config.mixinsr    spyder.config.baser!   spyder.config.fontsr"   spyder.config.guir#   spyder.py3compatr$   r%   r&   spyder.utils.icon_managerr'   spyder.utils.qthelpersr(   r)   r*   r+   3spyder.plugins.variableexplorer.widgets.arrayeditorr,   2spyder.plugins.variableexplorer.widgets.basedialogr-   r   r   int64int32r   rP  	complex64
complex128r   r8   r   rX   ra   rb   r]   r_   r   r   r   r   r   	lightGrayr   BACKGROUND_INDEX_ALPHAr   r   r;   rG   rI   r  rm  r  r  rr  rw  r   r   r<   r:   <module>r     s  , 
  $ 2
 
 
 '    G A   3 &. . )> > L I C2884 r}}= 3  

   ! "   \\    &a( aHK$J ; K$\P. PfK- K\^-j"= ^-H	&%R zF r<   