Пример #1
0
    def __init__(self,
                 parent,
                 serverLocation=UPDATE_SERVER_LOCATION,
                 serverDirectory=UPDATE_DIRECTORY,
                 dataFile=UPDATE_DATABASE_FILE,
                 exitOnClose=False,
                 helpUrl=None):

        self.exitOnClose = exitOnClose
        self.helpUrl = helpUrl
        UpdateAgent.__init__(self,
                             serverLocation,
                             serverDirectory,
                             dataFile,
                             isStandAlone=exitOnClose)
        self.fileUpdate = None

        if exitOnClose:
            quitFunc = sys.exit
        else:
            quitFunc = None

        BasePopup.__init__(self,
                           parent=parent,
                           title='CcpNmr Software Updates',
                           quitFunc=quitFunc)
Пример #2
0
    def startBasePopup(self, parent, title, modal, True):

        BasePopup.__init__(self,
                           parent=parent,
                           title=title,
                           modal=modal,
                           transient=True)
Пример #3
0
    def __init__(self, parent, project):

        self.project = project
        self.guiParent = parent
        self.selectedFormats = []
        self.defaultText = 'Select file'

        self.chainDict = {}
        self.chainList = []

        self.shiftListDict = {}
        self.shiftLists = []

        for shiftList in self.project.currentNmrProject.findAllMeasurementLists(
                className='ShiftList'):
            if shiftList.measurements != ():
                label = str(shiftList.serial) + ':' + str(shiftList.name)
                self.shiftListDict[label] = shiftList
                self.shiftLists.append(label)

        if not self.shiftLists:

            showError('Error', 'No shift lists available!')
            return

        BasePopup.__init__(self,
                           parent=parent,
                           title="Project '%s': " % project.name +
                           'Write BMRB chemical shift deposition file',
                           modal=False,
                           transient=True)
Пример #4
0
    def __init__(self, parent, title='Text output'):

        BasePopup.__init__(self,
                           parent=parent,
                           title=title,
                           modal=False,
                           transient=False)
    def __init__(self, parent, project, autoAssignProjectFile):

        self.project = project
        self.guiParent = parent
        self.autoAssignProjectFile = autoAssignProjectFile

        self.validSelection = False

        self.peakLists = []

        for nmrExp in self.project.currentNmrProject.sortedExperiments():
            for ds in nmrExp.sortedDataSources():
                for pl in ds.sortedPeakLists():
                    self.peakLists.append(pl)

        if not self.peakLists:
            raise ('No peak lists available!')

        (self.peakNameList,
         self.peakNameDict) = createSelection(self.peakLists)
        self.peakNameList.insert(0, 'None')
        self.peakNameDict['None'] = None

        BasePopup.__init__(self,
                           parent=parent,
                           title="Project '%s': " % project.name +
                           'Write AutoAssign project file',
                           modal=True,
                           transient=True)
Пример #6
0
    def __init__(self,
                 parent,
                 headings,
                 entries,
                 title='',
                 file='',
                 *args,
                 **kw):

        headings = [heading.replace('\n', ' ') for heading in headings]

        if (headings[0].lower() == 'number'):
            self.addNumber = False
        else:
            self.addNumber = True
            headings.insert(0, 'Number')

        if (not title):
            title = 'Export data'

        self.exportSelection = parent.tableExportSelection
        self.headings = headings
        self.entries = entries
        self.file = file

        kw['title'] = title
        kw['transient'] = True
        kw['modal'] = True
        BasePopup.__init__(self, parent=parent, *args, **kw)
Пример #7
0
    def __init__(self,
                 parent,
                 message,
                 nmrRes,
                 optionList,
                 title,
                 urlFile=None):

        # Constructor doesn't do much except call body
        # The parent is self.parent (parent of the popup)

        self.singleResonanceStatus = None

        self.message = message
        self.optionList = optionList
        self.nmrRes = nmrRes

        if urlFile:
            self.help_url = joinPath(getHelpUrlDir(), urlFile + '.html')

        else:
            self.help_url = None

        # modal = true means that it won't continue unless this one returns value
        BasePopup.__init__(self,
                           parent=parent,
                           title=title,
                           modal=True,
                           transient=True)
Пример #8
0
    def __init__(self, parent, project):

        self.project = project
        self.guiParent = parent

        self.autoAssignFormat = AutoAssignFormat(project, guiParent=parent)

        self.format = 'autoAssign'

        self.chainStampSep = '-'

        self.dateTimeFlag = time.strftime("%Y%m%d.%H:%M")

        self.getPreviousDateTimeStamps()

        self.getChainsAndChainStamps()

        self.importFileName = self.exportFileName = None

        BasePopup.__init__(self,
                           parent=parent,
                           title="Project '%s': " % project.name +
                           'AutoAssign export/import cycle.',
                           modal=True,
                           transient=True)
Пример #9
0
    def __init__(self, parent, peakList, *args, **kw):

        self.peakList = peakList
        self.colours = ['red', 'green']
        self.dataSets = []

        BasePopup.__init__(self, parent=parent, title='Test Popup', **kw)
Пример #10
0
    def __init__(self,
                 parent,
                 file_types=None,
                 directory=None,
                 multiSelect=False,
                 title='Browse files',
                 prompt=None,
                 show_file=True,
                 file='',
                 dismiss_text='Close',
                 extra_dismiss_text='',
                 selected_file_must_exist=False,
                 default_dir=None,
                 *args,
                 **kw):

        self.file_types = file_types
        self.directory = directory
        self.prompt = prompt
        self.show_file = show_file
        self.dismiss_text = dismiss_text
        self.extra_dismiss_text = extra_dismiss_text
        self.initial_file = file
        self.selected_file_must_exist = selected_file_must_exist
        self.default_dir = default_dir
        self.multiSelect = multiSelect

        kw['title'] = title
        kw['transient'] = True
        kw['modal'] = True
        BasePopup.__init__(self, parent=parent, *args, **kw)
Пример #11
0
    def __init__(self, parent, project, molName, createMoleculeDict,
                 localCreateMoleculeDict):

        self.molName = molName
        self.project = project
        self.createMoleculeDict = createMoleculeDict
        self.localCreateMoleculeDict = localCreateMoleculeDict

        self.hasChanged = False

        self.molecule = self.localCreateMoleculeDict[self.molName][0]

        self.deleteText = 'Delete'
        self.okText = 'OK'
        self.startText = 'Insert at start'
        self.endText = 'Append to end'

        self.newMoleculeList = []

        for molName in self.localCreateMoleculeDict.keys():
            if molName != self.molName and not self.localCreateMoleculeDict[
                    molName][0]:
                self.newMoleculeList.append(molName)

        # modal = true means that it won't continue unless this one returns value
        BasePopup.__init__(self,
                           parent=parent,
                           title="Project '%s': " % project.name +
                           'Set chemComps for sequence',
                           modal=True,
                           transient=True)
Пример #12
0
    def __init__(self, guiParent, run, protocolInterface, *args, **kw):

        self.run = run
        self.protocolInterface = protocolInterface
        self.widgetDict = {}  # maps interfaceParameter --> widget

        BasePopup.__init__(self, guiParent, *args, **kw)
Пример #13
0
    def __init__(self,
                 parent,
                 resonanceList,
                 resonanceDict,
                 code3Letter,
                 resName,
                 helpText,
                 multi,
                 title='Select resonances'):

        # Constructor doesn't do much except call body
        # The parent is self.parent (parent of the popup)

        self.selectedResonances = None

        self.resonanceList = resonanceList
        self.resonanceDict = resonanceDict
        self.code3Letter = code3Letter
        self.resName = resName
        self.helpText = helpText

        if multi:
            self.selectmode = Tkinter.MULTIPLE
        else:
            self.selectmode = Tkinter.SINGLE

        # modal = true means that it won't continue unless this one returns value
        BasePopup.__init__(self,
                           parent=parent,
                           title=title,
                           modal=True,
                           transient=True)
Пример #14
0
  def __init__(self, parent, project):

    self.project = project
    self.selectedFormats = []
    self.defaultText = 'Select file'
    
    self.formats = allFormatsDict.keys()
    self.formats.sort()
     
    BasePopup.__init__(self, parent=parent, title= "Project '%s': " % project.name +  'Write ccpNmr mapping file', modal=False, transient=True)
Пример #15
0
  def __init__(self, parent, project=None, *args, **kw):

    self.project = project
    self.parent  = parent
    self.objects = self.getObjects()
    self.object  = None
    
    BasePopup.__init__(self, parent=parent, title='Popup Template', **kw)
                       
    self.updateObjects()
Пример #16
0
    def __init__(self, parent, project):

        #
        # Info for writing file...
        #

        self.groupText = {}

        #
        # Set up molSystem information
        #

        self.project = project

        self.molSysList = list(project.sortedMolSystems())
        self.molSystems = None

        self.molSysLabelList = []
        self.molSysLabelDict = {}
        self.molSysRelationDict = {}

        molSysLabel = 'All molSystems'

        if self.setChainLabels(molSysLabel, self.molSysList):
            self.molSysLabelList.append(molSysLabel)
            self.molSysLabelDict[molSysLabel] = self.molSysList

        for molSys in self.molSysList:
            molSysLabel = '%s' % molSys.code

            if self.setChainLabels(molSysLabel, [molSys]):
                self.molSysLabelList.append(molSysLabel)
                self.molSysLabelDict[molSysLabel] = [molSys]

        if not self.molSysLabelList:
            showWarning('Warning',
                        'No chemical shift lists available! Exiting...')
            return

        #
        # Some initializing...
        #

        self.chains = None
        self.shiftList = None
        self.shiftListLabel = None
        self.results = None

        # modal = true means that it won't continue unless this one returns value
        BasePopup.__init__(self,
                           parent=parent,
                           title="Project '%s': " % project.name +
                           'Group chemical shift values',
                           modal=False,
                           transient=True)
Пример #17
0
    def __init__(self, parent, project):

        self.project = project
        self.peakLists = []

        BasePopup.__init__(self,
                           parent=parent,
                           title="Project '%s': " % project.name +
                           'Create shift list from peak lists',
                           modal=False,
                           transient=True)
Пример #18
0
 def __init__(self, parent, text = '', progress = 0, total = 100, title=None,
              width = 200, height = 15, transient = True, *args, **kw):
   
   self.progress = float(progress)
   self.cWidth   = width
   self.cHeight  = height
   self.total    = float(total) or 1.0
   self.text     = text
   
   BasePopup.__init__(self, parent=parent, title=title or 'Progress Bar',
                      transient=transient, *args, **kw)
Пример #19
0
 def __init__(self, parent, objects, key=None, labels=None, objectName=None, 
              refClassName=None, **kw):
   
   self.parent = parent
   
   self.resetObjectType(objects, key, labels, objectName, refClassName)
   
   self.doRegisters()
   
   BasePopup.__init__(self, parent, title= "Object Selection",
                      borderwidth=5,  **kw)
Пример #20
0
    def __init__(self,
                 parent,
                 file=None,
                 files=None,
                 component=None,
                 selectionText='Select',
                 title=None,
                 format=None,
                 multiSelect=False):

        #
        # Also get format (from self?)
        #

        self.file = None  # Use this to return single file info, for backward compat

        if not multiSelect and file:
            self.files = [file]

        elif files:
            self.files = files

        else:
            self.files = []

        if self.files:
            for i in range(len(self.files)):
                self.files[i] = normalisePath(self.files[i])

        self.component = component
        self.fileSelected = False
        self.selectionText = selectionText
        self.format = format

        self.multiSelect = multiSelect

        if not title:
            title = 'Select %s file' % component

        BasePopup.__init__(self,
                           parent=parent,
                           title=title,
                           modal=True,
                           transient=True)
Пример #21
0
    def __init__(self,
                 parent,
                 resonanceNameList,
                 resonanceLineDict,
                 ccpCode,
                 title='Group resonances'):

        self.resNameGroups = None

        self.resonanceNameList = resonanceNameList
        self.resonanceLineDict = resonanceLineDict
        self.checkButtons = []
        self.ccpCode = ccpCode

        BasePopup.__init__(self,
                           parent=parent,
                           title=title,
                           modal=True,
                           transient=True)
Пример #22
0
    def __init__(self,
                 parent,
                 entries,
                 label='',
                 message='',
                 select_text='Select',
                 *args,
                 **kw):

        self.entries = entries
        self.label = label
        self.message = message
        self.select_text = select_text

        self.item = None

        kw['title'] = 'Select item'
        kw['transient'] = True
        kw['modal'] = True
        BasePopup.__init__(self, parent=parent, *args, **kw)
Пример #23
0
    def __init__(self,
                 parent,
                 serverLocation=UPDATE_SERVER_LOCATION,
                 serverDirectory=UPDATE_DIRECTORY,
                 dataFile=UPDATE_DATABASE_FILE):

        UpdateAgent.__init__(self,
                             serverLocation,
                             serverDirectory,
                             dataFile,
                             admin=1)

        self.fileTypes = [
            FileType('Python', ['*.py']),
            FileType('C', ['*.c']),
            FileType('All', ['*'])
        ]
        self.fileUpdate = None

        BasePopup.__init__(self,
                           parent=parent,
                           title='CcpNmr Update Administrator',
                           quitFunc=self.quit)
Пример #24
0
  def __init__(self, parent, acqProcPars, format):
  
    self.rawData = acqProcPars.experiment.rawData
    self.freqData = acqProcPars.freqDataDims[format][0].dataSource
    self.expDimRefs = acqProcPars.expDimRefs
    self.format = format
    self.updateAcqProcPars = acqProcPars.parameterUpdate
    self.updateAcqProcParsWidget = acqProcPars.updateFromWidget
    self.getDataDimRefs = acqProcPars.getDataDimRefs
    
    self.formatObjectDict = parent.formatObjectDict
    
    self.guiParent = parent
    self.project = self.rawData.root
    
    #
    # Dict for setup
    #
    # TODO: really need two datasources for nmrPipe... one fid, one processed!?!?
    #
    
    for writeFormatName in acqProcPars.writeFormats:
      setattr(self,writeFormatName,writeFormatName)
    
    value = 0
    self.fileSetup = {}
    self.writeSetup = {}
    
    #
    #  nmrPipe definitions
    #
    
    self.fileSetup[self.nmrPipe] = [
                           ['Conversion script file\n        (outputs to...)',
                            lambda: self.rawData.findFirstApplicationData(application = self.nmrPipe,keyword = 'conversion script'),
                            lambda x = value: self.setApplData(self.rawData,self.nmrPipe,'conversion script',x),
                            ['autoconv.com'],
	        'conversion script'],
                           ['    nmrPipe FIDs\n(inputs to...)',
                            lambda: self.rawData.findFirstApplicationData(application = self.nmrPipe,keyword = 'FID'),
                            lambda x = value: self.setApplData(self.rawData,self.nmrPipe,'FID',x),
                            ['auto.fid','auto%03d.fid'],
	        'FID'],
                           ['Processing script file\n       (outputs to...)',
                            lambda: self.freqData.findFirstApplicationData(application = self.nmrPipe,keyword = 'processing script'),
                            lambda x = value: self.setApplData(self.freqData,self.nmrPipe,'processing script',x),
                            ['autoproc.com'],
	        'processing script'],
                           ['Processed data',
                            lambda: self.getDataSourceFileName(self.freqData),
                            lambda x = value: self.doDataStoreFileName(self.freqData,x),
                            ['auto.ft','auto%03d.ft'],
	        'processed data']
                          ]
      
    # TODO: can add execute nmrPipe program buttons... see dataNavigator
      
    self.writeSetup[self.nmrPipe] = [
                                  ['Write conversion file',
                                   lambda : self.writeFile(self.nmrPipe,['conversion'])],
                                  ['Write processing file',
                                   lambda : self.writeFile(self.nmrPipe,['processing'])],
                                  ['Write all',
                                   lambda : self.writeFile(self.nmrPipe,['conversion','processing'])]
                                 ]

    #
    #  azara definitions
    #
    
    self.fileSetup[self.azara] = [
                           ['Processing parameters file\n          (inputs to...)',
                            lambda: self.rawData.findFirstApplicationData(application = self.azara,keyword = 'processing parameters'),
                            lambda x = value: self.setApplData(self.rawData,self.azara,'processing parameters',x),
                            ['autoproc.par'],
	        'processing parameters'],
                           ['Processing script file\n (outputs to both...)',
                            lambda: self.freqData.findFirstApplicationData(application = self.azara,keyword = 'processing script'),
                            lambda x = value: self.setApplData(self.freqData,self.azara,'processing script',x),
                            ['autoproc.scr'],
	        'processing script'],
                           ['Processed data',
                            lambda: self.getDataSourceFileName(self.freqData),
                            lambda x = value: self.doDataStoreFileName(self.freqData,x),
                            ['spectrum.ft'],
	        'spectrum'],
                           ['Processed data parameter file\n',
                            lambda: self.freqData.findFirstApplicationData(application = self.azara,keyword = 'spectrum parameters'),
                            lambda x = value: self.setApplData(self.freqData,self.azara,'spectrum parameters',x),
                            ['spectrum.par'],
	        'spectrum parameters']
                          ]
      
    # TODO: can add execute process program buttons... see dataNavigator
      
    self.writeSetup[self.azara] = [
                                  ['Write processing parameters file',
                                   lambda : self.writeFile(self.azara,['processingPars'])],
                                  ['Write processing script file',
                                   lambda : self.writeFile(self.azara,['processingScript'])],
                                  ['Write all',
                                   lambda : self.writeFile(self.azara,['processingPars','processingScript'])]
                                 ]
    
    BasePopup.__init__(self,parent = parent, title = "Project '%s': " % self.project.name + '%s processing write' % format, modal = False, transient=False)
Пример #25
0
    def __init__(self, parent, format, dim, getValue):

        #
        # General setup
        #

        self.maxArgs = 4
        self.nmrPipe = 'nmrPipe'
        self.azara = 'azara'
        self.format = format

        self.freqDataDim = parent.freqDataDims[format][dim]
        self.expDimRef = parent.expDimRefs[dim]

        #
        # Window function settings (different per program)
        #

        self.windowFunctions = {}

        specWidth = self.freqDataDim.spectralWidthOrig

        # TODO: these for azara still have to change a bit...
        self.windowFunctions[self.azara] = [
            ['sine', 'sinebell', [['Angle (deg)', 0, 'deg']]],
            ['sine^2', 'sinebell2', [['Angle (deg)', 0, 'deg']]],
            ['exponential (fixed)', 'decay', [['End value', 0.5, 'end']]],
            [
                'exponential', 'decay_sw',
                [['Line broadening (Hz)', 10, 'lb'],
                 ['Spectral width (Hz)', specWidth, 'sw']]
            ],
            [
                'gaussian (fixed)', 'gaussian',
                [['Total points fraction for max', 0.25, 'frac'],
                 ['End value', 1, 'end']]
            ],
            [
                'gaussian', 'gaussian_sw',
                [['Line broadening (Hz)', 10, 'lb'],
                 ['Sharpening factor', 0.7, 'shrp'],
                 ['Spectral width (Hz)', specWidth, 'sw']]
            ],
            [
                'inverse cosine', 'inv_cosine',
                [['Frequency (Hz)', 0, 'freq'],
                 ['Spectral width (Hz)', specWidth, 'sw']]
            ]
        ]

        self.windowFunctions[self.nmrPipe] = [
            [
                'sine', 'SP',
                [['Start sine at (pi)', 0, 'off'],
                 ['End sine at (pi)', 1, 'end'], ['Sine to power', 1, 'pow']]
            ], ['exponential', 'EM', [['Line broadening (Hz)', 10, 'lb']]],
            [
                'lorentz-gauss', 'GM',
                [['Inverse exp width (Hz)', 0, 'g1'],
                 ['Gaussian width (Hz)', 0, 'g2'], ['Center (0-1)', 0, 'g3']]
            ],
            [
                'gaussian', 'GMB',
                [['Exponential term', 0, 'lb'], ['Gaussian term', 0, 'gb']]
            ],
            [
                'trapezoid', 'TM',
                [['Ramp length left', 0, 't1'], ['Ramp length right', 0, 't2']]
            ],
            [
                'triangle', 'TRI',
                [['Point loc of apex', 0,
                  'loc'], ['Left edge height', 0, 'lHi'],
                 ['Right edge height', 0, 'rHi']]
            ]
        ]

        #
        # Make list of names for pulldown menu
        #

        self.windowFuncList = []

        for (winFunc, winFuncAppl,
             winFuncArgs) in self.windowFunctions[format]:
            self.windowFuncList.append(winFunc)

        #
        # Get the right window function from appldata (if there)
        #

        self.windowFunctionKeyword = 'windowFunction'
        self.winFuncIndex = self.getWindowFunctionIndex()

        #
        # Set defaults depending on nucleus type if no window function set
        #

        if self.winFuncIndex == -1:

            if format == self.nmrPipe:
                self.winFuncIndex = 0
                if self.expDimRef.isotopeCodes[0] == '1H':
                    # use SP '-off 0.3333 -pow 2.0'
                    self.windowFunctions[self.nmrPipe][
                        self.winFuncIndex][2][0][1] = 0.3333
                    self.windowFunctions[self.nmrPipe][
                        self.winFuncIndex][2][2][1] = 2.0
                else:
                    # for non-H, use SP '-off 0.5 -pow 2.0'
                    self.windowFunctions[self.nmrPipe][
                        self.winFuncIndex][2][0][1] = 0.5
                    self.windowFunctions[self.nmrPipe][
                        self.winFuncIndex][2][2][1] = 2.0

            elif format == self.azara:
                self.winFuncIndex = 1
                if self.expDimRef.isotopeCodes[0] == '1H':
                    # use sinebell2 60
                    self.windowFunctions[self.azara][
                        self.winFuncIndex][2][0][1] = 60
                else:
                    # for non-H, use sinebell2 90
                    self.windowFunctions[self.azara][
                        self.winFuncIndex][2][0][1] = 90

        # Get actual values for arguments from appldata if they exists!

        self.updateWindowFunctions()

        # Also using this to return the current window function 'string value'
        if not getValue:

            # modal = true means that it won't continue unless this one returns value
            BasePopup.__init__(
                self,
                parent=parent,
                title='Select window function',
                modal=False,
                transient=True,
            )
Пример #26
0
  def __init__(self, parent, format, component = None, threading = True):
  
    self.project = parent.project
    self.guiParent = parent
    self.format = format 
    self.formatObjectDict = parent.formatObjectDict
    self.component = component
    self.threading = threading
    
    self.setImportExportFlag()
    
    self.files = {}
    self.function = {}
    self.components = []
    self.widgetSetup = {}
    self.toggleInfoIndex = {}
    
    #
    # Do the import of the relevant format class and the IOkeywords dictionary
    #
    
    self.formatLabel = allFormatsDict[self.format]
    self.formatModule = __import__('ccpnmr.format.converters.%sFormat' % self.formatLabel,{},{},['%sFormat' % self.formatLabel,'IOkeywords'])

    #
    # Definitions for import/export windows, files and functions (come from IoDefinitions)
    # 
    
    self.exportFunc = {}
    self.importFunc = {}
    self.IOkeywords = {}
    
    for (component,readFunc,writeFunc,fileDict,importSetup,exportSetup,exportFunc,importFunc) in IoSetupList:
      
      #
      # If component passed in, only do that one.
      #
      
      if self.component and self.component != component:
        continue
      
      #
      # Set import or export info
      #
      
      self.toggleInfoIndex[component] = 0

      if self.importExportFlag == 'import':
        self.widgetSetup[component] = importSetup[:]
        self.function[component] = readFunc
        componentAction = 'read'
        
        #
        # For multiple file import, don't bother with project files
        #
        
        if not self.component and component == 'project':
          continue
        
      else:
        self.widgetSetup[component] = exportSetup[:]
        self.function[component] = writeFunc
        componentAction = 'write'
      
      #
      # Set some variables and functions...
      #
      
      componentKeyWord = writeFunc[5:]        # This is also OK for import...
      
      self.exportFunc[component] = exportFunc
      self.importFunc[component] = importFunc
      
      #
      # Now set format specific information
      #
      
      if fileDict.has_key(format):
      
        (fileName,importFlag,exportFlag,addImport,addExport) = fileDict[format]
        
        if self.importExportFlag == 'import':
          validFlag = importFlag
          addInfo = addImport
        else:
          validFlag = exportFlag
          addInfo = addExport
        
        if validFlag:
        
          self.files[component] = fileName
          self.components.append(component)          
          self.IOkeywords[component] = {}
          
          #
          # Normal import/export flag
          #
          
          if validFlag == 1:

            #
            # Set fileName(s) info if available (is not in IOkeywords from Format files!!)
            #

            for widgetInfo in self.widgetSetup[component]:
              if widgetInfo[1] == 'fileName':
                self.IOkeywords[component]['fileName'] = (None,True,'The file name to be %sed.' % self.importExportFlag)
                break
              elif widgetInfo[1] == 'fileNames':
                self.IOkeywords[component]['fileNames'] = (None,True,'The file names to be %sed.' % self.importExportFlag)
                break

            #
            # Get IOkeywords info from Format files...
            #

            if self.formatModule.IOkeywords.has_key(self.function[component]):
              self.IOkeywords[component].update(self.formatModule.IOkeywords[self.function[component]])

              for superClass in self.formatModule.IOkeywords['subClasses']:
                if componentKeyWord in self.formatModule.IOkeywords['subClasses'][superClass]:
                  superClassFunc = componentAction + superClass
                  self.IOkeywords[component].update(self.formatModule.IOkeywords[superClassFunc])

            else:
              print "  Warning: no IOkeywords information for %s!" % self.function[component]
              self.IOkeywords[component] = {}

            #
            # Also add to self.toggleInfoIndex[component] if required keywords...
            #

            for IoKeyword in self.IOkeywords[component].keys():
              if self.IOkeywords[component][IoKeyword][1]:
                for widgetInfo in self.widgetSetup[component]:
                  if widgetInfo[1] == IoKeyword:
                    self.toggleInfoIndex[component] += 1

          #
          # Display text for import that refers to other mechanism...
          #
          
          else:
          
            self.IOkeywords[component]['showText'] = "Please use %s to %s %s." % (validFlag,self.importExportFlag,component)
            addInfo = None

        if addInfo:
                
          #
          # Now add format specific widget info and make sure it's all valid...
          #

          for addItem in addInfo:
            inputKeyWord = addItem[1]
            
            if inputKeyWord not in self.IOkeywords[component]:
              print "  Error: invalid %s keyword '%s' for %s!" % (self.importExportFlag,inputKeyWord,component)
              continue

            # Check whether keyword already exists! If so, replace...
            for widgetIndex in range(0,len(self.widgetSetup[component])):
              widgetInfo = self.widgetSetup[component][widgetIndex]
              if inputKeyWord == widgetInfo[1]:
                self.widgetSetup[component][widgetIndex] = addItem
                inputKeyWord = None

            # If the keyword wasn't found, then append to the full list.
            if inputKeyWord:
              self.widgetSetup[component].insert(self.toggleInfoIndex[component],addItem)
              self.toggleInfoIndex[component] += 1
                 
    # TODO: use labels here instead of name    
    BasePopup.__init__(self,parent = parent, title = self.titleText, modal = False, transient=False)
Пример #27
0
  def close(self):
  
    self.doUnregisters()
    self.parent.argumentVar.set(1)
 
    BasePopup.close(self)
Пример #28
0
class SelectObjectPopup(BasePopup):

  def __init__(self, parent, objects, key=None, labels=None, objectName=None, 
               refClassName=None, **kw):
    
    self.parent = parent
    
    self.resetObjectType(objects, key, labels, objectName, refClassName)
    
    self.doRegisters()
    
    BasePopup.__init__(self, parent, title= "Object Selection", borderwidth=5,
                       **kw)
    self.geometry("+50+50")
  
  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')
    
  
  def body(self, master):
    
    textMatrix = self.getTextMatrix(self.objects)
        
    self.label = Label(self,text='Select %s ' % self.objectName)
    self.label.grid(row=0,column=0,sticky='nw')
    
    self.scrolledMatrix = ScrolledMatrix(self, initialRows=10,
                            headingList=self.headingList, 
                            callback=self.selectCell,
                            objectList=self.objects, textMatrix=textMatrix)
    self.scrolledMatrix.grid(row=1,column=0,sticky='nsew')
    self.grid_rowconfigure   (0, weight=0)
    self.grid_rowconfigure   (1, weight=1)
    self.grid_columnconfigure(0, weight=1)
  
    self.protocol('WM_DELETE_WINDOW', self.close)
  
  def getAttributeHeadings(self, refClass):
  
    attrNames, keyNames = getDisplayAttrNames(refClass, self.labels)
  
    # set up for key parameter and fullkey
    # fullKey will be used as key if none othe is present,
    # and will be put at the end otherwise
    if self.key is None:
      if keyNames:
        attrNames.append('fullKey')
      else:
        # key in class not available, no key passed in. Use fullKekey = 'fullKey'
        attrNames.insert(0,'fullKey')
    else:
      try:
        attrNames.remove(self.key)
      except ValueError:
        raise ApiError("key %s not in attributes or labels: %s"
                        % (self.key, attrNames))
      attrNames.insert(0,self.key)
      attrNames.append('fullKey')
     
    return attrNames
      
  def getTextMatrix(self,objects):
    
    headings = self.headingList
    nHeadings = len(headings)
    matrix = []
    
    for ii,object in enumerate(objects):
      line = nHeadings * ['None']
      for jj,attrName in enumerate(headings):
      
        if self.labels.get(attrName) is None:
          
          if hasattr(object,attrName):
            val = getattr(object,attrName)
            if isinstance(val, frozenset):
              val = list(val)
              val.sort()
            ss = str(val)
            if len(ss) > 32:
              ss = ss[:32] + '...'
            line[jj] = ss
        
        else:
          line[jj] = self.labels[attrName][ii]
                        
      matrix.append(line)
    
    return matrix
    
    self.resetObjectType(objects, key, labels, objectName, refClassName)
  
  def update(self, objects, key=None, labels=None, objectName=None, 
             refClassName=None, remove=None, reset=True):
    
    if reset:
      self.doUnregisters()
      self.resetObjectType(objects, key, labels, objectName, refClassName)
      self.doRegisters()
    
    if remove:
      ii = self.objects.index(remove)
      del self.objects[ii]
      for ll in self.labels.values():
        del ll[ii]
    
    if not self.objects:
      self.selectCell(None)
    
    if len(objects) == 1:
      return objects[0]

    self.label.set('Select %s ' % self.objectName)
    textMatrix = self.getTextMatrix(self.objects)
    self.scrolledMatrix.update(objectList=self.objects, 
                               headingList=self.headingList, 
                               textMatrix=textMatrix)

  def close(self):
  
    self.doUnregisters()
    self.parent.argumentVar.set(1)
 
    BasePopup.close(self)

  def destroy(self):
  
    self.doUnregisters()
    try:
      self.parent.argumentVar.set(1)
    except AttributeError, e:
      pass
      
    BasePopup.destroy(self)
Пример #29
0
 def quit(self):
 
   BasePopup.destroy(self)  
Пример #30
0
    def open(self, file=''):

        if (file):
            self.setFile(file)
        BasePopup.open(self)