FFc@s dZdefdYZdS(s This module documents a class that implements the behavior for the template editor's description treeview. @author: Lateef Alabi-Oki @organization: The Scribes Project @copyright: Copyright © 2007 Lateef Alabi-Oki @license: GNU GPLv2 or Later @contact: mystilleef@gmail.com tDescriptionTreeViewcBseZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdZdZdZdZdZdZdZRS(sD This class implements the behavior for the description treeview. cCsH|i|||i|id|i|_|id|i|_|id|i|_ |i id|i |_ |i id|i |_|id|i|_|id|i|_|id|i|_|id |i|_|i id |i|_d d kl}l}||i||i|_d S(s> Initialize object. @param self: Reference to the DescriptionTreeView instance. @type self: A DescriptionTreeView 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. tdestroyslanguage-selectedtshowsnotify::sensitivescursor-changedsremove-templatesexport-templatestrigger-selectedt sensitives drag-data-geti(t monitor_addt MONITOR_FILEN(t%_DescriptionTreeView__init_attributest$_DescriptionTreeView__set_propertiestconnectt _DescriptionTreeView__destroy_cbt!_DescriptionTreeView__signal_id_1t*_DescriptionTreeView__language_selected_cbt!_DescriptionTreeView__signal_id_2t connect_aftert_DescriptionTreeView__show_cbt!_DescriptionTreeView__signal_id_3t_DescriptionTreeView__treeviewt"_DescriptionTreeView__sensitive_cbt!_DescriptionTreeView__signal_id_4t'_DescriptionTreeView__cursor_changed_cbt!_DescriptionTreeView__signal_id_5t(_DescriptionTreeView__remove_template_cbt!_DescriptionTreeView__signal_id_6t(_DescriptionTreeView__export_template_cbt!_DescriptionTreeView__signal_id_7t)_DescriptionTreeView__trigger_selected_cbt!_DescriptionTreeView__signal_id_8t*_DescriptionTreeView__manager_sensitive_cbt!_DescriptionTreeView__signal_id_9t&_DescriptionTreeView__drag_data_get_cbt"_DescriptionTreeView__signal_id_10tgnomevfsRRt"_DescriptionTreeView__database_urit)_DescriptionTreeView__database_changed_cbt _DescriptionTreeView__monitor_id(tselftmanagerteditorRR((s-plugins/TemplateEditor/DescriptionTreeView.pyt__init__%s  c Csl||_||_d|_t|_d|_|i|_|i |_ |i |_ |i |_ |i|_|iid|_ddkl}|i}g}|D]}||iq~|_ddkl}|d}ddkl} | ||_d|_d|_|_d|_ |_!d|_"|_#d|_$|_%d|_&|_'dS(sG Initialize data attributes. @param self: Reference to the DescriptionTreeView instance. @type self: A DescriptionTreeView 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. Ri(tSourceLanguagesManager(tmetadata_folders templates.gdb(tget_uri_from_local_pathN((t_DescriptionTreeView__managert_DescriptionTreeView__editortNonet_DescriptionTreeView__languagetTruet _DescriptionTreeView__can_updatet_DescriptionTreeView__triggert"_DescriptionTreeView__create_modelt_DescriptionTreeView__modelt%_DescriptionTreeView__create_renderert#_DescriptionTreeView__name_renderert(_DescriptionTreeView__create_name_columnt!_DescriptionTreeView__name_columnt*_DescriptionTreeView__description_renderert/_DescriptionTreeView__create_description_columnt(_DescriptionTreeView__description_columntgladet get_widgetRt gtksourceviewR'tget_available_languagestget_idt_DescriptionTreeView__languagest SCRIBES.infoR(RR)R R"R R RRRRRRRR( R#R$R%R't language_listt_[1]tnameR(t database_pathR)((s-plugins/TemplateEditor/DescriptionTreeView.pyt__init_attributesBs2     *  cCsddkl}|ii}|i|ddkl}l}l}d d g}|ii ||||B|ii d|i |ii |i |ii |i|iid |i id S( s Set the description view's default properties. @param self: Reference to the TemplateEditorLanguageView instance. @type self: A TemplateEditorLanguageView object. i(tSELECTION_MULTIPLE(t BUTTON1_MASKt ACTION_COPYtACTION_DEFAULTs text/plainii{tSTRINGtmodelRN(s text/plainii{(RJii{(tgtkRFRt get_selectiontset_modetgtk.gdkRGRHRItenable_model_drag_sourcet set_propertyR2t append_columnR6R9tnotifytclicked(R#RFt selectionRGRHRIttargets((s-plugins/TemplateEditor/DescriptionTreeView.pyt__set_propertiesjs   cCs#ddkl}|tt}|S(s Create the model for the template editor's description view. @param self: Reference to the TemplateEditorDescriptionView instance. @type self: A TemplateEditorDescriptionView object. @return: A model for the description view. @rtype: A gtk.ListStore object. i(t ListStore(RLRXtstr(R#RXRK((s-plugins/TemplateEditor/DescriptionTreeView.pyt__create_model~s cCsddkl}|}|S(s Create the renderer for the description view's column @param self: Reference to the TemplateEditorDescriptionView instance. @type self: A TemplateEditorDescriptionView object. @return: A renderer for the description view. @rtype: A gtk.CellRendererText object. i(tCellRendererText(RLR[(R#R[trenderer((s-plugins/TemplateEditor/DescriptionTreeView.pyt__create_renderers  cCsddkl}l}ddkl}ddkl}|||idd}|idt|id||id t |i d|id t |id ||S( s Create the column for the template editor's description view. @param self: Reference to the TemplateEditorDescriptionView instance. @type self: A TemplateEditorDescriptionView object. @return: A column for the description view. @rtype: A gtk.TreeViewColumn object. i(tTreeViewColumntTREE_VIEW_COLUMN_GROW_ONLY(tSORT_ASCENDING(tmsg0002ttextitexpandtsizingt clickablessort-indicators sort-order( RLR^R_R`ti18nRaR4RQtFalseR.tset_sort_column_id(R#R^R_R`Ratcolumn((s-plugins/TemplateEditor/DescriptionTreeView.pyt__create_name_columns  cCsrddkl}l}ddkl}ddkl}|||idd}|idt|id||S( s Create the column for the template editor's description view. @param self: Reference to the TemplateEditorDescriptionView instance. @type self: A TemplateEditorDescriptionView object. @return: A column for the description view. @rtype: A gtk.TreeViewColumn object. i(R^R_(R`(tmsg0003RbiRcRd( RLR^R_R`RfRkR7RQR.(R#R^R_R`RkRi((s-plugins/TemplateEditor/DescriptionTreeView.pyt__create_description_columns c st}|iid||iiddkl}ddkl}ddkl }l }l fd}fd}t |t ||i } |} x| iD]} t} x)| D]!} | i| o t} PqqW| oqn| io@t}| id}| | d }|ii||gqqW|| |iid|||od Sn|id S( s Populate the treeview. @param self: Reference to the DescriptionTreeView instance. @type self: A DescriptionTreeView object. @param language: An object representing a language. @type language: A gtksourceview.SourceLanguage object. Ri(topen_template_database(tclose_template_database(teqtnot_tnecs |iS((t startswith(tx(tlanguage(s-plugins/TemplateEditor/DescriptionTreeView.pytscs |S(((Rs(RqRt(s-plugins/TemplateEditor/DescriptionTreeView.pyRustiN(RgRRQR2tcleartMetadataRmRntoperatorRoRpRqtfilterR?tkeysRrR.treplacetappendt _DescriptionTreeView__select_row(R#RttbooleanRmRnRoRpt same_prefixtremove_languagetsimilar_prefixtdatabasetkeytskiptvalueRCt description((RtRqs-plugins/TemplateEditor/DescriptionTreeView.pyt__populate_models:       c Csy|ii}|id|ii}|ii|}|ii||iidtdd|ii ||iid|ii |ii Wnt j onXdS(s Select the first row in the treeview. @param self: Reference to the DescriptionTreeView instance. @type self: A DescriptionTreeView object. ig?gN( RRMt select_pathR2tget_iter_firsttget_pathtscroll_to_cellt get_columnR.t set_cursortcolumns_autosizet grab_focust TypeError(R#RUtiteratortpath((s-plugins/TemplateEditor/DescriptionTreeView.pyt __select_rows ( cCs|ii}|i|io|i}|i}|i|d}ddkl}l }|||iog|i ||i |}|ii ||ii dtdd|ii||ii dqxto|i|}||o|iPn|i|d}|||ioh|i ||i |}|ii ||ii dtdd|ii||ii dPqqWn |id|_|iidt|ii|iidS(Nii(RoRpg?gR(RRMt unselect_allR0R2Rt get_valueRyRoRpt select_iterRRRR.Rt iter_nextR~R,R*temitRR(R#RURKRttriggerRoRpR((s-plugins/TemplateEditor/DescriptionTreeView.pyt__select_new_rows<     (#    (    cCsddkl}l}l}l}ddkl}|i|}|||tjo |n|||tjo |ndS(s Check whether or not the location can be written to. @param self: Reference to the DescriptionTreeView instance. @type self: A DescriptionTreeView object. @param filename: A string representing a file. @type filename: A String object. i(taccesstF_OKtW_OKR(tExportPermissionErrorN( tosRRRRt ExceptionsRtdirnameRg(R#tfilenameRRRRRtfolder((s-plugins/TemplateEditor/DescriptionTreeView.pyt__check_permissions "  c sii}|i\}ddkl}ddkl}||o |nfd}t||}ddkl }ddkl }|fd} t| |} || S(s Get template information. @param self: Reference to the DescriptionTreeView instance. @type self: A DescriptionTreeView object. @return: A list of template information. @rtype: A List object. i(Rp(tExportSelectionErrorcsii|dS(i(Rtget_iter(R(RK(s-plugins/TemplateEditor/DescriptionTreeView.pyRu@s(Rm(Rncsi|S((t"_DescriptionTreeView__get_template(R(R#R(s-plugins/TemplateEditor/DescriptionTreeView.pyRuEs( RRMtget_selected_rowsRyRpRRtmapRxRmRn( R#RUtpathsRpRt get_triggerttriggersRmRnt get_templatet templates((R#RRKs-plugins/TemplateEditor/DescriptionTreeView.pyt__get_template_info1s   cCs1|i|||i|d||i|dfS(Nii(R-(R#RR((s-plugins/TemplateEditor/DescriptionTreeView.pyt__get_templateJscCsddkl}l}||i|||i|||i|||i|i||i|i||i |||i |||i |||i |||i |i|io!ddkl}||in|ii||d}~dS(s Destroy instance of this class. @param self: Reference to the DescriptionTreeView instance. @type self: A DescriptionTreeView object. @param manager: Reference to the TemplateManager instance. @type manager: A TemplateManager object. i(tdisconnect_signaltdelete_attributes(tmonitor_cancelN(t SCRIBES.utilsRRR R RRRRRRRRRR"RRRR,(R#R$RRR((s-plugins/TemplateEditor/DescriptionTreeView.pyt __destroy_cbMs&    cCs'||_|i||iidS(s Handles callback when the "language-selected" signal is emitted. @param self: Reference to the DescriptionTreeView instance. @type self: A DescriptionTreeView object. @param manager: Reference to the TemplateManager instance. @type manager: A TemplateManager object. @param language: An object representing a language object. @type language: A gtksourceview.SourceLanguage object. N(R-t$_DescriptionTreeView__populate_modelRR(R#R$Rt((s-plugins/TemplateEditor/DescriptionTreeView.pyt__language_selected_cbks   cGs(|iido|iindS(s Handles callback when the "show" signal is emitted. @param self: Reference to the DescriptionTreeView instance. @type self: A DescriptionTreeView object. RN(Rt get_propertyR(R#targs((s-plugins/TemplateEditor/DescriptionTreeView.pyt __show_cb}s$cCs |iid|iddS(sN Handles callback when the "sensitive" property changes. @param self: Reference to the DescriptionTreeView instance. @type self: A DescriptionTreeView object. @param treeview: Reference to the DescriptionTreeView. @type treeview: A DescriptionTreeView object. @param data: Random data @type data: A GObject object. s description-treeview-sensitivityRN(R*RR(R#ttreeviewtdata((s-plugins/TemplateEditor/DescriptionTreeView.pyt__sensitive_cbs cCs|i}|i\}}ddkl}||odSn|i|d}|i|d}|iid|i|fdS(s Handles callback when the "cursor-changed" signal is emitted. @param self: Reference to the DescriptionTreeView instance. @type self: A DescriptionTreeView object. @return: True to propagate signals to parent widgets. @type: A Boolean Object. i(RpNistemplate-selected( RMRRyRpRRR*RR-(R#RRURKRRpRR((s-plugins/TemplateEditor/DescriptionTreeView.pyt__cursor_changed_cbs c s|idtii}|i\}ddkl}l}||odSnfd}t||}ddk l }ddk l } |d} dd kl } l}x8| i D]*} |||| oqn| | =qW| | dS( s Handles callback when the "remove-template" signal is emitted. @param self: Reference to the DescriptionTreeView instance. @type self: A DescriptionTreeView object. @param manager: Reference to the TemplateManager instance. @type manager: A TemplateManager object. Ri(RptcontainsNcs iii|dS(i(R-RR(R(R#RK(s-plugins/TemplateEditor/DescriptionTreeView.pyRus(Rm(Rntw(RoRp(RRgRRMRRyRpRRRxRmRnRoR{( R#R$RURRpRtget_keysR{RmRnRRoR((R#RKs-plugins/TemplateEditor/DescriptionTreeView.pyt__remove_template_cbs"     c Csddkl}ddkl}ddkl}ddkl}|||g}|||o+|i|i|i|i i ndS(s Handles callback when the template database is modified. @param self: Reference to the DescriptionTreeView instance. @type self: An DescriptionTreeView object. @param monitor_uri: The uri that is monitored. @type monitor_uri: A String object. @param info_uri: The uri that is monitored. @type info_uri: A String object. @param event_type: The type of modification that occured. @type event_type: A gnomevfs.MONITOR_EVENT* object. i(tMONITOR_EVENT_DELETED(tMONITOR_EVENT_CREATED(tMONITOR_EVENT_CHANGED(RN( RRRRRyRRR-t$_DescriptionTreeView__select_new_rowRR( R#t monitor_uritinfo_urit event_typeRRRRtevents((s-plugins/TemplateEditor/DescriptionTreeView.pyt__database_changed_cbs c Csy`ddkl}l}|idt|i||i}ddkl}|||Wnk|j o*ddk l }|i i i |n7|j o*ddk l}|i i i |nX|idtdS(s Handles callback when the "export-template" signal is emitted. @param self: Reference to the DescriptionTreeView instance. @type self: A DescriptionTreeView object. @param manager: Reference to the TemplateManager instance. @type manager: A TemplateManager object. i(RRR(tcreate_template_file(tmsg0011(tmsg0012N(RRRRRgt&_DescriptionTreeView__check_permissiont'_DescriptionTreeView__get_template_infotWriteXMLTemplateRRfRR+t error_dialogt show_messageRR.( R#R$RRRRRRR((s-plugins/TemplateEditor/DescriptionTreeView.pyt__export_template_cbs   cCs ||_dS(N(R0(R#R$R((s-plugins/TemplateEditor/DescriptionTreeView.pyt__trigger_selected_cbs cCs]|ii|iiddkl}||odSn|ii|iidS(Ni(Rp(R+tresponseRRRyRp(R#R$RRp((s-plugins/TemplateEditor/DescriptionTreeView.pyt__manager_sensitive_cbs    c CsB|i}ddkl}||}|i|id|tS(s Handles callback when the "drag-data-get" signal is emitted. @param self: Reference to the TemplateEditorDescriptionView instance. @type self: A TemplateEditorDescriptionView object. @param treeview: Reference to the TemplateEditorDescriptionView @type treeview: A TemplateEditorDescriptionView object. @param context: An object representing context data. @type context: A gtk.DragContext object. @param data: An object representing selection data. @type data: A gtk.SelectionData object. @param info: A unique identification number for the text editor. @type info: An Integer object. @param time: The time of the drag and drop operation. @type time: An Integer object. @return: True to propagate signals to parent widgets. @type: A Boolean Object. i(tcreate_template_stringi(RRRtsetttargetRg( R#RtcontextRtinfottimeRRtstring((s-plugins/TemplateEditor/DescriptionTreeView.pyt__drag_data_get_cbs   (t__name__t __module__t__doc__R&RRR1R3R5R8RR~RRRRR R RRRRR!RRRR(((s-plugins/TemplateEditor/DescriptionTreeView.pyR s2  (      &  "            N(RtobjectR(((s-plugins/TemplateEditor/DescriptionTreeView.pyss