def updatePeakListTable(self): textMatrix = [] windowPeakLists = [] windowPane = self.windowPulldown.getObject() if windowPane: # Note that windowPane.sortedSpectrumWindowViews() does not sort # consistently from one instantation to the next nor does # spectrumWindowView.sortedWindowPeakLists() so do it by hand for spectrumWindowView in windowPane.spectrumWindowViews: windowPeakLists.extend(spectrumWindowView.windowPeakLists) tt = [(x.analysisPeakList.peakList, x) for x in windowPeakLists] tt.sort() windowPeakLists = [x[1] for x in tt] for windowPeakList in windowPeakLists: analysisPeakList = windowPeakList.analysisPeakList peakList = analysisPeakList.peakList spectrum = peakList.dataSource experiment = spectrum.experiment text = [] text.append('%s:%s:%s' % (experiment.name, spectrum.name, peakList.serial)) peaksOn = PrintBasic.getPrintOption(windowPeakList, 'PeaksOn', windowPeakList.isSymbolDrawn) text.append(peaksOn and 'Yes' or 'No') if windowPeakList.isAnnotationDrawn: default = analysisPeakList.analysisSpectrum.font else: default = no_peak_text text.append(PrintBasic.getPrintOption(windowPeakList, 'PeakFont', default)) textMatrix.append(text) self.peakListTable.update(objectList=windowPeakLists, textMatrix=textMatrix)
def setNegColor(self, *extra): spectrumWindowView = self.spectrumTable.currentObject if spectrumWindowView: analysisSpec = spectrumWindowView.analysisSpectrum PrintBasic.setPrintOption(analysisSpec, 'NegativeColors', self.negColorPulldown.getObject().colors) self.updateSpectrumTable()
def updateSpectrumTable(self): textMatrix = [] spectrumWindowViews = [] windowPane = self.windowPulldown.getObject() if windowPane: # Note that windowPane.sortedSpectrumWindowViews() does not sort # consistently from one instantation to the next so do it by hand spectrumWindowViews = windowPane.spectrumWindowViews tt = [(x.analysisSpectrum.dataSource, x) for x in spectrumWindowViews] tt.sort() spectrumWindowViews = [x[1] for x in tt] for spectrumWindowView in spectrumWindowViews: analysisSpectrum = spectrumWindowView.analysisSpectrum spectrum = analysisSpectrum.dataSource experiment = spectrum.experiment text = [] text.append('%s:%s' % (experiment.name, spectrum.name)) positiveOn = PrintBasic.getPrintOption(spectrumWindowView, 'PositiveOn', spectrumWindowView.isPosVisible) text.append(positiveOn and 'Yes' or 'No') negativeOn = PrintBasic.getPrintOption(spectrumWindowView, 'NegativeOn', spectrumWindowView.isNegVisible) text.append(negativeOn and 'Yes' or 'No') textMatrix.append(text) self.spectrumTable.update(objectList=spectrumWindowViews, textMatrix=textMatrix)
def resetPeakList(self): windowPeakLists = self.peakListTable.currentObjects for windowPeakList in windowPeakLists: PrintBasic.setPrintOption(windowPeakList, 'PeaksOn', windowPeakList.isSymbolDrawn) PrintBasic.setPrintOption(windowPeakList, 'PeakFont', windowPeakList.spectrumWindowView.analysisSpectrum.font) self.updateAfter()
def resetSpectrum(self): spectrumWindowViews = self.spectrumTable.currentObjects for spectrumWindowView in spectrumWindowViews: PrintBasic.setPrintOption(spectrumWindowView, 'PositiveOn', spectrumWindowView.isPosVisible) PrintBasic.setPrintOption(spectrumWindowView, 'NegativeOn', spectrumWindowView.isNegVisible) self.updateAfter()
def setPeakColor(self, *extra): windowPeakList = self.peakListTable.currentObject if windowPeakList: color = self.peakColorPulldown.getObject() scheme = self.analysisProfile.findFirstColorScheme(colors=(color,)) if scheme: color = scheme.name analysisPeakList = windowPeakList.analysisPeakList PrintBasic.setPrintOption(analysisPeakList, 'PeakColor', color) self.updatePeakListTable()
def getPeakFont(self, windowPeakList): if windowPeakList.isAnnotationDrawn: default = windowPeakList.analysisPeakList.analysisSpectrum.font else: default = no_peak_text font = PrintBasic.getPrintOption(windowPeakList, 'PeakFont', defaultValue=default) self.fontMenu.set(font)
def resetSpectrum(self): spectrumWindowViews = self.spectrumTable.currentObjects analysisSpectra = set() for spectrumWindowView in spectrumWindowViews: PrintBasic.setPrintOption(spectrumWindowView, 'PositiveOn', spectrumWindowView.isPosVisible) PrintBasic.setPrintOption(spectrumWindowView, 'NegativeOn', spectrumWindowView.isNegVisible) analysisSpectra.add(spectrumWindowView.analysisSpectrum) for analysisSpectrum in analysisSpectra: PrintBasic.setPrintOption(analysisSpectrum, 'PositiveColors', analysisSpectrum.posColors) PrintBasic.setPrintOption(analysisSpectrum, 'NegativeColors', analysisSpectrum.negColors) self.updateAfter()
def getNegColor(self, spectrumWindowView): schemes = getHueSortedColorSchemes(self.analysisProfile) names = [s.name for s in schemes] colors = [list(s.colors) for s in schemes] index = 0 analysisSpec = spectrumWindowView.analysisSpectrum negColors = list(PrintBasic.getPrintOption(analysisSpec, 'NegativeColors', defaultValue=analysisSpec.negColors)) if negColors in colors: index = colors.index(negColors) self.negColorPulldown.setup(names, schemes, index, colors)
def resetPeakList(self): windowPeakLists = self.peakListTable.currentObjects analysisPeakLists = set() for windowPeakList in windowPeakLists: PrintBasic.setPrintOption(windowPeakList, 'PeaksOn', windowPeakList.isSymbolDrawn) PrintBasic.setPrintOption(windowPeakList, 'PeakFont', windowPeakList.spectrumWindowView.analysisSpectrum.font) analysisPeakLists.add(windowPeakList.analysisPeakList) for analysisPeakList in analysisPeakLists: PrintBasic.setPrintOption(analysisPeakList, 'PeakColor', analysisPeakList.symbolColor) self.updateAfter()
def saveFile(self): windowPane = self.windowPulldown.getObject() if not windowPane: return axisPanels = windowPane.sortedAxisPanels() aspectRatio = self.getPrintAspectRatio() pixelWidth = self.totalSize(axisPanels[0]) pixelHeight = aspectRatio*self.totalSize(axisPanels[1]) unitWidth = self.totalOverrideRegion(axisPanels[0]) unitHeight = self.totalOverrideRegion(axisPanels[1]) printFrame = self.printFrame isOverrideSpectrumSelected = self.overrideSpectrum.isSelected() if isOverrideSpectrumSelected: spectrumWindowViews = self.spectrumTable.objectList # alternatively, spectrumWindowViews = windowPane.spectrumWindowViews analysisSpectra = set() for spectrumWindowView in spectrumWindowViews: spectrumWindowView.printPositive = PrintBasic.getPrintOption(spectrumWindowView, 'PositiveOn', spectrumWindowView.isPosVisible) spectrumWindowView.printNegative = PrintBasic.getPrintOption(spectrumWindowView, 'NegativeOn', spectrumWindowView.isNegVisible) analysisSpectra.add(spectrumWindowView.analysisSpectrum) for analysisSpectrum in analysisSpectra: analysisSpectrum.printPositiveColors = PrintBasic.getPrintOption(analysisSpectrum, 'PositiveColors', analysisSpectrum.posColors) analysisSpectrum.printNegativeColors = PrintBasic.getPrintOption(analysisSpectrum, 'NegativeColors', analysisSpectrum.negColors) isOverridePeakListSelected = self.overridePeakList.isSelected() if isOverridePeakListSelected: windowPeakLists = self.peakListTable.objectList analysisPeakLists = set() for windowPeakList in windowPeakLists: windowPeakList.printPeaks = PrintBasic.getPrintOption(windowPeakList, 'PeaksOn', windowPeakList.isSymbolDrawn) if windowPeakList.isAnnotationDrawn: default = windowPeakList.analysisPeakList.analysisSpectrum.font else: default = no_peak_text windowPeakList.printFont = PrintBasic.getPrintOption(windowPeakList, 'PeakFont', default) analysisPeakLists.add(windowPeakList.analysisPeakList) for analysisPeakList in analysisPeakLists: analysisPeakList.printColor = PrintBasic.getPrintOption(analysisPeakList, 'PeakColor', analysisPeakList.symbolColor) xrr = axisPanels[0].findFirstAxisRegion().region dxx = abs(xrr[0]-xrr[1]) yrr = axisPanels[1].findFirstAxisRegion().region dyy = abs(yrr[0]-yrr[1]) try: outputHandler = printFrame.getOutputHandler(pixelWidth, pixelHeight, unitWidth, unitHeight, fonts=printNames) if not outputHandler: return analysisProject = self.analysisProject major_minor_dict = {} spacing_choice = PrintBasic.getPrintOption(analysisProject, 'SpacingChoice', spacing_choices[0]) if spacing_choice != spacing_choices[0]: for attr in ('XMajor', 'XMinor', 'XDecimal', 'YMajor', 'YMinor', 'YDecimal',): val = PrintBasic.getPrintOption(analysisProject, attr, None) if val is not None: major_minor_dict[attr] = val tick_length_choice = PrintBasic.getPrintOption(analysisProject, 'TickLengthChoice', tick_length_choices[0]) if tick_length_choice != tick_length_choices[0]: for attr in ('TickMajor', 'TickMinor'): val = PrintBasic.getPrintOption(analysisProject, attr, None) if val is not None: major_minor_dict[attr] = val windowDraw = WindowDraw(self.parent, windowPane) PrintBasic.printWindow(windowDraw, outputHandler, printFrame.tick_location, printFrame.tick_placement, aspectRatio, printFrame.tick_font, major_minor_dict) msg = 'Saved to file "%s"' % printFrame.file_name showInfo('Success', msg, parent=self) except IOError, e: showError('IO Error', str(e), parent=self)
def setPeakFont(self, windowPeakList): PrintBasic.setPrintOption(windowPeakList, 'PeakFont', self.fontMenu.getText()) self.updateAfter()
def togglePeaks(self, windowPeakList): PrintBasic.setPrintOption(windowPeakList, 'PeaksOn', not PrintBasic.getPrintOption(windowPeakList, 'PeaksOn', defaultValue=windowPeakList.isSymbolDrawn)) self.updateAfter()
def toggleNeg(self, spectrumWindowView): PrintBasic.setPrintOption(spectrumWindowView, 'NegativeOn', not PrintBasic.getPrintOption(spectrumWindowView, 'NegativeOn', defaultValue=spectrumWindowView.isNegVisible)) self.updateAfter()
def togglePos(self, spectrumWindowView): PrintBasic.setPrintOption(spectrumWindowView, 'PositiveOn', not PrintBasic.getPrintOption(spectrumWindowView, 'PositiveOn', defaultValue=spectrumWindowView.isPosVisible)) self.updateAfter()
def body(self, guiFrame): self.geometry('600x350') project = self.project analysisProject = self.analysisProject guiFrame.grid_columnconfigure(1, weight=1) row = 0 frame = Frame(guiFrame, grid=(0,0)) label = Label(frame, text=' Window:', grid=(0,0)) self.windowPulldown = PulldownList(frame, grid=(0,1), tipText='The window that will be printed out', callback=self.selectWindow) tipTexts = ['For the window pulldown, show all of the spectrum windows in the current project, irrespective of the active group', 'For the window pulldown, show only spectrum windows that are in the currently active window group'] self.whichWindows = RadioButtons(frame, grid=(0,2), entries=ACTIVE_OPTIONS, tipTexts=tipTexts, select_callback=self.updateWindows) texts = [ 'Save Print File' ] tipTexts = [ 'Save the printout to the specified file' ] commands = [ self.saveFile ] buttons = UtilityButtonList(guiFrame, helpUrl=self.help_url, grid=(row,2), commands=commands, texts=texts, tipTexts=tipTexts) self.buttons = buttons buttons.buttons[0].config(bg='#B0FFB0') row += 1 guiFrame.grid_rowconfigure(row, weight=1) options = ['Options', 'Spectra', 'Peak Lists', 'Region'] tipTexts = ['Optional settings for spectra', 'Optional settings for peak lists', 'Optional settings for the region'] tabbedFrame = TabbedFrame(guiFrame, options=options, tipTexts=tipTexts) tabbedFrame.grid(row=row, column=0, columnspan=3, sticky='nsew') self.tabbedFrame = tabbedFrame optionFrame, spectrumFrame, peakListFrame, regionFrame = tabbedFrame.frames optionFrame.expandGrid(0, 0) getOption = lambda key, defaultValue: PrintBasic.getPrintOption(analysisProject, key, defaultValue) setOption = lambda key, value: PrintBasic.setPrintOption(analysisProject, key, value) self.printFrame = PrintFrame(optionFrame, getOption=getOption, grid=(0,0), gridSpan=(1,1), setOption=setOption, haveTicks=True, doOutlineBox=False) spectrumFrame.expandGrid(0, 0) frame = Frame(spectrumFrame, grid=(0,0), gridSpan=(1,1)) frame.expandGrid(1,0) self.overrideSpectrum = CheckButton(frame, text='Use below settings when printing', tipText='Use below settings when printing instead of the window values', grid=(0,0), sticky='w') tipText = 'Change the settings of the selected spectra back to their window values' button = Button(frame, text='Reset Selected', tipText=tipText, command=self.resetSelected, grid=(0,1), sticky='e') self.posColorPulldown = PulldownList(self, callback=self.setPosColor) self.negColorPulldown = PulldownList(self, callback=self.setNegColor) headings = ['Spectrum', 'Pos. Contours\nDrawn', 'Neg. Contours\nDrawn', 'Positive\nColours', 'Negative\nColours'] tipTexts = ['Spectrum in window', 'Whether the positive contours should be drawn', 'Whether the negative contours should be drawn', 'Colour scheme for positive contours (can be a single colour)', 'Colour scheme for negative contours (can be a single colour)'] editWidgets = [ None, None, None, self.posColorPulldown, self.negColorPulldown] editGetCallbacks = [ None, self.togglePos, self.toggleNeg, self.getPosColor, self.getNegColor] editSetCallbacks = [ None, None, None, self.setPosColor, self.setNegColor] self.spectrumTable = ScrolledMatrix(frame, headingList=headings, tipTexts=tipTexts, multiSelect=True, editWidgets=editWidgets, editGetCallbacks=editGetCallbacks, editSetCallbacks=editSetCallbacks, grid=(1,0), gridSpan=(1,2)) peakListFrame.expandGrid(0, 0) frame = Frame(peakListFrame, grid=(0,0), gridSpan=(1,3)) frame.expandGrid(1,0) self.overridePeakList = CheckButton(frame, text='Use below settings when printing', tipText='Use below settings when printing instead of the window values', grid=(0,0)) tipText = 'Change the settings of the selected peak lists back to their window values' button = Button(frame, text='Reset Selected', tipText=tipText, command=self.resetSelected, grid=(0,1), sticky='e') colors = Color.standardColors self.peakColorPulldown = PulldownList(self, callback=self.setPeakColor, texts=[c.name for c in colors], objects=[c.hex for c in colors], colors=[c.hex for c in colors]) headings = [ 'Peak List', 'Symbols Drawn', 'Peak Font', 'Peak Colour'] self.fontMenu = FontList(self, mode='Print', extraTexts=[no_peak_text]) editWidgets = [ None, None, self.fontMenu, self.peakColorPulldown] editGetCallbacks = [ None, self.togglePeaks, self.getPeakFont, self.getPeakColor ] editSetCallbacks = [ None, None, self.setPeakFont, self.setPeakColor ] self.peakListTable = ScrolledMatrix(frame, headingList=headings, multiSelect=True, editWidgets=editWidgets, editGetCallbacks=editGetCallbacks, editSetCallbacks=editSetCallbacks, grid=(1,0), gridSpan=(1,2)) regionFrame.expandGrid(0, 0) frame = Frame(regionFrame, grid=(0,0), gridSpan=(1,3)) frame.expandGrid(3,0) tipText = 'Use the specified override region when printing rather than the window values' self.overrideButton = CheckButton(frame, text='Use override region when printing', tipText=tipText, callback=self.toggledOverride, grid=(0,0)) tipTexts = ('Use min and max to specify override region', 'Use center and width to specify override region') self.use_entry = USE_ENTRIES[0] self.useButtons = RadioButtons(frame, entries=USE_ENTRIES, tipTexts=tipTexts, select_callback=self.changedUseEntry, grid=(1,0)) texts = ('Set Region from Window', 'Set Center from Window', 'Set Width from Window') tipTexts = ('Set the override region to be the current window region', 'Set the center of the override region to be the center of the current window region', 'Set the width of the override region to be the width of the current window region') commands = (self.setRegionFromWindow, self.setCenterFromWindow, self.setWidthFromWindow) self.setRegionButton = ButtonList(frame, texts=texts, tipTexts=tipTexts, commands=commands, grid=(2,0)) self.minRegionWidget = FloatEntry(self, returnCallback=self.setMinRegion, width=10) self.maxRegionWidget = FloatEntry(self, returnCallback=self.setMaxRegion, width=10) headings = MIN_MAX_HEADINGS editWidgets = [ None, None, self.minRegionWidget, self.maxRegionWidget ] editGetCallbacks = [ None, None, self.getMinRegion, self.getMaxRegion ] editSetCallbacks = [ None, None, self.setMinRegion, self.setMaxRegion ] self.regionTable = RegionScrolledMatrix(frame, headingList=headings, editWidgets=editWidgets, editGetCallbacks=editGetCallbacks, editSetCallbacks=editSetCallbacks, grid=(3,0)) self.updateWindows() self.updateAfter() self.administerNotifiers(self.registerNotify)