³ò >ôDFc@s dZdefd„ƒYZdS(sB This module documents a class that monitors the editor's buffer for template triggers. It emits a signal when template triggers are found or activated. @author: Lateef Alabi-Oki @organization: The Scribes Project @copyright: Copyright © 2007 Lateef Alabi-Oki @license: GNU GPLv2 or Later @contact: mystilleef@gmail.com tTemplateMonitorcBsƒeZdZd„Zd„Zd„Zd„Zd„Zd„Zd„Z d„Z d „Z d „Z d „Z d „Zd „ZRS(sœ This class creates an object that monitors the editor's buffer for template triggers. It emits a signal when template triggers are found or activated. cCs¿|i||ƒ|id|iƒ|_|id|iƒ|_|id|iƒ|_|id|iƒ|_ |i id|i ƒ|_ |id|i ƒ|_|id|iƒ|_dS( s6 Initialize object. @param self: Reference to the TemplateMonitor instance. @type self: A TemplateMonitor object. @param manager: Reference to the TemplateManager instance. @type manager: A TemplateManager object. @param editor: Reference to the text editor. @type editor: An Editor object. tdestroysloaded-general-templatessloaded-language-templatess cursor-movedskey-press-eventstrigger-activatedstemplate-destroyedN(t!_TemplateMonitor__init_attributestconnectt_TemplateMonitor__destroy_cbt_TemplateMonitor__signal_id_1t-_TemplateMonitor__loaded_general_templates_cbt_TemplateMonitor__signal_id_2t._TemplateMonitor__loaded_language_templates_cbt_TemplateMonitor__signal_id_3t!_TemplateMonitor__cursor_moved_cbt_TemplateMonitor__signal_id_4ttextviewt$_TemplateMonitor__key_press_event_cbt_TemplateMonitor__signal_id_5t&_TemplateMonitor__trigger_activated_cbt_TemplateMonitor__signal_id_6t'_TemplateMonitor__template_destroyed_cbt_TemplateMonitor__signal_id_7(tselftmanagerteditor((splugins/Templates/Monitor.pyt__init__(s cCs¥||_||_d|_h|_h|_d|_|_|_d|_ d|_ |ii ƒ}|ii i d|tƒ|_|ii i d|tƒ|_dS(sÖ Initialize data attributes. @param self: Reference to the TemplateManager instance. @type self: A TemplateManager object. @param editor: Reference to the text editor. @type editor: An Editor object. iN(t_TemplateMonitor__editort_TemplateMonitor__managertNonet_TemplateMonitor__languaget%_TemplateMonitor__language_dictionaryt$_TemplateMonitor__general_dictionaryRRR R t"_TemplateMonitor__active_templatestget_cursor_positiont textbuffert create_marktTruet_TemplateMonitor__bmarkt_TemplateMonitor__emark(RRRtiterator((splugins/Templates/Monitor.pyt__init_attributes>s       cCs¡ddkl}d|idƒ}d}|io|i|idƒ}n||iiƒ|ƒo|i|Sn)||iiƒ|ƒo|i|SndS(sä Get template associated with word, if possible. @param self: Reference to the TemplateMonitor instance. @type self: A TemplateMonitor object. @param word: A possible template trigger. @type word: A String object. iÿÿÿÿ(tcontainstGeneralt`tN(toperatorR&tlstripRRtkeysRR(RtwordR&tgeneraltlanguage((splugins/Templates/Monitor.pyt__get_templateUs $cCsŸddkl}||i|ƒdƒo'|iid|i|ifƒtSn|iid|i|ifƒ|i |ƒ|iid|i|ifƒtS(sÆ Check if word is a template trigger. @param self: Reference to the TemplateMonitor instance. @type self: A TemplateMonitor object. @param word: A string. @type word: A String object. iÿÿÿÿ(tis_sno-trigger-founds trigger-foundN( R*R1t_TemplateMonitor__get_templateRRtemitR"R#tFalset_TemplateMonitor__mark_position(RR-R1((splugins/Templates/Monitor.pyt__check_triggeris  cCs”|iiƒ}ddkl}||ii|iƒƒ|iiƒ}|iƒ}x$tt|ƒƒD]}|i ƒqfW|ii i ||ƒdS(Niÿÿÿÿ(tremove_trailing_spaces_on_line( RRtutilsR7R tget_linetcopytxrangetlent backward_charRtdelete(RR-R$R7t temp_itert character((splugins/Templates/Monitor.pyt__remove_trigger}s cCsx|iiƒ}|iƒ}|iii|i|ƒx$tt|ƒƒD]}|iƒqGW|iii|i |ƒdS(sÆ Mark position of word in the buffer. @param self: Reference to the TemplateMonitor instance. @type self: A TemplateMonitor object. @param word: A string. @type word: A String object. N( RRR:Rt move_markR#R;R<R=R"(RR-R$t temporaryR@((splugins/Templates/Monitor.pyt__mark_position‡s  cCsÀddkl}l}|iiƒ|iiƒ||i|ƒ||i|ƒ||i|ƒ||i |i ƒ||i |i i ƒ||i |ƒ||i|ƒ||ƒd}~dS(sò Destroy instance of this object. @param self: Reference to the TemplateMonitor instance. @type self: A TemplateMonitor object. @param manager: Reference to the TemplateManager instance. @type manager: A TemplateManager object. iÿÿÿÿ(tdelete_attributestdisconnect_signalN(t SCRIBES.utilsRERFRtclearRRRR R RRR RRR(RRRERF((splugins/Templates/Monitor.pyt __destroy_cb™s    cCs!|iiƒ|ii|ƒdS(s Handles callback when the "loaded-general-templates" signal is emitted. @param self: Reference to the TemplateMonitor instance. @type self: A TemplateMonitor object. @param manager: Reference to the TemplateManager instance. @type manager: A TemplateManager object. @param dictionary: A dictionary containing general templates. @type dictionary: A Dict object. N(RRHtupdate(RRt dictionary((splugins/Templates/Monitor.pyt__loaded_general_templates_cb²s cCsf|iiƒ|ii|ƒd|_ddkl}||iiƒ}|o|i ƒ|_ndS(s Handles callback when the "loaded-language-templates" signal is emitted. @param self: Reference to the TemplateManager instance. @type self: A TemplateManager object. @param dictionary: A dictionary containing language templates. @type dictionary: A Dictionary object. iÿÿÿÿ(t get_languageN( RRHRJRRRGRMRturitget_id(RRRKRMt source_lang((splugins/Templates/Monitor.pyt__loaded_language_templates_cbÄs  c Gs¼ddkl}ddkl}||ii|iiƒƒ}||ƒo'|iid|i |i fƒt Snddk l }l}y||iƒWnnX||i|ƒ|_t S(s¤ Handles callback when the "cursor-moved" signal is emitted. @param self: Reference to the TemplateMonitor instance. @type self: A TemplateMonitor object. iÿÿÿÿ(tnot_(tword_to_cursorsno-trigger-found(tidle_addt source_remove(R*RRR8RSRRRRR3R"R#R4tgobjectRTRUt!_TemplateMonitor__cursor_moved_idt_TemplateMonitor__check_trigger(RtargsRRRSR-RTRU((splugins/Templates/Monitor.pyt__cursor_moved_cb×s c CsTt}ddkl}ddkl}l}l}||i|iƒoÌy˜ddk l }||i i |i i ƒƒ} || ƒo t‚n|i| ƒ} || dƒo t‚nt}|i| ƒ|iid| ƒWq|io|iidƒtSntSqXn||i|iƒo&|io|iidƒtSqPn|S(Niÿÿÿÿ(tkeysyms(teqRRR1(RSstrigger-activatedsnext-placeholdersprevious-placeholder(R4tgtkR[R*R\RRR1tkeyvaltTabR8RSRRRt ExceptionR2RR!t _TemplateMonitor__remove_triggerRR3Rt ISO_Left_Tab( RR teventtresultR[R\RRR1RSR-ttemplate((splugins/Templates/Monitor.pyt__key_press_event_cbìs.     cGs|id7_dS(Ni(R(RRY((splugins/Templates/Monitor.pyt__trigger_activated_cbscGs!y|id8_WnnXdS(Ni(R(RRY((splugins/Templates/Monitor.pyt__template_destroyed_cb s (t__name__t __module__t__doc__RRR2RXRaR5RRRR R RR(((splugins/Templates/Monitor.pyR!s           N(RktobjectR(((splugins/Templates/Monitor.pyss