Package Pmv :: Module picker
[hide private]
[frames] | no frames]

Source Code for Module Pmv.picker

  1  ############################################################################# 
  2  # 
  3  # Author: Michel F. SANNER 
  4  # 
  5  # Copyright: M. Sanner TSRI 2000 
  6  # 
  7  ############################################################################# 
  8   
  9  # $Header: /opt/cvs/python/packages/share1.5/Pmv/picker.py,v 1.4 2004/12/17 19:21:23 sanner Exp $ 
 10  # 
 11  # $Id: picker.py,v 1.4 2004/12/17 19:21:23 sanner Exp $ 
 12  # 
 13   
 14  ##  from ViewerFramework.gui import InputFormDescr 
 15  from mglutil.gui.InputForm.Tk.gui import InputFormDescr 
 16  from ViewerFramework.picker import Picker 
 17  import Tkinter, Pmw 
 18  from MolKit.molecule import AtomSet, BondSet 
 19   
20 -class AtomPicker(Picker):
21 """ 22 This objects can be used to prompt the user for selecting a set of atoms 23 or starting a picker that will call a callback function after a user- 24 defined number of atoms have been selected 25 """ 26
27 - def removeAlreadySelected(self, objects):
28 """remove for objects the ones already in self.objects""" 29 return objects - self.objects
30 31
32 - def getObjects(self, pick):
33 """to be implemented by sub-class""" 34 atoms = self.vf.findPickedAtoms(pick) 35 return atoms
36
37 - def clear(self):
38 """clear AtomSet of selected objects""" 39 self.objects = AtomSet([])
40 41
42 - def updateGUI(self, atom):
43 name = atom.full_name() 44 self.ifd.entryByName['Atom']['widget'].setentry(name)
45 46
47 - def buildInputFormDescr(self):
48 """to be implemented by sub-class""" 49 50 ifd=InputFormDescr() 51 ifd.title = "atom picker" 52 ifd.append({'widgetType':Tkinter.Label, 53 'name':'event', 54 'wcfg':{'text':'last atom: '}, 55 'gridcfg':{'sticky':Tkinter.W} }) 56 ifd.append({'widgetType':Pmw.EntryField, 57 'name':'Atom', 58 'wcfg':{'labelpos':'w', 59 'label_text':'Atom: ', 'validate':None}, 60 'gridcfg':{'sticky':'we'}}) 61 if self.numberOfObjects==None: 62 ifd.append({'widgetType':Tkinter.Button, 63 'wcfg':{'text':'Done'}, 64 'command': self.stop}) 65 66 return ifd
67 68
69 -class BondPicker(Picker):
70 71
72 - def go(self, modal=0, level='parts'):
73 Picker.go( self, modal, level)
74 75
76 - def removeAlreadySelected(self, objects):
77 """remove for objects the ones already in self.objects""" 78 return objects - self.objects
79 80
81 - def clear(self):
82 """clear BondSet of selected objects""" 83 self.objects = BondSet([])
84 85
86 - def getObjects(self, pick):
87 """to be implemented by sub-class""" 88 bonds = self.vf.findPickedBonds(pick) 89 return bonds
90 91
92 - def updateGUI(self, bond):
93 name = bond.atom1.full_name() 94 self.ifd.entryByName['Atom1']['widget'].setentry(name) 95 name = bond.atom2.full_name() 96 self.ifd.entryByName['Atom2']['widget'].setentry(name) 97 name = str(bond.bondOrder) 98 self.ifd.entryByName['BondOrder']['widget'].setentry(name)
99 100
101 - def buildInputFormDescr(self):
102 """to be implemented by sub-class""" 103 104 ifd=InputFormDescr() 105 ifd.title = "bond picker" 106 ifd.append({'widgetType':Tkinter.Label, 107 'name':'event', 108 'wcfg':{'text':'event: '+self.event}, 109 'gridcfg':{'sticky':Tkinter.W} }) 110 111 ifd.append({'widgetType':Pmw.EntryField, 112 'name':'Atom1', 113 'wcfg':{'labelpos':'w', 114 'label_text':'Atom 1: ', 115 'validate':None}, 116 'gridcfg':{'sticky':'we'}}) 117 ifd.append({'widgetType':Pmw.EntryField, 118 'name':'Atom2', 119 'wcfg':{'labelpos':'w', 120 'label_text':'Atom 2: ', 121 'validate':None}, 122 'gridcfg':{'sticky':'we'}}) 123 ifd.append({'widgetType':Pmw.EntryField, 124 'name':'BondOrder', 125 'wcfg':{'labelpos':'w', 126 'label_text':'BondOrder: ', 127 'validate':None}, 128 'gridcfg':{'sticky':'we'}}) 129 130 if self.numberOfObjects==None: 131 ifd.append({'widgetType':Tkinter.Button, 132 'wcfg':{'text':'Done'}, 133 'command': self.stop}) 134 135 return ifd
136 137 138 from DejaVu.IndexedPolygons import IndexedPolygons 139
140 -class MsmsPicker(Picker):
141
142 - def getObjects(self, pick):
143 """to be implemented by sub-class""" 144 result = [] 145 for o in pick.hits.keys(): 146 if isinstance(o, IndexedPolygons): 147 if hasattr(o, 'mol'): 148 if hasattr(o,'userName'): 149 result.append(o) 150 return result
151 152
153 - def updateGUI(self, geom):
154 name = geom.userName 155 self.ifd.entryByName['Surface']['widget'].setentry(name)
156 157
158 - def buildInputFormDescr(self):
159 """to be implemented by sub-class""" 160 161 ifd=InputFormDescr() 162 ifd.title = "MSMSsel picker" 163 ifd.append({'widgetType':Tkinter.Label, 164 'name':'event', 165 'wcfg':{'text':'event: '+self.event}, 166 'gridcfg':{'sticky':Tkinter.W} }) 167 ifd.append({'widgetType':Pmw.EntryField, 168 'name':'Surface', 169 'wcfg':{'labelpos':'w', 170 'label_text':'Surface name: ', 171 'validate':None}, 172 'gridcfg':{'sticky':'we'}}) 173 if self.numberOfObjects==None: 174 ifd.append({'widgetType':Tkinter.Button, 175 'wcfg':{'text':'Done'}, 176 'command': self.stop}) 177 return ifd
178 179
180 -class NewMsmsPicker(MsmsPicker):
181
182 - def getObjects(self, pick):
183 """to be implemented by sub-class""" 184 for o in pick.hits.keys(): 185 if o: 186 if isinstance(o, IndexedPolygons): 187 if hasattr(o, 'mol'): 188 if hasattr(o,'userName'): 189 return o 190 if hasattr(o, 'name'): 191 if o.name=='msms': 192 result.append(o) 193 return result 194 else: 195 if self.ifd.entryByName.has_key('AllObjects'): 196 widget = self.ifd.entryByName['AllObjects']['widget'] 197 if len(widget.lb.curselection()): 198 return widget.entries(int(widget.lb.curselection()[0])) 199 return None
200 201
202 - def allChoices(self):
203 choices = [] 204 for mol in self.vf.Mols: 205 geoms = mol.geomContainer.geoms 206 for geomname in geoms.keys(): 207 if hasattr(geoms[geomname], 'userName') or \ 208 (geomname=='msms' and geoms[geomname].vertexSet): 209 choices.append(mol.geomContainer.geoms[geomname]) 210 return choices
211 212
213 - def updateGUI(self, geom):
214 if geom.name=='msms': 215 name = 'msms' 216 else: 217 name = geom.userName 218 self.ifd.entryByName['Surface']['widget'].setentry(name)
219 220
221 - def buildInputFormDescr(self):
222 """to be implemented by sub-class""" 223 224 ifd=InputFormDescr() 225 ifd.title = "MSMSsel picker" 226 ifd.append({'widgetType':Tkinter.Label, 227 'name':'event', 228 'wcfg':{'text':'event: '+self.event}, 229 'gridcfg':{'sticky':Tkinter.W} }) 230 ifd.append({'widgetType':Pmw.EntryField, 231 'name':'Surface', 232 'wcfg':{'labelpos':'w', 233 'label_text':'Surface name: ', 234 'validate':None}, 235 'gridcfg':{'sticky':'we'}}) 236 ifd.append({'widgetType':Tkinter.Button, 237 'name':'Cancel', 238 'wcfg':{'text':'Cancel', 239 'command':self.Cancel 240 } 241 }) 242 243 if self.numberOfObjects==None: 244 ifd.append({'widgetType':Tkinter.Button, 245 'wcfg':{'text':'Done'}, 246 'command': self.stop}) 247 return ifd
248
249 - def Cancel(self, event=None):
250 self.form.destroy()
251