
    >Ic                     .   d dl mZ d dl mZmZmZ d dlZd dlZd Z G d dej                        Z	e
dk(  r` ej                         Z e	 ed      j                               Zej!                  e       ej#                           ej$                          yy)	    )Pango)GtkGObjectGdkNc                     t         j                  j                  d      rd| g}nLt         j                  j                  d      rd| g}n(t         j                  j                  d      rd| g}nd| g}t        j                         dk(  r,d	t         j                  v rd
dt         j                  d	   g|z   }nFt        j                         dk(  r/dt         j                  v rd
dddt         j                  d   z   g|z   }t        j                  |       y)z#Open the specified URL in a browserz/usr/bin/xdg-openzxdg-openz/usr/bin/exo-openzexo-openz/usr/bin/gnome-openz
gnome-openzx-www-browserr   	SUDO_USERsudoz-u
PKEXEC_UIDz-H#N)ospathexistsgetuidenviron
subprocessPopen)urlcommands     @/usr/lib/python3/dist-packages/DistUpgrade/ReleaseNotesViewer.pyopen_urlr   !   s     
ww~~)*s#	+	,s#	-	.%"C(	yy{aK2::54K!89GC		lbjj84L1135<=W    c                   6    e Zd Zd Zd Zd Zd Zd Zd Zd Z	y)	ReleaseNotesViewerc                 R   t         j                   j                  |        d| _        d| _        | j	                  dd       | j                  d       | j                  t        j                  d             t        j                         | _        | j                  | j                         | j                  j                  |       | j                  d| j                         | j                  d| j                          | j                  d| j"                         | j%                          y)	zInit the ReleaseNotesViewer as an Inheritance of the Gtk.TextView.
           Load the notes into the buffer and make links clickableFTeditable	monospacezbutton-press-eventzmotion-notify-eventzvisibility-notify-eventN)r   __init__hoveringfirstset_propertyset_cursor_visiblemodify_fontr   FontDescriptionr   
TextBufferbuffer
set_bufferset_textconnectbutton_press_eventmotion_notify_eventvisibility_notify_eventsearch_links)selfnotess     r   r   zReleaseNotesViewer.__init__6   s     	  &
*e,&..{;<nn&$U#)4+B+BC*D,D,DE.0L0LMr   c                     | j                   j                  ddt        j                  j                        }||_        | j                   j                  |||       y)z@Apply the tag that marks links to the specified buffer selectionNblue)
foreground	underline)r%   
create_tagr   	UnderlineSINGLEr   	apply_tag)r-   startendr   tags        r   tag_linkzReleaseNotesViewer.tag_linkK   sJ    kk$$Tf/4/E/E % Gc5#.r   c                    | j                   j                  d      }	 |j                  dt        j                  j
                  d      }|sy|\  }}|j                         }	 |j                         r|j                  |      }|dv rnn|j                         }8|j                  |      }| j                  |||       |})zlSearch for http URLs in the buffer and call the tag_link method
           for each one to tag them as linksr   zhttp://N) )]
	)
r%   get_iter_at_offsetforward_searchr   TextSearchFlagsVISIBLE_ONLYcopyforward_charget_textr:   )r-   iterretmatch_start	match_end	match_tmptextr   s           r   r,   zReleaseNotesViewer.search_linksR   s     {{--a0%%i&)&9&9&F&F&*,C '*$[)!(I))+$--i8D::%NN,	  &&y1CMM+y#6D1 r   c                    |j                   dk7  ry	 | j                  j                         \  }}|j                         |j                         k7  ry| j                  t        j                  j                  t        |j                        t        |j                              \  }}| j                  ||      }|j                         }|D ]!  }	t        |	dd      }
|
dk7  st        |
        y y# t        $ r Y w xY w)zcallback for mouse click events   Fr   N )buttonr%   get_selection_bounds
get_offset
ValueErrorwindow_to_buffer_coordsr   TextWindowTypeWIDGETintxyget_iter_at_locationget_tagsgetattrr   )r-   	text_vieweventr7   r8   rY   rZ   rH   tagsr9   r   s              r   r)   z%ReleaseNotesViewer.button_press_eventq   s    <<1	;;;;=LUC !S^^%55 --c.@.@.G.G.1%''lCLJA((A. }} 	C#ud+Cby		  		s   C. .	C:9C:c                 >   |j                  t        j                  j                  t	        |j
                        t	        |j                              \  }}| j                  ||       | j                  t        j                  j                        j                          y)z{callback for the mouse movement event, that calls the
           check_hovering method with the mouse postition coordiantesF)rU   r   rV   rW   rX   rY   rZ   check_hovering
get_windowTEXTget_pointer)r-   r^   r_   rY   rZ   s        r   r*   z&ReleaseNotesViewer.motion_notify_event   sp     001C1C1J1J14UWWs577|M1Aq!**//0<<>r   c                     |j                  t        j                  j                        }|j	                         \  }}}}|j                  t        j                  j                  ||      \  }}	| j                  ||	       y)zcallback if the widgets gets visible (e.g. moves to the foreground)
           that calls the check_hovering method with the mouse position
           coordinatesF)rc   r   rV   rd   re   rU   rW   rb   )
r-   r^   r_   windowscreenwxwymodbxbys
             r   r+   z*ReleaseNotesViewer.visibility_notify_event   sq     %%c&8&8&=&=> & 2 2 4R44%%r2/RB#r   c                    d}| j                  ||      }|j                         }|D ]  }t        |dd      }|dk7  sd} n || j                  k7  s| j                  rd| _        || _        | j                  rn| j                  t        j                  j                        j                  t        j                  j                  t        j                  j                               y| j                  t        j                  j                        j                  t        j                  j                  t        j                  j                               yy)zRCheck if the mouse is above a tagged link and if yes show
           a hand cursorFr   NrP   T)r[   r\   r]   r   r   rc   r   rV   rd   
set_cursorr   Cursornew
CursorTypeHAND2LEFT_PTR)r-   rY   rZ   	_hoveringrH   r`   r9   r   s           r   rb   z!ReleaseNotesViewer.check_hovering   s     	((A. }} 	C#ud+Cby 			 %DJ%DM}} 2 2 7 78CCJJNN3>>#7#78:  2 2 7 78CCJJNN3>>#:#:;= *4r   N)
__name__
__module____qualname__r   r:   r,   r)   r*   r+   rb    r   r   r   r   5   s%    */>6	=r   r   __main__z"../DistUpgrade/ReleaseAnnouncement)gi.repositoryr   r   r   r   r   r   r   TextViewr   rv   Windowwinopenreadrvaddshow_allmainry   r   r   <module>r      s   6   + + 	 (D= D=N z
#**,C	D!EFKKM	NBGGBKLLNCHHJ r   