Jump to content

From ini file to GUI


Recommended Posts

Hi.

I want to create GUI that is similar to excel ... I was searching in help file and here in forum, but nothing found.

Here is my ini file

[KOORDINATE]
x1=11
y1=59
x2=10
y2=60
x3=9
y3=60
x4=8
y4=59
x5=8
y5=57
x6=13
y6=62
x7=9
y7=62
x8=8
y8=62
x9=7
y9=61
x10=7
y10=58
x11=8
y11=56
x12=12
y12=56
x13=11
y13=63
x14=9
y14=64
x15=6
y15=62
x16=18
y16=61
x17=14
y17=57
x18=15
y18=56
x19=14
y19=55
x20=9
y20=54
x21=8
y21=54
x22=7
y22=55
x23=8
y23=55
x24=5
y24=56
x25=6
y25=57
x26=6
y26=60
x27=5
y27=58

This are coordinates, and I need GUI, that will have 2 columns .. for x and y ... and the numbers ( x(number) y(number)) are rows. So in this case we have 27 rows. And when I click on some coordinate, it must be able to edit it, or delete it and save changes to .ini file.

Thx for answers ..

Edited by DoctorSLO
Link to comment
Share on other sites

Hi.

I want to create GUI that is similar to excel ... I was searching in help file and here in forum, but nothing found.

Here is my ini file

[KOORDINATE]
x1=11
y1=59
x2=10
y2=60
x3=9
y3=60
x4=8
y4=59
x5=8
y5=57
x6=13
y6=62
x7=9
y7=62
x8=8
y8=62
x9=7
y9=61
x10=7
y10=58
x11=8
y11=56
x12=12
y12=56
x13=11
y13=63
x14=9
y14=64
x15=6
y15=62
x16=18
y16=61
x17=14
y17=57
x18=15
y18=56
x19=14
y19=55
x20=9
y20=54
x21=8
y21=54
x22=7
y22=55
x23=8
y23=55
x24=5
y24=56
x25=6
y25=57
x26=6
y26=60
x27=5
y27=58

This are coordinates, and I need GUI, that will have 2 columns .. for x and y ... and the numbers ( x(number) y(number)) are rows. So in this case we have 27 rows. And when I click on some coordinate, it must be able to edit it, or delete it and save changes to .ini file.

Thx for answers ..

Hi,

have a look in helpfile for IniReadSection and start coding.

You may use Koda to create your own gui and have a look in helpfile, how to fill gui elements with data you get with IniReadSection (2-D array) by a for loop.

So 1 st step is to fill your Gui with data. Next step is to code edit, delete and save changes....

Any further problems, post your code and you will have more support.

;-))

Stefan

Edited by 99ojo
Link to comment
Share on other sites

  • Moderators

DoctorSLO,

To help you get started, here is a little script that saves the cell contents to an ini file. It is based on Achilles' Grid UDF which you can find here.

My additional code is merely the part within the ########. Press F1 to create the ini.

#include-once

#include <GUIConstantsEx.au3>

; #INDEX# ====================================================================================================

===================
; Title .........: Grid (First release)
; AutoIt Version : Any (I think)
; Language ......: English
; Description ...: Use a grid of labels for games involving keyboard or mouse
; Notes .........: Some coordinates may seem backwards, this is due to the Cartesian coordinate system (what you use in math)
;                  This could easily be converted to use pictures (just modify the _Grid_Create function)
; ====================================================================================================

===========================

; #CURRENT# ====================================================================================================

=================
;_Grid_Create
;_Grid_Destroy
;_Grid_GetColor
;_Grid_GetCoords
;_Grid_IsValidCtrlID
;_Grid_SetAreaColor
;_Grid_SetColor
; ====================================================================================================

===========================

Global $xGrid[1][1]; an array containing all the control ID's for each item
Global $colorGrid[1][1]; an array containing all the colors for each item
Global $xR; number of rows
Global $xC; number of columns
Global $xBkColor; background color

; #######################################################################################

$hGUI = GUICreate("Test", 500, 500)

$iFirst = _Grid_Create(10, 2, 40, 0xFFFF, 0, 0, $hGUI)

$hSave = GUICtrlCreateDummy()
ConsoleWrite("Dummy = " & $hSave & @CRLF)
Global $aAccels[1][2] = [["{F1}", $hSave]]
GUISetAccelerators ($aAccels)

GUISetState()

For $i = 1 To 2
    For $j = 1 To 10
        GUICtrlSetData($iFirst + ($i - 1) * 10 + ($j -1), ($i - 1) * 10 + $j)
    Next
Next

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hSave
            ConsoleWrite("Saving" & @CRLF)
            Saver()
    EndSwitch

WEnd

Func Saver()

    $sIni_Path = @ScriptDir & "\Cells.ini"

    For $i = 1 To 2
        For $j = 1 To 10
            $sData = GUICtrlRead($iFirst + ($i - 1) * 10 + ($j -1))
            IniWrite($sIni_Path, "Cells", Chr(64 + $i) & $j, $sData)
        Next
    Next

EndFunc

; ######################################################################################

; #FUNCTION# ====================================================================================================

================
; Name...........: _Grid_Create
; Description ...: Creates a grid of labels
; Syntax.........: _Grid_Create($r, $c, $size, $bkColor, $x, $y, $gui)
; Parameters ....: $r       - Number of rows
;                 $c        - Number of columns
;                  $size    - Size of each label
;                  $bkColor - Color to set each label
;                  $x       - X position to start adding labels on the GUI
;                  $y       - Y positioon to start adding labels on the GUI
;                  $gui     - The handle the GUI that the labels are being added onto
; Return values .: Success  - Returns 1
;                  Failure  - Returns -1
; Author ........: Michael McFarland (Ichigo)
; Related .......: _Grid_Destory
; ====================================================================================================

===========================
Func _Grid_Create($r, $c, $size, $bkColor, $x, $y, $gui)
    If $r < 0 or $c < 0 or $size < 0 then Return -1

    ReDim $xGrid[$r][$c]
    ReDim $colorGrid[$r][$c]
    $xR = $r
    $xC = $c
    $xBkColor = $bkColor

    GUISwitch($gui)
    For $r = 0 to $xR - 1
        For $c = 0 to $xC - 1
            $xGrid[$r][$c] = GUICtrlCreateLabel('', $x + $c * $size, $y + $r * $size, $size, $size)
                GUICtrlSetBkColor(-1, $bkColor)
            $colorGrid[$r][$c] = $bkColor
        Next
    Next

    Return $xGrid[0][0]
EndFunc

; #FUNCTION# ====================================================================================================

================
; Name...........: _Grid_Destroy
; Description ...: Deletes the grid of labels
; Syntax.........: _Grid_Destroy()
; Parameters ....: None
; Return values .: Returns 1
; Author ........: Michael McFarland (Ichigo)
; Related .......: _Grid_Create
; ====================================================================================================

===========================
Func _Grid_Destroy()
    For $r = 0 to $xR - 1
        For $c = 0 to $xC - 1
            GUICtrlDelete($xGrid[$r][$c])
        Next
    Next
    Return 1
EndFunc

; #FUNCTION# ====================================================================================================

================
; Name...........: _Grid_GetColor
; Description ...: Gets the color of a label in the grid
; Syntax.........: _Grid_GetColor($c, $r)
; Parameters ....: $c       - Column index
;                 $r        - Row index
; Return values .: Success - Color of the specific item
;                  Failure - Return -1
; Author ........: Michael McFarland (Ichigo)
; Related .......: _Grid_SetColor
; ====================================================================================================

===========================
Func _Grid_GetColor($c, $r)
    If $c < 0 or $c >= $xC or $r < 0 or $r >= $xR then Return -1
    Return $colorGrid[$r][$c]
EndFunc

; #FUNCTION# ====================================================================================================

================
; Name...........: _Grid_GetCoords
; Description ...: Gets the coordinates the label that has the given control ID
; Syntax.........: _Grid_GetCoords($controlID)
; Parameters ....: $controlID - Control ID to verify
; Return values .: Success - Returns a two-element array that containing the mouse coordinates: $array[0] = col, $array[1] = row
;                  Failure - Returns -1
; Author ........: Michael McFarland (Ichigo)
; Related .......: _Grid_SetColor
; ====================================================================================================

===========================
Func _Grid_GetCoords($controlID)
    Dim $pos[2]

    If Not _Grid_IsValidCtrlID($controlID) then Return -1

    For $r = 0 to $xR - 1
        For $c = 0 to $xC - 1
            If $xGrid[$r][$c] = $controlID then
                $pos[0] = $c
                $pos[1] = $r
                Return $pos
            EndIf
        Next
    Next

    Return -1
EndFunc

; #FUNCTION# ====================================================================================================

================
; Name...........: _Grid_IsValidCtrlID
; Description ...: Determines if a control ID belongs to one of the labels in the grid
; Syntax.........: _Grid_IsValidCtrlID($controlID)
; Parameters ....: $controlID - Control ID to verify
; Return values .: Success - Returns True
;                  Failure - Returns False
; Author ........: Michael McFarland (Ichigo)
; Remarks .......: Do NOT call this if your are using _Grid_GetCoords, _Grid_GetCoords calls this function itself
; Related .......: _Grid_GetCoords
; ====================================================================================================

===========================
Func _Grid_IsValidCtrlID($controlID)
    Return $controlID >= $xGrid[0][0] and $controlId <= $xGrid[$xR - 1][$xC - 1]
EndFunc

; #FUNCTION# ====================================================================================================

================
; Name...........: _Grid_SetAreaColor
; Description ...: Sets the color of the entire GUI or a specific item
; Syntax.........: _Grid_SetAreaColor($bkColor, $rStart, $cStart, $rEnd, $cEnd)
; Parameters ....: $bkColor - Color to set
;                  $cStart  - Column index to start at
;                 $rStart  - Row index to start at
;                  $cEnd    - Column index to end at
;                 $rEnd - Row index to end at
; Return values .: Returns 1 (any parameters that cause it to fail wil cause it to set the entire background to the color)
; Author ........: Michael McFarland (Ichigo)
; Remarks .......: This function has no error checking, if there is an error your entire grid will be set to the $bkColor
; Related .......: _Grid_SetColor
; ====================================================================================================

===========================
Func _Grid_SetAreaColor($bkColor, $cStart, $rStart, $cEnd, $rEnd)
    For $r = $rStart to $rEnd
        For $c = $cStart to $cEnd
            _Grid_SetColor($bkColor, $c, $r)
        Next
    Next
EndFunc

; #FUNCTION# ====================================================================================================

================
; Name...........: _Grid_SetColor
; Description ...: Sets the color of the entire GUI or a specific item
; Syntax.........: _Grid_SetColor($bkColor, $c = -1, $r = -1)
; Parameters ....: $bkColor - Color to set
;                  $c       - [Optional] Column index
;                 $r        - [Optional] Row index
; Return values .: Returns 1 (any parameters that cause it to fail wil cause it to set the entire background to the color)
; Author ........: Michael McFarland (Ichigo)
; Remarks ......:  If the two optional parameters are not passed than the entire grid gets set to the specified color
; Related .......: _Grid_GetColor
; ====================================================================================================

===========================
Func _Grid_SetColor($bkColor, $c = -1, $r = -1)
    If $r < 0 or $c < 0 or $r >= $xR or $c >= $xC then
        $xBkColor = $bkColor
        For $r = 0 to $xR - 1
            For $c = 0 to $xC - 1
                If $colorGrid[$r][$c] <> $xBkColor then
                    GUICtrlSetBkColor($xGrid[$r][$c], $xBkColor)
                    $colorGrid[$r][$c] = $xBkColor
                EndIf
            Next
        Next
    Else
        GUICtrlSetBkColor($xGrid[$r][$c], $bkColor)
        $colorGrid[$r][$c] = $bkColor
    EndIf

    Return 1
EndFunc

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Yes, thx everyone ... I made it with Listview, and I changed ini file ... so now looks like this:

farme2.ini

[X]
x1=11
x2=10
x3=9
x4=8
x5=8
x6=13
x7=9
x8=8
x9=7
x10=7
[Y]
y1=59
y2=60
y3=60
y4=59
y5=57
y6=62
y7=62
y8=62
y9=61
y10=58

And my code:

#Include <GuiListView.au3>

$mygui = GUICreate("lol", 600, 600)

$cordX = IniReadSection("farme2.ini", "X")
$cordY = IniReadSection("farme2.ini", "Y")

$mainlist = GUICtrlCreateListView("No.|X|Y", 10, 10, 200, 300)
For $i = 1 To 10
    _GUICtrlListView_AddItem($mainlist, $i)
    _GUICtrlListView_AddSubItem($mainlist, $i - 1, $cordX[$i][1], 1)
    _GUICtrlListView_AddSubItem($mainlist, $i - 1, $cordY[$i][1], 2)
Next
GUISetState()

Sleep(55555)

This is what I was searching for ... now I only need to add buttons for edit and add ...

Now If I make edit button, and I select one row and press edit, then it must appear mybe inputbox for X and then for Y .... but how to get information which row is selected ? :/

Edited by DoctorSLO
Link to comment
Share on other sites

Ok, here is my code so far ... now with add button and delete

#Include <GuiListView.au3>

$mygui = GUICreate("lol", 600, 600)

$cordX = IniReadSection("farme2.ini", "X")
$cordY = IniReadSection("farme2.ini", "Y")

$mainlist = GUICtrlCreateListView("No.|X|Y", 10, 10, 200, 300)
$add = GUICtrlCreateButton("Add", 250, 60, 70, 30)
$delete = GUICtrlCreateButton("Delete", 250, 100, 70, 30)
GUICtrlCreateLabel("X:", 220, 40, 21, 17)
GUICtrlCreateLabel("Y:", 277, 40, 31, 17)
$dodajx = GUICtrlCreateInput("", 232, 37, 40, 21)
$dodajy = GUICtrlCreateInput("", 289, 37, 40, 21)
check()
MsgBox(0, "lol", $last)
For $i = 1 To $last
    _GUICtrlListView_AddItem($mainlist, $i)
    _GUICtrlListView_AddSubItem($mainlist, $i - 1, $cordX[$i][1], 1)
    _GUICtrlListView_AddSubItem($mainlist, $i - 1, $cordY[$i][1], 2)
Next
GUISetState()

While 1
    $msg = GUIGetMsg()
    Select
    Case $msg = $add
        $x = GUICtrlRead($dodajx)
        $y = GUICtrlRead($dodajy)
        $last = $last + 1
        IniWrite("farme2.ini", "X", "x"&$last, $x)
        IniWrite("farme2.ini", "Y", "y"&$last, $y)
        _GUICtrlListView_AddItem($mainlist, $last)
        _GUICtrlListView_AddSubItem($mainlist, $last-1, $x, 1)
        _GUICtrlListView_AddSubItem($mainlist, $last-1, $y, 2)
    Case $msg = $delete
        _GUICtrlListView_DeleteItemsSelected($mainlist) ; doesn't works :/
    EndSelect
WEnd
    


Func check()
    For $b = 1 To 1000
        $a = IniRead("farme2.ini", "X", "x"&$b, "nc")
        If $a = "nc" Then
            Global $last = $b - 1
            ExitLoop
        EndIf
    Next
EndFunc

But I still can't get delete button working :/

... any advices ? :D

EDIT: I puted MsgBox(0, "Deleted?", _GUICtrlListView_DeleteItem($mainlist, 1))

and it says True ... but nothing happened in gui :D

Edited by DoctorSLO
Link to comment
Share on other sites

...

_GUICtrlListView_DeleteItemsSelected($mainlist) ; doesn't works :/

...

For that UDF you have to get handle.

best regards, Reinhard

#include <GUIConstantsEx.au3>
#Include <GuiListView.au3>

DIM $last



$mygui = GUICreate("lol", 600, 600)

$cordX = IniReadSection("farme2.ini", "X")
$cordY = IniReadSection("farme2.ini", "Y")

$mainlist = GUICtrlCreateListView("No.|X|Y", 10, 10, 200, 300)
$add = GUICtrlCreateButton("Add", 250, 60, 70, 30)
$delete = GUICtrlCreateButton("Delete", 250, 100, 70, 30)
GUICtrlCreateLabel("X:", 220, 40, 21, 17)
GUICtrlCreateLabel("Y:", 277, 40, 31, 17)
$dodajx = GUICtrlCreateInput("", 232, 37, 40, 21)
$dodajy = GUICtrlCreateInput("", 289, 37, 40, 21)

check()

MsgBox(0, "lol", $last)
For $i = 1 To $last
    _GUICtrlListView_AddItem($mainlist, $i)
    _GUICtrlListView_AddSubItem($mainlist, $i - 1, $cordX[$i][1], 1)
    _GUICtrlListView_AddSubItem($mainlist, $i - 1, $cordY[$i][1], 2)
Next
GUISetState()


While 1
    $msg = GUIGetMsg()
    Switch $msg
    Case $GUI_EVENT_CLOSE
        ExitLoop
    Case $add
        $x = GUICtrlRead($dodajx)
        $y = GUICtrlRead($dodajy)
        $last = $last + 1
        IniWrite("farme2.ini", "X", "x"&$last, $x)
        IniWrite("farme2.ini", "Y", "y"&$last, $y)
        _GUICtrlListView_AddItem($mainlist, $last)
        _GUICtrlListView_AddSubItem($mainlist, $last-1, $x, 1)
        _GUICtrlListView_AddSubItem($mainlist, $last-1, $y, 2)
    Case $delete
        if _GUICtrlListView_GetSelectedCount($mainlist) = 0 then 
            msgBox(0,"","Nothing selected")
        Else
             _GUICtrlListView_DeleteItemsSelected (GUICtrlGetHandle($mainlist))
        EndIf
    EndSwitch
WEnd

Func check()
    For $b = 1 To 1000
        $a = IniRead("farme2.ini", "X", "x"&$b, "nc")
        If $a = "nc" Then
            Global $last = $b - 1
            ExitLoop
        EndIf
    Next
EndFunc
Link to comment
Share on other sites

Thanks all for help

Here is now fully working code ... :D

#Include <GuiListView.au3>
#Include <File.au3>

$mygui = GUICreate("lol", 600, 600)

$cordX = IniReadSection("farme2.ini", "X")
$cordY = IniReadSection("farme2.ini", "Y")

$mainlist = GUICtrlCreateListView("No.|X|Y", 10, 10, 200, 300)
$add = GUICtrlCreateButton("Add", 250, 60, 70, 30)
$delete = GUICtrlCreateButton("Delete", 250, 100, 70, 30)
GUICtrlCreateLabel("X:", 220, 40, 21, 17)
GUICtrlCreateLabel("Y:", 277, 40, 31, 17)
$dodajx = GUICtrlCreateInput("", 232, 37, 40, 21)
$dodajy = GUICtrlCreateInput("", 289, 37, 40, 21)
$obstaja = FileExists("farme2.ini")
If $obstaja = 1 Then
    check()
Else
    $last = 0
EndIf
MsgBox(0, "lol", $last)
For $i = 1 To $last
    _GUICtrlListView_AddItem($mainlist, $i)
    _GUICtrlListView_AddSubItem($mainlist, $i - 1, $cordX[$i][1], 1)
    _GUICtrlListView_AddSubItem($mainlist, $i - 1, $cordY[$i][1], 2)
Next
GUISetState()

While 1
    $msg = GUIGetMsg()
    Select
    Case $msg = $add
        $x = GUICtrlRead($dodajx)
        $y = GUICtrlRead($dodajy)
        $last = $last + 1
        IniWrite("farme2.ini", "X", "x"&$last, $x)
        IniWrite("farme2.ini", "Y", "y"&$last, $y)
        _GUICtrlListView_AddItem($mainlist, $last)
        _GUICtrlListView_AddSubItem($mainlist, $last-1, $x, 1)
        _GUICtrlListView_AddSubItem($mainlist, $last-1, $y, 2)
        GUICtrlSetData($dodajx, "")
        GUICtrlSetData($dodajy, "")
    Case $msg = $delete
        If _GUICtrlListView_GetSelectedCount($mainlist) = 0 then
            MsgBox(0,"","Nothing selected")
        Else
            $handle = GUICtrlGetHandle($mainlist)
            $kerje = _GUICtrlListView_GetSelectionMark($handle) + 1
            MsgBox(0, "", $kerje)
            IniDelete("farme2.ini", "X", "x"&$kerje)
            IniDelete("farme2.ini", "Y", "y"&$kerje)
            _GUICtrlListView_DeleteItemsSelected($handle)
            $sh = -1
            Do
                $sh = $sh + 1
                _ReplaceStringInFile("farme2.ini", "x"&$kerje + 1 + $sh, "x"&$kerje + $sh)
                _ReplaceStringInFile("farme2.ini", "y"&$kerje + 1 + $sh, "y"&$kerje + $sh)
            Until $kerje + $sh = $last
            $last = $last - 1
        EndIf
    EndSelect
WEnd
    


Func check()
    $b = 0
    Do
        $b = $b + 1
        $a = IniRead("farme2.ini", "X", "x"&$b, "nc")
        If $a <> "nc" Then
            Global $last = $b
        EndIf
    Until $b = 1000
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...