def calculate_paths(): global share_path global lib_path global materials_path global exe_command global device_lib_path global light_dll_path cal_share_path() cal_lib_path() cal_bin_path() device_lib_path=os.path.join(share_path,"device_lib") materials_path=os.path.join(share_path,"materials") if running_on_linux() == True: if os.path.isfile("./main.c")==True: exe_command=os.path.join(os.getcwd(), "go.o") else: exe_command="opvdm_core" else: if os.path.isfile("opvdm_core.exe")==True: exe_command=os.path.join(os.getcwd(), "opvdm_core.exe") else: exe_command=os.path.join(share_path,"opvdm_core.exe") light_dll_path=os.path.join(lib_path,"light")
def run(self): if running_on_linux()==True: print "thread: start" wm = pyinotify.WatchManager() print "wathcing path",self.watch_path ret=wm.add_watch(self.watch_path, pyinotify.IN_CLOSE_WRITE, self.onChange,False,False) print ret print "thread: start notifyer",self.notifier self.notifier = pyinotify.Notifier(wm) try: while 1: self.notifier.process_events() if self.notifier.check_events(): self.notifier.read_events() #self.notifier.loop() except: print "error in notify",sys.exc_info()[0] else: hDir = win32file.CreateFile (self.watch_path,FILE_LIST_DIRECTORY,win32con.FILE_SHARE_READ | win32con.FILE_SHARE_WRITE | win32con.FILE_SHARE_DELETE,None,win32con.OPEN_EXISTING,win32con.FILE_FLAG_BACKUP_SEMANTICS,None) while 1: results = win32file.ReadDirectoryChangesW (hDir,1024,True, win32con.FILE_NOTIFY_CHANGE_FILE_NAME | win32con.FILE_NOTIFY_CHANGE_DIR_NAME | win32con.FILE_NOTIFY_CHANGE_ATTRIBUTES | win32con.FILE_NOTIFY_CHANGE_SIZE | win32con.FILE_NOTIFY_CHANGE_LAST_WRITE | win32con.FILE_NOTIFY_CHANGE_SECURITY, None, None) for action, file in results: full_filename = os.path.join (self.watch_path, file) self.onChange(full_filename)
def stop(self): print("thread: stop been called", threading.currentThread()) if running_on_linux() == True: self.notifier.stop() self.notifier = False print("thread:I have shutdown the notifyer", threading.currentThread())
def clone_materials(dest,src_dir,file_type): if running_on_linux()==False: progress_window=progress_class() progress_window.show() progress_window.start() process_events() if os.path.isdir(dest)==False: os.makedirs(dest) files=find_materials(mat_path=src_dir,file_type=file_type) for i in range(0,len(files)): src_file=os.path.join(src_dir,files[i]) dest_file=os.path.join(dest,files[i]) clone_material(dest_file,src_file) progress_window.set_fraction(float(i)/float(len(files))) progress_window.set_text("Configuring "+files[i]) process_events() progress_window.stop() else: os.symlink(src_dir, dest)
def cal_share_path(): global share_path if os.path.isfile("configure.ac"): share_path = os.getcwd() return if os.path.isfile("ver.py"): share_path = os.path.abspath(os.path.join(os.getcwd(), os.pardir)) return if running_on_linux() == False: if os.path.isfile(os.path.join(os.getcwd(), "gpvdm_core.exe")): share_path = os.getcwd() else: share_path = "c:\\gpvdm" else: if os.path.isdir("/usr/lib64/gpvdm"): share_path = "/usr/lib64/gpvdm/" elif os.path.isdir("/usr/lib/gpvdm"): share_path = "/usr/lib/gpvdm/" else: share_path = os.path.dirname( os.path.dirname(os.path.realpath(__file__))) print("I don't know where the shared files are assuming ", share_path)
def wake_nodes(self): if running_on_linux()==True: if get_distro=="Fedora": print "waking all nodes:" for i in range(0, len(self.nodes)): print "waking", self.nodes[i].mac wol.send_magic_packet(self.nodes[i].mac)
def search_known_paths(file_or_dir_to_find, ext, key_file): global share_path global bin_path #check cwd paths = [] for ex in ext: paths.append(os.path.join(os.getcwd(), file_or_dir_to_find) + ex) paths.append( os.path.join(os.path.abspath(os.path.join(os.getcwd(), os.pardir)), file_or_dir_to_find) + ex) paths.append(os.path.join(share_path, file_or_dir_to_find) + ex) paths.append(os.path.join(bin_path, file_or_dir_to_find) + ex) paths.append(os.path.join(get_sim_path(), file_or_dir_to_find) + ex) if running_on_linux() == True: paths.append( os.path.join("/usr/share/gpvdm/", file_or_dir_to_find) + ex) paths.append( os.path.join("/usr/local/bin/", file_or_dir_to_find) + ex) paths.append(os.path.join("/usr/bin/", file_or_dir_to_find) + ex) for item in paths: if key_file == None: if os.path.isdir(item) or os.path.isfile(item): #print "found",item return to_native_path(item) else: if os.path.isfile(os.path.join(item, key_file)): return to_native_path(item) #print "Can't find",file_or_dir_to_find, "setting it to",paths[0] return paths[2]
def uid_get(): uid = "" if running_on_linux() == True: path = os.path.join(expanduser("~"), ".gpvdm_uid.inp") else: path = os.path.join(get_exe_path(), "uid.inp") try: lines = [] found = False lines = inp_load_file(path) if lines != False: uid = inp_search_token_value(lines, "#uid") found = True if found == False: uid = str(uuid.uuid4())[0:8] lines = [] lines.append("#uid") lines.append(uid) lines.append("#ver") lines.append("1.0") lines.append("#end") inp_save(path, lines) except: print("uid error") return uid
def search_known_paths(file_or_dir_to_find,ext,key_file): global share_path global bin_path #check cwd paths=[] for ex in ext: paths.append(os.path.join(os.getcwd(),file_or_dir_to_find)+ex) paths.append(os.path.join(os.path.abspath(os.path.join(os.getcwd(), os.pardir)),file_or_dir_to_find)+ex) paths.append(os.path.join(share_path,file_or_dir_to_find)+ex) paths.append(os.path.join(bin_path,file_or_dir_to_find)+ex) if running_on_linux()==True: paths.append(os.path.join("/usr/share/gpvdm/",file_or_dir_to_find)+ex) paths.append(os.path.join("/usr/local/bin/",file_or_dir_to_find)+ex) paths.append(os.path.join("/usr/bin/",file_or_dir_to_find)+ex) for item in paths: if key_file==None: if os.path.isdir(item) or os.path.isfile(item): #print "found",item return item else: if os.path.isfile(os.path.join(item,key_file)): return item #print "Can't find",file_or_dir_to_find, "setting it to",paths[0] return paths[2]
def cal_share_path(): global share_path if os.path.isfile("configure.ac"): share_path=os.getcwd() return if os.path.isfile("ver.py"): share_path=os.path.abspath(os.path.join(os.getcwd(), os.pardir)) return if running_on_linux()==False: try: registry_key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, "Software\\gpvdm", 0, winreg.KEY_READ) value, regtype = winreg.QueryValueEx(registry_key, "installpath") winreg.CloseKey(registry_key) share_path=value except WindowsError: share_path="c:\\gpvdm" print("No registry key found using default",share_path) else: if os.path.isdir("/usr/lib64/gpvdm"): share_path="/usr/lib64/gpvdm/" elif os.path.isdir("/usr/lib/gpvdm"): share_path="/usr/lib/gpvdm/" else: share_path="/usr/lib64/gpvdm/" print("I don't know where the shared files are assuming ",share_path)
def search_known_paths(file_or_dir_to_find, ext, key_file, is_file): global share_path global bin_path root_dir_rel_to_script_for_source_code = os.path.dirname( os.path.dirname(os.path.dirname(os.path.realpath( __file__)))) #gpvdm.py ../../ assuming it's in the right palce #print(root_dir_rel_to_script) #check cwd paths = [] for ex in ext: paths.append(os.path.join(os.getcwd(), file_or_dir_to_find) + ex) #chk cwd and in the gpvdm_* directories paths.append( os.path.join(os.getcwd(), "gpvdm_data", file_or_dir_to_find) + ex) paths.append( os.path.join(os.getcwd(), "gpvdm_gui", file_or_dir_to_find) + ex) paths.append( os.path.join(os.getcwd(), "gpvdm_core", file_or_dir_to_find) + ex) #check where the root directory for a normal install paths.append( os.path.join(root_dir_rel_to_script_for_source_code, "gpvdm_data", file_or_dir_to_find) + ex) paths.append( os.path.join(root_dir_rel_to_script_for_source_code, "gpvdm_gui", file_or_dir_to_find) + ex) paths.append( os.path.join(root_dir_rel_to_script_for_source_code, "gpvdm_core", file_or_dir_to_find) + ex) paths.append( os.path.join(os.path.abspath(os.path.join(os.getcwd(), os.pardir)), file_or_dir_to_find) + ex) paths.append(os.path.join(bin_path, file_or_dir_to_find) + ex) paths.append(os.path.join(get_sim_path(), file_or_dir_to_find) + ex) if running_on_linux() == True: paths.append( os.path.join("/usr/share/gpvdm/", file_or_dir_to_find) + ex) paths.append( os.path.join("/usr/local/bin/", file_or_dir_to_find) + ex) paths.append(os.path.join("/usr/bin/", file_or_dir_to_find) + ex) for item in paths: #print(item,os.path.isfile(item),os.path.dirname(os.path.realpath(__file__))) if key_file == None: if os.path.isdir(item) and is_file == False: #print "found",item return to_native_path(item) if os.path.isfile(item) and is_file == True: #print "found",item return to_native_path(item) else: if os.path.isfile(os.path.join(item, key_file)) and is_file == True: return to_native_path(item) #print "Can't find",file_or_dir_to_find, "setting it to",paths[0] return paths[2]
def multiplatform_exe_command(command): if running_on_linux() == False: if command.count(".exe") > 0: command = "\"" + command command = command.replace(".exe", ".exe\"", 1) #print("exe command=",command) return command
def update_fetch(): text=[] text.append("Checking web for updates...") # disk_files=[] web_src=[] disk_dest=[] update_path="http://www.gpvdm.com/update_windows/"+ver()+"/" lines=get_data_from_web(update_path+"list.dat") print("Got file list") lines=lines.split('\n') files=[] md5=[] web_md5=[] for i in range(0,len(lines)): if lines[i].count(" ")!=0: m,f=lines[i].split(" ") f=f[2:].split("/") md5.append(m) files.append(f) for i in range(0,len(files)): root=files[i][0] if root=="images" or root=="solvers" or root=="gpvdm_core.exe" or root=="device_lib" or root=="sim.gpvdm" or root=="lang" or root=="materials" or root=="light": md5_web=md5[i] md5_disk="none" disk_path=os.path.join(get_share_path(),"/".join(files[i])) web_path=update_path+"/".join(files[i]) if os.path.isfile(disk_path): md5_disk=hashlib.md5(open(disk_path,'rb').read()).hexdigest() if md5_web!=md5_disk: web_src.append(web_path) disk_dest.append(disk_path) web_md5.append(md5_web) for i in range(0,len(web_src)): text.append(web_src[i]+" "+disk_dest[i]) a=get_data_from_web(web_src[i]) l=len(a) if l>100: l=100; if a[:l].count("403 Forbidden")!=0: text.append("Access to file "+web_src[i]+" forbidden") else: web_hash=hashlib.md5(a).hexdigest() list_hash=web_md5[i] if web_hash==list_hash: text.append("updating file "+disk_dest[i]) if running_on_linux()==False: f=open(disk_dest[i], mode='wb') lines = f.write(a) f.close() else: text.append("Checksum error "+disk_dest[i]) return text
def get_web_cache_path(sub_dir): if running_on_linux() == False: ret = os.path.join(os.dirname(materials_base_path), "web_cache", sub_dir) else: ret = os.path.join(get_home_path(), "web_cache", sub_dir) if os.path.isdir(ret) == False: os.makedirs(ret) return ret
def get_reg_key(self,token): if running_on_linux()==False: try: registry_key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, "Software\\gpvdm", 0, winreg.KEY_READ) value, regtype = winreg.QueryValueEx(registry_key, token) winreg.CloseKey(registry_key) return value except WindowsError: pass return False
def callback_run_fit(self, widget, data=None): if running_on_linux()==True: cmd = "cd "+os.getcwd()+" \n" self.terminal.feed_child(cmd) cmd = get_exe_command()+" --1fit&\n" self.terminal.feed_child(cmd) else: cmd = get_exe_command()+" --1fit" subprocess.Popen([cmd])
def onChange(self,ev): if running_on_linux()==True: file_name=os.path.basename(ev.pathname) else: file_name=os.path.basename(ev) file_name=file_name.rstrip() self.thread_data[0] self.thread_data[0]=file_name print "thread: file changed" self.emit("file_changed")
def onChange(self, ev): if running_on_linux() == True: file_name = os.path.basename(ev.pathname) else: file_name = os.path.basename(ev) file_name = file_name.rstrip() self.thread_data[0] self.thread_data[0] = file_name print("thread: file changed") self.emit("file_changed")
def get_home_path(): global home_path if home_path == None: if running_on_linux() == True: home_path = str(Path.home()) else: home_path = str(os.environ['USERPROFILE']) if home_path.endswith("NTUSER.DAT") == True: home_path = os.path.dirname(home_path) return home_path
def thumb_nail_gen(): if running_on_linux() == True: thumb_dir = os.path.join(get_sim_path(), "thumb") if os.path.isdir(thumb_dir) == False: os.mkdir(thumb_dir) for i in [16, 32, 48, 64, 128]: icon_path = os.path.join(thumb_dir, str(i) + "x" + str(i) + ".png") gen_icon(icon_path, i) archive_add_file(os.path.join(get_sim_path(), "sim.gpvdm"), icon_path, thumb_dir)
def get_exe_name(): if running_on_linux() == True: if os.path.isfile("./go.o")==True: exe_name="go.o" elif os.path.isfile("./main.c")==True: exe_name="go.o" else: exe_name="opvdm_core" return exe_name else: exe_name="opvdm_core.exe" return exe_name
def killall(self): self.stop_work=True if self.cluster==True: self.cluster_killall() else: if running_on_linux()==True: cmd = 'killall '+get_exe_name() os.system(cmd) print(cmd) else: cmd="taskkill /im "+get_exe_name() print(cmd) os.system(cmd)
def cal_bin_path(): global bin_path if running_on_linux()==True: bin_path="/bin/" else: try: registry_key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, "Software\\opvdm", 0, _winreg.KEY_READ) value, regtype = _winreg.QueryValueEx(registry_key, "installpath") _winreg.CloseKey(registry_key) print "Lib path at", value bin_path=value except WindowsError: print "No registry key found using default" bin_path="c:\\opvdm"
def find_models(): ret=[] if running_on_linux()==True: ext="so" else: ext="dll" path=get_light_dll_path() for file in glob.glob(os.path.join(path,"*."+ext)): ret.append(os.path.splitext(os.path.basename(file))[0]) return ret
def QIcon_load(name, size=-1): global use_theme if use_theme == None: use_theme = inp_get_token_value( os.path.join(os.getcwd(), "config.inp"), "#gui_use_icon_theme") if use_theme == None: use_theme = False else: use_theme = str2bool(use_theme) if running_on_linux() == True and use_theme == True: image = QIcon() if image.hasThemeIcon(name) == True: return image.fromTheme(name) return QIcon(get_icon_path(name, size=size))
def clone_spectras(dest): if running_on_linux() == False: src_dir = os.path.join(get_base_spectra_path()) dest_dir = dest if os.path.isdir(dest_dir) == False: os.mkdir(dest_dir) files = find_light_source(get_base_spectra_path()) for i in range(0, len(files)): src_file = os.path.join(src_dir, files[i]) dest_file = os.path.join(dest_dir, files[i]) clone_spectra(dest_file, src_file) else: os.symlink(get_base_spectra_path(), dest)
def cal_lib_path(): global lib_path if running_on_linux()==True: if os.path.isfile("main.c")==True: lib_path=os.getcwd() else: lib_path="/usr/lib64/opvdm/" else: try: registry_key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, "Software\\opvdm", 0, _winreg.KEY_READ) value, regtype = _winreg.QueryValueEx(registry_key, "installpath") _winreg.CloseKey(registry_key) print "Lib path at", value lib_path=value except WindowsError: print "No registry key found using default" lib_path="c:\\opvdm"
def decrypt(data): global key global iv if running_on_linux()==True: ret="" m = hashlib.md5() m.update(key.encode('utf-8')) key_hash=m.digest() m = hashlib.md5() m.update(iv.encode('utf-8')) iv_hash=m.digest() encryptor = AES.new(key_hash, AES.MODE_CBC, IV=iv_hash) ret= encryptor.decrypt(bytes(data)) return ret
def check_lib_in_bash_rc(): if running_on_linux() == True: f = inp() gpvdm_installed = -1 if f.load(os.path.join(get_home_path(), ".bashrc")) != False: for i in range(0, len(f.lines)): if f.lines[i].startswith( "export LD_LIBRARY_PATH" ) == True and f.lines[i].count("gpvdm") != 0: gpvdm_installed = i if f.lines[i].endswith(get_exe_path()): return line = "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:" + get_exe_path() if gpvdm_installed == -1: f.lines.append(line) else: f.lines[i] = line f.save()
def run_jobs(self): if self.cluster == True: s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) port = 8888 self.mylock = True s.sendto("set_master_ip", (self.server_ip, port)) self.wait_lock() self.mylock = True s.sendto("set_exe#" + get_exe_command(), (self.server_ip, port)) self.wait_lock() # self.mylock.clear() s.sendto("run", (self.server_ip, port)) # self.mylock.wait(1000) s.close() else: if len(self.jobs) == 0: return for i in range(0, len(self.jobs)): if self.jobs_running < self.cpus: if self.status[i] == 0: self.status[i] = 1 print "Running job", self.jobs[i] if self.enable_gui == True: self.progress_window.set_text("Running job" + self.jobs[i]) self.jobs_running = self.jobs_running + 1 if running_on_linux() == True: cmd = "cd " + self.jobs[i] + ";" cmd = cmd + get_exe_command() + " --lock " + "lock" + str(i) + " &\n" print "command=" + cmd if self.enable_gui == True: self.terminal.feed_child(cmd) else: print cmd os.system(cmd) else: cmd = get_exe_command() + " --lock " + "lock" + str(i) + " &\n" print cmd, self.jobs[i] subprocess.Popen(cmd, cwd=self.jobs[i])
def gui_sim_stop(self,text): message="" self.notebook.set_current_page(self.notebook_active_page) self.spin.stop() if os.path.isfile("signal_stop.dat")==True: f = open('signal_stop.dat') lines = f.readlines() f.close() message=lines[0].rstrip() if text!="": message=text if running_on_linux()==True: if message!="": pynotify.init ("opvdm") Hello=pynotify.Notification ("opvdm:",message,os.path.join(get_image_file_path(),"application-opvdm.svg")) Hello.set_timeout(2000) Hello.show ()
def run(self, path, command): for i in range(0, self.cpus): if self.process[i].state() == QProcess.NotRunning: cursor = self.terminals[i].textCursor() self.terminals[i].clear() cursor.insertHtml(_("Running: ") + command + "<br>") self.process[i].setWorkingDirectory(path) if running_on_linux() == False: if command.count(".exe") > 0: command = "\"" + command command = command.replace(".exe", ".exe\"", 1) print("exe command=", command) self.process[i].start(command) return True print(_("I could not find a free cpu to run the command on")) return False
def gen_icon(path, icon_size): if running_on_linux() == True: #surface = cairo.SVGSurface('example1.svg', icon_size, icon_size) surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, icon_size, icon_size) ctx = cairo.Context(surface) ctx.scale(icon_size, icon_size) # Normalizing the canvas pat = cairo.LinearGradient(0.0, 0.0, 0.0, 1.0) pat.add_color_stop_rgba(1, 0.7, 0, 0, 0.5) # First stop, 50% opacity pat.add_color_stop_rgba(0, 0.9, 0.7, 0.2, 1) # Last stop, 100% opacity ctx.rectangle(0.25, 0.25, 0.5, 0.5) # Rectangle(x0, y0, x1, y1) ctx.set_source(pat) ctx.fill() ctx.translate(0.1, 0.1) # Changing the current transformation matrix surface.write_to_png(path) # Output to PNG surface.finish()
def killall(self): if self.cluster==True: data=tx_struct() data.id="gpvdm_stop_all_jobs" self.tx_packet(data) data.id="gpvdmkillall" self.tx_packet(data) sleep(1) data.id="gpvdm_delete_all_jobs" self.tx_packet(data) else: print("stop jobs") if running_on_linux()==True: exe_name=os.path.basename(get_exe_command()) cmd = 'killall '+exe_name ret= os.system(cmd) self.stop()
def run(self): if running_on_linux() == True: print("thread: start") wm = pyinotify.WatchManager() print("wathcing path", self.watch_path) ret = wm.add_watch(self.watch_path, pyinotify.IN_CLOSE_WRITE, self.onChange, False, False) print(ret) print("thread: start notifyer", self.notifier) self.notifier = pyinotify.Notifier(wm) try: while 1: self.notifier.process_events() if self.notifier.check_events(): self.notifier.read_events() #self.notifier.loop() except: print("error in notify", sys.exc_info()[0]) else: hDir = win32file.CreateFile( self.watch_path, FILE_LIST_DIRECTORY, win32con.FILE_SHARE_READ | win32con.FILE_SHARE_WRITE | win32con.FILE_SHARE_DELETE, None, win32con.OPEN_EXISTING, win32con.FILE_FLAG_BACKUP_SEMANTICS, None) while 1: results = win32file.ReadDirectoryChangesW( hDir, 1024, True, win32con.FILE_NOTIFY_CHANGE_FILE_NAME | win32con.FILE_NOTIFY_CHANGE_DIR_NAME | win32con.FILE_NOTIFY_CHANGE_ATTRIBUTES | win32con.FILE_NOTIFY_CHANGE_SIZE | win32con.FILE_NOTIFY_CHANGE_LAST_WRITE | win32con.FILE_NOTIFY_CHANGE_SECURITY, None, None) for action, file in results: full_filename = os.path.join(self.watch_path, file) self.onChange(full_filename)
def cal_share_path(): global share_path if os.path.isfile("configure.ac"): share_path = os.getcwd() return if os.path.isfile("ver.py"): share_path = os.path.abspath(os.path.join(os.getcwd(), os.pardir)) return if running_on_linux() == False: try: registry_key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, "Software\\gpvdm", 0, winreg.KEY_READ) value, regtype = winreg.QueryValueEx(registry_key, "installpath") winreg.CloseKey(registry_key) share_path = value except WindowsError: if os.path.isfile(os.path.join(os.getcwd(), "gpvdm_core.exe")): share_path = os.getcwd() else: share_path = "c:\\gpvdm" print("No registry key found using default", share_path) else: if os.path.isdir("/usr/lib64/gpvdm"): share_path = "/usr/lib64/gpvdm/" elif os.path.isdir("/usr/lib/gpvdm"): share_path = "/usr/lib/gpvdm/" else: share_path = os.path.dirname( os.path.dirname(os.path.realpath(__file__))) print("I don't know where the shared files are assuming ", share_path)
# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. import sys import os import shutil from win_lin import running_on_linux if running_on_linux()==False: import _winreg materials_path=None light_dll_path=None exe_command=None share_path=None device_lib_path=None bin_path=None lib_path=None def remove_cwdfrompath(path): tmp=path if tmp.startswith(os.getcwd()): tmp=tmp[len(os.getcwd())+1:]
# import sys import os #import shutil import threading import gobject #import multiprocessing #import glob #import socket #from time import sleep from win_lin import running_on_linux #import subprocess #from util import gui_print_path if running_on_linux() == True: import pyinotify else: import win32file import win32con FILE_LIST_DIRECTORY = 0x0001 class IdleObject(gobject.GObject): def __init__(self): gobject.GObject.__init__(self) def emit(self, *args): gobject.idle_add(gobject.GObject.emit, self, *args)
import pygtk import gtk from progress import progress_class from gui_util import process_events from inp import inp_get_token_value from inp import inp_write_lines_to_file from inp import inp_load_file from inp import inp_get_next_token_array from inp import inp_isfile from inp import inp_update_token_value from tab_main import tab_main from tab import tab_class from tab_homo import tab_bands from welcome import welcome_class from win_lin import running_on_linux if running_on_linux()==True: from tab_terminal import tab_terminal from dos_main import dos_main from pl_main import pl_main from cal_path import get_bin_path from cal_path import get_image_file_path from inp_description import inp_file_to_description import i18n _ = i18n.language.gettext class opvdm_notebook(gtk.Notebook): progress=progress_class() finished_loading=False item_factory=None
def to_native_path(path): ret = path if running_on_linux() == False: ret = ret.replace("/", "\\") ret = ret.lower() return ret
def cal_bin_path(): global bin_path if running_on_linux() == True: bin_path = "/bin/" else: bin_path = share_path
def encrypt_load(): global key global iv if running_on_linux() == True: iv = inp_get_token_value("cluster.inp", "#iv") key = inp_get_token_value("cluster.inp", "#key")
def __init__(self): gobject.GObject.__init__(self) self.my_server=server() self.my_server.init(os.getcwd()) self.my_server.statusicon.connect('popup-menu', self.on_status_icon_right_click) self.my_server.setup_gui(self.gui_sim_start,self.gui_sim_stop) if running_on_linux()==True: DBusGMainLoop(set_as_default=True) self.bus = dbus.SessionBus() self.bus.add_match_string_non_blocking("type='signal',interface='org.my.opvdm'") self.bus.add_message_filter(self.adbus) else: self.win_pipe=win_pipe() self.win_pipe.connect('new-data', self.win_dbus) self.win_pipe.start() self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) #self.window.set_size_request(-1,1000) self.window.set_border_width(10) self.window.set_title(_("Organic Photovoltaic Device Model (www.opvdm.com)")) splash=splash_window() splash.init() temp_error=ver_error() print temp_error if len(temp_error)>0: md = gtk.MessageDialog(self.window,gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, temp_error) md.run() md.destroy() self.undo_list=undo_list_class() self.undo_list.init() self.experiment_window=None self.fxexperiment_window=None self.qe_window=None self.win_list=windows() self.win_list.load() self.config=config() #table = gtk.Table(3,6,False) self.window.set_icon_from_file(os.path.join(get_image_file_path(),"image.jpg")) self.show_tabs = True self.show_border = True self.menu_items = ( ( _("/_File"), None, None, 0, "<Branch>" ), (_("/File/_New simulation"), "<control>N", self.callback_new, 0, "<StockItem>", "gtk-new" ), (_("/File/_Open simulation"), "<control>O", self.callback_open, 0, "<StockItem>", "gtk-open" ), ( _("/File/_Export data"), None, self.callback_export, 0, "<StockItem>", "gtk-save" ), ( _("/File/Import data"), None, self.callback_import, 0 , "<StockItem>", "gtk-harddisk"), ( _("/File/Import from library"), None, self.callback_import_from_lib, 0 , "<StockItem>", "gtk-harddisk"), ( _("/File/Quit"), "<control>Q", gtk.main_quit, 0, "<StockItem>", "gtk-quit" ), ( _("/_Simulate"), None, None, 0, "<Branch>" ), ( _("/Simulate/Run"), None, self.callback_simulate, 0, "<StockItem>", "gtk-media-play" ), ( _("/Simulate/Parameter scan"), None, self.callback_scan , 0, None ), ( _("/Simulate/Start cluster server"), None, self.callback_start_cluster_server , 0, None ), ( _("/_View"), None, None, 0, "<Branch>" ), ( _("/_Plots"), None, None, 0, "<Branch>" ), ( _("/Plots/Plot simulation result"), None, self.callback_plot_select, 0, "<StockItem>", "gtk-open"), ( _("/_Plots/"), None, None, 0, "<Separator>" ), ( _("/_Help"), None, None, 0, "<LastBranch>" ), ( _("/_Help/Help Index"), None, self.callback_help, 0, "<StockItem>", "gtk-help" ), ( _("/_Help/About"), None, self.callback_about_dialog, 0, "<StockItem>", "gtk-about" ), ) pos=0 self.menubar = self.get_main_menu(self.window) #a = (( "/Plots/Plot after simulation", None, self.callback_plot_after_run_toggle, 0, "<ToggleItem>" ), ) #self.item_factory.create_items( a, ) #a = (( "/Plots/One plot window", None, self.callback_set_plot_auto_close, 0, "<ToggleItem>" ), ) #self.item_factory.create_items( a, ) #table.show() self.window.connect("destroy", gtk.main_quit) self.tooltips = gtk.Tooltips() self.window.set_size_request(-1, 780) main_vbox = gtk.VBox(False, 5) main_vbox.set_border_width(1) self.window.add(main_vbox) #window.add(table) main_vbox.show() toolbar = gtk.Toolbar() toolbar.set_style(gtk.TOOLBAR_ICONS) toolbar.set_size_request(-1, 50) open_sim = gtk.ToolButton(gtk.STOCK_OPEN) self.tooltips.set_tip(open_sim, _("Open a simulation")) toolbar.insert(open_sim, pos) pos=pos+1 #self.save_sim = gtk.ToolButton(gtk.STOCK_SAVE) #self.tooltips.set_tip(self.save_sim, "Save a simulation") #toolbar.insert(self.save_sim, pos) #pos=pos+1 new_sim = gtk.ToolButton(gtk.STOCK_NEW) self.tooltips.set_tip(new_sim, _("Make a new simulation")) toolbar.insert(new_sim, pos) pos=pos+1 sep_lhs = gtk.SeparatorToolItem() sep_lhs.set_draw(True) sep_lhs.set_expand(False) toolbar.insert(sep_lhs, pos) pos=pos+1 self.undo = gtk.ToolButton(gtk.STOCK_UNDO) self.tooltips.set_tip(self.undo, "Undo") toolbar.insert(self.undo, pos) self.undo.connect("clicked", self.callback_undo) pos=pos+1 sep_lhs = gtk.SeparatorToolItem() sep_lhs.set_draw(True) sep_lhs.set_expand(False) toolbar.insert(sep_lhs, pos) pos=pos+1 image = gtk.Image() image.set_from_file(os.path.join(get_image_file_path(),"play.png")) self.play = gtk.ToolButton(image) self.tooltips.set_tip(self.play, _("Run the simulation")) toolbar.insert(self.play, pos) self.play.connect("clicked", self.callback_simulate) pos=pos+1 image = gtk.Image() image.set_from_file(os.path.join(get_image_file_path(),"forward.png")) self.tb_run_scan = gtk.ToolButton(image) self.tb_run_scan.connect("clicked", self.callback_run_scan) self.tooltips.set_tip(self.tb_run_scan, _("Run parameter scan")) toolbar.insert(self.tb_run_scan, pos) self.tb_run_scan.set_sensitive(False) pos=pos+1 if debug_mode()==True: image = gtk.Image() image.set_from_file(os.path.join(get_image_file_path(),"fit.png")) self.tb_run_fit = gtk.ToolButton(image) self.tb_run_fit.connect("clicked", self.callback_run_fit) self.tooltips.set_tip(self.tb_run_fit, _("Run a fit command")) toolbar.insert(self.tb_run_fit, pos) self.tb_run_fit.set_sensitive(True) pos=pos+1 image = gtk.Image() image.set_from_file(os.path.join(get_image_file_path(),"pause.png")) self.stop = gtk.ToolButton(image ) self.tooltips.set_tip(self.stop, _("Stop the simulation")) self.stop.connect("clicked", self.callback_simulate_stop) toolbar.insert(self.stop, pos) pos=pos+1 sep = gtk.SeparatorToolItem() sep.set_draw(True) sep.set_expand(False) toolbar.insert(sep, pos) pos=pos+1 image = gtk.Image() image.set_from_file(os.path.join(get_image_file_path(),"scan.png")) self.param_scan = gtk.ToolButton(image) self.param_scan.connect("clicked", self.callback_scan) self.tooltips.set_tip(self.param_scan, _("Parameter scan")) toolbar.insert(self.param_scan, pos) pos=pos+1 sep = gtk.SeparatorToolItem() sep.set_draw(True) sep.set_expand(False) toolbar.insert(sep, pos) pos=pos+1 image = gtk.Image() image.set_from_file(os.path.join(get_image_file_path(),"plot.png")) self.plot_select = gtk.MenuToolButton(image,"hello") self.tooltips.set_tip(self.plot_select, _("Find a file to plot")) self.plotted_graphs = used_files_menu() self.plot_select.set_menu(self.plotted_graphs.menu) toolbar.insert(self.plot_select, pos) self.plot_select.connect("clicked", self.callback_plot_select) self.plot_select.set_sensitive(False) pos=pos+1 #image = gtk.Image() #image.set_from_file(os.path.join(get_image_file_path(),"refresh.png")) #self.plot_open = gtk.ToolButton(image) #self.tooltips.set_tip(self.plot_open, "Replot the graph") #toolbar.insert(self.plot_open, pos) #self.plot_open.set_sensitive(False) #os=pos+1 image = gtk.Image() image.set_from_file(os.path.join(get_image_file_path(),"plot_time.png")) self.examine = gtk.ToolButton(image) self.tooltips.set_tip(self.examine, _("Examine results in time domain")) self.examine.connect("clicked", self.callback_examine) toolbar.insert(self.examine, pos) pos=pos+1 sep = gtk.SeparatorToolItem() sep.set_draw(True) sep.set_expand(False) toolbar.insert(sep, pos) pos=pos+1 image = gtk.Image() image.set_from_file(os.path.join(get_image_file_path(),"time.png")) self.experiment_window_button = gtk.ToolButton(image) self.tooltips.set_tip(self.experiment_window_button, _("Edit the time mesh")) self.experiment_window_button.connect("clicked", self.callback_edit_experiment_window) toolbar.insert(self.experiment_window_button, pos) pos=pos+1 image = gtk.Image() image.set_from_file(os.path.join(get_image_file_path(),"spectrum.png")) self.examine = gtk.ToolButton(image) self.tooltips.set_tip(self.examine, _("Frequency domain mesh editor")) self.examine.connect("clicked", self.callback_fxexperiment_window) toolbar.insert(self.examine, pos) pos=pos+1 sep2 = gtk.SeparatorToolItem() sep2.set_draw(False) sep2.set_expand(True) toolbar.insert(sep2, pos) pos=pos+1 help = gtk.ToolButton(gtk.STOCK_HELP) self.tooltips.set_tip(help, "Help") help.connect("clicked", self.callback_help) toolbar.insert(help, pos) pos=pos+1 #quittb = gtk.ToolButton(gtk.STOCK_QUIT) #self.tooltips.set_tip(quittb, "Quit") #toolbar.insert(quittb, pos) #quittb.connect("clicked", gtk.main_quit) #pos=pos+1 new_sim.connect("clicked", self.callback_new) open_sim.connect("clicked", self.callback_open) #self.save_sim.connect("clicked", self.callback_export) #self.plot_open.connect("clicked", self.callback_plot_open) toolbar1=self.make_tool_box1() toolbar.show_all() main_vbox.pack_start(self.menubar, False, True, 0) handlebox = gtk.HandleBox() handlebox.set_snap_edge(gtk.POS_LEFT) handlebox.show() toolbar.set_size_request(1000, -1) tb_vbox=gtk.VBox() tb_vbox.add(toolbar) tb_vbox.add(toolbar1) tb_vbox.show() handlebox.add(tb_vbox) main_vbox.pack_start(handlebox, False, False, 0) self.window.connect("delete-event", self.callback_close_window) self.win_list.set_window(self.window,"main_window") self.menubar.show() self.make_window2(main_vbox) self.window.show() process_events()
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. import sys import os #import shutil from win_lin import running_on_linux from gui_enable import gui_get from os.path import expanduser if running_on_linux() == False: import winreg materials_path = None plugins_path = None exe_command = None share_path = None device_lib_path = None bin_path = None lib_path = None image_path = None css_path = None flag_path = None lang_path = None inp_file_path = None src_path = None
def __init__(self): super(gpvdm_main_window, self).__init__() icon_init_db() #from scans_io import scans_io #from cal_path import get_sim_path #scans=scans_io(get_sim_path()) #sims=scans.get_scan_dirs() #print(sims) #asdsa self.splash = splash_window() self.scan_human_labels = get_scan_human_labels() self.splash.inc_value() process_events() process_events() #from wiz import wiz #a=wiz() #a.exec_() #sys.exit() do_import() if os.path.isdir(os.path.dirname(sys.argv[0])) == False: error_dlg(self, _("I can't run from inside a zip file!")) sys.exit() self.splash.inc_value() self.splash.inc_value() server_init() self.splash.inc_value() self.check_sim_exists = check_sim_exists() self.splash.inc_value() self.check_sim_exists.start_thread() self.splash.inc_value() self.check_sim_exists.sim_gone.connect(self.sim_gone) self.splash.inc_value() self.my_server = server_get() self.my_server.init(get_sim_path()) self.splash.inc_value() self.undo_list = undo_list_class() wpos_load() self.splash.inc_value() self.ribbon = ribbon() self.splash.inc_value() self.notebook_active_page = None self.setAcceptDrops(True) #self.setGeometry(200, 100, 1300, 600) self.setWindowTitle( "General-purpose Photovoltaic Device Model (https://www.gpvdm.com)" ) self.l = lock_gui() #self.l.disable_all.connect(self.disable_interface) #self.l.enable_all.connect(self.enable_disable_buttons) #super(gpvdm_main_window, self).__init__(parent, QtCore.Qt.FramelessWindowHint) #gobject.GObject.__init__(self) #self.my_server.setup_gui(self.gui_sim_start) self.my_server.sim_started.connect(self.gui_sim_start) self.splash.inc_value() self.my_server.sim_finished.connect(self.gui_sim_stop) self.splash.inc_value() help_init() self.splash.inc_value() #help_window().help_set_help(["star.png",_("<big><b>Update available!</b></big><br>")]) #self.show() if running_on_linux() == True: self.bus = dbus.SessionBus() self.bus.add_match_string_non_blocking( "type='signal',interface='org.my.gpvdm'") self.bus.add_message_filter(self.adbus) else: self.win_pipe = win_pipe() self.win_pipe.new_data.connect(self.win_dbus) self.win_pipe.start() self.notebook = gpvdm_notebook() vbox = QVBoxLayout() self.splash.inc_value() vbox.addWidget(self.ribbon) self.ribbon.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum) self.notebook.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) vbox.addWidget(self.notebook) wvbox = QWidget() self.splash.inc_value() wvbox.setLayout(vbox) self.setCentralWidget(wvbox) self.splash.inc_value() self.statusBar() temp_error = ver_error() #print(temp_error) if len(temp_error) > 0: error_dlg(self, temp_error) return self.setWindowIcon( QIcon(os.path.join(get_image_file_path(), "image.jpg"))) self.splash.inc_value() self.show_tabs = True self.show_border = True self.ribbon.file.home_new.clicked.connect(self.callback_new) self.ribbon.file.home_open.clicked.connect(self.callback_open) self.ribbon.file.used_files_click.connect(self.load_sim) self.ribbon.home.undo.triggered.connect(self.callback_undo) self.ribbon.home.run.start_sim.connect(self.callback_simulate) self.splash.inc_value() #self.ribbon.home.stop.setEnabled(False) self.ribbon.home.scan.setEnabled(False) self.ribbon.thermal.setEnabled(False) self.ribbon.home.help.triggered.connect(self.callback_on_line_help) update_init() resize_window_to_be_sane(self, 0.7, 0.75) self.change_dir_and_refresh_interface(get_sim_path()) self.splash.inc_value() #self.ribbon.home.sun.changed.connect(self.notebook.update) self.ribbon.setAutoFillBackground(True) self.splash.inc_value() self.show() help_window().show() self.enable_disable_buttons() val = inp_get_token_value(os.path.join(get_sim_path(), "config.inp"), "#use_gpvdm_local") if val != "false": if os.path.isdir(get_materials_path()) == False: clone_materials(get_materials_path(), get_base_material_path(), "material") if os.path.isdir(get_emission_path()) == False: clone_materials(get_emission_path(), get_base_emission_path(), "emission") if os.path.isdir(get_shape_path()) == False: clone_materials(get_shape_path(), get_base_shape_path(), "shape") if os.path.isdir(get_scripts_path()) == False: shutil.copytree(get_base_scripts_path(), get_scripts_path(), symlinks=True) if os.path.isdir(get_spectra_path()) == False: clone_spectras(get_spectra_path()) self.cache = cache(only_open_if_full=True) #from shape_editor import shape_editor #self.shape_window=shape_editor("/home/rod/gpvdm_local/shape/pedot") #self.shape_window.show() #from shape_import import shape_import #self.shape_import=shape_import("/home/rod/gpvdm_local/shape/pedot") #self.shape_import.show() check_lib_in_bash_rc()
def __init__(self): self.undo_list=undo_list_class() super(gpvdm_main_window,self).__init__() self.setGeometry(200, 100, 1300, 600) self.setWindowTitle(_("General-purpose Photovoltaic Device Model (www.gpvdm.com)")) #super(gpvdm_main_window, self).__init__(parent, QtCore.Qt.FramelessWindowHint) #gobject.GObject.__init__(self) server_init() self.my_server=server_get() self.my_server.init(os.getcwd()) self.my_server.setup_gui(self.gui_sim_start) self.my_server.sim_finished.connect(self.gui_sim_stop) help_init() #help_window().help_set_help(["star.png",_("<big><b>Update available!</b></big><br>")]) self.win_list=windows() self.win_list.load() #self.show() if running_on_linux()==True: DBusQtMainLoop(set_as_default=True) self.bus = dbus.SessionBus() self.bus.add_match_string_non_blocking("type='signal',interface='org.my.gpvdm'") self.bus.add_message_filter(self.adbus) else: self.win_pipe=win_pipe() self.win_pipe.new_data.connect(self.win_dbus) self.win_pipe.start() self.notebook=gpvdm_notebook() self.setCentralWidget(self.notebook) self.show() self.statusBar() toolbar = self.addToolBar('Exit') toolbar.setIconSize(QSize(42, 42)) self.splash=splash_window() self.splash.init() temp_error=ver_error() print(temp_error) if len(temp_error)>0: msgBox = QMessageBox(self) msgBox.setIcon(QMessageBox.Critical) msgBox.setText(self.tr("gpvdm")) msgBox.setInformativeText(temp_error) msgBox.setStandardButtons(QMessageBox.Ok ) msgBox.setDefaultButton(QMessageBox.Ok) reply = msgBox.exec_() return self.experiment_window=None self.fxexperiment_window=None self.jvexperiment_window=None self.fit_window=None self.config_window=None self.qe_window=None self.lasers_window=None self.sim_info_window=None self.setWindowIcon(QIcon(os.path.join(get_image_file_path(),"image.jpg"))) self.show_tabs = True self.show_border = True menubar = self.menuBar() file_menu = menubar.addMenu('&File') self.menu_new=file_menu.addAction(_("&New simulation")) self.menu_new.triggered.connect(self.callback_new) self.menu_new_optical_material=file_menu.addAction(_("New optical material")) self.menu_export_open=file_menu.addAction(_("&Open simulation")) self.menu_export_open.triggered.connect(self.callback_open) self.menu_export_data=file_menu.addAction(_("&Export data")) self.menu_export_data.triggered.connect(self.callback_export) self.menu_import_data=file_menu.addAction(_("&Import data")) self.menu_import_data.triggered.connect(self.callback_import) self.menu_import_lib=file_menu.addAction(_("Import from library")) self.menu_import_lib.triggered.connect(self.callback_import_from_lib) self.menu_quit=file_menu.addAction(_("&Quit")) self.menu_quit.triggered.connect(self.close_now) simulation_menu = menubar.addMenu('&Simulation') self.menu_run=simulation_menu.addAction(_("&Run")) self.menu_run.triggered.connect(self.callback_simulate) self.menu_stop=simulation_menu.addAction(_("&Stop")) self.menu_stop.triggered.connect(self.callback_simulate_stop) self.menu_scan=simulation_menu.addAction(_("&Parameter scan")) self.menu_scan.triggered.connect(self.callback_scan) self.menu_configure=simulation_menu.addAction(_("&Configure")) self.menu_configure.triggered.connect(self.callback_config_window) view_menu = menubar.addMenu('&View') view_menu.addAction(_("&None")) plot_menu = menubar.addMenu('&Plot') self.plot_menu_plot=plot_menu.addAction(_("&Plot simulation result")) self.plot_menu_plot.triggered.connect(self.callback_plot_select) help_menu = menubar.addMenu('Help') help_web=help_menu.addAction(_("&Help window")) help_web.triggered.connect(self.callback_help) help_web=help_menu.addAction(_("&Online help")) help_web.triggered.connect(self.callback_on_line_help) help_web=help_menu.addAction(_("&License")) help_web.triggered.connect(self.callback_license) about=help_menu.addAction(_("&About")) about.triggered.connect(self.callback_about_dialog) if enable_webupdates()==False: self.help_menu_update=help_menu.addAction(_("&Check for updates")) self.help_menu_update.triggered.connect(self.callback_update) new_sim = QAction(QIcon(os.path.join(get_image_file_path(),"new.png")), _("Make a new simulation"), self) new_sim.triggered.connect(self.callback_new) toolbar.addAction(new_sim) open_sim = QAction(QIcon(os.path.join(get_image_file_path(),"open.png")), _("Open a simulation"), self) open_sim.triggered.connect(self.callback_open) toolbar.addAction(open_sim) toolbar.addSeparator() self.undo = QAction(QIcon(os.path.join(get_image_file_path(),"undo.png")), _("Undo"), self) self.undo.triggered.connect(self.callback_undo) toolbar.addAction(self.undo) #seperator self.run = QAction(QIcon(os.path.join(get_image_file_path(),"play.png")), _("Run the simulation"), self) self.run.triggered.connect(self.callback_simulate) toolbar.addAction(self.run) self.tb_run_scan = QAction(QIcon(os.path.join(get_image_file_path(),"forward.png")), _("Run parameter scan"), self) self.tb_run_scan.triggered.connect(self.callback_run_scan) self.tb_run_scan.setEnabled(False) toolbar.addAction(self.tb_run_scan) self.stop = QAction(QIcon(os.path.join(get_image_file_path(),"pause.png")), _("Stop the simulation"), self) self.stop.triggered.connect(self.callback_simulate_stop) toolbar.addAction(self.stop) self.stop.setEnabled(False) toolbar.addSeparator() self.param_scan = QAction(QIcon(os.path.join(get_image_file_path(),"scan.png")), _("Parameter scan"), self) self.param_scan.triggered.connect(self.callback_scan) toolbar.addAction(self.param_scan) self.param_scan.setEnabled(False) if enable_betafeatures()==True: self.tb_run_fit = QAction(QIcon(os.path.join(get_image_file_path(),"fit.png")), _("Run a fit command"), self) self.tb_run_fit.triggered.connect(self.callback_run_fit) toolbar.addAction(self.tb_run_fit) self.tb_run_fit.setEnabled(True) toolbar.addSeparator() self.plot_select = QAction(QIcon(os.path.join(get_image_file_path(),"plot.png")), _("Find a file to plot"), self) self.plot_select.triggered.connect(self.callback_plot_select) toolbar.addAction(self.plot_select) self.examine = QAction(QIcon(os.path.join(get_image_file_path(),"plot_time.png")), _("Examine results in time domain"), self) self.examine.triggered.connect(self.callback_examine) toolbar.addAction(self.examine) toolbar.addSeparator() self.tb_time_domain = QAction(QIcon(os.path.join(get_image_file_path(),"time.png")), _("Time domain simulation editor."), self) self.tb_time_domain.triggered.connect(self.callback_edit_experiment_window) toolbar.addAction(self.tb_time_domain) self.experiment_window_button = QAction(QIcon(os.path.join(get_image_file_path(),"spectrum.png")), _("Frequency domain simulation editor"), self) self.experiment_window_button.triggered.connect(self.callback_fxexperiment_window) toolbar.addAction(self.experiment_window_button) self.jv_button = QAction(QIcon(os.path.join(get_image_file_path(),"jv.png")), _("Steady state simulation editor"), self) self.jv_button.triggered.connect(self.callback_jv_window) toolbar.addAction(self.jv_button) self.laser_button = QAction(QIcon(os.path.join(get_image_file_path(),"lasers.png")), _("Lasers editor"), self) self.laser_button.triggered.connect(self.callback_configure_lasers) toolbar.addAction(self.laser_button) spacer = QWidget() spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) toolbar.addWidget(spacer) self.help = QAction(QIcon(os.path.join(get_image_file_path(),"help.png")), _("Help"), self) self.help.triggered.connect(self.callback_on_line_help) toolbar.addAction(self.help) self.addToolBarBreak() toolbar1=self.make_tool_box1() self.addToolBar(toolbar1) if enable_betafeatures()==True: self.hpc_toolbar=hpc_class(self.my_server) #self.addToolBarBreak() toolbar_hpc = self.addToolBar(self.hpc_toolbar) self.win_list.set_window(self,"main_window") # self.menubar.show() # self.make_window2(main_vbox) #help_window().show() self.change_dir_and_refresh_interface(os.getcwd()) # self.window.show() # process_events() self.show() self.light_button.changed.connect(self.notebook.update)
def gen_infofile_plot(file_list_in, base_dir, plot_token): file_name = os.path.splitext( plot_token.file0)[0] + plot_token.tag0 + "#" + os.path.splitext( plot_token.file1)[0] + plot_token.tag1 + ".dat" values = "" result = [] #only allow files from real simulations in the list for i in range(0, len(file_list_in)): test_name = os.path.join(os.path.dirname(file_list_in[i]), 'sim.gpvdm') if os.path.isfile(test_name): result.append(file_list_in[i]) if len(result) == 0: print("No files found") return #pull out first item ittr_path = os.path.dirname(result[0]) start_of_sim_dir_path_pos = len(base_dir) + 1 ittr_path = ittr_path[start_of_sim_dir_path_pos:] #check it's depth if running_on_linux(): depth = ittr_path.count('/') else: depth = ittr_path.count('\\') #Remove the first part of the path name just leaving what is in the simulation dir if depth == 0: mydirs = [""] else: mydirs = [] for i in result: ittr_path = os.path.dirname(i) ittr_path = ittr_path[start_of_sim_dir_path_pos:] ittr_path = os.path.split(ittr_path) #print ittr_path if mydirs.count(ittr_path[0]) == 0: mydirs.append(ittr_path[0]) data = ["" for x in range(len(mydirs))] #for each directory save the data into an array element? for i in range(0, len(result)): cur_sim_path = os.path.dirname(result[i]) if cur_sim_path != base_dir: #print result[i],cur_sim_path values = gen_plot_line(cur_sim_path, plot_token) if depth == 0: pos = 0 else: ittr_path = os.path.dirname(result[i]) ittr_path = ittr_path[start_of_sim_dir_path_pos:] ittr_path = os.path.split(ittr_path) pos = mydirs.index(ittr_path[0]) #print pos data[pos] = data[pos] + values #print data[pos] plot_files = [] plot_labels = [] #Dump the array elements to disk for i in range(0, len(mydirs)): newplotfile = os.path.join(base_dir, mydirs[i], file_name) plot_files.append(newplotfile) plot_labels.append(os.path.basename(mydirs[i])) f = open(newplotfile, 'w') f.write(data[i]) f.close() save_file = os.path.join(base_dir, os.path.splitext(file_name)[0]) + ".oplot" #print "save path",save,plot_files plot_populate_plot_token(plot_token, None) return plot_files, plot_labels, save_file
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
def gen_infofile_plot(file_list_in,base_dir,plot_token): file_name=os.path.splitext(plot_token.file0)[0]+plot_token.tag0+"#"+os.path.splitext(plot_token.file1)[0]+plot_token.tag1+".dat" values="" result=[] #only allow files from real simulations in the list for i in range(0,len(file_list_in)): test_name=os.path.join(os.path.dirname(file_list_in[i]),'sim.gpvdm') if os.path.isfile(test_name): result.append(file_list_in[i]) if len(result)==0: print("No files found") return #pull out first item ittr_path=os.path.dirname(result[0]) start_of_sim_dir_path_pos=len(base_dir)+1 ittr_path=ittr_path[start_of_sim_dir_path_pos:] #check it's depth if running_on_linux(): depth=ittr_path.count('/') else: depth=ittr_path.count('\\') #Remove the first part of the path name just leaving what is in the simulation dir if depth==0: mydirs=[""] else: mydirs=[] for i in result: ittr_path=os.path.dirname(i) ittr_path=ittr_path[start_of_sim_dir_path_pos:] ittr_path=os.path.split(ittr_path) #print ittr_path if mydirs.count(ittr_path[0])==0: mydirs.append(ittr_path[0]) data=["" for x in range(len(mydirs))] #for each directory save the data into an array element? for i in range(0, len(result)): cur_sim_path=os.path.dirname(result[i]) if cur_sim_path!=base_dir: #print result[i],cur_sim_path values=gen_plot_line(cur_sim_path,plot_token) if depth==0: pos=0 else: ittr_path=os.path.dirname(result[i]) ittr_path=ittr_path[start_of_sim_dir_path_pos:] ittr_path=os.path.split(ittr_path) pos=mydirs.index(ittr_path[0]) #print pos data[pos]=data[pos]+values #print data[pos] plot_files=[] plot_labels=[] #Dump the array elements to disk for i in range(0,len(mydirs)): newplotfile=os.path.join(base_dir,mydirs[i],file_name) plot_files.append(newplotfile) plot_labels.append(os.path.basename(mydirs[i])) f = open(newplotfile,'w') f.write(data[i]) f.close() save_file=os.path.join(base_dir,os.path.splitext(file_name)[0])+".oplot" #print "save path",save,plot_files plot_populate_plot_token(plot_token,None) return plot_files, plot_labels, save_file
def cal_bin_path(): global bin_path if running_on_linux()==True: bin_path="/bin/" else: bin_path=share_path
def encrypt_load(): global key global iv if running_on_linux()==True: iv=inp_get_token_value("crypto.inp","#iv") key=inp_get_token_value("crypto.inp","#key")
def stop(self): print "thread: stop been called",threading.currentThread() if running_on_linux()==True: self.notifier.stop() self.notifier=False print "thread:I have shutdown the notifyer",threading.currentThread()
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()