Jump to content

I want to take my script to the next level - by creating some gUI


amfony
 Share

Recommended Posts

hi everyone,

I am a fair, but competent noob to autoit scripting, but i definatley am a massive noob to GUI and graphic interfacing.

I have a simple script that will tell me whos up and whos down via ping (on my internal LAN) here is the code:

#include <File.au3>
#include <Date.au3>

While 1

$list = FileOpen("d:\Node.txt", 0)
$FileCount = _FileCountLines("c:\Node.txt")

    for $i = 1 to $FileCount
        
        $node = FileReadLine($list)
        $error = @error
    ;MsgBox(4096, "", $node & "   " & $i)

        if $error = -1 Then
            MsgBox(4096, "End of Nodes.txt", "No more computer names in the file.")
            ExitLoop
        EndIf

        ping($node)

        if @error <> 0 Then
            ;beep(1900,100)
            ;MsgBox(4096,"","Computer: " & $node & " is not up.",10)
                fileOpen("D:\downnode.dat", 1)
                fileWrite("D:\downnode.dat", "Computer: " & $node & @CRLF)
        EndIf
            
    Next

$list = 0
$FileCount = 0

sleep(60000)

WEnd

This is a very rough cut as u can see. However what i would like to do is to (in a perfect world) have a graphical representation of each node from my list of computers, and have each graphic blue for up and then when it goes down turn red. For thoes who are aware of programs like whats up gold and IPMonitor - this is what im trying to achieve with AutoItScript.

I dont really have any idea where to start with the GUI aspect? can any one help with some direction?

Ofcourse if i have left any info out please let me know and i will divulge everything i know!

Thanks everyone.

Link to comment
Share on other sites

If something is wrong with your help files get some new ones or use the online help.

You want to dive into GUICreate, GuiSetState, GuictrlCreateListView and the GuiListView.au3 UDF.

You would probably benefit from using http://www.autoitscript.com/fileman/users/lookfar/formdesign.html (FD.EXE) If you have the Scite4Autoit installation koda is part of the package and found under the Tools menu.

EDIT: typo.

Edited by Uten
Link to comment
Share on other sites

There is no such thing as silly questions as long as you ask your selfe first, then the help file and lastly try to do a search. If the question still needs to be asked try to back it up with the findings you did encounter from your research.

Wish you the best in the GUI World. I know it can be a real pain to go from basic to nice, so don't be afraid to ask those "What is wrong with this code sample", "I want it to do such, and such but it won't even as I have tried this and that".

Happy coding :whistle:

Link to comment
Share on other sites

Hey again,

Im back!

I took the advice given and used koda. I have a working code now and it does what i want it to do, i am pleased with myself.

However now im trying to get fancy and colour the lists accrodingly, have a look:

#include <File.au3>
#include <Date.au3>
#include <GUIConstants.au3>

$Form1 = GUICreate("Online/Offline", 300, 385, 201, 115)

While 1

    $List1 = 0
    $List2 = 0

    $List1 = GUICtrlCreateList("", 24, 40, 97, 318)
    GUICtrlSetFont(-1, 8, 9, 0, "Lucida Console")
    GUICtrlSetColor(-1, 0xFF0000)
    
    $List2 = GUICtrlCreateList("", 160, 40, 97, 314)
    GUICtrlSetColor(-1, 0xFF0000)
    GUICtrlSetFont(-1, 8, 9, 0, "Lucida Console")
    
    GUICtrlCreateLabel("Online:", 24, 16, 53, 15)
    GUICtrlSetFont(-1, 8, 400, 0, "Lucida Console")
    GUICtrlSetColor(-1, 0x000080)
    
    GUICtrlCreateLabel("Offline:", 160, 16, 60, 15)
    GUICtrlSetFont(-1, 8, 400, 0, "Lucida Console")
    GUICtrlSetColor(-1, 0xFF0000)

    

    $list = FileOpen("e:\Node.txt", 0)
    $FileCount = _FileCountLines("e:\Node.txt")

        for $i = 1 to $FileCount
            
            $node = FileReadLine($list)
            $error = @error
    ;MsgBox(4096, "", $node & "   " & $i)

            if $error = -1 Then
                MsgBox(4096, "End of Nodes.txt", "No more computer names in the file.")
                ExitLoop
            EndIf

            ping($node,50)

            if @error <> 0 Then
            ;beep(1900,100)
            ;MsgBox(4096,"","Computer: " & $node & " is not up.",10)
                    GUICtrlSetData($List2, $node & "|")
                    fileOpen("e:\downnode.dat", 1)
                    fileWrite("e:\downnode.dat", "Computer: " & $node & @CRLF)
                Else
                    GUICtrlSetData($List1, $node & "|")
            EndIf
                            
        Next

    $list = 0
    $FileCount = 0


    GUISetState(@SW_SHOW)

    sleep(10000)

WEnd

My problem i cant seem to get around is wen im trying to colour my lists. I can font-ify my lists, i can colour my labels, but i cant colour my list!

I used Koda to do exsactly what i wanted with static entries (via tstrings prperty) coloured the lists appropriatley, and in Koda the lists are colured but when i run the cod it generates for me the colours dissapear, yet the fonts remain.

Can anyone confirm? Here is the code generated by Koda to prove my lack of colour-ness:

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("AForm1", 633, 447, 193, 115)
$List1 = GUICtrlCreateList("", 80, 56, 81, 226)
GUICtrlSetData(-1, "t|tes|tes|test|tset")
GUICtrlSetFont(-1, 8, 400, 0, "Lucida Console")
GUICtrlSetColor(-1, 0x000080)
$List2 = GUICtrlCreateList("", 192, 56, 89, 226)
GUICtrlSetData(-1, "se|se|set|set|t|t|test|tse")
GUICtrlSetFont(-1, 8, 400, 0, "Lucida Console")
GUICtrlSetColor(-1, 0xFF0000)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

Thanks for the help Uten and everyone else.

EDIT: sorry i should mention i am using autoIt Beta

Edited by amfony
Link to comment
Share on other sites

You put your code to sleep before it can update the color.

#include <File.au3>
#include <Date.au3>
#include <GUIConstants.au3>

$Form1 = GUICreate("Online/Offline", 300, 385, 201, 115)

    $List1 = 0
    $List2 = 0

    $List1 = GUICtrlCreateList("", 24, 40, 97, 318)
    GUICtrlSetFont(-1, 8, 9, 0, "Lucida Console")
    GUICtrlSetColor(-1, 0xFF0000)
    
    $List2 = GUICtrlCreateList("", 160, 40, 97, 314)
    GUICtrlSetColor(-1, 0xFF0000)
    GUICtrlSetFont(-1, 8, 9, 0, "Lucida Console")
    
    GUICtrlCreateLabel("Online:", 24, 16, 53, 15)
    GUICtrlSetFont(-1, 8, 400, 0, "Lucida Console")
    GUICtrlSetColor(-1, 0x000080)
    
    GUICtrlCreateLabel("Offline:", 160, 16, 60, 15)
    GUICtrlSetFont(-1, 8, 400, 0, "Lucida Console")
    GUICtrlSetColor(-1, 0xFF0000)
    GUISetState(@SW_SHOW)
    ; sleep(10000) ;A no, no, HELL NO! Use TimeDiff in your loop and sleep max 250ms to not loos events..:)
GUICtrlSetData($List1,  "test1|test2|")
GUICtrlSetData($List2,  "test1|test2|")

Update() ;Run once to populate the lists
Addlibenable("Update", 10000) ;Update every 10s

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE ;Always lett the user be able to close the app. I hda to use taskmanager
            Exit

    EndSwitch
WEnd

Func Update()
    $list = FileOpen("e:\Node.txt", 0)
    $FileCount = _FileCountLines("e:\Node.txt")

        for $i = 1 to $FileCount
            
            $node = FileReadLine($list)
            $error = @error
    ;MsgBox(4096, "", $node & "   " & $i)

            if $error = -1 Then
                MsgBox(4096, "End of Nodes.txt", "No more computer names in the file.")
                ExitLoop
            EndIf

            ping($node,50)

            if @error <> 0 Then
            ;beep(1900,100)
            ;MsgBox(4096,"","Computer: " & $node & " is not up.",10)
                    GUICtrlSetData($List2, $node & "|")
                    fileOpen("e:\downnode.dat", 1)
                    fileWrite("e:\downnode.dat", "Computer: " & $node & @CRLF)
                Else
                    GUICtrlSetData($List1, $node & "|")
            EndIf
                            
        Next

    $list = 0
    $FileCount = 0
    ;TODO: It is good practice  to use fileclose after you have done a fileopen. As of now you would consume all your file handels pretty quick.
EndFunc
Link to comment
Share on other sites

thank alot for the input uten, unfortunatley my lists are both still black, they are fontified, yet still black.

I looked at your code and learned quite abit, like the 'do not sleep' ad adLibEnable, also the exit button (that was just me being lazy). I did make some changes as your code was appending to the list every cycle, not refreshing. All it took was a "GUICtrlSetData($List,"" ".

I fear it may be something to do with my versions of autoIt perhaps?

Did it work on your computer Uten , the coloured list i mean?

Thasnks again mate!

Link to comment
Share on other sites

Yes it did and stil does, gave me red text in both list boxes (as coded). I was running 3.2.1.11

Yes, my sample added some items to it. I dont have your monitor files.:whistle:

NOTE: If yo dont want to install the beta you should download the zip version and run the scite you find in there. It does not have all the wistel and bells but works without an installation and can be deleted again.

Take a look at this sample:

#include <File.au3>
#include <Date.au3>
#include <GUIConstants.au3>
#include <GUIList.au3>
$Form1 = GUICreate("Online/Offline", 300, 385, 201, 115)

    $List1 = 0
    $List2 = 0

    $List1 = GUICtrlCreateList("", 24, 40, 97, 318)
    GUICtrlSetFont(-1, 8, 9, 0, "Lucida Console")
    GUICtrlSetColor(-1, 0x000080) ;0xFF0000)
    
    $List2 = GUICtrlCreateList("", 160, 40, 97, 314)
    GUICtrlSetColor(-1, 0xFF0000)
    GUICtrlSetFont(-1, 8, 9, 0, "Lucida Console")
    
    GUICtrlCreateLabel("Online:", 24, 16, 53, 15)
    GUICtrlSetFont(-1, 8, 400, 0, "Lucida Console")
    GUICtrlSetColor(-1, 0x000080)
    
    GUICtrlCreateLabel("Offline:", 160, 16, 60, 15)
    GUICtrlSetFont(-1, 8, 400, 0, "Lucida Console")
    GUICtrlSetColor(-1, 0xFF0000)
    GUISetState(@SW_SHOW)
    ; sleep(10000) ;A no, no, HELL NO! Use TimeDiff in your loop and sleep max 250ms to not loos events..:)

AdlibEnable("Update", 1000)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case 0
            Sleep(250)
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func Update()
   ;Take a look at the udf functions to add remove and position data.
   _GUICtrlListAddItem($List1,  @min & ":" & @SEC) 
   _GUICtrlListAddItem($List2,   @min & ":" & @SEC)
return 
EndFunc
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...