Jump to content
Sign in to follow this  
blitzkrg

treeview/array problems

Recommended Posts

I'm working on a an autoit program for my mp3 player.

one of the things i want it to do, it to get a list of songs and albums that are on the player and display it in a treeview format.

I have that part working (sorta)

Lets say i have 2 artist and 3 album's

Korn -> follow the leader - > songs

Metallica -> And Justice for all - > songs

Metallica -> black album - > songs

the problem is how it's displayed.

when i click on Korn, i get the album and then the songs

when click on metallica, i get the album and then the songs. which is right,

but on the 3rd album, since metallica is already in the list once, i want it to put the 2nd album under the entry that already exist.

but instead it creates a whole new entry.

see the screenshot.

Here is the function, any help getting it to do what i want would be apprechiated.

thanks

Func getlist()

    $glist1 = _FileListToArray($sdevice)
    If (Not IsArray($glist1)) and (@Error=1) Then
        MsgBox (0,"","No Files\Folders Found.")
    EndIf

    For $x = 1 to $glist1[0] Step 1
    $glist3 = _FileListToArray($sdevice & "\" & $glist1[$x])
    For $y = 1 to $glist3[0] Step 1
    $glist5 = _FileListToArray($sdevice & "\" & $glist1[$x] & "\" & $glist3[$y])
    $glisttv1 = GUICtrlCreateTreeViewitem($glist1[$x],$Treeview2)
    $glisttv2 = GUICtrlCreateTreeViewitem($glist3[$y],$glisttv1)
    For $z = 1 to $glist5[0] Step 1
    $glisttv3 = GUICtrlCreateTreeViewitem($glist5[$z],$glisttv2)

;   $glist7 = _ArrayDisplay($glist1,"Artists")
;   $glist8 = _ArrayDisplay($glist3,"Album")
;   $glist9 = _ArrayDisplay($glist5,"Songs")

    next
    next
    next
Endfunc

Share this post


Link to post
Share on other sites

I'm working on a an autoit program for my mp3 player.

one of the things i want it to do, it to get a list of songs and albums that are on the player and display it in a treeview format.

I have that part working (sorta)

Lets say i have 2 artist and 3 album's

Korn -> follow the leader - > songs

Metallica -> And Justice for all - > songs

Metallica -> black album - > songs

the problem is how it's displayed.

when i click on Korn, i get the album and then the songs

when click on metallica, i get the album and then the songs. which is right,

but on the 3rd album, since metallica is already in the list once, i want it to put the 2nd album under the entry that already exist.

but instead it creates a whole new entry.

see the screenshot.

Here is the function, any help getting it to do what i want would be apprechiated.

thanks

Func getlist()

    $glist1 = _FileListToArray($sdevice)
    If (Not IsArray($glist1)) and (@Error=1) Then
        MsgBox (0,"","No Files\Folders Found.")
    EndIf

    For $x = 1 to $glist1[0] Step 1
    $glist3 = _FileListToArray($sdevice & "\" & $glist1[$x])
    For $y = 1 to $glist3[0] Step 1
    $glist5 = _FileListToArray($sdevice & "\" & $glist1[$x] & "\" & $glist3[$y])
    $glisttv1 = GUICtrlCreateTreeViewitem($glist1[$x],$Treeview2)
    $glisttv2 = GUICtrlCreateTreeViewitem($glist3[$y],$glisttv1)
    For $z = 1 to $glist5[0] Step 1
    $glisttv3 = GUICtrlCreateTreeViewitem($glist5[$z],$glisttv2)

;   $glist7 = _ArrayDisplay($glist1,"Artists")
;   $glist8 = _ArrayDisplay($glist3,"Album")
;   $glist9 = _ArrayDisplay($glist5,"Songs")

    next
    next
    next
Endfunc
i sent this to OP via PM reply, but just incase the code would help anyone else, this is the solution that i came up with. I was working from a text file list(attached) so my solution is based on that, and i suggested that he write some code to create the list file automatically in his script, and then he'll have a working solution without having to do any other integration.

#include<file.au3>
#include<array.au3>
Dim $list
_FileReadToArray("c:\songs.txt",$list)
Global $n = $list[0]
$list = shellsort($list)

#include <GuiConstants.au3>
#include <GuiTreeView.au3>
#include <File.au3>
#Include <Array.au3>

dim $Treeview1,$Treeview2
$main1 = GuiCreate("Playlist Genorator v1.0", 392, 383,(@DesktopWidth-392)/2, (@DesktopHeight-383)/2 , -1, 0x00000018)
$sdevice = "c:\unit1"

; input box
$Input1 = GuiCtrlCreateInput("", 10, 20, 300, 20)
$Input2 = GUICtrlSetState($Input1,$GUI_ACCEPTFILES)

; Buttons
$Button1 = GuiCtrlCreateButton("Add", 320, 20, 60, 20)
$Button2 = GuiCtrlCreateButton("Upload", 10, 260, 60, 20)
$Button3 = GuiCtrlCreateButton("Delete", 70, 260, 60, 20)


; Labels
$Label1 = GuiCtrlCreateLabel("Used Space:", 20, 310, 70, 20)
$Label2 = GuiCtrlCreateLabel("Total Space:", 20, 330, 70, 20)
$Label3 = GuiCtrlCreateLabel("Free Space:", 20, 350, 70, 20)
$Label4 = GuiCtrlCreateLabel("", 90, 310, 70, 20)
$Label5 = GuiCtrlCreateLabel("", 90, 330, 70, 20)
$Label6 = GuiCtrlCreateLabel("", 90, 350, 70, 20)

; treeview
$Treeview1 = GuiCtrlCreateTreeview(10, 50, 370, 200,$TVS_HASBUTTONS + $TVS_HASLINES + $TVS_LINESATROOT + $TVS_DISABLEDRAGDROP + $TVS_SHOWSELALWAYS)
$Treeview2 = GUICtrlCreateTreeViewitem("Music", $Treeview1)
$Treeview3 = GUICtrlSetColor($Treeview2, 0x0000C0)
$Treeview4 = GuiCtrlSetState($Treeview2, $GUI_DEFBUTTON)

For $x = 0 to $n-1
$line1 = StringSplit($list[$x],"\")
If $line1[0] = 3  Then $artist = GUICtrlCreateTreeViewItem($line1[3],$Treeview1)
If $line1[0] = 4 Then $album = GUICtrlCreateTreeViewItem($line1[4],$artist)
If $line1[0] = 5 Then $song = GUICtrlCreateTreeViewItem($line1[5],$album)
Next

    
    

GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case $msg = $Input1
    $bob = GUICtrlRead($Input1)
    GUICtrlCreateTreeViewitem($bob, $Treeview2)
    GUICtrlSetdata($Input1,"")
; MsgBox (4096, "drag drop file", GUICtrlRead($Input_1))
        
            Case $Msg = $Button3
            _GUICtrlTreeViewDeleteItem ($main1, $Treeview1)
Case $msg = $Button2
msgbox(0,"debug",_GUICtrlTreeViewItemGetTree ($main1, $Treeview1, "\"))
    EndSelect
WEnd
Exit

Func shellsort($array)
    Dim $inner,$outer,$temp; declare variables
    _ArrayDelete($array,0)
$h = 1
While $h <= $n/3
    $h = $h * 3 + 1
WEnd

While $h >0
    For $outer = $h To $n-1
        $temp = StringStripWS($array[$outer],1)
        $inner = $outer
        While $inner > ($h - 1) And StringStripWS($array[$inner-$h],1) >= $temp
            $array[$inner] = $array[$inner-$h]
            $inner = $inner - $h
        WEnd
        $array[$inner] = $temp
    Next
$h = ($h - 1)/3
WEnd
Return($array)
EndFunc

Share this post


Link to post
Share on other sites

After working with my code a bit this morning, i was able to get it to work the way i wanted to by re-ordering some of my commands.

thanks to cameronsdad for looking into it!

Func getlist()

    $glist1 = _FileListToArray($sdevice)
    If (Not IsArray($glist1)) and (@Error=1) Then
        MsgBox (0,"","No Files\Folders Found.")
    EndIf

    For $x = 1 to $glist1[0] Step 1
        $glisttv1 = GUICtrlCreateTreeViewitem($glist1[$x],$Treeview2)
        $glist3 = _FileListToArray($sdevice & "\" & $glist1[$x])
    
    For $y = 1 to $glist3[0] Step 1
        $glist5 = _FileListToArray($sdevice & "\" & $glist1[$x] & "\" & $glist3[$y],"*.mp3",0)
        $glisttv2 = GUICtrlCreateTreeViewitem($glist3[$y],$glisttv1)
    
    For $z = 1 to $glist5[0] Step 1
        $glisttv3 = GUICtrlCreateTreeViewitem($glist5[$z],$glisttv2)

    next
    next
    next
Endfunc
Edited by blitzkrg

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...