def fillInUI(self, parent): import Pmw, Tkinter SaveModeless.fillInUI(self, parent) self.clientArea.columnconfigure(0, weight=1) row = 0 from chimera.widgets import ModelOptionMenu self.surfList = ModelOptionMenu(self.clientArea, labelpos='w', label_text="Save surface:", filtFunc=lambda m: isinstance(m, MSMSModel)) self.surfList.grid(row=row, column=0) row += 1 self.saveNormalsVar = Tkinter.IntVar(self.clientArea) self.saveNormalsVar.set(True) Tkinter.Checkbutton(self.clientArea, text="Save normals", variable=self.saveNormalsVar).grid(row=row) row += 1 self.displayedOnlyVar = Tkinter.IntVar(self.clientArea) self.displayedOnlyVar.set(True) Tkinter.Checkbutton(self.clientArea, text="Limit output to" " displayed surface sections", variable=self.displayedOnlyVar).grid(row=row) row += 1
def fillInUI(self, parent): import Pmw, Tkinter SaveModeless.fillInUI(self, parent) row = 0 from chimera.widgets import MoleculeOptionMenu self.modelMenu = MoleculeOptionMenu( self.clientArea, labelpos='w', label_text="Save model:", command=lambda m: self.configure(self.modelMenu.getvalue(), refreshList=False)) self.modelMenu.grid(row=row, column=0, sticky='w') row += 1 from AddCharge import knownChargeModels, defaultChargeModel from chimera import dialogs self.parmsetOption = Pmw.OptionMenu( self.clientArea, labelpos='w', label_text="Select force field type: ", initialitem=defaultChargeModel, items=knownChargeModels) # not always shown; remember row number self._msmRow = row self.parmsetOption.grid(row=row, column=0, sticky='w') row += 1
def __init__(self, histDialog): # make dialog hidden initially self.histDialog = histDialog SaveModeless.__init__(self, clientPos='s', clientSticky="ew", initialfile="chimera.cmd")
def fillInUI(self, parent): import Tkinter as Tk import Pmw from HtmlText import HtmlText SaveModeless.fillInUI(self, parent) parent = self.clientArea self.notes = Pmw.ScrolledText(parent, text_pyclass=HtmlText, text_relief=Tk.FLAT, text_wrap=Tk.WORD, text_height=4, text_width=10, text_highlightthickness=0) self.notes.pack(side=Tk.TOP, anchor=Tk.NW, fill=Tk.BOTH, expand=True, pady=5, padx=10) self.notes.configure(text_state=Tk.DISABLED, hscrollmode='dynamic', vscrollmode='dynamic', text_background=parent.cget('background')) import exports self.notes.settext(exports.getNotes(self.getFilter()))
def fillInUI(self, parent): import Pmw, Tkinter SaveModeless.fillInUI(self, parent) self.clientArea.columnconfigure(0, weight=1) row = 0 from chimera.widgets import ModelOptionMenu self.surfList = ModelOptionMenu( self.clientArea, labelpos='w', label_text="Save surface:", filtFunc=lambda m: isinstance(m, MSMSModel)) self.surfList.grid(row=row, column=0) row += 1 self.saveNormalsVar = Tkinter.IntVar(self.clientArea) self.saveNormalsVar.set(True) Tkinter.Checkbutton(self.clientArea, text="Save normals", variable=self.saveNormalsVar).grid(row=row) row += 1 self.displayedOnlyVar = Tkinter.IntVar(self.clientArea) self.displayedOnlyVar.set(True) Tkinter.Checkbutton(self.clientArea, text="Limit output to" " displayed surface sections", variable=self.displayedOnlyVar).grid(row=row) row += 1
def __init__(self, mav): self.mav = mav self.title = "Save Association Info of %s" % mav.title defaultFile = os.path.splitext(self.mav.title or "alignment")[0] SaveModeless.__init__(self, clientPos='s', initialfile=defaultFile + ".asc")
def fillInUI(self, parent): SaveModeless.fillInUI(self, parent) self.clientArea.columnconfigure(0, weight=1) self.clientArea.columnconfigure(1, weight=1) self.amount = Pmw.RadioSelect(self.clientArea, orient='vertical', buttontype='radiobutton', labelpos='w', pady=0, label_text="Record") self.amount.add("selected commands") self.amount.add("all commands") self.amount.invoke(1) self.amount.grid(row=0, column=0) self.commandStyle = Pmw.RadioSelect(self.clientArea, orient='vertical', command=self._adjustFileName, buttontype='radiobutton', labelpos='w', pady=0, label_text="Record as") self.commandStyle.add("Chimera commands") self.commandStyle.add("Python commands") self.commandStyle.invoke(0) self.commandStyle.grid(row=1, column=0) self.appending = Tkinter.IntVar(parent) self.appending.set(0) Tkinter.Checkbutton(self.clientArea, variable=self.appending, text="Append to file").grid(row=0, column=1, rowspan=2)
def __init__(self, mav): self.mav = mav self.title = "Save EPS of %s" % mav.title defaultFile = os.path.splitext(self.mav.title or "alignment")[0] SaveModeless.__init__(self, clientPos='s', initialfile=defaultFile, filters=[("EPS", "*.eps", ".eps")])
def fillInUI(self, parent): SaveModeless.fillInUI(self, parent) from CGLtk import Hybrid br = Hybrid.Entry(self.clientArea, 'Bit rate (Kb/sec):', 6, self.default_bit_rate) br.frame.grid(row=0, column=0, sticky='w') self.bit_rate = br.variable
def fillInUI(self, parent): SaveModeless.fillInUI(self, parent) from CGLtk import Hybrid br = Hybrid.Entry(self.clientArea, 'Bit rate (Kb/sec):', 6, self.default_bit_rate) br.frame.grid(row = 0, column = 0, sticky = 'w') self.bit_rate = br.variable
def __init__(self): self.default_bit_rate = 6000 from MovieRecorder import RecorderGUI filters = map(lambda f: (f[0], '*.%s' % f[1], '.%s' % f[1]), RecorderGUI.formats) SaveModeless.__init__(self, clientPos = 's', clientSticky = 'w', filters = filters, historyID = "MorphMap")
def __init__(self): self.prefs = preferences.addCategory("write PDB dialog", preferences.HiddenCategory, optDict={"multiSavePDB": "multiple"}) self.haveTraj = False SaveModeless.__init__(self, clientPos='s', clientSticky='ewns', filters=[("PDB", "*.pdb", ".pdb")]) openModels.addAddHandler(self._modelsChange, None), openModels.addRemoveHandler(self._modelsChange, None) self._modelsChange()
def __init__(self): self.prefs = preferences.addCategory("write Mol2 dialog", preferences.HiddenCategory, optDict={"multiSaveMol2": "multiple", "hydrogen naming": "sybyl", "residue numbers": True}) SaveModeless.__init__(self, clientPos='s', clientSticky='ewns', filters=[("Mol2", "*.mol2", ".mol2")]) openModels.addAddHandler(self._modelsChange, None) openModels.addRemoveHandler(self._modelsChange, None) self._modelsChange()
def __init__(self): self.default_bit_rate = 6000 from MovieRecorder import RecorderGUI filters = map(lambda f: (f[0], '*.%s' % f[1], '.%s' % f[1]), RecorderGUI.formats) SaveModeless.__init__(self, clientPos='s', clientSticky='w', filters=filters, historyID="MorphMap")
def enter(self): # if any new export types have been added, # then add them to the dialog import exports filterInfo = exports.getFilterInfo() for pos, fi in enumerate(filterInfo): if fi[0] in self.addedSceneTypes: continue self.addedSceneTypes.add(fi[0]) self.addFilter(fi, pos) # next do the normal enter stuff SaveModeless.enter(self)
def _save(text): global _saveDialog if not _saveDialog: from OpenSave import SaveModeless _saveDialog = SaveModeless( title="Choose Attribute Calculator Save File", command=_fileChosen, initialfile="attrcalc.txt", historyID="Attribute Calculator Output") else: _saveDialog.enter() _saveDialog._text = text
def fillInUI(self, parent): SaveModeless.fillInUI(self, parent) self.saveTypes = Pmw.RadioSelect(self.clientArea, pady=0, buttontype='checkbutton', labelpos='w', orient='vertical', label_text="Save:") self.saveTypes.grid(row=0, column=0) for name in self.structMeasure.notebook.pagenames(): mode = 'normal' if name not in [DISTANCES, ANGLES, BONDROTS, GEOMETRIES]: mode = 'disabled' self.saveTypes.add(name, state=mode) if mode == 'normal': self.saveTypes.invoke(name)
def __init__(self, **kw): import exports self.notes = None filterInfo = exports.getFilterInfo() self.addedSceneTypes = set([i[0] for i in filterInfo]) SaveModeless.__init__(self, clientPos='s', clientSticky='ew', filters=filterInfo, defaultFilter='X3D', command=self._command, setFilterCommand=self._setFilterCB, **kw)
def export_cb(self): def save(okay, dialog, self=self): if okay: paths = dialog.getPaths() if paths: self.write_comma_separated_values(paths[0]) from segment_dialog import current_segmentation seg = current_segmentation() if seg is None: idir = ifile = None elif hasattr(seg, 'path'): import os.path idir, ifile = os.path.split(seg.path) ifile = os.path.splitext(ifile)[0] + '.csv' else: import os.path idir = None ifile = os.path.splitext(seg.name)[0] + '.csv' from OpenSave import SaveModeless SaveModeless(title='Export Comma Separated Values', initialdir=idir, initialfile=ifile, command=save)
def write_grasp_surface_file(): from chimera import openModels from _surface import SurfaceModel mlist = openModels.list(modelTypes=[SurfaceModel]) if len(mlist) == 0: from chimera import replyobj replyobj.status('No displayed surfaces') return varray, tarray, narray = surface_geometry(mlist) if len(tarray) == 0: from chimera import replyobj replyobj.status('No displayed triangles') return def save_geometry(okay, d, varray=varray, tarray=tarray, narray=narray): if not okay: return # User canceled action. path = d.getPaths()[0] f = grasp_surface_file(varray, tarray, narray) file = open(path, 'wb') file.write(f) file.close() from OpenSave import SaveModeless SaveModeless(title="Save Surface", filters=[('GRASP surface', ['*.srf'], '.srf')], command=save_geometry)
def saveDemoAs(self): from OpenSave import SaveModeless SaveModeless(command=self._saveCB, title="Choose Demo Save Location", dialogKw={'oneshot': 1}, historyID="Demo Save As", defaultFilter=0, filters=[("Demo", ["*.src"], ".src")])
def __init__(self, movie): self.movie = movie movie.subdialogs.append(self) from MovieRecorder import RecorderGUI formats = [] exts = [] for fmtInfo in RecorderGUI.formats: fmt, ext = fmtInfo[:2] formats.append(fmt) exts.append("." + ext) filters = [] for i, fmt in enumerate(formats): ext = exts[i] filters.append((fmt, '*'+ext, ext)) SaveModeless.__init__(self, clientPos='s', clientSticky='ew', defaultFilter=prefs[RECORDER_FORMAT], filters=filters, historyID="MD recorder")
def fillInUI(self, parent): SaveModeless.fillInUI(self, parent) from chimera.tkoptions import SymbolicEnumOption, BooleanOption class ColorModeOption(SymbolicEnumOption): values = ["color", "gray", "mono"] labels = ["color", "grayscale", "black & white"] self.colorMode = ColorModeOption(self.clientArea, 0, "color mode", "color", None, balloon="output color range") self.orientation = BooleanOption( self.clientArea, 1, "rotate 90", False, None, balloon="If true, output will be rotated 90 degrees\n" "(i.e. landscape mode)") class ExtentOption(SymbolicEnumOption): values = ["visible", "all"] labels = ["visible region", "entire alignment"] self.extent = ExtentOption( self.clientArea, 2, "extent", "visible", None, balloon="save the entire alignment or just the visible part") self.hideNodes = BooleanOption( self.clientArea, 3, "hide tree control nodes", True, None, balloon="Hide square boxes used as controls for tree") if not self.mav.seqCanvas.treeShown: self.hideNodes.forget() self._nodesHandler = self.mav.triggers.addHandler( DISPLAY_TREE, self._treeDispCB, None)
def fillInUI(self, parent): SaveModeless.fillInUI(self, parent) self.selUnsel = Pmw.OptionMenu(self.clientArea, items=[ "selected", "unselected"], labelpos='w', label_text= "Write") self.selUnsel.grid(row=0, column=0, sticky='e') self.classMenu = Pmw.OptionMenu(self.clientArea, items= map(lambda c: c.__name__.lower() + "s", classes)) self.classMenu.grid(row=0, column=1, sticky='w') from tkoptions import NamingStyleOption if self.prefs[self.PREF_NAMING] in NamingStyleOption.values: default = self.prefs[self.PREF_NAMING] else: default = None self.naming = NamingStyleOption(self.clientArea, 1, None, default, None)
def fillInUI(self, *args): if isinstance(self, SaveModeless): SaveModeless.fillInUI(self, *args) else: SaveModal.fillInUI(self, *args) import Tkinter self.saveRegion = Tkinter.IntVar(self.clientArea) self.saveRegion.set(False) Tkinter.Checkbutton(self.clientArea, variable=self.saveRegion, text="Restrict save to active region").grid(row=0, sticky='w') self.omitGaps = Tkinter.IntVar(self.clientArea) self.omitGaps.set(True) Tkinter.Checkbutton(self.clientArea, variable=self.omitGaps, text="Omit all-gap columns").grid(row=1, sticky='w') self.appendNumberings = Tkinter.IntVar(self.clientArea) Tkinter.Checkbutton(self.clientArea, variable=self.appendNumberings, text="Append sequence" " numberings to sequence names").grid(row=2, sticky='w')
def __init__(self, movie): self.movie = movie movie.subdialogs.append(self) from MovieRecorder import RecorderGUI formats = [] exts = [] for fmtInfo in RecorderGUI.formats: fmt, ext = fmtInfo[:2] formats.append(fmt) exts.append("." + ext) filters = [] for i, fmt in enumerate(formats): ext = exts[i] filters.append((fmt, '*' + ext, ext)) SaveModeless.__init__(self, clientPos='s', clientSticky='ew', defaultFilter=prefs[RECORDER_FORMAT], filters=filters, historyID="MD recorder")
def fillInUI(self, parent): SaveModeless.fillInUI(self, parent) from chimera.tkoptions import SymbolicEnumOption self.headerChoice = SymbolicEnumOption(self.clientArea, 0, "Save", None, None) self.omitNoValueVar = Tkinter.IntVar(self.clientArea) self.omitNoValueVar.set(True) frame = Tkinter.Frame(self.clientArea) frame.grid(row=1, column=0, columnspan=2) ckb = Tkinter.Checkbutton(frame, variable=self.omitNoValueVar, text="Omit no-value positions") ckb.grid() chimera.help.register(ckb, balloon= "If on, conservations positions without\n" "values will not have lines in the output file") self._populateMenu() from MAViewer import SHOW_HEADERS, HIDE_HEADERS for trig in [SHOW_HEADERS, HIDE_HEADERS]: self.mav.triggers.addHandler(trig, self._populateMenu, None)
def browse(self): if hasattr(self, '_saveDialog'): self._saveDialog.enter() return from OpenSave import SaveModeless self._saveDialog = SaveModeless( command=self._saveCB, historyID='Delphi output %s' % self.name, title='Save %s' % self.name, initialfile=self.default, filters=[(self.name, '*', self.defaultextension)], compressed=self.compressed)
def fillInUI(self, parent): import Pmw, Tkinter SaveModeless.fillInUI(self, parent) row = 0 from chimera.widgets import MoleculeOptionMenu self.modelMenu = MoleculeOptionMenu(self.clientArea, labelpos='w', label_text="Save model:", command=lambda m: self.configure( self.modelMenu.getvalue(), refreshList=False)) self.modelMenu.grid(row=row, column=0, sticky='w') row += 1 from AddCharge import knownChargeModels, defaultChargeModel from chimera import dialogs self.parmsetOption = Pmw.OptionMenu(self.clientArea, labelpos='w', label_text="Select force field type: ", initialitem=defaultChargeModel, items=knownChargeModels) # not always shown; remember row number self._msmRow = row self.parmsetOption.grid(row=row, column=0, sticky='w') row += 1
def fillInUI(self, *args): if isinstance(self, SaveModeless): SaveModeless.fillInUI(self, *args) else: SaveModal.fillInUI(self, *args) import Tkinter self.saveRegion = Tkinter.IntVar(self.clientArea) self.saveRegion.set(False) Tkinter.Checkbutton(self.clientArea, variable=self.saveRegion, text="Restrict save to active region").grid( row=0, sticky='w') self.omitGaps = Tkinter.IntVar(self.clientArea) self.omitGaps.set(True) Tkinter.Checkbutton(self.clientArea, variable=self.omitGaps, text="Omit all-gap columns").grid(row=1, sticky='w') self.appendNumberings = Tkinter.IntVar(self.clientArea) Tkinter.Checkbutton(self.clientArea, variable=self.appendNumberings, text="Append sequence" " numberings to sequence names").grid(row=2, sticky='w')
def save_fits_cb(self): lfits = self.selected_listbox_fits() mlist = sum([f.fit_molecules() for f in lfits], []) if len(mlist) == 0: from chimera.replyobj import warning warning('No fits of molecules chosen from list.') return idir = ifile = None vlist = [f.volume for f in lfits] pmlist = [m for m in mlist + vlist if hasattr(m, 'openedAs')] if pmlist: for m in pmlist: import os.path dpath, fname = os.path.split(m.openedAs[0]) base, suf = os.path.splitext(fname) if ifile is None: suffix = '_fit%d.pdb' if len(lfits) > 1 else '_fit.pdb' ifile = base + suffix if dpath and idir is None: idir = dpath def save(okay, dialog, lfits=lfits): if okay: paths = dialog.getPaths() if paths: path = paths[0] import Midas if len(lfits) > 1 and path.find('%d') == -1: base, suf = os.path.splitext(path) path = base + '_fit%d' + suf for i, fit in enumerate(lfits): p = path if len(lfits) == 1 else path % (i + 1) fit.place_models(self.session) Midas.write(fit.fit_molecules(), relModel=fit.volume, filename=p) from OpenSave import SaveModeless SaveModeless(title='Save Fit Molecules', filters=[('PDB', '*.pdb', '.pdb')], initialdir=idir, initialfile=ifile, command=save)
def _save(output, show): global _saveDialog if not _saveDialog: from OpenSave import SaveModeless _saveDialog = SaveModeless( title="Choose Surface Area/Volume Save File", command=_fileChosen, initialfile="output.html", historyID="Surface Area/Volume Output") else: _saveDialog.enter() _saveDialog._output = output _saveDialog._show = show
def select_save_path_modeless(save_cb): from fileformats import file_writers filters = map(lambda fw: (fw[0], ['*' + fw[2]], fw[2]), file_writers) def save(okay, d, save_cb=save_cb): if not okay: return paths_and_types = d.getPathsAndTypes() if len(paths_and_types) == 0: return path, file_type = paths_and_types[0] save_cb(path, file_type) from OpenSave import SaveModeless d = SaveModeless(title="Save Volume Data", filters=filters, defaultFilter=0, command=save)
def Save(self): if self.image is None: return def save(okay, dialog, self=self): if not okay: return paths_and_types = dialog.getPathsAndTypes() if len(paths_and_types) == 0: return path, format = paths_and_types[0] self.image.save(path, format) from OpenSave import SaveModeless SaveModeless(title='Save Image', filters=[('JPEG', '*.jpg', '.jpg'), ('PNG', '*.png', '.png'), ('TIFF', '*.tif', '.tif')], command=save)
def show_save_dialog(seg, saved_cb=None): def save(okay, dialog, saved_cb=saved_cb): if okay: paths = dialog.getPaths() if paths: write_segmentation(seg, paths[0]) if saved_cb: saved_cb(seg) if hasattr(seg, 'path'): import os.path idir, ifile = os.path.split(seg.path) else: idir = None ifile = seg.name from OpenSave import SaveModeless SaveModeless(title='Save Segmentation %s' % seg.name, filters=[('Segmentation', '*.seg', '.seg')], initialdir=idir, initialfile=ifile, command=save)
def __init__(self, mav): self.mav = mav self.title = "Save Header of %s" % mav.title defaultFile = os.path.splitext(self.mav.title or "alignment")[0] SaveModeless.__init__(self, initialfile=defaultFile+".hdr", clientPos='s')
def fillInUI(self, parent): import Pmw, Tkinter SaveModeless.fillInUI(self, parent) row = 0 from chimera.widgets import MoleculeScrolledListBox, \ ModelOptionMenu self.modelList = MoleculeScrolledListBox(self.clientArea, labelpos='w', label_text="Save models:", listbox_selectmode='extended', selectioncommand=lambda: self.configure( self.modelList.getvalue(), refreshList=False)) self.modelList.grid(row=row, column=0, sticky='nsew') self.clientArea.rowconfigure(row, weight=1) self.clientArea.columnconfigure(0, weight=1) row += 1 from chimera import dialogs self.labelMap = { "individual": "a single file [individual @MOLECULE sections]", "combined": "a single file [combined @MOLECULE section]", "multiple": "multiple files [appending model number]" } preferred = self.labelMap[self.prefs["multiSaveMol2"]] self.multiSaveMenu = Pmw.OptionMenu(self.clientArea, labelpos='w', label_text="Save multiple models in", initialitem=preferred, items=self.labelMap.values()) # not always shown; remember row number self._msmRow = row row += 1 self.saveRelativeVar = Tkinter.IntVar(self.clientArea) self.saveRelativeVar.set(False) self.relativeFrame = f = Tkinter.Frame(self.clientArea) Tkinter.Checkbutton(f, variable=self.saveRelativeVar, text="Save relative to model:").grid(row=0, column=0, sticky='e') self.relModelMenu = ModelOptionMenu(f) self.relModelMenu.grid(row=0, column=1, sticky='w') self.saveUntransformedVar = Tkinter.IntVar(parent) self.saveUntransformedVar.set(True) self.untransformedButton = Tkinter.Checkbutton(self.clientArea, variable=self.saveUntransformedVar, text="Use untransformed coordinates") self._rfRow = row row += 1 self.sybylHydNamesVar = Tkinter.IntVar(self.clientArea) self.sybylHydNamesVar.set( self.prefs["hydrogen naming"] == "sybyl") Tkinter.Checkbutton(self.clientArea, variable=self.sybylHydNamesVar, text="Use Sybyl-style hydrogen naming (e.g. HE12" " rather than 2HE1)").grid(row=row, column=0, sticky="w") row += 1 self.resNumsVar = Tkinter.IntVar(self.clientArea) self.resNumsVar.set(self.prefs["residue numbers"]) Tkinter.Checkbutton(self.clientArea, variable=self.resNumsVar, text="Include residue sequence numbers in substructure" " names").grid(row=row, column=0, sticky='w') row += 1 self.writeGaffVar = Tkinter.IntVar(self.clientArea) self.resNumsVar.set(False) Tkinter.Checkbutton(self.clientArea, variable=self.writeGaffVar, text="Write Amber/GAFF atom types instead of Sybyl atom types" ).grid(row=row, column=0, sticky='w') row += 1 self.rigidVar = Tkinter.IntVar(self.clientArea) self.rigidVar.set(False) Tkinter.Checkbutton(self.clientArea, variable=self.rigidVar, text="Write current selection to @SETS section of file" ).grid(row=row, column=0, sticky="w") row += 1
def __init__(self, mav, **kw): self.mav = mav if isinstance(self, SaveModeless): SaveModeless.__init__(self, **kw) else: SaveModal.__init__(self, **kw)
def WriteRegionsFile(smod, fname=None): if fname is None: # Show save-file dialog. def save(okay, dialog): if okay: paths = dialog.getPaths() if paths: WriteRegionsFile(smod, paths[0]) bname = smod.name[0:smod.name.rfind('_regions')] prefix = smod.path + bname + "_regions_save_%d" uupath = unusedFile(prefix) from OpenSave import SaveModeless d = SaveModeless(title='Save Regions', initialdir=smod.path, initialfile=os.path.basename(uupath), command=save) return tot_write_regions = [0] tot_e_size = 1 for region in smod.regions: tot_e_size += RegionSize(region, tot_write_regions) num_cons = 0 rcons = smod.region_contacts() for r1, cr1 in rcons.iteritems(): for r2, o in cr1.iteritems(): if r1.rid < r2.rid: num_cons = num_cons + 1 tot_e_size = tot_e_size + 1 + 4 * (num_cons) print "Writing %d regions, %d grouped" % (tot_write_regions[0], len(smod.regions)) if fname: print " - to", fname e = numpy.zeros([tot_e_size], numpy.float32) e[0] = float(tot_write_regions[0]) e_at = 1 rlist = renumberRegions(smod) for region in rlist: e_at = AddRegion(smod, region, e, e_at) print " - writing %d contacts" % (num_cons) e[e_at] = float(num_cons) e_at = e_at + 1 #consa = [] for r1, cr1 in rcons.iteritems(): for r2, o in cr1.iteritems(): if r1.rid < r2.rid: #consa = consa + [r1.rid, r2.rid, o.N, o.D] e[e_at + 0] = float(r1.rid) e[e_at + 1] = float(r2.rid) e[e_at + 2] = o.N e[e_at + 3] = o.D e_at = e_at + 4 #consa = [len(consa)/4] + consa #e = numpy.concatenate ( [ e, numpy.array ( consa, numpy.float32 ) ] ) e.tofile(fname) print "Wrote %s" % os.path.basename(fname)
def __init__(self): import preferences options = { self.PREF_NAMING: "simple" } self.prefs = preferences.addCategory("write selection dialog", preferences.HiddenCategory, optDict=options) SaveModeless.__init__(self, clientPos='s')
def _writeFileCB(self): if not hasattr(self, "_writeFileDialog"): from OpenSave import SaveModeless self._writeFileDialog = SaveModeless(command=self._writeFile, title="Write 2D Labels Info") self._writeFileDialog.enter()
class IlabelDialog(ModelessDialog): name = "2D Labels/Color Key" provideStatus = True buttons = ("Delete", "Close") LABELS = "Labels" COLOR_KEY = "Color Key" MOUSE_LABEL_TEXT = "Use mouse for label placement" MOUSE_KEY_TEXT = "Use mouse for key placement" EmphasisColor = "forest green" def __init__(self): import os.path myDir, junk = os.path.split(__file__) addFunction('place text', (self._pickLabel, self._moveLabel, None), icon=chimage.get(Image.open(os.path.join(myDir, 'ilabel.png')), tkgui.app)) addFunction('place key', (self._startOrGrabKey, self._sizeOrMoveKey, None), icon=chimage.get( Image.open(os.path.join(myDir, 'key.png')), tkgui.app)) import Ilabel if not Ilabel._ilabelModel: Ilabel.IlabelModel() self.model = Ilabel._ilabelModel ModelessDialog.__init__(self) self._sessionHandlerID = chimera.triggers.addHandler( SAVE_SESSION, self._saveSession, None) self._closeHandlerID = chimera.triggers.addHandler( CLOSE_SESSION, self.destroy, None) self._beginRestoreHandlerID = chimera.triggers.addHandler( BEGIN_RESTORE_SESSION, self.destroy, None) def fillInUI(self, parent): top = parent.winfo_toplevel() menubar = Tkinter.Menu(top, type="menubar", tearoff=False) top.config(menu=menubar) self.fileMenu = Tkinter.Menu(menubar) menubar.add_cascade(label="File", menu=self.fileMenu) self.fileMenu.add_command(label="Write...", command=self._writeFileCB) self.fileMenu.add_command(label="Read...", command=self._readFileCB) from chimera.tkgui import aquaMenuBar aquaMenuBar(menubar, parent, row=0) from ColorKey import KeyModel parent.rowconfigure(1, weight=1) parent.columnconfigure(0, weight=1) # _pageRaisedCB uses mouseModeVar, so define first self.mouseLabelingVar = Tkinter.IntVar(parent) self.mouseLabelingVar.set(True) self.mlLabelVar = Tkinter.StringVar(parent) self.mouseModeButton = Tkinter.Checkbutton(parent, command=self._mouseFuncCB, variable=self.mouseLabelingVar, textvariable=self.mlLabelVar) self.mouseModeButton.grid(row=2, column=0) self.notebook = Pmw.NoteBook(parent, raisecommand=self._pageRaisedCB) self.notebook.add(self.LABELS, tab_text=self.LABELS) self.notebook.add(self.COLOR_KEY, tab_text=self.COLOR_KEY) self.notebook.grid(row=1, column=0, sticky="nsew") self._fillLabelsPage(self.notebook.page(self.LABELS)) self.keyModel = KeyModel(self) self.keyPosition = None self._fillColorKeyPage(self.notebook.page(self.COLOR_KEY)) def _fillLabelsPage(self, page): page.columnconfigure(0, weight=1) page.columnconfigure(1, weight=1) page.columnconfigure(2, weight=1) row = 0 from CGLtk.Table import SortableTable self.labelTable = SortableTable(page, automultilineHeaders=False) self.labelTable.addColumn("Label [(x, y) text]", self._labelListing, anchor='w') self.labelTable.addColumn("Shown", "shown", format=bool) self.labelTable.setData(self.model.labels) self.labelTable.launch(browseCmd=self._tableCB, selectMode="single") self.labelTable.grid(row=row, column=0, columnspan=3, sticky="nsew") page.rowconfigure(row, weight=1) row += 1 self.labelText = Pmw.ScrolledText(page, labelpos='w', label_text="Text", text_height=3, text_width=20, text_wrap='none', text_state='disabled', text_exportselection=False) text = self.labelText.component('text') text.bind("<<Modified>>", self._textCB) text.bind("<<Selection>>", self._updateTextAttrWidgets) self.labelText.grid(row=row, column=0, sticky='nsew', columnspan=3) page.rowconfigure(row, weight=1) row += 1 self.labelSymbolMenu = Pmw.OptionMenu(page, labelpos='w', label_text="Insert symbol:", command=self._insertSymbol, items=[ u'\N{GREEK SMALL LETTER ALPHA}', u'\N{GREEK SMALL LETTER BETA}', u'\N{GREEK SMALL LETTER GAMMA}', u'\N{GREEK SMALL LETTER DELTA}', u'\N{GREEK SMALL LETTER EPSILON}', u'\N{GREEK SMALL LETTER PI}', u'\N{GREEK SMALL LETTER PHI}', u'\N{GREEK SMALL LETTER CHI}', u'\N{GREEK SMALL LETTER PSI}', u'\N{GREEK SMALL LETTER OMEGA}', u'\N{LEFTWARDS ARROW}', u'\N{RIGHTWARDS ARROW}', u'\N{LEFT RIGHT ARROW}', u'\N{UPWARDS ARROW}', u'\N{DOWNWARDS ARROW}', u'\N{SUPERSCRIPT TWO}', u'\N{SUPERSCRIPT THREE}', u'\N{DEGREE SIGN}', u'\N{LATIN CAPITAL LETTER A WITH RING ABOVE}', "more..." ]) self.labelSymbolMenu.grid(row=row, column=0, columnspan=3) row += 1 colorHouse = Pmw.LabeledWidget(page, labelpos='w', label_text="Color") colorHouse.grid(row=row, column=0, rowspan=3) from CGLtk.color.ColorWell import ColorWell self.colorWell = ColorWell(colorHouse.interior(), color=self._contrastWithBG(), callback=self._colorCB) self.colorWell.grid() from chimera.tkoptions import IntOption self.labelFontSize = IntOption(page, row, "Font size", 24, self._labelChangeCB, startCol=1, min=1, attribute="size", width=3) row += 1 self.labelFontStyle = FontStyle(page, row, "Font style", oglFont.normal, self._labelChangeCB, startCol=1) row += 1 self.labelFontTypeface = FontTypeface(page, row, "Font typeface", FONT_TYPEFACE_VALUES[0], self._labelChangeCB, startCol=1) row += 1 if self.model.curLabel: self.changeToLabel(self.model.curLabel, force=True) def _fillColorKeyPage(self, page): from chimera.tkoptions import IntOption, EnumOption, \ BooleanOption, RGBAOption f = Tkinter.Frame(page) f.grid(row=0, columnspan=2) self.numComponents = IntOption(f, 0, "Number of colors/labels", 3, self._componentsCB, min=2, width=2) self.componentsFrame = Tkinter.Frame(page) self.componentsFrame.grid(row=1, column=0, sticky="nsew", columnspan=2) page.columnconfigure(0, weight=1) self.componentsFrame.columnconfigure(1, weight=1) class ColorTreatment(EnumOption): values = ("distinct", "blended") self.colorTreatment = ColorTreatment(page, 2, "Color range depiction", "blended", self._keyChangeCB, balloon="Should colors be shown as distinct rectangles" " or as a continuous range") class LabelPosition(EnumOption): values = ("left/top", "right/bottom") self.labelPos = LabelPosition(page, 3, "Label positions", "right/bottom", self._keyChangeCB, balloon="Position of" " labels relative to color key.\nLabels always" " positioned adjacent to long side.") self.labelColor = RGBAOption(page, 4, "Label color", self._contrastWithBG(), self._keyChangeCB, balloob= "Label color. If set to 'No color', use corresponding" " key color", noneOkay=True) class LabelJustification(EnumOption): values = ("left", "decimal point", "right") self.justification = LabelJustification(page, 5, "Label justification", "decimal point", self._keyChangeCB, balloon="Justification of label text" " in a vertical key layout.\nHorizontal key labels will" " always be center justified.") self.labelOffset = IntOption(page, 6, "Label offset", 0, self._keyChangeCB, width=3, balloon="Additional offset" " of labels from color bar, in pixels") self.keyFontSize = IntOption(page, 7, "Font size", 24, self._keyChangeCB, width=3) self.keyFontStyle = FontStyle(page, 8, "Font style", oglFont.normal, self._keyChangeCB) self.keyFontTypeface = FontTypeface(page, 9, "Font typeface", FONT_TYPEFACE_VALUES[0], self._keyChangeCB) self.borderColor = RGBAOption(page, 10, "Border color", None, self._keyChangeCB, balloon="Color of border" " around color key (not each individual color).\n" "If 'no color', then no border is drawn.") self.borderWidth = IntOption(page, 11, "Border width", 3, self._keyChangeCB, balloon="in pixels") self.tickMarks = BooleanOption(page, 12, "Show tick marks", False, self._keyChangeCB, balloon="Show tick marks" " pointing from key to labels") self._componentsCB(self.numComponents) def destroy(self, *args): self.mouseLabelingVar.set(True) self.mouseModeButton.invoke() chimera.triggers.deleteHandler(SAVE_SESSION, self._sessionHandlerID) chimera.triggers.deleteHandler(CLOSE_SESSION, self._closeHandlerID) chimera.triggers.deleteHandler(BEGIN_RESTORE_SESSION, self._beginRestoreHandlerID) chimera.openModels.close([self.model, self.keyModel]) ModelessDialog.destroy(self) def map(self, e=None): self._pageRaisedCB(self.notebook.getcurselection()) def unmap(self, e=None): self.mouseLabelingVar.set(True) self.mouseModeButton.invoke() def changeToLabel(self, nextLabel, force=False): if nextLabel == self.model.curLabel and not force: return if self.model.curLabel and not unicode(self.model.curLabel) \ and self.model.curLabel != nextLabel: # remove previous label if empty self.removeLabel(self.model.curLabel) self.model.changeToLabel(nextLabel) self.labelText.component('text').configure(state='normal') self.labelTable.select(nextLabel) self.labelText.settext(unicode(nextLabel)) text = self.labelText.component('text') lineIndex = 1 for line in self.model.curLabel.lines: charIndex = 0 for c in line: text.tag_add(id(c), "%d.%d" % (lineIndex, charIndex)) charIndex += 1 text.tag_add(id(line), "%d.%d" % (lineIndex, charIndex)) lineIndex += 1 def Delete(self): if self.notebook.getcurselection() == self.LABELS: self.labelText.clear() if not self.model.curLabel: self.status("No label to delete", color="red", blankAfter=10) return self.removeLabel(self.model.curLabel) self.labelText.component('text').configure( state='disabled') else: self.keyPosition = None self._keyChangeCB() def Help(self): helpLoc = "ContributedSoftware/2dlabels/2dlabels.html" if self.notebook.getcurselection() == self.COLOR_KEY: helpLoc += "#colorkey" chimera.help.display(helpLoc) def keyConfigure(self, data, pageChange=True): self._componentsCB(len(data), update=False) for datum, well, label in zip(data, self.wells, self.labels): color, text = datum well.showColor(color, doCallback=False) label.variable.set(text, invoke_callbacks=False) self._keyChangeCB() if pageChange: self.notebook.selectpage(self.COLOR_KEY) def makeChar(self, char, model): attrs = {} try: attrs['rgba'] = self.colorWell.rgba except AttributeError: # multi or None if model: attrs['rgba'] = model.rgba size = self.labelFontSize.get() if size is not None: attrs['size'] = size style = self.labelFontStyle.get() if style is not None: attrs['style'] = style fontName = self.labelFontTypeface.get() if fontName is not None: attrs['fontName'] = fontName return Character(char, **attrs) def newLabel(self, pos): label = self.model.newLabel(pos) self.labelTable.setData(self.model.labels) self.status("Mouse drag to reposition label", color=self.EmphasisColor) return label def removeLabel(self, label): self.model.removeLabel(label) self.labelTable.setData(self.model.labels) if self.model.curLabel is not None: self.labelTable.select(self.model.curLabel) def reverseKey(self): data = zip([w.rgba for w in self.wells], [l.variable.get() for l in self.labels]) data.reverse() self.keyConfigure(data) def setLabelFromText(self): curLabel = self.model.curLabel text = self.labelText.component('text') # delete parts of label not in text... # # newlines first... while len(curLabel.lines) > 1: for i, line in enumerate(curLabel.lines[:-1]): if not text.tag_ranges(id(line)): curLabel.lines[i+1][:0] = line del curLabel.lines[i] break else: break # characters... for line in curLabel.lines: for c in line[:]: if not text.tag_ranges(id(c)): line.remove(c) # get new parts of text into label model = None targets = [] lines = curLabel.lines for line in lines: targets.extend([id(c) for c in line]) if not model and line: model = line[0] if line is not lines[-1]: targets.append(id(line)) contents = self.labelText.get()[:-1] # drop trailing newline if targets: target = targets.pop(0) else: target = None textLine = 1 textIndex = -1 curLine = lines[0] for c in contents: textIndex += 1 if str(target) in text.tag_names("%d.%d" % (textLine, textIndex)): if targets: target = targets.pop(0) else: target = None if c == '\n': textLine += 1 textIndex = -1 curLine = lines[[id(l) for l in lines].index( id(curLine))+1] elif curLine: model = curLine[textIndex] elif c == '\n': insertLine = curLine[0:textIndex] lines.insert(textLine-1, insertLine) del curLine[0:textIndex] text.tag_add(id(insertLine), "%d.%d" % (textLine, textIndex)) textLine += 1 textIndex = -1 else: labelChar = self.makeChar(c, model) curLine.insert(textIndex, labelChar) text.tag_add(id(labelChar), "%d.%d" % (textLine, textIndex)) self.model.setMajorChange() def updateGUI(self, source="gui"): curLabel = self.model.curLabel if curLabel and source == "gui": self.setLabelFromText() self.labelTable.setData(self.model.labels) if curLabel: self.labelTable.select(curLabel) self._updateTextAttrWidgets() def _colorCB(self, color): curLabel = self.model.curLabel if not curLabel: self.status("No label to color", color='red') return self.model.setMajorChange() for c in self._selChars(): c.rgba = color def _componentsCB(self, opt, update=True): cf = self.componentsFrame if hasattr(self, 'wells'): for well in self.wells: well.grid_forget() well.destroy() for label in self.labels: label.frame.grid_forget() self.reverseButton.grid_forget() self.reverseButton.destroy() else: Tkinter.Label(cf, text="Colors").grid(row=0) Tkinter.Label(cf, text="Labels").grid(row=0, column=1) if isinstance(opt, int): numComponents = opt self.numComponents.set(opt) else: numComponents = opt.get() wellSize = min(38, int( (7 * 38) / numComponents )) from CGLtk.color.ColorWell import ColorWell self.wells = [] self.labels = [] from CGLtk import Hybrid for i in range(numComponents): well = ColorWell(cf, width=wellSize, height=wellSize, callback=self._keyChangeCB, color='white') well.grid(row=i+1) self.wells.append(well) label = Hybrid.Entry(cf, "", 10) label.variable.add_callback(self._keyTypingCB) label.frame.grid(row=i+1, column=1, sticky='ew') self.labels.append(label) self.reverseButton = Tkinter.Button(cf, command=self.reverseKey, text="Reverse ordering of above", pady=0) self.reverseButton.grid(row=numComponents+1, column=0, columnspan=2) self.notebook.setnaturalsize() if update: self._keyChangeCB() def _contrastWithBG(self): bg = chimera.viewer.background if bg: bgColor = bg.rgba() else: bgColor = (0, 0, 0) if bgColor[0]*2 + bgColor[1]*3 + bgColor[2] < 0.417: return (1, 1, 1) else: return (0, 0, 0) def _eventToPos(self, viewer, event, offset = (0, 0)): w, h = viewer.windowSize return (event.x - offset[0]) / float(w), \ (h - event.y - offset[1]) / float(h) def _handleTextChange(self): self.updateGUI() self.labelText.edit_modified(False) def _insertSymbol(self, item): if len(item) > 1: from chimera import help help.display("ContributedSoftware/2dlabels/symbols.html") return if not self.model.labels: self.status("No labels have been created yet", color="red") return if not self.labelTable.selected(): self.status("No labels active", color="red") self.labelText.insert("insert", item) self.setLabelFromText() def _keyChangeCB(self, *args): self.keyModel.setMajorChange() def _keyTypingCB(self, fromAfter=False): # wait for a pause in typing before updating key... if fromAfter: self._typingHandler = None self._keyChangeCB() return handle = getattr(self, '_typingHandler', None) if handle: self.componentsFrame.after_cancel(handle) self._typingHandler = self.componentsFrame.after(500, lambda: self._keyTypingCB(fromAfter=True)) def _labelChangeCB(self, option): curLabel = self.model.curLabel self.model.setMajorChange() val = option.get() attrName = option.attribute for c in self._selChars(): setattr(c, attrName, val) def _labelListing(self, label): text = unicode(label) if '\n' in text: newline = text.index('\n') text= text[:newline] + "..." if not text: text = "<empty>" return "(%.2f, %.2f) %s" % (label.pos[0], label.pos[1], text) def _mouseFuncCB(self): self.status("") if not self.mouseLabelingVar.get(): if hasattr(self, "_prevMouse"): setButtonFunction("1", (), self._prevMouse) delattr(self, "_prevMouse") elif self.mlLabelVar.get() == self.MOUSE_LABEL_TEXT: if not hasattr(self, "_prevMouse"): self._prevMouse = getFuncName("1", ()) setButtonFunction("1", (), "place text") else: if not hasattr(self, "_prevMouse"): self._prevMouse = getFuncName("1", ()) setButtonFunction("1", (), "place key") def _moveLabel(self, viewer, event): pos = self._eventToPos(viewer, event, self._moveOffset) self.model.moveLabel(pos) curLabel = self.model.curLabel self.labelTable.setData(self.model.labels) self.labelTable.select(curLabel) def _pageRaisedCB(self, pageName): if pageName == "Labels": pageItem = self.MOUSE_LABEL_TEXT if not self.model.labels: self.status("Click mouse button 1 in graphics\n" "window to place first label", color=self.EmphasisColor) for index in range(0, self.fileMenu.index('end')+1): self.fileMenu.entryconfigure(index, state='normal') else: pageItem = self.MOUSE_KEY_TEXT self.status("Drag mouse to position/size key", color=self.EmphasisColor) for index in range(0, self.fileMenu.index('end')+1): self.fileMenu.entryconfigure(index, state='disabled') self.mlLabelVar.set(pageItem) # just setting the var doesn't cause the callback, and # yet using invoke() toggles the var, so set it _opposite_ # to what's desired before calling invoke() self.mouseLabelingVar.set(False) self.mouseModeButton.invoke() def _pickLabel(self, viewer, event): w, h = viewer.windowSize pos = self._eventToPos(viewer, event) label, self._moveOffset = self.model.pickLabel(pos, w, h) if label is None: label = self.newLabel(pos) self._moveOffset = (0, 0) self.changeToLabel(label) self.labelText.component('text').focus_set() def _readFile(self, okayed, dialog): if not okayed: return from Ilabel import readFiles readFiles(dialog.getPaths(), clear=dialog.deleteExistingVar.get()) def _readFileCB(self): if not hasattr(self, "_readFileDialog"): self._readFileDialog = ReadFileDialog( command=self._readFile, clientPos='s') self._readFileDialog.enter() def _restoreSession(self, info): if info["sel ranges"]: self.labelText.tag_add("sel", *info["sel ranges"]) self._updateTextAttrWidgets() self._suppressMap = True self.labelText.edit_modified(False) if "key position" not in info: self.notebook.selectpage(self.LABELS) if info["mouse func"] == "normal": self.mouseLabelingVar.set(True) self.mouseModeButton.invoke() return self.keyPosition = info["key position"] self.colorTreatment.set(info["color depiction"]) self.labelPos.set(info["label positions"]) self.labelColor.set(info["label color"]) self.justification.set(info["label justification"]) self.labelOffset.set(info["label offset"]) self.keyFontSize.set(info["font size"]) self.keyFontStyle.set(info["font typeface"]) if "font name" in info: self.keyFontTypeface.set(info["font name"]) self.borderColor.set(info["border color"]) self.borderWidth.set(info["border width"]) self.tickMarks.set(info["show ticks"]) self.keyConfigure(info["colors/labels"]) if self.keyPosition: self.notebook.selectpage(self.COLOR_KEY) else: self.notebook.selectpage(self.LABELS) if info["mouse func"] == "normal": self.mouseLabelingVar.set(True) self.mouseModeButton.invoke() return info def _saveSession(self, triggerName, myData, sessionFile): print>>sessionFile, """ def restore2DLabelDialog(info): from chimera.dialogs import find, display from Ilabel.gui import IlabelDialog dlg = find(IlabelDialog.name) if dlg is not None: dlg.destroy() dlg = display(IlabelDialog.name) dlg._restoreSession(info) import SimpleSession SimpleSession.registerAfterModelsCB(restore2DLabelDialog, %s) """ % repr(self._sessionInfo()) def _selChars(self): chars = [] curLabel = self.model.curLabel if curLabel: sel = self.labelText.tag_ranges("sel") if sel: sline, schar = [int(x) for x in str(sel[0]).split('.')] eline, echar = [int(x) for x in str(sel[1]).split('.')] sline -= 1 eline -= 1 for li, line in enumerate(curLabel.lines): if li < sline: continue if li > eline: break if sline == eline: chars.extend(line[schar:echar]) elif li == sline: chars.extend(line[schar:]) elif li == eline: chars.extend(line[:echar]) else: chars.extend(line) else: for l in curLabel.lines: chars.extend(l) return chars def _sessionInfo(self): info = {} info["sel ranges"] = tuple([str(tr) for tr in self.labelText.tag_ranges("sel")]) if self.mouseLabelingVar.get(): info["mouse func"] = "labeling" else: info["mouse func"] = "normal" info["key position"] = self.keyPosition info["colors/labels"] = [(w.rgba, l.variable.get()) for w, l in zip(self.wells, self.labels)] info["color depiction"] = self.colorTreatment.get() info["label positions"] = self.labelPos.get() info["label color"] = self.labelColor.get() info["label justification"] = self.justification.get() info["label offset"] = self.labelOffset.get() info["font size"] = self.keyFontSize.get() info["font typeface"] = self.keyFontStyle.get() info["font name"] = self.keyFontTypeface.get() info["border color"] = self.borderColor.get() info["border width"] = self.borderWidth.get() info["show ticks"] = self.tickMarks.get() return info def _sizeOrMoveKey(self, viewer, event): pos = self._eventToPos(viewer, event) if self.grabPos: deltas = [pos[axis] - self.grabPos[axis] for axis in [0, 1]] for posIndex in [0, 1]: old = self.keyPosition[posIndex] self.keyPosition[posIndex] = ( old[0] + deltas[0], old[1] + deltas[1]) self.grabPos = pos elif len(self.keyPosition) == 1: self.keyPosition.append(pos) else: self.keyPosition[1] = pos self._keyChangeCB() def _startOrGrabKey(self, viewer, event): pos = self._eventToPos(viewer, event) if self.keyPosition and len(self.keyPosition) == 2: # possible grab; # see if in middle third of long side... p1, p2 = self.keyPosition x1, y1 = p1 x2, y2 = p2 if abs(x2 - x1) < abs(y2 - y1): longAxis = 1 ymin = min(y2, y1) ymax = max(y2, y1) b1 = (2* ymin + ymax) / 3.0 b2 = (2* ymax + ymin) / 3.0 o1 = min(x1, x2) o2 = max(x1, x2) else: longAxis = 0 xmin = min(x2, x1) xmax = max(x2, x1) b1 = (2* xmin + xmax) / 3.0 b2 = (2* xmax + xmin) / 3.0 o1 = min(y1, y2) o2 = max(y1, y2) if b1 < pos[longAxis] < b2 \ and o1 < pos[1-longAxis] < o2: self.grabPos = pos return self.grabPos = None self.keyPosition = [pos] self._keyChangeCB() self.status("Grab middle of key to reposition", color=self.EmphasisColor) def _tableCB(self, sel): if not sel: return self.changeToLabel(sel) def _textCB(self, e): text = self.labelText.component('text') if not text.tk.call((text._w, 'edit', 'modified')): #if not text.edit_modified(): return # this callback can happen _before_ the change # actually occurs, so do the processing after idle text.after_idle(self._handleTextChange) def _updateTextAttrWidgets(self, e=None): rgba = None multiple = False for c in self._selChars(): if rgba is None: rgba = c.rgba elif rgba != c.rgba: multiple = True break if rgba is not None: self.colorWell.showColor(rgba, multiple=multiple, doCallback=False) self.labelFontSize.display(self._selChars()) self.labelFontStyle.display(self._selChars()) self.labelFontTypeface.display(self._selChars()) def _writeFile(self, okayed, dialog): if not okayed: return from Ilabel import writeFile writeFile(dialog.getPaths()[0]) def _writeFileCB(self): if not hasattr(self, "_writeFileDialog"): from OpenSave import SaveModeless self._writeFileDialog = SaveModeless(command=self._writeFile, title="Write 2D Labels Info") self._writeFileDialog.enter()
def __init__(self): SaveModeless.__init__(self, command=_saveCB, filters=[("Chimera session", ["*.py"], ".py")], historyID="SimpleSession", compressed=True)
def fillInUI(self, parent): SaveModeless.fillInUI(self, parent) row = 0 from chimera.widgets import MoleculeScrolledListBox, \ ModelOptionMenu self.modelList = MoleculeScrolledListBox(self.clientArea, labelpos='w', label_text="Save models:", listbox_selectmode='extended', selectioncommand=lambda: self.configure( self.modelList.getvalue(), refreshList=False)) self.modelList.grid(row=row, column=0, sticky='nsew') self.clientArea.rowconfigure(row, weight=1) self.clientArea.columnconfigure(0, weight=1) row += 1 import Tkinter, Pmw self.dispOnlyVar = Tkinter.IntVar(parent) self.dispOnlyVar.set(False) Tkinter.Checkbutton(self.clientArea, variable=self.dispOnlyVar, text="Save displayed atoms only").grid(row=row, column=0, sticky='w') row += 1 self.selOnlyVar = Tkinter.IntVar(parent) self.selOnlyVar.set(False) Tkinter.Checkbutton(self.clientArea, variable=self.selOnlyVar, text="Save selected atoms only").grid(row=row, column=0, sticky='w') row += 1 self.saveRelativeVar = Tkinter.IntVar(parent) self.saveRelativeVar.set(False) self.relativeFrame = f = Tkinter.Frame(self.clientArea) Tkinter.Checkbutton(f, variable=self.saveRelativeVar, text="Save relative to model:" ).grid(row=0, column=0, sticky='e') self.relModelMenu = ModelOptionMenu(f) self.relModelMenu.grid(row=0, column=1, sticky='w') self.saveUntransformedVar = Tkinter.IntVar(parent) self.saveUntransformedVar.set(True) self.untransformedButton = Tkinter.Checkbutton(self.clientArea, variable=self.saveUntransformedVar, text="Use untransformed coordinates") self._rfRow = row row += 1 self.frameSave = Pmw.OptionMenu(self.clientArea, labelpos='w', label_text="Save", initialitem="current frame", items=["current frame", "all frames"]) # not always shown; remember row number self._fsRow = row row += 1 from chimera import dialogs self.labelMap = { "single": "a single file", "multiple": "multiple files [appending model number]" } preferred = self.labelMap[self.prefs["multiSavePDB"]] self.multiSaveMenu = Pmw.OptionMenu(self.clientArea, labelpos='w', label_text="Save multiple models in", initialitem=preferred, items=self.labelMap.values()) # not always shown; remember row number self._msmRow = row row += 1
def __init__(self, mav): self.mav = mav self.title = "Save Association Info of %s" % mav.title defaultFile = os.path.splitext(self.mav.title or "alignment")[0] SaveModeless.__init__(self, clientPos='s', initialfile=defaultFile+".asc")
def fillInUI(self, parent): SaveModeless.fillInUI(self, parent) from chimera.tkoptions import NamingStyleOption self.namingStyle = NamingStyleOption(self.clientArea, 0, None, None, None)
def __init__(self, info, callback, **kw): self.info = info self.callback = callback SaveModeless.__init__(self, clientPos='s', **kw)
def __init__(self): SaveModeless.__init__(self, clientPos='s', clientSticky='ewns', filters=[("DMS", "*.dms", ".dms")])
def __init__(self): SaveModeless.__init__(self, clientPos='s', clientSticky='ewns', filters=[("Prmtop", "*.prmtop", ".prmtop")])
def fillInUI(self, parent): SaveModeless.fillInUI(self, parent) self.clientArea.columnconfigure(1, weight=1) startFrame = self.movie.startFrame endFrame = self.movie.endFrame from chimera.tkoptions import IntOption, BooleanOption, \ FloatOption, StringOption self.startFrame = IntOption(self.clientArea, 0, "Starting frame", startFrame, None, min=startFrame, max=endFrame, width=6) numFrames = endFrame - startFrame + 1 defStride = 1 + int(numFrames/300) self.stride = IntOption(self.clientArea, 2, "Step size", defStride, None, min=1, max=numFrames, width=3) self.endFrame = IntOption(self.clientArea, 3, "Ending frame", endFrame, None, min=startFrame, max=endFrame, width=6) self.roundtrip = BooleanOption(self.clientArea, 4, "Encode" ' forward then backward ("roundtrip")', prefs[ RECORDER_ROUNDTRIP], None, balloon= "Encode the frames in forward and then reverse\n" "order so that if the movie is played as a loop\n" "the motion seems continuous") class FrameQuality(BooleanOption): labels = ["screen", "supersampled"] self.supersample = FrameQuality(self.clientArea, 5, "Frame quality", prefs[RECORDER_SUPERSAMPLE], self.supersampleCB, balloon= "Whether each frame should be taken as is from\n" "the screen (fast) or redrawn at higher quality\n" "with several samples per pixel.") from chimera.printer import SupersampleOption self.samples = SupersampleOption(self.clientArea, 6, "Samples", prefs[RECORDER_SAMPLES], None) self.supersampleCB() self.raytrace = BooleanOption(self.clientArea, 7, "Raytrace" " with POV-Ray", prefs[RECORDER_RAYTRACE], None) def povOptCB(): from chimera.dialogs import display d = display("preferences") from chimera.printer import POVRAY_SETUP d.setCategoryMenu(POVRAY_SETUP) Tkinter.Button(self.clientArea, text="POV-Ray Options", pady=0, command=povOptCB).grid(row=8, column=0, columnspan=2) self.recordArgs = StringOption(self.clientArea, 9, "Additional recording options", prefs[RECORDER_RECORD_ARGS], None, balloon= "Options (other than 'supersample' and 'raytrace')\n" "for recording frames as per Chimera's 'movie record'" " command") self.encodeArgs = StringOption(self.clientArea, 10, "Additional encoding options", prefs[RECORDER_ENCODE_ARGS], None, balloon= "Options (other than 'mformat', 'output', and\n" "'roundtrip') for composing the frames into the\n" "final animation as per Chimera's 'movie encode'\n" "command") Tkinter.Label(self.clientArea, text= "On some computers it may be necessary to make sure" " that no\nwindows occlude the main Chimera graphics" " window (even\npartially) during non-raytraced movie" " recording").grid(row=11, column=0, columnspan=2)