def onImportScriptFile(self, e=None, file=None): from ifigure.utils.addon_utils import onLoadFile ret = onLoadFile(self, message="Enter script file name", modename='pathmode', pathname='path', extname='.py', reject_loc=['wdir', 'owndir'], file=file, wildcard='*.py') if not ret: return file = self.path2fullpath() if self.getvar('pathmode') == 'owndir': newname = str(os.path.basename(file).split('.')[0]) self.rename(newname) else: self.load_script(file) # ifigure.events.SendFileSystemChangedEvent(self) # self.load_script(file) return file = dialog.read(None, message="Select script", wildcard='*.py') mode, path = FileHolder.fullpath2path(self, 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 self.import_script(file)
def onImportScriptFile(self, e=None, file = None): from ifigure.utils.addon_utils import onLoadFile ret = onLoadFile(self, message="Enter script file name", modename = 'pathmode', pathname = 'path', extname = '.py', reject_loc = ['wdir', 'owndir'], file = file, wildcard='*.py') if not ret: return file=self.path2fullpath() if self.getvar('pathmode') == 'owndir': newname = str(os.path.basename(file).split('.')[0]) self.rename(newname) else: self.load_script(file) # ifigure.events.SendFileSystemChangedEvent(self) # self.load_script(file) return file = dialog.read(None, message="Select script", wildcard='*.py') mode, path = FileHolder.fullpath2path(self, 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 self.import_script(file)
def read_report(file=None, offset=None): if file is None: from ifigure.widgets.dialog import read path = read(message='Memory Report file to read', defaultdir=os.getcwd()) if path == '': return else: path = expanduser(file) fid = open(path) lines = fid.readlines() fid.close() keys = lines[0].strip().split() mem_out = [] swp_out = [] for ll in lines[1:]: txts = ll.strip().split() if txts[0].startswith('Mem'): mem_out.append([str2number(s) for s in txts[1:]]) if txts[0].startswith('Swap'): swp_out.append([str2number(s) for s in txts[1:]]) mem_out = np.array(mem_out).transpose() swp_out = np.array(swp_out).transpose() mem_out = {keys[i]: mem_out[i] for i in range(len(mem_out))} swp_out = {keys[i]: swp_out[i] for i in range(len(swp_out))} return mem_out, swp_out
def onImportModuleFile(self, e=None): file = dialog.read(None, message="Select Module", wildcard='*.py') mode, path = self.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 self.import_module(file)
def onImportModuleFile(self, e=None): file = dialog.read(None, message="Select Module", wildcard='*.py') mode, path=self.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 self.import_module(file)
def onImportFile(self, e): ''' import file from outside project directory pathmode will be set to 'owndir' ''' file = dialog.read(None, message="Select file") if file == '': return mode, path=self.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 self.import_file(file)
def nas2mfem(file=None, offset=None): if file is None: from ifigure.widgets.dialog import read path = read(message='Select NAS file to read', wildcard='*.nas') if path == '': return else: path = expanduser(file) if offset is None: offset = [0.0, 0.0, 0.0] mname = os.path.basename(path) dirname = os.path.dirname(path) if '.' in mname: mname = '.'.join(mname.split('.')[:-1]) mname = mname + '.mesh' print('reading file ' + path) reader = NASReader(path) reader.load() write_nas2mfem(os.path.join(dirname, mname), reader, offset=offset)
def import_ns(model, path=None): from ifigure.mto.py_code import PyData from ifigure.mto.py_script import PyScript proj = model.get_root_parent() if path is None: path = dialog.read( wildcard='piScope subtree(pfs)|*.pfs|Python Script (py)|*.py') if path == '': return if path.endswith(".pfs"): if not proj.has_child(name='mfem_tmp'): proj.add_folder('mfem_tmp') child = proj.mfem_tmp.load_subtree(path) nsname = '_'.join(child.get_child(idx=0).name.split('_')[:-1]) nsname0 = nsname k = 0 while model.namespaces.has_child(nsname + '_ns'): k = k + 1 nsname = nsname0 + str(k) ns = child.get_child(name=nsname0 + '_ns') data = child.get_child(name=nsname0 + '_data') if ns is None: return ns.duplicate(model.namespaces, new_name=nsname + '_ns') if data is not None: data.duplicate(model.datasets, new_name=nsname + '_data') proj.mfem_tmp.destroy() elif path.endswith('.py'): shutil.copy(os.path.join(path), model.namespaces.owndir()) name = os.path.basename(path) sc = model.namespaces.add_childobject(PyScript, name[:-3]) sc.load_script(os.path.join(model.namespaces.owndir(), name)) obj = model.datasets.add_data(name[:-6] + '_data') else: raise AssertionError("Unsupported file")
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()
def onSetFile(self, e): file = dialog.read(None, message="Select file") self.setfile(file)