Skip to content

Commit

Permalink
Add progress load bar when cell sam is segmenting
Browse files Browse the repository at this point in the history
  • Loading branch information
mimithecoconut committed Dec 19, 2023
1 parent 9ed40a1 commit 9b9e2da
Showing 1 changed file with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useSelector } from '@xstate/react';
import React, { useCallback } from 'react';
import { useEditSegment, useSelect, useRaw } from '../../../ProjectContext';
import React, { useCallback, useState } from 'react';
import { useEditSegment, useSelect, useRaw, useSegmentApi } from '../../../ProjectContext';
import ActionButton from './ActionButton';
import { MenuItem, TextField } from '@mui/material';
import { MenuItem, TextField, LinearProgress, Box } from '@mui/material';
import Grid from '@mui/material/Grid';

function LayerSelector({ layer, channelType }) {
Expand Down Expand Up @@ -54,9 +54,16 @@ function LayerSelector({ layer, channelType }) {

function SegmentAllButton({ props, layer }) {
const segment = useEditSegment();
const segmentAPI = useSegmentApi();
const segmentFinished = useSelector(segmentAPI, (state) => state.matches('idle'));
const grayscale = useSelector(segment, (state) => state.matches('display.grayscale'));

const onClick = useCallback(() => segment.send('SEGMENTALL'), [segment]);
const segmentAction = useCallback(() => {
setSegmentButtonClicked(true);
segment.send('SEGMENTALL');
}, [segment]);

const [segmentButtonClicked, setSegmentButtonClicked] = useState(false);

const tooltipText = (
<span>
Expand All @@ -79,12 +86,15 @@ function SegmentAllButton({ props, layer }) {
{...props}
// disabled={!grayscale}
tooltipText={grayscale ? tooltipText : 'Run cell sam on one channel'}
onClick={onClick}
onClick={segmentAction}
hotkey='m'
>
Segment All
</ActionButton>
</Grid>
<Box sx={{ minWidth: 140, marginTop: 0.4 }}>
{segmentButtonClicked && !segmentFinished && <LinearProgress />}
</Box>
</Grid>
);
}
Expand Down

0 comments on commit 9b9e2da

Please sign in to comment.