happy2help Posted February 22, 2010 Posted February 22, 2010 Hi All I am hoping someone can help me get started with a GUI. All me scripts up to now have not needed a GUI (or i have found a work around) Can someone get me started on a GUI that reads a list of au3 files in B:\scripts\To Use\ and reads the folders under B:\scripts and lists them somehow so i can click on a au3 listed and a folder listed, click go and it will copy the file from "to use" to the other folder. I then have a script which runs on each of my machines that monitors it's own folder under B:\scripts and runs any au3 files it finds there. I am not asking for someone to write it for me, just maybe so examples on how you would do it, so i can learn how to make scripts with GUIs built in too. A few months ago, i looked at Koda and got totally confused where to start. Any help would be grateful as I'm stuck using this massive part of autoit. The script i use to run any found au3s is this expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_icon=..\Icons\DocumentRepository.ico #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #RequireAdmin #include "B:\Scripts\File.au3" Opt("WinWaitDelay", 850) ;250 milliseconds Opt("TrayIconDebug", 1) ;0=no info, 1=debug line info ;Opt("SendKeyDelay", 50) ;50 milliseconds If @compiled = 0 Then HotKeySet("{ESC}", "Exit1") Func Exit1() Exit EndFunc MsgBox(0, "WAIT", "FolderMonitor now running", 10) While 1 $filename = "FolderMonitor.ini" $file = FileOpen($filename, 0) $progy = "Empty" ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.", 20) Sleep(300000) ContinueLoop EndIf ; Read in lines of text until the EOF is reached While 1 $line = "B:\Scripts\" & @ComputerName & "\" & FileReadLine($file) If @error = -1 Then ExitLoop If FileExists ($line) Then RunWait(@AutoItExe & " /AutoIt3ExecuteScript " & $line) If $line = "B:\Scripts\" & @ComputerName & "\RestartServer.au3" Then $progy = $line EndIf Sleep (5000) FileDelete($line) EndIf Wend If $progy = "B:\Scripts\" & @ComputerName & "\RestartServer.au3" Then Shutdown(6) FileClose($file) Sleep(300000) WEnd
Moderators Melba23 Posted February 22, 2010 Moderators Posted February 22, 2010 (edited) happy2help,How I would do what you are looking to do:Create a GUI with 2 lists side by side. Use FileListToArray twice, once to get all the files, and then again to get all the folders. Populate the lists with the files on the left and the folders to the right. When you have selected the file and folder, have a button which reads the selections and then runs code to transfer the file to the folder.What you want to do is not difficult - honestly! Give it a go and come back if you have problems.If you have never created a GUI before then I strongly suggest reading BrettF's excellent tutorial here - Section 9 deals with GUIs and will give you a good basis to work with. There is even a bit about Koda in there! M23Edit: If you look here you will get an idea of what I mean. Edited February 22, 2010 by Melba23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
happy2help Posted February 28, 2010 Author Posted February 28, 2010 i have got this far expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <ListBoxConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Include <File.au3> #Include <Array.au3> $FileList=_FileListToArray("B:\Scripts\To Use\", "*", 1) If @Error=1 Then MsgBox (0,"","No Files\Folders Found.") Exit EndIf _ArrayDisplay($FileList,"$FileList") $FolderList=_FileListToArray("B:\Scripts\", "*", 2) If @Error=1 Then MsgBox (0,"","No Files\Folders Found.") Exit EndIf _ArrayDisplay($FolderList,"$FolderList") #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Script Copier", 625, 443, 193, 125) $List1 = GUICtrlCreateList("Scripts", 72, 48, 177, 318) $List2 = GUICtrlCreateList("Machines", 256, 48, 169, 318) $Button1 = GUICtrlCreateButton("Copy Now", 456, 48, 73, 49, 0) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 MsgBox(0,"Done", "Done") EndSwitch WEnd but dont know how to put $FileList into $List1 ( or do i replace $List1 with $FileList) also, how do i tell what the user has clicked on (the 2 arrays) when they click on "Copy now"? thanks for your help, i just can't get my head around it at the moment.
Moderators Melba23 Posted March 1, 2010 Moderators Posted March 1, 2010 happy2help, You need to start reading that Help file more closely! but dont know how to put $FileList into $List1You add data to a control with GUICtrlSetData. From the Help file page for that command: data - Combo, List, ListView, ListViewItem: An Opt("GUIDataSeparatorChar",...) separated list of items. Now the default GUIDataSeparatorChar is "|", so we need to get the array that is returned from _FileListToArray into a single string with "|" separators - something like this: $sFileList = "" For $i = 1 To $aFileList[0] $sFileList &= $aFileList[$i] & "|" Next ; And then add it to the list like this GUICtrlSetData($List1, $sFileList) Obviously you do somehting similar thing for the other list. how do i tell what the user has clicked onHere you use GUICtrlRead and you find the values in the two lists like this: $Value1 = GUICtrlRead($List1) $Value2 = GUICtrlRead($List2) Now you have these 2 values, you can fill the parameters of the FileCopy command to be actioned whan you press the button. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
happy2help Posted March 1, 2010 Author Posted March 1, 2010 (edited) Thanks I took what you said and produced this expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <ListBoxConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Include <File.au3> #Include <Array.au3> $Form1 = GUICreate("Script Copier", 625, 443, 193, 125) $List1 = GUICtrlCreateList("", 72, 48, 177, 318) $List2 = GUICtrlCreateList("", 256, 48, 169, 318) $Button1 = GUICtrlCreateButton("Copy Now", 456, 48, 73, 49, 0) $FileList=_FileListToArray("B:\Scripts\To Use\", "*", 1) If @Error=1 Then MsgBox (0,"","No Files\Folders Found.") Exit EndIf $sFileList = "" For $i = 1 To $FileList[0] $sFileList &= $FileList[$i] & "|" Next GUICtrlSetData($List1, $sFileList) $FolderList=_FileListToArray("B:\Scripts\", "*", 2) If @Error=1 Then MsgBox (0,"","No Files\Folders Found.") Exit EndIf $sFolderList = "" For $i = 1 To $FolderList[0] $sFolderList &= $FolderList[$i] & "|" Next GUICtrlSetData($List2, $sFolderList) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $Value1 = GUICtrlRead($List1) $Value2 = GUICtrlRead($List2) If FileExists("B:\Scripts\" & $Value2 & "\" & $Value1) Then MsgBox(0, "ERROR", "B:\Scripts\" & $Value2 & "\" & $Value1 & " already exists") FileCopy("B:\Scripts\To Use\" & $Value1, "B:\Scripts\" & $Value2 & "\") If FileExists("B:\Scripts\" & $Value2 & "\" & $Value1) Then MsgBox(0, "B:\Scripts\To Use\" & $Value1, "B:\Scripts\" & $Value2 & "\" & $Value1 & " Exists") EndSwitch WEnd Is this right or is there a better way? edit.. Also how do you remove a phrase from an array when you don't know where it is going to be? I want to remove "To Use" from the array $FolderList. I could rename the folder to "_To Use" and then remove it by using _Arraydelete ($FolderList, 1) Edited March 2, 2010 by happy2help
Moderators Melba23 Posted March 2, 2010 Moderators Posted March 2, 2010 happy2help,I would remove the folder from the list like this: $sFolderList = "" For $i = 1 To $aFolderList[0] If $aFolderList[$i] <> "To Use" Then $sFolderList &= $aFolderList[$i] & @CRLF EndIf NextA couple of other points:1. I recommend you differentiate your variables a bit more clearly. Look at my example script above - arrays begin $a, strings begin $s, integers begin $i, etc. As AutoIt does not type its variables, this helps you remember just what is where - and makes the above code snippet easier to understand. 2. Do the listing of the files/folders BEFORE you create the GUI - then you do not risk pausing the GUI creation while doing all the array manipulation. Playing with arrays is usually timecnsuming and, particularly if you have a very large array to adjust, you could end up with an embarrassing delay while your half-formed GUI is waiting for the other code to finish.M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
happy2help Posted March 3, 2010 Author Posted March 3, 2010 Hi, thanks for your help. This is what i have come up with expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <ListBoxConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <File.au3> #include <Array.au3> #Region ;reading directors and putting it in a list $sFileList = "" $sFileList2 = "" $sFolderList = "" $aFileList = _FileListToArray("B:\Scripts\To Use\", "*", 1) If @error = 1 Then MsgBox(0, "", "No Files\Folders Found.") Exit EndIf For $i = 1 To $aFileList[0] $sFileList &= $aFileList[$i] & "|" Next $aFolderList = _FileListToArray("B:\Scripts\", "*", 2) If @error = 1 Then MsgBox(0, "", "No Files\Folders Found.") Exit EndIf For $i = 1 To $aFolderList[0] If $aFolderList[$i] <> "To Use" Then $sFolderList &= $aFolderList[$i] & "|" EndIf Next #EndRegion #Region ; create GUI $Form1 = GUICreate("Script Copier", 360, 300, 193, 125) $List1 = GUICtrlCreateList("", 20, 20, 120, 270) $List2 = GUICtrlCreateList("", 150, 20, 120, 270) $Button1 = GUICtrlCreateButton("Copy Now", 280, 20, 73, 49, 0) $Button2 = GUICtrlCreateButton("Update ini File", 280, 100, 73, 49, 0) GUICtrlSetData($List1, $sFileList) GUICtrlSetData($List2, $sFolderList) GUISetState(@SW_SHOW) #EndRegion While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 CopyPressed() Case $Button2 UpDate() EndSwitch WEnd Func CopyPressed() MsgBox(0, "Button Pressed", "About to copy the file you have selected", 3) $Value1 = GUICtrlRead($List1) $Value2 = GUICtrlRead($List2) If FileExists("B:\Scripts\" & $Value2 & "\" & $Value1) Then MsgBox(0, "ERROR", "B:\Scripts\" & $Value2 & "\" & $Value1 & " already exists") FileCopy("B:\Scripts\To Use\" & $Value1, "B:\Scripts\" & $Value2 & "\") If FileExists("B:\Scripts\" & $Value2 & "\" & $Value1) Then $answer = MsgBox(0, "B:\Scripts\To Use\" & $Value1, "B:\Scripts\" & $Value2 & "\" & $Value1 & " Exists", 30) If $answer = -1 Then Exit EndIf EndFunc ;==>CopyPressed Func UpDate() $file = FileOpen("FolderMonitor.ini", 2) If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf For $i = 1 To $aFileList[0] $sFileList2 &= $aFileList[$i] & @CRLF Next FileWrite($file, $sFileList2) FileClose($file) MsgBox(0, "Done", "FolderMonitor.ini now Up To Date.") EndFunc ;==>UpDate Any suggestions or improvements will be gratefully received
Moderators Melba23 Posted March 3, 2010 Moderators Posted March 3, 2010 happy2help,Count how many times you have used "B:\Scripts\To Use\" & "B:\Scripts\" in the code. Why not set 2 variables at the start of the script and then use those variables in place of the literal strings?That sort of thing makes code much more "portable" and also helps prevent stupid typing errors (which i make far too frequently! )M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now