łň Cn]Fc@s dZdefd„ƒYZdS(s  This module documents a class that performs bracket completion operations for the text editor. @author: Lateef Alabi-Oki @organization: The Scribes Project @copyright: Copyright Š 2007 Lateef Alabi-Oki @license: GNU GPLv2 or Later @contact: mystilleef@gmail.com tBracketManagercBsÝeZdZd„Zd„Zd„Zd„Zd„Zd„Zd„Z d„Z d „Z d „Z d „Z d „Zd „Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„ZRS(sŹ This class implements bracket completion operations for the text editor. Closing characters for most pair characters are automatically inserted into the editing area. cCsŞ|i|ƒddkl}l}||id|ƒ|iƒ|iid|iƒ|_ |id|i ƒ|_ |id|i ƒ|_ |iid|iƒ|_dS(sË Initialize object. @param self: Reference to the BracketManager instance. @type self: A BracketManager object. @param editor: Reference to the text editor. @type editor: An Editor object. i˙˙˙˙(tidle_addt PRIORITY_LOWtpriorityskey-press-events cursor-movedsloaded-documentN(t _BracketManager__init_attributestgobjectRRt _BracketManager__compile_methodst_BracketManager__check_mimetypettextviewtconnectt#_BracketManager__key_press_event_cbt_BracketManager__signal_id_1t _BracketManager__cursor_moved_cbt_BracketManager__signal_id_2t#_BracketManager__loaded_document_cbt_BracketManager__signal_id_3t connect_aftert)_BracketManager__key_press_event_after_cbt_BracketManager__signal_id_4(tselfteditorRR((s$plugins/BracketCompletion/Manager.pyt__init__'s  cCsí||_ddkl}||_g|_d|_ddkl}|i|i |i |i |i |i |i|i|i|i|i|i|i|i|i|ig|_|i|i|ig|_d|_|_|_d|_dS(sÔ Initialize data attributes. @param self: Reference to the BracketManager instance. @type self: A BracketManager object. @param editor: Reference to the text editor. @type editor: An Editor object. i˙˙˙˙(t!source_iter_find_matching_brackets\(tkeysymsN( t_BracketManager__editort gtksourceviewRt_BracketManager__matcht_BracketManager__monitor_listt!_BracketManager__escape_charactertgtkRtquotedblt braceleftt bracketleftt parenlefttleftdoublequotemarkt guillemotlefttguillemotrighttleftsinglequotemarktleftmiddlecurlybracet lowleftcornert topleftparensttopleftsqbrackett upleftcornert botleftparenstbotleftsqbrackett apostrophet%_BracketManager__open_pair_characterstlesst5_BracketManager__open_pair_characters_for_enclosementtNoneR R RR(RRRR((s$plugins/BracketCompletion/Manager.pyt__init_attributes:s&            cCs|iƒdS(s† Destroy instance of this class. @param self: Reference to the BracketManager instance. @type self: A BracketManager object. N(t_BracketManager__destroy(R((s$plugins/BracketCompletion/Manager.pytdestroy^s cCs?ddkl}l}ddkl}|||iƒo|i||iƒně|||iƒo|i||iƒnÂ|||i ƒo|i||i ƒn˜|||i ƒo|i||i ƒnn|||i ƒo|i||iƒnD|||iƒo|i||iƒn|||iƒo|i||iƒnđ|||iƒo|i||iƒnĆ|||iƒo|i||iƒnœ|||iƒo|i||iƒnr|||iƒo|i||iƒnH|||iƒo|i||iƒn|||iƒo|i||iƒnô|||iƒo|i||iƒnĘ|||iƒo|i||i ƒn |||i!ƒo|i||i"ƒnv|||i#ƒo|i||i#ƒnL|||i$ƒo8||i%ƒƒo|i||i$ƒq;|i&ƒndS(s Insert closing pair characters into the text editor's buffer. @param self: Reference to the BracketManager instance. @type self: A BracketManager object. @param keyval: A value representing a keyboard symbol @type keyval: An Integer object. i˙˙˙˙(teqttruth(RN('toperatorR5R6RRRt'_BracketManager__insert_pair_charactersRt bracerightR t bracketrightR!t parenrightR"trighdoublequotemarkR#R$R%trightsinglequotemarkR&trightmiddlecurlybraceR'tlowrightcornerR(ttoprightparensR)ttoprightsqbracketR*t uprightcornerR+tbotrightparensR,tbotrightsqbracketR/tgreatertdollarR-t&_BracketManager__can_insert_apostrophet"_BracketManager__insert_apostrophe(RtkeyvalR5R6R((s$plugins/BracketCompletion/Manager.pyt__insert_closing_pair_characternsR c Cs6|ii}ddkl}t||ƒƒidƒ}t||ƒƒidƒ}ddkl}||ƒ}|id|t ƒ} |i ƒ|i ||ƒ|i ƒddkl}||ƒ}|id|tƒ} |iƒ|i|ƒ|ii|| | ffƒddkl} |iii| dƒdS(su Insert pair characters into the text editor's buffer. @param self: Reference to the BracketManager instance. @type self: A BracketManager object. @param open_keyval: A value representing the openning character. @type open_keyval: An Integer object. @param close_keyval: A value representing the closing character. @type close_keyval: An Integer object. i˙˙˙˙(tkeyval_to_unicodesutf-8(tget_cursor_iterator(tmsg0001tsucceedN(Rt textbuffertgtk.gdkRKtunichrtencodetSCRIBES.cursorRLt create_markR1tTruetbegin_user_actiontinsert_at_cursortend_user_actiontFalset backward_chart place_cursorRtappendti18nRMtfeedbacktupdate_status_message( Rt open_keyvalt close_keyvalRORKtutf8_open_charactertutf8_closing_characterRLtcursor_positiont begin_marktend_markRM((s$plugins/BracketCompletion/Manager.pyt__insert_pair_charactersŁs&       cCsNddkl}ddkl}|||iƒo|i|i|iƒnţ|||iƒo|i|i|iƒnŃ|||iƒo|i|i|i ƒn¤|||i ƒo|i|i |i ƒnw|||i ƒo|i|i |i ƒnJ|||iƒo|i|i|iƒn|||iƒo|i|i|iƒnđ|||iƒo|i|i|iƒnĂ|||iƒo|i|i|iƒn–|||iƒo|i|i|iƒni|||iƒo|i|i|iƒn<|||iƒo|i|i|iƒn|||iƒo|i|i|iƒnâ|||iƒo|i|i|iƒnľ|||iƒo|i|i|iƒnˆ|||i ƒo|i|i |i!ƒn[|||i"ƒo|i|i"|i"ƒn.|||i#ƒo|i|i#|i#ƒndS(sŕ Enclose selection in pair characters. @param self: Reference to the BracketManager instance. @type self: A BracketManager object. @param keyval: The value of a pair character. @type keyval: An Integer object. i˙˙˙˙(R(R5N($RRR7R5Rt*_BracketManager__insert_enclosed_selectionRR9R R:R!R;R"trightdoublequotemarkR#R$R%R=R&R>R'R?R(R@R)RAR*RBR+RCR,RDR/RERFR-(RRIRR5((s$plugins/BracketCompletion/Manager.pyt__enclose_selectionÄsN c Csé|ii}ddkl}t||ƒƒidƒ}t||ƒƒidƒ}|iƒ}|i|d|dƒ}|||} |iƒ|i |d|dƒ|i | ƒ|i ƒddk l } |iii| dƒdS( sp Enclose selected text in pair characters. @param self: Reference to the BracketManager instance. @type self: A BracketManager object. @param open_keyval: An integer representing an open pair character. @type open_keyval: An Integer object. @param close_keyval: An integer representing a close pair character. @type close_keyval: An Integer object. i˙˙˙˙(RKsutf-8ii(tmsg0002RNN(RRORPRKRQRRtget_selection_boundstget_textRVtdeleteRWRXR]RkR^R_( RR`RaRORKRbRct selectiontstringttextRk((s$plugins/BracketCompletion/Manager.pyt__insert_enclosed_selectionös     cCsa|ii}|iddd}|i|ƒ}|i|ƒddkl}||iiƒdS(s Move cursor after closing pair character. @param self: Reference to the BracketManager instance. @type self: A BracketManager object. i˙˙˙˙i(tmove_view_to_cursorN(RRORtget_iter_at_markR[RSRsR(RRORftiteratorRs((s$plugins/BracketCompletion/Manager.pyt#__move_cursor_out_of_bracket_regions  cCsœ|iddd}|iddd}ddkl}||iƒƒo|iii|ƒn||iƒƒo|iii|ƒn|id=dS(sĄ Stop monitoring the most recently inserted bracket region. @param self: Reference to the BracketManager instance. @type self: A BracketManager object. i˙˙˙˙ii(tnot_N(RR7Rwt get_deletedRROt delete_mark(RReRfRw((s$plugins/BracketCompletion/Manager.pyt__stop_monitoring!s c CsJddkl}|ii}|iddd}|iddd}|i|ƒ}|i|ƒ}|t|i||ƒƒdƒotSn|i ƒddk l }|idd}t ||ƒƒi dƒ} ||iƒ| ƒotSn|iƒ|iƒ|i||ƒ|iƒddkl} |iii| d ƒtS( sí Remove closing pair character if it was automatically entered. @param self: Reference to the BracketManager instance. @type self: A BracketManager object. @return: True to handle keyboard events. @rtype: A Boolean object. i˙˙˙˙(tneiii(RKsutf-8(tmsg0003RN(R7R{RRORRttlenRmRYt forward_charRPRKRQRRtget_charRZRVRnRXR]R|R^R_RU( RR{ROReRftbegintendRKRat characterR|((s$plugins/BracketCompletion/Manager.pyt__remove_closing_pair_character2s&  *    cCsZ|iiƒ}|iƒ}|iƒddkl}||iƒ|iƒotSnt S(s Check for escape character before single or double quote character. @param self: Reference to the BracketManager instance. @type self: A BracketManager object. @return: True if there's an escape character before single or double quote character. @rtype: A Boolean object. i˙˙˙˙(R5( Rtget_cursor_positiontcopyRZR7R5RRRURY(Rt end_iteratortstart_iteratorR5((s$plugins/BracketCompletion/Manager.pyt__has_escape_characterPs   !cCs?|iiƒ}|iƒ}|iƒ|iii||ƒdS(s Remove escape character. @param self: Reference to the BracketManager instance. @type self: A BracketManager object. N(RR„R…RZRORn(RR†R‡((s$plugins/BracketCompletion/Manager.pyt__remove_escape_characteras   cCs‚ddkl}||iiƒ}ddkl}||iƒƒotSn|iƒ|i ƒ}||i ƒƒot SntS(s~ Check whether or not a closing apostrophe can be automatically inserted into the text editor's buffer. Automatic completion will not be performed for apostrophes following an alphabet. @param self: Reference to the BracketManager instance. @type self: A BracketManager object. @return: True to insert automatically insert apostrophe. @rtype: A Boolean object. i˙˙˙˙(RL(R6( RSRLRROR7R6t starts_lineRURZRtisalphaRY(RRLRuR6R‚((s$plugins/BracketCompletion/Manager.pyt__can_insert_apostrophens  cCsUddkl}ddkl}t||iƒƒidƒ}|iii |ƒdS(s’ Insert a single apostrophe into the buffer. @param self: Reference to the BracketManager instance. @type self: A BracketManager object. i˙˙˙˙(R(RKsutf-8N( RRRPRKRQR-RRRRORW(RRRKtutf8_apostrophe_character((s$plugins/BracketCompletion/Manager.pyt__insert_apostrophe…s c Csëddkl}l}l}ddkl}ddkl}ddddg}||ii ƒod Sny||ii ƒ}Wnt j o d SnX||d ƒo|i i |i ƒn(|||ƒo|i i |iƒnd S( sÔ Check the mimetype of the file and modify completion behavior for LaTeX and markup source code if possible. @param self: Reference to the BracketManager instance. @type self: A BracketManager object. i˙˙˙˙(R5tcontainsRw(t get_mime_type(Rs text/htmlsapplication/xmlstext/xmlsapplication/docbook+xmlNs text/x-tex(R7R5RRwtgnomevfsRRRRturit RuntimeErrorR.R\RFR/(RR5RRwRRtmarkup_mimetypetmimetype((s$plugins/BracketCompletion/Manager.pyt__check_mimetype’s cCs˝yŁddkl}||iƒ||iƒ||iƒ||iƒ||iƒ||iƒ||iƒ||i ƒ||i ƒ||i ƒ||i ƒWnt j onXtS(s˝ Use psyco, the Python performance optimizing compiler to precompile certain methods. @param self: Reference to the BracketManager instance. @type self: A BracketManager object. i˙˙˙˙(tbind(tpsycoR—R8t._BracketManager__insert_closing_pair_characterRhRHt"_BracketManager__enclose_selectionRt._BracketManager__remove_closing_pair_charactert _BracketManager__stop_monitoringt2_BracketManager__move_cursor_out_of_bracket_regionRGt(_BracketManager__monitor_pair_characterst ImportErrorRY(RR—((s$plugins/BracketCompletion/Manager.pyt__compile_methodsŠs           cCsddkl}l}||i|iiƒ||i|iƒ||i|iƒ||i|iiƒ||ƒd}~dS(s† Destroy instance of this class. @param self: Reference to the BracketManager instance. @type self: A BracketManager object. i˙˙˙˙(tdelete_attributestdisconnect_signalN( t SCRIBES.utilsRĄR˘R RRR RRR1(RRĄR˘((s$plugins/BracketCompletion/Manager.pyt __destroyÂs c Cs™ddkl}l}l}|iiiƒ}||ƒo.||i|iƒo|i |iƒt Sn||i ƒoîddk l }||i|iƒo|iƒ}|Sn||i|iƒo|iƒt Sn||i dd|iƒoj||i|if|iƒo9||iƒƒo"|iƒ|i|iƒt SqQn|iƒt Sqgn||i|iƒo|i|iƒt SntS(s Handles callback when "key-press-event" signal is emitted. This function monitors the editing area for pair character insertions. @param self: Reference to the BracketManager instance. @type self: A BracketManager object. @param textview: The text editor's buffer container. @type textview: A ScribesTextView object. @param event: An event that occurs when keys on the keyboard are pressed. @type event: A gtk.Event object. @return: True to propagate signals to parent widgets. @type: A Boolean Object. i˙˙˙˙(R6R5R(Ri(R7R6R5RRRORlR0RIRšRURRRt BackSpaceR›tEscapeRRR-t%_BracketManager__has_escape_charactert(_BracketManager__remove_escape_characterR™R.RY( RRteventR6R5RRoRtresult((s$plugins/BracketCompletion/Manager.pyt__key_press_event_cbŮs2#      cGs!ddkl}||iƒtS(Ni˙˙˙˙(R(RRt_BracketManager__responseRY(RtargsR((s$plugins/BracketCompletion/Manager.pyt__key_press_event_after_cbs cCs|iiƒtS(N(RtresponseRY(R((s$plugins/BracketCompletion/Manager.pyt __response s cCs!ddkl}||iƒdS(sô Handles callback when the "cursor-moved" signal is emitted. @param self: Reference to the BracketManager instance. @type self: A BracketManager object. @param editor: Reference to the text editor. @type editor: An Editor object. i˙˙˙˙(RN(RRRž(RRR((s$plugins/BracketCompletion/Manager.pyt__cursor_moved_cbs  c Csddkl}l}||iƒotSn|ii}|iddd}|iddd}|i|ƒ}|i|ƒ}ddkl }||ƒ} || i |ƒƒp|| i |ƒƒo|i ƒn(|| i ||ƒƒo|i ƒntS(Ni˙˙˙˙(RwR6ii(RL( R7RwR6RRYRRORtRSRLtequalRœtin_range( RRwR6ROReRfR€RRLRd((s$plugins/BracketCompletion/Manager.pyt__monitor_pair_characterss  ,cCs|iƒdS(s÷ Handles callback when the "loaded-document" signal is emitted. @param self: Reference to the BracketManager instance. @type self: A BracketManager object. @param editor: Reference to the text editor. @type editor: An Editor object. N(R(RRR’((s$plugins/BracketCompletion/Manager.pyt__loaded_document_cb/s (t__name__t __module__t__doc__RRR4R™R8RšRhRRœR›R§R¨RGRHRRR3R RRŹR RžR(((s$plugins/BracketCompletion/Manager.pyR s0  $  5 ! 2          /    N(R¸tobjectR(((s$plugins/BracketCompletion/Manager.pyss