Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

Starting & Stopping within GUI


  • Please log in to reply
5 replies to this topic

#1 kiffab

kiffab

    Wayfarer

  • Active Members
  • Pip
  • 72 posts

Posted 14 July 2012 - 07:11 AM

Hi Guys

Building an app in work and need some expert assistance.

I have a GUI with a start/stop button. When I click it, it executes a function. This function reads a log and returns a status. I am using:

case $my_button MyFunction() AdlibRegister("My Function here", $interval)


$interval is just a refresh time like 10 secs, 20 secs etc.

If clicked a second time, I want it to STOP doing what it's doing. I'm not sure how to do this. The alternative is to just exit but I'd rather stop and remain in app.

Any help appreciated.

Thanks.







#2 Melba23

Melba23

    I'm old - what's your excuse?

  • Moderators
  • 20,901 posts

Posted 14 July 2012 - 07:17 AM

kiffab,

Perhaps like this: ;)
AutoIt         
#include <GUIConstantsEx.au3> $hGUI = GUICreate("Test", 500, 500) $cButton = GUICtrlCreateButton("Run", 10, 10, 80, 30) GUISetState() While 1     Switch GUIGetMsg()         Case $GUI_EVENT_CLOSE             Exit         Case $cButton             Switch GUICtrlRead($cButton)                 Case "Run"                     MsgBox(0, "Hi", "Function Running")                     AdlibRegister("_Run", 1000)                     GUICtrlSetData($cButton, "Stop")                 Case "Stop"                     MsgBox(0, "Hi", "Function Ended")                     AdlibUnRegister("_Run")                     GUICtrlSetData($cButton, "Run")             EndSwitch     EndSwitch WEnd Func _Run()     ConsoleWrite("Running at " & @SEC & @CRLF) EndFunc

Any help? :)

M23
StringSize - Automatically size controls to fit text                                                               ExtMsgBox - A user customisable replacement for MsgBox
Toast - Small GUIs which pop out of the Systray                                                                Marquee - Scrolling tickertape GUIs
Scrollbars - Automatically sized scrollbars with a single command                                   GUIFrame - Subdivide GUIs into many adjustable frames
GUIExtender - Extend and retract multiple sections within a GUI                                      NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes
ChooseFileFolder - Single and multiple selections from specified path tree structure      Notify - Small notifications on the edge of the display
Date_Time_Convert - Easily convert date/time formats, including the language               GUIListViewEx - Insert, delete, move, drag, sort and edit ListView items

#3 kiffab

kiffab

    Wayfarer

  • Active Members
  • Pip
  • 72 posts

Posted 14 July 2012 - 07:41 AM

adlibunregister !!! DOH!!!

Thanks buddy :guitar:

#4 kiffab

kiffab

    Wayfarer

  • Active Members
  • Pip
  • 72 posts

Posted 14 July 2012 - 07:48 AM

One complication... I am using an image as my button. :oops:
Can the same thing be achieved?

The button has an initial stop type image (red light). When clicked, it changes to green (on).

Also, I should add it's not technically a "button" - I'm using GUICtrlCreatePic. Sorry.

Edited by kiffab, 14 July 2012 - 07:51 AM.


#5 Melba23

Melba23

    I'm old - what's your excuse?

  • Moderators
  • 20,901 posts

Posted 14 July 2012 - 08:03 AM

kiffab,

I am using an image as my button. Can the same thing be achieved?

Very easily: :)
AutoIt         
#include <GUIConstantsEx.au3> Global $iColour = "Red" $sPath = StringRegExpReplace(@AutoItExe, "(^.*)(.*)", "1") $sRed = $sPath & "ExamplesGUIAdvancedImagesRed.bmp" $sGrn = $sPath & "ExamplesGUIAdvancedImagesGreen.bmp" $hGUI = GUICreate("Test", 500, 500) $cPic = GUICtrlCreatePic($sRed, 10, 10, 30, 30) GUISetState() While 1     Switch GUIGetMsg()         Case $GUI_EVENT_CLOSE             Exit         Case $cPic             Switch $iColour                 Case "Red"                     MsgBox(0, "Hi", "Function Running")                     AdlibRegister("_Run", 1000)                     GUICtrlSetImage($cPic, $sGrn)                     $iColour = "Green"                 Case "Green"                     MsgBox(0, "Hi", "Function Ended")                     AdlibUnRegister("_Run")                     GUICtrlSetImage($cPic, $sRed)                     $iColour = "Red"             EndSwitch     EndSwitch WEnd Func _Run()     ConsoleWrite("Running at " & @SEC & @CRLF) EndFunc

M23
StringSize - Automatically size controls to fit text                                                               ExtMsgBox - A user customisable replacement for MsgBox
Toast - Small GUIs which pop out of the Systray                                                                Marquee - Scrolling tickertape GUIs
Scrollbars - Automatically sized scrollbars with a single command                                   GUIFrame - Subdivide GUIs into many adjustable frames
GUIExtender - Extend and retract multiple sections within a GUI                                      NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes
ChooseFileFolder - Single and multiple selections from specified path tree structure      Notify - Small notifications on the edge of the display
Date_Time_Convert - Easily convert date/time formats, including the language               GUIListViewEx - Insert, delete, move, drag, sort and edit ListView items

#6 kiffab

kiffab

    Wayfarer

  • Active Members
  • Pip
  • 72 posts

Posted 14 July 2012 - 08:13 AM

Perfect! Works a treat and I understand exactly what you've done there. This will be useful for other parts of my app. Thank you :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users