Ejemplo n.º 1
0
    def SaveMappingToFile(self):
        if self.patterns.currentIndex() != 0:
            pattern, option = self.options_list[self.patterns.itemData(
                self.patterns.currentIndex())][1:]
            pattern_name = pattern.name
            option_name = option.name

            mapping = self.GetRoleMapping()

            data = {
                'version': 0,
                'pattern': pattern_name,
                'option': option_name,
                'roles': mapping
            }

            path, wildcard = SelectFiles(tm.ext.patterns_save_mapping,
                                         save=True,
                                         wildcard='.json file (*.json)')
            if path:
                try:
                    with open(path, 'w') as f:
                        json.dump(data, f, 'utf-8', ensure_ascii=True)
                except:
                    Notify(tm.ext.patterns_err_save)
Ejemplo n.º 2
0
 def Version2(data):
     from framework.project import ProjectView
     from framework.dialogs import Notify, SelectFiles, Choice
     projectdata = data.get('projectdata')
     if projectdata:
         Notify(
             _('Project data found in configuration. Please save it as project file.'
               ))
         del data['projectdata']
         while True:
             path = SelectFiles(tm.main.save_project_as,
                                save=True,
                                wildcard=ProjectView.msg_wildcard)
             if path:
                 try:
                     with open(path, 'w') as f:
                         json.dump(dict(data=projectdata),
                                   f,
                                   'utf-8',
                                   ensure_ascii=False)
                         data['projectfile'] = path
                         break
                 except:
                     if not Choice(
                             tm.main.config_convert_project_file_failed):
                         break
             else:
                 if Choice(tm.main.config_abort_project_convert):
                     break
Ejemplo n.º 3
0
 def SaveProjectAs(self):
     path, wildcard = SelectFiles(tm.main.save_project_as,
                                  save=True,
                                  wildcard=tm.main.project_wildcard)
     if not path or not Document.VerifyEditablePaths([path]):
         return
     self.SaveProjectToFile(path)
Ejemplo n.º 4
0
 def OpenProject(self):
     if self.projectfile:
         defDir = os.path.dirname(self.projectfile)
     else:
         defDir = './'
     path, wildcard = SelectFiles(tm.main.open_project,
                                  multi=False,
                                  defaultDir=defDir,
                                  wildcard=tm.main.project_wildcard)
     if not path:
         return
     self.OpenProjectFile(path)
Ejemplo n.º 5
0
 def LoadMappingFromFile(self):
     path, wildcard = SelectFiles(tm.ext.patterns_load_mapping,
                                  multi=False,
                                  wildcard='.json file (*.json)')
     if path:
         try:
             with open(path, 'r') as f:
                 data = json.load(f, 'utf-8')
                 pattern = '.'.join((data['pattern'], data['option']))
                 self.SetPatternOption(pattern, data['roles'])
         except:
             log.exception()
             Notify(tm.ext.patterns_err_load)
Ejemplo n.º 6
0
 def OnRunFile(self):
     if self.fileprocessor:
         path, wildcard = SelectFiles('Run file...', multi=False)
         if path:
             self.fileprocessor(path)