Sign in to follow this  
Followers 0
nago

Emergency Halt Button

5 posts in this topic

#1 ·  Posted (edited)

Hi, I'm having some problems with the GUI modes conceptually. My goal is to have a small Gui frontend for a script which:

A) Has a start button,

B) Has a stop button,

C) Has an exit button.

D) Has a few settings fields, Apply/Save button (ETC).

The "Start" button will start a long macro: A long series of keypresses, sleeps, WinWaitActive() functions, etcetera.

The "Stop" button should stop the aforementioned function at any time.

The "Exit" button -- the default window's "X", should close the gui and halt the script instantly at any time.

The problem is, once the macro function has been started, the gui is no longer responsive... In either GUI mode. In the event mode, once one event has been triggered, none of the other buttons respond. Or, in the default mode, (with the case $button layout) the function with the macro sequence in it still prevents it from paying any attention from the gui, so.

I'm at a loss for how to design something like this.

I was considering actually putting this macro into its own .exe and calling it with Run(), but then there are issues of how to update the settings fields and variables and whatnot between the spawned script and the main settings window, etc.

Any tips?

Edited by nago

Share this post


Link to post
Share on other sites



Try using a hot key and then use AdLibEnable(). See what you can do there.


[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

Share this post


Link to post
Share on other sites

I suggest, due to the macros, to use HotKeySet()

... Be sure to see the demo at the bottom of the page, that may be exactly what you are looking for

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

What is happening is that your "macro" is a event so when it's executed any other events are queued. To solve that easily move your "macro" to the mainloop.

See this (rather messy) example for OnEventMode:

(run from SciTe and watch the console when you press the buttons)

#include <GUIConstantsEx.au3>
Opt("GUIOnEventMode", 1)

Global $xyz = False

GUICreate("Test")
$start = GUICtrlCreateButton("start", 10, 10)
GUICtrlSetOnEvent(-1, "_start")
$stop = GUICtrlCreateButton("stop", 10, 50)
GUICtrlSetOnEvent(-1, "_stop")

GUISetState()
GUISetOnEvent($GUI_EVENT_CLOSE, "_quit")

While 1
    If $xyz = True Then _SomeFunc()
    Sleep(10)
WEnd

Func _SomeFunc()
    While 1
        If $xyz = False Then Return
        ConsoleWrite(Random() & @CRLF)
        Sleep(10)
    WEnd
EndFunc

Func _start()
    $xyz = True
EndFunc

Func _stop()
    $xyz = False
EndFunc

Func _quit()
    Exit
EndFunc
Edited by AdmiralAlkex

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

The HotKeySet() Is a good suggestion, though I am dead-set on using a stop button instead of a hotkey, if only for ease of use. I have always considered hotkeys, with regards to user interfaces, as secondary interfaces.

As for the third reply, I will investigate this more deeply: I am not sure I understand what you mean just yet, so let me look into your example and digest it.

Edit: OK, I see. I will still have to work the "Stop" functionality into my "Macro Function", however: the Exit button should at least now work with no further modifications. This is a good vector in which to solve this problem, I'll work on a version using your method. Very clever.

In the meantime, any other suggestions are still welcome.

For an example of my "Macro Function", it's something akin to the following:

Func Macro
  WaitWinActive("Game Window")
  Sleep(200)
  Send('{ENTER}')
  sleep(20)
  Send('{ENTER}')
  sleep(20)
  Send('{DOWN}')
  sleep(30)
  ...
EndFunc

Etcetera. There are a lot of loops and various WinWaitActive()s in there, but the "main loop" of the macro function takes about two and a half minutes to complete.

Second Edit: Since I'm only using Send() and Sleep() and WinWaitActive() in the 'Macro Function', I think what I can do to achieve an "instantaneous stop", is write a custom wrapper for each function, like _MacroSend(), _MacroSleep() and _MacroWinWaitActive(), and in those wrappers, just have a simple if/then, such as:

If Not $STOP Then
  (Pass Arguments on to Proper Function)

And so if "STOP" is pressed, all functions cease doing any actual work, achieving an emergency halt.

Sound logic?

Edited by nago

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  
Followers 0