
    BPc                         d Z ddlZddlmZ g dg dg ddZd Z G d	 d
          Z G d de          Z G d d          ZdS )z6
Wraps the gtk windows with something a little nicer.
    N)Gtk)expandfillpaddingz	pack-type)
top-attachleft-attachheightwidth)r   r   zbottom-attachzright-attach)BoxGridTablec           	          t          | t                    st          |           } |D ]-}|| j        v r"t          | j         d| j         d| d          .dS )z[Simple check for protecting an inherrited class from having
    certain methods over-riddenz in z has protected def z()N)
isinstancetype__dict__RuntimeError__name__
__module__)clsmethodsmethods      2/usr/share/inkscape/extensions/inkex/gui/window.pyprotectr       s~     c4   3ii  S\!!<VVS^VVFVVV   "     c                   x    e Zd ZdZdZdZd Zd ZddZd Z	d Z
dd	Zd
 ZddZd Zd Zd Zed             ZdS )Windowz
    This wraps gtk windows and allows for having parent windows

    name = 'name-of-the-window'

    Should the window be the first loaded and end gtk when closed:

    primary = True/False
    TNc                    || _         d| _        d | _        d| _        |                    | j                  }t          j                    | _        | j        j	        | _
        | j                            |j                   | j                            |           | 
                    | j                  | _        | j        st          d| j         d| d          t!          t#          | j                            | _        d S )NF zMissing window widget 'z' from '')gappdeadparentargsget_ui_filenamer   Builderw_tree
get_objectwidgetset_translation_domainapp_nameadd_from_filewindowKeyErrorstrhashwid)selfr    ui_files      r   __init__zWindow.__init__:   s    			""49-- kmmk,**4=999!!'*** kk$),,{ 	TRTYRRRRRSSS tDK(())r   c                 x    | j                                         D ]}| j                             |           |c S dS )z5Extract this window's container for use in other appsN)r-   get_childrenremove)r2   childs     r   extractzWindow.extractO   sH    [--// 	 	EKu%%%LLL	 	r   c                    d|vrt          | dddd           || _        || _        | j                            |            | j                            d| j                   | j        r9| j                            | j                   | j        	                    d            | j
        di | j         | j                                         dS )	z'Initialise the window within the GtkAppreplacedestroyexitload_windowproto_windowFNr   )r   r#   r"   r'   connect_signalsr-   connectr=   set_transient_forset_sensitiveload_widgetsshow)r2   r"   kwargss      r   initzWindow.initU   s    F""D)V]NKKK	##D))) 	Ity111 ; 	-K))$+666K%%e,,, 	&&DI&&&r   c                 B    | j         |d<    | j        j        |g|R i |S )z,Load child window, automatically sets parentr"   )r-   r    r>   )r2   r%   r#   rF   s       r   r>   zWindow.load_windowk   s3    ;x$ty$T;D;;;F;;;r   c                     dS )z-Child class should use this to create widgetsNr   r2   s    r   rD   zWindow.load_widgetsp         r   c                 l    t          j        d| j                   | j                                         dS )zDestroy the windowzDestroying Window '%s'N)loggingdebugr%   r-   r<   r2   r)   s     r   r<   zWindow.destroys   s1    .	:::r   c                     dS )z7Internal method for what to do when the window has diedNr   rJ   s    r   pre_exitzWindow.pre_exity   rK   r   c                    |rt          |t          j                  s|                                  |                                  | j        r| j                            d           | j        r.t          j	        d           | j
                                         n4t          j	        d| j                   | j
                            |            d| _        |                                  |S )z%Called when the window needs to exit.TzExiting the applicationzRemoving Window %s from parent)r   r   r   r<   rQ   r"   rC   primaryrM   rN   r    r=   r%   remove_windowr!   	post_exitrO   s     r   r=   zWindow.exit|   s      	Z
;; 	LLNNN; 	,K%%d+++ < 	*M3444INNM:DIFFFI##D)))	r   c                     dS )z$Called after we've killed the windowNr   rJ   s    r   rU   zWindow.post_exit   rK   r   c                 J    |                      |          pt          |          S )z
        Attempt to get the widget from gtk, but if not return a fake that won't
        cause any trouble if we don't further check if it's real.
        )r)   
FakeWidgetr2   r%   s     r   	if_widgetzWindow.if_widget   s#    
 {{4  4Jt$4$44r   c                    t          |t                    r|                     |          }t          |t                    r|                     |          }|                                }|                                }|C||                    |           |                    |           |                    |           dS dS )z*Replace the old widget with the new widgetN)r   r/   r)   
get_parentr7   add)r2   oldnewtargetsources        r   r;   zWindow.replace   s    c3 	#++c""Cc3 	#++c""C!!!!!c"""MM#JJsOOOOO	 r   c                 @    t           j                            |           S )z,Return the widget's name in the builder file)r   	Buildableget_name)objs    r   get_widget_namezWindow.get_widget_name   s     }%%c***r   N)r   r   __qualname____doc__rS   r%   r4   r9   rG   r>   rD   r<   rQ   r=   rU   rZ   r;   staticmethodrf   r   r   r   r   r   ,   s          GD* * **     ,< < <
< < <   F F F   .3 3 35 5 5   + + \+ + +r   r   c                       e Zd ZdZdZdS )ChildWindowa*  
    Base class for child window objects, these child windows are typically
    window objects in the same gtk builder file as their parents. If you just want
    to make a window that interacts with a parent window, use the normal
    Window class and call with the optional parent attribute.
    FN)r   r   rh   ri   rS   r   r   r   rl   rl      s          GGGr   rl   c                   $    e Zd ZdZd Zd Zd ZdS )rX   z'A fake widget class that can take callsc                     || _         d S rg   )_namerY   s     r   r4   zFakeWidget.__init__   s    


r   c                     d }|S )Nc                  2    t          j        d| |           d S )NzCalling fake method: %s:%s)rM   info)r#   rF   s     r   _fakez%FakeWidget.__getattr__.<locals>._fake   s    L5tVDDDDDr   r   )r2   r%   rs   s      r   __getattr__zFakeWidget.__getattr__   s    	E 	E 	E r   c                     dS )NFr   rJ   s    r   __bool__zFakeWidget.__bool__   s    ur   N)r   r   rh   ri   r4   rt   rv   r   r   r   rX   rX      sG        11        r   rX   )	ri   rM   gi.repositoryr   PROPSr   r   rl   rX   r   r   r   <module>ry      s   $         655<<<KKK	 		 	 	B+ B+ B+ B+ B+ B+ B+ B+J    &            r   