Jump to content

Calling child gui more than once from parent gui


 Share

Recommended Posts

Group,

First, in case they read this, just wanted to thank SmOke N and gafrost for helping on different pieces of this gui from previous posts, you make it look easy! Now on to the question/issue. In the following script, I have a child gui being called. The child gui prompts for certain informaiton and returns this information to the parent gui, for the most part this works as expected and without issue. However, once the child gui has ran 1 time, I cannot run it again without exiting the parent gui and restarting the script (this is probably a simple fix, but simple can be a relative term...) However I seem to be missing the logic on keeping the child gui available repeatedly, to run it over and over from the parent gui during the same instance.

Second, in the child gui you'll notice a 'clear' button. I would like to have this button clear the selected fields of the combo list boxes but leave the possible selections available, i.e. allow the user to start over. Right now the only thing I seem to be able to do is clear the entire combo box, removing all possible selections from view... :)

Let me know if anyone has any suggestions or can point out what I'm doing wrong.

and as always, thanks in advance

Zenkensei

#include <GUIConstants.au3>
Dim $ADivCombo1
Dim $ASiteCombo1
Dim $APadCombo1
Dim $AClassCombo1
Dim $AModelCombo1
Dim $AClosetCombo1
Dim $ASeriesCombo1
Dim $DivID
Dim $SiteID
Dim $PadID
Dim $ClassID
Dim $ModelID
Dim $ClosetID
Dim $SeriesID

; == GUI generated with Koda ==
$Form1 = GUICreate("AForm1", 282, 441, 192, 113)
$Button1 = GUICtrlCreateButton("Switch Name", 24, 24, 73, 25)
GUICtrlSetTip(-1, "Start Child Menu")
$Input1 = GUICtrlCreateInput("AInput1", 112, 24, 145, 21, -1, $WS_EX_CLIENTEDGE)
GUICtrlSetTip(-1, "Returned from ChildGUI")
$Button2 = GUICtrlCreateButton("Ok", 24, 80, 73, 25)
$Button3 = GUICtrlCreateButton("Exit", 184, 80, 73, 25)
GUISetState(@SW_SHOW)
While 1
   $msg = GUIGetMsg()
   Select
      Case $msg = $GUI_EVENT_CLOSE
         ExitLoop
      Case $msg = $Button1
         GUICtrlSetData($Input1, _GuiChild())
      Case Else
        ;;;;;;;
   EndSelect
WEnd
Exit

Func _GuiChild()
  ; == GUI generated with Koda ==
   $CiscoNamer = GUICreate("Cisco Switch Namer", 232, 441, 367, 114)
   GUICtrlCreateLabel("Division:", 24, 16, 55, 20)
   GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
   GUICtrlSetTip(-1, "Select the Division")
   $ADivCombo1 = GUICtrlCreateCombo("", 88, 16, 121, 21)
   GUICtrlSetData(-1, "Bloomingdales|Bloomingdales.com|FACS Central|FACS South|FACS West|Federated Corporate|Federated Systems|Fed-Logistics|Home Office|Macys.com|Macys Marketing|Macys East|Macys Home|Macys Florida|Macys Merchandising|Macys Northwest|Macys South|Macys West|Overseas Office|Space")
   GUICtrlSetTip(-1, "Choose Division")
   GUICtrlCreateLabel("Site ID:", 24, 56, 46, 20)
   GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
   GUICtrlSetTip(-1, "Select Divisional Site ID")
   $ASiteCombo1 = GUICtrlCreateCombo("", 88, 56, 121, 21)
   GUICtrlSetData($ASiteCombo1, _ComboInsertNum3(200, 3), 'Choose Number'); 1000 and 3 are optional, just used to show you you could change it
  ; GUICtrlSetData(-1, "000|001|002|003|004|005")
   GUICtrlSetTip(-1, "Choose Site ID")
   GUICtrlCreateLabel("Pad ID:", 24, 96, 48, 20)
   GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
   GUICtrlSetTip(-1, "Select Store PAD ID")
   $APadCombo1 = GUICtrlCreateCombo("", 88, 96, 121, 21)
   GUICtrlSetData(-1, "X|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z")
   GUICtrlSetTip(-1, "Choose the site Pad ID")
   GUICtrlCreateLabel("Class ID:", 24, 136, 57, 20)
   GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
   GUICtrlSetTip(-1, "Class ID is Fixed")
   $AClassCombo1 = GUICtrlCreateCombo("", 88, 136, 121, 21)
   GUICtrlSetData(-1, "N")
   GUICtrlSetTip(-1, "Class ID Fixed")
   GUICtrlCreateLabel("Model:", 24, 176, 45, 20)
   GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
   GUICtrlSetTip(-1, "Select the Model")
   $AModelCombo1 = GUICtrlCreateCombo("", 88, 176, 121, 21)
   GUICtrlSetData(-1, "1900 Switch|2900 Switch|3500 Switch|3700 Switch")
   GUICtrlSetTip(-1, "Select Switch Model")
   GUICtrlCreateLabel("Closet:", 24, 216, 45, 20)
   GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
   GUICtrlSetTip(-1, "Select the Switch Closet")
   $AClosetCombo1 = GUICtrlCreateCombo("", 88, 216, 121, 21)
   GUICtrlSetData(-1, "Computer Room|Generic Switch|POS Room|RF|01A|01B|01C|01D|01E|01F|02A|02B|02C|02D|02E|02F|03A|03B|03C|03D|03E|03F|04A|04B|04C|04D|04E|

04F|05A|05B|05C|05D|05E|05F|06A|06B|06C|06D|06E|06F|07A|07B|07C|07D|07E|07F|08A|08B|08C|08D|08E|08F|

09A|09B|09C|09D|09E|09F|10A|10B|10C|10D|10E|10F")
   GUICtrlSetTip(-1, "Select Switch Closet")
   GUICtrlCreateLabel("Series:", 24, 256, 46, 20)
   GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
   GUICtrlSetTip(-1, "Select Switch Number")
   $ASeriesCombo1 = GUICtrlCreateCombo("", 88, 256, 121, 21)
   GUICtrlSetData($ASeriesCombo1, _ComboInsertNum2(99, 2), 'Choose Number'); 1000 and 3 are optional, just used to show you you could change it
  ; GUICtrlSetData(-1, "01|02|03|04|05")
   GUICtrlSetTip(-1, "Select Series Switch")
   $Button1 = GUICtrlCreateButton("Finish", 24, 400, 65, 25)
   GUICtrlSetTip(-1, "Accept Switch Name")
   $AClearButton2 = GUICtrlCreateButton("Clear", 128, 400, 65, 25)
   GUICtrlSetTip(-1, "Clear the Form")
  ; GUICtrlCreateLabel("Switch Name", 56, 312, 97, 24)
  ; GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
  ; GUICtrlSetTip(-1, "Switch Name")
   $ASwitchInput1 = GUICtrlCreateInput("", 24, 344, 169, 24, -1, $WS_EX_CLIENTEDGE)
   GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
   GUICtrlSetTip(-1, "Switch Name")
   
   GUISetState(@SW_SHOW)
   While 1
      $DivID = (GUICtrlRead($ADivCombo1))
      If $DivID = "Bloomingdales" Then $DivID = "BL"
      If $DivID = "Bloomingdales.com" Then $DivID = "BD"
      If $DivID = "FACS Central" Then $DivID = "FC"
      If $DivID = "FACS South" Then $DivID = "FA"
      If $DivID = "FACS West" Then $DivID = "FW"
      If $DivID = "Federated Corporate" Then $DivID = "FD"
      If $DivID = "Federated Systems" Then $DivID = "FS"
      If $DivID = "Fed-Logistics" Then $DivID = "FL"
      If $DivID = "Home Office" Then $DivID = "HO"
      If $DivID = "Macys.com" Then $DivID = "MD"
      If $DivID = "Macys Marketing" Then $DivID = "MK"
      If $DivID = "Macys South" Then $DivID = "MS"
      If $DivID = "Macys East" Then $DivID = "ME"
      If $DivID = "Macys Florida" Then $DivID = "MF"
      If $DivID = "Macys Home" Then $DivID = "MH"
      If $DivID = "Macys Merchandising" Then $DivID = "MG"
      If $DivID = "Macys Northwest" Then $DivID = "MN"
      If $DivID = "Macys West" Then $DivID = "MW"
      If $DivID = "Overseas Office" Then $DivID = "OS"
      If $DivID = "Space" Then $DivID = "SP"
      $SiteID   = (GUICtrlRead($ASiteCombo1))
      $PadID = (GUICtrlRead($APadCombo1))
      $ClassID = (GUICtrlRead($AClassCombo1))
      
     ; The following section formats the switch model to a 3 character code
      $ModelID = (GUICtrlRead($AModelCombo1))
      If $ModelID = "1900 Switch" Then $ModelID = "S19"
      If $ModelID = "2900 Switch" Then $ModelID = "S29"
      If $ModelID = "3500 Switch" Then $ModelID = "S35"
      If $ModelID = "3700 Switch" Then $ModelID = "S37"
      
     ; The following section formats the closet assignment to a 3 character code
      $ClosetID = (GUICtrlRead($AClosetCombo1))
      If $ClosetID = "Computer Room" Then $ClosetID = "CRM"
      If $ClosetID = "Generic Switch" Then $ClosetID = "STO"
      If $ClosetID = "POS Room" Then $ClosetID = "POS"
      If $ClosetID = "RF" Then $ClosetID = "RFQ"
      
      $SeriesID = (GUICtrlRead($ASeriesCombo1))
      
      GUICtrlSetData($ASwitchInput1, $DivID & $SiteID & $PadID & $ClassID & $ModelID & $ClosetID & $SeriesID)
      
      
      $msg2 = GUIGetMsg()
      Select
         Case $msg2 = $GUI_EVENT_CLOSE
            ExitLoop
         Case $msg2 = ($Button1)
            ExitLoop
         Case $msg2 = ($AClearButton2)
            _clearChildForm()
      EndSelect
   WEnd
   $tmp = GUICtrlRead($ASwitchInput1)
   GUIDelete($CiscoNamer)
   Return $tmp
EndFunc  ;==>_GuiChild


Func _ComboInsertNum2($i_Count = '99', $i_LeadingZeros = '2')
   Local $i_Data = ''
   For $i = 1 To $i_Count
      $i_Data = $i_Data & StringReplace(StringFormat('%' & $i_LeadingZeros & 'g', $i), ' ', '0') & '|'
   Next
   Return StringTrimRight($i_Data, 1)
EndFunc  ;==>_ComboInsertNum2

Func _ComboInsertNum3($i_Count = '100', $i_LeadingZeros = '3')
   Local $i_Data = ''
   For $i = 0 To $i_Count
      $i_Data = $i_Data & StringReplace(StringFormat('%' & $i_LeadingZeros & 'g', $i), ' ', '0') & '|'
   Next
   Return StringTrimRight($i_Data, 1)
EndFunc  ;==>_ComboInsertNum3

Func _clearChildForm()
  ; clear name fields
   GUICtrlSetData($ADivCombo1,"")
   GUICtrlSetData($ASiteCombo1, "")
   GUICtrlSetData($APadCombo1, "")
   GUICtrlSetData($AClassCombo1, "")
   GUICtrlSetData($AModelCombo1, "")
   GUICtrlSetData($AClosetCombo1, "")
   GUICtrlSetData($ASeriesCombo1, "")
   
EndFunc  ;==>_clearChildForm
Link to comment
Share on other sites

I modified the main msg loop to have these tests:

Case $msg = $Button1
         MsgBox (0, "1", "button 1")
         GUICtrlSetData($Input1, _GuiChild())
     Case $msg = $Button2
         MsgBox (0, "2", "button 2")

When I did that, I noticed that $button2 was always caught, but $button1 was only caught before the child gui was created. So, I looked through the child gui code, and sure enough, you create a new $button1 inside the child gui. That's your issue.

Link to comment
Share on other sites

From what I can see, you are attempting to create the child gui every time you click button1

Case $msg = $Button1

GUICtrlSetData($Input1, _GuiChild())

Case Else

I would assign a return variable to the function:

$GUIreturn = GUICtrlSetData($Input1, _GuiChild())

and test for $GUIreturn before calling the function. If it exists, show or activate the child window, if not create it.

Link to comment
Share on other sites

  • 2 months later...

this is what i did and it works (was quite surprised myself!)

Case $msg = $About
                GUICtrlDelete($about)
            _ChildGui()
                $About = GUICtrlCreateButton("About", 320, 370, 180, 35)

just deleted the button and upon return to parent recreated it.

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