def openSaveDialog(self, title='Save Animation', fileext="_animation"): dialog = Pmw.Dialog(self.master, buttons=('OK', 'Cancel'), defaultbutton='OK', title=title) dialog.withdraw() savesession = Tkinter.IntVar() savesession.set(1) frame = dialog.interior() checkb = Tkinter.Checkbutton(frame, text="Save Pmv Session", variable=savesession) checkb.pack(side='top', anchor='w') entry = Pmw.EntryField(frame, label_text="File name:", labelpos='w') entry.pack(expand=1, fill='both', padx=4, pady=4, side='left') self.balloon.bind( entry, "Enter a filename.\nfilename%s.py and filename_session.psf\nwill be created" % (fileext, )) button = Tkinter.Button(frame, text="BROWSE", command=CallbackFunction( self.saveFileDialog_cb, entry, fileext)) button.pack(side='left') ans = dialog.activate( geometry='+%d+%d' % (self.master.winfo_x() + 300, self.master.winfo_y() + 100)) filename = entry.get() return ans, filename, savesession.get()
def set(self, column, value): tree = self.tree() col = tree.columns[column] fill = col.buttonColors val = self.chkbtval[column] #print 'AAAAAAAA SET', col.name, value, val, len(self.chkbtid) if value: if val: #tree.redraw() return val = self.chkbtval[column] = 1 else: if not val: #tree.redraw() return val = self.chkbtval[column] = 0 if len(self.chkbtid): # length==0 when node is not drawn if self.chkbtid[column] and not col.showPercent: tree.canvas.itemconfigure(self.chkbtid[column], fill=fill[val]) if col.commandType=='button' and val==1: cb = CallbackFunction(self.resetButtons, column) tree.master.after(100, cb) if col.inherited: tree.manageChildren(self, column)
def createColHeader(self, columnDescr, number): cw = self.colWidth x = self.treeWidth + (0.5*self.colWidth) # add column background if number%2: _id = self.canvas.create_rectangle( x+number*cw-cw/2, 0, x+number*cw+cw/2, 10000, tags=('backgroundStripes',), fill='#EEEEEE', outline='#EEEEEE') # add title and icon _id = self.canvas.create_text( x+number*cw, 7, text=columnDescr.title, justify='center', tags=('ColHeaders',), fill=columnDescr.color, font=self.font) cb = CallbackFunction(self.rightButtonClick, columnDescr) self.canvas.tag_bind(_id, "<Button-3>", cb) self.colLabIds.append(_id) # add column header icons if columnDescr.iconfile: if columnDescr.icon is None: columnDescr.getIcon(columnDescr.iconfile) _id = self.canvas.create_image( x+number*cw, 19,tags=('ColHeaders',), image=columnDescr.icon) self.colLabIds.append(_id)
def makewin(self): """ """ self.win = Pmw.MegaToplevel(master = self.parent, title = 'Library Manager') topbar = tk.Frame(self.win.interior()) tk.Label(topbar, text='Add files to create a new %s library...' % self._type, font=self.FONT, compound='left', image = self._ICON_package).pack(anchor='w',side='left',pady=5, expand=1,fill='x') topbar.pack(anchor='n', side='top',expand=0, fill='x',padx=5, pady=1) ### # settings button # XXX DISABLED ### b = tk.Button(left_tbar, image= self._ICON_sys, **self.BORDER) ### b.pack(anchor='n', side='top',expand=0, fill='x') self.center = Pmw.Group(self.win.interior(), tag_text = 'Local files [ 0 ]', tag_font=self.FONTbold) left_tbar = tk.Frame(self.center.interior()) b = tk.Button(left_tbar, text='', image=self._ICON_open, **self.BORDER) b.pack(anchor='n', side='top',expand=0, fill='x') addlig_items = [ ['Add ligands'], ['Import files...', 'normal', self.openfiles], [], ['Scan directory...', 'normal', self.open_dirs], ['Scan directory (recursively)...', 'normal', self.open_dirs_recursive], ] menu = rb.RacMenu(b, addlig_items, toolbar=left_tbar) b = tk.Button(left_tbar, text='[X]', image=self._ICON_remove, **self.BORDER) b.pack(anchor='n', side='top',expand=0, fill='x', pady=1) addlig_items = [ ['Remove ligands'], ['Remove selected', 'normal', self.delete], ['Remove all', 'normal', self.delete_all], ] menu = rb.RacMenu(b, addlig_items, toolbar=left_tbar) left_tbar.pack(anchor='w', side='left', expand=0,fill='y',pady=2,padx=2) self.fmanager = Pmw.ScrolledListBox(self.center.interior(), listbox_font=self.FONT, listbox_selectmode='extended') self.fmanager.pack(expand=1, fill='both', anchor='n', side='top',padx=2, pady=1) delkey = CallbackFunction(self.delete, **{'nuke':False}) self.fmanager.component('listbox').bind('<Delete>', delkey) #damjan begin if not self.app.guse == None: self.uploadButton = tk.Button(self.center.interior(), text='Prepare for gUSE', width=400, image=self._ICON_upload, compound='left', command=self.prepare_ligands_for_guse, font=self.FONT, state='disabled', **self.BORDER) else: self.uploadButton = tk.Button(self.center.interior(), text='Upload...', width=400, image=self._ICON_upload, compound='left', command=self.ask_upload, font=self.FONT, state='disabled', **self.BORDER) #damjan end self.uploadButton.pack(anchor='s', side='bottom', expand=0, fill='x',padx=2, pady=2) self.center.pack(expand=1, fill='both', side='left',anchor='n',padx=3) right = tk.Frame(self.win.interior()) b6 = tk.Button(right, text='Close', command=self.destroy, font=self.FONT, **self.BORDER) b6.pack(anchor='s', side='bottom',expand=1,fill='x') right.pack(anchor='e', side='bottom', expand=0, fill='y', pady=6,padx=5) self.win.activate()
def openLoadDialog(self, title='Save Animation', fileext="_animation"): dialog = Pmw.Dialog(self.master, buttons=('OK', 'Cancel'), defaultbutton='OK', title=title) dialog.withdraw() frame = dialog.interior() entry1 = Pmw.EntryField(frame, label_text="Animation file:", labelpos='w') entry1.grid(row=0, column=0, padx=5, pady=5, sticky='w') button1 = Tkinter.Button(frame, text="BROWSE") button1.grid(row=0, column=1, padx=5, pady=5, sticky='w') loadsession = Tkinter.IntVar() loadsession.set(1) checkb = Tkinter.Checkbutton(frame, text="Load Pmv Session", variable=loadsession) checkb.grid(row=1, column=0, padx=5, pady=5, sticky='w') entry2 = Pmw.EntryField(frame, label_text="Session file:", labelpos='w') entry2.grid(row=2, column=0, padx=5, pady=5, sticky='w') button2 = Tkinter.Button(frame, text="BROWSE") button2.grid(row=2, column=1, padx=5, pady=5, sticky='w') button1.configure(command=CallbackFunction( self.openFileDialog_cb, entry1, entry2, title, fileext)) button2.configure(command=CallbackFunction( self.openFileDialog_cb, entry2, entry1, title, fileext)) self.balloon.bind(entry1, "Enter path to the animation file.") self.balloon.bind(entry2, "Enter path to the Pmv session file.") ans = dialog.activate( geometry='+%d+%d' % (self.master.winfo_x() + 300, self.master.winfo_y() + 100)) animfile = entry1.get() sessionfile = entry2.get() return ans, animfile, sessionfile, loadsession.get()
def makeMAAButton(self, maa): """ Places a button into created Actions group """ assert isinstance(maa, MultipleActorsActions) # add the maa self.maas.append(maa) master = self.createdActionsG.interior() cb = CallbackFunction(self.runMaa, maa) b = Tkinter.Button(master=master, compound='left', command=cb, width=0, height=0) self.maaButtons.append(b) if hasattr(maa, "shortName"): shortName = maa.shortName else: shortName = maa.__class__.__name__ if not self.maaButtonNames.has_key(shortName): self.maaButtonNames[shortName] = 1 count = self.maaButtonNames[shortName] self.maaButtonNames[shortName] += 1 text = "%s%d" % (maa.shortName, count) b.configure(text=text) nbuttons = len(self.maas) - 1 row = nbuttons / 4 col = nbuttons % 4 b.grid(row=row, column=col, sticky='w') #self.balloon.bind(b, maa.name) # the balloon will display a string returned by maa.__repr__() self.balloon.bind(b, maa) b.bind('<Button-3>', CallbackFunction(self.maaMenu_cb, maa, b))
def __init__(self, pmv, master=None): assert isinstance(pmv, MoleculeViewer) from Pmv.GeomFilter import GeomFilter self.gf = GeomFilter(pmv) filterFunction = self.gf.filter vi = pmv.GUI.VIEWER kw = { 'showAll': False, 'filterFunction': filterFunction, 'refreshButton': True, 'showAllButton': True } gcOpt = [(), kw] ShowHideGeomPanel.__init__(self, vi, 'pmv.GUI.VIEWER', GeomChooser, gcOpt, master=master) self.lastRow += 1 # select 'All' entry by default gc = self.geomChooser gc.chooserW.lb.select_set(0) self.selectedGeom = [[0], [vi.rootObject]] frame = self.effectsContainer # partial fade in button cb = CallbackFunction(self.makeMAA, PartialFadeMolGeomsMAA, (gc, ), {'pmv': pmv}) parent = self.makeActionsG.interior() w = self.pfadeB = Tkinter.Button(parent, text='Partial fade', command=cb) w.grid(column=0, row=self.lastRow, sticky='ew') w.bind( '<Button-3>', CallbackFunction(self.showMaaEditor_cb, PartialFadeMolGeomsMAA, (), {'pmv': pmv}))
def __init__(self, pmv, master=None): assert isinstance(pmv, MoleculeViewer) vi = pmv.GUI.VIEWER self.pmv = pmv AnimationPanel.__init__(self, vi, 'pmv.GUI.VIEWER', master) gc = self.geomChooser = PmvGeomChooser( pmv, root=self.geomChooserG.interior(), showAll=False, refreshButton=True, showAllButton=True, command=self.onSelect_cb) gc.pack(side='top', fill='both', expand=1, anchor="w") # select 'All' entry by default gc.chooserW.lb.select_set(0) self.selectedGeom = [[0], [pmv.GUI.VIEWER.rootObject]] # add action creating buttons parent = self.makeActionsG.interior() self.colorClips = {} for lastRow, txt in enumerate(colorCmds.keys()): #if txt == "choose color": continue cb = CallbackFunction(self.makeMAA, PmvColorObjectMAA, (), { 'pmv': pmv, 'colortype': txt }) w = Tkinter.Button(parent, text=txt, command=cb) w.grid(column=0, row=lastRow, columnspan=2, sticky='ew') w.bind( '<Button-3>', CallbackFunction(self.showMaaEditor_cb, PmvColorObjectMAA, (), { 'pmv': pmv, 'colortype': txt })) self.lastRow = lastRow
def add(self, event=None, settings={}): """ add a new filter widget if settings is not empty, the new filter will be initialized with the specified values """ f = InteractionFilterWidget(self.filtFrame.interior(), manager=self, settings=settings) cb = CallbackFunction(self.destroy, f) f.destroy_cb = cb self.filters.append(f) f.pack(anchor='w', side='top', padx=2, pady=1, expand=1, fill='x')
def displayValue(self): """Add things to the rigth side of the tree """ if len(self.chkbtVar)==0: return master = self.tree.master canvas = self.tree.scrolledCanvas.interior() tree = self.tree dx = self.x-self.tree.offx level = dx/OFFSET col = ['gray75', 'red', 'cyan', 'green', 'yellow'] for i in range(tree.nbColumns): if not tree.colHasButtton(i, self.objectKey.__class__): self.chkbt.append(None) continue v = self.chkbtVar[i] cb = CallbackFunction(self.buttonClick, self, i ) button = Tkinter.Checkbutton(canvas, variable=v, command=cb, padx=0, pady=0, background=col[level-1], activeforeground='pink') self.chkbt.append(button) cid = canvas.create_window( 20 + self.tree.offx + 175 + i*35, self.y, window=button, width=20, height=15) self.canvasIDs.append(cid) # add secondary structure glyph molFrag = self.objectKey if isinstance(molFrag, Residue): if hasattr(molFrag, 'secondarystructure'): ssname = molFrag.secondarystructure.name if ssname[:6]=='Strand': color = '#FFF700' elif ssname[:4]=='Coil': color = 'grey45' elif ssname[:5]=='Helix': color = '#FF198C' elif ssname[:4]=='Turn': color = 'blue' cid = canvas.create_rectangle( 150 + self.tree.offx, self.y-10, 160 + self.tree.offx, self.y+10, outline=color,fill=color) self.canvasIDs.append(cid) cid = canvas.create_text( 162 + self.tree.offx, self.y, text=ssname, anchor=Tkinter.W) # fill=color) self.canvasIDs.append(cid) func = tree.buttonValFunc[i] if func: func(self)
def maaMenu_cb(self, maa, button, event=None): """ Opens the saved clip menu (right mouse click on the clip button) """ menu = Tkinter.Menu(self.master, title=maa.name) ## cb = CallbackFunction(_clipboard.addMaa, maa) ## menu.add_command(label="Add to Clipboard", command=cb) from Scenario2 import addTargetsToMenu addTargetsToMenu(menu, maa) if maa.editorClass: cb = CallbackFunction(self.editMAA_cb, maa, button) menu.add_command(label="Edit ...", command=cb) menu.add_command(label="Delete", command=CallbackFunction(self.deleteMAA_cb, maa, button)) menu.add_command(label="Dismiss menu") menu.post(event.x_root, event.y_root)
def shiftButtonClick(self, column, event=None): # get called for each checkbutton tree = self.tree() menu = self.menu if menu.index(0) == 0: # there is something in the menu, remove it menu.delete(0, 100) for i, menuEntry in enumerate(tree.menuEntries[column]): v = self.menuVars[column][i] cb = CallbackFunction(self.menu_cb, column, menuEntry, i) menu.add_checkbutton(label=menuEntry, variable=v, command=cb) menu.post(event.x_root, event.y_root)
def createCheckbuttons(self, object): # get menu button if isinstance(object, Geom): menuB = self.animObjMenuB elif isinstance(object, Camera): menuB = self.animCamMenuB elif isinstance(object, Light): menuB = self.animLightMenuB elif isinstance(object, ClippingPlane): menuB = self.animClipMenuB else: print 'no menu button for object:', object, object.__class__ return # clear menu's content menuB.menu.delete(0, 'end') # get list of properties p1 = object.animatableProps[0].keys() p1.sort() propnames = p1 #p2 = object.animatableProps[1].keys() #p2.sort() #propnames = p1+p2 # get dict of currently animated properties for this object #aprop = object.animatedProperties aprop = self.animatedProperties for i, name in enumerate(propnames): var = Tkinter.IntVar() actorname = getActorName(object, name) if aprop.has_key(actorname): var.set(1) aprop[actorname].guiVar = var cb = CallbackFunction( self.toggleAnimatePropVar, name, var, object) menuB.menu.add_checkbutton( label=name, command=cb, variable = var) menuB.menu.add_separator() cb = CallbackFunction(self.actorFromFile_cb, propnames, object) menuB.menu.add_command( label="Create Actor From File", command=cb)
def selectColor(self, event=None): colNum = self.colorVar.get() hcol = self.colors[colNum] rgb = int(hcol[1:3], 16), int(hcol[3:5], 16), int(hcol[5:7], 16) col = [x / 255. for x in rgb] if colNum > 47: # custom color self.ce.pack(side='right', fill='both', expand=1) if self.currentEditingCB: self.ce.cbManager.RemoveCallback(self.currentEditingCB) cb = CallbackFunction(self.editCustom, custColNum=colNum - 48) self.ce.cbManager.AddCallback(cb) self.ce.set(col, trigger=0) self.currentEditingCB = cb else: self.ce.pack_forget() self.cbManager.CallCallbacks(col)
def makeInterfaceSsh(self): """ """ bset = { 'bg': '#969b9d' } # 'width' : 22, 'height': 22, 'relief' : 'raised'} bset = {} bset.update(self.BORDER) self.resetFrame() self.recGroup = Pmw.Group(self.frame, tag_text='Accepted structures [ 0 ]', tag_font=self.FONTbold) # toolbar toolb = tk.Frame(self.recGroup.interior()) if self.sysarch == 'Windows': bwidth = 54 else: bwidth = 32 ###### add button # make button b = tk.Button(toolb, text='Add...', compound='top', image=self._ICON_add, width=bwidth, font=self.FONTbold, **bset) b.pack(anchor='n', side='top') # make menu items addrec_items = [ ['Add receptors'], ['Import files...', 'normal', self.openfiles], [], ['Scan directory...', 'normal', self.opendir], [ 'Scan directory (recursively)...', 'normal', self.opendir_recursive ], # [], # ['Select structure from history...', 'normal', self.opendir], ] # make menu menu = rb.RacMenu(b, addrec_items, toolbar=toolb) ###### add button # make button b = tk.Button(toolb, text='Remove...', compound='top', image=self._ICON_rem, width=bwidth, font=self.FONTbold, **bset) b.pack(anchor='n', side='top', pady=1) # make menu items addrec_items = [ ['Remove receptors'], ['Remove selected', 'normal', self.deletefiles], ['Remove all', 'normal', self.deleteallfiles], ] # make menu menu = rb.RacMenu(b, addrec_items, toolbar=toolb) # #tk.Button(toolb, text='Settings\n&\nAlignment...', compound='top', image = self._ICON_sys, width=32, # font=self.FONTbold, **bset ).pack(anchor='n', side='top',pady=1) toolb.pack(side='left', anchor='w', expand=0, fill='y', pady=0) # files manager self.recFileManager = TkTreectrl.ScrolledMultiListbox( self.recGroup.interior(), bd=2) self.recFileManager.listbox.config( bg='white', fg='black', font=self.FONT, columns=('name', 'chains', 'res.', 'flex_res', 'atom types', 'unk.types', 'filename'), selectmode='extended', ) delkey = CallbackFunction(self.deletefiles, {'nuke': False}) self.recFileManager.listbox.bind('<Delete>', delkey) self.recFileManager.pack(anchor='w', side='left', expand=1, fill='both') self.recGroup.pack(anchor='n', side='top', expand=1, fill='both') self.frame.pack(expand=1, fill='both', anchor='n', side='top')
def tagBind(self): self.canvas.bind("<Motion>", self.OnCanvas) lid = self.canvas.find_withtag("line_"+self.uniqueId) for i in lid: cb = CallbackFunction(self.OnLine,i) self.canvas.tag_bind(i,"<Motion>",cb)
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 loadStyles(self): # find the location fo the styles directory import Image, ImageTk from Pmv import styles path = styles.__path__[0] from glob import glob styleFiles = glob(os.path.join(path, "*_style.py")) styleFiles.sort() self.styleRow = self.styleCol = 0 inside = self.stylesScrolledFrame.interior() self.styles = {} currentx = 0 currenty = 0 border = 1 for sfile in styleFiles: # import the function name = os.path.basename(sfile)[:-9] modpath = 'Pmv.styles.' + name + '_style' mod = __import__(modpath, {}, {}, ['*']) styleObj = Style(name, mod.applyStyle, mod.numberOfMolecules, mod.__doc__) self.styles[name] = styleObj photoIcon = ImageTk.PhotoImage( file=os.path.join(path, name + '_icon.png')) cb = CallbackFunction(self.applyStyle, styleObj) b = Tkinter.Button(inside, compound='left', image=photoIcon, command=cb) b.photo = photoIcon width = b.photo.width() height = b.photo.height() b.place(x=currentx, y=currenty, width=width, height=height) textw = Tkinter.Label(inside, text=name, justify='left') textw.place(x=width + border, y=currenty) textw.update() # to allow label to appear and size to be correct currenty += max(textw.winfo_height(), height + border) # bind callback to display large version photo = ImageTk.PhotoImage(file=os.path.join(path, name + '.png')) cb = CallbackFunction(self.showLargeImage, photo, mod.__doc__) b.bind('<Enter>', cb) b.bind('<Motion>', self.move_cb) b.bind('<Leave>', self.leave_cb) b.photo1 = photo #self.balloon.bind(b, mod.__doc__) #print 'adding style', name, currenty, self.styleRow,self.styleCol if self.styleCol == 3: self.styleCol = 0 self.styleRow = self.styleRow + 1 else: self.styleCol = self.styleCol + 1
def drawNodeCustomization(self, x, y): """ Add things to the rigth side of the tree """ tree = self.tree() canvas = tree.canvas level = 2 col = ['gray75', 'red', 'cyan', 'green', 'yellow'] nbButtons = tree.nbCol x = tree.treeWidth # create Tk variables if needed if len(self.chkbtid)==0: nbButtons = tree.nbCol self.chkbtid = [None]*nbButtons i = 0 cw = tree.colWidth for i, val in enumerate(self.chkbtval): col = tree.columns[i] if self.object.__class__ in col.objClassHasNoButton: continue xo = x+i*cw cw2 = cw/2 midx = xo+cw2 midy = y + tree.fontSize/2 + 2 cid1 = None color = col.color width = 1 if self.buttonType=='OnOffButtons' and not col.onOnly: # overrides col.commandType and put 2 buttons for on off #uniq = '%d_%d'%(midx,midy) cid = canvas.create_oval( midx-cw2+1, midy-cw2+1, midx+1, midy+1, outline='#3D8E54', width=width, fill='#44A05E', tags=('on','button')) canvas.addtag_withtag(str(cid), cid) if col.cbOn is None: cb1 = CallbackFunction(self.onOffButtonClick, i, 1) else: cb1 = CallbackFunction(col.cbOn, self, i, 1) cb2 = CallbackFunction(col.optMenu_cb, self, i) balloon = col.onButtonBalloon%(self.object.name) cid1 = canvas.create_oval( midx-1, midy-1, midx+cw2-1, midy+cw2-1, outline='#B52121', width=width, fill='#E2282D', tags=('off','button')) canvas.addtag_withtag(str(cid1), cid1) if col.cbOff is None: cb1_1 = CallbackFunction(self.onOffButtonClick, i, 0 ) else: cb1_1 = CallbackFunction(col.cbOff, self, i, 0) cb2_1 = None balloon1 = col.offButtonBalloon%(self.object.name) else: shape = col.buttonShape sx2 = cw/2-2 sy2 = tree.fontSize/2 fill = col.buttonColors from MolKit.listSet import ListSet if shape=='circle': sy2 = min(sx2, sy2) if col.showPercent: fillCol = fill[0] else: fillCol = fill[val] cid = canvas.create_oval( midx-sx2, midy-sy2, midx+sx2, midy+sy2, outline=color, width=width, fill=fillCol, tags=('button',)) if col.showPercent and not isinstance(self.object, ListSet): if hasattr(self.object,col.showPercent): extent = getattr(self.object,col.showPercent)*360 if extent>0.0: #print 'YES', self.object.name, col.showPercent, extent if extent==360.: # special case full disc as sometimes # extent 360 shows nothing cid1 = canvas.create_oval( midx-sx2, midy-sy2, midx+sx2, midy+sy2, fill=fill[1], outline='', tags=('button',)) self.chkbtval[i] = 1 else: cid1 = canvas.create_arc( midx-sx2, midy-sy2, midx+sx2, midy+sy2, extent=-extent, fill=fill[1], outline='', tags=('button',)) self.chkbtval[i] = 0 else: self.chkbtval[i] = 0 elif shape=='oval': cid = canvas.create_oval( midx-dx, midy-dx, midx+dx, midy+dy, outline=color, width=width, fill=fill[val], tags=('button',)) elif shape=='square': dx = min(sx2, sy2) cid = canvas.create_rectangle( midx-dx, midy-dx, midx+dx, midy+dy, outline=color, width=width, tags=('button',))# fill=fill[val]) elif shape=='downTriangle': cid = canvas.create_polygon( midx-sx2, midy-sy2, midx+sx2, midy-sy2, midx, midy+sy2, midx-sx2, midy-sy2, outline=color, width=width, fill=fill[val], tags=('button',)) elif shape=='rectangle': if col.showPercent: fillCol = fill[0] else: fillCol = fill[val] cid = canvas.create_rectangle( midx-sx2, midy-sy2, midx+sx2, midy+sy2, outline=color, width=width, fill=fillCol, tags=('button',)) if col.showPercent and not isinstance(self.object, ListSet): if hasattr(self.object,col.showPercent): extent = getattr(self.object, col.showPercent) #print 'Redraw 1', self.object, extent if extent>0.0: cid1 = canvas.create_rectangle( midx-sx2+1, midy+sy2, midx+sx2-1, midy-sy2+2*sy2*(1.-extent), fill=fill[1], outline='', tags=('button',)) self.chkbtval[i] = int(extent) else: self.chkbtval[i] = 0 elif shape=='diamond': hw = sx2 hh = sy2 cid = canvas.create_polygon( midx, midy-sy, midx+sx, midy, midx, midy+sy, midx-sx, midy, midx, midy-sy, fill=fill[val], width=width, outline=color, tags=('button',)) if cid1: cb1_1 = CallbackFunction(self.buttonClick, i ) cb2_1 = CallbackFunction(col.optMenu_cb, self, i ) balloon1 = col.buttonBalloon%(self.object.full_name()) if col.cbOn is None: cb1 = CallbackFunction(self.buttonClick, i ) else: cb1 = CallbackFunction(col.cbOn, self, i, 1) if col.cbOff is None: cb2 = CallbackFunction(col.optMenu_cb, self, i ) else: cb2 = CallbackFunction(col.cbOff, self, i, 0) balloon = col.buttonBalloon%(self.object.full_name()) if cid1: canvas.tag_raise(cid1) canvas.tag_bind(cid1, "<ButtonRelease-1>", cb1_1) if cb2_1: canvas.tag_bind(cid1, "<ButtonRelease-3>", cb2_1) tree.balloon.tagbind(canvas, cid1, balloon1) self.canvasIDs.append(cid1) self.chkbtid[i] = cid1 canvas.tag_bind(cid, "<ButtonRelease-1>", cb1) canvas.tag_bind(cid, "<ButtonRelease-3>", cb2) tree.balloon.tagbind(canvas, cid, balloon) self.canvasIDs.append(cid) self.chkbtid[i] = cid nodeHeight = tree.nodeHeight ## MS 09/10 this is molecular stuff, should not be in mglutil # add secondary structure glyph molFrag = self.object if isinstance(molFrag, Residue): if hasattr(molFrag, 'secondarystructure'): ssname = molFrag.secondarystructure.name if ssname[:6]=='Strand': color = '#FFFC6D' elif ssname[:4]=='Coil': color = 'grey45' elif ssname[:5]=='Helix': color = '#FF198C' elif ssname[:4]=='Turn': color = 'blue' #tw = tree.treeWidth tw = self.nodeStartX cid = canvas.create_rectangle( tw-20, y, tw-10, y+nodeHeight, outline=color, fill=color) self.canvasIDs.append(cid) tree.balloon.tagbind(canvas, cid, ssname) cb = CallbackFunction(self.toggleResSelection, molFrag.secondarystructure.residues) canvas.tag_bind(cid, "<ButtonRelease-1>", cb) #cid = canvas.create_text( 152, y, text=ssname, anchor='nw') # self.canvasIDs.append(cid) return x + (i*cw)
def setCallback(self, column, pmvcmd, iconName=None, balloonText=None, name='command', function=None, bValFunc=None): """define a callback for the checkbuttons in a given column. pmvcmd is the Pmv command to run in the callback associated with the checkbuttons and used to get default values using the 'default form. name is a string describing the command in that column, defaults to cmd.name iconName is the name of the icon to be used for the button balloonText is the tooltip, defaults to name. function is an option callback to override the default callback. It gets called with (node, column, pmvcmd) """ assert column<1000 def callback(node, column): # default call back # search for button because some commands do not have # buttons at all levels while node and not node.chkbt[column]: node = node.parent if node is None: return # get Pmv's command default arguments pmvcmd = node.tree.pmvcmd[column] defaultValues = pmvcmd.getLastUsedValues() # handle negate key to reflect state of checkbutton val = node.chkbtVar[column].get() if defaultValues.has_key('negate'): defaultValues['negate'] = not val defaultValues['callListener'] = False # apply the command at each level of the current selection for obj in node.getObjects(column): apply( pmvcmd, (obj,), defaultValues) if pmvcmd.lastUsedValues['default'].has_key('callListener'): del pmvcmd.lastUsedValues['default']['callListener'] if function is None: function = callback self.callbacks[column] = function self.buttonValFunc[column] = bValFunc if name is None: if hasattr(function, 'name'): name = function.name self.names[column] = name self.pmvcmd[column] = pmvcmd if balloonText is None: balloonText = name self.balloonText[column] = balloonText if iconName: iconfile = os.path.join(self.ICONDIR, iconName) image = Image.open(iconfile) im = ImageTk.PhotoImage(image=image, master=self.master) self.iconList[column] = im v = Tkinter.IntVar() cb = CallbackFunction(self.editColumn, column) button = Tkinter.Checkbutton( self.master, variable=v, command=cb, height=32, width=32, indicatoron=0, image=im) self.colHeaderButtons[column] = button self.colHeaderTkVars[column] = v cid = self.canvasHeaderCol.create_window( 20 + self.offx + 175 + column*35, 32, window=button, width=40, height=40, anchor='center') self.balloons.bind(button, self.balloonText[column]) else: cid = self.canvasHeaderCol.create_text( 20 + self.offx + 175 + column*35, 5, text=name, anchor='n')
def makeInterface(self): """ create interface for ssh """ self.resetFrame() colors = { 'center_x' : '#ff3333', 'center_y' : 'green', 'center_z' : '#00aaff', 'size_x' : '#ff3333', 'size_y' : 'green', 'size_z' : '#0099ff', } frame_set = { 'ring_bd' : 1, 'ring_highlightbackground' :'black', 'ring_borderwidth' : 2, 'ring_highlightcolor' : 'black', 'ring_highlightthickness' : 1, 'ring_relief' : 'flat', 'groupchildsite_bg':'white', 'groupchildsite_relief':'sunken','ring_bg':'white', 'tag_bd' : '1', 'tag_highlightbackground' :'black', 'tag_borderwidth':2, 'tag_highlightcolor' : 'black', 'tag_highlightthickness': 1} frame_set = { 'ring_bd' : 1, 'ring_highlightbackground' :'black', 'ring_borderwidth' : 2, 'ring_highlightcolor' : 'black', 'ring_highlightthickness' : 1, 'ring_relief' : 'flat'} frame_set = {} bset = { 'bg' : '#95bed5', 'width' : 22, 'height': 22, 'relief' : 'raised'} bset = { 'bg' : '#2e363b', 'width' : 22, 'height': 22, 'relief' : 'raised'} bset = { 'bg' : '#a6abae', 'width' : 22, 'height': 22, 'relief' : 'raised'} bset = { 'bg' : '#969b9d' } # 'width' : 22, 'height': 22, 'relief' : 'raised'} bset = {} bset.update(self.BORDER) # left frame lframe = tk.Frame(self.frame) # button tollbar tk.Frame(lframe, height=7).pack(expand=0, fill='x', padx=0, pady=0, side='top', anchor='n') # minispacer bframe = tk.Frame(lframe) b = tk.Button(bframe, text='Load...', command = self.openConfig, image= self._ICON_open, compound='left', height=14,**bset) b.pack(expand=1,fill='x', anchor='w', side='left',padx=1) b.pack(expand=1,fill='x', anchor='w', side='left',padx=1) bframe.pack(expand=0, fill='x', padx=0, pady=0, side='top', anchor='n') ########################## center wheels self._thumbw_array = [] c_group = Pmw.Group(lframe, tag_text='Center', tag_font=self.FONTbold, **frame_set) for lab in ['center_x', 'center_y', 'center_z']: cb = CallbackFunction(self.setWheelBox, lab) tw = ThumbWheel( c_group.interior(), labCfg={'text':lab, 'side':'left','fg':colors[lab], 'bg':'black', 'width':9 }, showLabel=1, width=90, height=14, type=float, value=0.0, callback=cb, continuous=True, oneTurn=5, wheelPad=0) tw.pack(side='top', pady=2,anchor='n') self._thumbw_array.append(tw) c_group.pack(side='top', anchor='n', expand=0,fill='x',ipadx=2,ipady=3, padx=1) ########################## size wheels s_group = Pmw.Group(lframe, tag_text='Size', tag_font=self.FONTbold, **frame_set) for lab in ['size_x', 'size_y', 'size_z']: cb = CallbackFunction(self.setWheelBox, lab) tw = ThumbWheel( s_group.interior(), labCfg={'text':lab, 'side':'left','fg':colors[lab], 'bg':'black', 'width':9 }, showLabel=1, width=90, height=14, type=float, value=0.0, min=0.0001, callback=cb, continuous=True, oneTurn=5, wheelPad=0) tw.pack(side='top', pady=2,anchor='n') self._thumbw_array.append(tw) s_group.pack(side='top', anchor='n', expand=0,fill='x',ipadx=2,ipady=3, padx=1,pady=2) ########################## search settings self.searchparmgroup = Pmw.Group(lframe, tag_text='Search parameters', tag_font=self.FONTbold, **frame_set) # autodock search parms self.buildSearchADPanel(target = self.searchparmgroup ) # vina search parms self.buildSearchVinaPanel(target = self.searchparmgroup ) self.searchparmgroup.pack(side='top', anchor='n', expand=0,fill='x',ipadx=2,ipady=3, padx=1,pady=5) ########################## Receptors self._receptors_group = Pmw.Group(lframe, tag_text='Receptor list', tag_font=self.FONTbold,collapsedsize=3, **frame_set) # important self.receptorListbox = Pmw.ScrolledListBox(self._receptors_group.interior(), listbox_highlightbackground = 'black', # selectioncommand=self.loadreceptor, listbox_selectbackground='yellow') self.receptorListbox.pack(expand=1, fill='both',padx=3, pady=0) self.receptorListbox.component('listbox').bind('<ButtonRelease-1>', self.loadreceptor) self.receptorListbox.component('listbox').bind('<Button-3>', self._delreceptor) tb = tk.Frame(self._receptors_group.interior()) # single-multi load buttons self.recLoaderMode_single = tk.Radiobutton(tb, text='Single', image = self._ICON_single, indicatoron=False, variable=self.recLoaderMultiMode, value = False, compound='left', height=16, **bset) self.recLoaderMode_single.pack(anchor='n', side='left',pady=1,expand=1,fill='x',padx=1) self.recLoaderMode_multi = tk.Radiobutton(tb, text='Multi', image = self._ICON_multi, indicatoron=False, variable=self.recLoaderMultiMode, value = True, compound='left', height=16, **bset) self.recLoaderMode_multi.pack(anchor='n', side='left',pady=1,expand=1,fill='x',padx=1) tb.pack(expand=0, fill='x',anchor='s',side='bottom',padx=3) self._receptors_group.pack(side='bottom', anchor='n', expand=1, fill='both',ipadx=4,ipady=4, padx=1,pady=0) lframe.pack(side = 'left', anchor='n', expand='n', fill='y', padx=0, pady=0) ###### 3D Viewer rframe = tk.Frame(self.frame) spacer = tk.Frame(rframe, width=5) #, bg='red') spacer.pack(expand=0,fill='y',side='left',anchor='w') spacer.pack_propagate(0) vgroup = Pmw.Group(rframe, tag_text = '3D viewer', tag_font=self.FONTbold,groupchildsite_bg='black', **frame_set) # TOOLBAR vtoolbar = tk.Frame(vgroup.interior()) vtoolbar.pack(side='left', anchor='w', expand=0, fill='y') cb = CallbackFunction(self.centerView, None) tk.Button(vtoolbar, text='Center\nall', image = self._ICON_center_all, width=22, height=22, command=cb, **bset).pack(anchor='n', side='top') cb = CallbackFunction(self.centerView, 'mol') tk.Button(vtoolbar, text='Center\nmol', image = self._ICON_center_mol, width=22, height=22, command=cb, **bset ).pack(anchor='n', side='top') cb = CallbackFunction(self.centerView, 'box') tk.Button(vtoolbar, text='Center\nbox', image = self._ICON_center_box, width=22, height=22, command=cb, **bset ).pack(anchor='n', side='top',pady=1) # 3d Viewer settings XXX TODO #tk.Button(vtoolbar, text='Settings', image = self._ICON_sys, width=22, height=22, **bset).pack(anchor='n', side='top') vgroup.pack(side='right', anchor='e', expand=1, fill='both', padx=0, pady=0) # 3D viewer self.make3Dboxviewer(vgroup.interior()) rframe.pack(side = 'right', anchor='n', expand=1, fill='both',padx=0, pady=0) if self.app.dockengine == 'vina': self.setSearchParmsVina() elif self.app.dockengine == 'autodock': self.setSearchParmsAD() self.frame.pack(expand=1, fill='both',anchor='n', side='top')
def drawNodeCustomization(self, x, y): """Add things to the rigth side of the tree """ tree = self.tree() canvas = tree.canvas level = 2 col = ['gray75', 'red', 'cyan', 'green', 'yellow'] nbButtons = 10 ## if not hasattr(self, 'chkbt'): ## self.chkbtVar = [] ## self.chkbt = [] ## for i in range(nbButtons): ## v = IntVar() ## self.chkbtVar.append(v) ## cb = CallbackFunction(self.buttonClick, i ) ## button = Checkbutton( ## canvas, variable=v, command=cb, padx=0, pady=0, ## background=col[level-1], anchor='nw') ## self.chkbt.append(button) x = 150 fill = ['white', 'green'] if not hasattr(self, 'chkbt'): nbButtons = tree.nbCol self.chkbt = [0] * nbButtons self.chkbtid = [None] * nbButtons # create a pull down menu and allocate variables for each column self.menu = Menu(canvas, title='Choose', tearoff=False) self.menuVars = [] # list of [column][menu entries] IntVar for i, entries in enumerate(tree.menuEntries): l = [] for j in range(len(entries)): l.append(IntVar()) self.menuVars.append(l) # a list for each column for i, val in enumerate(self.chkbt): xo = x + i * 35 cid = canvas.create_oval(xo, y, xo + 15, y + 15, fill=fill[val]) cb = CallbackFunction(self.buttonClick, i) canvas.tag_bind(cid, "<Button-1>", cb) cb = CallbackFunction(self.shiftButtonClick, i) canvas.tag_bind(cid, "<Shift-Button-1>", cb) self.chkbtid[i] = cid self.canvasIDs.append(cid) ## button = self.chkbt[i] ## cid = canvas.create_window( x+i*35, y, window=button, ## width=20, height=15) ## self.canvasIDs.append(cid) # add secondary structure glyph molFrag = self.object if isinstance(molFrag, Residue): if hasattr(molFrag, 'secondarystructure'): ssname = molFrag.secondarystructure.name if ssname[:6] == 'Strand': color = '#FFF700' elif ssname[:4] == 'Coil': color = 'grey45' elif ssname[:5] == 'Helix': color = '#FF198C' elif ssname[:4] == 'Turn': color = 'blue' cid = canvas.create_rectangle(130, y - 10, 140, y + 10, outline=color, fill=color) self.canvasIDs.append(cid) cid = canvas.create_text(152, y, text=ssname, anchor='nw', font=self.tree.font) self.canvasIDs.append(cid) return x + i * 35
def flash(self, nbfIn=5, nbfOut=25, fullPause=200): self.fadeIn(nbf=nbfIn) cb = CallbackFunction(self.fadeOut, nbf=nbfOut) self.viewer.master.after(fullPause, self.fadeOut)
def __init__(self, viewer, viewerName, geomChooserClass, geomChooserClassOpt, master=None): """ viewer is a DejaVu Viewer instance viewerName is a string which when evaluated yields viewer geomChooserClass is class defining the geomChooser object to create geomChooserClassOpt is a sequence or *args and **kw used to create the geomChooser. (viewer,) is automatically inserted at the begining of args and 'root', and 'command' are automatically set in kw. other possible kw include 'filterFunction', 'refreshButton', 'showAllButton' """ AnimationPanel.__init__(self, viewer, viewerName, master) args, kw = geomChooserClassOpt kw['root'] = self.geomChooserG.interior() kw['command'] = self.onSelect_cb args = (viewer, ) + args gc = self.geomChooser = geomChooserClass(*args, **kw) gc.pack(side='top', fill='both', expand=1, anchor="w") self.selectedGeom = None # add action creating buttons lastRow = 0 parent = self.makeActionsG.interior() # fly in button cb = CallbackFunction(self.makeMAA, FlyInObjectMAA, (), {}) w = self.flyinB = Tkinter.Button(parent, text='Fly In', command=cb) w.grid(column=0, row=lastRow, sticky='ew') w.bind('<Button-3>', CallbackFunction(self.showMaaEditor_cb, FlyInObjectMAA, (), {})) # fly out button cb = CallbackFunction(self.makeMAA, FlyOutObjectMAA, (), {}) w = self.flyoutB = Tkinter.Button(parent, text='Fly Out', command=cb) w.grid(column=1, row=lastRow, sticky='ew') w.bind( '<Button-3>', CallbackFunction(self.showMaaEditor_cb, FlyOutObjectMAA, (), {})) lastRow += 1 # fade in button cb = CallbackFunction(self.makeMAA, FadeInObjectMAA, (), {}) w = self.fadeinB = Tkinter.Button(parent, text='Fade In', command=cb) w.bind( '<Button-3>', CallbackFunction(self.showMaaEditor_cb, FadeInObjectMAA, (), {})) w.grid(column=0, row=lastRow, sticky='ew') # fade out button cb = CallbackFunction(self.makeMAA, FadeOutObjectMAA, (), {}) w = self.fadeoutB = Tkinter.Button(parent, text='Fade Out', command=cb) w.bind( '<Button-3>', CallbackFunction(self.showMaaEditor_cb, FadeOutObjectMAA, (), {})) w.grid(column=1, row=lastRow, sticky='ew') lastRow += 1 # show button cb = CallbackFunction(self.makeMAA, VisibleObjectMAA, (), {'visible': 1}) w = self.showB = Tkinter.Button(parent, text='Show', command=cb) w.grid(column=0, row=lastRow, sticky='ew') # hide button cb = CallbackFunction(self.makeMAA, VisibleObjectMAA, (), {'visible': 0}) w = self.hideB = Tkinter.Button(parent, text='Hide', command=cb) w.grid(column=1, row=lastRow, sticky='ew') lastRow += 1 # rotation button cb = CallbackFunction(self.makeMAA, RotationMAA, (), {}) w = self.rotationB = Tkinter.Button(parent, text='Rotate', command=cb) w.grid(column=0, row=lastRow, sticky='ew') w.bind('<Button-3>', CallbackFunction(self.showMaaEditor_cb, RotationMAA, (), {})) # rock button cb = CallbackFunction(self.makeMAA, RockMAA, (), {}) w = self.rockB = Tkinter.Button(parent, text='Rock', command=cb) w.grid(column=1, row=lastRow, sticky='ew') w.bind('<Button-3>', CallbackFunction(self.showMaaEditor_cb, RockMAA, (), {})) lastRow += 1 self.lastRow = lastRow
def buildGUI(self): tree = self.tree if tree.pmvcmd[self.column]: b = Tkinter.Button(self.root, command=self.getOpt, height=32, width=32, image=tree.iconList[self.column]) b.grid(row=0, column=0, sticky='e') tree.optionButton = Tkinter.Button( self.root, text='Set default Options for command', command=self.getOpt) tree.optionButton.grid(row=0, column=1, sticky='w') tree.balloons.bind(tree.optionButton, self.optionHelp) self.bbmodevar = Tkinter.StringVar() self.bbmodevar.set("All") bbmode_menu = Pmw.OptionMenu( self.root, labelpos='w', label_text='Protein:', menubutton_textvariable=self.bbmodevar, items=['Backbone', 'Sidechain', 'Sidechains+CA', 'All'], menubutton_width=8, command=self.bbmode_cb, ) bbmode_menu.grid(row=0, column=2, sticky='ew', padx=10, pady=10) tree.balloons.bind(bbmode_menu, tree.proteinHelp) self.chainedPanelVar = Tkinter.IntVar() w = Pmw.Group(self.root, tag_pyclass = Tkinter.Checkbutton, tag_text='show command chaining interface', tag_variable=self.chainedPanelVar, tag_foreground='blue') self.chainedPanelVar.set(0) w.toggle() self.chainedPanelGroup = w def toggle(event=None): self.chainedPanelGroup.toggle() if self.chainedPanelVar.get(): self.chainedPanelGroup.configure( tag_text='hide command chaining interface', tag_foreground='blue') else: self.chainedPanelGroup.configure( tag_text='show command chaining interface', tag_foreground='blue') w.configure(tag_command = toggle) # tag_text='Check commands to run after %s:'%\ # tree.names[self.column]) w.grid(row=1, column=0, columnspan=3, sticky='ew', padx=5, pady=5) tree.balloons.bind(w, self.chainHelp) groupMaster = w.interior() # add argument option menu ## self.argVar = Tkinter.StringVar() ## self.argOptMenu = Pmw.OptionMenu( ## groupMaster, labelpos = 'w', ## label_text = 'Argument to be used passed to chained command:', ## menubutton_textvariable = self.argVar, ## items = ['N/A', 'True', 'False', 'Same', 'Opposite'], ## menubutton_width = 10, ## ) ## self.argOptMenu.grid(row=0, column=0, columnspan=4) column1 = Tkinter.Frame(groupMaster) column2 = Tkinter.Frame(groupMaster) self.chainVars = [] self.chainWhenVars = [] self.chainArgVars = [] self.chainProtVars = [] chainList = tree.chainWith[self.column] col = -1 halfLength = int(round(tree.nbColumns*0.5)) for i in range(tree.nbColumns): row=(i% halfLength)+1 if row==1: col += 4 master = Tkinter.Frame(groupMaster, relief='ridge') l = Tkinter.Label(master, text='Cmd:') l.grid(row=0, column=col-3) l = Tkinter.Label( master, text='Call when cmd\nbutton is:') l.grid(row=0, column=col-2) l = Tkinter.Label(master, text='Set chained\ncmd button to:') l.grid(row=0, column=col-1) l = Tkinter.Label(master, text='Apply to:') l.grid(row=0, column=col) master.pack(side='left', padx=10, anchor='n') v = Tkinter.IntVar() self.chainVars.append(v) whenVar = Tkinter.StringVar() whenVar.set('Checked') self.chainWhenVars.append(whenVar) argVar = Tkinter.StringVar() argVar.set('Same') self.chainArgVars.append(argVar) protVar = Tkinter.StringVar() protVar.set('All') self.chainProtVars.append(protVar) status = 'normal' if i==self.column: status = 'disabled' v.set(0) elif chainList[i]: run, arg, prot = chainList[i] v.set(1) whenVar.set(run) argVar.set(arg) protVar.set(prot) else: v.set(0) cb = CallbackFunction(self.setChain, i) if tree.iconList[i]: b = Tkinter.Checkbutton(master, variable=v, state=status, command=cb, height=32, width=32, indicatoron=0, image=tree.iconList[i]) else: l = Tkinter.Label(master, state=status, text=tree.names[i].replace('\n', ' ')) l.grid(column=4*col-3, row=row, sticky='e') b = Tkinter.Checkbutton(master, variable=v, state=status, command=cb) b.grid(column=col-3, row=row, sticky='w') tree.balloons.bind(b, tree.balloonText[i]) argMenuCall = Pmw.OptionMenu( master, labelpos = 'w', menubutton_textvariable = whenVar, items = ['Checked', 'Unchecked', 'Always'], menubutton_width = 7, command=cb ) argMenuCall.grid(column=col-2, row=row, sticky='w') tree.balloons.bind(argMenuCall, self.callWhenHelp) argMenuVar = Pmw.OptionMenu( master, labelpos = 'w', menubutton_textvariable = argVar, items = ['True', 'False', 'Same', 'Opposite'], menubutton_width = 6, command=cb ) argMenuVar.grid(column=col-1, row=row, sticky='w') tree.balloons.bind(argMenuVar, self.argHelp) argMenuVar = Pmw.OptionMenu( master, labelpos = 'w', menubutton_textvariable = protVar, items = ['All', 'Backbone', 'Sidechain+CA', 'Sidechain'], menubutton_width = 10, command=cb ) argMenuVar.grid(column=col, row=row, sticky='w') tree.balloons.bind(argMenuVar, tree.proteinHelp) if self.editable: pass #cmdList = ['select', 'displayLines', 'displaySticksAndBalls', # 'displayCPK', 'displayExtrudedSS', 'displayMSMS', # 'LabelAtoms', 'LabelResidues', '', ] self.OK = Tkinter.Button(self.root, text='OK', command=tree.colHeaderButtons[self.column].invoke) self.OK.grid(row=2, column=0, columnspan=3, sticky='ew')
def setGuseResource(self): self._buildjobscrollbar() self.resetFrame() self.group = Pmw.Group(self.frame, tag_text='gUSE submission requirements', tag_font=self.FONTbold) f = self.group.interior() #f.configure(bg='red') lwidth = 20 rwidth = 60 lbg = '#ffffff' rbg = '#ff8888' fg = 'black' # ligands tk.Label(f, text='Ligands', width=lwidth, font=self.FONT, anchor='e').grid(row=3, column=1, sticky='e', padx=5, pady=1) self.reqLig = tk.Label(f, text='[ click to select ]', fg=fg, bg=rbg, width=rwidth, font=self.FONT, **self.BORDER) self.reqLig.grid(row=3, column=2, sticky='w', pady=1) cb = CallbackFunction(self.switchtab, 'Ligands') self.reqLig.bind('<Button-1>', cb) # receptor tk.Label(f, text='Receptors', width=lwidth, font=self.FONT, anchor='e').grid(row=5, column=1, sticky='e', padx=5, pady=0) self.reqRec = tk.Label(f, text='[ click to select ]', fg=fg, bg=rbg, width=rwidth, font=self.FONT, **self.BORDER) self.reqRec.grid(row=5, column=2, sticky='w') cb = CallbackFunction(self.switchtab, 'Receptors') self.reqRec.bind('<Button-1>', cb) # config tk.Label(f, text='Config', width=lwidth, font=self.FONT, anchor='e').grid(row=7, column=1, sticky='e', padx=5, pady=1) self.reqConf = tk.Label(f, text='[ click to select ]', fg=fg, bg=rbg, width=rwidth, font=self.FONT, **self.BORDER) self.reqConf.grid(row=7, column=2, sticky='w', pady=1) cb = CallbackFunction(self.switchtab, 'Config') self.reqConf.bind('<Button-1>', cb) # submission self.SubmitButton = tk.Button(f, text='Submit...', image=self._ICON_submit, font=self.FONT, compound='left', state='normal', command=self.submit, **self.BORDER) self.SubmitButton.grid(row=20, column=1, sticky='we', columnspan=3, padx=4, pady=3) self.group.pack(fill='none', side='top', anchor='w', ipadx=5, ipady=5) self.frame.pack(expand=0, fill='x', anchor='n') self._updateRequirementsGuse()
def setClusterResource(self): self._buildjobman(self.parent) self.resetFrame() #self.frame.configure(bg='red') self.group = Pmw.Group(self.frame, tag_text='Cluster submission requirements', tag_font=self.FONTbold) f = self.group.interior() #f.configure(bg='red') lwidth = 20 rwidth = 60 lbg = '#ffffff' rbg = '#ff8888' fg = 'black' # server connection tk.Label(f, text='Server', width=lwidth, font=self.FONT, anchor='e').grid(row=1, column=1, sticky='e', padx=5, pady=0) self.reqConn = tk.Label(f, text='[ click to connect ]', fg=fg, bg=rbg, width=rwidth, font=self.FONT, **self.BORDER) self.reqConn.grid(row=1, column=2, sticky='e') cb = CallbackFunction(self.switchtab, 'Setup') self.reqConn.bind('<Button-1>', cb) # XXX self.GUI_LigStatus.bind('<Button-1>', lambda x : self.notebook.selectpage('Ligands')) # docking service # ligands tk.Label(f, text='Docking service', width=lwidth, font=self.FONT, anchor='e').grid(row=2, column=1, sticky='e', padx=5, pady=1) self.reqService = tk.Label(f, text='[ click to select ]', fg=fg, bg=rbg, width=rwidth, font=self.FONT, **self.BORDER) self.reqService.grid(row=2, column=2, sticky='w', pady=1) cb = CallbackFunction(self.switchtab, 'Setup') self.reqService.bind('<Button-1>', cb) # ligands tk.Label(f, text='Ligands', width=lwidth, font=self.FONT, anchor='e').grid(row=3, column=1, sticky='e', padx=5, pady=1) self.reqLig = tk.Label(f, text='[ click to select ]', fg=fg, bg=rbg, width=rwidth, font=self.FONT, **self.BORDER) self.reqLig.grid(row=3, column=2, sticky='w', pady=1) cb = CallbackFunction(self.switchtab, 'Ligands') self.reqLig.bind('<Button-1>', cb) # receptor tk.Label(f, text='Receptors', width=lwidth, font=self.FONT, anchor='e').grid(row=5, column=1, sticky='e', padx=5, pady=0) self.reqRec = tk.Label(f, text='[ click to select ]', fg=fg, bg=rbg, width=rwidth, font=self.FONT, **self.BORDER) self.reqRec.grid(row=5, column=2, sticky='w') cb = CallbackFunction(self.switchtab, 'Receptors') self.reqRec.bind('<Button-1>', cb) # config tk.Label(f, text='Config', width=lwidth, font=self.FONT, anchor='e').grid(row=7, column=1, sticky='e', padx=5, pady=1) self.reqConf = tk.Label(f, text='[ click to select ]', fg=fg, bg=rbg, width=rwidth, font=self.FONT, **self.BORDER) self.reqConf.grid(row=7, column=2, sticky='w', pady=1) cb = CallbackFunction(self.switchtab, 'Config') self.reqConf.bind('<Button-1>', cb) # scheduler #tk.Label(f, text='Scheduler', width=lwidth, font=self.FONT,anchor='e').grid(row=9, column=1,sticky='e',padx=5, pady=0) #self.reqSched = tk.Label(f, text = '[ click to select ]', fg = fg, bg=rbg, width=rwidth, font=self.FONT, **self.BORDER) #self.reqSched.grid(row=9,column=2, sticky='w') #cb = CallbackFunction(self.switchtab, 'Setup') #self.reqSched.bind('<Button-1>', cb) # submission self.SubmitButton = tk.Button(f, text='Submit...', image=self._ICON_submit, font=self.FONT, compound='left', state='disabled', command=self.submit, **self.BORDER) self.SubmitButton.grid(row=20, column=1, sticky='we', columnspan=3, padx=4, pady=3) self.group.pack(fill='none', side='top', anchor='w', ipadx=5, ipady=5) self.frame.pack(expand=0, fill='x', anchor='n') self._updateRequirementsSsh()
def onAddCmdToViewer(self): if not self.vf.hasGui: return self.vf.browseCommands('displayCommands', package='Pmv', log=0) self.vf.browseCommands('secondaryStructureCommands', package='Pmv', log=0) self.hasMSMS = True try: import mslib self.vf.browseCommands('msmsCommands', package='Pmv', log=0) except: self.hasMSMS = False self.vf.browseCommands('colorCommands', package='Pmv', log=0) self.vf.browseCommands('labelCommands', package='Pmv', log=0) self.vf.browseCommands('selectionCommands', package='Pmv', log=0) # register intrest in other commands self.vf.cmdsWithOnRun[self.vf.showMolecules] = [self] self.vf.cmdsWithOnRun[self.vf.select] = [self] self.vf.cmdsWithOnRun[self.vf.clearSelection] = [self] self.vf.cmdsWithOnRun[self.vf.displayLines] = [self] self.vf.cmdsWithOnRun[self.vf.displaySticksAndBalls] = [self] self.vf.cmdsWithOnRun[self.vf.displayCPK] = [self] self.vf.cmdsWithOnRun[self.vf.displayExtrudedSS] = [self] if self.hasMSMS: self.vf.cmdsWithOnRun[self.vf.displayMSMS] = [self] self.vf.cmdsWithOnRun[self.vf.labelByProperty] = [self] self.vf.cmdsWithOnRun[self.vf.colorByAtomType] = [self] self.vf.cmdsWithOnRun[self.vf.colorByChains] = [self] self.vf.cmdsWithOnRun[self.vf.colorByMolecules] = [self] self.vf.cmdsWithOnRun[self.vf.colorBySecondaryStructure] = [self] self.vf.cmdsWithOnRun[self.vf.colorAtomsUsingDG] = [self] self.vf.cmdsWithOnRun[self.vf.colorByResidueType] = [self] from Pmv.moleculeViewer import DeleteAtomsEvent, AddAtomsEvent self.vf.registerListener(DeleteAtomsEvent, self.handleDeleteEvents) self.vf.registerListener(AddAtomsEvent, self.handleAddEvents) # build the tree master = Tkinter.Toplevel() master.withdraw() master.protocol('WM_DELETE_WINDOW',self.hide) self.tree = tvolist = TreeViewWithCheckbuttons( name='Control Panel', displayValue=True, # needed to show buttons multi_choice=True, master = master, offy=0, offx=0) self.tree.sets = self.vf.sets self.msmsDefaultValues = {} #cache used to decide if we re-compute # custom call back function for display MSMS column def displayMS_cb(node, column): val = node.chkbtVar[column].get() defaultValues = node.tree.pmvcmd[column].getLastUsedValues() oldDefaultValues = self.msmsDefaultValues recompute = False if len(oldDefaultValues)==0: recompute=True else: for k,v in oldDefaultValues.items(): nv = defaultValues.get(k, None) if nv!=v: recompute=True break molat = {} for obj in node.getObjects(column): molecules, atmSets = self.vf.getNodesByMolecule(obj, Atom) for mol, atoms in zip(molecules, atmSets): if molat.has_key(mol): molat[mol] += atoms else: molat[mol] = atoms for mol, atoms in molat.items(): if not mol.geomContainer.geoms.has_key('MSMS-MOL'): recompute=True if len(defaultValues): if defaultValues['perMol']==0 and val: recompute=True if type(defaultValues['surfName'])==types.TupleType: defaultValues['surfName']=defaultValues['surfName'][0] if recompute: apply( self.vf.computeMSMS, (atoms,), defaultValues) else: pmvcmd = self.vf.displayMSMS defaultValues['callListener'] = False pmvcmd(atoms, negate= not val, callListener=False) if pmvcmd.lastUsedValues['default'].has_key('callListener'): del pmvcmd.lastUsedValues['default']['callListener'] if recompute: self.msmsDefaultValues.update(defaultValues) def label_cb(node, column, level=Atom, property=['name']): val = node.chkbtVar[column].get() for obj in node.getObjects(column): nodes = obj.findType(level) pmvcmd = self.vf.labelByProperty pmvcmd(nodes, negate=not val, callListener=False, properties=property) if pmvcmd.lastUsedValues['default'].has_key('callListener'): del pmvcmd.lastUsedValues['default']['callListener'] # self.labelByProperty("1crn::;", textcolor=(1.0, 1.0, 1.0,), log=0, format=None, only=0, location='Center', negate=0, font='Helvetica12', properties=['name']) # custom callback for color commands which runs command only if # button is checked def color_cb(node, column): val = node.chkbtVar[column].get() cmd = node.tree.pmvcmd[column] if val: for obj in node.getObjects(column): apply( cmd, (obj,), {'callListener':False}) if cmd.lastUsedValues['default'].has_key('callListener'): del pmvcmd.lastUsedValues['default']['callListener'] else: if node.selected: for node in self.tree.list_selected: node.chkbtVar[column].set(0) def showHideVal(node): if node.name == 'All': return mols = [node.objectKey.top] vis = 0 for m in mols: n = self.tree.objToNode[m] v = m.geomContainer.geoms['master'].visible if v: vis = 1 n.chkbtVar[0].set(v) #print node.name, vis hum not sure why the following line does not work self.tree.roots[0].chkbtVar[0].set(vis) col = 0 tvolist.setCallback(col, self.vf.showMolecules, 'eye.png', 'show/Hide molecule', bValFunc=showHideVal) col += 1 tvolist.setCallback(col, self.vf.select,'select.png', 'select molecular fragment') col += 1 tvolist.setCallback(col, self.vf.displayLines, 'lines.png', 'Display/Undisplay Lines representation', 'Display Lines') col += 1 tvolist.setCallback(col, self.vf.displaySticksAndBalls, 'sb.png', 'Display/Undisplay atoms as small spheres and bonds as cylinders', 'Display Sticks and Balls') col += 1 tvolist.setCallback(col, self.vf.displayCPK, 'cpk.png', 'Display/Undisplay atoms as spheres', 'Display CPK') col += 1 tvolist.setCallback(col, self.vf.displayExtrudedSS, 'ss.png', 'Display/Undisplay secondary structure', 'Display Ribbon', ) if self.hasMSMS: col += 1 tvolist.setCallback(col, self.vf.computeMSMS, 'ms.png', 'Compute and display molecular surface', 'Display molecular surface', displayMS_cb) col += 1 cb = CallbackFunction( label_cb, level=Atom) tvolist.setCallback(col, None, 'labelAtom.png', 'Label atoms', 'Label Atoms', cb) col += 1 cb = CallbackFunction( label_cb, level=Residue) tvolist.setCallback(col, None, 'labelRes.png', 'label Residues', 'Label Residues', cb) col += 1 tvolist.setCallback(col, self.vf.colorByAtomType, 'colorAtom.png', 'Color all representations by atoms type', 'Color by Atom Type', color_cb) col += 1 tvolist.setCallback(col, self.vf.colorByChains, 'colorChain.png', 'Color all representations by chain', 'Color by Chain', color_cb) col += 1 tvolist.setCallback(col, self.vf.colorByMolecules, 'colorMol.png', 'Color all representations by molecule', 'Color by Molecule', color_cb) col += 1 tvolist.setCallback(col, self.vf.colorBySecondaryStructure, 'colorSS.png', 'Color all representations by secondary structure element type', 'Color by Secondary Structure', color_cb) col += 1 tvolist.setCallback(col, self.vf.colorAtomsUsingDG, 'colorDG.png', 'Color using the David Goodsell scheme\nin which atoms are either neutral,\nor slightly or strongly charged', 'Color by D. Goodsell', color_cb) col += 1 tvolist.setCallback(col, self.vf.colorByResidueType, 'colorRes.png', 'Color all representations by residue\nusing the RASMOL coloring scheme', 'color Residues by Rasmol', color_cb) #col += 1 #tvolist.setCallback(col, self.vf.colorResiduesUsingShapely, .... # 'color\nby\nShapely') # add current molecules n = NodeWithCheckbuttons hasChildren = len(self.vf.Mols)>0 node = tvolist.addNode('All', parent=None, object=self.vf.Mols, nodeClass=n, hasChildren=hasChildren) node.createTkVar(self.tree.nbColumns)
def createCanvas(self, master): height = self.height width = self.width cd = { 'width': width, 'height': height, 'relief': 'sunken', 'borderwidth': 0, 'bg': 'white' } #'bg':'grey70'} cd.update(self.canvasCfg) canvas = self.canvas = Tkinter.Canvas(self, **cd) self.canvas.configure(cursor='sb_h_double_arrow') self.bw = bw = cd['borderwidth'] # create the background polygon between the cursors # bb of poly is (0, 0, 200, 16) lp1 = canvas.create_rectangle( 1 + bw, 1 + bw, width + bw - 1, height + bw, fill='SteelBlue1', outline='black', #fill='#0081FF', outline='black', tags=('poly', )) # create left cursor (light upper left line) ## bb for 'leftl is (0,0,20,16) lc1 = canvas.create_line(2 + bw, height + bw - 1, 2 + bw, 2 + bw, 18 + bw, 2 + bw, fill='white', width=1, tags=('left', )) # create a polygon filling the cursor lp1 = canvas.create_rectangle(bw + 3, bw + 3, 17 + bw, height + bw - 2, fill='grey75', outline='grey75', tags=('left', ), width=1) # create left cursor (dark lower rigth line) lc2 = canvas.create_line(18 + bw, 2 + bw, 18 + bw, height + bw - 1, 2 + bw, height + bw - 1, width=1, fill='black', tags=('left', )) # create a letter in the cursor ll1 = canvas.create_text(bw + 11, 1 + bw + self.height / 2, text=unicode(u"\u25B6"), font=self.FONTsmall, tags=('left', )) self.leftOrigBB = canvas.bbox('left') # create right cursor (light upper left line) rc1 = canvas.create_line(2 + bw, height + bw - 1, 2 + bw, 2 + bw, 18 + bw, 2 + bw, fill='white', tags=('right', )) # create a polygon filling the cursor rp1 = canvas.create_rectangle(bw + 3, bw + 3, 17 + bw, height + bw - 2, fill='grey75', outline='grey75', tags=('right', )) # create right cursor (dark lower rigth line) rc2 = canvas.create_line(18 + bw, 2 + bw, 18 + bw, height + bw - 1, 2 + bw, height + bw - 1, fill='black', tags=('right', )) # create a letter in the cursor rl1 = canvas.create_text(bw + 11, bw + self.height / 2, text=unicode(u"\u25C0"), font=self.FONTsmall, tags=('right', )) self.canvas.move('right', width - 20, 0) self.rightOrigBB = canvas.bbox('right') self.updateBackPoly() canvas.tag_bind('left', "<ButtonPress-1>", CallbackFunction(self.mouseDown, 'left')) #canvas.tag_bind('left', "<ButtonRelease-1>", # CallbackFunction( self.mouseUp, 'left')) canvas.tag_bind('left', "<B1-Motion>", CallbackFunction(self.mouseMove, 'left')) canvas.tag_bind('right', "<ButtonPress-1>", CallbackFunction(self.mouseDown, 'right')) #canvas.tag_bind('right', "<ButtonRelease-1>", # CallbackFunction( self.mouseUp, 'right')) canvas.tag_bind('right', "<B1-Motion>", CallbackFunction(self.mouseMove, 'right')) canvas.tag_bind('poly', "<ButtonPress-1>", CallbackFunction(self.mouseDown, 'poly')) canvas.tag_bind('poly', "<B1-Motion>", CallbackFunction(self.mouseMove, 'poly')) #canvas.tag_bind('poly', "<ButtonRelease-1>", # CallbackFunction( self.mouseUp, 'poly')) self.canvas.pack(side=Tkinter.LEFT)