File: //lib/python3/dist-packages/DistUpgrade/__pycache__/ReleaseNotesViewer.cpython-38.pyc
U
B��]� � @ s� d dl mZ d dl mZmZmZ d dlZd dlZdd� ZG dd� dej�Z e
dkr�e�� Ze e
d ��� �Ze�e� e�� e�� dS )
� )�Pango)�Gtk�GObject�GdkNc C s� t j�d�rd| g}n4t j�d�r,d| g}nt j�d�rBd| g}nd| g}t �� dkrvd t jkrvd
dt jd g| }n0t �� dkr�dt jkr�d
d
ddt jd g| }t�|� dS )z#Open the specified URL in a browserz/usr/bin/xdg-openzxdg-openz/usr/bin/exo-openzexo-openz/usr/bin/gnome-openz
gnome-openz
x-www-browserr Z SUDO_USERZsudoz-uZ
PKEXEC_UIDz-H�#N)�os�path�exists�getuid�environ�
subprocess�Popen)�urlZcommand� r �@/usr/lib/python3/dist-packages/DistUpgrade/ReleaseNotesViewer.py�open_url! s
��r c @ sD e Zd Zdd� Zdd� Zdd� Zdd� Zd d
� Zdd� Zd
d� Z dS )�ReleaseNotesViewerc C s� t j �| � d| _d| _| �dd� | �d� | �t�d�� t �
� | _| �| j� | j�
|� | �d| j� | �d| j� | �d| j� | �� dS ) z�Init the ReleaseNotesViewer as an Inheritance of the Gtk.TextView.
Load the notes into the buffer and make links clickableFTZeditableZ monospacezbutton-press-eventzmotion-notify-eventzvisibility-notify-eventN)r �__init__�hovering�firstZset_propertyZset_cursor_visibleZmodify_fontr ZFontDescriptionr Z
TextBuffer�bufferZ
set_bufferZset_textZconnect�button_press_event�motion_notify_event�visibility_notify_event�search_links)�selfZnotesr r r r 6 s
zReleaseNotesViewer.__init__c C s0 | j jddtjjd�}||_| j �|||� dS )z@Apply the tag that marks links to the specified buffer selectionNZblue)Z
foregroundZ underline)r Z
create_tagr Z UnderlineZSINGLEr Z apply_tag)r �start�endr �tagr r r �tag_linkK s
�zReleaseNotesViewer.tag_linkc C s� | j �d�}|�dtjjd�}|s$q||\}}|�� }|�� r^|�|�}|dkrTq^nq^|�� }q4|�|�}| � |||� |}qdS )zlSearch for http URLs in the buffer and call the tag_link method
for each one to tag them as linksr zhttp://N)� �)�]�
� )
r Zget_iter_at_offsetZforward_searchr ZTextSearchFlagsZVISIBLE_ONLY�copyZforward_charZget_textr )r �iterZretZmatch_startZ match_endZ match_tmp�textr r r r r R s$ �
zReleaseNotesViewer.search_linksc C s� |j dkrdS z| j�� \}}W n tk
r4 Y nX |�� |�� krJdS | �tjjt |j
�t |j��\}}| �||�}|�
� }|D ]$} t| dd�}
|
dkr�t|
� q�q�dS )zcallback for mouse click events� Fr N� )Zbuttonr Zget_selection_bounds�
ValueErrorZ
get_offset�window_to_buffer_coordsr �TextWindowType�WIDGET�int�x�y�get_iter_at_location�get_tags�getattrr )r � text_view�eventr r r/ r0 r&