Getting a visual tree (trying to) :):)

Just starting out? Need help? Post your questions and find answers here.
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4792
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Getting a visual tree (trying to) :):)

Post by Fangbeast »

Could anyone possibly have a looka t the following code and tell me where I have gone wrong please? I am trying to build a visual tree, just like the tree in a file manager:)

Code: Select all

;
#TV_FIRST                               = $1100
#TVM_SETBKCOLOR                         = #TV_FIRST + 29
#TVM_SETTEXTCOLOR                       = #TV_FIRST + 30

#WindowIndex                            = 0
#GadgetIndex                            = 0
#ImageIndex                             = 0
#StatusBarIndex                         = 0
#MenuBarIndex                           = 0

#Window_Form1                           = #WindowIndex    : #WindowIndex    = #WindowIndex    + 1

#MenuBar_Form1                          = #MenuBarIndex   : #MenuBarIndex   = #MenuBarIndex   + 1
#MenuBar_Form1_exit                     = #GadgetIndex    : #GadgetIndex    = #GadgetIndex    + 1
#MenuBar_Form1_run                      = #GadgetIndex    : #GadgetIndex    = #GadgetIndex    + 1

#Gadget_Form1_icat                      = #GadgetIndex    : #GadgetIndex    = #GadgetIndex    + 1
#Gadget_Form1_dirtree                   = #GadgetIndex    : #GadgetIndex    = #GadgetIndex    + 1
#Gadget_Form1_filebox                   = #GadgetIndex    : #GadgetIndex    = #GadgetIndex    + 1

#StatusBar_Form1                        = #StatusBarIndex : #StatusBarIndex = #StatusBarIndex + 1
#StatusBar_Form1_Field1                 = 0
#StatusBar_Form1_Field2                 = 1
#StatusBar_Form1_Field3                 = 2
;
NewList dir.s()
;
Procedure.l Window_Form1()
  If OpenWindow(#Window_Form1,213,47,640,580,#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget|#PB_Window_ScreenCentered|#PB_Window_Invisible,"Work Form1")
    CreateMenu(#MenuBar_Form1,WindowID(#Window_Form1))
      MenuTitle("Files")
      MenuBar()
      MenuItem(#MenuBar_Form1_exit,"Exit")
      MenuTitle("Jobs")
      MenuBar()
      MenuItem(#MenuBar_Form1_run,"Run Job")
    If CreateGadgetList(WindowID())
      Frame3DGadget(#Gadget_Form1_icat,0,0,640,540,"")
      TreeGadget(#Gadget_Form1_dirtree,4,10,140,525)
        SendMessage_(GadgetID(#Gadget_Form1_dirtree),#TVM_SETBKCOLOR,0,8421631)
      ListIconGadget(#Gadget_Form1_filebox,145,10,490,525,"ListIcon4",484,#PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection)
        SendMessage_(GadgetID(#Gadget_Form1_filebox),#LVM_SETBKCOLOR,0,8421631)
        SendMessage_(GadgetID(#Gadget_Form1_filebox),#LVM_SETTEXTBKCOLOR,0,8421631)
      CreateStatusBar(#StatusBar_Form1,WindowID(#Window_Form1))
        AddStatusBarField(420)
        AddStatusBarField(110)
        AddStatusBarField(110)
      HideWindow(#Window_Form1,0)
      ProcedureReturn WindowID()
    EndIf
  EndIf
EndProcedure
;
If Window_Form1()

  Repeat
    EventID = WaitWindowEvent()
      Select EventID
        Case #PB_EventMenu
          Select EventMenuID()
            Case #MenuBar_Form1_run : GoSub GetTree
            Case #MenuBar_Form1_exit
          EndSelect
      EndSelect

   Until EventID = #PB_Event_CloseWindow And EventWindowID() = #Window_Form1
EndIf

End
;
GetTree:
  ClearList(dir.s())
  AddElement(dir())
  dir() = "C:"
  idx = 0
  Repeat
    SelectElement(dir(), idx)
    If ExamineDirectory(0, dir(), "*.*")
      path.s = dir() + "\"
      quit = 0
      Repeat
        nextfile = NextDirectoryEntry()
        filename.s = DirectoryEntryName()
        Select nextfile
          Case 0  : quit = 1                                                              ; Nothing found
          Case 1  : count + 1                                                             ; Filename found
          Case 2                                                                          ; Directory name found
            filename.s = DirectoryEntryName()
            If filename.s <> ".." And filename.s <> "."
              AddElement(dir())
              dir() = path + filename.s
              levelpos = 1
              node.s = dir()
              ResetList(dir())
              While StringField(node.s, levelpos, "\") <> ""
                While NextElement(dir())
                  If node.s <> dir()
                    OpenTreeGadgetNode(#Gadget_Form1_dirtree)
                    AddGadgetItem(#Gadget_Form1_dirtree, -1, node.s)
                  Else
                    AddGadgetItem(#Gadget_Form1_dirtree, -1, node.s)
                  EndIf
                Wend
                levelpos + 1
              Wend
              For closenodes = 1 To levelpos
                CloseTreeGadgetNode(#Gadget_Form1_dirtree)
              Next closenodes
              LastElement(dir())
            EndIf
        EndSelect  
      Until quit = 1
    EndIf
    idx + 1
  Until idx > CountList(dir()) - 1
Return
;

Last edited by Fangbeast on Fri May 02, 2003 12:43 pm, edited 1 time in total.
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
Denis
Enthusiast
Enthusiast
Posts: 779
Joined: Fri Apr 25, 2003 5:10 pm
Location: Doubs - France

Post by Denis »

Hi Fangbeast,

I take a look at your code.
It run for the treegadget and listicon Gadget windows but when did you fill them ?

You never call your GetTree procedure (GetTree is a label in your code, but you don't have a Gosub to call it).


Denis
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4792
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

GetTree

Post by Fangbeast »

Hi Denis, I was cutting and pasting to the forum and missed a few things. I actually run the GetTree procedure from the Jobs/Run Jobs menu section.

It gets to that gosub and then exits the whole program and I can't see anywhere except the END statement after the main program where it should do this. Weird.
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
Denis
Enthusiast
Enthusiast
Posts: 779
Joined: Fri Apr 25, 2003 5:10 pm
Location: Doubs - France

Post by Denis »

Send your new code, may somebody will find the problem.


Have a nice Day.



Denis
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4792
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

:)

Post by Fangbeast »

You too, thanks:)
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
freak
PureBasic Team
PureBasic Team
Posts: 5948
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

Hi,

I allready coded something like the one you try to do. Currently i am
recoding it, so it may become a real Gadget for v3.7.

I'd like to give you the code I wrote first (in PB), but unfortunately i don't
have any access to my webspace atm. If you want to have it, drop me
a mail at freak@abwesend.de , and i'll send it to you.

Timo
quidquid Latine dictum sit altum videtur
freak
PureBasic Team
PureBasic Team
Posts: 5948
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

Ok, I finally got a connection to my ftp account, and uploaded the File. 8)

http://freak.coolfreepages.com/stuff/Di ... Gadget.zip
(copy&paste that to a new window)

It's fully API coded, so it won't make problems with any PB Numbers or
IDs.

This one works quite well, but as i've been working with this for some
time now, the real Gadget in 3.7 will ve much more flexibla, and with
more functionality. (unfortionately, it is not finished yet :) )

Timo
quidquid Latine dictum sit altum videtur
Post Reply