Jump to content

Multiple GUI Not Behaving as Expected


Recommended Posts

I'm taking a stab at my first GUI and am running into an issue. I've studied the "Managing Multiple GUIs" Wiki entry pretty thoroughly, but I'm going wrong somewhere.

If I keep the "OK" and "Cancel" buttons code active for my second GUI in the code below, I get stuck in a loop, but I haven't been able to figure out why it's even firing when it is.

Can you please take a look at what I have and tell me where I'm going wrong? I'm sure it's obvious, but I'm just not seeing it.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <TabConstants.au3>

Global $mTestApp, $sSetMenu, $sOk, $sCancel

_MainGUI()

Func _MainGUI()
#region ### START Koda GUI section ###
$mTestApp = GUICreate("TestApp - GUI Version", 436, 354, 263, 131)
$mFile = GUICtrlCreateMenu("&File")
$mClose = GUICtrlCreateMenuItem("Close", $mFile)
$mOptions = GUICtrlCreateMenu("&Options")
$mSettings = GUICtrlCreateMenuItem("Settings", $mOptions)
$mHelp = GUICtrlCreateMenu("&Help")
$mGuide = GUICtrlCreateMenuItem("Guide", $mHelp)
$mAbout = GUICtrlCreateMenuItem("About...", $mHelp)
GUISetBkColor(0xFFFFFF)
$mLogo = GUICtrlCreatePic("", 7, 5, 180, 130)
$mCatGrp = GUICtrlCreateGroup("Category", 207, 5, 215, 130)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$mDoc = GUICtrlCreateRadio("DC", 227, 25, 113, 38)
$mHD = GUICtrlCreateRadio("HD", 227, 55, 113, 38)
$mSD = GUICtrlCreateRadio("SD", 227, 85, 113, 38)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$mFilesGrp = GUICtrlCreateGroup("Files", 7, 155, 415, 90)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$mLabel = GUICtrlCreateLabel("Select Folder to Process", 17, 175, 143, 17)
$mSource = GUICtrlCreateInput("", 17, 200, 300, 21)
$mBrowse = GUICtrlCreateButton("Browse", 332, 198, 70, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$mGo = GUICtrlCreateButton("GO", 132, 258, 75, 25)
$mCancel = GUICtrlCreateButton("Cancel", 222, 258, 75, 25)
$mProgress = GUICtrlCreateProgress(7, 298, 420, 25)
GUISetState()
#endregion ### END Koda GUI section ###

While 1
  $mMsg = GUIGetMsg(1)
  Switch $mMsg[1] ; Check Which GUI Sent the Message
   Case $mTestApp ; _MainGUI
    Select
     Case $mMsg[0] = $mDoc And BitAND(GUICtrlRead($mDoc), $GUI_CHECKED) = $GUI_CHECKED
      $udcat = $mDoc
     Case $mMsg[0] = $mHD And BitAND(GUICtrlRead($mHD), $GUI_CHECKED) = $GUI_CHECKED
      $udcat = $mHD
     Case $mMsg[0] = $mSD And BitAND(GUICtrlRead($mHD), $GUI_CHECKED) = $GUI_CHECKED
      $udcat = $mSD
    EndSelect
    Select
     Case $mMsg[0] = $mBrowse
      $full_path = FileSelectFolder("Select Folder to Process", "", 6, @HomeDrive)
      GUICtrlSetData($mSource, $full_path)
     Case $mMsg[0] = $mSource
      $full_path = $mSource
    EndSelect
    Switch $mMsg[0] ; Check the messages for $mTestApp
     Case $GUI_EVENT_CLOSE ; Close Button
      ExitLoop
     Case $mGuide ; Help - Guide
      MsgBox(0, "Guide", "You clicked the Guide Button!") ; Add code to open HowTo file/window
     Case $mAbout ; Help - About
      MsgBox(0, "About", "You clicked the About Button!") ; Add code to open About file/window
     Case $mSettings ; Options - Settings button pressed
      GUISetState(@SW_DISABLE, $mTestApp) ; Disable access to main window while Settings are open
      _SettingsGUI() ; Launch Settings window
     Case $mGo
      MsgBox(0, "GO", "You clicked the GO Button!")
     Case $mCancel
      ExitLoop
    EndSwitch

   ;==================================================
   ; 'Options - Settings' Menu Item Window
   ;==================================================
   Case $sSetMenu ; _SettingsGUI Func
    Switch $mMsg[0] ; Check the messages for $sSetMenu
     Case $GUI_EVENT_CLOSE ; Close Button
      GUIDelete($sSetMenu) ; Just delete the GUI window
      GUISetState(@SW_ENABLE, $mTestApp) ; Enable access to main window again
     Case $sOk
      MsgBox(4096, "OK", "You clicked OK!")
     Case $sCancel
      MsgBox(4096, "Cancel", "You clicked Cancel!")
      GUIDelete($sSetMenu) ; Just delete the GUI window
      GUISetState(@SW_ENABLE, $mTestApp) ; Enable access to main window again
    EndSwitch
  EndSwitch
WEnd
EndFunc   ;==>_MainGUI

Func _SettingsGUI()
#region ### START Koda GUI section ###
$sSetMenu = GUICreate("Settings", 402, 331, 266, 131, -1, -1, $mTestApp)
$sSettings = GUICtrlCreateTab(10, 6, 385, 281)
$sConfigTab = GUICtrlCreateTabItem("Config")
$slblDocCat = GUICtrlCreateLabel("DC Category", 132, 107, 120, 17)
$slblHDCat = GUICtrlCreateLabel("HD Category", 132, 167, 102, 17)
$slblSDCat = GUICtrlCreateLabel("SD Category", 132, 226, 101, 17)
$sVerChk = GUICtrlCreateCheckbox("Check for Updates", 132, 38, 110, 17)
$sLogging = GUICtrlCreateCheckbox("Enable Logging", 132, 68, 100, 17)
$sDocCat = GUICtrlCreateInput("", 132, 127, 121, 21)
$sHDCat = GUICtrlCreateInput("", 132, 187, 121, 21)
$sSDCat = GUICtrlCreateInput("", 132, 246, 121, 21)
$sCatGrp = GUICtrlCreateGroup("Categories", 25, 94, 353, 185)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$sPathsTab = GUICtrlCreateTabItem("Paths")
$sNamingTab = GUICtrlCreateTabItem("Naming")
$sFilesTab = GUICtrlCreateTabItem("Files")
GUICtrlCreateTabItem("")
$sOk = GUICtrlCreateButton("OK", 115, 296, 75, 25)
$sCancel = GUICtrlCreateButton("Cancel", 211, 296, 75, 25)
GUISetState()
#endregion ### END Koda GUI section ###
EndFunc   ;==>_SettingsGUI
Link to comment
Share on other sites

Ugh - I just figured it out by stumbling on another post that was seemingly unrelated....

FYI for anyone that comes after me: I needed to set the values for the Globals to 9999.

I do have another simple question:

When I close the "Settings" window, the main app window doesn't stay top-most. Is there a way to force this?

Link to comment
Share on other sites

  • Moderators

NoTolerance,

Is there a way to force this?

Yes - just reenable the main GUI before you delete the settings GUI -like this: ;)

Case $sSetMenu ; _SettingsGUI Func
    Switch $mMsg[0] ; Check the messages for $sSetMenu
        Case $sCancel
            MsgBox(4096, "Cancel", "You clicked Cancel!")
            ContinueCase
        Case $GUI_EVENT_CLOSE ; Close Button
            GUISetState(@SW_ENABLE, $mTestApp) ; Enable access to main window again
            GUIDelete($sSetMenu) ; Just delete the GUI window
        Case $sOk
            MsgBox(4096, "OK", "You clicked OK!")
    EndSwitch

I also showed how to save the typing fingers a bit by using ContinueCase. ;)

Please ask if anything is unclear. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

_MainGUI()
Func _MainGUI()
#region ### START Koda GUI section ###
$mTestApp = GUICreate("TestApp - GUI Version", 436, 354, 263, 131)
$mFile = GUICtrlCreateMenu("&File")
$mClose = GUICtrlCreateMenuItem("Close", $mFile)
$mOptions = GUICtrlCreateMenu("&Options")
$mSettings = GUICtrlCreateMenuItem("Settings", $mOptions)
$mHelp = GUICtrlCreateMenu("&Help")
$mGuide = GUICtrlCreateMenuItem("Guide", $mHelp)
$mAbout = GUICtrlCreateMenuItem("About...", $mHelp)
GUISetBkColor(0xFFFFFF)
$mLogo = GUICtrlCreatePic("", 7, 5, 180, 130)
$mCatGrp = GUICtrlCreateGroup("Category", 207, 5, 215, 130)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$mDoc = GUICtrlCreateRadio("DC", 227, 25, 113, 38)
$mHD = GUICtrlCreateRadio("HD", 227, 55, 113, 38)
$mSD = GUICtrlCreateRadio("SD", 227, 85, 113, 38)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$mFilesGrp = GUICtrlCreateGroup("Files", 7, 155, 415, 90)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$mLabel = GUICtrlCreateLabel("Select Folder to Process", 17, 175, 143, 17)
$mSource = GUICtrlCreateInput("", 17, 200, 300, 21)
$mBrowse = GUICtrlCreateButton("Browse", 332, 198, 70, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$mGo = GUICtrlCreateButton("GO", 132, 258, 75, 25)
$mCancel = GUICtrlCreateButton("Cancel", 222, 258, 75, 25)
$mProgress = GUICtrlCreateProgress(7, 298, 420, 25)
GUISetState()
#endregion ### END Koda GUI section ###
While 1
$mMsg = GUIGetMsg(1)
Switch $mMsg[1] ; Check Which GUI Sent the Message
Case $mTestApp ; _MainGUI
Select
     Case $mMsg[0] = $mDoc And BitAND(GUICtrlRead($mDoc), $GUI_CHECKED) = $GUI_CHECKED
     $udcat = $mDoc
     Case $mMsg[0] = $mHD And BitAND(GUICtrlRead($mHD), $GUI_CHECKED) = $GUI_CHECKED
     $udcat = $mHD
     Case $mMsg[0] = $mSD And BitAND(GUICtrlRead($mHD), $GUI_CHECKED) = $GUI_CHECKED
     $udcat = $mSD
EndSelect
Select
     Case $mMsg[0] = $mBrowse
     $full_path = FileSelectFolder("Select Folder to Process", "", 6, @HomeDrive)
     GUICtrlSetData($mSource, $full_path)
     Case $mMsg[0] = $mSource
     $full_path = $mSource
EndSelect
Switch $mMsg[0] ; Check the messages for $mTestApp
     Case $GUI_EVENT_CLOSE ; Close Button
     ExitLoop
     Case $mGuide ; Help - Guide
     MsgBox(0, "Guide", "You clicked the Guide Button!") ; Add code to open HowTo file/window
     Case $mAbout ; Help - About
     MsgBox(0, "About", "You clicked the About Button!") ; Add code to open About file/window
     Case $mSettings ; Options - Settings button pressed
     GUISetState(@SW_DISABLE, $mTestApp) ; Disable access to main window while Settings are open
     _SettingsGUI() ; Launch Settings window
     Case $mGo
     _MainScript($udcat, $full_path)
     Case $mCancel
     ExitLoop
EndSwitch
EndSwitch
WEnd
EndFunc ;==>_MainGUI
Func _MainScript($fUDCat, $fFullPath)
; Do some stuff
; Then do more stuff
; Do even more stuff
; We're almost done with stuff to do
; *phew* Finally done doing stuff!
EndFunc ;==>_MainScript

Can you point me at a relevant thread or tutorial on utilizing the progress bar for this? I've been reading thread after thread on it, but nothing seems to apply or I just can't wrap my head around what's being explained.

This is a slightly trimmed version of the code above (I just removed the _SettingsGUI to make it easier to read and added the call to the _MainScript function when the OK button is pressed).

My goal is to have the Progress bar in the MainGUI update as the _MainScript function runs. The MainGUI is just taking a couple of user inputs, and then passes those values to the _MainScript. The _MainScript does all the work in the background, but I'd like the user to see progress is happening. Sometimes the script will complete in seconds, other times it may run for a few minutes.

Most of the Progress Bar posts I've read are dealing with either copying files or only focus on tracking progress within the same GUI.

Edited by NoTolerance
Link to comment
Share on other sites

Use GUICtrlSetData($mProgress, <the percentage you want the progress bar set at>). You will either have to make the variable $mProgress a global variable or pass its value on to the _MainScript function when you run it, so that you can update the progress bar.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Use GUICtrlSetData($mProgress, <the percentage you want the progress bar set at>). You will either have to make the variable $mProgress a global variable or pass its value on to the _MainScript function when you run it, so that you can update the progress bar.

Would I use that within the _MainScript function like so:

Func _MainScript($fUDCat, $fFullPath, $fProg)
; Do some stuff
GUICtrlSetData($mProgress, 20)
; Then do more stuff
GUICtrlSetData($mProgress, 40)
; Do even more stuff
GUICtrlSetData($mProgress, 60)
; We're almost done with stuff to do
GUICtrlSetData($mProgress, 80)
; *phew* Finally done doing stuff!
GUICtrlSetData($mProgress, 100)
EndFunc ;==>_MainScript

Or....?

Link to comment
Share on other sites

If you don't need to update the progress bar with a realistic value, because you don't know how long something will take, you can use the $PBS_MARQUEE style when you create the ProgressBar which creates one that just scans back and forth and doesn't need to be updated.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • Moderators

If you don't want to make $mProgress a Global variable, you would pass it like so as BrewManNH suggested.

Func _MainScript($fUDCat, $fFullPath, $fProg, $mProgress)

Edit: Or $PBS_MARQUEE. Too slow again :)

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

I slapped in some test values as described in so I could see if that worked and it did. So thank you for that.

However, I like your second suggestion better, as adding a progress meter doesn't make a lot of sense in my application. I'm going to try that next.

Link to comment
Share on other sites

If you don't want to make $mProgress a Global variable, you would pass it like so as BrewManNH suggested.

Func _MainScript($fUDCat, $fFullPath, $fProg, $mProgress)

Edit: Or $PBS_MARQUEE. Too slow again :)

Actually, I did with the $fProg variable so as to not confuse variable names. But thanks for pointing that out! I should've mentioned that's what I was doing.
Link to comment
Share on other sites

If you don't need to update the progress bar with a realistic value, because you don't know how long something will take, you can use the $PBS_MARQUEE style when you create the ProgressBar which creates one that just scans back and forth and doesn't need to be updated.

I've tried using $PBS_MARQUEE a couple of different ways with no success. I must have something wrong with the syntax or where it should go to fire it properly.

If I do:

Case $mGo
If $udcat = "" Then
MsgBox(16, "Error", "You need to choose a Category!")
ElseIf $full_path = "" Then
MsgBox(16, "Error", "You need to choose a folder to process!")
Else
GUICtrlSendMsg($mProgress, $PBM_SETMARQUEE, True, 50)
GUISetState(@SW_DISABLE, $mTestApp)
_MainScript($udcat, $full_path)
GUISetState(@SW_ENABLE, $mTestApp)
EndIf

... it fires after the _MainScript function runs.

If I do:

Func _MainScript($mUDCat, $mFullPath, $mProgress)

GUICtrlSendMsg($mProgress, $PBM_SETMARQUEE, True, 50)

... it still fires off after the _MainScript function runs.

So what am I doing wrong now?

BTW, I don't see anything in the Help files about $PBS_MARQUEE.

Link to comment
Share on other sites

Try this demo and ask if anything doesn't make sense.

#include <Progressconstants.au3>
GUICreate("test", 400, 200 )
$progressbar = GUICtrlCreateProgress(30, 30, 330, 20, $PBS_MARQUEE)
GUICtrlSendMsg($progressbar, $PBM_SETMARQUEE, True, 20) ; the 20 sets the update speed
GUISetState()
While GUIGetMsg() <> -3
     Sleep(10)
WEnd

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

If your script is doing a lot of work in the background that is taking up a large amount of the CPU processing time, the marquee style is going to freeze until that back ground work is done. I use it on a script that has a listview and when the LV has a lot of items in it and I am sorting it, the progressbar won't move until after the sorting is done. There's no work around that I've found to fix that.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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...