Sign in to follow this  
Followers 0
ToDoWaldi

Dynamic TreeView from File

3 posts in this topic

Hello!

I made this GUI:

(look in the attachments)

It reads the lines from a txt and creates TreeItems and Sub Items(depends on the dots in the beginning of each line[example: locations.txt]).

But how can I find out now, which Tree Item was clicked on so that i can call a specific function?

Teleportlist.au3

locations.txt

Share this post


Link to post
Share on other sites



Hello!

I made this GUI:

(look in the attachments)

It reads the lines from a txt and creates TreeItems and Sub Items(depends on the dots in the beginning of each line[example: locations.txt]).

But how can I find out now, which Tree Item was clicked on so that i can call a specific function?

This might do some of what you want

#include <GUIConstants.au3>
#include <File.au3>
#include <Array.au3>
#include <guiTreeView.au3>;<----------added this
Global $lastitem = 0;<--------------------and this

Func _ArraySize( $aArray )
    SetError( 0 )
    
    $index = 0
    
    Do
        $pop = _ArrayPop( $aArray )
        $index = $index + 1
    Until @error = 1
    
    Return $index - 1
EndFunc

Func getLoc()
    ControlClick("WoWEmuHacker", "", "Button24")
    $m = ControlGetText("WoWEmuHacker", "", "Edit12")
    $x = ControlGetText("WoWEmuHacker", "", "Edit9")
    $y = ControlGetText("WoWEmuHacker", "", "Edit10")
    $z = ControlGetText("WoWEmuHacker", "", "Edit11")
    GUICtrlSetData($mInput, $m)
    GUICtrlSetData($xInput, $x)
    GUICtrlSetData($yInput, $y)
    GUICtrlSetData($zInput, $z)
EndFunc

Func createLocFile()
    If FileOpen ("locations.txt", 1) == -1 Then
        _FileCreate("locations.txt")
        createLocFile()
    EndIf
EndFunc

Func countBeginningDots($string)
    $var = $string
    $j = 0
    While StringLeft($var, 1) == "."
        $j = $j + 1
        $var = StringTrimLeft ($var, 1)
    WEnd
    return $j
EndFunc

Func deleteBeginningDots($string)
    $var = $string
    $j = 0
    While StringLeft($var, 1) == "."
        $j = $j + 1
        $var = StringTrimLeft ($var, 1)
    WEnd
    return $var
EndFunc

    Dim $treeItems[1000]
Func buildTree()

    Dim $dots[50]
    $treeItems[0] = "New root category"
    $i = 1  
    While 1
        $treeItems[$i] = FileReadLine("locations.txt", $i)
        If @error = -1 Then ExitLoop
        $i = $i + 1
    Wend
    $treeItems[0] = GUICtrlCreateTreeViewItem($treeItems[0], $treeview)
    
    $dots[0] = 0
    $j = 1
    While $treeItems[$j] <> ""
        $numOfDots = countBeginningDots($treeItems[$j])
        $lastSurCatIndexIndex = $numOfDots-1
        $lastSurCatIndex = $dots[$lastSurCatIndexIndex]
        $treeItems[$j] = GUICtrlCreateTreeViewItem(deleteBeginningDots($treeItems[$j]), $treeItems[$lastSurCatIndex])
        $lastItem = $j;<------------------------added this line
        $dots[$numOfDots] = $j
        $j = $j + 1
    WEnd
    GUICtrlSetState($treeItems[0], $GUI_EXPAND)
    GUISetState()
EndFunc

GUICreate("Teleportlist", 265, 410)
$treeview = GUICtrlCreateTreeView(0, 5, 175, 300, BitOr($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
$getLocButton = GUICtrlCreateButton ("Get Loc", 190, 5, 70, 20)
$mInput = GUICtrlCreateInput ("", 190, 30, 70, 20)
$xInput = GUICtrlCreateInput ("", 190, 55, 70, 20)
$yInput = GUICtrlCreateInput ("", 190, 80, 70, 20)
$zInput = GUICtrlCreateInput ("", 190, 105, 70, 20)
$nInput = GUICtrlCreateInput ("Enter Name", 190, 130, 70, 20)
$mLabel = GUICtrlCreateLabel ("M", 180, 34, 10, 20)
$xLabel = GUICtrlCreateLabel ("X", 180, 59, 10, 20)
$yLabel = GUICtrlCreateLabel ("Y", 180, 84, 10, 20)
$zLabel = GUICtrlCreateLabel ("Z", 180, 109, 10, 20)
$addLocButton = GUICtrlCreateButton ("Add Loc", 190, 155, 70, 20)
$catInput = GUICtrlCreateInput ("Catname", 190, 185, 70, 20)
$addCatButton = GUICtrlCreateButton ("Add Cat", 190, 210, 70, 20)

createLocFile()
buildTree()

GUISetState (@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    Switch $msg
        case $GUI_EVENT_CLOSE 
            ExitLoop
        case $getLocButton
            getLoc()
        case $addLocButton
        ;addLoc()
        case $addCatButton
            addCat()
        case $treeItems[0] to $treeItems[$lastItem];<--------------added this case
            for $in = 0 to $lastitem
                if $msg = $treeItems[$in] Then
                    ConsoleWrite('hit "' &  _GUICtrlTreeView_GetText($treeview, $treeItems[$in]) & '"' & @LF)
                    ExitLoop
                EndIf
            Next
            
        EndSwitch
Wend

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

ey yo gaZZu man! it works

thank you!

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