def load_ref(file_name): r = ref() #we could have zipped the file archive = os.path.basename(os.path.dirname(file_name)) + ".zip" file_name = os.path.splitext(file_name)[0] + ".ref" #if os.path.isfile(file_name)==False: # return None lines = inp_load_file(file_name, archive=archive) #print(file_name,lines) if lines == False: return None text = "" r.website = inp_get_token_value_from_list(lines, "#ref_website") if r.website == None: r.website = "" r.group = inp_get_token_value_from_list(lines, "#ref_research_group") if r.group == None: r.group = "" r.author = inp_get_token_value_from_list(lines, "#ref_authors") if r.author == None: r.author = "" r.journal = inp_get_token_value_from_list(lines, "#ref_jounral") if r.journal == None: r.journal = "" r.title = inp_get_token_value_from_list(lines, "#ref_title") if r.title == None: r.title = "" r.volume = inp_get_token_value_from_list(lines, "#ref_volume") if r.volume == None: r.volume = "" r.pages = inp_get_token_value_from_list(lines, "#ref_pages") if r.pages == None: r.pages = "" r.year = inp_get_token_value_from_list(lines, "#ref_year") if r.year == None: r.year = "" r.doi = inp_get_token_value_from_list(lines, "#ref_doi") if r.doi == None: r.doi = "" r.unformatted = inp_get_token_value_from_list(lines, "#ref_unformatted") if r.unformatted == None: r.unformatted = "" return r
def load_config(self): lines = [] lines = inp_load_file(self.config_file_path) if lines != False: self.file_name = inp_get_token_value_from_list( lines, "#import_file_path") if os.path.isfile(self.file_name) == False: return False self.x_combo.setCurrentIndex( int(inp_get_token_value_from_list(lines, "#import_x_combo_pos"))) self.y_combo.setCurrentIndex( int(inp_get_token_value_from_list(lines, "#import_y_combo_pos"))) self.title_entry.setText( inp_get_token_value_from_list(lines, "#import_title")) self.xlabel_entry.setText( inp_get_token_value_from_list(lines, "#import_xlabel")) self.ylabel_entry.setText( inp_get_token_value_from_list(lines, "#import_ylabel")) self.area_entry.setText( inp_get_token_value_from_list(lines, "#import_area")) self.x_spin.setValue( int(inp_get_token_value_from_list(lines, "#import_x_spin"))) self.y_spin.setValue( int(inp_get_token_value_from_list(lines, "#import_y_spin"))) return True else: return False
def load_ref(file_name): r = ref() file_name = os.path.splitext(file_name)[0] + ".ref" if os.path.isfile(file_name) == False: return None lines = inp_load_file(file_name) if lines != False: text = "" r.group = inp_get_token_value_from_list(lines, "#ref_research_group") if r.group == None: r.group = "" r.author = inp_get_token_value_from_list(lines, "#ref_authors") if r.author == None: r.author = "" r.journal = inp_get_token_value_from_list(lines, "#ref_jounral") if r.journal == None: r.journal = "" r.title = inp_get_token_value_from_list(lines, "#ref_title") if r.title == None: r.title = "" r.volume = inp_get_token_value_from_list(lines, "#ref_volume") if r.volume == None: r.volume = "" r.pages = inp_get_token_value_from_list(lines, "#ref_pages") if r.pages == None: r.pages = "" r.year = inp_get_token_value_from_list(lines, "#ref_year") if r.year == None: r.year = "" r.doi = inp_get_token_value_from_list(lines, "#ref_doi") if r.doi == None: r.doi = "" r.unformatted = inp_get_token_value_from_list(lines, "#ref_unformatted") if r.unformatted == None: r.unformatted = "" return r
def load_config(self): lines=[] lines=inp_load_file(self.config_file_path) if lines!=False: self.file_names=[inp_get_token_value_from_list(lines,"#import_file_path")] if os.path.isfile(self.file_names[0])==False: return False self.disable_callbacks=True self.x_combo.setCurrentIndex(int(inp_get_token_value_from_list(lines,"#import_x_combo_pos"))) self.data_combo.setCurrentIndex(int(inp_get_token_value_from_list(lines,"#import_data_combo_pos"))) self.title_entry.setText(inp_get_token_value_from_list(lines,"#import_title")) self.xlabel_entry.setText(inp_get_token_value_from_list(lines,"#import_xlabel")) self.data_label_entry.setText(inp_get_token_value_from_list(lines,"#import_data_label")) self.area_entry.setText(inp_get_token_value_from_list(lines,"#import_area")) self.x_spin.setValue(int(inp_get_token_value_from_list(lines,"#import_x_spin"))) self.data_spin.setValue(int(inp_get_token_value_from_list(lines,"#import_data_spin"))) self.x_invert.setChecked(str2bool(inp_get_token_value_from_list(lines,"#import_x_invert"))) self.data_invert.setChecked(str2bool(inp_get_token_value_from_list(lines,"#import_data_invert"))) self.disable_callbacks=False self.update() return True else: return False
def fill_store(self): #partitions = #for p in partitions: # print(p.mountpoint, psutil.disk_usage(p.mountpoint).percent) #print(expanduser("~")) self.file_list=[] #print(self.path) if self.path=="/gpvdmroot": itm=file_store() itm.file_name="simulation_dir" itm.icon="si" itm.display_name=_("Simulation") self.file_list.append(itm) itm=file_store() itm.file_name="home_dir" itm.icon="user-home" itm.display_name=_("Home") self.file_list.append(itm) if get_desktop_path()!=False: itm=file_store() itm.file_name="desktop_dir" itm.icon="desktop" itm.display_name=_("Desktop") self.file_list.append(itm) if get_downloads_path()!=False: itm=file_store() itm.file_name="downloads_dir" itm.icon="folder-download" itm.display_name=_("Downloads") self.file_list.append(itm) itm=file_store() itm.file_name="gpvdm_configure" itm.icon="cog" itm.display_name=_("Configure") self.file_list.append(itm) for p in psutil.disk_partitions(): name=p.mountpoint if running_on_linux()==True: name=os.path.basename(name) if name=="": name="/" itm=file_store() itm.file_name="mount_point::::"+p.mountpoint itm.icon="drive-harddisk" itm.display_name=name self.file_list.append(itm) elif self.path=="/gpvdmroot/gpvdm_configure": itm=file_store() itm.file_name="gpvdm_cluster_config" itm.icon="server" itm.display_name=_("Cluster") self.file_list.append(itm) itm=file_store() itm.file_name="gpvdm_language_config" itm.icon="internet-chat" itm.display_name=_("Language") self.file_list.append(itm) itm=file_store() itm.file_name="gpvdm_solver_config" itm.icon="accessories-calculator" itm.display_name=_("Solver") self.file_list.append(itm) itm=file_store() itm.file_name="gpvdm_led_config" itm.icon="oled" itm.display_name=_("LED") self.file_list.append(itm) itm=file_store() itm.file_name="gpvdm_dump_config" itm.icon="hdd_custom" itm.display_name=_("Output files") self.file_list.append(itm) itm=file_store() itm.file_name="gpvdm_gui_config" itm.icon="applications-interfacedesign" itm.display_name=_("GUI configuration") self.file_list.append(itm) itm=file_store() itm.file_name="gpvdm_thermal_config" itm.icon="thermal" itm.display_name=_("Thermal") self.file_list.append(itm) itm=file_store() itm.file_name="gpvdm_server_config" itm.icon="cpu" itm.display_name=_("Server") self.file_list.append(itm) else: path=self.path if os.path.isdir(path)==False: error_dlg(self,_("The directory is gone, so I can't open it. Did you delete it?")+" "+path) return else: all_files=os.listdir(path) all_files.sort() for fl in all_files: #print(fl) file_name=os.path.join(path, fl) itm=file_store() if is_mat_file(file_name)==True: if fl.endswith(".zip"): fl=fl[:-4] itm.file_name=fl itm.icon="organic_material" #if it is a directory if os.path.isdir(file_name): gpvdm_file_type=inp_get_token_value(os.path.join(file_name,"mat.inp"), "#gpvdm_file_type") if gpvdm_file_type=="spectra": itm.file_name=fl itm.icon="spectra" else: show_dir=True if os.path.isfile(os.path.join(file_name,"gpvdm_gui_config.inp"))==True: show_dir=False if show_dir==True: itm.file_name=fl itm.icon="folder" else: #append=False ext=os.path.splitext(file_name) if len(ext)>1: ext=ext[1].lower() else: ext="" if (ext==".dat"): read_ok=False try: f = open(file_name, 'rb') text = f.readline() f.close() read_ok=True except: pass if read_ok==True: if len(text)>0: if text[len(text)-1]==10: text=text[:-1] if text==b"#gpvdm": itm.file_name=fl itm.icon="dat_file" elif (ext==".inp") and self.show_inp_files==True: itm.file_name=fl itm.icon="text-x-generic" elif (ext==".omat"): itm.file_name=fl itm.icon="omat" elif os.path.basename(file_name)=="sim_info.dat": itm.file_name=fl itm.icon="info" elif file_name.endswith("default.gpvdm")==False and file_name.endswith(".gpvdm"): lines=[] lines=inp_load_file("info.inp",archive=file_name) if lines!=False: itm.file_name=fl itm.display_name=inp_get_token_value_from_list(lines, "#info_name")+" ("+fl+")" icon_name=inp_get_token_value_from_list(lines, "#info_icon") itm.icon=icon_name itm.hidden=str2bool(inp_get_token_value_from_list(lines, "#info_hidden")) a=zip_lsdir(file_name,sub_dir="fs/") #,zf=None,sub_dir=None if len(a)!=0: for fname in a: lines=ret=read_lines_from_archive(file_name,"fs/"+fname) if lines!=False: web_link=inp_get_token_value_from_list(lines, "#web_link") name=inp_get_token_value_from_list(lines, "#name") sub_itm=file_store() sub_itm.icon="internet-web-browser" sub_itm.display_name=name sub_itm.file_name=web_link sub_itm.hidden=False self.file_list.append(sub_itm) if itm.icon=="": if icon_get(ext)!=False: itm.icon=ext itm.file_name=fl else: itm.icon="misc" itm.file_name=fl if itm.display_name=="": itm.display_name=itm.file_name if file_name.endswith("sim.gpvdm")==False: self.file_list.append(itm) for i in range(0,len(self.file_list)): if self.file_list[i].file_name=="p3htpcbm.gpvdm": self.file_list.insert(0, self.file_list.pop(i)) break self.paint()
def fill_store(self): self.file_list = [] if os.path.isdir(self.path) == False: error_dlg( self, _("The directory is gone, so I can't open it. Did you delete it?" ) + " " + self.path) return all_files = os.listdir(self.path) #all_files.sort() for fl in all_files: file_name = os.path.join(self.path, fl) itm = file_store() #if it is a directory if os.path.isdir(file_name): gpvdm_file_type = inp_get_token_value( os.path.join(file_name, "mat.inp"), "#gpvdm_file_type") if gpvdm_file_type == "spectra": itm.file_name = fl itm.icon = "spectra" elif gpvdm_file_type == "mat": itm.file_name = fl itm.icon = "organic_material" else: show_dir = True if os.path.isfile( os.path.join(file_name, "gpvdm_gui_config.inp")) == True: show_dir = False if show_dir == True: itm.file_name = fl itm.icon = "folder" else: #append=False if (file_name.endswith(".dat") == True): f = open(file_name, 'rb') text = f.readline() f.close() #text=text.encode('utf-8').strip() #print(text) #text=text.rstrip() if len(text) > 0: if text[len(text) - 1] == 10: text = text[:-1] if text == b"#gpvdm": itm.file_name = fl itm.icon = "dat_file" if (file_name.endswith(".inp") == True) and self.show_inp_files == True: itm.file_name = fl itm.icon = "text-x-generic" if (file_name.endswith(".omat") == True): itm.file_name = fl itm.icon = "omat" if file_name.endswith(".pdf") == True: itm.file_name = fl itm.icon = "pdf" if file_name.endswith(".jpg") == True: itm.file_name = fl itm.icon = "image-x-generic" if os.path.basename(file_name) == "sim_info.dat": itm.file_name = fl itm.icon = "info" if file_name.endswith( "default.gpvdm") == False and file_name.endswith( ".gpvdm"): lines = [] lines = inp_load_file("info.inp", archive=file_name) if lines != False: itm.file_name = fl itm.display_name = inp_get_token_value_from_list( lines, "#info_name") + " (" + fl + ")" icon_name = inp_get_token_value_from_list( lines, "#info_icon") itm.icon = icon_name itm.hidden = str2bool( inp_get_token_value_from_list( lines, "#info_hidden")) a = zip_lsdir(file_name, sub_dir="fs/") #,zf=None,sub_dir=None if len(a) != 0: for fname in a: lines = ret = read_lines_from_archive( file_name, "fs/" + fname) if lines != False: web_link = inp_get_token_value_from_list( lines, "#web_link") name = inp_get_token_value_from_list( lines, "#name") sub_itm = file_store() sub_itm.icon = "internet-web-browser" sub_itm.display_name = name sub_itm.file_name = web_link sub_itm.hidden = False self.file_list.append(sub_itm) if itm.display_name == "": itm.display_name = itm.file_name self.file_list.append(itm) for i in range(0, len(self.file_list)): if self.file_list[i].file_name == "p3htpcbm.gpvdm": self.file_list.insert(0, self.file_list.pop(i)) break self.paint()
def fill_store(self): self.file_list = [] path = self.path all_files = self.listdir() #all_files.sort() if path.endswith("dynamic") == True: self.set_list_view() else: self.set_grid_view() for itm in all_files: #print(fl) #if it is a directory file_name = os.path.join(path, itm.file_name) if itm.isdir == True: if itm.type == "spectra": itm.icon = "spectra" elif itm.type == "shape": itm.icon = "shape" elif itm.type == "snapshots": itm.icon = "cover_flow" elif itm.type == "light": itm.icon = "optics2" elif itm.type == "material": itm.icon = "organic_material" elif itm.type == "emission": itm.icon = "emission" elif itm.type == "backup_main": itm.icon = "backup" elif itm.type == "multi_plot_dir": itm.icon = "multi_plot_dir" elif itm.type == "backup": itm.icon = "backup" elif itm.type == "scan_dir": itm.icon = "scan" elif itm.type == "parameter_dir": itm.icon = "star" elif itm.type == "cache": itm.hidden = True else: itm.icon = "folder" else: #append=False ext = os.path.splitext(file_name) if len(ext) > 1: ext = ext[1].lower() else: ext = "" if (ext == ".dat"): text = peek_data(file_name) if itm.file_name in [ "theta_small_x.dat", "theta_small_z.dat", "theta_Y.dat", "theta_small_y.dat", "theta_X.dat", "theta_Z.dat", "theta_RGB.dat" ]: itm.icon = "color" elif text.startswith(b"#multiplot"): itm.icon = "multiplot" elif str(text).count("#type poly") > 0: itm.icon = "vector" elif str(text).count("#gobj") > 0: itm.icon = "vector" elif text.startswith(b"#"): itm.icon = "dat_file" else: itm.hidden = True if (ext == ".chk"): itm.hidden = True elif (ext == ".inp"): if self.show_inp_files == True: itm.icon = "text-x-generic" else: itm.hidden = True elif (ext == ".gmat"): itm.icon = "gmat" elif os.path.basename(file_name) == "sim_info.dat": itm.icon = "info" elif file_name.endswith( "default.gpvdm") == False and file_name.endswith( ".gpvdm"): text = peek_data(file_name) if text.startswith(b"gpvdmenc"): itm.hidden = True itm.icon = "sim_lock" else: lines = [] lines = inp_load_file("info.inp", archive=file_name) if lines != False: itm.display_name = inp_get_token_value_from_list( lines, "#info_name") icon_name = inp_get_token_value_from_list( lines, "#info_icon") itm.icon = icon_name itm.hidden = str2bool( inp_get_token_value_from_list( lines, "#info_hidden")) a = zip_lsdir( file_name, sub_dir="fs/") #,zf=None,sub_dir=None if len(a) != 0: for fname in a: lines = ret = read_lines_from_archive( file_name, "fs/" + fname) if lines != False: web_link = inp_get_token_value_from_list( lines, "#web_link") name = inp_get_token_value_from_list( lines, "#name") sub_itm = file_store() sub_itm.icon = "internet-web-browser" sub_itm.display_name = name sub_itm.file_name = web_link sub_itm.hidden = False self.file_list.append(sub_itm) if itm.icon == "": if icon_get(ext) != False: itm.icon = ext else: itm.icon = "misc" if itm.display_name == "": itm.display_name = itm.file_name if len(self.show_only) != 0: if itm.type not in self.show_only: itm.hidden = True self.file_list.append(itm) for i in range(0, len(self.file_list)): if self.file_list[i].file_name == "p3htpcbm.gpvdm": self.file_list.insert(0, self.file_list.pop(i)) if self.file_list[i].file_name == "perovskite.gpvdm": self.file_list.insert(1, self.file_list.pop(i)) if self.file_list[i].file_name == "ofet.gpvdm": self.file_list.insert(2, self.file_list.pop(i)) if self.file_list[i].file_name == "oled.gpvdm": self.file_list.insert(3, self.file_list.pop(i)) self.paint()