def callback_copy_page(self): tab = self.notebook.currentWidget() old_index = tab.index new_sim_name = dlg_get_text( _("Clone the current fit to a new fit called:"), tab.tab_name, "clone.png") if new_sim_name.ret != None: index = fit_new_filename() shutil.copy( os.path.join(get_sim_path(), "fit" + str(old_index) + ".inp"), os.path.join(get_sim_path(), "fit" + str(index) + ".inp")) shutil.copy( os.path.join(get_sim_path(), "fit_data" + str(old_index) + ".inp"), os.path.join(get_sim_path(), "fit_data" + str(index) + ".inp")) shutil.copy( os.path.join(get_sim_path(), "fit_patch" + str(old_index) + ".inp"), os.path.join(get_sim_path(), "fit_patch" + str(index) + ".inp")) shutil.copy( os.path.join(get_sim_path(), "fit_math" + str(old_index) + ".inp"), os.path.join(get_sim_path(), "fit_math" + str(index) + ".inp")) inp_update_token_value( os.path.join(get_sim_path(), "fit" + str(index) + ".inp"), "#fit_name", new_sim_name.ret) self.add_page(index)
def callback_set_hpc_dir(self,widget,data): config_file=os.path.join(self.sim_dir,"server.inp") hpc_path=inp_get_token_value(config_file, "#hpc_dir") dialog = gtk.FileChooserDialog(_("Select HPC dir"), None, gtk.FILE_CHOOSER_ACTION_OPEN, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OK, gtk.RESPONSE_OK)) dialog.set_default_response(gtk.RESPONSE_OK) dialog.set_action(gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER) if os.path.isdir(hpc_path): dialog.set_current_folder(hpc_path) filter = gtk.FileFilter() filter.set_name(_("All files")) filter.add_pattern("*") dialog.add_filter(filter) response = dialog.run() if response == gtk.RESPONSE_OK: inp_update_token_value(config_file, "#hpc_dir", dialog.get_filename(),1) dialog.destroy()
def tree_apply_constant(directory, program_list): for i in range(0, len(program_list)): if program_list[i][3] == "constant": inp_update_token_value(os.path.join(directory, program_list[i][0]), program_list[i][1], program_list[i][2]) return True
def call_back_sim_mode_changed(self): mode = self.sim_mode.currentText() for i in range(0, len(self.store_list)): if self.store_list[i].token == mode: inp_update_token_value(os.path.join(get_sim_path(), "sim.inp"), "#simmode", mode + "@" + self.store_list[i].file)
def callback_add_page(self): new_sim_name=dlg_get_text( _("New laser name:"), _("laser ")+str(self.notebook.count()),"new.png") if new_sim_name.ret!=None: index=laser_new_filename() inp_copy_file("laser"+str(index)+".inp","laser0.inp") inp_update_token_value("laser"+str(index)+".inp", "#laser_name", new_sim_name.ret,1) self.add_page(index)
def update(self): self.cb.blockSignals(True) self.cb.clear() models = self.find_models() if len(models) == 0: error_dlg( self, _("I can't find any optical plugins, I think the model is not installed properly." )) return for i in range(0, len(models)): self.cb.addItem(models[i]) used_model = inp_get_token_value( os.path.join(get_sim_path(), "light.inp"), "#light_model") print(models, used_model) if models.count(used_model) == 0: used_model = "exp" inp_update_token_value(os.path.join(get_sim_path(), "light.inp"), "#light_model", "exp") self.cb.setCurrentIndex(self.cb.findText(used_model)) else: self.cb.setCurrentIndex(self.cb.findText(used_model)) self.cb.blockSignals(False)
def call_back_light_changed(self): light_power = self.light.currentText() inp_update_token_value(os.path.join(get_sim_path(), "light.inp"), "#Psun", light_power, id="tb_item_sun") self.changed.emit()
def callback_copy_page(self): tab = self.notebook.currentWidget() old_index = tab.index new_sim_name = dlg_get_text( _("Clone the current experiment to a new experiment called") + ":", tab.tab_name.split("@")[0], "clone.png") new_sim_name = new_sim_name.ret if new_sim_name != None: new_sim_name = new_sim_name + "@" + tab.tab_name.split("@")[1] index = experiment_new_filename("fxdomain") if inp_copy_file( os.path.join(get_sim_path(), "fxdomain" + str(index) + ".inp"), os.path.join(get_sim_path(), "fxdomain" + str(old_index) + ".inp")) == False: print("Error copying file" + os.path.join(get_sim_path(), "fxdomain" + str(old_index) + ".inp")) return if inp_copy_file( os.path.join(get_sim_path(), "fxmesh" + str(index) + ".inp"), os.path.join(get_sim_path(), "fxmesh" + str(old_index) + ".inp")) == False: print("Error copying file" + os.path.join(get_sim_path(), "fxdomain" + str(old_index) + ".inp")) return inp_update_token_value( os.path.join(get_sim_path(), "fxdomain" + str(index) + ".inp"), "#sim_menu_name", new_sim_name) self.add_page(index) self.changed.emit()
def call_back_light_changed(self, widget, data=None): light_power=self.light.get_active_text() #print light_power inp_update_token_value("light.inp", "#Psun", light_power,1) if global_isobject("experiment_graph_update")==True: global_object_get("experiment_graph_update")() self.emit("refresh")
def call_back_mode_changed(self): mode = self.mode.currentText() if mode == _("Raw data"): inp_update_token_value(os.path.join(self.path, "mat.inp"), self.token, "data") if mode == _("Equation"): inp_update_token_value(os.path.join(self.path, "mat.inp"), self.token, "equation")
def callback_edit(self): print("updating lang file", self.file_path) inp_update_token_value(self.file_path, "#lang", self.lang_box.itemText( self.lang_box.currentIndex()), archive="base.gpvdm") error_dlg(self, "Please restart gpvdm for the changes to take effect.")
def save_data(self): print("save") for i in range(0, self.tab.rowCount()): file_name = os.path.join(get_sim_path(), self.tab.item(i, 0).text() + ".inp") inp_update_token_value(file_name, "#doping_start", self.tab.item(i, 2).text()) inp_update_token_value(file_name, "#doping_stop", self.tab.item(i, 3).text())
def callback_edit(self, widget, data=None): if type(widget)==gtk.Entry: a=undo_list_class() a.add([self.file_name, data, inp_get_token_value(self.file_name, data),widget]) inp_update_token_value(self.file_name, data, widget.get_text(),1) else: inp_update_token_value(self.file_name, data, widget.get_active_text(),1) my_help_class.help_set_help(["save.png","<big><b>Saved to disk</b></big>\n"])
def write_cluster_config(self): tab = self.notebook.currentWidget() file_name=tab.file_name cluster_ip=inp_get_token_value(os.path.join(get_sim_path(),file_name), "#cluster_ip") inp_update_token_value(os.path.join(get_cluster_path(),"node.inp"),"#master_ip",cluster_ip) cluster_ip=inp_get_token_value(os.path.join(get_sim_path(),file_name), "#nodes") print(cluster_ip) inp_update_token_value(os.path.join(get_cluster_path(),"node_list.inp"),"#node_list",cluster_ip)
def callback_add_page(self): new_sim_name=dlg_get_text( _("New experiment name:"), _("experiment ")+str(self.notebook.count()+1),"new.png") if new_sim_name.ret!=None: index=experiment_new_filename() inp_copy_file("pulse"+str(index)+".inp","pulse0.inp") inp_copy_file("time_mesh_config"+str(index)+".inp","time_mesh_config0.inp") inp_update_token_value("pulse"+str(index)+".inp", "#sim_menu_name", new_sim_name.ret+"@pulse",1) self.add_page(index) self.changed.emit()
def callback_add_page(self): new_sim_name = dlg_get_text(_("New laser name:"), _("laser ") + str(self.notebook.count()), "document-new.png") if new_sim_name.ret != None: index = laser_new_filename() inp_copy_file("laser" + str(index) + ".inp", "laser0.inp") inp_update_token_value("laser" + str(index) + ".inp", "#laser_name", new_sim_name.ret) self.add_page(index)
def tree_apply_mirror(program_list): print(program_list) for i in range(0, len(program_list)): if program_list[i][2]=="mirror": f=scan_items_get_file(program_list[i][3]) t=scan_items_get_token(program_list[i][3]) src_value=inp_get_token_value(f, t) inp_update_token_value(program_list[i][0], program_list[i][1], src_value,1) return True
def set_state(self, val): for token in self.tokens: inp_update_token_value(os.path.join(get_sim_path(), "dump.inp"), token, str(val).lower()) for token in self.const_tokens: inp_update_token_value(os.path.join(get_sim_path(), "dump.inp"), token[0], str(token[1]).lower())
def callback_add_page(self, widget, data=None): new_sim_name=dlg_get_text( _("New fit name:"), _("fit ")+str(len(self.notebook.get_children())+1),image_name="new.png") if new_sim_name!=None: index=fit_new_filename() shutil.copy("fit0.inp","fit"+str(index)+".inp") shutil.copy("fit_data0.inp","fit_data"+str(index)+".inp") shutil.copy("fit_patch0.inp","fit_patch"+str(index)+".inp") inp_update_token_value("fit"+str(index)+".inp", "#fit_name", new_sim_name,1) self.add_page(index)
def callback_rename_page(self): tab = self.notebook.currentWidget() new_laser_name = dlg_get_text(_("Rename the laser to be called:"), tab.tab_name, "rename.png") if new_laser_name.ret != None: index = self.notebook.currentIndex() self.notebook.setTabText(index, new_laser_name.ret) inp_update_token_value(tab.file_name, "#laser_name", new_laser_name.ret)
def callback_add_page(self, widget, data=None): new_sim_name=dlg_get_text( _("New experiment name:"), _("experiment ")+str(len(self.notebook.get_children())+1)) if new_sim_name!=None: index=experiment_new_filename() inp_copy_file("pulse"+str(index)+".inp","pulse0.inp") inp_copy_file("time_mesh_config"+str(index)+".inp","time_mesh_config0.inp") inp_update_token_value("pulse"+str(index)+".inp", "#sim_menu_name", new_sim_name+"@pulse",1) self.add_page(index) global_object_get("tb_item_sim_mode_update")()
def tree(flat_simulation_list,program_list,tree_items,base_dir,level,path,var_to_change,value_to_change): #print(level,tree_items) values=tree_items[2][level] values=values.split() if tree_items[0][level]=="notknown": return False if tree_items[1][level]=="notknown": return False pass_var_to_change=var_to_change+" "+str(level) #print(pass_var_to_change) for ii in values: cur_dir=os.path.join(path,ii) if not os.path.exists(cur_dir): os.makedirs(cur_dir) pass_value_to_change=value_to_change+" "+ii if ((level+1)<len(tree_items[0])): ret=tree(flat_simulation_list,program_list,tree_items,base_dir,level+1,cur_dir,pass_var_to_change,pass_value_to_change) if ret==False: return False else: flat_simulation_list.append(cur_dir) new_values=pass_value_to_change.split() pos=pass_var_to_change.split() config_file=os.path.join(cur_dir,"sim.gpvdm") if os.path.isfile(config_file)==False: #Don't build a simulation over something that exists already copy_simulation(base_dir,cur_dir) os.chdir(cur_dir) if tree_apply_constant(cur_dir,program_list)==False: return False if tree_apply_python_script(cur_dir,program_list)==False: return False for i in range(0, len(pos)): file_path=os.path.join(cur_dir,tree_items[0][int(pos[i])]) inp_update_token_value(file_path, tree_items[1][int(pos[i])], new_values[i]) #print("updating", file_path, tree_items[1][int(pos[i])], new_values[i]) tree_apply_mirror(cur_dir,program_list) inp_update_token_value(os.path.join(cur_dir,"dump.inp"), "#plot", "0") if level==0: f = open(os.path.join(cur_dir,'scan.inp'),'w') f.write("data") f.close() return True
def tree(flat_simulation_list,program_list,tree_items,base_dir,level,path,var_to_change,value_to_change): print(level,tree_items) values=tree_items[2][level] values=values.split() if tree_items[0][level]=="notknown": return False if tree_items[1][level]=="notknown": return False pass_var_to_change=var_to_change+" "+str(level) print(pass_var_to_change) for ii in values: cur_dir=os.path.join(path,ii) if not os.path.exists(cur_dir): os.makedirs(cur_dir) pass_value_to_change=value_to_change+" "+ii if ((level+1)<len(tree_items[0])): ret=tree(flat_simulation_list,program_list,tree_items,base_dir,level+1,cur_dir,pass_var_to_change,pass_value_to_change) if ret==False: return False else: flat_simulation_list.append(cur_dir) new_values=pass_value_to_change.split() pos=pass_var_to_change.split() config_file=os.path.join(cur_dir,"sim.gpvdm") if os.path.isfile(config_file)==False: #Don't build a simulation over something that exists already copy_simulation(base_dir,cur_dir) os.chdir(cur_dir) for i in range(0, len(pos)): inp_update_token_value(tree_items[0][int(pos[i])], tree_items[1][int(pos[i])], new_values[i],1) print("updating",tree_items[0][int(pos[i])], tree_items[1][int(pos[i])], new_values[i]) if tree_apply_constant(program_list)==False: return False if tree_apply_python_script(program_list)==False: return False tree_apply_mirror(program_list) inp_update_token_value("dump.inp", "#plot", "0",1) if level==0: f = open(os.path.join(cur_dir,'scan.inp'),'w') f.write("data") f.close() return True
def tree_apply_python_script(program_list): for i in range(0, len(program_list)): if program_list[i][3]=="python_code": ret="" exec(program_list[i][2]) inp_update_token_value(program_list[i][0], program_list[i][1], ret,1) print(os.getcwd()) print("Replace",program_list[i][0], program_list[i][1], ret,1) return True
def sync_to_electrical_mesh(self): tot=0 for i in range(0,len(self.model)): if yes_no(self.model[i][COLUMN_DEVICE])==True: tot=tot+float(self.model[i][COLUMN_THICKNES]) lines=[] if inp_load_file(lines,os.path.join(os.getcwd(),"mesh_y.inp"))==True: mesh_layers=int(inp_search_token_value(lines, "#mesh_layers")) if mesh_layers==1: inp_update_token_value(os.path.join(os.getcwd(),"mesh_y.inp"), "#mesh_layer_length0", str(tot),1)
def tree_apply_constant(program_list): param_list = scan_items_get_list() for i in range(0, len(program_list)): if program_list[i][2] == "constant": pos_mirror_dest = scan_items_index_item(program_list[i][0]) inp_update_token_value( param_list[pos_mirror_dest].filename, param_list[pos_mirror_dest].token, program_list[i][1], param_list[pos_mirror_dest].line, )
def callback_copy_page(self): tab = self.notebook.currentWidget() new_sim_name=dlg_get_text(_("Clone the current laser to a new laser called:"), "clone.png") if new_sim_name.ret!=None: index=laser_new_filename() if inp_copy_file("laser"+str(index)+".inp",tab.file_name)==False: print ("Error copying file"+tab.file_name) return inp_update_token_value("laser"+str(index)+".inp", "#laser_name", new_sim_name.ret,1) self.add_page(index)
def callback_enable(self): file_list = zip_lsdir(os.path.join(get_sim_path(), "sim.gpvdm")) for i in range(0, len(file_list)): if inp_issequential_file(file_list[i], self.base_file_name[0]) == True: inp_update_token_value(file_list[i], "#tab_enabled", "false") tab = self.notebook_pointer.currentWidget() inp_update_token_value(os.path.join(get_sim_path(), tab.file_name), "#tab_enabled", "true") self.enabled.set_value(True)
def update_cb_model(self): models=find_models() for i in range(0, len(models)): self.cb_model.append_text(models[i]) used_model=inp_get_token_value("light.inp", "#light_model") if models.count(used_model)==0: used_model="exp" inp_update_token_value("light.inp", "#light_model","exp",1) self.cb_model.set_active(models.index(used_model)) scan_item_add("light.inp","#light_model","Optical model",1)
def callback_add_page(self): new_sim_name=dlg_get_text( _("New experiment name:"), _("experiment ")+str(self.notebook.count()+1),"new.png") new_sim_name=new_sim_name.ret if new_sim_name!=None: index=experiment_new_filename() inp_copy_file("fxdomain"+str(index)+".inp","fxdomain0.inp") inp_copy_file("fxmesh"+str(index)+".inp","fxmesh0.inp") inp_update_token_value("fxdomain"+str(index)+".inp", "#sim_menu_name", new_sim_name+"@fxdomain",1) self.add_page(index) self.changed.emit()
def update_light_source_model(self): models=find_light_source() for i in range(0, len(models)): self.light_source_model.append_text(models[i]) used_model=inp_get_token_value("optics.inp", "#sun") if models.count(used_model)==0: used_model="sun" inp_update_token_value("optics.inp", "#sun","sun",1) self.light_source_model.set_active(models.index(used_model)) scan_item_add("optics.inp","#sun","Light source",1)
def tree_apply_python_script(directory,program_list): for i in range(0, len(program_list)): if program_list[i][3]=="python_code": ret="" command=program_list[i][2] ret=eval(command) file_path=os.path.join(directory,program_list[i][0]) #print("EXEC=",command,">",ret,"<") inp_update_token_value(file_path, program_list[i][1], ret) #print("Replace",file_path, program_list[i][1], ret) return True
def tree_apply_mirror(directory,program_list): for i in range(0, len(program_list)): #print(program_list[i]) if program_list[i][2]=="mirror": f=scan_items_get_file(program_list[i][3]) t=scan_items_get_token(program_list[i][3]) #print(f,t,program_list[i][3]) src_value=inp_get_token_value(os.path.join(directory,f), t) #print("mirror src",f,t,src_value) inp_update_token_value(os.path.join(directory,program_list[i][0]), program_list[i][1], src_value) #print("mirror to",os.path.join(directory,program_list[i][0]), program_list[i][1]) return True
def update(self): self.sim_mode.clear() lines = [] self.store_list = [] temp = [] files = inp_lsdir("sim.gpvdm") if files != False: for i in range(0, len(files)): if files[i].endswith(".inp") and files[i].count("/") == 0: lines = inp_load_file(files[i]) value = inp_search_token_value(lines, "#sim_menu_name") if value != False: if value.count("@") == 1: temp.append(value) temp.sort() for i in range(0, len(temp)): value = temp[i].rstrip() command, module = value.split("@") self.sim_mode.addItem(command) a = store(command, module) self.store_list.append(a) print(os.getcwd()) token = inp_get_token_value("sim.inp", "#simmode") print(token) if token.count("@") != 0: command, module = token.split("@") else: command = token found = False all_items = [ self.sim_mode.itemText(i) for i in range(self.sim_mode.count()) ] for i in range(0, len(all_items)): if all_items[i] == command: self.sim_mode.setCurrentIndex(i) found = True #if there is no known mode, just set it to jv mode if found == False: for i in range(0, len(self.store_list)): if self.store_list[i].token == "jv": self.sim_mode.setCurrentIndex(i) inp_update_token_value( os.path.join(get_sim_path(), "sim.inp"), "#simmode", "jv@jv") break
def update(self): self.cb.blockSignals(True) models = find_light_source() for i in range(0, len(models)): self.cb.addItem(models[i]) used_model = inp_get_token_value("light.inp", "#sun") if models.count(used_model) == 0: used_model = "sun" inp_update_token_value("light.inp", "#sun", "sun") self.cb.setCurrentIndex(self.cb.findText(used_model)) self.cb.blockSignals(False)
def callback_add_page(self): new_sim_name = dlg_get_text( _("New measurement name") + ":", _("measurement ") + str(self.notebook.count() + 1), "document-new.png") if new_sim_name.ret != None: index = measure_new_filename() inp_copy_file( os.path.join(get_sim_path(), "measure" + str(index) + ".inp"), os.path.join(get_sim_path(), "measure0.inp")) inp_update_token_value( os.path.join(get_sim_path(), "measure" + str(index) + ".inp"), "#measure_name", new_sim_name.ret) self.add_page(index)
def apply_constants(self): for program_line in self.program_list: if program_line.opp=="constant": if program_line.file.endswith("*"): search_file=program_line.file[:-1] file_list=zip_lsdir(os.path.join(self.directory,"sim.gpvdm")) #print(self.directory,file_list) for f in file_list: if f.startswith(search_file)==True: inp_update_token_value(os.path.join(self.directory,f), program_line.token, program_line.values) #print(">>> edited",f) else: inp_update_token_value(os.path.join(self.directory,program_line.file), program_line.token, program_line.values) return True
def callback_copy_page(self,widget,data): pageNum = self.notebook.get_current_page() tab = self.notebook.get_nth_page(pageNum) old_index=tab.index new_sim_name=dlg_get_text( _("Clone the current fit to a new fit called:"), tab.tab_name,image_name="clone.png") if new_sim_name!=None: new_sim_name=new_sim_name index=fit_new_filename() shutil.copy("fit"+str(old_index)+".inp","fit"+str(index)+".inp") shutil.copy("fit_data"+str(old_index)+".inp","fit_data"+str(index)+".inp") shutil.copy("fit_patch"+str(old_index)+".inp","fit_patch"+str(index)+".inp") inp_update_token_value("fit"+str(index)+".inp", "#fit_name", new_sim_name,1) self.add_page(index)
def update_light_source_model(self): self.light_source_model.blockSignals(True) models=find_light_source() for i in range(0, len(models)): self.light_source_model.addItem(models[i]) used_model=inp_get_token_value("light.inp", "#sun") print("models================",models,used_model) if models.count(used_model)==0: used_model="sun" inp_update_token_value("light.inp", "#sun","sun",1) self.light_source_model.setCurrentIndex(self.light_source_model.findText(used_model)) scan_item_add("light.inp","#sun","Light source",1) self.light_source_model.blockSignals(False)
def callback_rename_page(self): tab = self.notebook_pointer.currentWidget() name = inp_get_token_value(tab.file_name, self.name_token) name = name.split("@")[0] new_sim_name = dlg_get_text(self.rename_dlg_text + ":", name, "rename.png") new_sim_name = new_sim_name.ret if new_sim_name != None: inp_update_token_value(tab.file_name, self.name_token, new_sim_name + self.postfix) index = self.notebook_pointer.currentIndex() self.notebook_pointer.setTabText(index, new_sim_name) self.changed.emit()
def callback_copy_page(self): tab = self.notebook.currentWidget() index = laser_new_filename() new_file = "laser" + str(index) + ".inp" new_sim_name = dlg_get_text( _("Clone the current laser to a new laser called:"), tab.tab_name + "_new", "clone.png") if new_sim_name.ret != None: dest = os.path.join(get_sim_path(), new_file) if inp_copy_file(dest, tab.file_name) == False: print("Error copying file" + dest + " " + tab.file_name) return inp_update_token_value(dest, "#laser_name", new_sim_name.ret) self.add_page(index)
def callback_add_page(self): new_sim_name = dlg_get_text( _("New experiment name") + ":", _("experiment ") + str(self.notebook.count() + 1), "document-new.png") if new_sim_name.ret != None: index = experiment_new_filename("jv") inp_copy_file( os.path.join(get_sim_path(), "jv" + str(index) + ".inp"), os.path.join(get_sim_path(), "jv0.inp")) inp_update_token_value( os.path.join(get_sim_path(), "jv" + str(index) + ".inp"), "#sim_menu_name", new_sim_name.ret + "@jv") self.add_page(index) self.changed.emit()
def callback_run(self): self.my_server = server_get() self.dump_optics = inp_get_token_value("dump.inp", "#dump_optics") #self.dump_optics_verbose=inp_get_token_value("dump.inp", "#dump_optics_verbose") inp_update_token_value("dump.inp", "#dump_optics", "true") #inp_update_token_value("dump.inp", "#dump_optics_verbose","true") #pwd=os.getcwd() #os.chdir(get_sim_path()) #cmd = get_exe_command()+' --simmode opticalmodel@optics' #print(cmd) #ret= os.system(cmd) #os.chdir(pwd) self.my_server.clear_cache() self.my_server.add_job(get_sim_path(), "--simmode opticalmodel@optics") self.my_server.set_callback_when_done(self.optics_sim_finished) self.my_server.start()
def callback_add_page(self): new_sim_name = dlg_get_text(self.new_dlg_text + ":", self.new_name(), "document-new.png") if new_sim_name.ret != None: number = self.new_filenumber() for b in range(0, len(self.base_file_name)): new_filename = self.base_file_name[b] + number + ".inp" orig_filename = self.base_file_name[b] + "0.inp" inp_copy_file(os.path.join(get_sim_path(), new_filename), os.path.join(get_sim_path(), orig_filename)) if b == 0: inp_update_token_value( os.path.join(get_sim_path(), new_filename), self.name_token, new_sim_name.ret + self.postfix) emit_file_name = new_filename self.added.emit(emit_file_name)
def tree_apply_python_script(program_list): param_list = scan_items_get_list() for i in range(0, len(program_list)): if program_list[i][2] == "python_code": pos_mirror_dest = scan_items_index_item(program_list[i][0]) ret = "" exec (program_list[i][1]) inp_update_token_value( param_list[pos_mirror_dest].filename, param_list[pos_mirror_dest].token, ret, param_list[pos_mirror_dest].line, ) print os.getcwd() print "Replace", param_list[pos_mirror_dest].filename, param_list[pos_mirror_dest].token, program_list[i][ 1 ], ret
def callback_copy_page(self,widget,data): pageNum = self.notebook.get_current_page() tab = self.notebook.get_nth_page(pageNum) old_index=tab.index new_sim_name=dlg_get_text( _("Clone the current experiment to a new experiment called:"), tab.tab_name.split("@")[0]) if new_sim_name!=None: new_sim_name=new_sim_name+"@"+tab.tab_name.split("@")[1] index=experiment_new_filename() if inp_copy_file("pulse"+str(index)+".inp","pulse"+str(old_index)+".inp")==False: print "Error copying file"+"pulse"+str(old_index)+".inp" return if inp_copy_file("time_mesh_config"+str(index)+".inp","time_mesh_config"+str(old_index)+".inp")==False: print "Error copying file"+"pulse"+str(old_index)+".inp" return inp_update_token_value("pulse"+str(index)+".inp", "#sim_menu_name", new_sim_name,1) self.add_page(index) global_object_get("tb_item_sim_mode_update")()
def callback_copy_page(self,widget,data): pageNum = self.notebook.get_current_page() tab = self.notebook.get_nth_page(pageNum) old_index=tab.index new_sim_name=dlg_get_text( _("Clone the current experiment to a new experiment called:"), tab.tab_name.split("@")[0],image_name="clone.png") if new_sim_name!=None: new_sim_name=new_sim_name+"@"+tab.tab_name.split("@")[1] index=experiment_new_filename() if inp_copy_file("fxdomain"+str(index)+".inp","fxdomain"+str(old_index)+".inp")==False: print("Error copying file"+"fxdomain"+str(old_index)+".inp") return if inp_copy_file("fxmesh"+str(index)+".inp","fxmesh"+str(old_index)+".inp")==False: print("Error copying file"+"fxdomain"+str(old_index)+".inp") return inp_update_token_value("fxdomain"+str(index)+".inp", "#sim_menu_name", new_sim_name,1) self.add_page(index) self.changed.emit()
def toggle_tab_visible(self,name): if self.finished_loading==True: for child in self.get_children(): if child.label_name==name: if child.visible==False: if self.item_factory!=None: widget=self.item_factory.get_widget(_("/View/")+name) widget.set_active(True) child.show() child.visible=True else: if self.item_factory!=None: widget=self.item_factory.get_widget(_("/View/")+name) widget.set_active(False) child.hide() child.visible=False inp_update_token_value("gui_config.inp", "#"+child.file_name, str(int(child.visible)),1)
def duplicate_params(self): for program_line in self.program_list: #print(program_list[i]) if program_line.values=="duplicate": #print(">>>",program_line.opp,"<<",program_line.values) f=self.scan_human_labels.get_file_from_human_label(program_line.opp) src_token=self.scan_human_labels.get_token_from_human_label(program_line.opp) src_file=os.path.join(self.directory,f) in_file=inp() in_file.load(src_file) src_value=in_file.get_token(src_token) inp_update_token_value(os.path.join(self.directory,program_line.file), program_line.token, src_value) return True
def add_new_electrical_to_shape(self,shape_file): s=self.find_shape_by_file_name(shape_file) if s.shape_dos!="none": return s.shape_dos new_file=self.new_electrical_file("electrical") s.shape_dos=new_file inp_update_token_value(s.file_name,"#shape_electrical",s.shape_electrical) new_electrical_file=new_file+".inp" if inp().isfile(new_electrical_file)==False: electrical_path_generic=os.path.join(get_default_material_path(),"electrical.inp") inp_copy_file(new_electrical_file,electrical_path_generic) return new_file
def callback_copy_page(self): tab = self.notebook.currentWidget() old_index=tab.index new_sim_name=dlg_get_text( _("Clone the current experiment to a new experiment called:"), tab.tab_name.split("@")[0],"clone.png") new_sim_name=new_sim_name.ret if new_sim_name!=None: new_sim_name=new_sim_name+"@"+tab.tab_name.split("@")[1] index=experiment_new_filename() if inp_copy_file("pulse"+str(index)+".inp","pulse"+str(old_index)+".inp")==False: print("Error copying file"+"pulse"+str(old_index)+".inp") return if inp_copy_file("time_mesh_config"+str(index)+".inp","time_mesh_config"+str(old_index)+".inp")==False: print("Error copying file"+"pulse"+str(old_index)+".inp") return inp_update_token_value("pulse"+str(index)+".inp", "#sim_menu_name", new_sim_name,1) self.add_page(index) self.changed.emit()
def update(self): self.sim_mode.clear() lines=[] self.store_list=[] files=inp_lsdir() if files!=False: for i in range(0,len(files)): if files[i].endswith(".inp"): inp_load_file(lines,files[i]) value=inp_search_token_value(lines, "#sim_menu_name") if value!=False: if value.count("@")==1: value=value.rstrip() command,module=value.split("@") self.sim_mode.addItem(command) a=store(command,module) self.store_list.append(a) token=inp_get_token_value("sim.inp", "#simmode") if token.count("@")!=0: command,module=token.split("@") else: command=token found=False all_items = [self.sim_mode.itemText(i) for i in range(self.sim_mode.count())] for i in range(0,len(all_items)): if all_items[i] == command: self.sim_mode.setCurrentIndex(i) found=True #if there is no known mode, just set it to jv mode if found==False: for i in range(0,len(self.store_list)): if self.store_list[i].token=="jv": self.sim_mode.activated(i) inp_update_token_value("sim.inp", "#simmode", "jv@jv",1) break
def callback_edit(self, file_name, token, widget): if type(widget) == QLineEdit: a = undo_list_class() a.add([file_name, token, inp_get_token_value(self.file_name, token), widget]) inp_update_token_value(file_name, token, widget.text(), 1) elif type(widget) == gtkswitch: inp_update_token_value(file_name, token, widget.get_value(), 1) elif type(widget) == leftright: inp_update_token_value(file_name, token, widget.get_value(), 1) elif type(widget) == QComboBox: inp_update_token_value(file_name, token, widget.itemText(widget.currentIndex()), 1) help_window().help_set_help(["32_save.png", "<big><b>Saved to disk</b></big>\n"])
def device_lib_fix_ver(file_name, ver ): archives=find_device_libs() for i in range(0,len(archives)): src_file=os.path.join(os.path.dirname(archives[i]),file_name) archive=os.path.basename(archives[i]) value=inp_get_token_value(src_file, "#ver",archive=archives[i]) if value!=None and value != ver: inp_update_token_value(src_file, "#ver", ver,archive=archives[i]) print(value) if value==None: lines=inp_load_file(src_file,archive=archives[i]) for ii in range(0,len(lines)): if lines[ii]=="#end": lines[ii]="#ver" lines[ii+1]=ver lines.append("#end") print(lines) inp_save(src_file,lines,archive=archives[i])
def ver_sync_ver(): file_name=os.path.join(os.getcwd(),"include","version.h") found=False if os.path.isfile(file_name)==True: f = open(file_name, "r") lines = f.readlines() f.close() for l in range(0, len(lines)): lines[l]=lines[l].rstrip() if lines[l].startswith("#define")==True: text=(lines[l].split("\t")[2].strip("\"")) found=True if found==True: print("seting ver to: ",text) inp_update_token_value("ver.inp","#core",text,archive="sim.gpvdm") inp_update_token_value("ver.inp","#core",text,archive="base.gpvdm") else: print(_("version.h not found"))
def tree_apply_mirror(program_list): param_list = scan_items_get_list() for i in range(0, len(program_list)): for ii in range(0, len(program_list)): if program_list[i][2] == program_list[ii][0]: # I have found two matching IDs pos_mirror_src = scan_items_index_item(program_list[i][2]) pos_mirror_dest = scan_items_index_item(program_list[i][0]) src_value = inp_get_token_value(param_list[pos_mirror_src].filename, param_list[pos_mirror_src].token) # pull out of the file the value if program_list[i][1] != "mirror": # find value in list orig_list = program_list[i][1].split() look_up = program_list[ii][1].split() src_value = orig_list[look_up.index(src_value.rstrip())] inp_update_token_value( param_list[pos_mirror_dest].filename, param_list[pos_mirror_dest].token, src_value, param_list[pos_mirror_dest].line, )
def tree(flat_simulation_list, program_list, tree_items, base_dir, level, path, var_to_change, value_to_change): param_list = scan_items_get_list() print level, tree_items i = tree_items[1][level] words = i.split() pass_var_to_change = var_to_change + " " + str(scan_items_index_item(tree_items[0][level])) print pass_var_to_change for ii in words: cur_dir = os.path.join(path, ii) if not os.path.exists(cur_dir): os.makedirs(cur_dir) pass_value_to_change = value_to_change + " " + ii if (level + 1) < len(tree_items[0]): tree( flat_simulation_list, program_list, tree_items, base_dir, level + 1, cur_dir, pass_var_to_change, pass_value_to_change, ) else: flat_simulation_list.append(cur_dir) new_values = pass_value_to_change.split() pos = pass_var_to_change.split() config_file = os.path.join(cur_dir, "sim.opvdm") if os.path.isfile(config_file) == False: # Don't build a simulation over something that exists already copy_simulation(base_dir, cur_dir) os.chdir(cur_dir) for i in range(0, len(pos)): inp_update_token_value( param_list[int(pos[i])].filename, param_list[int(pos[i])].token, new_values[i], param_list[int(pos[i])].line, ) tree_apply_constant(program_list) tree_apply_python_script(program_list) tree_apply_mirror(program_list) inp_update_token_value("materialsdir.inp", "#materialsdir", os.path.join(base_dir, "materials"), 1) inp_update_token_value("dump.inp", "#plot", "0", 1) if level == 0: f = open(os.path.join(cur_dir, "scan.inp"), "w") f.write("data") f.close()
def update_cb_model(self): self.cb_model.blockSignals(True) self.cb_model.clear() models=find_models() if len(models)==0: error_dlg(self,_("I can't find any optical plugins, I think the model is not installed properly.")) return for i in range(0, len(models)): self.cb_model.addItem(models[i]) used_model=inp_get_token_value("light.inp", "#light_model") print(models,used_model) if models.count(used_model)==0: used_model="exp" inp_update_token_value("light.inp", "#light_model","exp",1) self.cb_model.setCurrentIndex(self.cb_model.findText(used_model)) else: self.cb_model.setCurrentIndex(self.cb_model.findText(used_model)) scan_item_add("light.inp","#light_model","Optical model",1) self.cb_model.blockSignals(False)
def init(self): return False self.dumps=0 self.plot_token=plot_state() vbox=gtk.VBox() self.multi_plot=False self.log_scale_y="auto" menu_items = ( ( "/_Options", None, None, 0, "<Branch>" ), ( "/Options/_Subtract 0th frame", None, self.callback_toggle_subtract, 0, "<ToggleItem>", "gtk-save" ), ( "/_Axis/_Multiplot", None, self.callback_multi_plot, 0, "<ToggleItem>", "gtk-save" ), ( "/_Axis/_Set y axis to maximum", None, self.callback_set_min_max, 0, "<ToggleItem>", "gtk-save" ), ) self.plot.item_factory.create_items(menu_items) primary_hbox.add(self.entry0) sim_vbox.add(primary_hbox) secondary_hbox=gtk.HBox() text=gtk.Label("Secondary dir") secondary_hbox.add(text) self.entry1 = gtk.combo_box_entry_new_text() self.entry1.show() for i in range(0,len(self.snapshot_list)): self.entry1.append_text(self.snapshot_list[i]) secondary_hbox.add(self.entry1) sim_vbox.add(secondary_hbox) sim_vbox.show() #hbox.set_size_request(-1, 30) vbox.pack_start(sim_vbox, False, False, 0) hbox2=gtk.HBox() text=gtk.Label("Files to plot") hbox2.add(text) self.entry2 = gtk.Entry() self.entry2.set_text("pt_map nt_map") self.entry2.show() hbox2.add(self.entry2) hbox2.set_size_request(-1, 30) vbox.pack_start(hbox2, False, False, 0) hbox3=gtk.HBox() text=gtk.Label("Exprimental data") hbox3.add(text) self.entry3 = gtk.Entry() self.entry3.set_text("") self.entry3.show() hbox3.add(self.entry3) hbox3.set_size_request(-1, 30) vbox.pack_start(hbox3, False, False, 0) self.update_button = gtk.Button() self.update_button.set_label("Update") self.update_button.show() self.update_button.connect("clicked", self.callback_scale) vbox.add(self.update_button) self.config_load() self.count_dumps() if self.dumps==0: md = gtk.MessageDialog(None, 0, gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, "No slice data has been written to disk. You need to re-run the simulation with the dump_slices set to 1. Would you like to do this now? Note: This generates lots of files and will slow down the simulation.") response = md.run() if response == gtk.RESPONSE_YES: inp_update_token_value("dump.inp", "#dump_1d_slices", "1",1) os.system(get_exe_command()) md.destroy() self.count_dumps() self.entry0.connect("changed", self.callback_edit) self.entry1.connect("changed", self.callback_edit) self.entry2.connect("changed", self.callback_edit) self.entry3.connect("changed", self.callback_edit) vbox.show_all() self.add(vbox) self.update(0) if self.dumps!=0: self.plot.do_plot() print("CONVERT!!!!!!!!!!!",type(self.plot.plot_token.key_units)) self.set_border_width(10) self.set_title("Compare") self.set_icon_from_file(os.path.join(get_image_file_path(),"image.jpg")) self.connect('key_press_event', self.on_key_press_event) self.show()
def init(self): self.dumps=0 self.plot_token=plot_state() self.win_list=windows() self.win_list.load() self.win_list.set_window(self,"cmp_class") self.snapshot_list=self.update_snapshots_dir() vbox=gtk.VBox() self.multi_plot=False self.log_scale_y="auto" self.plot=plot_widget() self.plot.init(self) accel_group = gtk.AccelGroup() item_factory = gtk.ItemFactory(gtk.MenuBar, "<main>", accel_group) menu_items = ( ( "/_Options", None, None, 0, "<Branch>" ), ( "/Options/_Subtract 0th frame", None, self.callback_toggle_subtract, 0, "<ToggleItem>", "gtk-save" ), ( "/_Axis/_Multiplot", None, self.callback_multi_plot, 0, "<ToggleItem>", "gtk-save" ), ( "/_Axis/_Set y axis to maximum", None, self.callback_set_min_max, 0, "<ToggleItem>", "gtk-save" ), ) self.plot.item_factory.create_items(menu_items) image = gtk.Image() image.set_from_file(os.path.join(get_image_file_path(),"video.png")) self.video = gtk.ToolButton(image) self.plot.toolbar.add(self.video) self.video.show() self.video.connect("clicked", self.callback_save) image = gtk.Image() image.set_from_file(os.path.join(get_image_file_path(),"scale.png")) self.scale = gtk.ToolButton(image) self.plot.toolbar.add(self.scale) sep = gtk.SeparatorToolItem() sep.set_draw(False) sep.set_expand(True) self.plot.toolbar.add(sep) sep.show() help = gtk.ToolButton(gtk.STOCK_HELP) self.plot.toolbar.add(help) help.connect("clicked", self.callback_help) help.show() close = gtk.ToolButton(gtk.STOCK_QUIT) close.connect("clicked", self.callback_close) self.plot.toolbar.add(close) close.show() self.connect("delete-event", self.callback_close) self.plot.toolbar.show_all() self.canvas=self.plot.canvas self.plot.show() vbox.add(self.plot) #adjust self.adj1 = gtk.Adjustment(0.0, 0.0, 100, 1, 1.0, 1.0) self.adj1.connect("value_changed", self.callback_scale) vscale = gtk.HScale(self.adj1) vscale.set_update_policy(gtk.UPDATE_CONTINUOUS) vscale.set_digits(1) vscale.set_value_pos(gtk.POS_TOP) vscale.set_draw_value(True) vscale.set_size_request(200, 40) vscale.set_digits(0) vbox.pack_start(vscale, False, False, 10) sim_vbox=gtk.VBox() primary_hbox=gtk.HBox() text=gtk.Label("Primary dir") primary_hbox.add(text) self.entry0 = gtk.combo_box_entry_new_text() self.entry0.show() for i in range(0,len(self.snapshot_list)): self.entry0.append_text(self.snapshot_list[i]) primary_hbox.add(self.entry0) sim_vbox.add(primary_hbox) secondary_hbox=gtk.HBox() text=gtk.Label("Secondary dir") secondary_hbox.add(text) self.entry1 = gtk.combo_box_entry_new_text() self.entry1.show() for i in range(0,len(self.snapshot_list)): self.entry1.append_text(self.snapshot_list[i]) secondary_hbox.add(self.entry1) sim_vbox.add(secondary_hbox) sim_vbox.show() #hbox.set_size_request(-1, 30) vbox.pack_start(sim_vbox, False, False, 0) hbox2=gtk.HBox() text=gtk.Label("Files to plot") hbox2.add(text) self.entry2 = gtk.Entry() self.entry2.set_text("pt_map nt_map") self.entry2.show() hbox2.add(self.entry2) hbox2.set_size_request(-1, 30) vbox.pack_start(hbox2, False, False, 0) hbox3=gtk.HBox() text=gtk.Label("Exprimental data") hbox3.add(text) self.entry3 = gtk.Entry() self.entry3.set_text("") self.entry3.show() hbox3.add(self.entry3) hbox3.set_size_request(-1, 30) vbox.pack_start(hbox3, False, False, 0) self.update_button = gtk.Button() self.update_button.set_label("Update") self.update_button.show() self.update_button.connect("clicked", self.callback_scale) vbox.add(self.update_button) self.config_load() self.count_dumps() if self.dumps==0: md = gtk.MessageDialog(None, 0, gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, "No slice data has been written to disk. You need to re-run the simulation with the dump_slices set to 1. Would you like to do this now? Note: This generates lots of files and will slow down the simulation.") response = md.run() if response == gtk.RESPONSE_YES: inp_update_token_value("dump.inp", "#dump_1d_slices", "1",1) ret= os.system(get_exe_command()) md.destroy() self.count_dumps() self.entry0.connect("changed", self.callback_edit) self.entry1.connect("changed", self.callback_edit) self.entry2.connect("changed", self.callback_edit) self.entry3.connect("changed", self.callback_edit) vbox.show_all() self.add(vbox) self.update(0) if self.dumps!=0: self.plot.do_plot() print "CONVERT!!!!!!!!!!!",type(self.plot.plot_token.key_units) self.set_border_width(10) self.set_title("Compare") self.set_icon_from_file(os.path.join(get_image_file_path(),"image.jpg")) self.connect('key_press_event', self.on_key_press_event) self.show()