Mini Shell

Direktori : /lib64/python3.6/site-packages/pyanaconda/ui/gui/__pycache__/
Upload File :
Current File : //lib64/python3.6/site-packages/pyanaconda/ui/gui/__pycache__/utils.cpython-36.pyc

3

@��eN�@s�ddlZddlZejdd�ejdd�ddlZddlZddlZddlZddlm	Z	m
Z
ddlmZddl
mZddlmZmZdd	lmZmZdd
lmZmZmZmZmZddlmZee�Ze�Z dd
�Z!dd�Z"fddfdd�Z#d9dd�Z$edd��Z%dd�Z&dd�Z'dd�Z(d:d!d"�Z)d#d$�Z*d%d&�Z+d'd(�Z,d;d)d*�Z-d+d,�Z.d-d.�Z/iZ0d<d/d0�Z1d1d2�Z2iZ3d=d3d4�Z4d>d5d6�Z5d7d8�Z6dS)?�N�Gdkz3.0�Gtk)rr)�contextmanager)�glib)�	threadMgr�AnacondaThread)�async_action_wait�run_in_loop)�NOTICEABLE_FREEZE�
PASSWORD_HIDE�
PASSWORD_SHOW�PASSWORD_HIDE_ICON�PASSWORD_SHOW_ICON)�get_module_loggercs�fdd�}t||�dS)zUWrapper for GLib.idle_add call that ensures the func is called
       only once.
    cs�|�dS)NF�)�args)�funcr�/usr/lib64/python3.6/utils.py�wrap5szgtk_call_once.<locals>.wrapN)r	)rrrr)rr�
gtk_call_once1srcst��fdd��}|�S)z7Run some Gtk action in the main thread and wait for it.cs���S)Nrr)rrrr�
gtk_action?sz#fire_gtk_action.<locals>.gtk_action)r)rrrr)rrr�fire_gtk_action<sr�c	s�tj�st���fdd�}��fdd�}tj�}tj�}tjd|t	j
���tjtd||fd��t
||||f�|j�tjd|t	j
���d	S)
a
    Function that maps an action on items in a way that makes the action run in
    the main thread, but without blocking the main thread for a noticeable
    time. If a pre-processing function is given it is mapped on the items first
    before the action happens in the main thread.

    .. DANGER::
       MUST NOT BE CALLED NOR WAITED FOR FROM THE MAIN THREAD.

    :param action: any action that has to be done on the items in the main
                   thread
    :type action: (action_item, \*args) -> None
    :param items: an iterable of items that the action should be mapped on
    :type items: iterable
    :param args: additional arguments passed to the action function
    :type args: tuple
    :param pre_func: a function that is mapped on the items before they are
                     passed to the action function
    :type pre_func: item -> action_item
    :param batch_size: how many items should be processed in one run in the main loop
    :raise AssertionError: if called from the main thread
    :return: None

    csH�r"x4�D]}|j�|��q
Wnx�D]}|j|�q(W|jt�dS)N)Zput�
TERMINATOR)�queue_instance�item)�items�pre_funcrr�
preprocessbs

z!gtk_batch_map.<locals>.preprocesscs�|\}}}tj�}tj�}xp||tkr�xVt��D]J}y.|j�}|tkrT|j�dS||f���Wq2tjk
rzdSXq2Wtj�}qWdS)NFT)�timer
�rangeZ
get_nowaitr�set�queueZEmpty)�	argumentsr�action�
done_eventZtstamp_start�tstampZ_iZaction_item)r�
batch_sizerr�process_one_batchls

z(gtk_batch_map.<locals>.process_one_batchzStarting applying %s on %sZAnaGtkBatchPre)�prefix�targetrzFinished applying %s on %sN)rZin_main_thread�AssertionErrorr"ZQueue�	threadingZEvent�log�debug�object�__repr__�addrr	�wait)	r$rrrr'rr(Zitem_queue_instancer%r)rr'rrr�
gtk_batch_mapFs
r3�,��TcsG���fdd�dt�}|S)a�
    Function returning decorator for decorating often repeated actions that need
    to happen in the main loop (entry/slider change callbacks, typically), but
    that may take a long time causing the GUI freeze for a noticeable time.

    The return value of the decorator function returned by this function--i.e.,
    the value of timed_action()(function_to_be_decorated)--is an instance of
    the TimedAction class, which besides being callable provides a run_now
    method to shortcut the timer and run the action immediately. run_now will
    also be run in the main loop.

    If timed_action is used to decorate a method of a class, the decorated
    method will actually be a functools.partial instance. In this case, the
    TimedAction instance is accessible as the "func" property of the decorated
    method. Note that the func property will not have self applied.

    :param delay: number of milliseconds to wait for another invocation of the
                  decorated function before it is actually called
    :type delay: int
    :param threshold: upper bound (in milliseconds) to wait for the decorated
                      function to be called from the first/last time
    :type threshold: int
    :param busy_cursor: whether the cursor should be made busy or not in the
                        meantime of the decorated function being invocated from
                        outside and it actually being called
    :type busy_cursor: bool

    csTeZdZdZdd�Zedd��Z�fdd�Zedd	��Z	���fd
d�Z
dd
�ZdS)z!timed_action.<locals>.TimedActionzClass making the timing work.cSs||_d|_d|_i|_dS)N)�_func�_last_start�_timer�
_instance_map)�selfrrrr�__init__�sz*timed_action.<locals>.TimedAction.__init__cSs
|jdk	S)z1Whether there is a pending timer for this action.N)r8)r:rrr�timer_active�sz.timed_action.<locals>.TimedAction.timer_activecs.|\}}|j||�d|_d|_�r*t�dS)NF)r6r7r8�unbusyCursor)r:r#r�kwargs)�busy_cursorrr�_run_once_one_arg�sz3timed_action.<locals>.TimedAction._run_once_one_argc_s(|jr|jj�d|_|j||f�dS)N)r8�cancelr@)r:rr>rrr�run_now�s
z)timed_action.<locals>.TimedAction.run_nowcs�|jptj�|_tj�}|jr.|jj�d|_||jd�krR|j||�d|_�r\t�tjjj	�|_|jj
�|j||f�dS)Ni�)r7rr8rAr6�
busyCursor�
pyanacondaZcoreZtimerZTimerZtimeout_msecr@)r:rr>r&)r?�delay�	thresholdrr�__call__�s
z*timed_action.<locals>.TimedAction.__call__cSs&||jkrtj||�|j|<|j|S)N)r9�	functools�partial)r:�instance�ownerrrr�__get__�s
z)timed_action.<locals>.TimedAction.__get__N)�__name__�
__module__�__qualname__�__doc__r;�propertyr<r@rrBrGrLr)r?rErFrr�TimedAction�s
rR)r/)rErFr?rRr)r?rErFr�timed_action�sMrSccs|j|�dV|j|�dS)z`Prevent a GLib signal handling function from being called during some
       block of code.
    N)Zhandler_block_by_funcZhandler_unblock_by_func)�objrrrr�blockedHandlers
rUcCs(tj�}|sdS|jtjtjj��dS)N)r�get_default_root_window�
set_cursor�Cursor�
CursorTypeZWATCH)�windowrrrrCsrCcCs(tj�}|sdS|jtjtjj��dS)N)rrVrWrXrYZARROW)rZrrrr=sr=cCs2tj�}|jtdd��|j�}|j|tj�dS)aPrevent a dialog from accepting the escape keybinding, which emits a
       close signal and will cause the dialog to close with some return value
       we are likely not expecting.  Instead, this method will cause the
       escape key to do nothing for the given GtkDialog.
    z[@binding-set IgnoreEscape {   unbind 'Escape';}GtkDialog { gtk-key-bindings: IgnoreEscape }zutf-8N)r�CssProvider�load_from_data�bytes�get_style_context�add_provider�#STYLE_PROVIDER_PRIORITY_APPLICATION)Zdlg�provider�contextrrr�ignoreEscapes
rc�@theme_bg_colorcCs6tj�}|jtd|d��|j�}|j|tj�dS)z�Set the background color of the GtkViewport vp to be the same as the
       overall UI background.  This should not be called for every viewport,
       as that will affect things like TreeViews as well.
    zviewport { background: %s }zutf-8N)rr[r\r]r^r_r`)ZvpZcolorrarbrrr�setViewportBackground/srecCs*|j|�x|j�D]}|j|�qWdS)z�Set the sensitivity of a widget, and then set the sensitivity of
       all widgets it is a mnemonic widget for.  This has the effect of
       marking both an entry and its label as sensitive/insensitive, for
       instance.
    N)Z
set_sensitiveZlist_mnemonic_labels)�widget�value�wrrr�fancy_set_sensitive;s
ricCs|jd�|j�dS)z�Some widgets need to be both hidden, and have no_show_all set on them
       to prevent them from being shown later when the screen is redrawn.
       This method takes care of that.
    TN)�set_no_show_allZhide)rfrrr�really_hideFs
rkcCs|jd�|j�dS)z�Some widgets need to have no_show_all unset before they can also be
       shown, so they are displayed later when the screen is redrawn.  This
       method takes care of that.
    FN)rjZshow)rfrrr�really_showOs
rlcCsn|j�}|j�}x$|r4||||kr4|j|�}qW|s>dS|j�}|j|�|j|�}|j|ddd�|S)aw
    Select the given item in the given treeview and scroll to it.

    :param treeview: treeview to select and item in
    :type treeview: GtkTreeView
    :param item: item to be selected
    :type item: str
    :param col: column to search for the item in
    :type col: int
    :return: selected iterator or None if item was not found
    :rtype: GtkTreeIter or None

    NTg�?)Z	use_alignZ	row_align)Z	get_modelZget_iter_firstZ	iter_nextZ
get_selectionZselect_iter�get_pathZscroll_to_cell)Ztreeviewr�colZmodelZitrZ	selection�pathrrr�set_treeview_selectionXs

	rpcCstjjtj��dS)z�
    Set the right direction (RTL/LTR) of the Gtk widget's and their layout based
    on the current language configuration.

    N)rZWidgetZset_default_directionZget_locale_directionrrrr�setup_gtk_direction�srqcCstjt|��S)z�
    Escape strings for use within Pango markup.

    This function converts the value to a string before passing to GLib function.
    )rZmarkup_escape_text�str)rgrrr�
escape_markup�srscCsFddd�}||ftkr.it||f<|j||�||ft||f|<dS)a�
    Override a single property of a cell renderer.

    property_func takes the same arguments as GtkTreeCellDataFunc:
    (TreeViewColumn, CellRenderer, TreeModel, TreeIter, data). Instead of being
    expected to manipulate the CellRenderer itself, this method should instead
    return the value to which the property should be set.

    This method calls set_cell_data_func on the column and renderer.

    :param GtkTreeViewColumn column: the column to override
    :param GtkCellRenderer cell_renderer: the cell renderer to override
    :param str propname: the property to set on the renderer
    :param function property_func: a function that returns the value of the property to set
    :param data: Optional data to pass to property_func
    Nc
SsFt||f}x4|D],}||\}}||||||�}	|j||	�qWdS)N)�_override_cell_property_mapZset_property)
�tree_column�
cell_rendererZ
tree_modelZ	tree_iter�_dataZ	overridesZ
property_name�
property_funcZproperty_func_dataZproperty_valuerrr�_cell_data_func�s

z/override_cell_property.<locals>._cell_data_func)N)rtZset_cell_data_func)rurvZpropnamerx�dataryrrr�override_cell_property�s

r{cCsD|j�}x6|r>|j�}||�r"|St|tj�r
|j|j��q
WdS)a�
    Find the first child widget of a container matching the given function.

    This method performs a breadth-first search for the widget. match_func
    takes the widget as a paramter, and the return value will be evaulated as
    a bool.

    :param GtkContainer parent: the container to search
    :param function match_func: The function defining the condition to match
    :return: The first matching widget
    :rtype: GtkWidget or None
    N)�get_children�pop�
isinstancer�	Container�extend)�parentZ
match_funcZsearch_listrfrrr�find_first_child�s
r�c	Cs�dd�}dd�}|||�t|tj�r�x|j�D]}t|||�q0W|||f}|tkr�|jd|||f�}|jd|||f�}||ft|<dS)a{
    Call callback on widget and all children of widget as they are added.

    Callback is a function that takes widget and user_data as arguments. No
    return value is expected.

    Callback will be called immediately for widget, and, if widget is a
    GtkContainer, for all children of widget. If widget is a container it will
    be then be watched for new widgets added to the container, and callback
    will be called on the new children as they are added.

    :param GtkWidget widget: the widget to watch
    :param function callback: the callback function
    :param user_data: optional user_data to pass to callback
    cSs|\}}t|||�dS)N)�watch_children)�	containerrf�	user_data�callbackrrr�_add_signal�sz#watch_children.<locals>._add_signalcSs|\}}t|||�dS)N)�unwatch_children)r�rfr�r�rrr�_remove_signal�sz&watch_children.<locals>._remove_signalr1�removeN)r~rrr|r��_widget_watch_listZconnect)	rfr�r�r�r��child�
signal_key�
add_signal�
remove_signalrrrr��s

r�cCsf|||f}|tkr8t|\}}|j|�|j|�t|=t|tj�rbx|j�D]}t|||�qNWdS)a
    Unregister a callback previously added with watch_children.

    :param GtkWidget widget: the widget to unwatch
    :param function callback: the callback that was previously added to the widget
    :param user_data: the user_data that was previously added to the widget
    N)r�Z
disconnectr~rrr|r�)rfr�r�r�r�r�r�rrrr�s	


r�cCsDtjj}|rt}t}nt}t}|j|�|j||�|j	||�dS)zMake the password in/visible.N)
rZEntryIconPositionZ	SECONDARYr
rrrZset_visibilityZset_icon_from_icon_nameZset_icon_tooltip_text)�entryZvisibleZpositionZicon�textrrr�set_password_visibilitys
r�)r4r5T)rd)r)N)N)N)7ZgiZpyanaconda.core.timerrDZrequire_versionr"rr,rHZ
gi.repositoryrr�
contextlibrZpyanaconda.corerZpyanaconda.threadingrrZpyanaconda.core.async_utilsrr	Zpyanaconda.core.constantsr
rrr
rZpyanaconda.anaconda_loggersrrMr-r/rrrr3rSrUrCr=rcrerirkrlrprqrsrtr{r�r�r�r�r�rrrr�<module>sL
P
n

		
)

!
-