revonatu

general and specific GUI questions

9 posts in this topic

#1 ·  Posted (edited)

Hi,

I have a quite complex script and now I would like to define the initial parameters and directories via a GUI.

The first question is: Which GUI mode is best for my purposes? I don't understand in detail what the difference is. I tend to OnEvent mode as I only need the GUI at the beginning.

Edit: Ok, only in loop mode the file selection works. One question solved. But how do I pause my script and start it after I am done with the GUI?

This is my code so far:

#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <FileConstants.au3>
#include <StringConstants.au3>
#include <Date.au3>
#include <Array.au3>
#include <GUIConstantsEx.au3>
Local $AutoIt_GUI   = GUICreate("ATCOR4 - Initial Settings", 500, 400)                                                  ; title, width and height
Local $idLabel0     = GUICtrlCreateLabel("Wellcome to this ATCOR4 automation. Please choose your preferences.", 30, 10) ; text and position (left, top)
Local $idButton1    = GUICtrlCreateButton("*.meta file", 30, 50, 60)
Local $idLabel1     = GUICtrlCreateLabel("select the meta file with start and end time", 120, 55, 300, 60)
Local $idButton2    = GUICtrlCreateButton("*.pos file", 30, 80, 60); name, position and width
Local $idLabel2     = GUICtrlCreateLabel("select the pos file with flight geometry", 120, 85, 300, 60)
Local $idCombo1     = GUICtrlCreateCombo("Operation Type", 30, 150, 100)
GUICtrlSetData($idCombo1, "GUI|.inn file", "Operation Type")
Global $OperationMode = '"' & GUICtrlRead($idCombo1) & '"'

GUISetState(@SW_SHOW)                                                   ; display this GUI

 Local $idMsg = 0
    ; In this message loop we use variables to keep track of changes to the GUI controls
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
                Exit
            ;Case $GUI_EVENT_MINIMIZE
                ;MsgBox($MB_SYSTEMMODAL, "", "Dialog minimized", 2)
            ;Case $GUI_EVENT_MAXIMIZE
                ;MsgBox($MB_SYSTEMMODAL, "", "Dialog restored", 2)

            Case $idButton1
                Local $MetaOpenDialog = FileOpenDialog("Select the meta file...", @ScriptDir & "\", "Meta (*.meta)")
                $metaPath = $MetaOpenDialog
                GUICtrlSetData($idLabel1, $MetaOpenDialog)
            Case $idButton2
                Local $PosOpenDialog = FileOpenDialog("Select the pos file...", @ScriptDir & "\", "Pos (*.pos)")
                $posPath = $PosOpenDialog
                GUICtrlSetData($idLabel2, $PosOpenDialog)

        EndSwitch
    WEnd

Thanks in advance for any hints and suggestions (the shorter the code the better). :)

Edited by revonatu

Share this post


Link to post
Share on other sites



The buttons work for me as expected. :)


Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

Yes, some things work, but why does the Window not close when pressing the x Button in the upper right corner? How do I get back to my script and how do I pause it for the time the GUI is open. WinWaitActive and -Close?

Share this post


Link to post
Share on other sites

When are you not able to close your GUI? As, I was able to when it started and after hitting both buttons. 


Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

I don't know why but now it worked indeed. Maybe I included some needed package for other reasons.

I would still like to know if the loop mode is best for my case. Could I use the event mode as well? If yes, how?

After not doing many changes one of my combo boxes (operation mode --> GUI) won"t open a FileOpenDialog anymore. Can you reproduce this? I can"t find an error.

Global $metaPath    = ""    
Global $posPath     = ""    
Global $bsqPath     = ""    
Global $innPath     = ""    
Global $DEMPath     = ""


;#cs GUI Creation ################################################################################################################################
Local $AutoIt_GUI   = GUICreate("Initial Settings", 500, 300)                                                   ; title, width and height
Local $idLabel0     = GUICtrlCreateLabel("Wellcome to this automation. Please choose your preferences.", 30, 10)    ; text and position (left, top)

Local $idButton1    = GUICtrlCreateButton("*.meta file", 30, 50, 60)
Local $idLabel1     = GUICtrlCreateLabel("Select the meta file with start and end time in lines 1 and 2.", 150, 55, 300, 60, 0x0002) ; right-aligned
Local $idButton2    = GUICtrlCreateButton("*.pos file", 30, 80, 60)
Local $idLabel2     = GUICtrlCreateLabel("Select the pos file with geometry.", 150, 85, 300, 60, 0x0002) ; right-aligned

Local $idCombo1     = GUICtrlCreateCombo("operation mode", 30, 150, 100)
GUICtrlSetData($idCombo1, "GUI|.inn file", "operation mode")
Local $idLabel3     = GUICtrlCreateLabel("Select an operation mode and the corresponding input file.", 150, 155, 300, 60, 0x0002) ; right-aligned

Local $idCombo2     = GUICtrlCreateCombo("terrain type", 30, 200, 100)
GUICtrlSetData($idCombo2, "Flat|Rugged", "terrain type")
Local $idLabel4     = GUICtrlCreateLabel("Select a terrain type and in case of rugged terrain a DEM.", 150, 205, 300, 60, 0x0002) ; right-aligned

Local $idBExit      = GUICtrlCreateButton("Exit", 400, 250, 60); name, position (l t) and width
GUICtrlSetColor($idBExit, $COLOR_RED)
Local $idBRun       = GUICtrlCreateButton("Run", 30, 250, 60)
GUICtrlSetColor($idBRun, $COLOR_GREEN)

Sleep(1000)
GUISetState(@SW_SHOW)   ; display the GUI
WinWaitActive("ATCOR4 - Initial Settings")


    ; In this message loop we use variables to keep track of changes to the GUI controls ========================================================
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE , $idBExit ; when pressed, cancel and exit the script
                GUIDelete($AutoIt_GUI)
            Case $idButton1 ; when pressed, open the meta file selection, save and display the path in Label1
                $metaPath = FileOpenDialog("Select the meta file...", @ScriptDir, "Meta (*.meta)")
                GUICtrlSetData($idLabel1, $metaPath)
            Case $idButton2 ; when pressed, open the pos file selection, save and display the path in Label2
                $posPath = FileOpenDialog("Select the pos file...", @ScriptDir, "Pos (*.pos)")
                GUICtrlSetData($idLabel2, $posPath)
            Case $idCombo1 ; when pressed, save the selection as variable
                $OperationMode = GUICtrlRead($idCombo1)
                  If $OperationMode = "GUI" Then
                     $bsqPath = FileOpenDialog("Select the bsq file...", @ScriptDir, "BSQ (*.bsq")
                     GUICtrlSetData($idLabel3, $bsqPath)
                  ElseIf $OperationMode = ".inn file" Then
                     $innPath = FileOpenDialog("Select the initialisation file...", @ScriptDir, "inn (*.inn)")
                     GUICtrlSetData($idLabel3, $innPath)
                  Else
                     GUICtrlSetData($idLabel3, "The operation mode is not set yet. Please do so to continue.")
                  EndIf
            Case $idCombo2 ; when pressed, save the selection as variable
                $TerrainType = GUICtrlRead($idCombo2)
                  If $TerrainType = "Rugged" Then
                     $DEMPath = FileOpenDialog("Select the DEM...", @ScriptDir, "DEM (*.bsq;*.grd))")
                     GUICtrlSetData($idLabel4, "Rugged, DEM: " & $DEMPath)
                  ElseIf $TerrainType = "Flat" Then
                     GUICtrlSetData($idLabel4, $TerrainType)
                  Else
                     GUICtrlSetData($idLabel4, "The terrain type is not set yet. Please do so to continue.")
                  EndIf
            Case $idBRun ; when pressed, return to script and continue
                ExitLoop

        EndSwitch
    WEnd

WinClose("Initial Settings")

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

You should add in an ExitLoop line after the GUIDelete line for the close event.

GUIDelete only removes the visual elements.

Probably add a GUIDelete line before the ExitLoop line in your RUN button code too.

I would add in error checking for a lot of your code, and test various stages, variable values etc with many a MsgBox to test your code is working as anticipated.

P.S. If you only want the GUI to work momentarily, then investigate embedding it in a function, which you call from your main code at a relevant moment(s). You will get finer control that way.

Edited by TheSaint

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Of course! I could have come to that idea by myself. My script is full of error checking but in this case I forgot. There was just a bracket in the filter missing. :)

Thanks a lot.

I would still like to know if the loop mode is best for my case. Could I use the event mode as well? If yes, how?

Edited by revonatu

Share this post


Link to post
Share on other sites

revonatu,

I would still like to know if the loop mode is best for my case.

Without a definition of "is best" it is impossible to answer.

kylomas

 


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

"best" meaning most time and code efficient

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

  • Similar Content

    • anusha
      By anusha
      Hi I have jus started using auto-it . Please correct me if I'm wrong.
      I need to read data from an input in text box and search in excel file and return value in next column of matched cell on GUI.
      I have written below code but i cannot use variable which has data stored. it works only when search string is hard coded.
      Please help out.
       
      Example()
      Func Example()
      Local $GuiMain = GUICreate("EXCEL TEST", 399, 180) ;creates main GUI
      ;~ Local $idOK = GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
      Local $iWidthCell = 70
      Local $idLabel = GUICtrlCreateLabel("PART NUMBER", 10, 30, $iWidthCell,50)
      Local $RUN_1 = GUICtrlCreateButton("OK", 70, 70, 85, 25)
      Local $Input_1 = GUICtrlCreateInput("PART NUMBER", 100, 20, 120, 20)
      Local $sMenutext = GUICtrlRead($Input_1, 1)
      GUISetState(@SW_SHOW, $GuiMain)

          While 1
          $MSG = GUIGetMsg()
          Select
              Case $MSG = $GUI_EVENT_CLOSE
                  Exit
              Case $MSG = $RUN_1
                  Local $oAppl = _Excel_Open()

      Local $sFilePath1 = "D:\Anu_WorkFolder\Components.xlsx"
      Local $oWorkbook = _Excel_BookOpen($oAppl, $sFilePath1, Default, Default, True)
      Local $aResult = _Excel_RangeFind($oWorkbook, $sMenutext , Default, Default, $xlWhole)
    • Miliardsto
      By Miliardsto
      Hello.
      Drag option works only on parent window but as we can see on the parent gui is showed up child gui (on the right side with the color).
      Desired action is when we want to drag whole program we can also drag child gui and child gui will drag with parent gui.
      How to do this?
       
      #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Array.au3> GUIRegisterMsg($WM_NCHITTEST, "_NCHITTEST") $hGUI = GUICreate("Test", 500, 500, -1, -1) $cButton_0 = GUICtrlCreateButton("Child 0", 10, 10, 80, 30) $cButton_1 = GUICtrlCreateButton("Child 1", 10, 50, 80, 30) $cButton_2 = GUICtrlCreateButton("Child 2", 10, 90, 80, 30) GUISetState(@SW_SHOW, $hGUI) ; guis Global $hChild_[3] Global $countGUI = UBound($hChild_) - 1 ;MsgBox("","",$countGUI) ; licznik dla GUI Global $gui = 0 $hChild_[0] = GUICreate("Child 0", 350, 300, 150, 0, $WS_POPUP, $WS_EX_MDICHILD, $hGUI) GUISetBkColor(0xFF0000) GUISetState(@SW_SHOW, $hChild_[0]) $hChild_[1] = GUICreate("Child 1", 350, 300, 150, 0, $WS_POPUP, $WS_EX_MDICHILD, $hGUI) GUISetBkColor(0x00FF00) GUISetState(@SW_HIDE, $hChild_[1]) $hChild_[2] = GUICreate("Child 2", 350, 300, 150, 0, $WS_POPUP, $WS_EX_MDICHILD, $hGUI) GUISetBkColor(0x0000FF) GUISetState(@SW_HIDE, $hChild_[2]) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cButton_0 _All_Hide() GUISetState(@SW_SHOW, $hChild_[0]) $gui = 0 Case $cButton_1 _All_Hide() GUISetState(@SW_SHOW, $hChild_[1]) $gui = 1 Case $cButton_2 _All_Hide() GUISetState(@SW_SHOW, $hChild_[2]) $gui = 2 EndSwitch WEnd Func _All_Hide() GUISetState(@SW_HIDE, $hChild_[0]) GUISetState(@SW_HIDE, $hChild_[1]) GUISetState(@SW_HIDE, $hChild_[2]) EndFunc Func _NCHITTEST($hWnd, $uMsg, $wParam, $lParam) If $hWnd = $hGUI Then Local $aPos = WinGetPos($hWnd) If Abs(BitAND(BitShift($lParam, 16),0xFFFF)- $aPos[1]) < 500 Then Return $HTCAPTION EndIf Return $GUI_RUNDEFMSG EndFunc  
    • IAMK
      By IAMK
      Hello,
       
      I have a script which uses a GUI with two buttons. It gets shown and hidden., and pressing the buttons (including their hotkeys) highlights the button, making you able to press enter the next time.
      However, I don't want that.
       
      I've tried using WinActivate() to make enter do things on another program, but the enter is still tied to the AutoIT GUI (which still has the button highlighted).
       
      Here's the important part of my code:
      $MY_GUI = GUICreate("Check.exe", 400, 300, ((@DesktopWidth / 2) - 200), -500) WinSetOnTop($MY_GUI, "", 1) ;Keeps the window on the top. $Button1 = GUICtrlCreateButton("Pass (Ctrl+P)", 40, 250, 120, 40, $WS_GROUP) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") $Button2 = GUICtrlCreateButton("Fail (Ctrl+F)", 240, 250, 120, 40, $WS_GROUP) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") $GUIText = GUICtrlCreateLabel("", 20, 10, 360, 230) GUICtrlSetFont(-1, 13, 400, 0, "MS Sans Serif") GUICtrlSetData($GUIText, Execute($stepMessage[$step])) $showGUI = "True" GUISetState(@SW_SHOW) While($showGUI = "True") $buttonPressed = GUIGetMsg() Switch $buttonPressed Case $Button1 ;Pass $pass = "True" $buttonPressed = 0 $showGUI = "False" GUISetState(@SW_HIDE) Case $Button2 ;Fail $buttonPressed = 0 $showGUI = "False" GUISetState(@SW_HIDE) While($message = "") $message = InputBox("Check.exe", "Please enter the reason the step failed." & @CRLF, "", "", 300, 200, ((@DesktopWidth / 2) - 150), -400) WEnd Return $message EndSwitch WEnd Local $pass = "False" ;Whether "Pass" or "Fail" was pressed. Local $failLog = xxxfunc($pass) ;Returns a message to log if the step failed. ##THIS CALLS THE CODE SNIPPET ABOVE## FileWrite($file, _Now() & ": Step " & $step & getStatus($pass) & "and took " & Ceiling(TimerDiff($timer) / 1000) & " seconds." & @CRLF) If($failLog <> "") Then FileWrite($file, "Logged comment: " & $failLog & @CRLF) EndIf WinActivate("[TITLE:ProgramName]") ;Hotkeys: HotKeySet("^{p}", "pressPass") HotKeySet("^{f}", "pressFail") Func pressPass() $buttonPressed = $Button1 EndFunc Func pressFail() $buttonPressed = $Button2 EndFunc  
      The GUI's button/hotkey pressing works correctly.
      The same WinActivate code works in another script of mine.
      Together, WinActivate is not take "Active" away from the GUI's last-pressed button. How do I fix this?
       
      Thank you in advance.
    • fatpig
      By fatpig
      Dear AutoIT Community.
      I am currently working on a program that will display lots of images in a scroll down GUI.
      I create the GUI based on the number of images, which works fine.
      But all images I place using GuiCtrlCreatePic above a threshold of around 32000 pixels (cant say exactly) are placed at negative locations and finally will reach 0 again
      and will then populate on top of the images placed there before.
      For $i = 1 To $Images[0] ; Get picture dimensions $hImage = _GDIPlus_ImageLoadFromFile($ImgRep & $Images[$i]) $iX = _GDIPlus_ImageGetWidth($hImage) $iY = _GDIPlus_ImageGetHeight($hImage) _GDIPlus_ImageDispose($hImage) ; Resize & place images in GUI $Pic[$i] = GUICtrlCreatePic($ImgRep & $Images[$i], $Spacer, Round($yPos, 0), $MaxImgWidth, $MaxImgWidth * ($iY / $iX)) $yPos = $yPos + $MaxImgWidth * ($iY / $iX) + $Spacer $log = $log & "|" & $yPos $currentlut = $Images[1] Next I have found a limit at 32767 pixels for some GUI elements when googling around.
      Can someone tell me how to circumvent that?
      thanks!
      cheers
      Felix
    • Shirdish_chakravarthi
      By Shirdish_chakravarthi
      Hello Guys this is my gui and i need the numeric value typed in the highlighted  inputbox. if this value is greater than 1 i need to perform some operations
      \
       
      Here is the summary about that field which i got from wininfo tool

      i tried writing the code as shown below.. but the msgbox is popping up empty value..when the same code is pasted under some button action i am able to access the value present in the field..but when placed alone as written in the attached script i am unable to fetch it... 

      here i am using the valu present in the field

      can you guys tell me what's wrong??? or how can i get that value?
       
      My_GUI.au3