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 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) full_path = os.path.join(self.path, decode.file_name) if decode.file_name.startswith("http"): webbrowser.open(decode) return elif decode.file_name == "home_dir": self.set_path(get_home_path()) self.fill_store() return elif decode.file_name == "desktop_dir": self.set_path(get_desktop_path()) self.fill_store() return elif decode.file_name == "gpvdm_configure": self.set_path("/gpvdmroot/gpvdm_configure") self.fill_store() return elif decode.file_name == "music_dir": self.set_path(get_music_path()) self.fill_store() return elif decode.file_name == "downloads_dir": self.set_path(get_downloads_path()) self.fill_store() return elif decode.file_name == "simulation_dir": self.set_path(get_sim_path()) self.fill_store() return elif decode.file_name.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.file_name == "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.file_name == "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.file_name == "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.file_name == "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.file_name == "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 elif decode.file_name == "gpvdm_key": from lock_key_manager import lock_key_manager from msg_dlg import msg_dlg self.lock_key_manager = lock_key_manager( show_text=False, override_text=_("Please enter your license key:")) ret = self.lock_key_manager.run() if ret == QDialog.Accepted: msgBox = msg_dlg() msgBox.setText("License updated") reply = msgBox.exec_() elif decode.file_name == "gpvdm_cache": from cache import cache self.c = cache() self.c.show() elif decode.type == "scan_dir": from scan_tab import scan_vbox #print(full_path) self.scan_window = scan_vbox(full_path) self.scan_window.show() return elif decode.type == "parameter_dir": self.set_path(full_path) self.fill_store() return dir_type = get_dir_type(full_path) if self.open_own_files == True: self.file_path = full_path if dir_type == "spectra": from spectra_main import spectra_main self.mat_window = spectra_main(full_path) self.mat_window.show() return if dir_type == "shape": from shape_editor import shape_editor self.windows.append(shape_editor(full_path)) self.windows[-1].show() return if dir_type == "light": from optics import class_optical self.optics_window = class_optical() self.optics_window.show() if dir_type == "material": from materials_main import materials_main self.mat_window = materials_main(full_path) self.mat_window.show() return if dir_type == "emission": from emission_main import emission_main self.emission_window = emission_main(full_path) self.emission_window.show() return if dir_type == "snapshots": from cmp_class import cmp_class help_window().help_set_help([ "plot_time.png", _("<big><b>Examine the results in time domain</b></big><br> After you have run a simulation in time domain, if is often nice to be able to step through the simulation and look at the results. This is what this window does. Use the slider bar to move through the simulation. When you are simulating a JV curve, the slider sill step through voltage points rather than time points." ) ]) self.snapshot_window.append(cmp_class(full_path)) self.snapshot_window[-1].show() #print("snapshots!!") return if dir_type == "backup": ret = yes_no_dlg( self, _("Are you sure you want restore this file from the backup, it will overwrite all files in the simulation directory?" ) + "\n\n" + full_path) if ret == True: from backup import backup_restore backup_restore(get_sim_path(), full_path) if dir_type == "file": self.file_path = full_path if os.path.basename(full_path) == "sim_info.dat": self.sim_info_window = sim_info(full_path) self.sim_info_window.show() return if isfiletype(full_path, "dat") == True: text = peek_data(full_path) if text.startswith(b"#multiplot"): my_multiplot = multiplot() my_multiplot.plot(full_path) else: plot_gen([full_path], [], "auto") return if isfiletype(full_path, "gpvdm") == True: return desktop_open(full_path) return #self.reject.emit() if dir_type == "dir" or dir_type == "backup_main" or dir_type == "multi_plot_dir": self.file_path = full_path self.set_path(full_path) self.fill_store() else: self.accept.emit()
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 listdir(self): ret = [] if self.path == "/gpvdmroot": itm = file_store() itm.file_name = "simulation_dir" itm.icon = "si" itm.display_name = _("Simulation") ret.append(itm) itm = file_store() itm.file_name = "home_dir" itm.icon = "user-home" itm.display_name = _("Home") ret.append(itm) if get_desktop_path() != False: itm = file_store() itm.file_name = "desktop_dir" itm.icon = "desktop" itm.display_name = _("Desktop") ret.append(itm) if get_downloads_path() != False: itm = file_store() itm.file_name = "downloads_dir" itm.icon = "folder-download" itm.display_name = _("Downloads") ret.append(itm) itm = file_store() itm.file_name = "gpvdm_configure" itm.icon = "cog" itm.display_name = _("Configure") ret.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 ret.append(itm) elif self.path == "/gpvdmroot/gpvdm_configure": itm = file_store() itm.file_name = "gpvdm_cluster_config" itm.icon = "server" itm.display_name = _("Cluster") ret.append(itm) itm = file_store() itm.file_name = "gpvdm_language_config" itm.icon = "internet-chat" itm.display_name = _("Language") ret.append(itm) itm = file_store() itm.file_name = "gpvdm_solver_config" itm.icon = "accessories-calculator" itm.display_name = _("Solver") ret.append(itm) #itm=file_store() #itm.file_name="gpvdm_led_config" #itm.icon="oled" #itm.display_name=_("LED") #ret.append(itm) itm = file_store() itm.file_name = "gpvdm_dump_config" itm.icon = "hdd_custom" itm.display_name = _("Output files") ret.append(itm) itm = file_store() itm.file_name = "gpvdm_gui_config" itm.icon = "applications-interfacedesign" itm.display_name = _("GUI configuration") ret.append(itm) itm = file_store() itm.file_name = "gpvdm_server_config" itm.icon = "cpu" itm.display_name = _("Server") ret.append(itm) itm = file_store() itm.file_name = "gpvdm_key" itm.icon = "gnome-dialog-password" itm.display_name = _("License") ret.append(itm) itm = file_store() itm.file_name = "gpvdm_cache" itm.icon = "cache" itm.display_name = _("Cache") ret.append(itm) elif self.path.startswith(os.path.join(get_sim_path(), "parameters")) == True: from scan_human_labels import get_scan_human_labels s = get_scan_human_labels() s.ls_dir("/") itm = file_store() itm.file_name = "star" itm.icon = "star" itm.display_name = _("Cache") ret.append(itm) else: files = os.listdir(self.path) for f in files: itm = file_store() itm.file_name = f itm.isdir = os.path.isdir(os.path.join(self.path, f)) itm.type = get_dir_type(os.path.join(self.path, f)) if itm.type != "scan_dir": ret.append(itm) #print(get_sim_path(),self.path) if get_sim_path() == self.path: itm = file_store() itm.file_name = "parameters" itm.type = "parameter_dir" itm.icon = "star" itm.display_name = _("parameters") ret.append(itm) scan = scans_io(get_sim_path()) scans = scan.get_scans() for s in scans: for i in range(0, len(ret)): if ret[i].file_name == s.human_name: ret.pop(i) break itm = file_store() itm.type = "scan_dir" itm.isdir = True itm.file_name = os.path.basename(s.config_file) itm.display_name = s.human_name ret.append(itm) ret = sorted(ret, key=operator.attrgetter('display_name')) #files = sorted(files, key=operator.attrgetter('file_name')) return ret