当前位置: 首页>>代码示例>>Python>>正文


Python ThunkEventHandler.post方法代码示例

本文整理汇总了Python中ilastik.utility.gui.ThunkEventHandler.post方法的典型用法代码示例。如果您正苦于以下问题:Python ThunkEventHandler.post方法的具体用法?Python ThunkEventHandler.post怎么用?Python ThunkEventHandler.post使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ilastik.utility.gui.ThunkEventHandler的用法示例。


在下文中一共展示了ThunkEventHandler.post方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: LabelingGui

# 需要导入模块: from ilastik.utility.gui import ThunkEventHandler [as 别名]
# 或者: from ilastik.utility.gui.ThunkEventHandler import post [as 别名]

#.........这里部分代码省略.........
        self._programmaticallyRemovingLabels = False
    
    @traceLogged(traceLogger)
    def clearLabelListGui(self):
        # Remove rows until we have the right number
        while self._labelControlUi.labelListModel.rowCount() > 0:
            self.removeLastLabel()

    @traceLogged(traceLogger)
    def onLabelRemoved(self, parent, start, end):
        # Don't respond unless this actually came from the GUI
        if self._programmaticallyRemovingLabels:
            return

        assert start == end
        row = start

        oldcount = self._labelControlUi.labelListModel.rowCount() + 1
        logger.debug("removing label {} out of {}".format( row, oldcount ))

        # Remove the deleted label's color from the color table so that renumbered labels keep their colors.                
        oldColor = self._colorTable16.pop(row+1)
        
        # Recycle the deleted color back into the table (for the next label to be added)
        self._colorTable16.insert(oldcount, oldColor)

        # Update the labellayer colortable with the new color mapping
        labellayer = self.getLabelLayer()
        labellayer.colorTable = self._colorTable16

        currentSelection = self._labelControlUi.labelListModel.selectedRow()
        if currentSelection == -1:
            # If we're deleting the currently selected row, then switch to a different row
            self.thunkEventHandler.post( self.resetLabelSelection )

        # Changing the deleteLabel input causes the operator (OpBlockedSparseArray)
        #  to search through the entire list of labels and delete the entries for the matching label.
        self._labelingSlots.labelDelete.setValue(row+1)
        
        # We need to "reset" the deleteLabel input to -1 when we're finished.
        #  Otherwise, you can never delete the same label twice in a row.
        #  (Only *changes* to the input are acted upon.)
        self._labelingSlots.labelDelete.setValue(-1)
        
    def getLabelLayer(self):
        # Find the labellayer in the viewer stack
        try:
            labellayer = itertools.ifilter(lambda l: l.name == "Labels", self.layerstack).next()
        except StopIteration:
            raise RuntimeError("Couldn't locate the label layer in the layer stack.  Does it have the expected name?")
        return labellayer

    @traceLogged(traceLogger)
    def createLabelLayer(self, currentImageIndex, direct=False):
        """
        Return a colortable layer that displays the label slot data, along with its associated label source.
        direct: whether this layer is drawn synchronously by volumina
        """
        labelOutput = self._labelingSlots.labelOutput[currentImageIndex]
        if not labelOutput.ready():
            return (None, None)
        else:
            traceLogger.debug("Setting up labels for image index={}".format(currentImageIndex) )
            # Add the layer to draw the labels, but don't add any labels
            labelsrc = LazyflowSinkSource( self._labelingSlots.labelOutput[currentImageIndex],
                                           self._labelingSlots.labelInput[currentImageIndex])
开发者ID:LimpingTwerp,项目名称:applet-workflows,代码行数:70,代码来源:labelingGui.py

示例2: IlastikShell

# 需要导入模块: from ilastik.utility.gui import ThunkEventHandler [as 别名]
# 或者: from ilastik.utility.gui.ThunkEventHandler import post [as 别名]

#.........这里部分代码省略.........
        self.progressDisplayManager.addApplet(applet_index, app)
        
        # Set up handling of shell requests from this applet
        app.shellRequestSignal.connect( partial(self.handleShellRequest, applet_index) )

        self.projectManager.addApplet(app)
                
        return applet_index

    def handleAppletGuiControlSignal(self, applet_index, command=ControlCommand.DisableAll):
        """
        Applets fire a signal when they want other applet GUIs to be disabled.
        This function handles the signal.
        Each signal is treated as a command to disable other applets.
        A special command, Pop, undoes the applet's most recent command (i.e. re-enables the applets that were disabled).
        If an applet is disabled twice (e.g. by two different applets), then it won't become enabled again until both commands have been popped.
        """
        if command == ControlCommand.Pop:
            command = self._controlCmds[applet_index].pop()
            step = -1 # Since we're popping this command, we'll subtract from the disable counts
        else:
            step = 1
            self._controlCmds[applet_index].append( command ) # Push command onto the stack so we can pop it off when the applet isn't busy any more

        # Increase the disable count for each applet that is affected by this command.
        for index, count in enumerate(self._disableCounts):
            if (command == ControlCommand.DisableAll) \
            or (command == ControlCommand.DisableDownstream and index > applet_index) \
            or (command == ControlCommand.DisableUpstream and index < applet_index) \
            or (command == ControlCommand.DisableSelf and index == applet_index):
                self._disableCounts[index] += step

        # Update the control states in the GUI thread
        self.thunkEventHandler.post( self.updateAppletControlStates )

    def handleShellRequest(self, applet_index, requestAction):
        """
        An applet is asking us to do something.  Handle the request.
        """
        with Tracer(traceLogger):
            if requestAction == ShellRequest.RequestSave:
                # Call the handler directly to ensure this is a synchronous call (not queued to the GUI thread)
                self.projectManager.saveProject()

    def __len__( self ):
        return self.appletBar.count()

    def __getitem__( self, index ):
        return self._applets[index]
    
    def ensureNoCurrentProject(self, assertClean=False):
        """
        Close the current project.  If it's dirty, we ask the user for confirmation.
        
        The assertClean parameter is for tests.  Setting it to True will raise an assertion if the project was dirty.
        """
        closeProject = True
        if self.projectManager.isProjectDataDirty():
            # Testing assertion
            assert not assertClean, "Expected a clean project but found it to be dirty!"

            message = "Your current project is about to be closed, but it has unsaved changes which will be lost.\n"
            message += "Are you sure you want to proceed?"
            buttons = QMessageBox.Yes | QMessageBox.Cancel
            response = QMessageBox.warning(self, "Discard unsaved changes?", message, buttons, defaultButton=QMessageBox.Cancel)
            closeProject = (response == QMessageBox.Yes)
开发者ID:LimpingTwerp,项目名称:applet-workflows,代码行数:70,代码来源:ilastikShell.py

示例3: LabelingGui

# 需要导入模块: from ilastik.utility.gui import ThunkEventHandler [as 别名]
# 或者: from ilastik.utility.gui.ThunkEventHandler import post [as 别名]

#.........这里部分代码省略.........

        self._programmaticallyRemovingLabels = False

    def _clearLabelListGui(self):
        # Remove rows until we have the right number
        while self._labelControlUi.labelListModel.rowCount() > 0:
            self._removeLastLabel()

    def _onLabelRemoved(self, parent, start, end):
        # Don't respond unless this actually came from the GUI
        if self._programmaticallyRemovingLabels:
            return

        assert start == end
        row = start

        oldcount = self._labelControlUi.labelListModel.rowCount() + 1
        logger.debug("removing label {} out of {}".format(row, oldcount))

        # Remove the deleted label's color from the color table so that renumbered labels keep their colors.
        oldColor = self._colorTable16.pop(row+1)

        # Recycle the deleted color back into the table (for the next label to be added)
        self._colorTable16.insert(oldcount, oldColor)

        # Update the labellayer colortable with the new color mapping
        labellayer = self._getLabelLayer()
        if labellayer is not None:
            labellayer.colorTable = self._colorTable16

        currentSelection = self._labelControlUi.labelListModel.selectedRow()
        if currentSelection == -1:
            # If we're deleting the currently selected row, then switch to a different row
            self.thunkEventHandler.post( self._resetLabelSelection )

        e = self._labelControlUi.labelListModel.rowCount() > 0
        self._gui_enableLabeling(e)

        # If the gui list model isn't in sync with the operator, update the operator.
        if len(self._labelingSlots.labelNames.value) > self._labelControlUi.labelListModel.rowCount():
            # Changing the deleteLabel input causes the operator (OpBlockedSparseArray)
            #  to search through the entire list of labels and delete the entries for the matching label.
            self._labelingSlots.labelDelete.setValue(row+1)

            # We need to "reset" the deleteLabel input to -1 when we're finished.
            #  Otherwise, you can never delete the same label twice in a row.
            #  (Only *changes* to the input are acted upon.)
            self._labelingSlots.labelDelete.setValue(-1)

            labelNames = self._labelingSlots.labelNames.value
            labelNames.pop(start)
            self._labelingSlots.labelNames.setValue(labelNames, check_changed=False)

        if self._forceAtLeastTwoLabels and self._allowDeleteLastLabelOnly:
            # make previous label removable again and always leave at least two permanent labels
            if oldcount > 3:
                self._labelControlUi.labelListModel.makeRowRemovable(oldcount - 2)
        elif self._allowDeleteLastLabelOnly:
            # make previous label removable again
            if oldcount > 1:
                self._labelControlUi.labelListModel.makeRowRemovable(oldcount - 2)
        elif self._forceAtLeastTwoLabels:
            # if there are only two labels remaining make them permanent
            if self._labelControlUi.labelListModel.rowCount() == 2:
                self.labelingDrawerUi.labelListModel.makeRowPermanent(0)
                self.labelingDrawerUi.labelListModel.makeRowPermanent(1)
开发者ID:ilastik,项目名称:ilastik,代码行数:70,代码来源:labelingGui.py

示例4: CroppingGui

# 需要导入模块: from ilastik.utility.gui import ThunkEventHandler [as 别名]
# 或者: from ilastik.utility.gui.ThunkEventHandler import post [as 别名]

#.........这里部分代码省略.........
        # Don't respond unless this actually came from the GUI
        if self._programmaticallyRemovingCrops:
            return

        assert start == end
        row = start

        oldcount = self._cropControlUi.cropListModel.rowCount() + 1
        # we need at least one crop
        if oldcount <= 1:
            return

        logger.debug("removing crop {} out of {}".format( row, oldcount ))

        if self._allowDeleteLastCropOnly:
            # make previous crop removable again
            if oldcount >= 2:
                self._cropControlUi.cropListModel.makeRowRemovable(oldcount - 2)

        # Remove the deleted crop's color from the color table so that renumbered crops keep their colors.
        oldColor = self._colorTable16.pop(row+1)

        # Recycle the deleted color back into the table (for the next crop to be added)
        self._colorTable16.insert(oldcount, oldColor)

        # Update the croplayer colortable with the new color mapping
        croplayer = self._getCropLayer()
        if croplayer is not None:
            croplayer.colorTable = self._colorTable16

        currentSelection = self._cropControlUi.cropListModel.selectedRow()
        if currentSelection == -1:
            # If we're deleting the currently selected row, then switch to a different row
            self.thunkEventHandler.post( self._resetCropSelection )

        e = self._cropControlUi.cropListModel.rowCount() > 0
        #self._gui_enableCropping(e)

        # If the gui list model isn't in sync with the operator, update the operator.
        #if len(self._croppingSlots.cropNames.value) > self._cropControlUi.cropListModel.rowCount():
        if len(self.topLevelOperatorView.Crops.value) > self._cropControlUi.cropListModel.rowCount():
            # Changing the deleteCrop input causes the operator (OpBlockedSparseArray)
            #  to search through the entire list of crops and delete the entries for the matching crop.
            #self._croppingSlots.cropDelete.setValue(row+1)
            del self.topLevelOperatorView.Crops[self._cropControlUi.cropListModel[row].name]

            # We need to "reset" the deleteCrop input to -1 when we're finished.
            #  Otherwise, you can never delete the same crop twice in a row.
            #  (Only *changes* to the input are acted upon.)
            self._croppingSlots.cropDelete.setValue(-1)

    def getLayer(self, name):
        """find a layer by name"""
        try:
            croplayer = next(filter(lambda l: l.name == name, self.layerstack))
        except StopIteration:
            return None
        else:
            return croplayer

    def _getCropLayer(self):
        return self.getLayer('Crops')

    def createCropLayer(self, direct=False):
        """
        Return a colortable layer that displays the crop slot data, along with its associated crop source.
开发者ID:ilastik,项目名称:ilastik,代码行数:70,代码来源:croppingGui.py

示例5: VigraWatershedViewerGui

# 需要导入模块: from ilastik.utility.gui import ThunkEventHandler [as 别名]
# 或者: from ilastik.utility.gui.ThunkEventHandler import post [as 别名]

#.........这里部分代码省略.........

            # Wait for the image to be rendered into all three image views
            time.sleep(2)
            for imgView in self.editor.imageViews:
                imgView.scene().joinRenderingAllTiles()
            self.topLevelOperatorView.FreezeCache.setValue(True)

            self.updateSupervoxelStats()

        th = threading.Thread(target=updateThread)
        th.start()

    def updateSupervoxelStats(self):
        """
        Use the accumulated state in the watershed operator to display the stats for the most recent watershed computation.
        """
        totalVolume = 0
        totalCount = 0
        for (start, stop), maxLabel in self.topLevelOperatorView.opWatershed.maxLabels.items():
            blockshape = numpy.subtract(stop, start)
            vol = numpy.prod(blockshape)
            totalVolume += vol

            totalCount += maxLabel

        vol_caption = "Refresh Volume: {} megavox".format(totalVolume / float(1000 * 1000))
        count_caption = "Supervoxel Count: {}".format(totalCount)
        if totalVolume != 0:
            density_caption = "Density: {} supervox/megavox".format(totalCount * float(1000 * 1000) / totalVolume)
        else:
            density_caption = ""

        # Update the GUI text, but do it in the GUI thread (even if we were called from a worker thread)
        self.thunkEventHandler.post(self._drawer.refreshVolumeLabel.setText, vol_caption)
        self.thunkEventHandler.post(self._drawer.superVoxelCountLabel.setText, count_caption)
        self.thunkEventHandler.post(self._drawer.densityLabel.setText, density_caption)

    def getLabelAt(self, position5d):
        labelSlot = self.topLevelOperatorView.WatershedLabels
        if labelSlot.ready():
            labelData = labelSlot[index2slice(position5d)].wait()
            return labelData.squeeze()[()]
        else:
            return None

    def handleEditorLeftClick(self, position5d, globalWindowCoordinate):
        """
        This is an override from the base class.  Called when the user clicks in the volume.
        
        For left clicks, we highlight the clicked label.
        """
        label = self.getLabelAt(position5d)
        if label != 0 and label is not None:
            overrideSlot = self.topLevelOperatorView.OverrideLabels
            overrides = copy.copy(overrideSlot.value)
            overrides[label] = (255, 255, 255, 255)
            overrideSlot.setValue(overrides)

    def handleEditorRightClick(self, position5d, globalWindowCoordinate):
        """
        This is an override from the base class.  Called when the user clicks in the volume.
        
        For right clicks, we un-highlight the clicked label.
        """
        label = self.getLabelAt(position5d)
        overrideSlot = self.topLevelOperatorView.OverrideLabels
开发者ID:jenspetersen,项目名称:ilastik,代码行数:70,代码来源:vigraWatershedViewerGui.py

示例6: SplitBodyCarvingGui

# 需要导入模块: from ilastik.utility.gui import ThunkEventHandler [as 别名]
# 或者: from ilastik.utility.gui.ThunkEventHandler import post [as 别名]

#.........这里部分代码省略.........
            fragmentNames = op.getFragmentNames(ravelerLabel)
            numFragments = len(fragmentNames)

            renderLabels = []
            for i, name in enumerate(fragmentNames):
                if name != op.CurrentEditingFragment.value:
                    assert i < len(self._fragmentColors), "Too many fragments: colortable is too small"
                    color = ( fragmentColors[i+1].red() / 255.0,
                              fragmentColors[i+1].green() / 255.0,
                              fragmentColors[i+1].blue() / 255.0 )
                    renderLabel = self._renderMgr.addObject( color=color )
                    renderLabels.append( renderLabel )

            if op.CurrentEditingFragment.value != "":
                print " Asking for masked editing segmentation"
                maskedSegmentation = op.MaskedSegmentation(*rendering_roi_5d).wait()
                print " Obtained for masked editing segmentation"
                segLabel = numFragments

                print " Start updating volume data with masked segmentation"
                renderVol5d[:] = numpy.where(maskedSegmentation != 0, segLabel, renderVol5d)
                print " Finished updating volume data with masked segmentation"

                segmentationColor = (0.0, 1.0, 0.0)
                renderLabel = self._renderMgr.addObject( color=segmentationColor )
                renderLabels.append( renderLabel )

            # Relabel with the labels we were given by the renderer.
            # (We can skip this step if the renderer is guaranteed to give labels 1,2,3...)
            if renderLabels != list(range(len(renderLabels))):
                renderVol5d[:] = numpy.array([0] + renderLabels)[renderVol5d]

        print "Finished updating 3D volume data"
        self.thunkEventHandler.post(self._refreshRenderMgr)

    @threadRouted
    def _refreshRenderMgr(self):
        """
        The render mgr can segfault if this isn't called from the main thread.
        """
        print "Begin render update"
        self._renderMgr.update()
        print "End render update"

    
    def setupLayers(self):
        def findLayer(f, layerlist):
            for l in layerlist:
                if f(l):
                    return l
            return None

        layers = []
        baseCarvingLayers = super(SplitBodyCarvingGui, self).setupLayers()        
        
        crosshairSlot = self.topLevelOperatorView.AnnotationCrosshairs
        if crosshairSlot.ready():
            # 0=Transparent, 1=pink
            colortable = [QColor(0, 0, 0, 0).rgba(), QColor(236, 184, 201).rgba()]
            crosshairLayer = ColortableLayer(LazyflowSource(crosshairSlot), colortable, direct=True)
            crosshairLayer.name = "Annotation Points"
            crosshairLayer.visible = True
            crosshairLayer.opacity = 1.0
            layers.append(crosshairLayer)
        
        
开发者ID:JensNRAD,项目名称:ilastik_public,代码行数:68,代码来源:splitBodyCarvingGui.py

示例7: LabelingGui

# 需要导入模块: from ilastik.utility.gui import ThunkEventHandler [as 别名]
# 或者: from ilastik.utility.gui.ThunkEventHandler import post [as 别名]

#.........这里部分代码省略.........

        self._programmaticallyRemovingLabels = False

    def _clearLabelListGui(self):
        # Remove rows until we have the right number
        while self._labelControlUi.labelListModel.rowCount() > 0:
            self._removeLastLabel()

    def _onLabelRemoved(self, parent, start, end):
        # Don't respond unless this actually came from the GUI
        if self._programmaticallyRemovingLabels:
            return

        assert start == end
        row = start

        oldcount = self._labelControlUi.labelListModel.rowCount() + 1
        logger.debug("removing label {} out of {}".format( row, oldcount ))

        # Remove the deleted label's color from the color table so that renumbered labels keep their colors.
        oldColor = self._colorTable16.pop(row+1)

        # Recycle the deleted color back into the table (for the next label to be added)
        self._colorTable16.insert(oldcount, oldColor)

        # Update the labellayer colortable with the new color mapping
        labellayer = self._getLabelLayer()
        if labellayer is not None:
            labellayer.colorTable = self._colorTable16

        currentSelection = self._labelControlUi.labelListModel.selectedRow()
        if currentSelection == -1:
            # If we're deleting the currently selected row, then switch to a different row
            self.thunkEventHandler.post( self._resetLabelSelection )

        e = self._labelControlUi.labelListModel.rowCount() > 0
        self._gui_enableLabeling(e)

        # If the gui list model isn't in sync with the operator, update the operator.
        if len(self._labelingSlots.labelNames.value) > self._labelControlUi.labelListModel.rowCount():
            # Changing the deleteLabel input causes the operator (OpBlockedSparseArray)
            #  to search through the entire list of labels and delete the entries for the matching label.
            self._labelingSlots.labelDelete.setValue(row+1)
    
            # We need to "reset" the deleteLabel input to -1 when we're finished.
            #  Otherwise, you can never delete the same label twice in a row.
            #  (Only *changes* to the input are acted upon.)
            self._labelingSlots.labelDelete.setValue(-1)
            
            labelNames = self._labelingSlots.labelNames.value
            labelNames.pop(start)
            self._labelingSlots.labelNames.setValue(labelNames, check_changed=False)
       
    def getLayer(self, name):
        """find a layer by name"""
        try:
            labellayer = itertools.ifilter(lambda l: l.name == name, self.layerstack).next()
        except StopIteration:
            return None
        else:
            return labellayer

    def _getLabelLayer(self):
        return self.getLayer('Labels')

    def createLabelLayer(self, direct=False):
开发者ID:burcin,项目名称:ilastik,代码行数:70,代码来源:labelingGui.py


注:本文中的ilastik.utility.gui.ThunkEventHandler.post方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。