Update progress bar in GUI

Alex.01
Alex.01 Altair Community Member
edited October 2020 in Community Q&A

Hi all,

 

I am trying to create my first GUI for an old script I did, and I don't know if I am doing in the best way.

The GUI has a progress bar indeterminate (in the future I would want to do determinate), which should start when the user press a button and should stop when the script finish. However, when the script is running, GUI freezes and progress bar doesn't update.

 

I have the GUI and the script in two different procedures, like this (only the relevant info is showed, but I can show the whole script):

 

 proc interface {} {  # ------------------------------------------------------------------------------------------------ #  set progress_frame [hwtk::labelframe $gui.progress_frame -text 'Progress' -padding 5] pack $progress_frame -padx 1 -pady 3 -anchor n -fill x -side top  set progress [hwtk::progressbar $progress_frame.progress -mode indeterminate -length 350] pack $progress  # ------------------------------------------------------------------------------------------------ #  set button_start [hwtk::button $bottom_frame.button_start -text 'BURN IT!' -width 10 -command [list BarCommand start $progress_frame.progress]] pack $button_start -pady 1 -padx 3 -anchor e -side right -ipadx 4 -ipady 2  }  proc BarCommand {op args} {      foreach w $args { $w $op     } update main  }  proc main {}  {  # A lot of commands here  }

 

I have only found two topics related with problem:

 

  1. Unfreeze the HyperMesh GUI (I added command 'update' in the proc)
  2. Progress bar / status bar creation inside HM

 

But the GUI is still not working. I add command 'update' in the proc which is changing the progress bar, but it doesn't work.

 

The GUI is like the one I show in the image below.

image.png.c783c6b2daf04b972178c87752fd89e8.png

 

I think I am missing something but I don't know what...

 

Thanks in advance,

Alex

 

 

Answers

  • tinh
    tinh Altair Community Member
    edited October 2018

    What is body of main proc?

    Add update cmd into every loop of it

  • Alex.01
    Alex.01 Altair Community Member
    edited October 2018

    Hi tinh,

     

    'body' would correspond with the old script I mentioned before. There a lot of loops, and nested loops.

    I added update cmd like you said, and now I can see that the progress bar is working, but I can notice sometimes it get stuck. I wonder if there is a way to resolve this...

    Another question, update command makes the script runs slower?

     

    Thanks you tinh

  • tinh
    tinh Altair Community Member
    edited October 2018

    Yes, because update cmd will invoke various cmds, it slows down script. So do not make it runs smooth (look beautiful, but expensive!)

     

    The progress bar is stuck sometimes because a certain cmd takes much time,

    If you want it runs smoother, you have to put 'update' inside that cmd.

    If the cmd is a tcl proc, it is possible

    Otherwise is not.

     

     

     

  • Alex.01
    Alex.01 Altair Community Member
    edited October 2018

    Ok tinh, so then I won't put the progress bar... I need to show if the script is running or not, because HyperMesh freezes in a short period of time, so I will put a text showing 'running' and it will update when the script finish. Do you think is a good way? Or could be better?

  • tinh
    tinh Altair Community Member
    edited October 2018

    If your script runs very fast => don't need progress bar

    If your script runs in a short time => use smoothy updated progress bar, because it's not expensive so make it nice

    If your script runs in a long time => use periodically updated progress bar, because it's expensive so make it ugly!

    Ugly is better than none (hm frozen)

  • Alex.01
    Alex.01 Altair Community Member
    edited October 2018

    Ok tinh, thank you for your help!

  • brahmadev
    brahmadev Altair Community Member
    edited December 2018

    I don't understand what is update cmd ??

    I'm a newbie to automation, don't mind if my question sounds lame to you people.

  • tinh
    tinh Altair Community Member
    edited December 2018

    I don't understand what is update cmd ??

    I'm a newbie to automation, don't mind if my question sounds lame to you people.

     

    as its name => it is a command to update visualization

    but internally, it is a command to process event loop

     

    while tcl is processing a long task, example:

    for {set i 0} {$i<10000000000000} {incr i} {

         dosomething

    }

    => event loop will be stopped (GUI will be frozen, not responsed with mouse, keboard events,...)

     

     

     

    If you add an 'update'  inside a long task, example:

    for {set i 0} {$i<10000000000000} {incr i} {

         dosomething

         update

    }

    ==> now, the 'update' command will invoke event loop , so GUI will response with mouse, keyboard events, timers,...

    but it slows down the process, because it invokes event loop many times

     

     

     

  • Jeffersondhv
    Jeffersondhv Altair Community Member
    edited December 2018

    I'm trying to output the progress of my script in the user message field, but it gets stuck on 0% till the end of the run even tough I'm using update.

     

    Here follows the code I'm using:

     proc statusMsg { current total } {     ## Displays progress pecentage     set percnt [ expr $current/$total*100 ]     set str '%'     hm_usermessage 'In progress ($percnt$str)'     update }

    I even tried using hm_blockmessages 1 before and hm_blockmessages 0 after the code execution, but it didn't work.

     

    How can I fix this?

     

    Thank you.

  • tinh
    tinh Altair Community Member
    edited December 2018

    Attention: 1/100=50/100=0, 

    51/100=100/100=1

     

    And if you don't increase 'current' before calling statusMsg, % will not vary.

  • Jeffersondhv
    Jeffersondhv Altair Community Member
    edited December 2018

    Ok, got it.

    I'll shall use 100.0 instead of 100 then.

     

    Thanks tinh