a
    •aÏ  ã                   @   sr   d dl Z d dlmZmZmZ d dlZdZdZdZG dd„ dej	ƒZ
G dd	„ d	ejƒZG d
d„ dejƒZdd„ ZdS )é    N)ÚQtCoreÚQtGuiÚ	QtWidgetsé   iô  ZAllc                       s@   e Zd ZdZ‡ fdd„Zdd„ Zdd„ Zdd	„ Zd
d„ Z‡  Z	S )ÚIconBrowserzÏ
    A small browser window that allows the user to search through all icons from
    the available version of QtAwesome.  You can also copy the name and python
    code for the currently selected icon.
    c                    sÎ  t ƒ  ¡  |  dd¡ |  d¡ t ¡  tjd j}g }| ¡ D ]$\}}|D ]}| 	d||f ¡ qLq@t
 | ¡| _| j d¡ | j t¡ | jj | j¡ t|  ¡  tjj¡ƒ}| t|ƒ¡ t
 ¡ | _| j |¡ | j t
jj ¡ t!| ƒ| _"| j" #d¡ | j" $t%j&j'¡ | j" (| j¡ | j" )t
jj*¡ | j"j+ | j,¡ t% -| ¡| _.| j. /t
jj0¡ | j.j1 | j2¡ | j.j3 | j4¡ t% 5| ¡| _6| j6 7d¡ | j6j8 | j4¡ | j6 9t:gt| ;¡ ƒ ¡ t% <¡ }| =dddd¡ | >| j6¡ | >| j.¡ t% ?| ¡}| @|¡ t% Ad	| ¡| _B| jBjC | j,¡ t% D¡ }| >|¡ | >| j"¡ | >| jB¡ t% ?| ¡}	|	 @|¡ |  E|	¡ t% Ft Gt
jjH¡| | j,¡ | j. I¡  |  J¡ }
t%jK L¡ }| M| N¡  O¡ ¡}| P|¡ Q¡ }|
 R|¡ |  S|
¡ d S )
Ni  i,  zQtAwesome Icon BrowserZiconicz%s.%sTéK   r   z	Copy Name)TÚsuperÚ__init__ZsetMinimumSizeZsetWindowTitleÚ	qtawesomeZ	_instanceZ	_resourceÚcharmapÚitemsÚappendr   ZQTimerÚ_filterTimerZsetSingleShotZsetIntervalÚAUTO_SEARCH_TIMEOUTÚtimeoutZconnectÚ_updateFilterÚ	IconModelZpaletteÚcolorr   ZQPaletteÚTextZsetStringListÚsortedZQSortFilterProxyModelÚ_proxyModelZsetSourceModelZsetFilterCaseSensitivityÚQtZCaseInsensitiveÚIconListViewÚ	_listViewZsetUniformItemSizesZsetViewModer   Ú	QListViewZIconModeZsetModelZsetContextMenuPolicyZCustomContextMenuZdoubleClickedÚ_copyIconTextZ	QLineEditÚ	_lineEditZsetAlignmentZAlignCenterZtextChangedÚ_triggerDelayedUpdateZreturnPressedÚ_triggerImmediateUpdateZ	QComboBoxÚ	_comboBoxZsetMinimumWidthZcurrentIndexChangedZaddItemsÚALL_COLLECTIONSÚkeysZQHBoxLayoutZsetContentsMarginsZ	addWidgetZQFrameZ	setLayoutZQPushButtonZ_copyButtonZclickedZQVBoxLayoutZsetCentralWidgetZ	QShortcutZQKeySequenceZ
Key_ReturnZsetFocusZgeometryÚQApplicationÚdesktopZscreenNumberZcursorÚposZscreenGeometryÚcenterZ
moveCenterZsetGeometry)ÚselfZfontMapsZ	iconNamesZfontCollectionZfontDataZiconNameZmodelZlytZsearchBarFrameÚframeZgeor#   ZscreenZcenterPoint©Ú	__class__© ú5lib/python3.9/site-packages/qtawesome/icon_browser.pyr	      sv    









ý


zIconBrowser.__init__c                 C   sL   d}| j  ¡ }|tkr"|d| 7 }| j ¡ }|r<|d| 7 }| j |¡ dS )z{
        Update the string used for filtering in the proxy model with the
        current text from the line edit.
        Ú z^%s\.z.*%s.*$N)r   ZcurrentTextr    r   Útextr   ZsetFilterRegExp)r&   ZreStringÚgroupZ
searchTermr*   r*   r+   r   e   s    

zIconBrowser._updateFilterc                 C   s   | j  ¡  | j  ¡  dS )zY
        Reset the timer used for committing the search term to the proxy model.
        N)r   ÚstopÚstart©r&   r*   r*   r+   r   v   s    
z!IconBrowser._triggerDelayedUpdatec                 C   s   | j  ¡  |  ¡  dS )zt
        Stop the timer used for committing the search term and update the
        proxy model immediately.
        N)r   r/   r   r1   r*   r*   r+   r   }   s    
z#IconBrowser._triggerImmediateUpdatec                 C   s6   | j  ¡ }|sdS tj ¡  ¡ }| |d  ¡ ¡ dS )zP
        Copy the name of the currently selected icon to the clipboard.
        Nr   )r   ZselectedIndexesr   r"   ÚinstanceÚ	clipboardZsetTextÚdata)r&   Zindexesr3   r*   r*   r+   r   …   s
    
zIconBrowser._copyIconText)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r	   r   r   r   r   Ú__classcell__r*   r*   r(   r+   r      s   Nr   c                       s.   e Zd ZdZd‡ fdd„	Z‡ fdd„Z‡  ZS )r   zk
    A QListView that scales it's grid size to ensure the same number of
    columns are always drawn.
    Nc                    s   t ƒ  |¡ |  tjj¡ d S ©N)r   r	   ZsetVerticalScrollBarPolicyr   r   ZScrollBarAlwaysOn)r&   Úparentr(   r*   r+   r	   —   s    zIconListView.__init__c                    s\   |   ¡  ¡ d }|t }t|d ƒ}t|ƒ}|  t ||¡¡ |  t ||¡¡ tƒ  	|¡S )zœ
        Re-implemented to re-calculate the grid size to provide scaling icons

        Parameters
        ----------
        event : QtCore.QEvent
        é   gš™™™™™é?)
ZviewportÚwidthÚVIEW_COLUMNSÚintZsetGridSizer   ZQSizeZsetIconSizer   ÚresizeEvent)r&   Zeventr=   Z	tileWidthZ	iconWidthr(   r*   r+   r@   ›   s    zIconListView.resizeEvent)N)r5   r6   r7   r8   r	   r@   r9   r*   r*   r(   r+   r   ‘   s   r   c                       s0   e Zd Z‡ fdd„Zdd„ Z‡ fdd„Z‡  ZS )r   c                    s   t ƒ  ¡  || _d S r:   )r   r	   Ú
_iconColor)r&   Z	iconColorr(   r*   r+   r	   ´   s    
zIconModel.__init__c                 C   s   t jjt jjB S r:   )r   r   ZItemIsEnabledZItemIsSelectable)r&   Úindexr*   r*   r+   Úflags¸   s    zIconModel.flagsc                    s<   |t jjkr.| j|t jjd}tj|| jdS tƒ  ||¡S )zÔ
        Re-implemented to return the icon for the current index.

        Parameters
        ----------
        index : QtCore.QModelIndex
        role : int

        Returns
        -------
        Any
        )Úrole)r   )	r   r   ZDecorationRoler4   ZDisplayRoler
   ZiconrA   r   )r&   rB   rD   Z
iconStringr(   r*   r+   r4   »   s    zIconModel.data)r5   r6   r7   r	   rC   r4   r9   r*   r*   r(   r+   r   ²   s   r   c                  C   s*   t  g ¡} tƒ }| ¡  t |  ¡ ¡ dS )zB
    Start the IconBrowser and block until the process exits.
    N)r   r"   r   ZshowÚsysÚexitZexec_)ZappZbrowserr*   r*   r+   ÚrunÎ   s    
rG   )rE   Zqtpyr   r   r   r
   r>   r   r    ZQMainWindowr   r   r   ZQStringListModelr   rG   r*   r*   r*   r+   Ú<module>   s    !