本文整理汇总了Python中ilastik.shell.projectManager.ProjectManager.openProjectFile方法的典型用法代码示例。如果您正苦于以下问题:Python ProjectManager.openProjectFile方法的具体用法?Python ProjectManager.openProjectFile怎么用?Python ProjectManager.openProjectFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ilastik.shell.projectManager.ProjectManager
的用法示例。
在下文中一共展示了ProjectManager.openProjectFile方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: openProjectFile
# 需要导入模块: from ilastik.shell.projectManager import ProjectManager [as 别名]
# 或者: from ilastik.shell.projectManager.ProjectManager import openProjectFile [as 别名]
def openProjectFile(self, projectFilePath, force_readonly=False):
# Make sure all workflow sub-classes have been loaded,
# so we can detect the workflow type in the project.
import ilastik.workflows
try:
# Open the project file
hdf5File, workflow_class, readOnly = ProjectManager.openProjectFile(projectFilePath, force_readonly)
# If there are any "creation-time" command-line args saved to the project file,
# load them so that the workflow can be instantiated with the same settings
# that were used when the project was first created.
project_creation_args = []
if "workflow_cmdline_args" in hdf5File.keys():
if len(hdf5File["workflow_cmdline_args"]) > 0:
project_creation_args = map(str, hdf5File["workflow_cmdline_args"][...])
if workflow_class is None:
# If the project file has no known workflow, we assume pixel classification
import ilastik.workflows
workflow_class = ilastik.workflows.pixelClassification.PixelClassificationWorkflow
import warnings
warnings.warn( "Your project file ({}) does not specify a workflow type. "
"Assuming Pixel Classification".format( projectFilePath ) )
# Create our project manager
# This instantiates the workflow and applies all settings from the project.
self.projectManager = ProjectManager( self,
workflow_class,
headless=True,
workflow_cmdline_args=self._workflow_cmdline_args,
project_creation_args=project_creation_args )
self.projectManager._loadProject(hdf5File, projectFilePath, readOnly)
except ProjectManager.FileMissingError:
logger.error("Couldn't find project file: {}".format( projectFilePath ))
raise
except ProjectManager.ProjectVersionError:
# Couldn't open project. Try importing it.
oldProjectFilePath = projectFilePath
name, ext = os.path.splitext(oldProjectFilePath)
# Create a brand new project file.
projectFilePath = name + "_imported" + ext
logger.info("Importing project as '" + projectFilePath + "'")
hdf5File = ProjectManager.createBlankProjectFile(projectFilePath)
# For now, we assume that any imported projects are pixel classification workflow projects.
import ilastik.workflows
default_workflow = ilastik.workflows.pixelClassification.PixelClassificationWorkflow
# Create the project manager.
# Here, we provide an additional parameter: the path of the project we're importing from.
self.projectManager = ProjectManager( self,
default_workflow,
importFromPath=oldProjectFilePath,
headless=True,
workflow_cmdline_args=self._workflow_cmdline_args,
project_creation_args=self._workflow_cmdline_args )
self.projectManager._importProject(oldProjectFilePath, hdf5File, projectFilePath,readOnly = False)
示例2: HeadlessShell
# 需要导入模块: from ilastik.shell.projectManager import ProjectManager [as 别名]
# 或者: from ilastik.shell.projectManager.ProjectManager import openProjectFile [as 别名]
class HeadlessShell(object):
"""
For now, this class is just a stand-in for the GUI shell (used when running from the command line).
"""
def __init__(self):
self._applets = []
self.projectManager = ProjectManager()
self.currentImageIndex = -1
def addApplet(self, aplt):
self._applets.append(aplt)
self.projectManager.addApplet(aplt)
def changeCurrentInputImageIndex(self, newImageIndex):
if newImageIndex != self.currentImageIndex:
# Alert each central widget and viewer control widget that the image selection changed
for i in range(len(self._applets)):
self._applets[i].gui.setImageIndex(newImageIndex)
self.currentImageIndex = newImageIndex
def openProjectPath(self, projectFilePath):
try:
hdf5File, readOnly = self.projectManager.openProjectFile(projectFilePath)
self.projectManager.loadProject(hdf5File, projectFilePath, readOnly)
except ProjectManager.ProjectVersionError:
# Couldn't open project. Try importing it.
oldProjectFilePath = projectFilePath
name, ext = os.path.splitext(oldProjectFilePath)
projectFilePath = name + "_imported" + ext
logger.info("Importing project as '" + projectFilePath + "'")
projectFile = self.projectManager.createBlankProjectFile(projectFilePath)
self.projectManager.importProject(oldProjectFilePath, projectFile, projectFilePath)
示例3: openProjectFile
# 需要导入模块: from ilastik.shell.projectManager import ProjectManager [as 别名]
# 或者: from ilastik.shell.projectManager.ProjectManager import openProjectFile [as 别名]
def openProjectFile(self, projectFilePath):
# Make sure all workflow sub-classes have been loaded,
# so we can detect the workflow type in the project.
import ilastik.workflows
try:
# Open the project file
hdf5File, workflow_class, _ = ProjectManager.openProjectFile(projectFilePath)
# Create our project manager
# This instantiates the workflow and applies all settings from the project.
self.projectManager = ProjectManager( workflow_class,
headless=True,
workflow_cmdline_args=self._workflow_cmdline_args )
self.projectManager._loadProject(hdf5File, projectFilePath, readOnly = False)
except ProjectManager.ProjectVersionError:
# Couldn't open project. Try importing it.
oldProjectFilePath = projectFilePath
name, ext = os.path.splitext(oldProjectFilePath)
# Create a brand new project file.
projectFilePath = name + "_imported" + ext
logger.info("Importing project as '" + projectFilePath + "'")
hdf5File = ProjectManager.createBlankProjectFile(projectFilePath)
# For now, we assume that any imported projects are pixel classification workflow projects.
import ilastik.workflows
default_workflow = ilastik.workflows.pixelClassification.PixelClassificationWorkflow
# Create the project manager.
# Here, we provide an additional parameter: the path of the project we're importing from.
self.projectManager = ProjectManager( default_workflow,
importFromPath=oldProjectFilePath,
headless=True )
self.projectManager._importProject(oldProjectFilePath, hdf5File, projectFilePath,readOnly = False)
示例4: openProjectPath
# 需要导入模块: from ilastik.shell.projectManager import ProjectManager [as 别名]
# 或者: from ilastik.shell.projectManager.ProjectManager import openProjectFile [as 别名]
def openProjectPath(self, projectFilePath):
try:
# Open the project file
hdf5File, readOnly = ProjectManager.openProjectFile(projectFilePath)
# Create our project manager
# This instantiates the workflow and applies all settings from the project.
self.projectManager = ProjectManager( self._workflowClass, hdf5File, projectFilePath, readOnly, headless=True )
except ProjectManager.ProjectVersionError:
# Couldn't open project. Try importing it.
oldProjectFilePath = projectFilePath
name, ext = os.path.splitext(oldProjectFilePath)
# Create a brand new project file.
projectFilePath = name + "_imported" + ext
logger.info("Importing project as '" + projectFilePath + "'")
hdf5File = ProjectManager.createBlankProjectFile(projectFilePath)
# Create the project manager.
# Here, we provide an additional parameter: the path of the project we're importing from.
self.projectManager = ProjectManager( self._workflowClass, hdf5File, projectFilePath, readOnly=False, importFromPath=oldProjectFilePath, headless=True )
示例5: IlastikShell
# 需要导入模块: from ilastik.shell.projectManager import ProjectManager [as 别名]
# 或者: from ilastik.shell.projectManager.ProjectManager import openProjectFile [as 别名]
#.........这里部分代码省略.........
projectFilePath = str(projectFilePath)
fileSelected = True
# Add extension if necessary
fileExtension = os.path.splitext(projectFilePath)[1].lower()
if fileExtension != '.ilp':
projectFilePath += ".ilp"
if os.path.exists(projectFilePath):
# Since we changed the file path, we need to re-check if we're overwriting an existing file.
message = "A file named '" + projectFilePath + "' already exists in this location.\n"
message += "Are you sure you want to overwrite it?"
buttons = QMessageBox.Yes | QMessageBox.Cancel
response = QMessageBox.warning(self, "Overwrite existing project?", message, buttons, defaultButton=QMessageBox.Cancel)
if response == QMessageBox.Cancel:
# Try again...
fileSelected = False
return projectFilePath
def onImportProjectActionTriggered(self):
"""
Import an existing project into a new file.
This involves opening the old file, saving it to a new file, and then opening the new file.
"""
logger.debug("Import Project Action")
if not self.ensureNoCurrentProject():
return
# Find the directory of the most recently *imported* project
mostRecentImportPath = PreferencesManager().get( 'shell', 'recently imported' )
if mostRecentImportPath is not None:
defaultDirectory = os.path.split(mostRecentImportPath)[0]
else:
defaultDirectory = os.path.expanduser('~')
# Select the paths to the ilp to import and the name of the new one we'll create
importedFilePath = self.getProjectPathToOpen(defaultDirectory)
if importedFilePath is not None:
PreferencesManager().set('shell', 'recently imported', importedFilePath)
defaultFile, ext = os.path.splitext(importedFilePath)
defaultFile += "_imported"
defaultFile += ext
newProjectFilePath = self.getProjectPathToCreate(defaultFile)
# If the user didn't cancel
if importedFilePath is not None and newProjectFilePath is not None:
self.importProject( importedFilePath, newProjectFilePath )
def importProject(self, originalPath, newProjectFilePath):
newProjectFile = self.projectManager.createBlankProjectFile(newProjectFilePath)
self.projectManager.importProject(originalPath, newProjectFile, newProjectFilePath)
self.updateShellProjectDisplay()
# Enable all the applet controls
self.enableWorkflow = True
self.updateAppletControlStates()
def getProjectPathToOpen(self, defaultDirectory):
"""
Return the path of the project the user wants to open (or None if he cancels).
"""
projectFilePath = QFileDialog.getOpenFileName(
self, "Open Ilastik Project", defaultDirectory, "Ilastik project files (*.ilp)",
options=QFileDialog.Options(QFileDialog.DontUseNativeDialog))
# If the user canceled, stop now
if projectFilePath.isNull():
return None
return str(projectFilePath)
def onOpenProjectActionTriggered(self):
logger.debug("Open Project action triggered")
# Make sure the user is finished with the currently open project
if not self.ensureNoCurrentProject():
return
# Find the directory of the most recently opened project
mostRecentProjectPath = PreferencesManager().get( 'shell', 'recently opened' )
if mostRecentProjectPath is not None:
defaultDirectory = os.path.split(mostRecentProjectPath)[0]
else:
defaultDirectory = os.path.expanduser('~')
projectFilePath = self.getProjectPathToOpen(defaultDirectory)
if projectFilePath is not None:
PreferencesManager().set('shell', 'recently opened', projectFilePath)
self.openProjectFile(projectFilePath)
def openProjectFile(self, projectFilePath):
try:
hdf5File, readOnly = self.projectManager.openProjectFile(projectFilePath)
except ProjectManager.ProjectVersionError,e:
QMessageBox.warning(self, "Old Project", "Could not load old project file: " + projectFilePath + ".\nPlease try 'Import Project' instead.")
except ProjectManager.FileMissingError:
QMessageBox.warning(self, "Missing File", "Could not find project file: " + projectFilePath)