Example #1
0
    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)
Example #2
0
    def handleAddStackButtonClicked(self):
        """
        The user clicked the "Import Stack Directory" button.
        """
        # Find the directory of the most recently opened image file
        mostRecentStackDirectory = PreferencesManager().get(
            'DataSelection', 'recent stack directory')
        if mostRecentStackDirectory is not None:
            defaultDirectory = os.path.split(mostRecentStackDirectory)[0]
        else:
            defaultDirectory = os.path.expanduser('~')

        # Launch the "Open File" dialog
        directoryName = QFileDialog.getExistingDirectory(
            self,
            "Image Stack Directory",
            defaultDirectory,
            options=QFileDialog.Options(QFileDialog.DontUseNativeDialog
                                        | QFileDialog.ShowDirsOnly))

        # If the user didn't cancel
        if not directoryName.isNull():
            PreferencesManager().set('DataSelection', 'recent stack directory',
                                     str(directoryName))
            globString = self.getGlobString(str(directoryName))
            if globString is not None:
                self.importStackFromGlobString(globString)
Example #3
0
 def hideEvent(self, event):
     """
     This GUI is being hidden because the user selected another applet or the window is closing.
     Save all preferences.
     """
     with PreferencesManager() as prefsMgr:
         prefsMgr.set( 'vigra watershed viewer', 'cache block shape', self.mainOperator.CacheBlockShape.value )
         prefsMgr.set( 'vigra watershed viewer', 'block padding', self.mainOperator.WatershedPadding.value )
     super( VigraWatershedViewerGui, self ).hideEvent(event)
Example #4
0
 def storeToPreferences(self):
     # Auto-save after we're done setting prefs
     with PreferencesManager() as prefsMgr:
         for group, shortcutDict in self.shortcuts.items():
             groupKeys = {}
             for shortcut, (desc, obj) in shortcutDict.items():
                 groupKeys[desc] = shortcut.key(
                 )  # QKeySequence is pickle-able
             prefsMgr.set(self.PreferencesGroup, group, groupKeys)
Example #5
0
 def hideEvent(self, event):
     """
     The user has selected another applet or is closing the whole app.
     Save all preferences.
     """
     with PreferencesManager() as prefsMgr:
         prefsMgr.set('labeling', 'paint brush size',
                      self.paintBrushSizeIndex)
         prefsMgr.set('labeling', 'eraser brush size', self.eraserSizeIndex)
     super(LabelingGui, self).hideEvent(event)
Example #6
0
    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)
Example #7
0
    def __init__(self, mainOperator):
        """
        """
        super(VigraWatershedViewerGui, self).__init__( mainOperator )
        self.mainOperator = mainOperator
        
        self.mainOperator.FreezeCache.setValue(True)
        self.mainOperator.OverrideLabels.setValue( { 0: (0,0,0,0) } )

        # Default settings (will be overwritten by serializer)
        self.mainOperator.InputChannelIndexes.setValue( [] )
        self.mainOperator.SeedThresholdValue.setValue( 0.0 )
        self.mainOperator.MinSeedSize.setValue( 0 )

        # Init padding gui updates
        blockPadding = PreferencesManager().get( 'vigra watershed viewer', 'block padding', 10)
        self.mainOperator.WatershedPadding.notifyDirty( self.updatePaddingGui )
        self.mainOperator.WatershedPadding.setValue(blockPadding)
        self.updatePaddingGui()
        
        # Init block shape gui updates
        cacheBlockShape = PreferencesManager().get( 'vigra watershed viewer', 'cache block shape', (256, 10))
        self.mainOperator.CacheBlockShape.notifyDirty( self.updateCacheBlockGui )
        self.mainOperator.CacheBlockShape.setValue( cacheBlockShape )
        self.updateCacheBlockGui()

        # Init seeds gui updates
        self.mainOperator.SeedThresholdValue.notifyDirty( self.updateSeedGui )
        self.mainOperator.SeedThresholdValue.notifyReady( self.updateSeedGui )
        self.mainOperator.SeedThresholdValue.notifyUnready( self.updateSeedGui )
        self.mainOperator.MinSeedSize.notifyDirty( self.updateSeedGui )
        self.updateSeedGui()
        
        # Init input channel gui updates
        self.mainOperator.InputChannelIndexes.notifyDirty( self.updateInputChannelGui )
        self.mainOperator.InputChannelIndexes.setValue( [0] )
        def subscribeToInputMetaChanges(multislot, index):
            multislot[index].notifyMetaChanged( self.updateInputChannelGui )
        self.mainOperator.InputImage.notifyInserted( bind(subscribeToInputMetaChanges) )
        self.updateInputChannelGui()
Example #8
0
    def handleAddStackFilesButtonClicked(self):
        """
        The user clicked the "Import Stack Files" button.
        """
        # Find the directory of the most recently opened image file
        mostRecentStackImageFile = PreferencesManager().get(
            'DataSelection', 'recent stack image')
        if mostRecentStackImageFile is not None:
            defaultDirectory = os.path.split(mostRecentStackImageFile)[0]
        else:
            defaultDirectory = os.path.expanduser('~')

        # Launch the "Open File" dialog
        fileNames = self.getImageFileNamesToOpen(defaultDirectory)

        # If the user didn't cancel
        if len(fileNames) > 0:
            PreferencesManager().set('DataSelection', 'recent stack image',
                                     fileNames[0])
            # Convert into one big string, which is accepted by the stack loading operator
            bigString = "//".join(fileNames)
            self.importStackFromGlobString(bigString)
Example #9
0
    def handleAddFileButtonClicked(self):
        """
        The user clicked the "Add File" button.
        Ask him to choose a file (or several) and add them to both 
          the GUI table and the top-level operator inputs.
        """
        # Find the directory of the most recently opened image file
        mostRecentImageFile = PreferencesManager().get('DataSelection',
                                                       'recent image')
        if mostRecentImageFile is not None:
            defaultDirectory = os.path.split(mostRecentImageFile)[0]
        else:
            defaultDirectory = os.path.expanduser('~')

        # Launch the "Open File" dialog
        fileNames = self.getImageFileNamesToOpen(defaultDirectory)

        # If the user didn't cancel
        if len(fileNames) > 0:
            PreferencesManager().set('DataSelection', 'recent image',
                                     fileNames[0])
            self.addFileNames(fileNames)
Example #10
0
    def register(self, group, description, shortcut, objectWithToolTip=None):
        """
        Register a shortcut with the shortcut manager.
        
        group - The GUI category of this shortcut
        description - A description of the shortcut action (shows up as default tooltip text)
        shortcut - A QShortcut
        objectWithToolTip - (optional) If provided, used to update the tooltip text with the shortcut keys. (See ABC above)
        """
        assert description is not None
        assert objectWithToolTip is None or isinstance(objectWithToolTip,
                                                       ObjectWithToolTipABC)

        if not group in self._shortcuts:
            self._shortcuts[group] = collections.OrderedDict()
        self._shortcuts[group][shortcut] = (description, objectWithToolTip)

        # If we've got user preferences for this shortcut, apply them now.
        groupKeys = PreferencesManager().get(self.PreferencesGroup, group)
        if groupKeys is not None and description in groupKeys:
            keyseq = groupKeys[description]
            shortcut.setKey(keyseq)

        self.updateToolTip(shortcut)
Example #11
0
    def initLabelUic(self, drawerUiPath):
        _labelControlUi = uic.loadUi(drawerUiPath)

        # We own the applet bar ui
        self._labelControlUi = _labelControlUi

        # Initialize the label list model
        model = LabelListModel()
        _labelControlUi.labelListView.setModel(model)
        _labelControlUi.labelListModel = model
        _labelControlUi.labelListModel.rowsRemoved.connect(self.onLabelRemoved)
        _labelControlUi.labelListModel.labelSelected.connect(
            self.onLabelSelected)

        @traceLogged(traceLogger)
        def onDataChanged(topLeft, bottomRight):
            """Handle changes to the label list selections."""
            firstRow = topLeft.row()
            lastRow = bottomRight.row()

            firstCol = topLeft.column()
            lastCol = bottomRight.column()

            if lastCol == firstCol == 0:
                assert (firstRow == lastRow
                        )  #only one data item changes at a time

                #in this case, the actual data (for example color) has changed
                color = _labelControlUi.labelListModel[firstRow].color
                self._colorTable16[firstRow + 1] = color.rgba()
                self.editor.brushingModel.setBrushColor(color)

                # Update the label layer colortable to match the list entry
                labellayer = self.getLabelLayer()
                labellayer.colorTable = self._colorTable16
            else:
                #this column is used for the 'delete' buttons, we don't care
                #about data changed here
                pass

        # Connect Applet GUI to our event handlers
        _labelControlUi.AddLabelButton.clicked.connect(bind(self.addNewLabel))
        _labelControlUi.labelListModel.dataChanged.connect(onDataChanged)

        # Initialize the arrow tool button with an icon and handler
        iconPath = os.path.split(__file__)[0] + "/icons/arrow.jpg"
        arrowIcon = QIcon(iconPath)
        _labelControlUi.arrowToolButton.setIcon(arrowIcon)
        _labelControlUi.arrowToolButton.setCheckable(True)
        _labelControlUi.arrowToolButton.clicked.connect(
            lambda checked: self.handleToolButtonClicked(
                checked, Tool.Navigation))

        # Initialize the paint tool button with an icon and handler
        paintBrushIconPath = os.path.split(
            __file__)[0] + "/icons/paintbrush.png"
        paintBrushIcon = QIcon(paintBrushIconPath)
        _labelControlUi.paintToolButton.setIcon(paintBrushIcon)
        _labelControlUi.paintToolButton.setCheckable(True)
        _labelControlUi.paintToolButton.clicked.connect(
            lambda checked: self.handleToolButtonClicked(checked, Tool.Paint))

        # Initialize the erase tool button with an icon and handler
        eraserIconPath = os.path.split(__file__)[0] + "/icons/eraser.png"
        eraserIcon = QIcon(eraserIconPath)
        _labelControlUi.eraserToolButton.setIcon(eraserIcon)
        _labelControlUi.eraserToolButton.setCheckable(True)
        _labelControlUi.eraserToolButton.clicked.connect(
            lambda checked: self.handleToolButtonClicked(checked, Tool.Erase))

        # This maps tool types to the buttons that enable them
        self.toolButtons = {
            Tool.Navigation: _labelControlUi.arrowToolButton,
            Tool.Paint: _labelControlUi.paintToolButton,
            Tool.Erase: _labelControlUi.eraserToolButton
        }

        self.brushSizes = [(1, ""), (3, "Tiny"), (5, "Small"), (7, "Medium"),
                           (11, "Large"), (23, "Huge"), (31, "Megahuge"),
                           (61, "Gigahuge")]

        for size, name in self.brushSizes:
            _labelControlUi.brushSizeComboBox.addItem(str(size) + " " + name)

        _labelControlUi.brushSizeComboBox.currentIndexChanged.connect(
            self.onBrushSizeChange)

        self.paintBrushSizeIndex = PreferencesManager().get('labeling',
                                                            'paint brush size',
                                                            default=0)
        self.eraserSizeIndex = PreferencesManager().get('labeling',
                                                        'eraser brush size',
                                                        default=4)