Beispiel #1
0
  def __init__(self, parent, analysis, orientation='horizontal', callback = None, *args, **kw):

    self.analysis = analysis
    self.callback = callback

    apply(Frame.__init__, (self, parent) + args, kw)

    label = Label(self, text='Experiment:')
    label.grid(row=0, column=0, sticky='ne')
    self.expt_list = ExperimentList(self, self.analysis.getExperiments,
                                    callback=self.setSpectra)
    self.expt_list.grid(row=0, column=1, sticky='nw')
 
    if orientation in ['horizontal','h','H',Tkinter.HORIZONTAL]:
      row = 0
      col = 2
    else:
      row = 1
      col = 0
    
    label = Label(self, text='Spectrum:')
    label.grid(row=row, column=col, sticky='ne')
    self.spectrum_list = SpectrumList(self, self.getSpectra,
                                      callback=self.setSpectrumProperties)
    self.spectrum_list.grid(row=row, column=col+1, sticky='nw')

    for func in notify_funcs:
      Implementation.registerNotify(self.setExperiments, 'ccp.nmr.Nmr.Experiment', func)
      Implementation.registerNotify(self.setSpectra, 'ccp.nmr.Nmr.DataSource', func)
Beispiel #2
0
    def unregisterNotify(self,
                         notify,
                         classname,
                         funcname='',
                         application=None,
                         keyword=None,
                         modifyList=True):

        if application is None:
            application = self.application

        if modifyList:
            if application is None:
                key = funcname
            else:
                key = (funcname, application, keyword)
            try:
                cc = self.notifies[classname]
                ff = cc[key]
                ff.remove(notify)
                if not ff:
                    del cc[key]
                if not cc:
                    del self.notifies[classname]
            except:  # already been unregistered
                pass

        if self.application:
            self.application.unregisterNotify(notify, classname, funcname,
                                              keyword)
        elif application:
            Application.unregisterNotify(notify, classname, funcname,
                                         application, keyword)
        else:
            Implementation.unregisterNotify(notify, classname, funcname)
Beispiel #3
0
    def registerNotify(self,
                       notify,
                       classname,
                       funcname='',
                       application=None,
                       keyword=None,
                       modifyList=True):

        if application is None:
            application = self.application

        if self.application:
            self.application.registerNotify(notify, classname, funcname,
                                            keyword)
        elif application:
            Application.registerNotify(notify, classname, funcname,
                                       application, keyword)
        else:
            Implementation.registerNotify(notify, classname, funcname)

        if modifyList:
            cc = self.notifies.get(classname)
            if cc is None:
                cc = self.notifies[classname] = {}
            if application is None:
                key = funcname
            else:
                key = (funcname, application, keyword)
            ff = cc.get(key)
            if ff is None:
                ff = cc[key] = []
            ff.append(notify)
  def destroy(self):

    for func in ('__init__','delete'):
      Implementation.unregisterNotify(self.updateMolSystems, 'ccp.molecule.MolSystem.MolSystem', func)
      Implementation.unregisterNotify(self.updateChains, 'ccp.molecule.MolSystem.Chain', func)

    BasePopup.destroy(self)
Beispiel #5
0
    def destroy(self):

        for func in notify_funcs:
            Implementation.unregisterNotify(self.setAxisLabels,
                                            'ccpnmr.Analysis.AxisPanel', func)

        PulldownMenu.destroy(self)
Beispiel #6
0
    def destroy(self):

        for func in notify_funcs:
            Implementation.unregisterNotify(self.setExperiments,
                                            'ccp.nmr.Nmr.Experiment', func)

        PulldownMenu.destroy(self)
Beispiel #7
0
    def destroy(self):

        for func in notify_funcs:
            Implementation.unregisterNotify(self.setAxisTypes,
                                            'ccpnmr.Analysis.AxisType', func)

        ScrolledListbox.destroy(self)
Beispiel #8
0
    def destroy(self):

        for func in notify_funcs:
            Implementation.unregisterNotify(self.setColors,
                                            'ccpnmr.Analysis.Color', func)

        PulldownList.destroy(self)
Beispiel #9
0
    def destroy(self):

        #print 'PanelTypeList destroy'
        for func in notify_funcs:
            Implementation.unregisterNotify(self.setPanelTypes,
                                            'ccpnmr.Analysis.PanelType', func)

        PulldownMenu.destroy(self)
Beispiel #10
0
  def __init__(self, parent, getAxisUnits, *args, **kw):
 
    self.getAxisUnits = getAxisUnits
 
    PulldownMenu.__init__(self, parent, *args, **kw)
 
    for func in notify_funcs:
      Implementation.registerNotify(self.setAxisUnits, 'ccpnmr.Analysis.AxisUnit', func)
Beispiel #11
0
  def __init__(self, parent, getAxisUnits):
 
    self.getAxisUnits = getAxisUnits
 
    ScrolledListbox.__init__(self, parent, xscroll=False, selectmode=Tkinter.MULTIPLE)
 
    for func in notify_funcs:
      Implementation.registerNotify(self.setAxisUnits, 'ccpnmr.Analysis.AxisUnit', func)
Beispiel #12
0
    def destroy(self):

        for func in notify_funcs:
            Implementation.unregisterNotify(self.setChains,
                                            'ccp.molecule.MolSystem.Chain',
                                            func)

        PulldownMenu.destroy(self)
Beispiel #13
0
  def destroy(self):

    self.spectrum_list.destroy()
    self.expt_list.destroy()

    for func in notify_funcs:
      Implementation.unregisterNotify(self.setExperiments, 'ccp.nmr.Nmr.Experiment', func)
      Implementation.unregisterNotify(self.setSpectra, 'ccp.nmr.Nmr.DataSource', func)
Beispiel #14
0
  def doUnregisters(self):

    try:
      Implementation.unregisterNotify(self.updateAfter, self.refClassName,
                                    'delete')
    except AttributeError:
      # refClassName may be an abstract class, 
      # in which case registering will fail
      return
Beispiel #15
0
  def __init__(self, parent, getSpectra, extra_label = '', *args, **kw):

    self.getSpectra = getSpectra
    self.extra_label = extra_label

    PulldownMenu.__init__(self, parent, *args, **kw)

    for func in notify_funcs:
      Implementation.registerNotify(self.setSpectra, 'ccp.nmr.Nmr.DataSource', func)
Beispiel #16
0
  def __init__(self, parent, getPeakLists, extra_label = '', *args, **kw):

    self.getPeakLists = getPeakLists
    self.extra_label = extra_label

    PulldownMenu.__init__(self, parent, *args, **kw)

    for func in notify_funcs:
      Implementation.registerNotify(self.setPeakLists, 'ccp.nmr.Nmr.PeakList', func)
Beispiel #17
0
    def __init__(self, parent, getChains, extra_label='', *args, **kw):

        self.getChains = getChains
        self.extra_label = extra_label

        PulldownMenu.__init__(self, parent, *args, **kw)

        for func in notify_funcs:
            Implementation.registerNotify(self.setChains,
                                          'ccp.molecule.MolSystem.Chain', func)
Beispiel #18
0
def registerNotify(notify, classname, funcname, application = None, keyword = None):

  if application is None or keyword is None:
    assert application is None and keyword is None, 'application = %s, keyword = %s, both must be None' % (application, keyword)
    return GenImp.registerNotify(notify, classname, funcname)

  if funcname not in allowedNotifyFuncs:
    raise GenImp.ApiError('illegal funcname "%s", must be in %s' % (funcname, allowedNotifyFuncs))

  notifies = GenImp.getClassFromFullName(classname)._notifies
  notifies = notifies.setdefault((funcname, application, keyword), [])
  notifies.append(notify)
Beispiel #19
0
    def destroy(self):

        for func in ('__init__', 'delete', 'setName'):
            for clazz in ('ccp.nmr.NmrConstraint.DistanceConstraintList', ):
                Implementation.unregisterNotify(self.updateConstraintLists,
                                                clazz, func)
        for func in ('__init__', 'delete'):
            Implementation.unregisterNotify(
                self.updateConstraintSets,
                'ccp.nmr.NmrConstraint.NmrConstraintStore', func)

        BasePopup.destroy(self)
Beispiel #20
0
    def __init__(self, parent, getColors, extra_label='', *args, **kw):

        self.getColors = getColors
        self.extra_label = extra_label

        PulldownList.__init__(self, parent, *args, **kw)

        for func in notify_funcs:
            Implementation.registerNotify(self.setColors,
                                          'ccpnmr.Analysis.Color', func)

        self.setColors()
Beispiel #21
0
    def reload(self):

        try:
            reload(self.module)
        except:
            raise Implementation.ApiError('could not reload module "' +
                                          self.module_name + '"')
            return

        try:
            self.func = getattr(self.module, self.func_name)
        except:
            raise Implementation.ApiError('could not find function "' +
                                          self.func_name + '" in module "' +
                                          self.module_name + '"')
Beispiel #22
0
def unregisterNotify(notify, classname, funcname, application = None, keyword = None):

  if application is None or keyword is None:
    assert application is None and keyword is None, 'application = %s, keyword = %s, both must be None' % (application, keyword)
    return GenImp.unregisterNotify(notify, classname, funcname)

  if funcname not in allowedNotifyFuncs:
    raise GenImp.ApiError('illegal funcname "%s", must be in %s' % (funcname, allowedNotifyFuncs))

  try:
    notifies = GenImp.getClassFromFullName(classname)._notifies
    notifies = notifies[(funcname, application, keyword)]
    notifies.remove(notify)
  except:
    pass
Beispiel #23
0
  def resetObjectType(self, objects, key=None, labels=None, objectName=None, 
                      refClassName=None, **kw):
    if refClassName:
      apiClass = Implementation.getClassFromFullName(refClassName)
      refClass = apiClass._metaclass
    else:
      apiClass = objects[0].__class__
      refClass = objects[0].metaclass
      refClassName = refClass.qualifiedName()
    self.refClassName = refClassName
    self.apiClass = apiClass

    for obj in objects:
      if not isinstance(obj, self.apiClass):
        raise ApiError("Object %s is not instance of %s" % (obj, refClassName))
    
    self.objects = objects
    
    self.key    = key
    if labels is None:
      labels = {}
    self.labels = labels.copy()
    self.objectName = objectName or refClass.name 
        
    self.headingList = self.getAttributeHeadings(refClass)
    
    # add 'fullKey to labels
    self.labels['fullKey'] = [str(getattr(obj, 'getFullKey')()) 
           for obj in self.objects]
    
    if refClass.isAbstract:
      # add extra column to define the type
      self.labels['Class'] = [obj.__class__.__name__ for obj in self.objects]
      self.headingList.append('Class')
Beispiel #24
0
    def __init__(self, argumentServer, command_name, module_name, func_name):

        self.name = command_name
        self.module_name = module_name
        self.func_name = func_name
        self.argumentServer = argumentServer

        try:
            self.module = __import__(module_name)
        except:
            raise Implementation.ApiError('could not import module "' +
                                          self.module_name + '"')

        try:
            self.func = getattr(self.module, self.func_name)
        except:
            raise Implementation.ApiError('could not find function "' +
                                          self.func_name + '" in module "' +
                                          self.module_name + '"')
Beispiel #25
0
def createPeakMark(peak, lineWidth=1, dashLength=2, gapLength=2, remove=True, axisTypeDict=None):
  """
  Create a mark positioned at a given peak

  .. describe:: Input
  
  Nmr.Peak, Int, Int, Int, Boolean

  .. describe:: Output
  
  Analysis.Mark
  """

  if not axisTypeDict:
    axisTypeDict = {}

  peakList = peak.peakList
  project = peakList.root
  analysisProject = project.currentAnalysisProject
  
  analysisPeakList = peakList.analysisPeakList
  if analysisPeakList:
    color = analysisPeakList.symbolColor
  elif project.currentAnalysisProfile:
    color = project.currentAnalysisProfile.fgColor
  else:
    color = Color.grey.hex

  mark = analysisProject.newMark(lineWidth=lineWidth, dashLength=dashLength,
                                 gapLength=gapLength, color=color)

  for peakDim in peak.peakDims:
    axisType = axisTypeDict.get(peakDim)
    if not axisType:
      dataDimRef = peakDim.dataDimRef
  
      if dataDimRef:
        expDimRef = dataDimRef.expDimRef
        isotopeCodes = expDimRef.isotopeCodes
        axisType = analysisProject.findFirstAxisType(isotopeCodes=isotopeCodes)
      
        if not axisType:
          msg = 'Unknown axis type isotope codes ' + isotopeCodes
          raise Implementation.ApiError(msg)
        
    if axisType:
      markDim = mark.newMarkDim(position=peakDim.value, axisType=axisType)
 
  mark.peak = peak

  if remove:
    removeMarks(project)

  return mark
Beispiel #26
0
    def applyAuto(self, *extra):

        try:
            spectrum = self.spectrum
            scale = self.global_entry.get()
            changeMode = self.change_mode_buttons.getIndex(
            ) and 'add' or 'multiply'
            baseLevel = self.base_entry.get()

            if (baseLevel <= 0):
                raise Implementation.ApiError(
                    'Base level must be set to positive float')
            numberLevels = self.numberEntry.get()
            if (numberLevels < 1):
                raise Implementation.ApiError(
                    'Number of levels must be set to positive int')

            levelChanger = self.change_entry.get()
            if changeMode == 'add':
                if levelChanger <= 0.0:
                    raise Implementation.ApiError(
                        'Level adder must be set to number > 0.0')
            else:
                if levelChanger <= 1.0:
                    raise Implementation.ApiError(
                        'Level multiplier must be set to number > 1.0')

            self.analysisProject.globalContourScale = scale
            self.doUpdateForm = False

            analysisSpectrum = spectrum.analysisSpectrum
            analysisSpectrum.autoBaseLevel = baseLevel
            analysisSpectrum.autoNumLevels = numberLevels
            analysisSpectrum.autoLevelChanger = levelChanger
            analysisSpectrum.autoLevelMode = changeMode

            self.setContourLevels()
            self.doUpdateForm = True
        except Implementation.ApiError, e:
            showError('Levels error', e.error_msg, parent=self)
Beispiel #27
0
    def destroy(self):

        for func in notify_funcs:
            Implementation.unregisterNotify(
                self.setSpectrumViews, 'ccpnmr.Analysis.SpectrumWindowView',
                func)
        Implementation.unregisterNotify(self.setSpectrumViews,
                                        'ccp.nmr.Nmr.Experiment', 'setName')
        Implementation.unregisterNotify(self.setSpectrumViews,
                                        'ccp.nmr.Nmr.DataSource', 'setName')

        PulldownMenu.destroy(self)
Beispiel #28
0
    def __init__(self, parent, getSpectrumViews, extra_label='', *args, **kw):

        self.getSpectrumViews = getSpectrumViews
        self.extra_label = extra_label

        PulldownMenu.__init__(self, parent, *args, **kw)

        for func in notify_funcs:
            Implementation.registerNotify(
                self.setSpectrumViews, 'ccpnmr.Analysis.SpectrumWindowView',
                func)
        Implementation.registerNotify(self.setSpectrumViews,
                                      'ccp.nmr.Nmr.Experiment', 'setName')
        Implementation.registerNotify(self.setSpectrumViews,
                                      'ccp.nmr.Nmr.DataSource', 'setName')
Beispiel #29
0
    def turnOnNotifiers(self):

        for classname in self.notifies.keys():
            cc = self.notifies[classname]
            notifies = Implementation.getClassFromFullName(classname)._notifies
            for key in cc.keys():
                try:
                    (funcname, application, keyword) = key
                except:
                    funcname = key
                    application = keyword = None
                ff = cc[key]
                ll = notifies.get(key)
                for notify in ff:
                    # do checks below in case someone does open twice in row
                    if ll is None or notify not in ll:
                        self.registerNotify(notify,
                                            classname,
                                            funcname,
                                            application,
                                            keyword,
                                            modifyList=False)
    def __init__(self, parent, analysis, callback=None, *args, **kw):

        self.analysis = analysis
        self.callback = callback

        apply(Frame.__init__, (self, parent) + args, kw)

        label = Label(self, text='Experiment:')
        label.grid(row=0, column=0, sticky='ne')
        self.expt_list = ExperimentList(self,
                                        self.analysis.getExperiments,
                                        callback=self.setSpectra)
        self.expt_list.grid(row=0, column=1, sticky='nw')

        label = Label(self, text='Spectrum:')
        label.grid(row=0, column=2, sticky='ne')
        self.spectrum_list = SpectrumList(self,
                                          self.getSpectra,
                                          callback=self.setPeakLists)
        self.spectrum_list.grid(row=0, column=3, sticky='nw')

        label = Label(self, text='PeakList:')
        label.grid(row=0, column=4, sticky='ne')
        self.peak_list_list = PeakListList(self,
                                           self.getPeakLists,
                                           callback=self.doCallback)
        self.peak_list_list.grid(row=0, column=5, sticky='nw')

        for func in notify_funcs:
            Implementation.registerNotify(self.setExperiments,
                                          'ccp.nmr.Nmr.Experiment', func)
            Implementation.registerNotify(self.setSpectra,
                                          'ccp.nmr.Nmr.DataSource', func)
            if func != 'setName':
                Implementation.registerNotify(self.setPeakLists,
                                              'ccp.nmr.Nmr.PeakList', func)