Jump to content
Sign in to follow this  
JotaPx

Stoping a Timed Progress bar script

Recommended Posts

JotaPx

Hi,

i've been scripting around a bit with autoit but i always had this problem that i find a bit stupid on my part:

~Can't stop a script execution during a rotine...   "duh!" you may say   else take a look at this sample script:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$main = GUICreate("5.5 seconds!",1100,25,125,0,-1,$WS_EX_TOPMOST)

$prog = GUICtrlCreateProgress(0,0,1000,25)
$OK = GUICtrlCreateButton("GO!",1000,0,25,25)
$Stop = GUICtrlCreateButton("Stop",1025,0,50,25)
$label = GUICtrlCreateLabel("-",1075,0,25)
GUICtrlSetState($Stop,$GUI_DISABLE)
GUICtrlSetState($main,$GUI_ONTOP)
GUISetState()
$go = 1

while 1
$msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        case $msg = $OK     
            GUICtrlSetState($OK,$GUI_DISABLE)
            GUICtrlSetState($Stop,$GUI_ENABLE)
            Do
                $msg = GUIGetMsg()
                GUICtrlSetData($prog,0)
                sleep(1000) 
                GUICtrlSetData($prog,20)
                sleep(1000)
                GUICtrlSetData($prog,40)
                sleep(1000) 
                GUICtrlSetData($prog,60)
                sleep(1000) 
                GUICtrlSetData($prog,80)
                sleep(1000) 
                GUICtrlSetData($prog,100)
                sleep(250)
                MouseClick("left")
            until $msg = $GUI_EVENT_CLOSE
    EndSelect
WEnd

How can i use the Stop button to Stop the rotine? Any toughts on that?

best regards

Share this post


Link to post
Share on other sites
FireFox

Hi,

There are many ways to do it, and I have chosen the Timers.

 

The GUIGetMsg function can only catch messages when it's called, in your loop you have sleep functions avoiding the msgs to be caught.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
 
Local $iPhase = 0, $iStep = 20, $iMax = 100
Local $hTimer = 0, $fGo = False
 
$main = GUICreate("5.5 seconds!", 1100, 25, 125, 0, -1, $WS_EX_TOPMOST)
 
$prog = GUICtrlCreateProgress(0, 0, 1000, 25)
$OK = GUICtrlCreateButton("GO!", 1000, 0, 25, 25)
$Stop = GUICtrlCreateButton("Stop", 1025, 0, 50, 25)
$label = GUICtrlCreateLabel("-", 1075, 0, 25)
GUICtrlSetState($Stop, $GUI_DISABLE)
GUICtrlSetState($main, $GUI_ONTOP)
GUISetState()
 
$go = 1
 
$hTimer = TimerInit()
 
While 1
    $msg = GUIGetMsg()
 
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $OK
            $fGo = True
 
            GUICtrlSetState($OK, $GUI_DISABLE)
            GUICtrlSetState($Stop, $GUI_ENABLE)
 
            GUICtrlSetData($prog, 0)
        Case $Stop
            $fGo = False
 
            GUICtrlSetState($OK, $GUI_ENABLE)
            GUICtrlSetState($Stop, $GUI_DISABLE)
    EndSwitch
 
    If $fGo Then
        If $iPhase = $iMax / $iStep _ ;last step done
                And TimerDiff($hTimer) >= 250 Then
            MouseClick("left")
 
            $iPhase = 0 ;reset counter
        ElseIf TimerDiff($hTimer) >= 1000 Then
            GUICtrlSetData($prog, ($iPhase + 1) * $iStep)
 
            $iPhase += 1
 
            $hTimer = TimerInit()
        EndIf
    EndIf
WEnd
Br, FireFox. Edited by FireFox
  • Like 1

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
JotaPx

Hi,

There are many ways to do it, and I have chosen the Timers.

 

The GUIGetMsg function can only catch messages when it's called, in your loop you have sleep functions avoiding the msgs to be caught.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
 
Local $iPhase = 0, $iStep = 20, $iMax = 100
Local $hTimer = 0, $fGo = False
 
$main = GUICreate("5.5 seconds!", 1100, 25, 125, 0, -1, $WS_EX_TOPMOST)
 
$prog = GUICtrlCreateProgress(0, 0, 1000, 25)
$OK = GUICtrlCreateButton("GO!", 1000, 0, 25, 25)
$Stop = GUICtrlCreateButton("Stop", 1025, 0, 50, 25)
$label = GUICtrlCreateLabel("-", 1075, 0, 25)
GUICtrlSetState($Stop, $GUI_DISABLE)
GUICtrlSetState($main, $GUI_ONTOP)
GUISetState()
 
$go = 1
 
$hTimer = TimerInit()
 
While 1
    $msg = GUIGetMsg()
 
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $OK
            $fGo = True
 
            GUICtrlSetState($OK, $GUI_DISABLE)
            GUICtrlSetState($Stop, $GUI_ENABLE)
 
            GUICtrlSetData($prog, 0)
        Case $Stop
            $fGo = False
 
            GUICtrlSetState($OK, $GUI_ENABLE)
            GUICtrlSetState($Stop, $GUI_DISABLE)
    EndSwitch
 
    If $fGo Then
        If $iPhase = $iMax / $iStep _ ;last step done
                And TimerDiff($hTimer) >= 250 Then
            MouseClick("left")
 
            $iPhase = 0 ;reset counter
        ElseIf TimerDiff($hTimer) >= 1000 Then
            GUICtrlSetData($prog, ($iPhase + 1) * $iStep)
 
            $iPhase += 1
 
            $hTimer = TimerInit()
        EndIf
    EndIf
WEnd
Br, FireFox.

 

 

That seamed to do the trick. Will be giving a think about it. Thanks a mil

Share this post


Link to post
Share on other sites
JotaPx

Just made a couple of minor changes so it resets when stop is pressed:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
 
Local $iPhase = 0, $iStep = 20, $iMax = 100
Local $hTimer = 0, $fGo = False
 
$main = GUICreate("5.5 seconds!", 1100, 25, 125, 0, -1, $WS_EX_TOPMOST)
 
$prog = GUICtrlCreateProgress(0, 0, 1000, 25)
$OK = GUICtrlCreateButton("GO!", 1000, 0, 25, 25)
$Stop = GUICtrlCreateButton("Stop", 1025, 0, 50, 25)
$label = GUICtrlCreateLabel("-", 1075, 0, 25)
GUICtrlSetState($Stop, $GUI_DISABLE)
GUICtrlSetState($main, $GUI_ONTOP)
GUISetState()
 
$hTimer = TimerInit()
 
While 1
    $msg = GUIGetMsg()
 
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $OK
            $fGo = True
 
            GUICtrlSetState($OK, $GUI_DISABLE)
            GUICtrlSetState($Stop, $GUI_ENABLE)
 
            GUICtrlSetData($prog, 0)
        Case $Stop
            $fGo = False
            $iPhase = 0
            GUICtrlSetData($prog, 0)
            GUICtrlSetState($OK, $GUI_ENABLE)
            GUICtrlSetState($Stop, $GUI_DISABLE)
    EndSwitch
 
    If $fGo Then
        If $iPhase = $iMax / $iStep _ ;last step done
                And TimerDiff($hTimer) >= 1000 Then
            GUICtrlSetData($prog, $iMax)
            MouseClick("left")
 
            $iPhase = 0 ;reset counter
        ElseIf TimerDiff($hTimer) >= 1000 Then
            GUICtrlSetData($prog, ($iPhase ) * $iStep)
 
            $iPhase += 1
 
            $hTimer = TimerInit()
        EndIf
    EndIf
WEnd

Once again ty very much for the helpfull knowledge

Edited by JotaPx

Share this post


Link to post
Share on other sites
JotaPx

hi again, srry for the multi fast posting as i am sleepy  xD

what does de "_" do in:

If $iPhase = $iMax / $iStep _ ;last step done

thanks

Share this post


Link to post
Share on other sites
kylomas

continuation character so the statement can span multiple lines


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Similar Content

    • Skeletor
      By Skeletor
      Hi All,
      I want to make my progress bar progress with the amount of File lines read. 
      How would I do this correctly. So far the code below can sometimes run in the middle of the progress bar and state completed.. and other times it can run into the 200%. 
       
      ;======================================================================== ProgressOn("TITLE", "ACTION") ;======================================================================== For $count = 1 To _FileCountLines($FileRead) Step 1 $string = FileReadLine($FileRead, $count) $value1 = $input[1] $value2 = $input[2] $value3 = $input[3] $value4 = $input[4] $TM = FileWrite("C:\temp\test.txt", $value1 & " " & $value2 & " " & $value3 & " " & $value4 & @CRLF) ProgressSet($count, $count & "%") Next ;======================================================================== ; PROGRESS BAR OFF ;======================================================================== ProgressSet(_FileCountLines($FileRead), "Completed!") Sleep(750) ProgressOff() ;========================================================================  
    • mond1106
      By mond1106
      Hi,
       
      Im new to autoit im exploring some function and I am interested with the progress bar.
       
      Is it possible to have a end user input in how much the bar will progress?
       
      I saw this code in the examples.
      Example()
      Func Example()
          ; Display a progress bar window.
          ProgressOn("Progress Meter", "Increments every second", "0%")
          ; Update the progress value of the progress bar window every second.
          For $i = 10 To 100 Step 10
            
              Sleep(1000)
              ProgressSet($i, $i & "%")
          Next
          ; Set the "subtext" and "maintext" of the progress bar window.
          ProgressSet(100, "Done", "Complete")
          Sleep(5000)
          ; Close the progress window.
          ProgressOff()
       EndFunc   ;==>Example
       
      Thank you.

    • ur
      By ur
      The below script is used by me before for copying files/folders with progress bar(windows default progress bar).
      I found similar option for moving by using same object.
      But not able to find for delete.
       dml.vbs  (This is a vbscript one and I am posting in this forum because autoit is made on top of vbscript and it might have similar functions.)
      So, I checked in AutoIT forums and found below script files and which I have been modified for my requirement.
      In those below I found delete2.au3 is working fine but hanging during deletion of huge memory files/folders.
      Delete1_au3 
      Delete2_au3 
      Delete3_au3
      Please try to provide a solution.
       
       
    • sundar
      By sundar
      I have an application which delete folder and files specified by the user. Everthing workes fine but problem comes when the file/folder size is bigger(morethan 1GB). The GUI hangs when deleting large file/folder size. The idea is to have a progress bar with looping statement when deletion is in progress. So that looping stops the hanging of GUI and progress bar shows users to know about the process/progress. However i am unable to figureout how to detect deleting process.

      Thank you in advance.
    • johnmcloud
      By johnmcloud
      Hi guys, i have two question about Progress bar,
      I'm testing this code:


      ProgressOn("Progress Bar", "Sample progress bar", "Working...") For $i = 0 To 100 ProgressSet($i) Sleep(5) Next MyFunc() ProgressSet(100, "Done!") Sleep(750) ProgressOff()
      1) Thi function does not work as expected, seem working with time, sometime finish first, sometime finish later. The func is a runwait(@comspec) can process file from 1MB to many GB, so i don't know how to set it

      2) There is a version can integrate with GUI?

      Thanks for support
×