Skip to content

Multiple progress bar in Brainstorm#897

Open
Edouard2laire wants to merge 37 commits intobrainstorm-tools:masterfrom
Edouard2laire:multiple_progressbar
Open

Multiple progress bar in Brainstorm#897
Edouard2laire wants to merge 37 commits intobrainstorm-tools:masterfrom
Edouard2laire:multiple_progressbar

Conversation

@Edouard2laire
Copy link
Copy Markdown
Collaborator

@Edouard2laire Edouard2laire commented Mar 8, 2026

Hello,

3 years after posting #614, I finally came up with a simple, working design for having multiple progress bars in brainstorm without changing the progress bar API.
The idea is to have one window per progress bar and to keep track of which function invoked each progress bar, to be able to open/close/update the appropriate window.

This should make the management of the progress bar much easier, as each function won't have to worry if a progress bar is already open or if the function they are calling might have a progress bar. This PR only focuses on the change in the progress bar; we might then improve where it is used within brainstorm to provide better info to the user :)

Here is a list of few example i used to test:

1st example:

function main()
    bst_progress('start', 'External Loop', '', 0, 10);
    for iSubject = 1:10
        
        internal_loop();
        bst_progress('inc', 1);
    end
    bst_progress('stop');
end


function internal_loop()

    N = 20;    
    bst_progress('start', 'Internal Loop', '', 0, N);
    for i = 1:N
       pause(0.1)
       bst_progress('inc', 1);
    end

    %bst_progress('stop');

end

Example 2: Note that the progress bar of 'internal_A' is closed automatically, as the function is not calling bst_progress('stop'); so there is no risk of ending up with a dozen of open progress bars :)

function main()

    internal_A();
    internal_B()
end


function internal_A()

    N = 20;    
    bst_progress('start', 'Internal Loop A', '', 0, N);
    for i = 1:N
       pause(0.1)
       bst_progress('inc', 1);
    end

    %bst_progress('stop');

end



function internal_B()

    N = 20;    
    bst_progress('start', 'Internal Loop B', '', 0, N);
    for i = 1:N
       pause(0.1)
       bst_progress('inc', 1);
    end

    %bst_progress('stop');

end

Exemple 3: with parfor loops

    N = 20;
    q = parallel.pool.DataQueue;
    afterEach(q, @(x) bst_progress('inc', 1));

    bst_progress('start', 'Internal Loop', '', 0, N);
    parfor i = 1:N
        pause(1+1.2*abs(randn()))
        send(q, i); 

        fprintf('%d \n', i)
    end

    bst_progress('stop');

Example with multiple porgress bar within the same function:

Note: there can be a little risk, if bst_progress('stop'); is not called inside the loop, but i guess that's fine. If we don't want that, then we can change ix = find(strcmp(progress_list, caller_name), 1, 'last'); to ix = find(strcmp(progress_list, caller_name), 1, 'first');

N = 20;    
bst_progress('start', 'Externl Loop', '', 0, N);
for i = 1:N
    bst_progress('start', 'Internal Loop B', '', 0, 10);
    for j = 1:10
        pause(0.1)
        bst_progress('inc', 1);
    end
    bst_progress('stop');
    bst_progress('inc', 1);
end
bst_progress('stop');

Exemple when using MEM:
image

@Edouard2laire Edouard2laire marked this pull request as ready for review March 8, 2026 06:20
@Edouard2laire Edouard2laire force-pushed the multiple_progressbar branch from 78285b8 to e023ef5 Compare March 8, 2026 06:40
@Edouard2laire
Copy link
Copy Markdown
Collaborator Author

Edouard2laire commented Mar 10, 2026

I might have found an issue. bst_progress('start', 'User statistics', 'Downloading...'); doesn't create the usual bar with the blue dot moving from left to right.

edit: It seems it doesn't work even without the update.

Here is my system info:

=== Matlab ===
Matlab version : R2023b (23.02)
Java version : 1.8

=== System ===
OS name : macOS 26.3 (arm64)
OS type : mac64arm
Mem total : 16384 MiB
Mem avail : 8847 MiB

@Edouard2laire Edouard2laire marked this pull request as draft March 10, 2026 13:01
@Edouard2laire Edouard2laire marked this pull request as ready for review March 10, 2026 16:02
@rcassani
Copy link
Copy Markdown
Member

I might have found an issue. bst_progress('start', 'User statistics', 'Downloading...'); doesn't create the usual bar with the blue dot moving from left to right.

There is nothing inherently different for this call for bst_progress()
I tried in other combinations of OS and Matlab versions, and it works as it should.
Restart Matlab and check if this different behaviour persists

ok. i think it should be working fine now @rcassani

For the moment, I have not bandwidth to review this PR, it may take a bit before I take a look to it

@Edouard2laire
Copy link
Copy Markdown
Collaborator Author

For the moment, I have not bandwidth to review this PR, it may take a bit before I take a look to it

No problem. it's not really a urgent PR. Just cosmetic :) it would be nice however, if you or other people of the team could apply the change on their bst_progress file so we can detect 'undesired' behavior linked to the change as you use brainstorm :)

@Edouard2laire
Copy link
Copy Markdown
Collaborator Author

Edouard2laire commented Mar 24, 2026

Todo;

  • check import freesurfer. It create a dozen progress bar

@rcassani rcassani marked this pull request as draft March 24, 2026 18:31
@Edouard2laire
Copy link
Copy Markdown
Collaborator Author

ok. this is ready for review.

I added a limit on the number of progress bar so it is safe to use. Latter we can then optimize how we use the progress bar over the toolbox to improve the feedback given to the users.

@Edouard2laire Edouard2laire marked this pull request as ready for review April 14, 2026 19:15
Comment thread toolbox/io/import_mri.m Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants