def dlg_export(parent): dialog = QFileDialog(parent) dialog.setWindowTitle(_("Export the simulation as")) dialog.setAcceptMode(QFileDialog.AcceptSave) types=[] types.append(_("gpvdm archive input+output files")+" (*.gpvdm)") types.append(_("gpvdm archive input files")+" (*.gpvdm)") types.append(_("optical materials database")+" (*.zip)") types.append(_("pdf file")+" (*.pdf)") types.append(_("jpg image")+" (*.jpg)") types.append(_("tex file")+" (*.tex)") types.append(_("Excel file")+" (*.xlsx)") dialog.setNameFilters(types) dialog.setFileMode(QFileDialog.ExistingFile) dialog.setAcceptMode(QFileDialog.AcceptSave) if dialog.exec_() == QDialog.Accepted: file_name = dialog.selectedFiles()[0] #print(dialog.selectedNameFilter()) if dialog.selectedNameFilter()==_("gpvdm archive input+output files")+" (*.gpvdm)": export_archive(file_name,True) elif dialog.selectedNameFilter()==_("gpvdm archive input files")+" (*.gpvdm)": export_archive(file_name,False) elif dialog.selectedNameFilter()==_("optical materials database")+" (*.zip)": export_materials(file_name) elif dialog.selectedNameFilter()==_("pdf file")+" (*.pdf)" or dialog.selectedNameFilter()==_("jpg image")+" (*.jpg)" or dialog.selectedNameFilter()==_("tex file")+" (*.tex)": export_as(file_name) elif dialog.selectedNameFilter()==_("Excel file")+" (*.xlsx)": gen_workbook(get_sim_path(),set_file_ext(file_name,".xlsx"))
def dlg_export(parent): dialog = QFileDialog(parent) dialog.setWindowTitle(_("Export the simulation as")) dialog.setAcceptMode(QFileDialog.AcceptSave) types=[] types.append(_("gpvdm archive input+output files (*.gpvdm)")) types.append(_("gpvdm archive input files (*.gpvdm)")) types.append(_("optical materials database (*.zip)")) types.append(_("pdf file (*.pdf)")) types.append(_("jpg image (*.jpg)")) types.append(_("tex file (*.tex)")) types.append(_("Excel file (*.xlsx)")) dialog.setNameFilters(types) dialog.setFileMode(QFileDialog.ExistingFile) dialog.setAcceptMode(QFileDialog.AcceptSave) if dialog.exec_() == QDialog.Accepted: file_name = dialog.selectedFiles()[0] if dialog.selectedNameFilter()==_("gpvdm archive input+output files (*.gpvdm)"): export_archive(file_name,True) elif dialog.selectedNameFilter()==_("gpvdm archive input files (*.gpvdm)"): export_archive(file_name,False) elif dialog.selectedNameFilter()==_("optical materials database (*.zip)"): export_materials(file_name) elif dialog.selectedNameFilter()==_("pdf file (*.pdf)") or dialog.selectedNameFilter()==_("jpg image (*.jpg)") or dialog.selectedNameFilter()==_("tex file (*.tex)"): export_as(file_name) elif dialog.selectedNameFilter()==_("Excel file (*.xlsx)"): gen_workbook(os.getcwd(),file_name)
def callback_dbus(self,data_in): if data_in.startswith("hex"): data_in=data_in[3:] data=codecs.decode(data_in, 'hex') data=data.decode('ascii') if data.startswith("lock"): if len(self.jobs)==0: print(_("I did not think I was running any jobs")) self.stop() else: if self.finished_jobs.count(data)==0: job=int(data[4:]) self.base_job_finished(job) self.finished_jobs.append(data) make_work_book=inp_get_token_value(os.path.join(get_sim_path(),"dump.inp"),"#dump_workbook") if make_work_book!=None: if str2bool(make_work_book)==True: if gen_workbook(self.jobs[job].path,os.path.join(self.jobs[job].path,"data.xlsx"))==False: self.excel_workbook_gen_error=self.excel_workbook_gen_error or True self.progress_window.set_fraction(float(self.jobs_run)/float(len(self.jobs))) if (self.jobs_run==len(self.jobs)): self.stop() elif (data=="pulse"): if len(self.jobs)==1: splitup=data.split(":") if len(splitup)>1: text=data.split(":")[1] self.progress_window.set_text(text) #self.progress_window.progress.set_pulse_step(0.01) self.progress_window.pulse() elif (data.startswith("enable_pulse")): splitup=data.split(":") if len(splitup)>1: value=str2bool(data.split(":")[1]) self.progress_window.enable_pulse(value) elif (data.startswith("percent")): if len(self.jobs)==1: splitup=data.split(":") if len(splitup)>1: frac=float(data.split(":")[1]) self.progress_window.set_fraction(frac) elif (data.startswith("text")): if len(self.jobs)==1: splitup=data.split(":") if len(splitup)>1: self.progress_window.set_text(data.split(":")[1]) elif (data.startswith("fit_run")): elapsed_time = time.time() - self.gui_update_time if elapsed_time>5: self.gui_update_time=time.time() if self.fit_update!=None: self.fit_update()
def dlg_export_xls(parent): dialog = QFileDialog(parent) dialog.setWindowTitle(_("Export to xls file")) dialog.setAcceptMode(QFileDialog.AcceptSave) types=[] types.append(_("Excel file")+" (*.xlsx)") dialog.setNameFilters(types) dialog.setFileMode(QFileDialog.ExistingFile) dialog.setAcceptMode(QFileDialog.AcceptSave) if dialog.exec_() == QDialog.Accepted: file_name = dialog.selectedFiles()[0] #print(dialog.selectedNameFilter()) if dialog.selectedNameFilter()==_("Excel file")+" (*.xlsx)": gen_workbook(get_sim_path(),set_file_ext(file_name,".xlsx"))
def callback_dbus(self,data_in): if data_in.startswith("hex"): data_in=data_in[3:] data=codecs.decode(data_in, 'hex') data=data.decode('ascii') print("rx:",data) if data.startswith("lock"): if self.finished_jobs.count(data)==0: job=int(data[4:]) self.finished_jobs.append(data) gen_workbook(self.jobs[job],os.path.join(self.jobs[job],"data.xlsx")) self.jobs_run=self.jobs_run+1 self.jobs_running=self.jobs_running-1 self.progress_window.set_fraction(float(self.jobs_run)/float(len(self.jobs))) self.run_jobs() if (self.jobs_run==len(self.jobs)): self.stop() elif (data=="pulse"): if len(self.jobs)==1: splitup=data.split(":") if len(splitup)>1: text=data.split(":")[1] self.progress_window.set_text(text) #self.progress_window.progress.set_pulse_step(0.01) self.progress_window.pulse() elif (data.startswith("percent")): if len(self.jobs)==1: splitup=data.split(":") if len(splitup)>1: frac=float(data.split(":")[1]) self.progress_window.set_fraction(frac) elif (data.startswith("text")): if len(self.jobs)==1: splitup=data.split(":") if len(splitup)>1: self.progress_window.set_text(data.split(":")[1])
def export_as(output): tex=True dollar="$" col=" & " eol=" \\\\" ext= os.path.splitext(output)[1] line="" if ext==".xlsx": gen_workbook(os.getcwd(),output) elif (ext==".pdf") or (ext==".jpg") or (ext==".tex") or (ext==".csv"): if ext==".csv": tex=False dollar="" col="\t" eol="" lines=[] if tex==True: line=line+"\\documentclass{article}\n" line=line+"\\providecommand{\\e}[1]{\\ensuremath{\\times 10^{#1}}}\n" line=line+"\\begin{document}\n" line=line+"\\pagenumbering{gobble}\n" line=line+"\n" files=[] f_list=glob.iglob(os.path.join("./", "dos*.inp")) for in_file in f_list: files.append(in_file) print(files) if tex==True: line=line+"\\begin{table}[H]\n" line=line+"\\begin{center}\n" line=line+" \\begin{tabular}{lll}\n" line=line+" \\hline\n" line=line+" Parameter"+col+"label"+col+"unit "+eol+"\n" if tex==True: line=line+" \\hline\n" dos_lines=[] for i in range(0,len(files)): lines=[] inp_load_file(lines,files[i]) dos_lines.append(lines) t=tokens() for i in range(0,len(dos_lines[0]),2): my_token=t.find(dos_lines[0][i]) if my_token!=False: number="" if my_token.number_type=="e": for ii in range(0,len(files)): if len(files)>0: sub="_{"+str(ii)+"}" else: sub="" if dos_lines[0][i+1]!=dos_lines[ii][i+1] or ii==0: if tex==True: number=to_exp(dos_lines[ii][i+1]) else: number=dos_lines[ii][i+1] line=line+my_token.info+sub+col+dollar+number+dollar+col+dollar+pygtk_to_latex_subscript(my_token.units)+dollar+eol+"\n" if tex==True: line=line+" \\hline\n" line=line+"\\end{tabular}\n" line=line+"\\end{center}\n" line=line+"\\caption{Density of states}\n" line=line+"\\end{table}\n" line=line+"\n" files=["./device.inp","./led.inp","./device_epitaxy.inp", "./stark.inp", "./materials/redf/fit.inp", "./materials/redf/patch.inp"] names=["Device", "LED","Device Epitaxy","Stark","Fit redf","Fit patch"] if tex==True: line=line+"\\begin{table}[H]\n" line=line+"\\begin{center}\n" line=line+" \\begin{tabular}{lll}\n" line=line+" \\hline\n" line=line+" Parameter"+col+"label"+col+"unit "+eol+"\n" if tex==True: line=line+" \\hline\n" config_lines=[] cur_file=0 inp_load_file(config_lines,"latex_export_info.inp") for cur_file in range(0,len(files)): if os.path.isfile(files[cur_file])==True: inp_load_file(lines,files[cur_file]) t=tokens() for i in range(0,len(lines),2): dump_token=inp_search_token_value(config_lines, lines[i]) if dump_token=="1": my_token=t.find(lines[i]) if my_token!=False: if my_token.number_type=="e": number="" if tex==True: #print lines #print lines[i] number=to_exp(dos_lines[ii][i+1]) else: number=dos_lines[ii][i+1] line=line+my_token.info+col+dollar+number+dollar+col+dollar+pygtk_to_latex_subscript(my_token.units)+dollar+eol+"\n" if tex==True: line=line+" \\hline\n" line=line+"\\end{tabular}\n" line=line+"\\end{center}\n" line=line+"\\caption{"+names[cur_file]+"}\n" line=line+"\\end{table}\n" line=line+"\n" if tex==True: line=line+"\\end{document}\n" text_file = open("doc.tex", "w") text_file.write(line) text_file.close() if (ext==".pdf"): os.system("latex -interaction=batchmode doc") os.system("dvipdf doc.dvi") os.system("mv doc.pdf "+output) if (ext==".jpg"): os.system("latex -interaction=batchmode doc") os.system("convert -trim -bordercolor White -border 20x10 +repage -density 300 doc.dvi doc.jpg") os.system("mv doc.jpg "+output) if (ext==".tex"): os.system("mv doc.tex "+output) if (ext==".csv"): os.system("mv doc.tex "+output)
def export_as(output): tex = True dollar = "$" col = " & " eol = " \\\\" ext = os.path.splitext(output)[1] line = "" print(ext, output) if ext == ".xlsx": gen_workbook(get_sim_path(), output) elif (ext == ".pdf") or (ext == ".jpg") or (ext == ".tex") or (ext == ".csv"): print(ext) if ext == ".csv": tex = False dollar = "" col = "\t" eol = "" lines = [] if tex == True: line = line + "\\documentclass{article}\n" line = line + "\\providecommand{\\e}[1]{\\ensuremath{\\times 10^{#1}}}\n" line = line + "\\begin{document}\n" line = line + "\\pagenumbering{gobble}\n" line = line + "\n" files = [] f_list = glob.iglob(os.path.join("./", "dos*.inp")) for in_file in f_list: files.append(in_file) print(files) if tex == True: line = line + "\\begin{table}[H]\n" line = line + "\\begin{center}\n" line = line + " \\begin{tabular}{lll}\n" line = line + " \\hline\n" line = line + " Parameter" + col + "label" + col + "unit " + eol + "\n" if tex == True: line = line + " \\hline\n" dos_lines = [] for i in range(0, len(files)): lines = [] lines = inp_load_file(files[i]) dos_lines.append(lines) t = tokens() for i in range(0, len(dos_lines[0]), 2): my_token = t.find(dos_lines[0][i]) if my_token != False: number = "" if my_token.number_type == "e": for ii in range(0, len(files)): if len(files) > 0: sub = "_{" + str(ii) + "}" else: sub = "" if dos_lines[0][i + 1] != dos_lines[ii][i + 1] or ii == 0: if tex == True: number = to_exp(dos_lines[ii][i + 1]) else: number = dos_lines[ii][i + 1] line = line + my_token.info + sub + col + dollar + number + dollar + col + dollar + pygtk_to_latex_subscript( my_token.units) + dollar + eol + "\n" if tex == True: line = line + " \\hline\n" line = line + "\\end{tabular}\n" line = line + "\\end{center}\n" line = line + "\\caption{Density of states}\n" line = line + "\\end{table}\n" line = line + "\n" files = [ "./device.inp", "./led.inp", "./ray.inp", "./device_epitaxy.inp", "./stark.inp", "./materials/redf/fit.inp", "./materials/redf/patch.inp" ] names = [ "Device", "LED", "Ray", "Device Epitaxy", "Stark", "Fit redf", "Fit patch" ] if tex == True: line = line + "\\begin{table}[H]\n" line = line + "\\begin{center}\n" line = line + " \\begin{tabular}{lll}\n" line = line + " \\hline\n" line = line + " Parameter" + col + "label" + col + "unit " + eol + "\n" if tex == True: line = line + " \\hline\n" config_lines = [] cur_file = 0 config_lines = inp_load_file("latex_export_info.inp") for cur_file in range(0, len(files)): if os.path.isfile(files[cur_file]) == True: lines = inp_load_file(files[cur_file]) t = tokens() for i in range(0, len(lines), 2): dump_token = inp_search_token_value(config_lines, lines[i]) if dump_token == "1": my_token = t.find(lines[i]) if my_token != False: if my_token.number_type == "e": number = "" if tex == True: #print lines #print lines[i] number = to_exp(dos_lines[ii][i + 1]) else: number = dos_lines[ii][i + 1] line = line + my_token.info + col + dollar + number + dollar + col + dollar + pygtk_to_latex_subscript( my_token.units) + dollar + eol + "\n" if tex == True: line = line + " \\hline\n" line = line + "\\end{tabular}\n" line = line + "\\end{center}\n" line = line + "\\caption{" + names[cur_file] + "}\n" line = line + "\\end{table}\n" line = line + "\n" if tex == True: line = line + "\\end{document}\n" text_file = open("doc.tex", "w") text_file.write(line) print(line) text_file.close() if (ext == ".pdf"): os.system("latex -interaction=batchmode doc") os.system("dvipdf doc.dvi") os.system("mv doc.pdf " + output) if (ext == ".jpg"): os.system("latex -interaction=batchmode doc") os.system( "convert -trim -bordercolor White -border 20x10 +repage -density 300 doc.dvi doc.jpg" ) os.system("mv doc.jpg " + output) if (ext == ".tex"): os.system("mv doc.tex " + output) if (ext == ".csv"): os.system("mv doc.tex " + output)