def _getligprop(self, filename): """ calculate basic properties from PDBQT ligand mw, hba, hbd, heavy atoms """ try: lines = hf.getLines(filename) atoms = hf.getAtoms(lines) except: return False, sys.exc_info()[1] if len(lines) == 0: return False, "empty file" if len(atoms) == 0: return False, "no atoms (INVALID FILE)" try: tors = int(lines[-1].split()[1]) except: return False, "no torsions (INVALID FILE)" # hb hba, hbd = [ len(x) for x in hf.findHbAccepDon(atoms) ] # atypes ( report all types with duplicates, to be used for updating lib types) atypes = [ x.split()[-1] for x in atoms ] # heavy heavy = len([ x for x in atypes if not x == 'HD' ]) # mw mw = 0 for a in atypes: mw += hf.adtypes.get( a, [None,0])[1] atypes = list(set(atypes)) #[ x.split()[-1] for x in atoms ])) return True, {'tors' : tors, 'heavy' : heavy, 'mw' : mw, 'hba' : hba, 'hbd': hbd, 'atypes': atypes }
def _getligprop(self, filename): """ calculate basic properties from PDBQT ligand mw, hba, hbd, heavy atoms """ try: lines = hf.getLines(filename) atoms = hf.getAtoms(lines) except: return False, sys.exc_info()[1] if len(lines) == 0: return False, "empty file" if len(atoms) == 0: return False, "no atoms (INVALID FILE)" try: tors = int(lines[-1].split()[1]) except: return False, "no torsions (INVALID FILE)" # hb hba, hbd = [len(x) for x in hf.findHbAccepDon(atoms)] # atypes ( report all types with duplicates, to be used for updating lib types) atypes = [x.split()[-1] for x in atoms] # heavy heavy = len([x for x in atypes if not x == "HD"]) # mw mw = 0 for a in atypes: mw += hf.adtypes.get(a, [None, 0])[1] atypes = list(set(atypes)) # [ x.split()[-1] for x in atoms ])) return True, {"tors": tors, "heavy": heavy, "mw": mw, "hba": hba, "hbd": hbd, "atypes": atypes}
def writeLogJson(self, logname, compression = False): """ write log in json format """ if not len(self.results.keys()): print "cowardly refusing to write an empty file" return #hf.writejson(logname, self.results, compression) hf.writemarshal(logname, self.results, compression)
def makedirname(event=None): """ ButtonRelease """ chars = hf._allowedfilenamechars() text = self._lname.getvalue() if not len(text): self._dname.setvalue('') valid = [ x for x in text if x in hf._allowedfilenamechars()] valid = "".join(valid).lower() self._dname.setvalue(valid)
def saveServerInfo(self, fname=None): """save the server db and handle password saving""" if fname==None: fname = self.getServerInfoFile() srv_db = copy.deepcopy(self.settings['servers']) for s in srv_db['ssh'].keys(): srv = srv_db['ssh'][s] if '_save_passwd_' in srv.keys(): del srv['_save_passwd_'] else: srv['password'] = None hf.writejson(fname, srv_db, compression=True)
def _checkdirs(self, autocreate =True): """ check and create necessary raccoon dirs""" dirs = [ self.settings['racdir'], self.settings['datadir'] , self.settings['tempdir'], self.settings['dockingdir'], self.settings['targetdir'] ] for d in dirs: if not os.path.isdir(d): if autocreate: print "dir [%s] does not exist. Creating it..." % d hf.makeDir( fullpath = d) else: return False return True
def export(self, event=None): """ export list of problematic files""" buff = [] for f, e in self.problematic: f = ":".join(f) # handle multiple files per ligand buff.append("%s,%s" % (f, e) ) t = 'Select problematic log filename' ft = [("Any file type...", "*")] idir = self.app._lastdir suggest = 'problematic_results.csv' fname = tfd.asksaveasfilename(parent=self.interior(), title=t, filetypes=ft, initialdir=idir, initialfile=suggest) if not fname: return hf.writeList(fname, buff, addNewLine=1)
def readConfig(self, fname=None): """ read the confielf.saveServerInfo() # g file """ #print "READING CONFIG FILE" if fname == None: fname = self.getConfigFile() data = hf.readjson(fname) if data: self.settings = data
def loadTargetDb(self, fname=None): """ read the database where known used targets are stored """ if fname == None: fname = self.getTargetDbFile() data = hf.readjson(fname, compression = False) if data: self.knownTargets = data self.dprint("Target dbase initialized: %d items" % len(self.knownTargets.keys()) )
def __init__(self, parent, app, ligands=None, receptor=None, logfile=None, job=None, auto=False, debug=False): """ """ rb.RaccoonDefaultWidget.__init__(self, parent) DebugTools.DebugObj.__init__(self, debug) Pmw.Dialog.__init__(self, parent, buttons = ('Stop',), defaultbutton='Stop', title = 'Processing results', command=self.stop, master=self.parent) bbox = self.component('buttonbox') for i in range(bbox.numbuttons()): bbox.button(i).configure(font=self.FONT, default='disabled', **self.BORDER) self.job = job self.app = app self.auto = auto self.problematic = [] self._current = ('none', 'none', 'none') self.status = False if self.job: self.getData() else: self.ligands = ligands if receptor: self.receptor = receptor else: self.receptor = self.app.resultsProcessor.processor.recname self.logfile = logfile self.dirname = os.path.dirname(os.path.normpath(logfile)) self.logfile = os.path.basename(os.path.normpath(logfile)) # build GUI d = self.interior() f = tk.Frame(d) tk.Label(f, text='Processing: ', font=self.FONTbold).pack(side='left', anchor='w', padx=9) self.label = tk.Label(f, text='', font=self.FONT, anchor='w') self.label.pack(side='left', anchor='w') f.pack(expand=0, fill='x',side='top', anchor='n',pady=5) x = tk.Frame(d) self.pc_var = tk.DoubleVar(value=0.) self.progress = hf.ProgressBar(x, self.pc_var, w=300) self.progress.pack(expand=1, fill='x',anchor='n', side='top',padx=9,pady=3) x.pack(expand=1, fill='x', anchor='n', side='top', pady=5) status = self.check() if status == True: self.STOP = False # if successful: import the generated logfile # the log file must be saved with the name of the directory? # receptor Name? self.interior().after(100, self.start) self.activate() else: self.STOP = True self.problematic = [['None', status ]] self.label.configure(text='DONE') self.updateButton()
def targetFingerprint(self, fname): """ return target fingerprint and alias name """ try: fobj = open(fname, 'r') self.dprint("file opened [%s]" % fname) except: e = sys.exc_info()[1] self.dprint("error opening file [%s]:%s" % (fname, e)) return (False, e) fingerp = hf.hashfile(fobj) alias = os.path.basename(fname) return (fingerp, alias)
def _checkfiles(self, autocreate=True): """ check and create necessary raccoon files""" files = [ self.settings['config_file'], self.settings['history'], self.settings['server_dbase'] , self.settings['target_db'] ] for f in files: if not os.path.isfile(f): if autocreate: t = hf.touch(f) if not t: #print "error in file [%s] : [%s]" % (f,t) return False return True
def upload(self, dirname=None, destpath=None, autoregister=False, overwrite=False, bg=False): """upload the library to the remote server $dest path""" if dirname == None: dirname = hf.validFilename(self.name()) if dirname == '': dirname = 'libdir' self.dprint("warning: lib dirname empty, providing substutute [%s]" % libdir) if destpath == None: destpath == self.server.getLibraryPath() if (self.server == None) or (self.server == 'localhost'): self._localcopy( dirname, destpath, autoregister, overwrite, bg) else: self._remotecopy( dirname, destpath, autoregister, overwrite, bg) self.updatestatus()
def searchLigands(self, dirname, cb=None): #, pattern= '*_out.pdbqt'): """ scan dir for vina results""" pattern_list = { 'autodock' : '*.dlg', 'vina' : '*_out.pdbqt', } pattern = pattern_list[ self.app.getDockingEngine() ] dockfiles = hf.pathToList(dirname, recursive = True, pattern = pattern) #self.dprint("found %s dockfiles" % dockfiles) result = {} for d in dockfiles: name = os.path.basename(d).split("_out.pdbqt")[0] result[name] = d return result
def readServerInfo(self, fname=None): """read the server db and handle password saving""" if fname==None: fname = self.getServerInfoFile() data = hf.readjson(fname, compression=True) if data: srv_db = data for _type in srv_db.keys(): if _type =='ssh': for name in srv_db[_type].keys(): srv = srv_db[_type][name] if not srv['password'] == None: srv['_save_passwd_'] = None self.settings['servers'] = srv_db
def upload(self, dirname=None, destpath=None, autoregister=False, overwrite=False, bg=False): """upload the library to the remote server $dest path""" if dirname == None: dirname = hf.validFilename(self.name()) if dirname == "": dirname = "libdir" self.dprint("warning: lib dirname empty, providing substutute [%s]" % libdir) if destpath == None: destpath == self.server.getLibraryPath() if (self.server == None) or (self.server == "localhost"): self._localcopy(dirname, destpath, autoregister, overwrite, bg) else: self._remotecopy(dirname, destpath, autoregister, overwrite, bg) self.updatestatus()
def updateDownloadBigFile(self): """ update download status of big files transfers""" if self.checkPending() == False: return 100.00 #self._counter try: self.dprint("checking local size of [%s]" % self._localfile) curr_size = os.stat(self._localfile).st_size self.dprint(' found %s' % curr_size) except: self.dprint('file checking error [%s]' % sys.exc_info()[1] ) curr_size = 0 pc = hf.percent(curr_size, self._total) self.dprint("current size [%d/%d] : %2.3f%%" % (curr_size, self._total, pc) ) return pc
def _additems(self, items, propfunc=None, dup="rename", stopcheck=None, showpercent=None, GUI=None): """ add [items] to the current item list propfunc functio to be used to calculate properties dup = 'overwrite' duplicates not allowed (last kept) dup = 'rename' duplicates renamed dup = 'skip' duplicates not allowed (first kept) """ self.dprint("adding [%d] items" % len(items), new=1) problematic = [] c = 1 # XXX FIXME profile here! for i in items: # source = i checkreport = self._checkitem(i, dup=dup) if checkreport: name, destname = checkreport # if self._checkitem(i): # manage ligand properties if propfunc: report, prop = propfunc(i) else: report, prop = True, {} if report: self.items[name] = { "source": i, "fullpath": destname, # destname can be updated with the suffix dir for splitting "properties": prop, } else: self.dprint("problematic item [%s] : [%s]" % (i, prop)) problematic.append([i, prop]) c += 1 if not stopcheck == None: if stopcheck(): self.dprint("stopcheck() requested stopping...") break if not GUI == None: GUI.update() if not showpercent == None: pc = hf.percent(c, len(items)) showpercent(pc) self.updatestatus() return problematic
def _additems(self, items, propfunc=None, dup = 'rename', stopcheck=None, showpercent=None, GUI=None): """ add [items] to the current item list propfunc functio to be used to calculate properties dup = 'overwrite' duplicates not allowed (last kept) dup = 'rename' duplicates renamed dup = 'skip' duplicates not allowed (first kept) """ self.dprint("adding [%d] items"% len(items), new=1) problematic = [] c = 1 # XXX FIXME profile here! for i in items: #source = i checkreport = self._checkitem(i, dup = dup) if checkreport: name, destname = checkreport #if self._checkitem(i): # manage ligand properties if propfunc: report, prop = propfunc(i) else: report, prop = True, {} if report: self.items[name] = { 'source' : i, 'fullpath' : destname, # destname can be updated with the suffix dir for splitting 'properties': prop, } else: self.dprint("problematic item [%s] : [%s]" % (i, prop)) problematic.append([ i, prop ]) c+=1 if not stopcheck==None: if stopcheck(): self.dprint("stopcheck() requested stopping...") break if not GUI == None: GUI.update() if not showpercent == None: pc = hf.percent(c, len(items) ) showpercent(pc) self.updatestatus() return problematic
def opendir(self, event=None, recursive=False): """ scan dir(s) optionally recursively""" title = "Select a directory to scan" if recursive: title += " recursively" # add a GUI feedback: # - GUIvar # - progress bar # progress = tk.StringVar('Processing # dirname = tfd.askdirectory(parent=self.frame, title=title, mustexist=True) if dirname: files = hf.pathToList(dirname, pattern="*.pdbqt", recursive=recursive) # XXX progress var here... # files.append(hf.pathToList(dirname, pattern = '*.PDBQT', recursive = recursive)) # XXX ? # hf.writeList('FOUND.log', files, addNewLine=1) if len(files): self._file_checker(files)
def opendir(self, event=None, recursive=False): """ scan dir(s) optionally recursively""" title = 'Select a directory to scan' if recursive: title += ' recursively' # add a GUI feedback: # - GUIvar # - progress bar # progress = tk.StringVar('Processing # dirname = tfd.askdirectory(parent=self.frame, title=title, mustexist=True) if dirname: files = hf.pathToList( dirname, pattern='*.pdbqt', recursive=recursive) # XXX progress var here... #files.append(hf.pathToList(dirname, pattern = '*.PDBQT', recursive = recursive)) # XXX ? #hf.writeList('FOUND.log', files, addNewLine=1) if len(files): self._file_checker(files)
def _remotecopy(self, dirname, destpath, autoregister=False, overwrite=False, bg=True): """ perform the copy on remote path""" # generating fullpath destination dir self.path = destpath + '/' + dirname if self.server.ssh.exists(self.path): self.dprint('remote library dirname[%s] exist in the path[%s] => [%s]...' % (dirname, destpath, self.path)) if not overwrite: self.dprint('overwrite not allowed, returning') return else: self.server.ssh.remove([self.path]) # update the ligand destination with split_path step = self.options['split'] items = sorted(self.items.keys()) total = len(items) if (not step == None) and (step <= total): count = 0 for i in items: self.dprint("updating splitted name [%s] =>" % self.items[i]['fullpath']), self.items[i]['fullpath'] = '/'.join([hf.splitdir(count, total, step), self.items[i]['fullpath']]) self.dprint("[%s]" % self.items[i]['fullpath']) count+=1 transfer_list = [] for i in items: dest = '/'.join([dirname, self.items[i]['fullpath'] ]) transfer_list.append( [self.items[i]['source'], dest]) # transfer files mule = self.server.transfer self.dprint("starting the transfer with the mule[%s]" % mule) mule.upload(files = transfer_list, remotedestpath=destpath, bg=bg) self.dprint("mule started... ongoing...") if autoregister: if not bg: libindex = self.path + '/' + 'library.db' self.saveIndex(libindex) self.registerLibrary(overwrite) else: print "AUTOREGISTER DISABLED! BACKGROUND UPLOAD (TO FIX)"
def _remotecopy(self, dirname, destpath, autoregister=False, overwrite=False, bg=True): """ perform the copy on remote path""" # generating fullpath destination dir self.path = destpath + "/" + dirname if self.server.ssh.exists(self.path): self.dprint("remote library dirname[%s] exist in the path[%s] => [%s]..." % (dirname, destpath, self.path)) if not overwrite: self.dprint("overwrite not allowed, returning") return else: self.server.ssh.remove([self.path]) # update the ligand destination with split_path step = self.options["split"] items = sorted(self.items.keys()) total = len(items) if (not step == None) and (step <= total): count = 0 for i in items: self.dprint("updating splitted name [%s] =>" % self.items[i]["fullpath"]), self.items[i]["fullpath"] = "/".join([hf.splitdir(count, total, step), self.items[i]["fullpath"]]) self.dprint("[%s]" % self.items[i]["fullpath"]) count += 1 transfer_list = [] for i in items: dest = "/".join([dirname, self.items[i]["fullpath"]]) transfer_list.append([self.items[i]["source"], dest]) # transfer files mule = self.server.transfer self.dprint("starting the transfer with the mule[%s]" % mule) mule.upload(files=transfer_list, remotedestpath=destpath, bg=bg) self.dprint("mule started... ongoing...") if autoregister: if not bg: libindex = self.path + "/" + "library.db" self.saveIndex(libindex) self.registerLibrary(overwrite) else: print "AUTOREGISTER DISABLED! BACKGROUND UPLOAD (TO FIX)"
def buildGUI(self): """ set the widgets shown""" self.win = Pmw.Dialog(self.parent, title=self.title, buttons=('Stop', ), command=self.stop) button = self.win.component('buttonbox').button(0) button.configure(font=self.FONT, default='disabled', cursor='arrow', **self.BORDER) # TITLE # MESSAGE # Status : [ Running, stopped, error # Error: xxxxxxxxxxxxx # Elapsed: # Progress/process i = tk.Frame(self.win.interior(), relief='flat') #, bd=2) #, bg='white') # message f = tk.Frame(i) # , bg='white') if self.image: tk.Label(f, image=self.image).pack(anchor='w', side='left', expand=0, padx=6, pady=6) tk.Label(f, text=self.message, font=self.FONT).pack(anchor='w', side='left', expand=0, fill='x') f.pack(side='top', anchor='w', expand=0, fill='x', pady=5, padx=3) # status i.pack(expand=0, fill='both') i = tk.Frame(self.win.interior(), relief='sunken', bd=2, bg='white') # SPACER f = tk.Frame(i, bg='white') tk.Label(f, text='Status : ', width=20, anchor='e', bg='white', font=self.FONTbold).pack(anchor='w', side='left', expand=0, fill='x') self.status_label = tk.Label(f, width=30, text='ready', anchor='w', bg='white', font=self.FONT) self.status_label.pack(anchor='w', side='left', expand=0, fill='x') f.pack(side='top', anchor='w', expand=0, fill='x', padx=3) # elapsed time if self.showtime: f = tk.Frame(i, bg='white') tk.Label(f, text='Elapsed time : ', width=20, anchor='e', bg='white', font=self.FONTbold).pack(anchor='w', side='left', expand=0, fill='x') self.time_label = tk.Label(f, width=30, text='00 : 00 : 00', anchor='w', bg='white', font=self.FONT) self.time_label.pack(anchor='w', side='left', expand=0, fill='x') f.pack(side='top', anchor='w', expand=0, fill='x', padx=3) # error f = tk.Frame(i) self.error_title = tk.Label(f, text=' ', fg='red', bg='white', width=20, anchor='e', font=self.FONTbold) self.error_title.pack(anchor='w', side='left', expand=0, fill='x') self.error_label = tk.Label(f, width=30, text=' ', font=self.FONT, anchor='w', bg='white') self.error_label.pack(anchor='w', side='top', expand=0, fill='x') f.pack(side='top', anchor='w', expand=0, fill='x', padx=3) if self.progresstype == 'percent': #create percent bar f = tk.Frame(i, bg='white') self.progressBar = hf.ProgressBarThreadsafe(i, w=300, h=20) self.progressBar.pack(anchor='n', side='top', expand=0, fill='none') f.pack(side='top', anchor='n', expand=0, fill='none', padx=5, pady=8) elif self.progresstype == 'count': # create counter label # FIXME pass elif self.progresstype == None: # create the default "is alive" feedback self.dotsLabel = tk.Label(i, bg='white', text=self.rolling[0]) self.dotsLabel.pack() pass i.pack(expand=0, fill='both')
def writeConfig(self, fname=None): """ write the config file """ # XXX FIXME NOT WORKING if fname == None: fname = self.getConfigFile() self.settings = hf.writejson(fname, self.config)
def __init__(self, resource='local', dockengine='vina', eventmanager=None, racdir = None, debug=False): DebugTools.DebugObj.__init__(self, debug) if eventmanager == None: eventmanager = RaccoonEvents.RaccoonEventManager() self.eventManager = eventmanager self.dockengine = dockengine self.engine = RaccoonEngine.RaccoonEngine() self.engine.box_center = [ 0., 0., 0.] # results business self.results = {} self.resPropertiesReset() #self.eventManager.registerListener( RaccoonEvents.ResultsImportedDeleted, self.resPropertiesReset) self.eventManager.registerListener( RaccoonEvents.ResultsImportedDeleted, self.updateResultsProperties) self.eventManager.registerListener( RaccoonEvents.SyncJobHistory, self.syncServerHistory) self.filterEngine = RaccoonFilterEngine.FilterEngine(self, debug) # vs data source self.ligand_source = [] # this will contain objects to be called # to generate ligand filenames: # { 'lib': RaccoonLibrary, 'filters' : {} } self.knownTargets = {} # this is the database of all known and used targets stored with # unique MD5sum id # server object to wich we're connected # this should be one of RaccoonRemoteServer ('ssh'), RaccoonOpalServer ('opal') or # RaccoonLocalServer ('local') objects #damjan begin self.guse = None #damjan end self.server = None self.history = {} self.resource = resource # local, ssh, opal self.dockingservice = None self._system_info = hf.getOsInfo() self.ready = False self.settings = { 'engine' : dockengine, 'options': { 'save_username': True, 'save_password': False, }, # from config files 'servers': { 'ssh' : {}, # 'garibaldi' : { ''address': 'garibaldi.scripps.edu', # 'username': '******', # 'password': None, # 'pkey' : None, # file # '_save_passwd_' : False, # } 'opal': [], }, 'viewer': { }, # 3d viewer settings } self.resultsProcessor = vsg.RaccoonVsResultsGenerator(self, self.debug) self.setDockEngine(dockengine) #self.notebook.component('Config-tab').bind('<1>', cb) # less important stuff self._lastdir = None # /less important stuff if racdir == None: racdir = os.getenv("RACDIR") if racdir == None: racdir = os.path.expanduser('~') + os.sep + 'raccoon' print "[ RAC DIR SET TO [%s] ]" % racdir self.initRac(racdir)
def callback(self, name, count): """ callback to be passed to the processor""" self.label.configure(text=name) tot = len(self.ligands.keys()) self.pc_var.set( hf.percent(count, tot) ) self.progress.update()
def run_upload(self, name, dirname, remotepath, comment=None): """ """ # self.run_upload(name = libname, dirname = dirname, remotepath = remotepath) def _go(event=None): #server.debug = True #libobj.debug= True self.app.setBusy() if comment: libobj.info['comment'] = comment libobj.upload( dirname, remotepath, autoregister=0, bg = True) self.RUNNING = True self._stopclosebutton.configure(text= 'Stop', command=stop) status = server.transfer.progress(percent=1) while status < 100.: if server.transfer._STOP: break status = server.transfer.progress(percent=1) pc_var.set(status) self.bar.update() time.sleep(0.2) self.RUNNING = False libobj.debug = True # DEBUG if server.transfer._status['completed']: # EVENT trigger the event refresh of server list #idxfile = remotepath + '/'+ dirname +'/'+'library.db' #idxfile = 'library.db' self._statuslab1.configure(text='Generating index file') self._statuslab2.configure(text='...saving...') libobj.saveIndex() self._statuslab1.configure(text='Registering library to Library Index') self._statuslab2.configure(text='...ongoing...') libobj.register() self._statuslab1.configure(text='\nLibrary upload completed!') self._statuslab2.configure(text=' ') del self._ligand_list[:] self.delete(nuke=True) e = RaccoonEvents.ServerConnection() self.app.eventManager.dispatchEvent(e) else: error = server.transfer_status['error'] self._statuslab1.configure(text='Error trasnferring files!') self._statuslab2.configure(text=error) self._stopclosebutton.configure(text= 'Close', command=forceclose) self.app.setReady() def close(event=None): if event == None: #print "probably clicking on the corner..." return win.destroy() def stop(event=None): t = 'Stop transfer' m = 'The transfer is incomplete: do you want to stop it?' if not tmb.askyesno(parent = win.interior(), title=t, message=m): return server.transfer.stop() self._stopclosebutton.configure(text= 'Close', command=close) forceclose = CallbackFunction(close, True) ## print ">> adding ligands to lib object" # threaded files scanning... server = self.app.server libobj = RaccoonLibraries.LigandLibrary( server, name = name ) libobj.options['split'] = 1000 func = libobj.addLigands func_kwargs = {'ligands' : self._ligand_list } m = ('Extracting ligand properties...' ) self.app.setBusy() progressWin = rb.ProgressDialogWindowTk(parent = self.parent, function = func, func_kwargs = func_kwargs, title ='Ligand library', message = m, operation = 'ligand properties extraction', image = self._ICON_open, autoclose=True, progresstype='percent') progressWin.start() problematic = progressWin.getResults() if problematic == None: problematic = [] # normalize data structure self.app.setReady() #if response == None: #libobj.addLigands(self._ligand_list) # XXX TODO FIXME win = Pmw.MegaToplevel(master = self.win.interior(), title = 'Library manager') win.userdeletefunc(close) win.component('hull').configure(width=600, height=400) fullpath = remotepath + '/' + dirname self._statuslab1 = tk.Label(win.interior(), text = 'Transferring files...', font=self.FONTbold) self._statuslab1.pack(expand=0, fill='x', anchor='w', side='top') self._statuslab2 = tk.Label(win.interior(), text = 'Destination: %s' % fullpath, font=self.FONT) self._statuslab2.pack(expand=0, fill='x', anchor='w', side='top') pc_var = tk.DoubleVar(value=0.) self.bar = hf.ProgressBar(win.interior(), pc_var) self.bar.pack(expand=0, fill='none', anchor='n', side='top',padx=5, pady=3) tk.Frame(win.interior(),height=2,width=1,bd=1,relief='sunken').pack(expand=0, fill='x', anchor='w', side='top') self._stopclosebutton = tk.Button(win.interior(), text='STOP', font=self.FONT) self._stopclosebutton.pack(expand=0, fill='none', anchor='s', side='bottom') win.interior().after(50, _go) win.activate() # geometry='centerscreenalways' )
def ask_upload(self): """upload to remote location""" if len(self._ligand_list) == 0: return def close(event=None): if event == 'Start': server = self.app.server # check if lib name is in use libname = self._lname.getvalue() lib = server.getLibrary(libname) if lib: # and lib.info['type'] == self.info['type']: t = 'Name already in use' m = ('There is already a %s library with the same name.\n\n' 'Choose a different name and try again.') % self._type i = 'warning' tmb.showinfo(parent=win.interior(), title=t, message=m, icon=i) return # check directory name dirname = self._dname.getvalue() remotepath = self._remotepath.getvalue() fullpath = remotepath + '/' + dirname if server.ssh.exists(fullpath): t = 'Directory exist' m = ('There is already a directory with the same in the' 'remote path. Select a different dirname ' 'and try again.') i = 'warning' tmb.showinfo(parent=win.interior(), title=t, message=m, icon=i) self.app.setReady() return # comments, if any comment = self._comment.get('1.0', 'end').strip() win.destroy() self.app.setBusy() self.run_upload(name = libname, dirname = dirname, remotepath = remotepath, comment = comment) # once files habe been uploaded, clean up the engine from used files self.app.engine.removeLigands() self.app.setReady() else: win.destroy() self.app.setReady() def makedirname(event=None): """ ButtonRelease """ chars = hf._allowedfilenamechars() text = self._lname.getvalue() if not len(text): self._dname.setvalue('') valid = [ x for x in text if x in hf._allowedfilenamechars()] valid = "".join(valid).lower() self._dname.setvalue(valid) def setdefaultremote(event=None): self._remotepath.setvalue( self.app.server.getLibraryPath() ) #settings = { 'split' : 1000, # } win = Pmw.Dialog(self.win.interior(), title = 'Upload library', buttons = ('Start','Cancel'), command=close) w = win.interior() bbox = win.component('buttonbox') for i in range(bbox.numbuttons()): bbox.button(i).configure(font=self.FONT, default='disabled', **self.BORDER) w.pack_configure(ipadx=10, ipady=10) tk.Label(w, text=' ', image=self._ICON_upload, anchor='n', font=self.FONTbold).grid(row=0, column=0, sticky='we', columnspan = 3) tk.Label(w, text='Library name', anchor='e', font=self.FONT).grid(row=1, column=1, sticky='e') self._lname = Pmw.EntryField( w, validate = {'min':1,'minstrict':0}, entry_width=30, entry_font=self.FONT) self._lname.component('entry').bind('<KeyRelease>', makedirname) self._lname.grid(row=1, column=2,sticky='w',columnspan=1) tk.Label(w, text='Remote path', anchor='e', font=self.FONT).grid(row=3, column=1, sticky='e') self._remotepath = Pmw.EntryField( w, validate = {'min':1,'minstrict':0}, entry_width=30, entry_font=self.FONT) self._remotepath.grid(row=3, column=2,sticky='w',columnspan=1) tk.Button(w, text='D', command=setdefaultremote,image=self._ICON_default, **self.BORDER).grid(row=3, column=3, sticky='w') # FIXME probably useless, this should be hidden to the user! #tk.Label(w, text='Directory name', anchor='e').grid(row=5, column=1, sticky='e', # entry_font=self.FONT) self._dname = Pmw.EntryField( w, validate = hf.validateFname, entry_width=30) #self._dname.grid(row=5,column=2, sticky='w', columnspan=1) tk.Label(w, text='Comments', anchor='e', font=self.FONT).grid(row=6, column=1, sticky='e') self._comment = hf.TextCopyPaste( w, bg='white', height=10, width=30, font=self.FONT) self._comment.grid(row=6,column=2, sticky='w') setdefaultremote() win.activate() # geometry='centerscreenalways' )
def __init__(self, parent, update_cb=None, debug=False): #, destroy_cb): rb.RaccoonDefaultWidget.__init__(self, parent) DebugTools.DebugObj.__init__(self, debug) Pmw.Group.__init__(self, parent=parent, tag_text='Target interactions', tag_font=self.FONTbold, ring_border=1, ring_highlightcolor='black', ring_highlightbackground='black', ring_highlightthickness=1, ring_relief='flat') self.eventManager = RaccoonEvents.RaccoonEventManager() self.eventManager.registerListener( RaccoonEvents.FilterInteractionEvent, self.update) self.initIcons() self.filters = [] self.update_cb = update_cb self.container = tk.Frame( self.interior()) # this contains the widgets on the left # build toolbar self.toolbar = tk.Frame(self.container) # add button b = tk.Button(self.toolbar, text='+', image=self._ICON_add, command=self.add, **self.BORDER) b.pack(anchor='w', side='left') # remove button b = tk.Button(self.toolbar, text='-', image=self._ICON_del, **self.BORDER) b.pack(anchor='w', side='left', padx=1) selmenu = [ None, ['Remove inactive', 'normal', self.removeInactive], ['Remove all', 'normal', self.nuke], ] menu = rb.RacMenu(b, selmenu, placement='under') # selection button menu b = tk.Button(self.toolbar, text='s', image=self._ICON_selmenu, **self.BORDER) b.pack(anchor='w', side='left', padx=0) selmenu = [ None, ['Activate all', 'normal', self.setAllActive], ['Deactivate all', 'normal', self.setAllInactive], ['Invert active/inactive', 'normal', self.invertStatus], ] menu = rb.RacMenu(b, selmenu, placement='under') # mode pulldown self._mode_choices = {'match all': 'all', 'match any': 'any'} self.modeChoice = OptionMenuFix( self.toolbar, menubutton_font=self.FONT, menu_font=self.FONT, menubutton_width=10, menubutton_bd=1, menubutton_highlightbackground='black', menubutton_borderwidth=1, menubutton_highlightcolor='black', menubutton_highlightthickness=1, menubutton_height=1, #command = self.trigger, items=sorted(self._mode_choices.keys(), reverse=True), ) f = tk.Frame(self.toolbar) self.labelActiveFilt = tk.IntVar(value='0') tk.Label(f, text='active filters:', font=self.FONT).pack(anchor='w', side='left') tk.Label(f, textvar=self.labelActiveFilt, font=self.FONTbold).pack(anchor='w', side='left') f.pack(anchor='w', side='left', padx=15) self.modeChoice.pack(anchor='w', side='right', padx=1) self.toolbar.pack(anchor='w', side='top', expand=1, fill='x', padx=4, pady=2) # build filter filtFrame self.filtFrame = Pmw.ScrolledFrame( self.container, horizflex='expand', # vertflex='expand', vscrollmode='static', hscrollmode='dynamic') #self.filtFrame.component('hull').configure(**self.BORDER) self.filtFrame.component('clipper').configure(bg='white') self.filtFrame.component('frame').configure(relief='flat', bg='white') #self.filtFrame.component('vertscrollbar').bind("<Button-4>", self.mousescroll) for c in [ 'borderframe', 'clipper', 'frame', 'horizscrollbar', 'hull', 'vertscrollbar' ]: self.filtFrame.component(c).bind("<Button-4>", self.mousescroll) self.filtFrame.component(c).bind("<Button-5>", self.mousescroll) self.interior().bind("<Button-4>", self.mousescroll) self.interior().bind("<Button-5>", self.mousescroll) self.filtFrame.pack(anchor='w', side='top', expand=1, fill='both', padx=4, pady=2) self.container.pack(anchor='w', side='left', expand=1, fill='both') self.percentageFrame = tk.Frame( self.interior()) # this contains the widgets on the right # pie self.pie = hf.PercentPie(self.percentageFrame, radius=50) self.pie.pack(anchor='n', side='top', padx=5, pady=5) #self.pie.set_percent(20) # passed label f = tk.Frame(self.percentageFrame) tk.Label(f, text='passed :', font=self.FONTbold).pack(side='left', anchor='w') self.statusLabel = tk.Label(f, text='0', width=8, anchor='w', font=self.FONT) self.statusLabel.pack(side='left', anchor='w') f.pack(anchor='n', side='top') #self.percentageFrame.pack(anchor='e',side='left', expand=1, fill='y') self.percentageFrame.pack(expand=0, fill=None, anchor='e', side='left')