o >Ic@sddlmZddlmZmZmZddlZddlZddZGdddejZ e dkrDe Z e e d Ze ee edSdS) )Pango)GtkGObjectGdkNcCstjdr d|g}ntjdrd|g}ntjdr!d|g}nd|g}tdkr;d tjvr;d d tjd g|}ntdkrSd tjvrSd d d dtjd 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 SUDO_USERsudoz-u PKEXEC_UIDz-H#N)ospathexistsgetuidenviron subprocessPopen)urlcommandr@/usr/lib/python3/dist-packages/DistUpgrade/ReleaseNotesViewer.pyopen_url!s       rc@sDeZdZddZddZddZddZd d Zd d Zd dZ dS)ReleaseNotesViewercCstj|d|_d|_|dd|d|tdt |_ | |j |j ||d|j|d|j|d|j|dS) zInit the ReleaseNotesViewer as an Inheritance of the Gtk.TextView. Load the notes into the buffer and make links clickableFTeditable monospacezbutton-press-eventzmotion-notify-eventzvisibility-notify-eventN)r__init__hoveringfirst set_propertyset_cursor_visible modify_fontrFontDescriptionr TextBufferbuffer set_bufferset_textconnectbutton_press_eventmotion_notify_eventvisibility_notify_event search_links)selfnotesrrrr6s       zReleaseNotesViewer.__init__cCs0|jjddtjjd}||_|j|||dS)z@Apply the tag that marks links to the specified buffer selectionNblue) foreground underline)r! create_tagr UnderlineSINGLEr apply_tag)r)startendrtagrrrtag_linkKs zReleaseNotesViewer.tag_linkcCs|jd} |dtjjd}|sdS|\}}|} |r,||}|dvr+nnn|}q||}| ||||}q)zlSearch for http URLs in the buffer and call the tag_link method for each one to tag them as linksrzhttp://N) )]  ) r!get_iter_at_offsetforward_searchrTextSearchFlags VISIBLE_ONLYcopy forward_charget_textr5)r)iterret match_start match_end match_tmptextrrrrr(Rs.   zReleaseNotesViewer.search_linksc Cs|jdkrdSz |j\}}Wn tyYn w||kr$dS|tjjt |j t |j \}}| ||}| }|D]} t| dd} | dkrTt| dSqAdS)zcallback for mouse click eventsr6FrN)buttonr!get_selection_bounds ValueError get_offsetwindow_to_buffer_coordsrTextWindowTypeWIDGETintxyget_iter_at_locationget_tagsgetattrr) r) text_vieweventr2r3rRrSrCtagsr4rrrrr%qs*     z%ReleaseNotesViewer.button_press_eventcCsD|tjjt|jt|j\}}||||tjj  dS)z{callback for the mouse movement event, that calls the check_hovering method with the mouse postition coordiantesF) rNrrOrPrQrRrScheck_hovering get_windowTEXT get_pointer)r)rWrXrRrSrrrr&s  z&ReleaseNotesViewer.motion_notify_eventc CsD|tjj}|\}}}}|tjj||\}} ||| dS)zcallback if the widgets gets visible (e.g. moves to the foreground) that calls the check_hovering method with the mouse position coordinatesF)r[rrOr\r]rNrPrZ) r)rWrXwindowscreenwxwymodbxbyrrrr's  z*ReleaseNotesViewer.visibility_notify_eventcCsd}|||}|}|D]}t|dd}|dkrd}nq||jks'|jrTd|_||_|jrB|tjj t j t j jdS|tjj t j t j jdSdS)zRCheck if the mouse is above a tagged link and if yes show a hand cursorFrNrIT)rTrUrVrrr[rrOr\ set_cursorrCursornew CursorTypeHAND2LEFT_PTR)r)rRrS _hoveringrCrYr4rrrrrZs(  z!ReleaseNotesViewer.check_hoveringN) __name__ __module__ __qualname__rr5r(r%r&r'rZrrrrr5s r__main__z"../DistUpgrade/ReleaseAnnouncement) gi.repositoryrrrrr rrTextViewrrlWindowwinopenreadrvaddshow_allmainrrrrs