Jump to content
Sign in to follow this  
Alex.01

Update progress bar in GUI

Recommended Posts

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

 

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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 likes this

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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 likes this

Share this post


Link to post
Share on other sites
11 hours ago, brahmadev said:

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

 

 

 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
You are posting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...