示例#1
0
    def __init__(self,
                 parent,
                 title='Project : Open',
                 callback=None,
                 help_msg='',
                 help_url='',
                 load_project=None,
                 *args,
                 **kw):

        self.callback = callback
        self.help_msg = help_msg
        self.help_url = help_url
        self.project = None

        if not load_project:

            askdir = lambda title, prompt, initial_value: askDir(
                title,
                prompt,
                initial_value,
                parent=self,
                extra_dismiss_text='Skip')
            askfile = lambda title, prompt, initial_value: askFile(
                title,
                prompt,
                initial_value,
                parent=self,
                extra_dismiss_text='Skip')
            load_project = lambda path: loadProject(
                path, showWarning=showWarning, askDir=askdir, askFile=askfile)

        self.load_project = load_project

        BasePopup.__init__(self, parent=parent, title=title, *args, **kw)
示例#2
0
def launchApplication(projectDir=None):

  global top

  root = Tkinter.Tk()
  root.withdraw()
  top  = EntryCompletionGui(root)
 
  project = None
  if projectDir:
    projectDir = normalisePath(projectDir)
    askdir  = lambda title, prompt, initial_value, default_dir: askDir(title, prompt,
              initial_value, parent=top, extra_dismiss_text='Skip')
    askfile = lambda title, prompt, initial_value: askFile(title, prompt,
              initial_value, parent=top, extra_dismiss_text='Skip')
    try:
      project = loadProject(path=projectDir, showWarning=showWarning, askDir=askdir, askFile=askfile)

      userRepos = project.findFirstRepository(name='userData')
      chemCompPackLoc = project.findFirstPackageLocator(targetName='ccp.molecule.ChemComp')

      if userRepos not in chemCompPackLoc.repositories:
        chemCompPackLoc.addRepository(userRepos)

    except ApiError, e:
      showError('Reading project', e.error_msg, parent=top)
示例#3
0
def launchApplication(projectDir=None):

    global top

    root = Tkinter.Tk()
    root.withdraw(
    )  # get rid of the root window Tkinter would otherwise put up
    top = ApplicationPopup(
        root)  # creates our controlled window (this class in fact)

    project = None
    if projectDir:
        projectDir = normalisePath(projectDir)
        askdir = lambda title, prompt, initial_value, default_dir: askDir(
            title,
            prompt,
            initial_value,
            parent=top,
            extra_dismiss_text='Skip')
        askfile = lambda title, prompt, initial_value: askFile(
            title,
            prompt,
            initial_value,
            parent=top,
            extra_dismiss_text='Skip')
        try:
            project = loadProject(path=projectDir,
                                  showWarning=showWarning,
                                  askDir=askdir,
                                  askFile=askfile)
        except ApiError, e:
            showError('Reading project', e.error_msg, parent=top)
示例#4
0
def launchApplication(filename=None):

    global top

    root = Tkinter.Tk()
    root.withdraw()
    top = ApplicationPopup(root)

    project = None
    if filename:
        file = normalisePath(filename)
        askdir = lambda title, prompt, initial_value, default_dir: askDir(
            title,
            prompt,
            initial_value,
            parent=top,
            extra_dismiss_text='Skip',
            default_dir=default_dir)
        askfile = lambda title, prompt, initial_value: askFile(
            title,
            prompt,
            initial_value,
            parent=top,
            extra_dismiss_text='Skip')
        try:
            project = loadProject(path=file,
                                  showWarning=showWarning,
                                  askDir=askdir,
                                  askFile=askfile)
        except ApiError, e:
            showError('Reading project', e.error_msg)
示例#5
0
  def selectDir(self,component,format,buttonKeyword):
    
    dirName = self.widgets[component][buttonKeyword].__getitem__('text')
    
    title = 'Select directory for %s' % format
    prompt = 'Select %s directory for %s' % (component,format)

    newDirName = askDir(title,prompt,initial_value = dirName,parent = self)
    
    if newDirName:
      self.widgets[component][buttonKeyword].config(text = newDirName)
      
      if self.importExportFlag == 'import' and not self.component:
        self.checkButton[component].set(1)
示例#6
0
def loadProject(parent, path, projectName=None):

    path = uniIo.normalisePath(path)
    askdir = lambda title, prompt, initial_value: askDir(
        title, prompt, initial_value, parent=parent, extra_dismiss_text='Skip')
    askfile = lambda title, prompt, initial_value: askFile(
        title, prompt, initial_value, parent=parent, extra_dismiss_text='Skip')
    project = genIo.loadProject(path,
                                showWarning=showWarning,
                                askDir=askdir,
                                askFile=askfile)

    # now check dataStores
    # delete those that are not used
    # and otherwise check path to see if exists

    dataStores = []
    for dataLocationStore in project.dataLocationStores:
        for dataStore in dataLocationStore.dataStores:
            if isinstance(dataStore,
                          NumericMatrix) and not dataStore.nmrDataSources:
                print 'deleting dataStore %s with path %s' % (
                    dataStore, dataStore.fullPath)
                dataStore.delete()
            elif isinstance(
                    dataStore,
                    MimeTypeDataStore) and not dataStore.nmrDataSourceImages:
                print 'deleting dataStore %s with path %s' % (
                    dataStore, dataStore.fullPath)
                dataStore.delete()
            else:
                dataStores.append(dataStore)

    badDataStores = [
        dataStore for dataStore in dataStores
        if not os.path.exists(dataStore.fullPath)
    ]

    if badDataStores:
        popup = DataLocationPopup(parent, project, modal=True)
        popup.destroy()

    return project
示例#7
0
        print 'must specify project directory'
        sys.exit()

    path = sys.argv[1]

    import Tkinter
    from memops.gui.DataEntry import askDir, askFile
    from memops.gui.MessageReporter import showWarning
    from memops.general.Io import loadProject
    from memops.universal.Io import normalisePath

    # This needs to be above loadProject because that can pop up
    # dialogs, and it will create a root if one has not been created
    # already, and that will lead to the later code crashing
    r = Tkinter.Tk()

    path = normalisePath(path)
    askdir = lambda title, prompt, initial_value: askDir(
        title, prompt, initial_value, parent=top, extra_dismiss_text='Skip')
    askfile = lambda title, prompt, initial_value: askFile(
        title, prompt, initial_value, parent=top, extra_dismiss_text='Skip')
    project = loadProject(path,
                          showWarning=showWarning,
                          askDir=askdir,
                          askFile=askfile)

    popup = DataLocationPopup(r, project)

    r.withdraw()
    r.mainloop()
示例#8
0
文件: Io.py 项目: fenglb/ccpnmr2.4
def loadProject(parent, path, projectName=None):

    path = uniIo.normalisePath(path)
    askdir = lambda title, prompt, initial_value: askDir(
        title, prompt, initial_value, parent=parent, extra_dismiss_text='Skip')
    askfile = lambda title, prompt, initial_value: askFile(
        title, prompt, initial_value, parent=parent, extra_dismiss_text='Skip')
    project = genIo.loadProject(path,
                                showWarning=showWarning,
                                askDir=askdir,
                                askFile=askfile)

    # now check dataStores
    # delete those that are not used
    # and otherwise check path to see if exists

    dataStores = []
    for dataLocationStore in project.dataLocationStores:
        for dataStore in dataLocationStore.dataStores:
            if isinstance(dataStore,
                          NumericMatrix) and not dataStore.nmrDataSources:
                print 'deleting dataStore %s with path %s' % (
                    dataStore, dataStore.fullPath)
                dataStore.delete()
            elif isinstance(
                    dataStore,
                    MimeTypeDataStore) and not dataStore.nmrDataSourceImages:
                print 'deleting dataStore %s with path %s' % (
                    dataStore, dataStore.fullPath)
                dataStore.delete()
            else:
                dataStores.append(dataStore)

    badDataStores = [
        dataStore for dataStore in dataStores
        if not os.path.exists(dataStore.fullPath)
    ]

    if badDataStores:
        # find DataUrls involved
        dataUrls = set(dataStore.dataUrl for dataStore in badDataStores)
        startDir = project.packageLocator.findFirstRepository(
        ).url.dataLocation

        for dataUrl in dataUrls:
            if not dataUrl.dataStores.difference(badDataStores):
                # all DataStores for this DataUrl are bad
                # we can make changes without affecting 'good' DataStores

                # Look for an obvious place the data may have moved to
                dataStores = dataUrl.sortedDataStores()
                fullPaths = [dataStore.fullPath for dataStore in dataStores]
                baseDir, newPaths = uniIo.suggestFileLocations(
                    fullPaths, startDir=startDir)

                if baseDir is not None:
                    # We have a file location that fits all missing files.
                    # Change dataStores to use it
                    print 'WARNING, resetting data locations to: \n%s\n' % baseDir

                    ccpGenIo.changeDataStoreUrl(dataStores[0], baseDir)
                    for ii, dataStore in enumerate(dataStores):
                        dataStore.path = newPaths[ii]

        if [
                dataStore for dataStore in dataStores
                if not os.path.exists(dataStore.fullPath)
        ]:
            popup = DataLocationPopup(parent, project, modal=True)
            popup.destroy()

    return project