# This file is part of the Coral project.
# Please read the copyright notice in the LICENSE file.

import qt
import coral
import glob
import os
from coral.modeler.dlg.TemplateSelectionDlg import TemplateSelectionDlg


class TemplateSelectionDlgEx(TemplateSelectionDlg):

    def main(self, templates, modal=1):
        
        self.templates=templates

        for t in self.templates.keys():
            self.templateList.insertItem(str(t[:-4]))
                            
        if modal:
            self.exec_loop()
            if self.result()==qt.QDialog.Rejected:
                return -1
            else:
                return self.templateList.currentText()
        else:
            self.show()
            return -1

    def describe(self,a0):
        if a0:
            p=str(self.templates[str(a0.text())+".xml"][:-4])+".txt"
            try:
                f=open(p)
                ff=f.read()
                self.description.setText(ff)
            except:
                self.description.setText("No description!")
