Jump to content

Making a Responsive GUI?


SteveO
 Share

Recommended Posts

Okay, how do I get my program to Stop and wait for a new command when I click Stop in the GUI?

Lets say my program is in the middle of a function, and the user presses the "Stop" button, how do I get the Program to respond to that and exit the function and jump into another loop until another button on the GUI is pressed?

EDIT

I need the program to jump out of a "For" loop when the Stop button is pressed.

Edited by SteveO
Link to comment
Share on other sites

Link to comment
Share on other sites

Depends what is being done whilst in the stop button becomes unresposonsive. I can see a loop, but your code I cannot. My crystal ball is cloudy :D

hehe, sry. here you go.

Func NumPost()
    For $I = $startpost To $endpost
        _IENavigate($IE,$Thread[2] & $sid)
        $Post = _IEFormGetObjByName($IE,"post")
        $Mess = _IEFormElementGetObjByName($Post,"message")
        _IEFormElementSetValue($Mess, $startglobalbbcode & $Message & $endmsgbbcode & $startnumbbbcode & $sym & $I & $endglobalbbcode)
        _IEFormImageClick ($Post,"Submit","alt")
        $I = $I+1
        
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;        
            ;; Early Post End Check
            If $I == $endpost + 1 Then  
                If $tymsgonoff == 1 Then
                            Sleep(Random($min, $max, 1))
                            _IENavigate($IE,$Thread[3] & $sid)
                            $Post = _IEFormGetObjByName($IE,"post")
                            $Mess = _IEFormElementGetObjByName($Post,"message")
                            _IEFormElementSetValue($Mess, $tymsg)
                            _IEFormImageClick ($Post,"Submit","alt")
                            ;;End Msg
                            MsgBox(0, "The Bumping Catalyst v" & $ver, "Bumping Completed")
                            Exit
                Else
            MsgBox(0, "The Bumping Catalyst v" & $ver, "Bumping Completed")
            Exit
            EndIf
            EndIf
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;    

        Sleep(Random($min, $max, 1))
                        _IENavigate($IE,$Thread[3] & $sid)
        $Post = _IEFormGetObjByName($IE,"post")
        $Mess = _IEFormElementGetObjByName($Post,"message")
        _IEFormElementSetValue($Mess, $startglobalbbcode & $Message & $endmsgbbcode & $startnumbbbcode & $sym & $I & $endglobalbbcode)
        _IEFormImageClick ($Post,"Submit","alt")
        Sleep(Random($min, $max, 1))
    Next
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;        
                If $tymsgonoff == 1 Then
                            Sleep(Random($min, $max, 1))
                            _IENavigate($IE,$Thread[2] & $sid)
                            $Post = _IEFormGetObjByName($IE,"post")
                            $Mess = _IEFormElementGetObjByName($Post,"message")
                            _IEFormElementSetValue($Mess, $tymsg)
                            _IEFormImageClick ($Post,"Submit","alt")
                            ;;End Msg
                            MsgBox(0, "The Bumping Catalyst v" & $ver, "Bumping Completed")
                            Exit
                Else
                MsgBox(0, "The Bumping Catalyst v" & $ver, "Bumping Completed")
                Exit
                EndIf
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    EndFunc
Link to comment
Share on other sites

Hi,

You not need jump from loop to loop, you just check the events in the main loop :D ...

#include <GuiConstants.au3>

$GUI = GUICreate("Test Script", 300, 200)

$Button_1 = GUICtrlCreateButton("My Button 1", 20, 40, 80, 20)
$Button_2 = GUICtrlCreateButton("My Button 2", 20, 80, 80, 20)

$CheckBox = GUICtrlCreateCheckbox("My CheckBox", 20, 120)

GUISetState(@SW_SHOW, $GUI)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button_1
            MsgBox(0, "", "Button <" & GUICtrlRead($Button_1, 1) & "> pressed")
        Case $Button_2
            MsgBox(0, "", "Button <" & GUICtrlRead($Button_2, 1) & "> pressed")
        Case $CheckBox
            $IsChecked = BitAND(GUICtrlRead($CheckBox), $GUI_CHECKED) = $GUI_CHECKED
            MsgBox(0, "", "Checkbox checked = " & $IsChecked)
    EndSwitch
WEnd

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

Hi,

You not need jump from loop to loop, you just check the events in the main loop :D ...

#include <GuiConstants.au3>

$GUI = GUICreate("Test Script", 300, 200)

$Button_1 = GUICtrlCreateButton("My Button 1", 20, 40, 80, 20)
$Button_2 = GUICtrlCreateButton("My Button 2", 20, 80, 80, 20)

$CheckBox = GUICtrlCreateCheckbox("My CheckBox", 20, 120)

GUISetState(@SW_SHOW, $GUI)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button_1
            MsgBox(0, "", "Button <" & GUICtrlRead($Button_1, 1) & "> pressed")
        Case $Button_2
            MsgBox(0, "", "Button <" & GUICtrlRead($Button_2, 1) & "> pressed")
        Case $CheckBox
            $IsChecked = BitAND(GUICtrlRead($CheckBox), $GUI_CHECKED) = $GUI_CHECKED
            MsgBox(0, "", "Checkbox checked = " & $IsChecked)
    EndSwitch
WEnd
That's how my main code is set up. My problem is, I need the program to jump out of a "For" loop when the Stop button is pressed. Edited by SteveO
Link to comment
Share on other sites

This is what I always had problems with. I never really did figure out a way to have a global check for if anything was pressed. I guess you could possibly declare $nMsg or whatever your variable may be as like a global variable, then use adlibenable to start doing checks while you are in a function then when the function ends or whatever disable the adlib, but then again you would need to figure out a way to send exitloop :D. If (name not mentioned) would program some multithreading that would be KICK ASS.

What you could try is adding this

$Msg = GUIGetMsg()
        If $Msg = $SOMEBUTTON Then Exitloop

Now add that right before your for loop starts. The only problem is it will only execute after the for loop goes through completely then back to the start. And by he looks of it using IE stuff it will take a little while but so far its your only option.

EDIT: ooops out of the for loop , should be exitloop not return :P

Edited by Thatsgreat2345
Link to comment
Share on other sites

This is what I always had problems with. I never really did figure out a way to have a global check for if anything was pressed. I guess you could possibly declare $nMsg or whatever your variable may be as like a global variable, then use adlibenable to start doing checks while you are in a function then when the function ends or whatever disable the adlib, but then again you would need to figure out a way to send exitloop :D. If (name not mentioned) would program some multithreading that would be KICK ASS.

That might just work. I'll try testing with that. Thanks.

Link to comment
Share on other sites

Take a look at Timers, you can run a timer (using callback) that will check if there was an event.

If there was an event, just set a global variable, and check that variable in your loop(s).

P.S

Checking with GUIGetMsg() will slow down you loop, because this function include a pause on 10 ms (only when non "OnEvent mode" used).

Edited by MsCreatoR

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

Link to comment
Share on other sites

If you add the

If GUIGetMsg () = $SomeButton Then ExitLoop
at the toop of your For Loop, then it should do what you want :D
I edited my previouse post :P (i didn't seen your post).

P.S

Checking with GUIGetMsg() will slow down you loop, because this function include a pause on 10 ms (only when non "OnEvent mode" used).

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

Link to comment
Share on other sites

If you add the

If GUIGetMsg () = $SomeButton Then ExitLoop
at the toop of your For Loop, then it should do what you want :D
I tried that, and I tried making a function to check the GUI Message. Then I have it check if the stop button was pressed in specified times in the loop. I have to press the stop button like 20 times before it actually gets read. Edited by SteveO
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...