î ›rËZéã@sÁddlmZddlmZmZmZddlZddlZdd„ZGdd„dejƒZ e dkr½ej ƒZ e e d ƒjƒƒZe jeƒe jƒejƒndS) é)ÚPango)ÚGtkÚGObjectÚGdkNcCstjjdƒr!d|g}nNtjjdƒrBd|g}n-tjjdƒrcd|g}n d|g}tjƒdkr­d tjkr­d d tjd g|}nEtjƒdkròd tjkròd d d dtjd g|}ntj|ƒ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-browserrZ 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 !! rc@sdeZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dS)ÚReleaseNotesViewercCsËtjj|ƒd|_d|_|jddƒ|jdƒ|jtjdƒƒt j ƒ|_ |j |j ƒ|j j |ƒ|jd|jƒ|jd|jƒ|jd|jƒ|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ÚfirstZ set_propertyZset_cursor_visibleZ modify_fontrZFontDescriptionrZ TextBufferÚbufferZ set_bufferZset_textZconnectÚbutton_press_eventÚmotion_notify_eventÚvisibility_notify_eventÚ search_links)ÚselfZnotesrrrr6s   zReleaseNotesViewer.__init__cCsG|jjddddtjjƒ}||_|jj|||ƒdS)z@Apply the tag that marks links to the specified buffer selectionNZ foregroundZblueZ underline)rZ create_tagrZ UnderlineZSINGLErZ apply_tag)rÚstartÚendrÚtagrrrÚtag_linkKs zReleaseNotesViewer.tag_linkcCsÄ|jjdƒ}x«|jdtjjdƒ}|s:Pn|\}}|jƒ}x?|jƒrƒ|j|ƒ}|d kr„Pq„nP|jƒ}qUW|j|ƒ}|j |||ƒ|}qWdS) zlSearch for http URLs in the buffer and call the tag_link method for each one to tag them as linksrzhttp://Nú ú)ú]Ú ú )r r!r"r#r$) rZget_iter_at_offsetZforward_searchrZTextSearchFlagsZ VISIBLE_ONLYÚcopyZ forward_charZget_textr)rÚiterZretZ match_startZ match_endZ match_tmpÚtextrrrrrRs&       zReleaseNotesViewer.search_linksc Csï|jdkrdSy|jjƒ\}}Wntk r@YnX|jƒ|jƒkr]dS|jtjjt |j ƒt |j ƒƒ\}}|j ||ƒ}|j ƒ}x:|D]2} t| ddƒ} | dkrµt| ƒPqµqµWdS)zcallback for mouse click eventséFrNÚ)ZbuttonrZget_selection_boundsÚ ValueErrorZ get_offsetÚwindow_to_buffer_coordsrÚTextWindowTypeÚWIDGETÚintÚxÚyÚget_iter_at_locationÚget_tagsÚgetattrr) rÚ text_viewÚeventrrr/r0r&Útagsrrrrrrqs" $    z%ReleaseNotesViewer.button_press_eventcCs`|jtjjt|jƒt|jƒƒ\}}|j||ƒ|jtjj ƒj ƒdS)z{callback for the mouse movement event, that calls the check_hovering method with the mouse postition coordiantesF) r+rr,r-r.r/r0Úcheck_hoveringÚ get_windowÚTEXTÚ get_pointer)rr4r5r/r0rrrrŒs $z&ReleaseNotesViewer.motion_notify_eventc Csb|jtjjƒ}|jƒ\}}}}|jtjj||ƒ\}} |j|| ƒdS)z¢callback if the widgets gets visible (e.g. moves to the foreground) that calls the check_hovering method with the mouse position coordinatesF)r8rr,r9r:r+r-r7) rr4r5ZwindowZscreenZwxZwyÚmodZbxZbyrrrr•s z*ReleaseNotesViewer.visibility_notify_eventcCsöd}|j||ƒ}|jƒ}x6|D].}t|ddƒ}|dkr+d}Pq+q+W||jksu|jròd|_||_|jrÁ|jtjjƒj t j j t j jƒƒqò|jtjjƒj t j j t j jƒƒndS)zRCheck if the mouse is above a tagged link and if yes show a hand cursorFrNr)T)r1r2r3rrr8rr,r9Z set_cursorrZCursorÚnewZ CursorTypeZHAND2ZLEFT_PTR)rr/r0Z _hoveringr&r6rrrrrr7 s       z!ReleaseNotesViewer.check_hoveringN) Ú__name__Ú __module__Ú __qualname__rrrrrrr7rrrrr5s      rÚ__main__z"../DistUpgrade/ReleaseAnnouncement)Z gi.repositoryrrrrrr rZTextViewrr=ZWindowÚwinÚopenÚreadÚrvÚaddZshow_allÚmainrrrrÚs   †