ó «‡Uc@ssdZddlZejdƒddlZddlZdejfd„ƒYZd„ZedkroeƒndS(søText Widget/Hypertext Usually, tags modify the appearance of text in the view, e.g. making it bold or colored or underlined. But tags are not restricted to appearance. They can also affect the behavior of mouse and key presses, as this demo shows.iÿÿÿÿNs2.0t HypertextDemocBs’eZeZejjejjƒZejjejj ƒZ d d„Z d„Z d„Zd„Zd„Zd„Zd„Zd„Zd„ZRS( cCsLtjj|ƒy|j|jƒƒWn$tk rM|jdd„ƒnX|j|jj ƒ|j ddƒ|j dƒtj ƒ}|j tjƒ|jd|jƒ|jd|jƒ|jd|jƒ|jd|jƒ|jƒ}tjƒ}|jtjtjƒ|j|ƒ|j|ƒ|j|d ƒ|jƒdS( NtdestroycWs tjƒS(N(tgtkt main_quit(tw((s'/usr/lib/pygtk27/2.0/demos/hypertext.pytsiÂiskey-press-events event-aftersmotion-notify-eventsvisibility-notify-eventi(RtWindowt__init__t set_screent get_screentAttributeErrortconnectt set_titlet __class__t__name__tset_default_sizetset_border_widthtTextViewt set_wrap_modet WRAP_WORDtkey_press_eventt event_aftertmotion_notify_eventtvisibility_notify_eventt get_buffertScrolledWindowt set_policytPOLICY_AUTOMATICtaddt show_pagetshow_all(tselftparenttviewtbuffertsw((s'/usr/lib/pygtk27/2.0/demos/hypertext.pyRs*       cCsb|jtjjks*|jtjjkr^|jƒ}|j|jƒƒ}|j||ƒnt S(N( tkeyvalRtkeysymstReturntKP_EnterRtget_iter_at_markt get_inserttfollow_if_linktFalse(Rt text_viewteventR"titer((s'/usr/lib/pygtk27/2.0/demos/hypertext.pyR2s  c CsÔ|jtjjkrtS|jdkr,tS|jƒ}y|jƒ\}}Wntk ranX|j ƒ|j ƒkr~tS|j tj t |j ƒt |jƒƒ\}}|j||ƒ}|j||ƒtS(Ni(ttypeRtgdktBUTTON_RELEASER+tbuttonRtget_selection_boundst ValueErrort get_offsettwindow_to_buffer_coordstTEXT_WINDOW_WIDGETtinttxtytget_iter_at_locationR*( RR,R-R"tstarttendR9R:R.((s'/usr/lib/pygtk27/2.0/demos/hypertext.pyR;s    $c CsÉt}|jƒ}|j||ƒ}|jƒ}x3|D]+}|jdƒ} | dkr7t}Pq7q7W||jkr||_n|jr©|jtj ƒj |j ƒn|jtj ƒj |j ƒdS(Ntpagei( R+RR;tget_tagstget_datatTruethovering_over_linkt get_windowRtTEXT_WINDOW_TEXTt set_cursort hand_cursortregular_cursor( RR,R9R:thoveringR"R.ttagsttagR>((s'/usr/lib/pygtk27/2.0/demos/hypertext.pytset_cursor_if_appropriateWs      cCsT|jtjt|jƒt|jƒƒ\}}|j|||ƒ|jjƒt S(N( R6RR7R8R9R:RKtwindowt get_pointerR+(RR,R-R9R:((s'/usr/lib/pygtk27/2.0/demos/hypertext.pyRms  $ cCsM|jjƒ\}}}|jtj||ƒ\}}|j|||ƒtS(N(RLRMR6RR7RKR+(RR,R-twxtwytmodtbxtby((s'/usr/lib/pygtk27/2.0/demos/hypertext.pyRvscCsE|jddddtjƒ}|jd|ƒ|j|||ƒdS(sû Inserts a piece of text into the buffer, giving it the usual appearance of a hyperlink in a web browser: blue and underlined. Additionally, attaches some data on the tag, to make it recognizable as a link. t foregroundtbluet underlineR>N(t create_tagtNonetpangotUNDERLINE_SINGLEtset_datatinsert_with_tags(RR"R.ttextR>RJ((s'/usr/lib/pygtk27/2.0/demos/hypertext.pyt insert_link}s cCs&|jddƒ|jdƒ}|dkrŠ|j|dƒ|j||ddƒ|j|dƒ|j||dd ƒ|j|d ƒn˜|d krÂ|j|d d ƒ|j||d dƒn`|dkr"|jddtjƒ}|j|d|ƒ|j|dƒ|j||d dƒndS(s™ Fills the buffer with text and interspersed links. In any real hypertext app, this method would parse a file to identify the links. tiisSome text to show that simple t hypertextis can easily be realized with RIit.swA tag is an attribute that can be applied to some range of text. For example, a tag might be called "bold" and make the text inside the tag bold. However, the tag concept is more general than that tags don't have to affect appearance. They can instead affect the behavior of mouse and key presses, "lock" a range of text so the user can't edit it, or countless other things. iÿÿÿÿsGo backtweights hypertext: srmachine-readable text that is not sequential but is organized so that related items of information are connected. N( tset_texttget_iter_at_offsettinsertR]RVRWRXt WEIGHT_BOLDR[(RR"R>R.RJ((s'/usr/lib/pygtk27/2.0/demos/hypertext.pyR‰s&     cCsV|jƒ}xC|D];}|jdƒ}|dkr|j|jƒ|ƒPqqWdS(sÆ Looks at all tags covering the position of iter in the text view, and if one of them is a link, follow it by showing the page identified by the data attached to it. R>iN(R?R@RR(RR,R.RIRJR>((s'/usr/lib/pygtk27/2.0/demos/hypertext.pyR*¨s    N(Rt __module__R+RBRR0tCursortHAND2RFtXTERMRGRWRRRRKRRR]RR*(((s'/usr/lib/pygtk27/2.0/demos/hypertext.pyRs     cCstƒtjƒdS(N(RRtmain(((s'/usr/lib/pygtk27/2.0/demos/hypertext.pyRjµst__main__( t__doc__tpygtktrequireRRXRRRjR(((s'/usr/lib/pygtk27/2.0/demos/hypertext.pyts    ¦