Jump to content

dynamic input data update..


Recommended Posts

Hi all,

im as new to AutoIt as new can be! i've got quite far with what i been trying to do but im having problems with getting the input box to auto update

when the combobox selection changes...

The other problem im having is the icon input box doesn't work like the folder input box and i have no idea why, its been done up the same as the 'folders' code, and when selecting a file from the icon browse no filepath is written.

here's my code..

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <ButtonConstants.au3>

Opt('MustDeclareVars', 1)

Global $tab, $Ftab, $msg, $PathBrowse, $IconBrowse, $varFile, $ffPathSet, $ffRead, $ifRead
Global $ffList, $ifList, $ffChoice, $ifChoice, $ffPath, $ifPath, $ffBrowse, $ifBrowse, $ffItem, $ifItem ;~<Folders/>

$varFile = "Variables.inc"
$ffPathSet = IniRead($varFile, "Variables", "Fpath." & GUICtrlRead($ffList), "Default")

GUICreate("coNfig", 370, 245)
GUICtrlCreateButton("Apply", 309, 180, 50, 30)
$tab = GUICtrlCreateTab(10, 10, 350, 200)

$Ftab = GUICtrlCreateTabItem("Folders")
;~<Folders
GUICtrlCreateLabel("Folder:", 20, 50) ;==>
$ffList = GUICtrlCreateCombo("1", 60, 48, 35)
$ffChoice = GUICtrlSetData(-1, "2|3|4|5|6|7|8|9|10|11|12")
$ffPath = GUICtrlCreateInput("Path . . . browse - - >", 105, 48, 200)
    GUICtrlSetData($ffPath, IniRead($varFile, "Variables", "Fpath." & GUICtrlRead($ffList), "Default"))
$ffBrowse = GUICtrlCreateButton("...", 315, 47, 30, 22)

GUICtrlCreateLabel("Icon:", 28, 100)
$ifList = GUICtrlCreateCombo("1", 60, 98, 35)
$ifChoice = GUICtrlSetData(-1, "2|3|4|5|6|7|8|9|10|11|12")
$ifPath = GUICtrlCreateInput("Icon . . . browse - - >", 105, 98, 200)
    GUICtrlSetData($ifPath, IniRead($varFile, "Variables", "Ficon." & GUICtrlRead($ffList), "Default"))
$ifBrowse = GUICtrlCreateButton("...", 315, 97, 30, 22)
;~Folders/>

GUISetState()

While 1
    $msg = GUIGetMsg()
    $ffRead = GUICtrlRead($ffList)
    $ifRead = GUICtrlRead($ifList)
    Select
        Case $msg = $ffBrowse
            $PathBrowse = FileOpenDialog("Folder " & $ffRead & " path...", @ScriptDir, "All Types(*.*)")
            IniWrite($varFile, "Variables", "Fpath." & $ffRead, $PathBrowse)
        Case $msg = $ifBrowse
            $IconBrowse = FileOpenDialog("Icon " & $ifRead & " path...", @ScriptDir, "PNG(*.PNG)")
            IniWrite($varFile, "Variables", "Ficon." & $ifRead, $IconBrowse)
        EndSelect
    If $msg = $GUI_EVENT_CLOSE Then Exit
WEnd

excuse the code being all over the place

(any advice is appreciated, as im guessing i might need to use some Func's for the rest of this - the planned end result is 4/5 tabs with similar setups as this code)

if there is a easy solution i wouldn't mind someone directing to where it is in the manual have only been doing AutoIt for a week or so:p

thanks

Edited by katoNkatoNK
Link to comment
Share on other sites

Try this:

#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <ButtonConstants.au3>

Opt('MustDeclareVars', 1)

Global $tab, $Ftab, $msg, $PathBrowse, $IconBrowse, $varFile, $ffPathSet, $ffRead, $ifRead, $apply
Global $ffList, $ifList, $ffChoice, $ifChoice, $ffPath, $ifPath, $ffBrowse, $ifBrowse, $ffItem, $ifItem ;~<Folders/>
Global $aPath, $aIcon, $aDataPath[13], $aDataIcon[13], $value
$varFile = "Variables.inc"
$aPath = IniReadSection($varFile, "Variables Path")
$aIcon = IniReadSection($varFile, "Variables Icon")

If IsArray($aPath) Then
    For $i = 1 To UBound($aPath) - 1
        $aDataPath[$aPath[$i][0]] = $aPath[$i][1]
    Next
EndIf
If IsArray($aIcon) Then
    For $i = 1 To UBound($aIcon) - 1
        $aDataIcon[$aIcon[$i][0]] = $aIcon[$i][1]
    Next
EndIf

GUICreate("coNfig", 370, 245)
$apply = GUICtrlCreateButton("Apply", 309, 180, 50, 30)
$tab = GUICtrlCreateTab(10, 10, 350, 200)

$Ftab = GUICtrlCreateTabItem("Folders")
;~<Folders
GUICtrlCreateLabel("Folder:", 20, 50) ;==>
$ffList = GUICtrlCreateCombo("1", 60, 48, 35)
$ffChoice = GUICtrlSetData(-1, "2|3|4|5|6|7|8|9|10|11|12")
$ffPath = GUICtrlCreateInput("Path . . . browse - - >", 105, 48, 200)
$value = $aDataPath[GUICtrlRead($ffList)]
If $value = "" Then $value = "Default"
GUICtrlSetData($ffPath, $value)
$ffBrowse = GUICtrlCreateButton("...", 315, 47, 30, 22)

GUICtrlCreateLabel("Icon:", 28, 100)
$ifList = GUICtrlCreateCombo("1", 60, 98, 35)
$ifChoice = GUICtrlSetData(-1, "2|3|4|5|6|7|8|9|10|11|12")
$ifPath = GUICtrlCreateInput("Icon . . . browse - - >", 105, 98, 200)
$value = $aDataIcon[GUICtrlRead($ifList)]
If $value = "" Then $value = "Default"
GUICtrlSetData($ifPath, $value)
$ifBrowse = GUICtrlCreateButton("...", 315, 97, 30, 22)
;~Folders/>

GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case  $GUI_EVENT_CLOSE
            CreateINI()
            Exit
        Case $ffBrowse
            $ffRead = GUICtrlRead($ffList)
            $PathBrowse = FileOpenDialog("Folder " & $ffRead & " path...", @ScriptDir, "All Types (*.*)")
            If Not @error Then
                GUICtrlSetData($ffPath, $PathBrowse)
                $aDataPath[GUICtrlRead($ffList)] =  $PathBrowse
            EndIf
        Case $ifBrowse
            $ifRead = GUICtrlRead($ifList)
            $IconBrowse = FileOpenDialog("Icon " & $ifRead & " path...", @ScriptDir, "PNG (*.PNG)")
            If Not @error Then
                GUICtrlSetData($ifPath, $IconBrowse)
                $aDataIcon[GUICtrlRead($ifList)] =  $IconBrowse
            EndIf
        Case $ffList
            $value = $aDataPath[GUICtrlRead($ffList)]
            If $value = "" Then $value = "Default"
            GUICtrlSetData($ffPath, $value)
        Case $ifList
            $value = $aDataIcon[GUICtrlRead($ifList)]
            If $value = "" Then $value = "Default"
            GUICtrlSetData($ifPath, $value)
        Case $apply
            CreateINI()
    EndSwitch
WEnd

Func CreateINI()
    Local $hFile = FileOpen($varFile, 2)
    FileWriteLine($hFile, "[Variables Path]")
    For $i = 1 To 12
        FileWriteLine($hFile, $i & "=" & $aDataPath[$i])
    Next
    FileWriteLine($hFile, "[Variables Icon]")
    For $i = 1 To 12
        FileWriteLine($hFile, $i & "=" & $aDataIcon[$i])
    Next
    FileClose($hFile)
EndFunc

It is not the best way to do it but it is a start...

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Great! thank you for the reply

haven't put it to work yet but i can see what i needed, i had feared it would involve arrays after struggling to understand its implementation ><,

and hadn't expected a solution for the "apply" button:p but will save me a bit of time.

i just want to double check the use of the "CreateINI()",

would this be the same as editing the 'variables.inc'?

Edited by katoNkatoNK
Link to comment
Share on other sites

My idea was to create the ini on exit and not on each change you made in the GUI.

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

ah ye i see, it is a better way.

its working great! apart from the icon path saving still wont work.

..while in the gui and the path is set for an icon the path gets stored and stays there with the array but it still wont write to the file..i'll give it another look in the meantime.

Link to comment
Share on other sites

For me it is working properly - all values are set to the ini file which I made in the GUI!

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

mmye strange, i see the array that you made - that gets written perfectly, just not the actual 'icon' path's.

@Edit

the value is only written once i select a 'folder' path and apply it with the apply button - do i correct this by adding another 'Func' or a could i add another While/WEnd statement?

my other question is if someone could tell me how i could get a character set into the array, as i need to have "Fpath"/"Ipath" as a prefix for each of the relevant paths (the program that i'm making this for reads variables by its name and not section).

my knowledge of how arrays can me manipulated is 0..

thanks in advance:)

Edited by katoNkatoNK
Link to comment
Share on other sites

Been trying to find a solution to what the array reads..

I can get it to write "Fpath1=x" which is straightforward

but im still struggling to get the array to read what has been writing if its anything other than a number value.

Here's an example of what i need it to end up being/read from:

;--file

[Variables]

Fpath1=path

....

Fpath12=path

Ipath1=path

....

Ipath12=path

;--file

(for the end result i'm planning on having more tabs but with different variables in the file.. e.g H1..12 and so on)

Any help is greatly appreciated,

I hope it's not too much to ask for!

Edited by katoNkatoNK
Link to comment
Share on other sites

Bump

----

I'm guessing that i would a need 2d array

with the 'variables' prefix from the .inc file in the first column then its value for e.g "1-12" in the second?

I'm struggling horribly to understand how to implement an array,so if anyone could amend UEZ's code with a good example

i'd greatly appreciate it!

Edited by katoNkatoNK
Link to comment
Share on other sites

I don't understand the sense of the prefix neither in the ini file nor in the combobox.

You can add the prefix according to the number of the array everytime you want! Why to save it to the ini file?

Will be the ini file used by some other programs?

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

i meant 'prefix' in the context of the array number,the combobox read/setdata setup is good as it is :)

the way you have done it so far is perfect and thank you, just the number needs to now start with a Fpath/Ficon instead of just number.

(i used the word prefix because this is the first part of my config, so i just wanted to create the general idea of what was needed,sorry for the confusion - the rest of the config will have tabs: Apps, Drives, System & maybe more)

->i'm not expecting anyone to create something for the other tabs for the time being

and yes, im making this for Rainmeter (it reads variables by Key, not the section)

so the file being written to also needs to stay in the script directory, i don't know if it's done the same with you but if i add a file by browsing, CreatINI() writes the variables.inc to that folder which the file is in and not the script directory.

Thanks again for looking into this for me.

Edited by katoNkatoNK
Link to comment
Share on other sites

Next try:

#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <ButtonConstants.au3>

Opt('MustDeclareVars', 1)

Global $tab, $Ftab, $msg, $PathBrowse, $IconBrowse, $varFile, $ffPathSet, $ffRead, $ifRead, $apply
Global $ffList, $ifList, $ffChoice, $ifChoice, $ffPath, $ifPath, $ffBrowse, $ifBrowse, $ffItem, $ifItem ;~<Folders/>
Global $aPath, $aIcon, $aDataPath[13], $aDataIcon[13], $value
$varFile = "Variables.inc"
$aPath = IniReadSection($varFile, "Variables Path")
$aIcon = IniReadSection($varFile, "Variables Icon")

If IsArray($aPath) Then
    For $i = 1 To UBound($aPath) - 1
        $aDataPath[StringRegExpReplace($aPath[$i][0], "(?i)fpath", "")] = $aPath[$i][1] ;StringRegExpReplace removes the prefix
    Next
EndIf

If IsArray($aIcon) Then
    For $i = 1 To UBound($aIcon) - 1
        $aDataIcon[StringRegExpReplace($aIcon[$i][0], "(?i)ipath", "")] = $aIcon[$i][1] ;StringRegExpReplace removes the prefix
    Next
EndIf

GUICreate("coNfig", 370, 245)
$apply = GUICtrlCreateButton("Apply", 309, 180, 50, 30)
$tab = GUICtrlCreateTab(10, 10, 350, 200)

$Ftab = GUICtrlCreateTabItem("Folders")
;~<Folders
GUICtrlCreateLabel("Folder:", 20, 50) ;==>
$ffList = GUICtrlCreateCombo("1", 60, 48, 35)
$ffChoice = GUICtrlSetData(-1, "2|3|4|5|6|7|8|9|10|11|12")
$ffPath = GUICtrlCreateInput("Path . . . browse - - >", 105, 48, 200)
$value = $aDataPath[GUICtrlRead($ffList)]
If $value = "" Then $value = "Default"
GUICtrlSetData($ffPath, $value)
$ffBrowse = GUICtrlCreateButton("...", 315, 47, 30, 22)

GUICtrlCreateLabel("Icon:", 28, 100)
$ifList = GUICtrlCreateCombo("1", 60, 98, 35)
$ifChoice = GUICtrlSetData(-1, "2|3|4|5|6|7|8|9|10|11|12")
$ifPath = GUICtrlCreateInput("Icon . . . browse - - >", 105, 98, 200)
$value = $aDataIcon[GUICtrlRead($ifList)]
If $value = "" Then $value = "Default"
GUICtrlSetData($ifPath, $value)
$ifBrowse = GUICtrlCreateButton("...", 315, 97, 30, 22)
;~Folders/>

GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case  $GUI_EVENT_CLOSE
            CreateINI()
            Exit
        Case $ffBrowse
            $ffRead = GUICtrlRead($ffList)
            $PathBrowse = FileOpenDialog("Folder " & $ffRead & " path...", @ScriptDir, "All Types (*.*)")
            If Not @error Then
                GUICtrlSetData($ffPath, $PathBrowse)
                $aDataPath[GUICtrlRead($ffList)] =  $PathBrowse
            EndIf
        Case $ifBrowse
            $ifRead = GUICtrlRead($ifList)
            $IconBrowse = FileOpenDialog("Icon " & $ifRead & " path...", @ScriptDir, "PNG (*.PNG)")
            If Not @error Then
                GUICtrlSetData($ifPath, $IconBrowse)
                $aDataIcon[GUICtrlRead($ifList)] =  $IconBrowse
            EndIf
        Case $ffList
            $value = $aDataPath[GUICtrlRead($ffList)]
            If $value = "" Then $value = "Default"
            GUICtrlSetData($ffPath, $value)
        Case $ifList
            $value = $aDataIcon[GUICtrlRead($ifList)]
            If $value = "" Then $value = "Default"
            GUICtrlSetData($ifPath, $value)
        Case $apply
            CreateINI()
    EndSwitch
WEnd

Func CreateINI()
    Local $hFile = FileOpen($varFile, 2)
    FileWriteLine($hFile, "[Variables Path]")
    For $i = 1 To 12
        FileWriteLine($hFile, "FPath" & $i & "=" & $aDataPath[$i])
    Next
    FileWriteLine($hFile, "[Variables Icon]")
    For $i = 1 To 12
        FileWriteLine($hFile, "IPath" & $i & "=" & $aDataIcon[$i])
    Next
    FileClose($hFile)
EndFunc

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Thanks a bunch UEZ!

With one or two tweaks it was set to go :P

I do have a question, and one more problem that i've run into :D

#include <Array.au3>
#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <ButtonConstants.au3>

Opt('MustDeclareVars', 1)
Opt('TrayMenuMode', 3)
Opt('TrayAutoPause', 0)

Global $tMsg, $tMenu, $tOpen, $tVar, $tAbout, $tRestore, $tExit, $gui, $msg, $varFile, $varRead
Global $ffList, $ifList, $ffPath, $ifPath, $ffBrowse, $ifBrowse, $ffRead, $ifRead, $PathBrowse, $IconBrowse, $aDataPath[13], $aDataIcon[13] ;Folders/>
Global $value, $apply, $prompt_yn

$varFile = @ScriptDir & '\Variables.inc'
$varRead = IniReadSection($varFile, "Variables")

$prompt_yn = 1

If IsArray($varRead) Then
    For $i = 1 To UBound($varRead) - 1
        $aDataPath[StringRegExpReplace($varRead[$i][0], "(?i)Fpath", "")] = $varRead[$i][1] ;StringRegExpReplace removes the prefix
    Next
EndIf

If IsArray($varRead) Then
    For $i = 1 To UBound($varRead) - 1
        $aDataIcon[StringRegExpReplace($varRead[$i][0], "(?i)Ficon", "")] = $varRead[$i][1] ;StringRegExpReplace removes the prefix
    Next
EndIf

$tMenu = TrayCreateMenu("Resources")
    $tOpen = TrayCreateItem("Open", $tMenu)
    $tVar = TrayCreateItem("Variables.inc", $tMenu)
TrayCreateItem("")
$tAbout = TrayCreateItem("About")
$tRestore = TrayCreateItem("Restore")
TrayCreateItem("")
TrayCreateItem("")
$tExit = TrayCreateItem("Exit")

$gui = GUICreate("coNfig", 370, 245)
$apply = GUICtrlCreateButton("Apply", 309, 180, 50, 30)
    GUICtrlCreateTab(10, 10, 350, 200)

;<Folders
    GUICtrlCreateTabItem("Folders")

    GUICtrlCreateLabel("Folder:", 20, 50) ;==>
$ffList = GUICtrlCreateCombo("1", 60, 48, 35)
    GUICtrlSetData(-1, "2|3|4|5|6|7|8|9|10|11|12")
$ffPath = GUICtrlCreateInput("Path.   .   .   .   .   .   .   .   .   .   . [ browse>", 105, 48, 200)
    $value = $aDataPath[GUICtrlRead($ffList)]
    If $value = "" Then $value = "Default"
    GUICtrlSetData($ffPath, $value)
$ffBrowse = GUICtrlCreateButton("...", 315, 47, 30, 22)

    GUICtrlCreateLabel("Icon:", 28, 100)
$ifList = GUICtrlCreateCombo("1", 60, 98, 35)
    GUICtrlSetData(-1, "2|3|4|5|6|7|8|9|10|11|12")
$ifPath = GUICtrlCreateInput("Icon.   .   .   .   .   .   .   .   .   .   . [ browse>", 105, 98, 200)
    $value = $aDataIcon[GUICtrlRead($ifList)]
    If $value = "" Then $value = "Default"
    GUICtrlSetData($ifPath, $value)
$ifBrowse = GUICtrlCreateButton("...", 315, 97, 30, 22)
;Folders/>

GUISetState()
TraySetState(2)

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            If $prompt_yn > 0 Then Prompt()
            If $prompt_yn < 1 Then Exit
        Case $GUI_EVENT_MINIMIZE
            WinSetState($gui, "", @SW_HIDE)
            TraySetState()
            Tray()
        Case $ffBrowse
            $ffRead = GUICtrlRead($ffList)
            $PathBrowse = FileOpenDialog("Folder " & $ffRead & " path...", @ScriptDir, "All Types (*.*)")
            If Not @error Then
                GUICtrlSetData($ffPath, $PathBrowse)
                $aDataPath[GUICtrlRead($ffList)] = $PathBrowse
            EndIf
        Case $ifBrowse
            $ifRead = GUICtrlRead($ifList)
            $IconBrowse = FileOpenDialog("Icon " & $ifRead & " path...", @ScriptDir, "PNG (*.PNG)")
            If Not @error Then
                GUICtrlSetData($ifPath, $IconBrowse)
                $aDataIcon[GUICtrlRead($ifList)] = $IconBrowse
            EndIf
        Case $ffList
            $value = $aDataPath[GUICtrlRead($ffList)]
            If $value = "" Then $value = "Path.   .   .   .   .   .   .   .   .   .   . [ browse>"
            GUICtrlSetData($ffPath, $value)
        Case $ifList
            $value = $aDataIcon[GUICtrlRead($ifList)]
            If $value = "" Then $value = "Icon.   .   .   .   .   .   .   .   .   .   . [ browse>"
            GUICtrlSetData($ifPath, $value)
        Case $apply
            $prompt_yn = 0
            CreateINI()
    EndSwitch
WEnd

Func CreateINI()
    For $i = 1 To 12
        IniWrite($varFile, "Variables", "Fpath" & $i, $aDataPath[$i])
    Next
    For $i = 1 To 12
        IniWrite($varFile, "Variables", "Ficon" & $i, $aDataIcon[$i])
    Next
EndFunc   ;CreateINI/>

Func Prompt()
    Local $promptbox
    $promptbox = MsgBox(4, "", "Exit without saving?")
    If $promptbox = 6 Then Exit
    If $promptbox = 7 Then Return
EndFunc   ;Prompt/>

Func Tray()
    While 1
    $tMsg = TrayGetMsg()
        Switch $tMsg
            Case $tAbout
                MsgBox(0, "About", "")
            Case $tRestore
                TraySetState(2)
                WinSetState($gui, "", @SW_RESTORE)
                GUISetState(@SW_ENABLE, $gui)
            Case $tExit
                Exit
        EndSwitch
    WEnd
EndFunc

The Tray Func does what it is supposed to up until i try click on controls in the gui after it is 'restored'(only minimize works).. I've done whole trial and error through almost all i could find to try get it working but i just cant seem to get it right. :) How do i get it to go back to the gui's 'While 1' statement?

@Edit

Edited the code to the closest set of working functions ive got to, but the same thing still happens when i click on buttons after restoring, then if i minimize the gui again it doesn't go back to the tray either.

@Edit

Ignore this post , i figured it out by removing the Func Tray()... :)

Edited by katoNkatoNK
Link to comment
Share on other sites

Sori, but i should of thought of this before..is it possible to add something to writeINI(), that will write the input's data (according to the array) to the file IF the user manually enters a path and/or adds the path by the browse button - I've already tried getting it to write the value for both the manual entry and the browse with GUICtrlRead() which hasn't work.

Edited by katoNkatoNK
Link to comment
Share on other sites

You can use the GUIRegisterMsg() function to get the values from input control:

#include <Array.au3>
#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <ButtonConstants.au3>

Opt('MustDeclareVars', 1)
Opt('TrayMenuMode', 3)
Opt('TrayAutoPause', 0)

Global $tMsg, $tMenu, $tOpen, $tVar, $tAbout, $tRestore, $tExit, $gui, $msg, $varFile, $varRead
Global $ffList, $ifList, $ffPath, $ifPath, $ffBrowse, $ifBrowse, $ffRead, $ifRead, $PathBrowse, $IconBrowse, $aDataPath[13], $aDataIcon[13] ;Folders/>
Global $value, $apply, $prompt_yn

$varFile = @ScriptDir & '\Variables.inc'
$varRead = IniReadSection($varFile, "Variables")

$prompt_yn = 1

If IsArray($varRead) Then
    For $i = 1 To UBound($varRead) - 1
        $aDataPath[StringRegExpReplace($varRead[$i][0], "(?i)Fpath", "")] = $varRead[$i][1] ;StringRegExpReplace removes the prefix
    Next
EndIf

If IsArray($varRead) Then
    For $i = 1 To UBound($varRead) - 1
        $aDataIcon[StringRegExpReplace($varRead[$i][0], "(?i)Ficon", "")] = $varRead[$i][1] ;StringRegExpReplace removes the prefix
    Next
EndIf

$tMenu = TrayCreateMenu("Resources")
    $tOpen = TrayCreateItem("Open", $tMenu)
    $tVar = TrayCreateItem("Variables.inc", $tMenu)
TrayCreateItem("")
$tAbout = TrayCreateItem("About")
$tRestore = TrayCreateItem("Restore")
TrayCreateItem("")
TrayCreateItem("")
$tExit = TrayCreateItem("Exit")

$gui = GUICreate("coNfig", 370, 245)
$apply = GUICtrlCreateButton("Apply", 309, 180, 50, 30)
    GUICtrlCreateTab(10, 10, 350, 200)

;<Folders
    GUICtrlCreateTabItem("Folders")

    GUICtrlCreateLabel("Folder:", 20, 50) ;==>
$ffList = GUICtrlCreateCombo("1", 60, 48, 35)
    GUICtrlSetData(-1, "2|3|4|5|6|7|8|9|10|11|12")
$ffPath = GUICtrlCreateInput("Path.   .   .   .   .   .   .   .   .   .   . [ browse>", 105, 48, 200)
    $value = $aDataPath[GUICtrlRead($ffList)]
    If $value = "" Then $value = "Default"
    GUICtrlSetData($ffPath, $value)
$ffBrowse = GUICtrlCreateButton("...", 315, 47, 30, 22)

    GUICtrlCreateLabel("Icon:", 28, 100)
$ifList = GUICtrlCreateCombo("1", 60, 98, 35)
    GUICtrlSetData(-1, "2|3|4|5|6|7|8|9|10|11|12")
$ifPath = GUICtrlCreateInput("Icon.   .   .   .   .   .   .   .   .   .   . [ browse>", 105, 98, 200)
    $value = $aDataIcon[GUICtrlRead($ifList)]
    If $value = "" Then $value = "Default"
    GUICtrlSetData($ifPath, $value)
$ifBrowse = GUICtrlCreateButton("...", 315, 97, 30, 22)
;Folders/>

GUISetState()
TraySetState(2)

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            If $prompt_yn > 0 Then Prompt()
            If $prompt_yn < 1 Then Exit
        Case $GUI_EVENT_MINIMIZE
            WinSetState($gui, "", @SW_HIDE)
            TraySetState()
            Tray()
        Case $ffBrowse
            $ffRead = GUICtrlRead($ffList)
            $PathBrowse = FileOpenDialog("Folder " & $ffRead & " path...", @ScriptDir, "All Types (*.*)")
            If Not @error Then
                GUICtrlSetData($ffPath, $PathBrowse)
                $aDataPath[GUICtrlRead($ffList)] = $PathBrowse
            EndIf
        Case $ifBrowse
            $ifRead = GUICtrlRead($ifList)
            $IconBrowse = FileOpenDialog("Icon " & $ifRead & " path...", @ScriptDir, "PNG (*.PNG)")
            If Not @error Then
                GUICtrlSetData($ifPath, $IconBrowse)
                $aDataIcon[GUICtrlRead($ifList)] = $IconBrowse
            EndIf
        Case $ffList
            $value = $aDataPath[GUICtrlRead($ffList)]
            If $value = "" Then $value = "Path.   .   .   .   .   .   .   .   .   .   . [ browse>"
            GUICtrlSetData($ffPath, $value)
        Case $ifList
            $value = $aDataIcon[GUICtrlRead($ifList)]
            If $value = "" Then $value = "Icon.   .   .   .   .   .   .   .   .   .   . [ browse>"
            GUICtrlSetData($ifPath, $value)
        Case $apply
            $prompt_yn = 0
            CreateINI()
    EndSwitch
WEnd

Func CreateINI()
    For $i = 1 To 12
        IniWrite($varFile, "Variables", "Fpath" & $i, $aDataPath[$i])
    Next
    For $i = 1 To 12
        IniWrite($varFile, "Variables", "Ficon" & $i, $aDataIcon[$i])
    Next
EndFunc   ;CreateINI/>

Func Prompt()
    Local $promptbox
    $promptbox = MsgBox(4, "", "Exit without saving?")
    If $promptbox = 6 Then Exit
    If $promptbox = 7 Then Return
EndFunc   ;Prompt/>

Func Tray()
    While 1
    $tMsg = TrayGetMsg()
        Switch $tMsg
            Case $tAbout
                MsgBox(0, "About", "")
            Case $tRestore
                TraySetState(2)
                WinSetState($gui, "", @SW_RESTORE)
                GUISetState(@SW_ENABLE, $gui)
            Case $tExit
                Exit
        EndSwitch
    WEnd
EndFunc

Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    Local $chk = BitAND($wParam, 0x0000FFFF)
    Switch $chk
        Case $ffPath
            If FileExists(GUICtrlRead($ffPath)) Then
                $aDataPath[GUICtrlRead($ffList)] = GUICtrlRead($ffPath)
                GUICtrlSetBkColor($ffPath, 0xFFFFFF)
            Else
                GUICtrlSetBkColor($ffPath, 0xFF0000)
            EndIf
        Case $ifPath
            If FileExists(GUICtrlRead($ifPath)) Then
                $aDataIcon[GUICtrlRead($ifList)] = GUICtrlRead($ifPath)
                GUICtrlSetBkColor($ifPath, 0xFFFFFF)
            Else
                GUICtrlSetBkColor($ifPath, 0xFF0000)
            EndIf
    EndSwitch
EndFunc

If the file doesn't exist the background color from input control will be read.

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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