\Ec@s dZdefdYZdS(s This module documents a class that defines the behavior of the template editor's language treeview. @author: Lateef Alabi-Oki @organization: The Scribes Project @copyright: Copyright © 2007 Lateef Alabi-Oki @license: GNU GPLv2 or Later @contact: mystilleef@gmail.com tTemplateLanguageTreeViewcBseZdZdZdZdZdZdZdZdZ ddZ d Z d Z d Zd Zd ZdZdZdZdZdZdZRS(sg This class creates an object that defines the behavior of the template editor's language treeview. cCs|i|||i|i|i|id|i|_|iid|i|_ |iid|i|_ |id|i |_ |i id|i|_|id|i|_|i id|i|_|i id|i|_d S( sH Initialize object. @param self: Reference to the TemplateLanguageTreeView instance. @type self: A TemplateLanguageTreeView 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-documentsrenamed-documenttshowscursor-changedsimported-languages drag-data-getsdrag-data-receivedN(t*_TemplateLanguageTreeView__init_attributest)_TemplateLanguageTreeView__set_propertiest)_TemplateLanguageTreeView__populate_modelt*_TemplateLanguageTreeView__select_languagetconnectt%_TemplateLanguageTreeView__destroy_cbt&_TemplateLanguageTreeView__signal_id_1t!_TemplateLanguageTreeView__editort%_TemplateLanguageTreeView__generic_cbt&_TemplateLanguageTreeView__signal_id_2t&_TemplateLanguageTreeView__signal_id_3t"_TemplateLanguageTreeView__show_cbt&_TemplateLanguageTreeView__signal_id_4t#_TemplateLanguageTreeView__treeviewt,_TemplateLanguageTreeView__cursor_changed_cbt&_TemplateLanguageTreeView__signal_id_5t/_TemplateLanguageTreeView__imported_language_cbt&_TemplateLanguageTreeView__signal_id_6t+_TemplateLanguageTreeView__drag_data_get_cbt&_TemplateLanguageTreeView__signal_id_7t0_TemplateLanguageTreeView__drag_data_received_cbt&_TemplateLanguageTreeView__signal_id_8(tselftmanagerteditor((s*plugins/TemplateEditor/LanguageTreeView.pyt__init__&s    cCs||_||_|iid|_t|_|i|_|i |_ |i |_ ddk l}|i}g}|D]}||iq~|_d|_|_|_d|_|_|_d|_|_dS(sQ Initialize data attributes. @param self: Reference to the TemplateLanguageTreeView instance. @type self: A TemplateLanguageTreeView 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. tLanguageTreeViewi(tSourceLanguagesManagerN(t"_TemplateLanguageTreeView__managerR tgladet get_widgetRtTruet(_TemplateLanguageTreeView__is_first_timet'_TemplateLanguageTreeView__create_modelt _TemplateLanguageTreeView__modelt*_TemplateLanguageTreeView__create_renderert#_TemplateLanguageTreeView__renderert(_TemplateLanguageTreeView__create_columnt!_TemplateLanguageTreeView__columnt gtksourceviewRtget_available_languagestget_idt$_TemplateLanguageTreeView__languagestNoneR R R RRRRR(RRRRt language_listt_[1]tname((s*plugins/TemplateEditor/LanguageTreeView.pyt__init_attributes@s   *cCsddkl}l}ddkl}|ii|d g||iid|dfg||ii|i |ii |i |i i dS( s Set the language view's default properties. @param self: Reference to the TemplateEditorLanguageView instance. @type self: A TemplateEditorLanguageView object. i(tACTION_DEFAULTt BUTTON1_MASK(tTARGET_SAME_APPtSTRINGii{i|N(R6ii{( tgtk.gdkR3R4tgtkR5Rtenable_model_drag_sourcetenable_model_drag_destt append_columnR)t set_modelR%tclicked(RR3R4R5((s*plugins/TemplateEditor/LanguageTreeView.pyt__set_properties\s cCs#ddkl}|tt}|S(s Create the model for the template editor's language view. @param self: Reference to the TemplateEditorLanguageView instance. @type self: A TemplateEditorLanguageView object. @return: A model for the language view. @rtype: A gtk.ListStore object. i(t ListStore(R8R?tstr(RR?tmodel((s*plugins/TemplateEditor/LanguageTreeView.pyt__create_modelos cCsddkl}l}ddkl}ddkl}|||idd}|idt|id||id t |i d|id t |id ||S( s  Create the column for the template editor's language view. @param self: Reference to the TemplateEditorLanguageView instance. @type self: A TemplateEditorLanguageView object. @return: A column for the language view. @rtype: A gtk.TreeViewColumn object. i(tTreeViewColumntTREE_VIEW_COLUMN_GROW_ONLY(tSORT_ASCENDING(tmsg0001ttextitexpandtsizingt clickablessort-indicators sort-order( R8RCRDREti18nRFR't set_propertytFalseR"tset_sort_column_id(RRCRDRERFtcolumn((s*plugins/TemplateEditor/LanguageTreeView.pyt__create_column}s  cCsddkl}|}|S(s Create the renderer for the language view's column @param self: Reference to the TemplateEditorLanguageView instance. @type self: A TemplateEditorLanguageView object. @return: A renderer for the language view. @rtype: A gtk.CellRendererText object. i(tCellRendererText(R8RQ(RRQtrenderer((s*plugins/TemplateEditor/LanguageTreeView.pyt__create_renderers  cCsddkl}|i}g}|D]}||i|ifq*~}|iiddgx*|D]"\}}|ii||gqoWdS(s Populate the language view's model. @param self: Reference to the TemplateLanguageTreeView instance. @type self: A TemplateLanguageTreeView object. i(RtGeneralN(R*RR+tget_nameR,R%tappend(RRR/R0R1tlanguage_namestid((s*plugins/TemplateEditor/LanguageTreeView.pyt__populate_models3 c Csoddkl}l}||o|i}n|}|i}|i}|i|d}|||oW|ii}|i ||i |}|ii ||ii dt ddnxt o|i|}|o~|i|d}|||oX|ii}|i ||i |}|ii ||ii dt ddPqfqPqWdS(s Select a row corresponding to the language in the tree view. @param self: Reference to the TemplateLanguageTreeView instance. @type self: A TemplateLanguageTreeView object. i(teqtnot_iig?gN(toperatorRZR[t'_TemplateLanguageTreeView__get_languageR%tget_iter_firstt get_valueRt get_selectiont select_itertget_pathtscroll_to_cellt get_columnR"t iter_next( RtlanguageRZR[t language_idRAtiteratort selectiontpath((s*plugins/TemplateEditor/LanguageTreeView.pyt__select_languages0    ,  ( cCs;|ii}ddkl}||odSn|iS(s Get the current language of the file in the text editor. @param self: Reference to the TemplateLanguageTreeView instance. @type self: A TemplateLanguageTreeView object. @return: Return a language or "General" @rtype: A String object. i(R[RT(R RfR\R[R,(RRfR[((s*plugins/TemplateEditor/LanguageTreeView.pyt__get_languages c sMg}ddkl}ddkl}ddkl}l}lfd}fd}t|t||i} |} x| i D]} t } x)| D]!} | i | o t } PqqW| oqn| i oQt }| i d}| | d}| | d }|i|||fqqW|| |S( Ni(topen_template_database(tclose_template_database(RZR[tnecs |iS((t startswith(tx(Rf(s*plugins/TemplateEditor/LanguageTreeView.pytscs |S(((Rq(RoRf(s*plugins/TemplateEditor/LanguageTreeView.pyRrstii(tMetadataRmRnR\RZR[RotfilterR-tkeysRMRpR"treplaceRV(RRft templatesRmRnRZR[t same_prefixtremove_languagetsimilar_prefixtdatabasetkeytskiptvaluetbooleanttriggert descriptionttemplate((RoRfs*plugins/TemplateEditor/LanguageTreeView.pyt__get_templatess2   ! cCs4|ii}|i|}|i|d}|S(sf Get the language of the row drag and drop occurred. @param self: Reference to the TemplateEditorLanguageView instance. @type self: A TemplateEditorLanguageView object. @param path: The row a drag and drop occurred. @type path: A Tuple object. @return: The language identifier of the row a drag and drop occurred. @rtype: A String object. i(Rt get_modeltget_iterR_(RRjRARhRg((s*plugins/TemplateEditor/LanguageTreeView.pyt__get_drop_rows cs"fd}t||}|S(sX Convert old template information to new one. @param self: Reference to the LanguageTreeView instance. @type self: A LanguageTreeView object. @param templates: Reference to the templates information. @type templates: A List object. @param language: Language category to convert templates to. @type language: A String object. cs,|\}}}}|t||fS(N(tlen(tdataR}RRt old_language(Rf(s*plugins/TemplateEditor/LanguageTreeView.pyt new_templates(tmap(RRxRfR((Rfs*plugins/TemplateEditor/LanguageTreeView.pyt__create_new_templates s cCsddkl}l}||i|||i|i||i|i||i|||i|i ||i |||i |i ||i |i |i i|i i||d}~dS(s Handles callback when the "destroy" signal is emitted. @param self: Reference to the TemplateLanguageTreeView instance. @type self: A TemplateLanguageTreeView object. @param manager: Reference to the TemplateManager instance. @type manager: A TemplateManager object. i(tdelete_attributestdisconnect_signalN(t SCRIBES.utilsRRR R R R RRRRRRR%tclearRR.(RRRR((s*plugins/TemplateEditor/LanguageTreeView.pyt __destroy_cb s    cGsdyJ|ii}|i\}}|i|d}|iid|Wntj onXdS(s Handles callback when the "cursor-changed" signal is emitted. @param self: Reference to the TemplateLanguageTreeView instance. @type self: A TemplateLanguageTreeView object. islanguage-selectedN(RR`t get_selectedR_Rtemitt TypeError(RtargsRiRARhRg((s*plugins/TemplateEditor/LanguageTreeView.pyt__cursor_changed_cb:scGs|idS(s A generic callback handler to select a language. @param self: Reference to the TemplateLanguageTreeView instance. @type self: A TemplateLanguageTreeView object. N(R(RR((s*plugins/TemplateEditor/LanguageTreeView.pyt __generic_cbJs cGs.|iiddkl}||idS(s Handles callback when the "show" signal is emitted. @param self: Reference to the TemplateLanguageTreeView instance. @type self: A TemplateLanguageTreeView object. i(t select_rowN(Rt grab_focusRR(RRR((s*plugins/TemplateEditor/LanguageTreeView.pyt __show_cbTs  cCsH|i||idddkl}||i|iidS(so Handles callback when the "imported-language" signal is emitted. @param self: Reference to the TemplateLanguageTreeView instance. @type self: A TemplateLanguageTreeView object. @param manager: Reference to the TemplateManager instance. @type manager: A TemplateManager object. @param language: A language category @type language: A String object. s import-errori(RN(RRRRRR(RRRfR((s*plugins/TemplateEditor/LanguageTreeView.pyt__imported_language_cb`s    c Csyddkl}|i}|i\}} |i| d} |i| } ddkl} | | o |nddkl } | | }|i |i d|Wn|j onXt S(Ni(t NoDataErrori(R[(tcreate_template_stringi( t ExceptionsRR`RR_t(_TemplateLanguageTreeView__get_templatesR\R[tWriteXMLTemplateRtsetttargetR"(RttreeviewtcontextRtinfottimeRRiRARhRgRxR[Rtstring((s*plugins/TemplateEditor/LanguageTreeView.pyt__drag_data_get_cbvs  c Cs4yBddkl}l} ddkl} |i||\} } ddkl} l}| | |gjotSn|i | }|i }ddk l }||}ddk l}||o | n|i||}ddkl}||}ddkl}||}||o | n|iid |Wn|j oCdd kl}|iii|d |i|iid n| j oCdd kl}|iii|d |i|iid nP| j oCdd kl}|iii|d |i|iid nXtS(s Handles callback when the "drag-data-received" signal is emitted. @param self: Reference to the TemplateLanguageTreeView instance. @type self: A TemplateLanguageTreeView object. @param treeview: Reference to the TemplateEditorLanguageView. @type treeview: A TemplateEditorLanguageView object. @param context: An object containing data about a drag selection. @type context: A gtk.DragContextData object. @param x: The x-cordinate of the drop. @type x: An Integer object. @param y: The y-cordinate of the drop. @type y: An Integer object. @param selection_data: Data representing the drag selection. @type selection_data: A gtk.SelectionData object. @param info: A unique identification for the text editor. @type info: An Integer object. @param time: The time the drop operation occurred. @type time: An Integer object. @return: True to propagate signals to parent widgets. @type: A Boolean Object. i(tInvalidFileErrortValidationError(R(tTREE_VIEW_DROP_BEFOREtTREE_VIEW_DROP_AFTER(tget_template_from_string(R[(R(timport_template_from_stringsimported-language(tmsg0014t parent_windows import-error(tmsg0015(RRRRtget_dest_row_at_posR8RRR"t'_TemplateLanguageTreeView__get_drop_rowRtReadXMLTemplateRR\R[t/_TemplateLanguageTreeView__create_new_templatesRRtImportTemplateRRRRKRR t error_dialogt show_messaget!_TemplateLanguageTreeView__dialogR(RRRRqtyRRRRRRRjtpositionRRRgRRRxR[t new_templatesRttemplate_stringRRR((s*plugins/TemplateEditor/LanguageTreeView.pyt__drag_data_received_cbs@    N(t__name__t __module__t__doc__RRRR$R(R&RR.RR]RRRRRR RRRR(((s*plugins/TemplateEditor/LanguageTreeView.pyR s(        #        N(RtobjectR(((s*plugins/TemplateEditor/LanguageTreeView.pyss