Beispiel #1
0
    def load_extfolder(self):
        basepath = self.get_extfolderpath()
        warning = []
        for dirpath, dirname, filenames in os.walk(basepath):
            if '.' in os.path.basename(dirpath):
                continue
            dirname = [x for x in dirname if not '.'in x]
            relpath = os.path.relpath(dirpath, basepath)
            if relpath == '.':
                relpath = ''
            p = self

            tmp = relpath.split(os.sep)
            if any(['.' in x for x in tmp]):
                continue
            for name in relpath.split(os.sep):
                if name == '':
                    continue
                p = p.get_child(name=name)

            for name in dirname:
                obj = PyFolder()
                p.add_child(name, obj, warning=warning)
            for f in filenames:
                fpath = os.path.join(dirpath, f)
                if fpath.endswith('.py'):
                    newname = str(os.path.basename(fpath).split('.')[0])
                    child = PyScript()
                    idx = p.add_child(newname, child, warning=warning)
                    child.set_path_pathmode(fpath, checklist=['extfolder'])
                    # child.import_script(fpath)
#                    script.onImportScriptFile(file = fpath)
        for x in warning:
            if len(x) != 0:
                print(x)
Beispiel #2
0
    def load_script_folder(self, basepath, skip_underscore = False):
        from ifigure.mto.py_script import PyScript        
        warning = []
        for dirpath, dirname, filenames in os.walk(basepath):
            if '.' in os.path.basename(dirpath): continue
            dirname = [x for x in dirname if not '.'in x]
            relpath = os.path.relpath(dirpath, basepath)
            if relpath == '.': relpath =''
            p = self

            tmp = relpath.split(os.sep)
            if any(['.' in x for x in tmp]): continue
            for name in relpath.split(os.sep):
                if name == '': continue
                p = p.get_child(name = name)

            for name in dirname:
                obj = PyFolder()
                p.add_child(name, obj, warning = warning)
            for f in filenames:
                fpath = os.path.join(dirpath, f)                

                if fpath.endswith('.py'):
                    newname = str(os.path.basename(fpath).split('.')[0])
                    if skip_underscore and newname.startswith('_'): continue
                    child=PyScript()
                    idx  =p.add_child(newname, child, warning = warning)
                    child.import_script(fpath)
#                    script.onImportScriptFile(file = fpath)
        for x in warning:
            if len(x) != 0: print(x)
Beispiel #3
0
 def load_default_script(self):
     base_mod = 'ifigure.add_on.solver.script'
     mod_path = cbook.GetModuleDir(base_mod)
     file = os.path.join(mod_path, 'run_stdsolver.py')
     sc = PyScript()
     self.add_child('solver_script', sc)
     sc.import_script(file)
     self.add_default_mergesol_script()
Beispiel #4
0
 def add_default_cost_script(self):
     if self.has_child('cost'): return
     base_mod = 'ifigure.add_on.solver.script'
     mod_path = cbook.GetModuleDir(base_mod)
     file = os.path.join(mod_path, 'cost_optimizer.py')
     sc = PyScript()
     self.add_child('cost', sc)
     sc._name_readonly = True
     sc.import_script(file)
Beispiel #5
0
 def add_default_mergesol_script(self):
     if self.has_child('merge_sol'): return
     base_mod = 'ifigure.add_on.solver.script'
     mod_path = cbook.GetModuleDir(base_mod)
     file = os.path.join(mod_path, 'merge_sol_parametric.py')
     sc = PyScript()
     self.add_child('merge_sol', sc)
     sc._name_readonly = True
     sc.import_script(file)
Beispiel #6
0
 def load_default_script(self):
     base_mod = 'ifigure.add_on.solver.script'
     mod_path = cbook.GetModuleDir(base_mod)
     file = os.path.join(mod_path, 'run_parametric.py')
     sc = PyScript()
     self.add_child('solver_script', sc)
     sc._name_readonly = True
     sc.import_script(file)
     sc.setvar("task", 2)
     self.add_default_mergesol_script()
Beispiel #7
0
 def onAddAbsScript(self, e, file=None, name = None):
     from ifigure.mto.py_script import PyScript
     child=PyScript()
     if name is None:
          name=self.get_next_name(child.get_namebase())
     if self.has_child(name):
          print 'doing here'
          name=self.get_next_name(name)
     idx=self.add_child(name, child)
     #print('loading add-on', file)
     child.load_script(file)
Beispiel #8
0
 def onAddScriptFromFile(self, e):
     
     file = dialog.read(None, message="Select script", 
                          wildcard='*.py')
     if file == '':
         e.Skip()
         return 
     # this call is just import check..
     from ifigure.mto.py_script import PyScript        
     tmp_child=PyScript()        
     idx=self.add_child('_tempraroy_script', tmp_child)        
     mode, path = tmp_child.fullpath2path(file)
     if (mode == 'wdir' or mode == 'owndir'):
        m = 'Import should import from somewhere outside project directory'
        ret=dialog.message(None, message=m, 
            title='Import error')
        return
     
     if not file.endswith('.py'):
        m = 'Script fils should be a .py file'
        ret=dialog.message(None, message=m, 
            title='Import error')
        return
     name = os.path.basename(file)[:-3]
     
     from ifigure.widgets.dlg_fileimportmode import DlgFileimportmode
     
     copy, modes, copy_org = DlgFileimportmode(self,
                                               parent =  e.GetEventObject())
     if copy:
          newfile =  os.path.join(self.owndir()
                                    , os.path.basename(file))
          if not self.has_owndir(): self.mk_owndir()
          shutil.copyfile(file, newfile)
          file = newfile
          modes = ['owndir']
     mode, path = tmp_child.fullpath2path(file, modes)
     tmp_child.destroy()
     self.onAddAbsScript(e, file=file, name=name)
     e.Skip()