Sign in to follow this  
Followers 0
chrisj90

How to "Refresh" a GUI window

6 posts in this topic

Hello all,

I'm trying to write a UI that will loop within it's limits and continue to add lines to two different arrays. This is a small part of a larger program that is used by my company to do prep work on computer images. AutoIT seems to be much better than using Sysprep and we've had incredible success doing things this way. My goal now is to create multiple IP printer objects on the system based off of user input.

Assumptions:

-User has specified 5 total printer objects.

#Region
#AutoIt3Wrapper_Run_Obfuscator=y
#Obfuscator_Parameters=/SO
#EndRegion

#include <Array.au3>
#include <GUIConstantsEx.au3>

Opt('MustDeclareVars', 1)

Global $i = 0, $printers, $printarray[1], $printok, $printip, $ipprefix, $iparray[1]

PrintGUI()

Func PrintGUI()
    Opt("GUIOnEventMode", 1)
    
    $ipprefix = "10.6.12."
    GUICreate("Printer " & $i + 1, 400, 130)
        
    GUICtrlCreateLabel("Please select a printer.", 10, 10)
    $printers = GUICtrlCreateCombo("<None>", 10, 30, 165)
    GUICtrlSetData(-1, "HP LaserJet 1020|hp LaserJet 1320 PCL 6|HP LaserJet 2430 PCL 6|HP LaserJet 4100 Series PS|HP LaserJet 4300 PCL 6|HP LaserJet P2015 Series PCL 6|HP LaserJet P3005 PCL 6|HP LaserJet 8150 Series PCL", "<None>")
        
    $printok = GUICtrlCreateButton("OK", 235, 30, 125, 65)
    GUICtrlSetOnEvent(-1, "PrintOK")
        
    GUICtrlCreateLabel("Please enter printer IP.", 10, 60)
    $printip = GUICtrlCreateInput( $ipprefix, 10, 80)
        
    GUISetState()
    While 1
        Sleep(10)
    WEnd
EndFunc

Func PrintOK()
    If $i > 5 Then
        Exit
    Else
        _ArrayAdd($printarray, GUICtrlRead($printers))
        _ArrayAdd($iparray, GUICtrlRead($printip))
        $i += 1
        PrintGUI()
    EndIf
EndFunc

It's basically working as intended except that it wont progress past "Printer 2" phase. I assume my method is a bit off, so if you know of a better way, please share.

Thanks in advance,

Chris

Share this post


Link to post
Share on other sites



Hello all,

I'm trying to write a UI that will loop within it's limits and continue to add lines to two different arrays. This is a small part of a larger program that is used by my company to do prep work on computer images. AutoIT seems to be much better than using Sysprep and we've had incredible success doing things this way. My goal now is to create multiple IP printer objects on the system based off of user input.

Assumptions:

-User has specified 5 total printer objects.

#Region
#AutoIt3Wrapper_Run_Obfuscator=y
#Obfuscator_Parameters=/SO
#EndRegion

#include <Array.au3>
#include <GUIConstantsEx.au3>

Opt('MustDeclareVars', 1)

Global $i = 0, $printers, $printarray[1], $printok, $printip, $ipprefix, $iparray[1]

PrintGUI()

Func PrintGUI()
    Opt("GUIOnEventMode", 1)
    
    $ipprefix = "10.6.12."
    GUICreate("Printer " & $i + 1, 400, 130)
        
    GUICtrlCreateLabel("Please select a printer.", 10, 10)
    $printers = GUICtrlCreateCombo("<None>", 10, 30, 165)
    GUICtrlSetData(-1, "HP LaserJet 1020|hp LaserJet 1320 PCL 6|HP LaserJet 2430 PCL 6|HP LaserJet 4100 Series PS|HP LaserJet 4300 PCL 6|HP LaserJet P2015 Series PCL 6|HP LaserJet P3005 PCL 6|HP LaserJet 8150 Series PCL", "<None>")
        
    $printok = GUICtrlCreateButton("OK", 235, 30, 125, 65)
    GUICtrlSetOnEvent(-1, "PrintOK")
        
    GUICtrlCreateLabel("Please enter printer IP.", 10, 60)
    $printip = GUICtrlCreateInput( $ipprefix, 10, 80)
        
    GUISetState()
    While 1
        Sleep(10)
    WEnd
EndFunc

Func PrintOK()
    If $i > 5 Then
        Exit
    Else
        _ArrayAdd($printarray, GUICtrlRead($printers))
        _ArrayAdd($iparray, GUICtrlRead($printip))
        $i += 1
        PrintGUI()
    EndIf
EndFunc

It's basically working as intended except that it wont progress past "Printer 2" phase. I assume my method is a bit off, so if you know of a better way, please share.

Thanks in advance,

Chris

I think you need to remove the line

PrintGUI()

from the function PrintOK


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

I think you need to remove the line

PrintGUI()

from the function PrintOK

That appears to work, only problem with that is the Window Title is not updating itself. Ideally it would change it's number to reflect which printer you are entering data for. Any idea on how to get the Window Title to update itself? That's why I was calling the main function again, seemed to be the only way I could get it to update.

Share this post


Link to post
Share on other sites

I guess what I'm ultimately trying to do is re-draw the GUI after the OK button is pressed. That way all the text labels are updated with proper numbers etc.

Share this post


Link to post
Share on other sites

I guess what I'm ultimately trying to do is re-draw the GUI after the OK button is pressed. That way all the text labels are updated with proper numbers etc.

I think you only need WinSetTitle if you only want to change the title.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

I think you only need WinSetTitle if you only want to change the title.

Yeah, issue resolved.

Func PrintGUI($numPrinters)
    Opt("GUIOnEventMode", 1)
    
    ReDim $printarray[$numPrinters]
    ReDim $iparray[$numPrinters]
    
    $ipprefix = "10.6.12."
    $printui = GUICreate("Printer", 400, 130)
        
    $printlabel = GUICtrlCreateLabel("Please select a printer for printer " & $i + 1 & ".", 10, 10)
    $printers = GUICtrlCreateCombo("<None>", 10, 30, 165)
    GUICtrlSetData(-1, "HP LaserJet 1020|hp LaserJet 1320 PCL 6|HP LaserJet 2430 PCL 6|HP LaserJet 4100 Series PS|HP LaserJet 4300 PCL 6|HP LaserJet P2015 Series PCL 6|HP LaserJet P3005 PCL 6|HP LaserJet 8150 Series PCL", "<None>")
        
    $printok = GUICtrlCreateButton("OK", 235, 30, 125, 65)
    GUICtrlSetOnEvent(-1, "PrintOK")
        
    GUICtrlCreateLabel("Please enter printer IP.", 10, 60)
    $printip = GUICtrlCreateInput( $ipprefix, 10, 80)
        
    GUISetState(@SW_SHOW, $printui)
    
    While 1
        Sleep(10)
    WEnd
EndFunc

Func PrintOK()
    $printarray[$i] = GUICtrlRead($printers)
    $iparray[$i] = GUICtrlRead($printip)

    $i += 1

    If $i >= UBound($printarray) Then
        ArrayDisplay()
        Exit
    Else
        ControlSetText("Printer", "", $printlabel, "Please select a printer for printer " & $i + 1 & ".")
    EndIf
EndFunc

I ended up finding ControlSetText(), just took a long while of searching through the help files. Thank you for your help! Oh, and I moved away from changing the title of the window too :D.

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