def on_selection_changed(self): if len(self.selectedItems())>0: item=self.selectedItems()[0] if type(item)!=None: file_name=self.decode_name(item.text()) if file_name==None: return self.file_path=os.path.join(self.path, file_name) full_path=self.file_path if (file_name.endswith(".dat")==True): state=dat_file() get_plot_file_info(state,full_path) summary="<big><b>"+file_name+"</b></big><br><br>"+_("title")+": "+state.title+"<br>"+_("x axis")+": "+state.x_label+" ("+latex_to_html(state.x_units)+")<br>"+_("y axis")+": "+state.data_label+" ("+latex_to_html(state.data_units)+")<br><br><big><b>"+_("Double click to open")+"</b></big>" help_window().help_set_help(["dat_file.png",summary]) if file_name.endswith("equilibrium"): state=dat_file() get_plot_file_info(state,full_path) summary="<big><b>"+_("equilibrium")+"</b></big><br><br>"+_("This contains the simulation output at 0V in the dark.") help_window().help_set_help(["folder.png",summary]) #if os.path.isdir(full_path)==True: if is_mat_file(full_path)==True: summary="<b><big>"+file_name+"</b></big><br>" ref_path=os.path.join(full_path,"n.ref") ref=get_ref_text(ref_path) if ref!=None: summary=summary+ref help_window().help_set_help(["organic_material",summary])
def on_item_activated(self,item): text=item.text() if text=="..": if self.path==self.root_dir: self.set_path("/gpvdmroot") else: old_path=self.path self.set_path(os.path.dirname(self.path)) print(self.path,old_path,os.path.dirname(self.path)) if old_path==self.path: self.set_path("/gpvdmroot") self.fill_store() return decode=self.decode_name(text) if decode.startswith("http"): webbrowser.open(decode) return elif decode=="home_dir": self.set_path(get_home_path()) self.fill_store() return elif decode=="desktop_dir": self.set_path(get_desktop_path()) self.fill_store() return elif decode=="gpvdm_configure": self.set_path("/gpvdmroot/gpvdm_configure") self.fill_store() return elif decode=="music_dir": self.set_path(get_music_path()) self.fill_store() return elif decode=="downloads_dir": self.set_path(get_downloads_path()) self.fill_store() return elif decode=="simulation_dir": self.set_path(get_sim_path()) self.fill_store() return elif decode.startswith("mount_point")==True: point=decode.split("::::") self.set_path(point[1]) self.fill_store() return elif decode=="gpvdm_cluster_config": self.win=cluster_config_window(self) self.win.show() return elif decode=="gpvdm_language_config": self.config_window=class_config_window() from tab_lang import language_tab_class self.config_window.files=[ ] self.config_window.description=[] self.config_window.init() lang_tab=language_tab_class() self.config_window.notebook.addTab(lang_tab,_("Language")) self.config_window.show() return elif decode=="gpvdm_solver_config": self.config_window=class_config_window() self.config_window.files=["math.inp"] self.config_window.description=[_("Solver configuration")] self.config_window.init() self.config_window.show() return elif decode=="gpvdm_led_config": self.config_window=class_config_window() self.config_window.files=["led.inp"] self.config_window.description=[_("LED")] self.config_window.init() self.config_window.show() return elif decode=="gpvdm_dump_config": self.config_window=class_config_window() self.config_window.files=["dump.inp"] self.config_window.description=[_("Output files")] self.config_window.init() self.config_window.show() return elif decode=="gpvdm_gui_config": self.config_window=class_config_window() self.config_window.files=["config.inp"] self.config_window.description=[_("GUI configuration"),] self.config_window.init() self.config_window.show() return elif decode=="gpvdm_thermal_config": self.config_window=class_config_window() self.config_window.files=["thermal.inp"] self.config_window.description=[_("Thermal")] self.config_window.init() self.config_window.show() return elif decode=="gpvdm_server_config": self.config_window=class_config_window() self.config_window.files=["server.inp"] self.config_window.description=[_("Server configuration")] self.config_window.init() self.config_window.show() return full_path=os.path.join(self.path,decode) if is_mat_file(full_path)==True: print("mat file!!") from materials_main import materials_main self.mat_window=materials_main(full_path) self.mat_window.show() return if os.path.isfile(full_path)==True: self.file_path=full_path if self.open_own_files==True: if os.path.basename(full_path)=="sim_info.dat": self.sim_info_window=sim_info(full_path) self.sim_info_window.show() self.reject.emit() return elif isfiletype(full_path,"dat")==True: plot_gen([full_path],[],"auto") self.reject.emit() return else: desktop_open(full_path) self.reject.emit() return # else: # self.accept.emit() else: self.accept.emit() return else: if os.path.isfile(os.path.join(full_path,"mat.inp"))==True: self.file_path=full_path gpvdm_file_type=inp_get_token_value(os.path.join(full_path,"mat.inp"), "#gpvdm_file_type") if gpvdm_file_type=="spectra": from spectra_main import spectra_main self.mat_window=spectra_main(full_path) self.mat_window.show() self.accept.emit() else: self.set_path(full_path) #self.path = full_path self.fill_store()
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()