łň ƒr]Fc@s dZdefd„ƒYZdS(s„ This module documents a class that highlights regions within pair bracket characters. Characters currently affected are "(", ")", "[", "]" "<", ">", "{" and "}". More pair characters will be added if the need arises. @author: Lateef Alabi-Oki @organization: The Scribes Project @copyright: Copyright Š 2007 Lateef Alabi-Oki @license: GNU GPLv2 or Later @contact: mystilleef@gmail.com t HighlightercBsžeZdZd„Zd„Zd„Zd„Zd„Zd„Zd„Z d„Z d „Z d „Z d „Z d „Zd „Zd„Zd„Zd„ZRS(sĽ The class implements and object that highlights regions within pair characters. The following characters are supported "(", ")", "[", "]" "<", ">", "{" and "}" cCs|i|ƒddkl}l}||id|ƒ|id|iƒ|_|iid|i ƒ|_ |iid|i ƒ|_ |id|i ƒ|_|id|iƒ|_|id |i ƒ|_|id |iƒ|_|id |iƒ|_|iid |iƒd S(sĹ Initialize object. @param self: Reference to the Highlighter instance. @type self: A Highlighter object. @param editor: Reference to the text editor. @type editor: An Editor object. i˙˙˙˙(tidle_addt PRIORITY_LOWtprioritys cursor-moveds apply-tags remove-tagsloading-documentsloaded-documentsenable-readonlysdisable-readonlys load-errors#/apps/scribes/scope_highlight_colorN(t_Highlighter__init_attributestgobjectRRt_Highlighter__compile_methodtconnectt_Highlighter__cursor_moved_cbt_Highlighter__signal_id_1t textbuffert_Highlighter__apply_tag_cbt_Highlighter__signal_id_2t_Highlighter__remove_tag_cbt_Highlighter__signal_id_3t&_Highlighter__generic_highlight_off_cbt_Highlighter__signal_id_4t%_Highlighter__generic_highlight_on_cbt_Highlighter__signal_id_5t_Highlighter__signal_id_6t_Highlighter__signal_id_7t_Highlighter__signal_id_8t_Highlighter__clientt notify_addt_Highlighter__highlight_cb(tselfteditorRR((s*plugins/LexicalScopeHighlight/Highlight.pyt__init__*s cCsŽ||_|i|_t|_t|_|iƒ|_ddk l }||_ d |_ d |_d |_d |_d |_|_|_d S(sÎ Initialize data attributes. @param self: Reference to the Highlighter instance. @type self: A Highlighter object. @param editor: Reference to the text editor. @type editor: An Editor object. i˙˙˙˙(t!source_iter_find_matching_brackett(t[tt}N(RRRR (R!R"R#R$(t_Highlighter__editort gconf_clientRtTruet_Highlighter__can_highlighttFalset_Highlighter__buffer_is_taggedt"_Highlighter__create_highlight_tagt_Highlighter__highlight_tagt gtksourceviewRt_Highlighter__matchtNonet_Highlighter__start_markt_Highlighter__end_markt_Highlighter__start_characterst_Highlighter__end_charactersR R R(RRR((s*plugins/LexicalScopeHighlight/Highlight.pyt__init_attributesAs         cCs|iƒdS(s€ Destroy instance of this class. @param self: Reference to the Highlighter instance. @type self: A Highlighter object. N(t_Highlighter__destroy(R((s*plugins/LexicalScopeHighlight/Highlight.pytdestroy_s c Csř|ii}ddkl}l}||iƒo>|i|iƒ}|i|iƒ}|i |i ||ƒn|i|i ƒƒ}||i |ƒƒot Sn|i|i ƒƒ}y2|i||ƒ\}}|i|i ||ƒWnnXt S(sŠ Highlight region between pair characters. @param self: Reference to the Highlighter instance. @type self: A Highlighter object. i˙˙˙˙(tnot_ttruth(R%R toperatorR7R8R*tget_iter_at_markR0R1t remove_tagR,t get_insertR.R)t_Highlighter__get_boundaryt apply_tag( RR R7R8tbegintendtiteratort cursor_itertstart((s*plugins/LexicalScopeHighlight/Highlight.pyt__highlight_regionos cCsddkl}||i|iƒƒƒo|iƒ||fSn||i|iƒƒƒot|iƒ||i|iƒƒƒo<|i|ƒ|ii }|i |i ƒƒ}||fSn|iƒdSn|iƒ||i|iƒƒƒodSn|iƒ||fS(sş Return the region of pair characters. @param self: Reference to the Highlighter instance. @type self: A Highlighter object. @param citerator: The position of the cursor. @type citerator: A gtk.TextIter object. @param iterator: The position of a matching bracket. @type iterator: A gtk.TextIter object. @return: A pair of iterators representing the position of matching brackets or nothing. @rtype: A Tuple object. i˙˙˙˙(R8N( R9R8t _Highlighter__is_start_charactertget_chart forward_chart_Highlighter__is_end_charactert backward_charR.R%R R:R<R/(Rt citeratorRAR8R RB((s*plugins/LexicalScopeHighlight/Highlight.pyt__get_boundary†s"      $ cCs||ijotSntS(sE Whether or not character is an openning pair character. @param self: Reference to the Highlighter instance. @type self: A Highlighter object. @param character: A character in the buffer. @type character: A String object. @return: True if character is an openning pair character. @rtype: A Boolean object. (R2R'R)(Rt character((s*plugins/LexicalScopeHighlight/Highlight.pyt__is_start_characterŤs cCs||ijotSntS(sA Whether or not character is a closing pair character. @param self: Reference to the Highlighter instance. @type self: A Highlighter object. @param character: A character in the buffer. @type character: A String object. @return: True if character is a closing pair character. @rtype: A Boolean object. (R3R'R)(RRL((s*plugins/LexicalScopeHighlight/Highlight.pyt__is_end_characterťs cCsxddkl}|dƒ}d}|iidƒo|iidƒ}n|iiiƒi|ƒ|i d|ƒ|S(sÔ Create the a highlight tag. @param self: Reference to the LexicalScopeHighlight instance. @type self: A LexicalScopeHighlight object. @return: A region highlight tag. @rtype: A gtk.TextTag object. i˙˙˙˙(tTextTagtlexical_scope_tags#cfcfcfs#/apps/scribes/scope_highlight_colort background( tgtkRORtgett get_stringR%R t get_tag_tabletaddt set_property(RROttagtcolor((s*plugins/LexicalScopeHighlight/Highlight.pyt__create_highlight_tagËs  cCs|iiiƒi|iƒddkl}l}||i|iƒ||i |iiƒ||i |iiƒ||i |iƒ||i |iƒ||i |iƒ||i|iƒ||i|iƒddkl}||iƒo4||iiƒƒo|iii|iƒq$n||iƒo4||iiƒƒo|iii|iƒqhn||ƒd}~dS(s Destroy instance of this object. @param self: Reference to the Highlighter instance. @type self: A Highlighter object. i˙˙˙˙(tdelete_attributestdisconnect_signal(R8N(R%R RUtremoveR,t SCRIBES.utilsR[R\R R RRRRRRR9R8R0t get_deletedt delete_markR1R/(RR[R\R8((s*plugins/LexicalScopeHighlight/Highlight.pyt __destroyŢs* cCs<y.ddkl}||iƒ||iƒWnnXtS(sŔ Use psyco, the Python performance optimization compiler, to compile a method for performance. @param self: Reference to the Highlighter instance. @type self: A Highlighter object. i˙˙˙˙(tbind(tpsycoRbt_Highlighter__highlight_regionR=R)(RRb((s*plugins/LexicalScopeHighlight/Highlight.pyt__compile_methodűs cCsoddkl}||iƒodSnddkl}l}y||iƒWnnX||iƒ|_dS(sî Handles callback when the "cursor-moved" signal is emitted. @param self: Reference to the Highlighter instance. @type self: A Highlighter object. @param editor: Reference to the text editor. @type editor: An Editor object. i˙˙˙˙(R7N(Rt source_remove(R9R7R(RRRft_Highlighter__cursor_moved_idRd(RRR7RRf((s*plugins/LexicalScopeHighlight/Highlight.pyt__cursor_moved_cbs cCsÎddkl}l}|||iƒotSn|ii}||idƒo|i d|t ƒ|_n||i dƒo|i d|tƒ|_ n|i |i|ƒ|i |i |ƒt |_ t S(se Handles callback when the "apply-tag" signal is emitted. @param self: Reference to the ScribesTextBuffer instance. @type self: A ScribesTextBuffer object. @param textbuffer: The text editor's buffer. @type textbuffer: A ScribesTextBuffer object. @param tag: A tag in the text editor's buffer. @type tag: A gtk.TextTag object. @param start: The position of the begining of the tag. @type start: A gtk.TextIter object. @param end: The position of the end of the tag. @type end: A gtk.TextIter object. @return: True to propagate signals to parent widgets. @type: A Boolean Object. i˙˙˙˙(tnetis_N(R9RiRjR,R)R%R R0R/t create_markR'R1t move_markR*(RR RXRCR@RiRj((s*plugins/LexicalScopeHighlight/Highlight.pyt__apply_tag_cb%s  cCs8ddkl}|||iƒotSnt|_tS(sf Handles callback when the "remove-tag" signal is emitted. @param self: Reference to the ScribesTextBuffer instance. @type self: A ScribesTextBuffer object. @param textbuffer: The text editor's buffer. @type textbuffer: A ScribesTextBuffer object. @param tag: A tag in the text editor's buffer. @type tag: A gtk.TextTag object. @param start: The position of the begining of the tag. @type start: A gtk.TextIter object. @param end: The position of the end of the tag. @type end: A gtk.TextIter object. @return: True to propagate signals to parent widgets. @type: A Boolean Object. i˙˙˙˙(Ri(R9RiR,R)R*R'(RR RXRCR@Ri((s*plugins/LexicalScopeHighlight/Highlight.pyt__remove_tag_cbGs cGsAt|_|iiiƒ\}}|iii|i||ƒdS(sŐ A generic callback to disable scope highlights. @param self: Reference to the Highlighter instance. @type self: A Highlighter object. @param *args: Irrelevant arguments. @type *args: A List object. N(R)R(R%R t get_boundsR;R,(RtargsR?R@((s*plugins/LexicalScopeHighlight/Highlight.pyt__generic_highlight_off_cbbs cGsPt|_ddkl}l}y||iƒWnnX||iƒ|_dS(sÔ A generic callback to enable scope highlights. @param self: Reference to the Highlighter instance. @type self: A Highlighter object. @param *args: Irrelevant arguments. @type *args: A List object. i˙˙˙˙(RRfN(R'R(RRRft_Highlighter__generic_idRd(RRpRRf((s*plugins/LexicalScopeHighlight/Highlight.pyt__generic_highlight_on_cbqs c Cs |ii}|iƒ\}}|i|i||ƒ|iidƒ}|iid|ƒddkl } l } y| |i ƒWnnX| |i ƒ|_ dS(sü Handles callback #FIXME: yeap @param self: Reference to the LexicalScopeHighlight instance. @type self: A LexicalScopeHighlight object. @param client: A client used to query the GConf daemon and database @type client: A gconf.Client object. @param cnxn_id: The identification number for the GConf client. @type cnxn_id: An Integer object. @param entry: An entry from the GConf database. @type entry: A gconf.Entry object. @param data: Optional data @type data: Any type object. s#/apps/scribes/scope_highlight_colorRQi˙˙˙˙(RRfN( R%R RoR;R,RRTRWRRRft_Highlighter__highlight_idRd( Rtclienttcnxn_idtentrytdataR R?R@RYRRf((s*plugins/LexicalScopeHighlight/Highlight.pyt__highlight_cbŠs (t__name__t __module__t__doc__RRR6RdR=RERHR+R5RRR R RRR(((s*plugins/LexicalScopeHighlight/Highlight.pyR#s"     %       "   N(R|tobjectR(((s*plugins/LexicalScopeHighlight/Highlight.pys!s