def __init__(self, parent, windows, **args):
        tk.Frame.__init__(self, parent, bg='white', **args)
        self.windows = windows
        self.manager = windows.manager
        self.root = windows.root

        # tkFont.Font(size=12, family='verdana', weight='bold')
        bigSize = pwgui.cfgFontSize + 2
        smallSize = pwgui.cfgFontSize - 2
        fontName = pwgui.cfgFontName

        self.projNameFont = tkFont.Font(size=bigSize,
                                        family=fontName,
                                        weight='bold')
        self.projDateFont = tkFont.Font(size=smallSize, family=fontName)
        self.projDelFont = tkFont.Font(size=smallSize,
                                       family=fontName,
                                       weight='bold')
        self.manager = Manager()

        self.filter = tk.StringVar()
        self.filterBox = None
        self.addActionsFrame()

        self.columnconfigure(0, weight=1)
        self.rowconfigure(1, weight=1)
        text = TaggedText(self, width=40, height=15, bd=0, bg='white')
        text.grid(row=1, columnspan=2, column=0, sticky='news')

        self.createProjectList(text)
        text.setReadOnly(True)
        self.text = text
        self.filterBox.focus_set()
def main():
    args = get_parser().parse_args()
    projName = args.project

    # Create a manager and load the project
    manager = Manager()

    cwd = os.getcwd()  # Keep current directory to restore it later
    project = manager.loadProject(projName)

    # Export protocols as a dict
    jsonDict = project.getProtocolsDict()

    os.chdir(cwd)  # Restore after project load

    if args.output:
        print("Writing workflow to file: ", args.output)
        with open(args.output, 'w') as f:
            json.dump(list(jsonDict.values()),
                      f,
                      indent=4,
                      separators=(',', ': '))
    else:
        print(
            json.dumps(list(jsonDict.values()),
                       indent=4,
                       separators=(',', ': ')))
    def testExportSteps(self):

        manager = Manager()
        stepsStats = dict()

        for project in manager.listProjects():
            projectFolder = manager.getProjectPath(project.projName)

            project = Project(pyworkflow.Config.getDomain(), projectFolder)
            project.load()

            for prot in project.getRuns():
                protName = prot.getClassName()
                for step in prot.loadSteps():
                    stepName = "-".join([
                        prot.getClassPackageName(), protName,
                        step.funcName.get()
                    ])
                    stepSeconds = step.getElapsedTime().total_seconds()
                    if stepName not in stepsStats:
                        stepsStats[stepName] = []

                    stepsStats[stepName].append(stepSeconds)

        # average steps
        for name in stepsStats:
            plugin, protClass, step = name.split("-")
            stepStats = stepsStats[name]
            mean = sum(stepStats) / len(stepStats)
            # DO not send mean values if higher than a threshold to keep chart in a decent visualization range
            # We are loosing long duration steps, probably due to large
            if mean < 30:
                bm = Benchmark(time=mean, name="-".join([protClass, step]))
                codespeed.sendData(bm)
Beispiel #4
0
 def __init__(self):
     projName = self.__class__.__name__
     manager = Manager()
     if manager.hasProject(projName):
         self.project = manager.loadProject(projName)
     else:
         self.project = manager.createProject(projName)
         # Use graph view as default
         settings = self.project.getSettings()
         settings.setRunsView(1)  # graph view
         settings.write()
         self.loadWorkflow()
Beispiel #5
0
def setupTestProject(cls):
    """ Create and setup a Project for a give Test class. """
    projName = cls.__name__
    if os.environ.get('SCIPION_TEST_CONTINUE', None) == '1':
        proj = Manager().loadProject(projName)
    else:
        proj = Manager().createProject(
            projName)  # Now it will be loaded if exists

    cls.outputPath = proj.path
    # Create project does not change the working directory anymore
    os.chdir(cls.outputPath)
    cls.projName = projName
    cls.proj = proj
Beispiel #6
0
    def _select(self):
        projName = self.projName.get().strip()
        projLocation = self.projLocation.get().strip()
        copyFiles = self.tkCheckVar.get() != 0
        searchLocation = self.searchLocation.get().strip()
        manager = Manager()

        # If project name is empty we will use the same name as the source
        if not projName:
            projName = os.path.basename(projLocation)

        errorMessage = ''

        # Validate that project location is not empty
        if not projLocation:
            errorMessage = "Project location is empty\n"

        # Validate that project location exists
        elif not os.path.exists(projLocation):
            errorMessage += "Project location does not exist\n"

        # Validate that project location is a directory
        elif not os.path.isdir(projLocation):
            errorMessage += "Project location is not a directory\n"
        # Validate that the project location is a scipion project folder
        elif not os.path.exists(os.path.join(projLocation,
                                             Project.getDbName())):
            errorMessage += "Project location doesn't look like a scipion folder\n"

        # Validate that there isn't already a project with the same name
        if manager.hasProject(projName):
            errorMessage += "Project [%s] already exists\n" % projName

        # Validate that search location exists
        if searchLocation:
            if not os.path.exists(searchLocation):
                errorMessage += "Raw files location does not exist\n"
            # Validate that search location is a directory
            elif not os.path.isdir(searchLocation):
                errorMessage += "Raw files location is not a directory\n"

        if errorMessage:
            showError("Validation error", errorMessage, self.root)
        else:
            self.parent.importProject(projLocation, copyFiles, projName,
                                      searchLocation)
            self.close()
Beispiel #7
0
    def __init__(self, parent, windows, **args):
        tk.Frame.__init__(self, parent, bg='white', **args)
        self.windows = windows
        self.manager = windows.manager
        self.root = windows.root

        #tkFont.Font(size=12, family='verdana', weight='bold')
        bigSize = pwgui.cfgFontSize + 2
        smallSize = pwgui.cfgFontSize - 2
        fontName = pwgui.cfgFontName

        self.projNameFont = tkFont.Font(size=bigSize,
                                        family=fontName,
                                        weight='bold')
        self.projDateFont = tkFont.Font(size=smallSize, family=fontName)
        self.projDelFont = tkFont.Font(size=smallSize,
                                       family=fontName,
                                       weight='bold')
        self.manager = Manager()

        # Add the create project button
        btnFrame = tk.Frame(self, bg='white')
        btn = HotButton(btnFrame,
                        text=Message.LABEL_CREATE_PROJECT,
                        font=self.projNameFont,
                        command=self._onCreateProject)
        btn.grid(row=0, column=0, sticky='nw', padx=10, pady=10)

        # Add the Import project button
        btn = Button(btnFrame,
                     text=Message.LABEL_IMPORT_PROJECT,
                     font=self.projNameFont,
                     command=self._onImportProject)
        btn.grid(row=0, column=1, sticky='nw', padx=10, pady=10)

        btnFrame.grid(row=0, column=0, sticky='nw')

        self.columnconfigure(0, weight=1)
        self.rowconfigure(1, weight=1)
        text = TaggedText(self, width=40, height=15, bd=0, bg='white')
        text.grid(row=1, columnspan=2, column=0, sticky='news')

        self.createProjectList(text)
        text.setReadOnly(True)
        self.text = text
Beispiel #8
0
def main():
    if len(sys.argv) != 3:
        usage("Incorrect number of input parameters")

    projName = sys.argv[1]
    searchDir = os.path.abspath(sys.argv[2])

    # Create a new project
    manager = Manager()

    if not manager.hasProject(projName):
        usage("Nonexistent project: %s" % pwutils.red(projName))

    if not os.path.exists(searchDir):
        usage("Nonexistent SEARCH_DIR: %s" % pwutils.red(searchDir))

    project = manager.loadProject(projName)

    project.fixLinks(searchDir)
    def _writeSubset(self, subset):
        """ Generated the output of this subset. """
        newSubsetName = 'outputParticles_%03d' % self._counter
        self.info("Creating new subset: %s" % newSubsetName)
        subset.write()
        self._defineOutputs(**{newSubsetName: subset})
        self._defineTransformRelation(self.inputParticles, subset)
        # The following is required to commit the changes to the database
        self._store(subset)
        subset.close()

        manager = Manager()
        project = manager.loadProject(self.getProject().getName())
        input2D = self.input2dProtocol.get()
        copyProt = project.copyProtocol(project.getProtocol(input2D.getObjId()))
        copyProt.inputParticles.set(project.getProtocol(self.getObjId()))
        copyProt.inputParticles.setExtended(newSubsetName)
        project.scheduleProtocol(copyProt, self._runPrerequisites)
        # Next schedule will be after this one
        self._runPrerequisites.append(copyProt.getObjId())
Beispiel #10
0
def setupTestProject(cls, writeLocalConfig=False):
    """ Create and setup a Project for a give Test class. """
    projName = cls.__name__
    hostsConfig = None

    if writeLocalConfig:
        hostsConfig = '/tmp/hosts.conf'
        print("Writing local config: %s" % hostsConfig)
        import pyworkflow.protocol as pwprot
        pwprot.HostConfig.writeBasic(hostsConfig)

    if os.environ.get('SCIPION_TEST_CONTINUE', None) == '1':
        proj = Manager().loadProject(projName)
    else:
        proj = Manager().createProject(projName, hostsConf=hostsConfig)

    cls.outputPath = proj.path
    # Create project does not change the working directory anymore
    os.chdir(cls.outputPath)
    cls.projName = projName
    cls.proj = proj
Beispiel #11
0
    def __init__(self, config, **kwargs):

        windowTitle = config.get(WINDOWS_TITLE, 'Scipion wizard')
        try:
            title = '%s (%s on %s)' % (windowTitle, pwutils.getLocalUserName(),
                                       pwutils.getLocalHostName())
        except Exception:
            title = windowTitle

        settings = ProjectSettings()
        self.generalCfg = settings.getConfig()

        self.config = config
        ProjectBaseWindow.__init__(self, title, minsize=(400, 550), **kwargs)
        self.viewFuncs = {VIEW_WIZARD: BoxWizardView}
        self.manager = Manager()
        self.switchView(VIEW_WIZARD)
def openProject(projectName):
    """ Opens a scipion project:

    :param projectName: Name of a existing project to open,
            or "here" to create a project in the current working dir,
            or "last" to open the most recent project

    """
    manager = Manager()
    projName = os.path.basename(projectName)

    # Handle special name 'here' to create a project
    # from the current directory
    if projName == 'here':
        cwd = Config.SCIPION_CWD

        if " " in cwd:
            print("Projects can't have spaces in the name: %s" % cwd)
            sys.exit(1)

        print("\nYou are trying to create a project here:", pwutils.cyan(cwd))

        if os.listdir(cwd):
            print(pwutils.red('\nWARNING: this folder is not empty!!!'))
        key = input("\nDo you want to create a project here? [y/N]?")

        if key.lower().strip() != 'y':
            print("\nAborting...")
            sys.exit(0)
        else:
            print("\nCreating project....")
            projName = os.path.basename(cwd)
            projDir = os.path.dirname(cwd)
            manager.createProject(projName, location=projDir)

    elif projName == 'last':  # Get last project
        projects = manager.listProjects()
        if not projects:
            sys.exit("No projects yet, cannot open the last one.")
        projName = projects[0].projName

    projPath = manager.getProjectPath(projName)
    projWindow = ProjectWindow(projPath)

    projWindow.show()
Beispiel #13
0
n = len(sys.argv)

if n > 3:
    usage("Incorrect number of input parameters")

delete = '--delete' in sys.argv

arg1 = sys.argv[1]
if n > 1 and arg1 != '--delete':
    customUserData = arg1
else:
    customUserData = pw.Config.SCIPION_USER_DATA

print("Loading projects from:\n %s" % customUserData)

# Create a new project
manager = Manager(workspace=customUserData)

for projInfo in manager.listProjects():
    projName = projInfo.getName()
    proj = manager.loadProject(projName)
    settings = proj.getSettings()

    leftTime = proj.getLeftTime()
    if (leftTime is not None and leftTime.days < 0):
        if delete:
            print("Deleting: %s (%s) " % (projName, leftTime))
            manager.deleteProject(projName)
        else:
            print("Should delete: %s (%s)" % (projName, leftTime))
Beispiel #14
0
    def __init__(self, parent, windows, **kwargs):
        tk.Frame.__init__(self, parent, bg='white', **kwargs)
        self.windows = windows
        self.manager = windows.manager
        self.root = windows.root
        self.vars = {}
        self.checkvars = []
        self.microscope = None
        self.configDict = self.windows.config
        # Regular expression to validate username and sample name
        self.re = re.compile('\A[a-zA-Z0-9][a-zA-Z0-9_-]+[a-zA-Z0-9]\Z')

        # tkFont.Font(size=12, family='verdana', weight='bold')
        bigSize = pwgui.cfgFontSize + 2
        smallSize = pwgui.cfgFontSize - 2
        fontName = pwgui.cfgFontName

        self.bigFont = tkFont.Font(size=bigSize, family=fontName)
        self.bigFontBold = tkFont.Font(size=bigSize,
                                       family=fontName,
                                       weight='bold')

        self.projDateFont = tkFont.Font(size=smallSize, family=fontName)
        self.projDelFont = tkFont.Font(size=smallSize,
                                       family=fontName,
                                       weight='bold')
        self.manager = Manager()

        # Header section
        headerFrame = tk.Frame(self, bg='white')
        headerFrame.grid(row=0, column=0, sticky='new')
        headerText = "Create New Session"

        headerText += "  %s" % pwutils.prettyTime(dateFormat='%Y-%m-%d')

        label = tk.Label(headerFrame,
                         text=headerText,
                         font=self.bigFontBold,
                         borderwidth=0,
                         anchor='nw',
                         bg='white',
                         fg=pwgui.Color.DARK_GREY_COLOR)
        label.grid(row=0, column=0, sticky='nw', padx=(20, 5), pady=10)

        # Body section
        bodyFrame = tk.Frame(self, bg='white')
        bodyFrame.grid(row=1, column=0, sticky='news')
        self._fillContent(bodyFrame)

        # Add the create project button
        btnFrame = tk.Frame(self, bg='white')
        btn = HotButton(btnFrame,
                        text="Create New Session",
                        activebackground="dark grey",
                        activeforeground='black',
                        font=self.bigFontBold,
                        command=self._onAction)
        btn.grid(row=0, column=1, sticky='ne', padx=10, pady=10)

        # Add the Cancel project button
        btn = Button(btnFrame,
                     Message.LABEL_BUTTON_CANCEL,
                     Icon.ACTION_CLOSE,
                     font=self.bigFontBold,
                     command=self.windows.close)
        btn.grid(row=0, column=0, sticky='ne', padx=10, pady=10)

        btnFrame.grid(row=2, column=0, sticky='sew')
        btnFrame.columnconfigure(0, weight=1)

        self.columnconfigure(0, weight=1)
        self.rowconfigure(1, weight=1)
if n < 2:
    usage("This script accepts 1 mandatory parameter: the project name.")
elif n > 2 and sys.argv[2] != '--ignore':
    usage("The protocol class names to be ignored must be after a '--ignore' flag.")

projName = sys.argv[1]

# This fails, since it is triggering matplotlib.pyplot and then import error happens:
# ... pyworkflow/gui/no-tkinter/_tkinter.py: invalid ELF header. If we want this back we might need to
# invest some time "faking" tkinter again for python3.
# path = pw.join('gui', 'no-tkinter')
# sys.path.insert(1, path)

# Create a new project
manager = Manager()

if not manager.hasProject(projName):
    usage("There is no project with this name: %s"
          % pwutils.red(projName))

# the project may be a soft link which may be unavailable to the cluster so get the real path
try:
    projectPath = os.readlink(manager.getProjectPath(projName))
except:
    projectPath = manager.getProjectPath(projName)

project = Project(pw.Config.getDomain(), projectPath)
project.load()

runs = project.getRuns()
Beispiel #16
0
        This script show (or edit) some of the configuration of the project.
        Use readOnly=True (or False) to set/unset read only property
        Use lifeTime=X for setting X hours or None to unset life time of the project.
    """ % error
    sys.exit(1)


n = len(sys.argv)

if n < 2 or n > 4:
    usage("Incorrect number of input parameters")

# Load the given project
projectsDir = os.path.join(pw.Config.SCIPION_USER_DATA, 'projects')
projName = sys.argv[1]
manager = Manager()
project = manager.loadProject(projName)

if project is None:
    usage("Project '%s' does not exist in: \n  %s" % (projName, projectsDir))

setReadOnly = False
setLifeTime = False

for arg in sys.argv:
    if arg.startswith('readOnly='):
        setReadOnly = True
        value = arg.split('readOnly=')[1]
        b = Boolean(value=value)
        readOnlyValue = b.get()
    elif arg.startswith('lifeTime='):
Beispiel #17
0

ALL_TUTORIALS = OrderedDict([('intro', TutorialIntro),
                             ('betagal', TutorialBetagal)])

if __name__ == '__main__':

    def printUsage(msg):
        if msg:
            print("ERROR: ", msg)
            
        print("\nUSAGE: scipion tutorial [TUTORIAL_NAME]")
        print("\nwhere TUTORIAL_NAME can be:")
        print("\n".join([' %s' % k for k in ALL_TUTORIALS.keys()]))

    if len(sys.argv) == 2:
        manager = Manager()
        tutorialName = sys.argv[1]
        
        if tutorialName not in ALL_TUTORIALS:
            printUsage("Invalid tutorial '%s'." % tutorialName)
        else:
            # Instantiate the proper tutorial class
            tutorial = ALL_TUTORIALS[tutorialName]()
        
            projWindow = ProjectWindow(tutorial.project.getName())
            projWindow.show()
    else:
        msg = 'Too many arguments.' if len(sys.argv) > 2 else ''
        printUsage(msg)
Beispiel #18
0
    def _createSessionScipionProject(self, session):
        microscope = session.getMicroscope()
        camera = session.getCamera()
        path = session.getPath()

        manager = Manager()
        project = manager.createProject(session.getScipionProjectName(),
                                        location=path)

        # A custom workflow can be selected and then we will not modify it
        if 'workflow' in session.preprocessing:
            jsonFile = session.preprocessing['workflow']
            project.loadProtocols(jsonFile)
            return

        # If not, then we will customize the generic workflow

        jsonFile = getDataFile('workflows/scipion3_generic_workflow.json')
        project.loadProtocols(jsonFile)
        runsGraph = project.getRunsGraph(refresh=True)

        # Create a dict with class names and nodes for easier access
        nodeNames = {}
        for n in runsGraph.getNodes():
            p = n.run
            if p is not None:
                nodeNames[p.getClassName()] = n

        nodeImport = nodeNames['ProtImportMovies']
        nodeCompress = nodeNames['ProtRelionCompressMovies']
        nodeRelionMc = nodeNames['ProtRelionMotioncor']
        nodeMc = nodeNames['ProtMotionCorr']
        nodeCtffind = nodeNames['CistemProtCTFFind']
        nodeGctf = nodeNames['ProtGctf']

        # Update import parameters
        protImport = nodeImport.run
        protImport.setAttributesFromDict(
            {
                'filesPath': path,
                'filesPattern': CAMERA_SETTINGS[camera][PATTERN]
            },
            setBasic=False)
        project.saveProtocol(protImport)

        def _moveChilds(parent, newParent, inputName, outputName):
            for c in parent.getChilds():
                prot = c.run
                inputObj = getattr(prot, inputName)
                inputObj.set(newParent.run)
                inputObj.setExtended(outputName)
                project.saveProtocol(prot)

        # There is no need to compress if we are not using the
        # falcon3, let's remove that step from the workflow
        # and update the input for the dependent steps
        if camera != FALCON3:
            _moveChilds(nodeCompress, nodeImport, 'inputMovies',
                        'outputMovies')
            project.deleteProtocol(nodeCompress.run)

        opts = session.preprocessing['options']
        if opts['Motion correction'] == 'motioncor2':
            _moveChilds(nodeRelionMc, nodeMc, 'inputMicrographs',
                        'outputMicrographsDoseWeighted')
            protCtffind = nodeCtffind.run
            protCtffind.usePowerSpectra.set(False)
            project.saveProtocol(protCtffind)

        if opts['CTF estimation'] == 'gctf':
            _moveChilds(nodeCtffind, nodeGctf, "ctfRelations", "outputCTF")
def usage(error):
    print("""
    ERROR: %s
    
    Usage: fixlinks.py PROJECT SEARCH_DIR
        PROJECT: provide the project name to fix broken links in the imports.
        SEARCH_DIR: provide a directory where to look for the files.
        and fix the links.    
    """ % error)
    sys.exit(1)


if len(sys.argv) != 3:
    usage("Incorrect number of input parameters")

projName = sys.argv[1]
searchDir = os.path.abspath(sys.argv[2])

# Create a new project
manager = Manager()

if not manager.hasProject(projName):
    usage("Nonexistent project: %s" % pwutils.red(projName))

if not os.path.exists(searchDir):
    usage("Nonexistent SEARCH_DIR: %s" % pwutils.red(searchDir))

project = manager.loadProject(projName)

project.fixLinks(searchDir)
    def monitorStep(self):

        self._runPrerequisites = []
        manager = Manager()
        project = manager.loadProject(self.getProject().getName())

        percentage = [1.14, 2.29, 3.44, 5.74, 9.19, 14.94, 24.13, 39.08]
        numGlobalIters = len(percentage) + 2
        self.consecutiveBimodal = 2
        self.listConsecutiveBimodal = []

        targetResolution = self.minimumTargetResolution.get()

        #Global iterations
        for i in range(numGlobalIters):

            self.convertInputStep(percentage, i)

            print("Target resolution - group %s: %f " %
                  (chr(65 + i), float(targetResolution)))
            sys.stdout.flush()

            if i == 0:
                previousProtVol = self
                namePreviousVol = 'outputVolumesInit'
            else:
                previousProtVol = newHighRes
                namePreviousVol = 'outputVolume'

            newHighRes = project.newProtocol(
                XmippProtReconstructHighRes,
                objLabel='HighRes - group %s' % chr(65 + i),
                symmetryGroup=self.symmetryGroup.get(),
                numberOfIterations=1,
                particleRadius=self.particleRadius.get(),
                maximumTargetResolution=targetResolution,
                alignmentMethod=XmippProtReconstructHighRes.GLOBAL_ALIGNMENT,
                angularMaxShift=self.maxShift.get(),
                angularMinTilt=self.angularMinTilt.get(),
                angularMaxTilt=self.angularMaxTilt.get(),
                postAdHocMask=self.postAdHocMask.get(),
                postSymmetryWithinMask=self.postSymmetryWithinMask.get(),
                postSymmetryWithinMaskType=self.postSymmetryWithinMaskType.get(
                ),
                postSymmetryWithinMaskMask=self.postSymmetryWithinMaskMask.get(
                ),
                postSymmetryHelical=self.postSymmetryHelical.get(),
                postSymmetryHelicalRadius=self.postSymmetryHelicalRadius.get(),
                postSymmetryHelicalDihedral=self.postSymmetryHelicalDihedral.
                get(),
                postSymmetryHelicalMinRot=self.postSymmetryHelicalMinRot.get(),
                postSymmetryHelicalMaxRot=self.postSymmetryHelicalMaxRot.get(),
                postSymmetryHelicalMinZ=self.postSymmetryHelicalMinZ.get(),
                postSymmetryHelicalMaxZ=self.postSymmetryHelicalMaxZ.get(),
                postScript=self.postScript.get(),
                postSignificantDenoise=self.postSignificantDenoise.get(),
                postFilterBank=self.postFilterBank.get(),
                postLaplacian=self.postLaplacian.get(),
                postDeconvolve=self.postDeconvolve.get(),
                postSoftNeg=self.postSoftNeg.get(),
                postSoftNegK=self.postSoftNegK.get(),
                postDifference=self.postDifference.get(),
                numberOfMpi=self.numberOfMpi.get(),
                useGpu=self.useGpu.get(),
                gpuList=self.gpuList.get())

            previousProtPart = self
            namePreviousParticles = 'outputParticles%s' % chr(65 + i)
            newHighRes.inputParticles.set(previousProtPart)
            newHighRes.inputParticles.setExtended(namePreviousParticles)
            newHighRes.inputVolumes.set(previousProtVol)
            newHighRes.inputVolumes.setExtended(namePreviousVol)

            project.scheduleProtocol(newHighRes)

            # Next schedule will be after this one
            self._runPrerequisites.append(newHighRes.getObjId())
            self.childs.append(newHighRes)

            finishedIter = False
            while finishedIter == False:
                time.sleep(15)
                newHighRes = self._updateProtocol(newHighRes)
                if newHighRes.isFailed() or newHighRes.isAborted():
                    raise Exception('XmippProtReconstructHighRes has failed')
                if newHighRes.isFinished():
                    finishedIter = True

            fnDir = newHighRes._getExtraPath("Iter%03d" % 1)
            fnFSCs = open(self._getExtraPath('fnFSCs.txt'), 'a')
            fnFSCs.write(join(fnDir, "fsc.xmd") + " \n")
            fnFSCs.close()
            targetResolution = self.checkOutputsStep(newHighRes, i, False)
            targetResolution = max(targetResolution,
                                   self.maximumTargetResolution.get())

            if i >= 7:  #We are in the last three iterations
                #Check the output particles and remove all the disabled ones
                fnOutParticles = newHighRes._getPath('angles.xmd')
                params = '-i %s --query select "enabled==1"' % (fnOutParticles)
                self.runJob("xmipp_metadata_utilities", params, numberOfMpi=1)
                fnFinal = self._getExtraPath('inputLocalHighRes1.xmd')
                if i == 7:
                    copy(fnOutParticles, fnFinal)
                else:
                    params = ' -i %s --set union %s -o %s' % (
                        fnFinal, fnOutParticles, fnFinal)
                    self.runJob("xmipp_metadata_utilities",
                                params,
                                numberOfMpi=1)

                    if i == 9:
                        outputinputSetOfParticles = self._createSetOfParticles(
                        )
                        outputinputSetOfParticles.copyInfo(
                            self.inputParticles.get())
                        readSetOfParticles(fnFinal, outputinputSetOfParticles)
                        self._defineOutputs(
                            outputParticlesLocal1=outputinputSetOfParticles)
                        self._store(outputinputSetOfParticles)

        #Local iterations
        numLocalIters = 5
        for i in range(numLocalIters):

            if i > 2:
                minPrevRes = prevTargetResolution
                if targetResolution > minPrevRes:
                    print("Target resolution is stuck")
                    sys.stdout.flush()
                    break

            prevTargetResolution = targetResolution

            print("Target resolution - INPUT local %d: %f " %
                  ((i + 1), float(targetResolution)))
            sys.stdout.flush()
            previousProtVol = newHighRes
            namePreviousVol = 'outputVolume'
            #calling highres local with the new input set
            newHighRes = project.newProtocol(
                XmippProtReconstructHighRes,
                objLabel='HighRes - local %d' % (i + 1),
                symmetryGroup=self.symmetryGroup.get(),
                numberOfIterations=1,
                particleRadius=self.particleRadius.get(),
                maximumTargetResolution=targetResolution,
                alignmentMethod=XmippProtReconstructHighRes.LOCAL_ALIGNMENT,
                angularMaxShift=self.maxShift.get(),
                angularMinTilt=self.angularMinTilt.get(),
                angularMaxTilt=self.angularMaxTilt.get(),
                postAdHocMask=self.postAdHocMask.get(),
                postSymmetryWithinMask=self.postSymmetryWithinMask.get(),
                postSymmetryWithinMaskType=self.postSymmetryWithinMaskType.get(
                ),
                postSymmetryWithinMaskMask=self.postSymmetryWithinMaskMask.get(
                ),
                postSymmetryHelical=self.postSymmetryHelical.get(),
                postSymmetryHelicalRadius=self.postSymmetryHelicalRadius.get(),
                postSymmetryHelicalDihedral=self.postSymmetryHelicalDihedral.
                get(),
                postSymmetryHelicalMinRot=self.postSymmetryHelicalMinRot.get(),
                postSymmetryHelicalMaxRot=self.postSymmetryHelicalMaxRot.get(),
                postSymmetryHelicalMinZ=self.postSymmetryHelicalMinZ.get(),
                postSymmetryHelicalMaxZ=self.postSymmetryHelicalMaxZ.get(),
                postScript=self.postScript.get(),
                postSignificantDenoise=self.postSignificantDenoise.get(),
                postFilterBank=self.postFilterBank.get(),
                postLaplacian=self.postLaplacian.get(),
                postDeconvolve=self.postDeconvolve.get(),
                postSoftNeg=self.postSoftNeg.get(),
                postSoftNegK=self.postSoftNegK.get(),
                postDifference=self.postDifference.get(),
                numberOfMpi=self.numberOfMpi.get(),
                useGpu=self.useGpu.get(),
                gpuList=self.gpuList.get())
            newHighRes.inputParticles.set(self)
            namePreviousParticles = 'outputParticlesLocal%d' % (i + 1)
            newHighRes.inputParticles.setExtended(namePreviousParticles)
            newHighRes.inputVolumes.set(previousProtVol)
            newHighRes.inputVolumes.setExtended(namePreviousVol)

            project.scheduleProtocol(newHighRes, self._runPrerequisites)
            # Next schedule will be after this one
            self._runPrerequisites.append(newHighRes.getObjId())
            self.childs.append(newHighRes)

            finishedIter = False
            while finishedIter == False:
                time.sleep(15)
                newHighRes = self._updateProtocol(newHighRes)
                if newHighRes.isFailed() or newHighRes.isAborted():
                    raise Exception('XmippProtReconstructHighRes has failed')
                if newHighRes.isFinished():
                    finishedIter = True

            fnDir = newHighRes._getExtraPath("Iter%03d" % 1)
            fnFSCs = open(self._getExtraPath('fnFSCs.txt'), 'a')
            fnFSCs.write(join(fnDir, "fsc.xmd") + " \n")
            fnFSCs.close()
            targetResolution = self.checkOutputsStep(newHighRes,
                                                     numGlobalIters + i, True)
            targetResolution = max(targetResolution,
                                   self.maximumTargetResolution.get())

            #Check the output particles and remove all the disabled ones
            fnOutParticles = newHighRes._getPath('angles.xmd')
            params = '-i %s --query select "enabled==1"' % (fnOutParticles)
            self.runJob("xmipp_metadata_utilities", params, numberOfMpi=1)
            fnFinal = self._getExtraPath('inputLocalHighRes%d.xmd' % (i + 2))
            copy(fnOutParticles, fnFinal)

            if i > 1:
                #including the number of particles as stoppping criteria
                mdFinal = emlib.MetaData(fnFinal)
                Nfinal = mdFinal.size()
                Ninit = self.inputParticles.get().getSize()
                if Nfinal < Ninit * 0.3:
                    print("Image set size too small", Nfinal, Ninit)
                    sys.stdout.flush()
                    break

            outputinputSetOfParticles = self._createSetOfParticles()
            outputinputSetOfParticles.copyInfo(self.inputParticles.get())
            readSetOfParticles(fnFinal, outputinputSetOfParticles)
            result = {
                'outputParticlesLocal%d' % (i + 2): outputinputSetOfParticles
            }
            self._defineOutputs(**result)
            self._store(outputinputSetOfParticles)
            #self = self._updateProtocol(self)

        self.createOutputStep(project)
n = len(sys.argv)

if n < 2 or n > 4:
    usage("Incorrect number of input parameters")

projName = sys.argv[1]

jsonFile = None if n < 3 else os.path.abspath(sys.argv[2])
location = None if n < 4 else sys.argv[3]

# This might not be working anymore for python3.
# I'm getting invalid ELF header triggered by matplotlib -->from . import _tkagg
# path = pw.join('gui', 'no-tkinter')
# sys.path.insert(1, path)

# Create a new project
manager = Manager()

if manager.hasProject(projName):
    usage("There is already a project with this name: %s" %
          pwutils.red(projName))

if jsonFile is not None and not os.path.exists(jsonFile):
    usage("Nonexistent json file: %s" % pwutils.red(jsonFile))

project = manager.createProject(projName, location=location)

if jsonFile is not None:
    protDict = project.loadProtocols(jsonFile)
    def monitorStep(self):

        self._runPrerequisites = []
        manager = Manager()
        project = manager.loadProject(self.getProject().getName())

        self.numIter = self.maxNumClasses.get()
        for iter in range(1, self.numIter):

            if iter == 1:
                self.convertInputStep()

                newSplitProt = project.newProtocol(
                    XmippProtSplitVolumeHierarchical,
                    objLabel='split volume hierarchical - iter %d' % iter,
                    symmetryGroup=self.symmetryGroup.get(),
                    angularSampling=self.angularSampling.get(),
                    angularDistance=self.angularDistance.get(),
                    maxShift=self.maxShift.get(),
                    directionalClasses=self.directionalClasses.get(),
                    homogeneize=self.homogeneize.get(),
                    targetResolution=self.targetResolution.get(),
                    class2dIterations=self.class2dIterations.get(),
                    splitVolume=self.splitVolume.get(),
                    Niter=self.Niter.get(),
                    Nrec=self.Nrec.get(),
                    useGpu=self.useGpu.get(),
                    gpuList=self.gpuList.get())

                previousSplitProt = self
                newSubsetNameSplitVol = 'outputVolumesInit'
                newSplitProt.inputVolume.set(previousSplitProt)
                newSplitProt.inputVolume.setExtended(newSubsetNameSplitVol)

                newSubsetNameSplitParts = 'outputParticlesInit'
                newSplitProt.inputParticles.set(previousSplitProt)
                newSplitProt.inputParticles.setExtended(
                    newSubsetNameSplitParts)

                project.scheduleProtocol(newSplitProt, self._runPrerequisites)
                # Next schedule will be after this one
                self._runPrerequisites.append(newSplitProt.getObjId())
                self.childs.append(newSplitProt)

                newSignificantProt = project.newProtocol(
                    XmippProtReconstructHeterogeneous,
                    objLabel='significant heterogeneity - iter %d' % iter,
                    symmetryGroup=self.symmetryGroup.get(),
                    particleRadius=self.particleRadius.get(),
                    targetResolution=self.targetResolution.get(),
                    useGpu=self.useGpu.get(),
                    gpuList=self.gpuList.get(),
                    numberOfIterations=self.numberOfIterations.get(),
                    nxtMask=self.nextMask.get(),
                    angularMinTilt=self.angularMinTilt.get(),
                    angularMaxTilt=self.angularMaxTilt.get(),
                    numberOfReplicates=self.numberOfReplicates.get(),
                    angularMaxShift=self.angularMaxShift.get(),
                    numberVotes=self.numberVotes.get(),
                    stochastic=self.stochastic.get(),
                    stochasticAlpha=self.stochasticAlpha.get(),
                    stochasticN=self.stochasticN.get())

                previousSignifProt = newSplitProt
                newSubsetNameSignifParts = 'outputParticlesInit'
                newSignificantProt.inputParticles.set(previousSplitProt)
                newSignificantProt.inputParticles.setExtended(
                    newSubsetNameSignifParts)

                newSubsetNameSignifVol = 'outputVolumes'
                newSignificantProt.inputVolumes.set(previousSignifProt)
                newSignificantProt.inputVolumes.setExtended(
                    newSubsetNameSignifVol)

                project.scheduleProtocol(newSignificantProt,
                                         self._runPrerequisites)
                # Next schedule will be after this one
                self._runPrerequisites.append(newSignificantProt.getObjId())
                self.childs.append(newSignificantProt)

            elif iter > 1 and not self.finished:

                newSplitProt = project.newProtocol(
                    XmippProtSplitVolumeHierarchical,
                    objLabel='split volume hierarchical - iter %d' % iter,
                    symmetryGroup=self.symmetryGroup.get(),
                    angularSampling=self.angularSampling.get(),
                    angularDistance=self.angularDistance.get(),
                    maxShift=self.maxShift.get(),
                    directionalClasses=self.directionalClasses.get(),
                    homogeneize=self.homogeneize.get(),
                    targetResolution=self.targetResolution.get(),
                    class2dIterations=self.class2dIterations.get(),
                    splitVolume=self.splitVolume.get(),
                    Niter=self.Niter.get(),
                    Nrec=self.Nrec.get(),
                    useGpu=self.useGpu.get(),
                    gpuList=self.gpuList.get())

                newSubsetNameSplitVol = 'outputAuxVolumes'
                newSplitProt.inputVolume.set(previousSplitProt)
                newSplitProt.inputVolume.setExtended(newSubsetNameSplitVol)

                newSubsetNameSplitParts = 'outputAuxParticles'
                newSplitProt.inputParticles.set(previousSplitProt)
                newSplitProt.inputParticles.setExtended(
                    newSubsetNameSplitParts)

                project.scheduleProtocol(newSplitProt, self._runPrerequisites)
                # Next schedule will be after this one
                self._runPrerequisites.append(newSplitProt.getObjId())
                self.childs.append(newSplitProt)

                newSignificantProt = project.newProtocol(
                    XmippProtReconstructHeterogeneous,
                    objLabel='significant heterogeneity - iter %d' % iter,
                    symmetryGroup=self.symmetryGroup.get(),
                    particleRadius=self.particleRadius.get(),
                    targetResolution=self.targetResolution.get(),
                    useGpu=self.useGpu.get(),
                    gpuList=self.gpuList.get(),
                    numberOfIterations=self.numberOfIterations.get(),
                    nxtMask=self.nextMask.get(),
                    angularMinTilt=self.angularMinTilt.get(),
                    angularMaxTilt=self.angularMaxTilt.get(),
                    numberOfReplicates=self.numberOfReplicates.get(),
                    angularMaxShift=self.angularMaxShift.get(),
                    numberVotes=self.numberVotes.get(),
                    stochastic=self.stochastic.get(),
                    stochasticAlpha=self.stochasticAlpha.get(),
                    stochasticN=self.stochasticN.get())

                previousSignifProt = newSplitProt
                newSubsetNameSignifParts = 'outputAuxParticles'
                newSignificantProt.inputParticles.set(previousSplitProt)
                newSignificantProt.inputParticles.setExtended(
                    newSubsetNameSignifParts)

                newSubsetNameSignifVol = 'outputVolumes'
                newSignificantProt.inputVolumes.set(previousSignifProt)
                newSignificantProt.inputVolumes.setExtended(
                    newSubsetNameSignifVol)

                project.scheduleProtocol(newSignificantProt,
                                         self._runPrerequisites)
                # Next schedule will be after this one
                self._runPrerequisites.append(newSignificantProt.getObjId())
                self.childs.append(newSignificantProt)

            if not self.finished:
                finishedIter = False
                while finishedIter == False:
                    time.sleep(15)
                    newSplitProt = self._updateProtocol(newSplitProt)
                    newSignificantProt = self._updateProtocol(
                        newSignificantProt)
                    if newSplitProt.isFailed() or newSplitProt.isAborted():
                        raise Exception(
                            'XmippProtSplitVolumeHierarchical has failed')
                    if newSignificantProt.isFailed(
                    ) or newSignificantProt.isAborted():
                        raise Exception(
                            'XmippProtReconstructHeterogeneous has failed')
                    if newSignificantProt.isFinished():
                        finishedIter = True
                        for classItem in newSignificantProt.outputClasses:
                            self.classListSizes.append(classItem.getSize())
                            self.classListIds.append(classItem.getObjId())
                            self.classListProtocols.append(newSignificantProt)

                finishedSubset = False
                finishedLast = False
                if iter != self.numIter - 1:
                    subsetProt = self.checkOutputsStep(project, iter)
                    while finishedSubset == False and not self.finished:
                        time.sleep(5)
                        subsetProt = self._updateProtocol(subsetProt)
                        if subsetProt.isFailed() or subsetProt.isAborted():
                            raise Exception(
                                'XmippMetaProtCreateSubset has failed')
                        if subsetProt.isFinished():
                            finishedSubset = True
                    previousSplitProt = subsetProt
                elif iter == self.numIter - 1:
                    outputMetaProt = self.createOutputStep(project)
                    while finishedLast == False:
                        time.sleep(5)
                        outputMetaProt = self._updateProtocol(outputMetaProt)
                        if outputMetaProt.isFailed():
                            raise Exception(
                                'XmippMetaProtCreateOutput has failed')
                        if outputMetaProt.isFinished():
                            finishedLast = True

            if self.finished and iter == self.numIter - 1:
                finishedLast = False
                outputMetaProt = self.createOutputStep(project)
                while finishedLast == False:
                    time.sleep(5)
                    outputMetaProt = self._updateProtocol(outputMetaProt)
                    if outputMetaProt.isFailed():
                        raise Exception('XmippMetaProtCreateOutput has failed')
                    if outputMetaProt.isFinished():
                        finishedLast = True

            if self.finished and iter < self.numIter - 1:
                continue
if n < 2 or n > 3:
    usage("Incorrect number of input parameters")

jsonFn = os.path.abspath(sys.argv[1])

now = datetime.now()
tempSpace = "editor-%s" % now.strftime('%Y%m%d-%H%M%S')
customUserData = os.path.join(pw.Config.SCIPION_USER_DATA, 'tmp', tempSpace)

pwutils.makePath(os.path.join(customUserData, 'projects'))

print("Loading projects from:\n", customUserData)

# Create a new project
manager = Manager(workspace=customUserData)

projName = os.path.basename(jsonFn)
proj = manager.createProject(projName)
projPath = manager.getProjectPath(proj.getShortName())
proj.loadProtocols(jsonFn)


class EditorProjectWindow(ProjectWindow):
    def close(self, e=None):
        try:
            print("Writing protocols to: ", jsonFn)
            proj.getRunsGraph(refresh=True)  # Build project runs graph
            proj.exportProtocols(proj.getRuns(), jsonFn)
            print("Deleting temporary folder: ", customUserData)
            pwutils.cleanPath(customUserData)
Beispiel #24
0
class ProjectsView(tk.Frame):
    def __init__(self, parent, windows, **args):
        tk.Frame.__init__(self, parent, bg='white', **args)
        self.windows = windows
        self.manager = windows.manager
        self.root = windows.root

        #tkFont.Font(size=12, family='verdana', weight='bold')
        bigSize = pwgui.cfgFontSize + 2
        smallSize = pwgui.cfgFontSize - 2
        fontName = pwgui.cfgFontName

        self.projNameFont = tkFont.Font(size=bigSize,
                                        family=fontName,
                                        weight='bold')
        self.projDateFont = tkFont.Font(size=smallSize, family=fontName)
        self.projDelFont = tkFont.Font(size=smallSize,
                                       family=fontName,
                                       weight='bold')
        self.manager = Manager()

        # Add the create project button
        btnFrame = tk.Frame(self, bg='white')
        btn = HotButton(btnFrame,
                        text=Message.LABEL_CREATE_PROJECT,
                        font=self.projNameFont,
                        command=self._onCreateProject)
        btn.grid(row=0, column=0, sticky='nw', padx=10, pady=10)

        # Add the Import project button
        btn = Button(btnFrame,
                     text=Message.LABEL_IMPORT_PROJECT,
                     font=self.projNameFont,
                     command=self._onImportProject)
        btn.grid(row=0, column=1, sticky='nw', padx=10, pady=10)

        btnFrame.grid(row=0, column=0, sticky='nw')

        self.columnconfigure(0, weight=1)
        self.rowconfigure(1, weight=1)
        text = TaggedText(self, width=40, height=15, bd=0, bg='white')
        text.grid(row=1, columnspan=2, column=0, sticky='news')

        self.createProjectList(text)
        text.setReadOnly(True)
        self.text = text

    def createProjectList(self, text):
        """Load the list of projects"""
        r = 0
        text.setReadOnly(False)
        text.clear()
        parent = tk.Frame(text, bg='white')
        parent.columnconfigure(0, weight=1)
        colors = ['white', '#EAEBFF']
        for i, p in enumerate(self.manager.listProjects()):
            try:
                project = self.manager.loadProject(p.getName(),
                                                   chdir=False,
                                                   loadAllConfig=False)
                # Add creation time to project info
                p.cTime = project.getCreationTime()
                # Add if it's a link
                p.isLink = project.isLink()
                # If it's a link, get the linked folder
                if p.isLink:
                    p.linkedFolder = os.path.realpath(project.path)
                frame = self.createProjectLabel(parent, p, color=colors[i % 2])
                frame.grid(row=r, column=0, padx=10, pady=5, sticky='new')
                r += 1
            except Exception, ex:
                print "ERROR loading project: %s" % p.getName()
                print ex
        text.window_create(tk.INSERT, window=parent)
        text.bindWidget(parent)
        text.setReadOnly(True)
Beispiel #25
0
# *
# **************************************************************************
"""
Launch main project window
"""
import pickle

import sys
import os

from pyworkflow.project import Manager, Label
from pyworkflow.gui.project import ProjectWindow

if __name__ == '__main__':

    manager = Manager()
    projName = os.path.basename(sys.argv[1])
    projPath = manager.getProjectPath(projName)

    projWindow = ProjectWindow(projPath)

    proj = projWindow.project
    sett = proj.getSettings()
    sett.setColorMode(sett.COLOR_MODE_LABELS)

    with open(proj.getPath('labels.pkl'), 'r') as f:
        labelsDict, colorsDict = pickle.load(f)

    for labelName, prots in labelsDict.iteritems():
        label = Label(name=labelName, color=colorsDict[labelName])
        sett.getLabels().addLabel(label)
class ProjectsView(tk.Frame):
    _PROJ_CONTAINER = "projectsframe"

    def __init__(self, parent, windows, **args):
        tk.Frame.__init__(self, parent, bg='white', **args)
        self.windows = windows
        self.manager = windows.manager
        self.root = windows.root

        # tkFont.Font(size=12, family='verdana', weight='bold')
        bigSize = pwgui.cfgFontSize + 2
        smallSize = pwgui.cfgFontSize - 2
        fontName = pwgui.cfgFontName

        self.projNameFont = tkFont.Font(size=bigSize,
                                        family=fontName,
                                        weight='bold')
        self.projDateFont = tkFont.Font(size=smallSize, family=fontName)
        self.projDelFont = tkFont.Font(size=smallSize,
                                       family=fontName,
                                       weight='bold')
        self.manager = Manager()

        self.filter = tk.StringVar()
        self.filterBox = None
        self.addActionsFrame()

        self.columnconfigure(0, weight=1)
        self.rowconfigure(1, weight=1)
        text = TaggedText(self, width=40, height=15, bd=0, bg='white')
        text.grid(row=1, columnspan=2, column=0, sticky='news')

        self.createProjectList(text)
        text.setReadOnly(True)
        self.text = text
        self.filterBox.focus_set()

    def addActionsFrame(self):
        """ Add the "toolbar" for actions like create project, import
         project or filter"""
        # Add the create project button
        bg = "white"
        btnFrame = tk.Frame(self, bg=bg)
        btn = HotButton(btnFrame,
                        text=Message.LABEL_CREATE_PROJECT,
                        font=self.projNameFont,
                        command=self._onCreateProject)
        btn.grid(row=0, column=0, sticky='nw', padx=10, pady=10)
        # Add the Import project button
        btn = Button(btnFrame,
                     text=Message.LABEL_IMPORT_PROJECT,
                     font=self.projNameFont,
                     command=self._onImportProject)
        btn.grid(row=0, column=1, sticky='nw', padx=10, pady=10)
        btnFrame.grid(row=0, column=0, sticky='nw')

        # Add a filter box
        # Add the Import project button
        btn = tk.Label(btnFrame, bg=bg, text="Filter:", font=self.projNameFont)
        btn.grid(row=0, column=2, sticky='nse', padx=10, pady=10)
        self.filterBox = tk.Entry(btnFrame,
                                  font=self.projNameFont,
                                  textvariable=self.filter)
        self.filterBox.grid(row=0, column=3, sticky='ne', padx=10, pady=12)
        self.filterBox.bind('<Return>', self._onFilter)
        self.filterBox.bind('<KP_Enter>', self._onFilter)

    def createProjectList(self, text):
        """Load the list of projects"""
        r = 0
        text.setReadOnly(False)
        text.clear()
        parent = tk.Frame(text, bg='white', name=self._PROJ_CONTAINER)
        parent.columnconfigure(0, weight=1)
        colors = ['white', '#EAEBFF']
        for i, p in enumerate(self.manager.listProjects()):
            try:
                # Add creation time to project info
                # Add if it's a link
                p.index = "index%s" % i

                # Consider the filter
                if not self._doesProjectMatchFilter(p):
                    continue

                frame = self.createProjectLabel(parent, p, color=colors[i % 2])
                frame.grid(row=r, column=0, padx=10, pady=5, sticky='new')
                r += 1
            except Exception as ex:
                print("ERROR loading project: %s" % p.getName())
                print(ex)
        text.window_create(tk.INSERT, window=parent)
        text.bindWidget(parent)
        text.setReadOnly(True)

    def createProjectLabel(self, parent, projInfo, color):
        frame = tk.Frame(parent, bg=color, name=projInfo.index)
        # ROW1
        # Project name
        label = tk.Label(frame,
                         text=projInfo.projName,
                         anchor='nw',
                         bg=color,
                         justify=tk.LEFT,
                         font=self.projNameFont,
                         cursor='hand1',
                         width=50)
        label.grid(row=0, column=0, padx=2, pady=2, sticky='nw')
        label.bind('<Button-1>', lambda e: self.openProject(projInfo.projName))

        # ROW2
        # Timestamp line
        dateMsg = '%s%s    %s%s' % (
            Message.LABEL_MODIFIED, prettyDate(projInfo.mTime),
            Message.LABEL_CREATED, prettyTime(projInfo.cTime, time=False))
        dateLabel = tk.Label(frame,
                             text=dateMsg,
                             font=self.projDateFont,
                             bg=color)
        dateLabel.grid(row=1, column=0, sticky='nw')
        # Delete action
        delLabel = tk.Label(frame,
                            text=Message.LABEL_DELETE_PROJECT,
                            font=self.projDelFont,
                            bg=color,
                            cursor='hand1')
        delLabel.grid(row=1, column=1, padx=10)
        delLabel.bind('<Button-1>', lambda e: self.deleteProject(projInfo))
        # Rename action
        mvLabel = tk.Label(frame,
                           text=Message.LABEL_RENAME_PROJECT,
                           font=self.projDelFont,
                           bg=color,
                           cursor='hand1')
        mvLabel.grid(row=1, column=2)
        mvLabel.bind('<Button-1>',
                     lambda e: self.renameProject(projInfo.projName))

        # ROW3
        if projInfo.isLink():
            linkMsg = 'link --> ' + projInfo.realPath()
            lblLink = tk.Label(frame,
                               text=linkMsg,
                               font=self.projDateFont,
                               bg=color,
                               fg='grey',
                               justify=tk.LEFT)
            lblLink.grid(row=2, column=0, columnspan=3, sticky='w')

        return frame

    def createNewProject(self, projName, projLocation):
        proj = self.manager.createProject(projName, location=projLocation)
        self.createProjectList(self.text)
        self.openProject(proj.getShortName())

    def _onCreateProject(self, e=None):
        projWindow = ProjectCreateWindow("Create project", self)
        projWindow.show()

    def _onImportProject(self, e=None):
        importProjWindow = ProjectImportWindow("Import project", self)
        importProjWindow.show()

    def _onFilter(self, e=None):
        self.createProjectList(self.text)

    def _setFocusToList(self, e=None):
        self.text.focus_set()

    def _doesProjectMatchFilter(self, project):
        """ Returns true if the project matches the filter"""
        # Lets' use the name anc creation date for now:
        searchString = "~".join([
            project.getName().lower(),
            prettyDate(project.mTime),
            prettyTime(project.cTime, time=False)
        ])

        return self.filter.get().lower() in searchString

    def importProject(self, projLocation, copyFiles, projName, searchLocation):

        self.manager.importProject(projLocation, copyFiles, projName,
                                   searchLocation)
        self.createProjectList(self.text)
        self.openProject(projName)

    def openProject(self, projName):
        from subprocess import Popen
        script = pw.join(pw.APPS, 'pw_project.py')
        Popen([pw.PYTHON, script, projName])

    def deleteProject(self, projInfo):

        projName = projInfo.projName

        if askYesNo(
                Message.TITLE_DELETE_PROJECT,
                "Project *%s*. " % projName + Message.MESSAGE_DELETE_PROJECT,
                self.root):
            self.manager.deleteProject(projName)

            #Delete the frame
            self.text.children[self._PROJ_CONTAINER].children[
                projInfo.index].grid_forget()

    def renameProject(self, projName):
        newName = askString("Rename project %s" % projName, "Enter new name:",
                            self.root)
        if not newName or newName == projName:
            return
        if self.manager.hasProject(newName):
            showError("Rename cancelled",
                      "Project name already exists: %s" % newName, self.root)
            return
        self.manager.renameProject(projName, newName)
        self.createProjectList(self.text)
Beispiel #27
0
pathToProj = os.path.abspath(sys.argv[1])

now = datetime.now()
tempSpace = "loading-%s" % now.strftime('%Y%m%d-%H%M%S')
customUserData = os.path.join(pw.Config.SCIPION_USER_DATA, 'tmp', tempSpace)

projectsDir = os.path.join(customUserData, 'projects')
pwutils.makePath(projectsDir)

print("Loading projects from:\n", projectsDir)

projName = os.path.basename(pathToProj)
pwutils.createAbsLink(pathToProj, os.path.join(projectsDir, projName))

# Create a new project
manager = Manager(workspace=customUserData)

proj = manager.loadProject(projName)
projPath = manager.getProjectPath(projName)


class EditorProjectWindow(ProjectWindow):
    def close(self, e=None):
        try:
            print("Deleting temporary folder: ", customUserData)
            pwutils.cleanPath(customUserData)
        except Exception as ex:
            print("Error: ", ex)
        ProjectWindow.close(self, e)

Beispiel #28
0
from pyworkflow.project import Manager
from pyworkflow.gui.project import ProjectWindow
import pyworkflow.utils as pwutils

if __name__ == '__main__':

    # Add callback for remote debugging if available.
    try:
        from rpdb2 import start_embedded_debugger
        from signal import signal, SIGUSR2
        signal(SIGUSR2, lambda sig, frame: start_embedded_debugger('a'))
    except ImportError:
        pass

    if len(sys.argv) > 1:
        manager = Manager()
        projName = os.path.basename(sys.argv[1])

        # Handle special name 'here' to create a project
        # from the current directory
        if projName == 'here':
            cwd = os.environ['SCIPION_CWD']
            print "\nYou are trying to create a project here:", pwutils.cyan(
                cwd)

            if os.listdir(cwd):
                print pwutils.red('\nWARNING: this folder is not empty!!!')
            key = raw_input("\nDo you want to create a project here? [y/N]?")

            if key.lower().strip() != 'y':
                print "\nAborting..."