
    %
iH                        d dl Z d dlZd dlmZ d dlmZmZmZ  ej        dd ddd            ej        d	d d
dd            ej	        dd dd dg            G d d          Z
 G d d          Zd Zd Zedk    rFd dlZej        j                            e           de j        v r ee           dS  ee           dS dS )    N)	universal)DispatchWithEvents	constantsgencachez&{00020813-0000-0000-C000-000000000046}      T)
bForDemandz&{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}   z&{AC0714F2-3D04-11D1-AE7D-00A0C90F26F4}_IDTExtensibility2c                       e Zd Zd ZdS )ButtonEventc                 N    dd l }dd l}|                    dd|j                   |S )Nr   zHello from PythonzPython Test)win32conwin32ui
MessageBoxMB_OKCANCEL)selfbuttoncancelr   r   s        C:\Users\Dell Inspiron 16\Desktop\tws\AgrotaPowerBi\back-agrota-powerbi\mcp-client-agrota\venv\Lib\site-packages\win32com/demos/excelAddin.pyOnClickzButtonEvent.OnClickF   s5    .x?STTT    N)__name__
__module____qualname__r    r   r   r   r   E   s#            r   r   c                   V    e Zd ZdgZg Zej        ZdZdZ	dZ
d Zd Zd Zd Zd	 Zd
 ZdS )
ExcelAddinr   z&{C5482ECA-F559-45A0-B078-B2036E6F011A}zPython.Test.ExcelAddinz)win32com.server.policy.EventHandlerPolicyc                     d | _         d S )N)
appHostApp)r   s    r   __init__zExcelAddin.__init__V   s    r   c                    t          d||||           	 || _        | j        j                            dt          j        t          j        d          }|j                            t          j        d          }t          |t                    x}| _        t          j        |_        d|_        d|_        d|_        d	|_        d|_        d S # t&          j        $ r}|j        \  }}	}
}t          d
||	fz             |
t          d           nC|
\  }}}}}}t          d|           t          d|           t          d||fz             Y d }~d S Y d }~d S d }~ww xY w)NOnConnection	PythonBarT)NamePositionMenuBar	Temporary	Greetings)Type	Parameterz&PythonzPython rules the World34z&The Excel call failed with code %d: %sz&There is no extended error informationzThe source of the error iszThe error message isz$More info can be found in %s (id=%d))printr    CommandBarsAddr   	msoBarTopmsoBarTypeNormalControlsmsoControlButtonr   r   toolbarButtonmsoButtonCaptionStyle
BeginGroupCaptionTooltipTextWidthVisible	pythoncom	com_errorargs)r   applicationconnectModeaddincustomcbcMyBarbtnMyButtonxxx_todo_changemehrmsgexcargwcodesourcetexthelpFilehelpIdscodes                     r   r#   zExcelAddin.OnConnectionY   s   nk;vFFF	S)DO266 ",!2	 7  H #+///; 0  K 0B[0 0 K$, !* :K%)K""+K&>K# $K#H" 		S 		S 		S"3"8Rc3:b#YFGGG{>?????B<vtXvu2F;;;,d333<&?QQRRRRRRRRR @?????			Ss   B4C EA/EEc                 p    t          d           | j                            d          j         d | _        d S )NOnDisconnectionr$   )r-   r    r.   Delete)r   moderB   s      r   rQ   zExcelAddin.OnDisconnectionz   s5       ##K0077r   c                 &    t          d|           d S )NOnAddInsUpdater-   r   rB   s     r   rU   zExcelAddin.OnAddInsUpdate   s    '''''r   c                 &    t          d|           d S )NOnStartupCompleterV   rW   s     r   rY   zExcelAddin.OnStartupComplete   s    !6*****r   c                 &    t          d|           d S )NOnBeginShutdownrV   rW   s     r   r[   zExcelAddin.OnBeginShutdown   s    (((((r   N)r   r   r   _com_interfaces__public_methods_r<   CLSCTX_INPROC_SERVER_reg_clsctx__reg_clsid__reg_progid__reg_policy_spec_r!   r#   rQ   rU   rY   r[   r   r   r   r   r   N   s        ,-1L:K+LC  S S SB  
( ( (+ + +) ) ) ) )r   r   c                 j   dd l }|                    |j        d          }|                    || j                  }|                    |dd|j        d           |                    |dd|j        d           |                    |dd|j        d           |                    |dd|j        d	           d S )
Nr   z&Software\Microsoft\Office\Excel\AddinsCommandLineSafeLoadBehaviorr   DescriptionzExcel AddinFriendlyNamezA Simple Excel Addin)winreg	CreateKeyHKEY_CURRENT_USERra   
SetValueEx	REG_DWORDREG_SZ)klassrh   keysubkeys       r   RegisterAddinrq      s    MMM


 "N C c5#566F
f/F4DaHHH
fna1A1EEE
fmQ}MMM
fna@VWWWWWr   c                 x    dd l }	 |                    |j        d| j        z              d S # t          $ r Y d S w xY w)Nr   z'Software\Microsoft\Office\Excel\Addins\)rh   	DeleteKeyrj   ra   OSError)rn   rh   s     r   UnregisterAddinru      sg    MMM$:U=OO	
 	
 	
 	
 	
    s   #+ 
99__main__z--unregister)sysr<   win32comr   win32com.clientr   r   r   EnsureModuleRegisterInterfacesr   r   rq   ru   r   win32com.server.registerserverregisterUseCommandLineargvr   r   r   <module>r      s  b 


           C C C C C C C C C C  ,aA$     ,aA$   
 	 ,aA8L7M  
       8) 8) 8) 8) 8) 8) 8) 8)v
X 
X 
X	 	 	 z####O++J777!!
#####j!!!!! r   