a
    6i                     @   s\   d Z ddlZddlZddlZddlZddlZddlmZ ddlm	Z	 G dd dZ
dgZdS )(Implements a waiting dialog using zenity    N)Path)Optionalc                   @   sn   e Zd ZdZdeeddddZeeeef  ddd	Zee	j
 dd
dZddddZddddZdS )ZenityWaitDialogr   ProtonFixesN)texttitlereturnc                 C   s,   || _ || _d| _t | _d| _d| _dS )zInitialize zenity dialog

        :param text: the message displayed in the dialog window
        :type text: str

        :param title: the title of the dialog window
        :type title: str
        N)_text_title_proc	threadingEvent	_stop_evt_thread_tmp_cfg)selfr   r    r   _/home/james-whalen/.local/share/Steam/compatibilitytools.d/GE-Proton10-32/protonfixes/zenity.py__init__   s    	
zZenityWaitDialog.__init__r	   c                 C   s   t j }d|d< |ds*|ds*d S tjdd| _t| jj}|d }|j	ddd	 d
}|d j
|dd t||d< |S )N1ZGTK_CSDDISPLAYWAYLAND_DISPLAYzprotonfixes-gtk-)prefixzgtk-3.0T)parentsexist_okuP  
        window, dialog, box {
            background-color: #171d25;
        }

        /* The outer “frame” node GTK draws for CSD windows */
        decoration {
        background-color: #171d25;
        border: 1px solid #292e36;
        box-shadow: none;
        }

        /* Titlebar / headerbar */
        headerbar.titlebar {
        background-color: #171d25;
        color: #171d25;
        border-bottom: 1px solid #292e36;
        box-shadow: none;
        }

        headerbar.titlebar label {
        color: #ffffff;
        }

        /* Titlebar buttons (close/min/max) – if present */
        headerbar.titlebar button.titlebutton {
        background-color: #292e36;
        color: #000000;
        border: 1px solid #292e36;
        box-shadow: none;
        }

        headerbar.titlebar button.titlebutton:hover {
        background-color: #292e36;
        }

        /* Labels/text */
        label, text {
            color: #ffffff;
        }


        /* Progressbar ("status bar") */
        progressbar {
            color: #ffffff;
        }

        progressbar trough {
            background-color: #292e36;

            /* border / outline */
            border-color: #292e36;
            border-style: solid;
            border-width: 1px;

            /* optional: match the flat look */
            border-radius: 0;
            box-shadow: none;
        }

        progressbar progress {
            background-color: #292e36;
            border-radius: 0;
            box-shadow: none;
        }

        progressbar text {
            color: #ffffff;
        }
        zgtk.csszutf-8)encodingXDG_CONFIG_HOME)osenvironcopygettempfileTemporaryDirectoryr   r   namemkdir
write_textstr)r   envZcfg_rootZgtk_dircssr   r   r   	_make_env   s    
FzZenityWaitDialog._make_envc                 C   sN   |   }|sd S dddddd| j d| j dg}tj|tjtjtj|d	}|S )
Nzenityz
--progressz	--pulsatez--no-cancelz--auto-closez--title=z--text=z--width=420)stdinstdoutstderrr)   )r+   r   r
   
subprocessPopenPIPEDEVNULL)r   r)   cmdprocr   r   r   
_start_one|   s(    zZenityWaitDialog._start_onec                    sd   z    _W n ty(   d _Y dS 0  js4dS dd fdd}tj|dd _ j  dS )zShow the wait dialogNr   c                      sX    j  sT jrH j d urHz   _W n tyF   d  _Y d S 0 td q d S )Ng      ?)r   is_setr   pollr6   FileNotFoundErrortimesleepr   r   r   r   _watch   s    
z&ZenityWaitDialog.start.<locals>._watchT)targetdaemon)r6   r   r9   r   Threadr   start)r   r=   r   r<   r   rA      s    
zZenityWaitDialog.startc                 C   s   | j   | jr| j du rz2| jjrN| jjd | jj  | jj  W n tyb   Y n0 z| jj	dd W n4 ty   z| j
  W n ty   Y n0 Y n0 | jr| jjdd | jr| j  d| _dS )zHide the wait dialogNs   100
g      ?)timeout)r   setr   r8   r-   writeflushclose	Exceptionwait	terminater   joinr   cleanupr<   r   r   r   stop   s*    

zZenityWaitDialog.stop)r   )__name__
__module____qualname____doc__r(   r   r   dictr+   r0   r1   r6   rA   rL   r   r   r   r   r      s   ]r   )rP   r   r0   r#   r   r:   pathlibr   typingr   r   __all__r   r   r   r   <module>   s    C