def saveui_delete(self, name): from chimera import preferences removeXSection(name) preferences.save() redisplayMenu() self.dialog.status("Setting \"%s\" deleted" % name) return True
def saveui_delete(self, name): from chimera import preferences removeXSection(name) preferences.save() redisplayMenu() self.dialog.status("Setting \"%s\" deleted" % name) return True
def saveui_save(self, name): from chimera import preferences addRRC(name, self.guide, self.plane, self.planeNormal, self.isNucleic, self.mainchain) preferences.save() self.dialog.status("Setting \"%s\" saved" % name) return True
def saveui_save(self, name): from chimera import preferences addRRC(name, self.guide, self.plane, self.planeNormal, self.isNucleic, self.mainchain) preferences.save() self.dialog.status("Setting \"%s\" saved" % name) return True
def set_preferences(binary, dat): assert_preferences() if os.path.isfile(binary) and os.path.isdir(dat): preferences.set('tangram_nciplot', 'nciplot_bin', binary) preferences.set('tangram_nciplot', 'nciplot_dat', dat) preferences.save() else: raise ValueError('One or more of the specified paths do not exist.')
def _removeDblCmdCB(self): """callback from 'dbl-click commands' listbox""" cmdList = list(self.dblCommandsList.get(None)) del cmdList[int(self.dblCommandsList.curselection()[0])] self.dblCommandsList.setlist(cmdList) self.prefs['executionList'] = cmdList preferences.save()
def _removeDblCmdCB(self): """callback from 'dbl-click commands' listbox""" cmdList = list(self.dblCommandsList.get(None)) del cmdList[int(self.dblCommandsList.curselection()[0])] self.dblCommandsList.setlist(cmdList) self.prefs['executionList'] = cmdList preferences.save()
def _addDblCmdCB(self): """callback from 'command menu' listbox""" cmdList = list(self.dblCommandsList.get(None)) cmdList.append(self.dblCommandMenu.getcurselection()[0]) self.dblCommandsList.setlist(cmdList) self.dblCommandMenu.selection_clear() self.prefs['executionList'] = cmdList preferences.save()
def _addDblCmdCB(self): """callback from 'command menu' listbox""" cmdList = list(self.dblCommandsList.get(None)) cmdList.append(self.dblCommandMenu.getcurselection()[0]) self.dblCommandsList.setlist(cmdList) self.dblCommandMenu.selection_clear() self.prefs['executionList'] = cmdList preferences.save()
def _butChangeCB(self, butName): butInfo = self.buttonInfo[butName] if butInfo['variable'].get() == 0: # don't show button self.groupPanel._hideButton(butName) self.prefs['shownButs'][butName] = 0 else: # show button self.groupPanel._showButton(butName) self.prefs['shownButs'][butName] = 1 preferences.save()
def addStyle(name, info): exists = name in userStyles if exists and userStyles[name] == info: return userStyles[name] = info if not name: return prefStyles[name] = info from chimera import preferences preferences.save() chimera.triggers.activateTrigger(TRIGGER_SLAB_STYLES, name)
def _butChangeCB(self, butName): butInfo = self.buttonInfo[butName] if butInfo['variable'].get() == 0: # don't show button self.groupPanel._hideButton(butName) self.prefs['shownButs'][butName] = 0 else: # show button self.groupPanel._showButton(butName) self.prefs['shownButs'][butName] = 1 preferences.save()
def addDirectory(self, path, savePreferences=False): "Add a directory to preferences and load extension from it" if path not in self.directories: self.directories.append(path) if self.loadDirectory(path) and self.settingsGrid: self.remakeSettings() if savePreferences: preferences.makeCurrentSaved("Tools") preferences.save() else: from chimera import replyobj replyobj.error("Tools directory \"%s\" " "already loaded\n" % path)
def addDirectory(self, path, savePreferences=False): "Add a directory to preferences and load extension from it" if path not in self.directories: self.directories.append(path) if self.loadDirectory(path) and self.settingsGrid: self.remakeSettings() if savePreferences: preferences.makeCurrentSaved("Tools") preferences.save() else: from chimera import replyobj replyobj.error("Tools directory \"%s\" " "already loaded\n" % path)
def _colChangeCB(self, colName): gp = self.groupPanel colInfo = self.columnInfo[colName] if colInfo['variable'].get() == 0: # don't show column if gp.shownColumns.count(1) == 1: # can't hide _all_ columns colInfo['variable'].set(1) raise ValueError, "Can't hide all columns!" gp.shownColumns[_columnNames.index(colName)] = 0 self.prefs['shownColumns'][colName] = 0 else: # show column gp.shownColumns[_columnNames.index(colName)] = 1 self.prefs['shownColumns'][colName] = 1 preferences.save() gp._buildTable()
def _colChangeCB(self, colName): gp = self.groupPanel colInfo = self.columnInfo[colName] if colInfo['variable'].get() == 0: # don't show column if gp.shownColumns.count(1) == 1: # can't hide _all_ columns colInfo['variable'].set(1) raise ValueError, "Can't hide all columns!" gp.shownColumns[_columnNames.index(colName)] = 0 self.prefs['shownColumns'][colName] = 0 else: # show column gp.shownColumns[_columnNames.index(colName)] = 1 self.prefs['shownColumns'][colName] = 1 preferences.save() gp._buildTable()
def assert_preferences(): insert_defaults = False try: binary, dat = get_preferences() except KeyError: insert_defaults = True else: if not binary or not dat: insert_defaults = True if insert_defaults: binary = find_executable('nciplot') or '' dat = '' if 'NCIPLOT_HOME' in os.environ: dat = os.path.join(os.environ['NCIPLOT_HOME'], 'dat') preferences.set('tangram_nciplot', 'nciplot_bin', binary) preferences.set('tangram_nciplot', 'nciplot_dat', dat) preferences.save() return binary, dat
def savePrefs(self): group = self.options[0][1] optList = group[1][1] execFile = optList[0].var.get() needSave = False if execFile and execFile != prefs["executable"]: prefs["executable"] = execFile needSave = True radiiFile = optList[1].var.get() if radiiFile and radiiFile != prefs["radii"]: prefs["radii"] = radiiFile needSave = True chargesFile = optList[2].var.get() if chargesFile and chargesFile != prefs["charges"]: prefs["charges"] = chargesFile needSave = True if needSave: preferences.save()
def savePrefs(self): group = self.options[0][1] optList = group[1][1] execFile = optList[0].var.get() needSave = False if execFile and execFile != prefs["executable"]: prefs["executable"] = execFile needSave = True radiiFile = optList[1].var.get() if radiiFile and radiiFile != prefs["radii"]: prefs["radii"] = radiiFile needSave = True chargesFile = optList[2].var.get() if chargesFile and chargesFile != prefs["charges"]: prefs["charges"] = chargesFile needSave = True if needSave: preferences.save()
def saveui_save(self, name): from chimera import preferences addScaling(name, self._makeScalingValues()) preferences.save() self.dialog.status("Setting \"%s\" saved" % name) return True
def saveui_delete(self, name): from chimera import preferences removeScaling(name) preferences.save() self.dialog.status("Setting \"%s\" deleted" % name) return True
def removeStyle(name): del userStyles[name] del prefStyles[name] from chimera import preferences preferences.save() chimera.triggers.activateTrigger(TRIGGER_SLAB_STYLES, name)
class XSectionEditor: def __init__(self, parent, dialog): self.points = [] self.divisions = 10 self.closed = 0 self.smoothacross = 0 self.smoothalong = 0 self.mapped = 0 self.dialog = dialog self.currentXS = None from chimera.preferences import saveui self.saveui = saveui.SaveUI(parent, self) import Tkinter, Pmw f = Tkinter.Frame(parent) f.pack(expand=Tkinter.TRUE, fill=Tkinter.BOTH) self.opt = Pmw.RadioSelect(f, buttontype="checkbutton", command=self._optChange, orient="vertical", labelpos="n", label_text="Display Options", pady=0, hull_borderwidth=2, hull_relief=Tkinter.RIDGE) self.opt.pack(side=Tkinter.TOP) self.opt.add("closed", text="Closed cross section") self.opt.add("smoothacross", text="Smooth across ribbon") self.opt.add("smoothalong", text="Smooth along ribbon") t = Tkinter.Label(f, text="Click to add point; " "BackSpace to delete point.", fg="gray40") t.pack(side=Tkinter.TOP) t = Tkinter.Label(f, text="Changing grid division " "erases drawn cross section!", fg="gray40") t.pack(side=Tkinter.BOTTOM) subf = Tkinter.Frame(f) subf.pack(side=Tkinter.BOTTOM) self.div = Pmw.Counter(subf, labelpos="w", label_text="Number of grid divisions:", entry_width=3, entryfield_modifiedcommand=self._setDivisions, entryfield_value=self.divisions, entryfield_validate={ "validator": "integer", "minstrict": 0, "maxstrict": 0, "min": 4, "max": 100 }) self.div.pack(side=Tkinter.LEFT) self.divEntryfield = self.div.component("entryfield") self.erase = Tkinter.Button(subf, text="Erase All", command=self._erase) self.erase.pack(side=Tkinter.LEFT) self._makeDrawingSurface(f) item = self.saveui_defaultItem() if item: self.saveui_select(item) def _makeDrawingSurface(self, parent): import Tkinter f = Tkinter.Frame(parent, bd=2, relief=Tkinter.RIDGE) f.pack(expand=1, fill=Tkinter.BOTH) self.canvas = Tkinter.Canvas(f, bd=0, highlightthickness=0, bg="white", takefocus="1", width=200, height=200) self.grid = [] self.outline = None self.curPoint = None self.canvasWidth = 0 self.canvasHeight = 0 self.drawingSize = 0 self.drawingXStart = 0 self.drawingXEnd = 0 self.drawingYStart = 0 self.drawingYEnd = 0 self.canvas.bind("<Configure>", self._configureCanvas) self.canvas.bind("<ButtonRelease>", self._addPoint) self.canvas.bind("<BackSpace>", self._deletePoint) self.canvas.bind("<Delete>", self._deletePoint) self.canvas.bind("<Enter>", self._canvasEnter) self.canvas.bind("<Motion>", self._movePoint) self.canvas.pack(expand=1, fill=Tkinter.BOTH) def _optChange(self, option, onoff): self.currentXS = None setattr(self, option, onoff) if option == "closed": self._remakeOutline() def _setDivisions(self): self.currentXS = None if not self.divEntryfield.valid(): return d = int(self.divEntryfield.get()) if d == self.divisions: return self.divisions = d if self.outline: self.outline.delete() self.outline = None self.points = [] self._configureCanvas() def _configureCanvas(self, event=None): import Canvas if event is not None: self.mapped = True if (event.width == self.canvasWidth and event.height == self.canvasHeight): return self.canvasWidth = event.width self.canvasHeight = event.height # Leave some space for user to draw right # to the edge of canvas self.drawingSize = min(self.canvasWidth, self.canvasHeight) - 10 self.drawingXStart = (self.canvasWidth - self.drawingSize) / 2 self.drawingXEnd = self.drawingXStart + self.drawingSize self.drawingYStart = (self.canvasHeight - self.drawingSize) / 2 self.drawingYEnd = self.drawingYStart + self.drawingSize self.scale = float(self.drawingSize) / self.divisions # Remake grid lines for line in self.grid: line.delete() self.grid = [] for i in range(self.divisions + 1): line = Canvas.Line(self.canvas, [ self._mapToCanvas((i, 0)), self._mapToCanvas((i, self.divisions)) ], fill="gray") self.grid.append(line) line = Canvas.Line(self.canvas, [ self._mapToCanvas((0, i)), self._mapToCanvas((self.divisions, i)) ], fill="gray") self.grid.append(line) self._remakeOutline() self.canvas.focus_set() def _remakeOutline(self): if not self.mapped: return import Canvas if self.outline: self.outline.delete() if not self.points: self.outline = None elif len(self.points) < 2: pt = self._mapToCanvas(self.points[0]) ul = (pt[0] - 1, pt[1] - 1) lr = (pt[0] + 1, pt[1] + 1) self.outline = Canvas.Rectangle(self.canvas, [ul, lr], fill="black") else: coords = [] for pt in self.points: coords.append(self._mapToCanvas(pt)) if "closed" in self.opt.getvalue(): if self.points[0] != self.points[-1]: coords.append(self._mapToCanvas(self.points[0])) else: del self.points[-1] self.outline = Canvas.Line(self.canvas, coords, fill="black", width=3) def _addPoint(self, event): self.currentXS = None pt = self._mapFromCanvas(event) if not self.points or self.points[-1] != pt: self.points.append(pt) self._remakeOutline() def _deletePoint(self, event): self.currentXS = None if not self.points: return del self.points[-1] self._remakeOutline() def _movePoint(self, event): import Canvas pt = self._mapToCanvas(self._mapFromCanvas(event)) if self.curPoint: self.curPoint.delete() ul = (pt[0] - 1, pt[1] - 1) lr = (pt[0] + 1, pt[1] + 1) self.curPoint = Canvas.Rectangle(self.canvas, [ul, lr], outline="red") def _mapFromCanvas(self, event): if event.x < self.drawingXStart: x = 0 elif event.x >= self.drawingXEnd: x = self.divisions else: x = int(round((event.x - self.drawingXStart) / self.scale)) if event.y < self.drawingYStart: y = 0 elif event.y >= self.drawingYEnd: y = self.divisions else: y = int(round((event.y - self.drawingYStart) / self.scale)) return x, y def _mapToCanvas(self, pt): x = self.drawingXStart + pt[0] * self.scale y = self.drawingYStart + pt[1] * self.scale return x, y def _canvasEnter(self, event): self.canvas.focus_set() def _erase(self): self.points = [] self._remakeOutline() def _showXSection(self, name): xs = findXSection(name) values = [] self.smoothacross = xs.sw if xs.sw: values.append("smoothacross") self.smoothalong = xs.sl if xs.sl: values.append("smoothalong") self.closed = xs.closed if xs.closed: values.append("closed") self.opt.setvalue(values) self.divEntryfield.setvalue(str(xs.grid)) self.points = xs.points self._remakeOutline() self.currentXS = xs def Apply(self, restrict): if self.currentXS: xs = self.currentXS else: xs = XS(None, self.points, self.smoothacross, self.smoothalong, self.closed, self.divisions) if restrict: from chimera import selection rList = selection.currentResidues() else: rList = [] if rList: for r in rList: xs.setResidue(r) else: for m in chimera.openModels.list(modelTypes=[chimera.Molecule]): for r in m.residues: xs.setResidue(r) # SaveUI callback functions def saveui_label(self): return "Ribbon Cross Section" def saveui_presetItems(self): return systemXS.keys() def saveui_userItems(self): return userXS.keys() def saveui_defaultItem(self): try: return userXS.keys()[0] except IndexError: return systemXS.keys()[0] def saveui_select(self, name): self._showXSection(name) def saveui_save(self, name): if name in Reserved: from chimera import replyobj replyobj.error("%s is a reserved name. " "Please choose a different name." % name) return False try: checkXSection(self.closed, self.points) except ValueError, s: from chimera import replyobj replyobj.error(s) return False from chimera import preferences addXSection(name, self.points, self.smoothacross, self.smoothalong, self.closed, self.divisions) preferences.save() redisplayMenu() self.dialog.status("Setting \"%s\" saved" % name) return True
def saveui_save(self, name): from chimera import preferences addScaling(name, self._makeScalingValues()) preferences.save() self.dialog.status("Setting \"%s\" saved" % name) return True
def saveui_delete(self, name): from chimera import preferences removeScaling(name) preferences.save() self.dialog.status("Setting \"%s\" deleted" % name) return True