I need help with treeview and jpeg's.

Just starting out? Need help? Post your questions and find answers here.
Mr Tickle
User
User
Posts: 25
Joined: Mon Oct 13, 2003 10:33 pm
Location: England, Derbyshire.

I need help with treeview and jpeg's.

Post by Mr Tickle »

I have set up a tree view and populated it with nodes etc.

I would like to be able to click a certain node and then be able to see a picture (jpeg) in the righthand box.

I've also put an image gadget but if I dont select a pic at design time I get an error when I try to compile so I pointed it to a bmp(shown in righthand pane) which stops the error. However if I point it to a jpeg then the designer disapears and im back at the desktop.

How can I successfully get jpegs to work? jpegs = 5M bmps = 50M :roll:

Thanks in advance.

Here's a pic of my simple app so far to help you understand/help me :)

Image[/img]
Mr Tickle.
Athlon xp 2500+, Gigabyte KT400-FSB333, Gf3 Ti200, SB Live 5.1
Saboteur
Enthusiast
Enthusiast
Posts: 272
Joined: Fri Apr 25, 2003 7:09 pm
Location: (Madrid) Spain
Contact:

Post by Saboteur »

I don't know how do you code your application, but is possible that forget to include UseJPEGImageDecoder() at beginning. 8O
[:: PB Registered ::]

Win10 Intel core i5-3330 8GB RAM Nvidia GTX 1050Ti
Saboteur
Enthusiast
Enthusiast
Posts: 272
Joined: Fri Apr 25, 2003 7:09 pm
Location: (Madrid) Spain
Contact:

Post by Saboteur »

Here goes a little example. You only need to code the tree view :) But it depends from how do you manage the graphics...

Code: Select all

UseJPEGImageDecoder()

If OpenWindow(0,100,100,400,400,#PB_Window_SystemMenu,"")
  If CreateGadgetList(WindowID())
    ImageGadget(0,0,40,400,400,0)
    ButtonGadget(1,0,0,100,20,"Load image 1")
    ButtonGadget(2,0,20,100,20,"Load image 2")
  EndIf
  
  Repeat
    event=WaitWindowEvent()
    gadget=EventGadgetID()
    
    If event=#PB_Event_CloseWindow
      quit=#True
    EndIf
    If event=#PB_Event_Gadget
      If gadget=1
        LoadImage(50,"d:\temp\test.jpg")
        SetGadgetState(0,UseImage(50))
      EndIf
      If gadget=2
        LoadImage(51,"d:\temp\test2.jpg")
        SetGadgetState(0,UseImage(51))
      EndIf
    EndIf
  Until quit=#True
EndIf
[:: PB Registered ::]

Win10 Intel core i5-3330 8GB RAM Nvidia GTX 1050Ti
Mr Tickle
User
User
Posts: 25
Joined: Mon Oct 13, 2003 10:33 pm
Location: England, Derbyshire.

Post by Mr Tickle »

All my app needs to do is show an image when the user clicks an item in the tree view. I have lots of images to display:( all for different branches of the tree view.

Code: Select all

 ;At the moment I've set up my tree view...
Procedure FillTree()
        AddGadgetItem (#Tree, -1, "Physical ")     
        OpenTreeGadgetNode(#Tree) 
        AddGadgetItem (#Tree, -1, "Creature ")
            OpenTreeGadgetNode(#Tree)
                AddGadgetItem(#Tree, -1, "Undead")
                    OpenTreeGadgetNode(#Tree)
                        AddGadgetItem(#Tree, -1, "Haunt")
                        AddGadgetItem(#Tree, -1, "Zombie Types")
                            OpenTreeGadgetNode(#Tree)
                                AddGadgetItem(#Tree, -1, "Zombie")
                                AddGadgetItem(#Tree, -1, "FemZombie")
                                AddGadgetItem(#Tree, -1, "FreshZombie")
                            CloseTreeGadgetNode(#Tree)
                            AddGadgetItem(#Tree, -1, "Apparition")
                            OpenTreeGadgetNode(#Tree)
                                AddGadgetItem(#Tree, -1, "LibraryApparition")
                            CloseTreeGadgetNode(#Tree)
; and so on...
EndProcedure 
So I now need to code for the user clicking a branch and then display the appropriate image (I have 1000 images) :!: This where I'm lost.

Thanks Saboteur for your time and patience ;)
Mr Tickle.
Athlon xp 2500+, Gigabyte KT400-FSB333, Gf3 Ti200, SB Live 5.1
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4789
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: I need help with treeview and jpeg's.

Post by Fangbeast »

Mr Tickle wrote:I have set up a tree view and populated it with nodes etc.

I would like to be able to click a certain node and then be able to see a picture (jpeg) in the righthand box.

I've also put an image gadget but if I dont select a pic at design time I get an error when I try to compile so I pointed it to a bmp(shown in righthand pane) which stops the error. However if I point it to a jpeg then the designer disapears and im back at the desktop.

How can I successfully get jpegs to work? jpegs = 5M bmps = 50M :roll:

Thanks in advance.

Here's a pic of my simple app so far to help you understand/help me :)

Image[/img]
Try this, I lifted it out of Freak's image viewer and it works perfectly. Just remember to have your images base names the same as your node items:)

Code: Select all


UseJPEGImageDecoder() ; At the beginning of your code to allow jpeg support to work

; In your event handler
Repeat 
  EventID = WaitWindowEvent()
    If EventID = #PB_EventGadget
      Select EventGadgetID()
        Case #My_Tree_Gadget  ; If the tree was clicked
        ; Get the current node pressed and the text at that node
          TreeName.s = GetGadgetItemText(#My_Tree_Gadget, GetGadgetState(#My_Tree_Gadget), 0) ; Name of the item from the tree
            ; Make sure all the images have the same base name as the node items
            If LoadImage(0, TreeName.s + ".jpg")
              FreeGadget(#My_Image_Gadget)
              ImageGadget(#My_Image_Gadget, 10, 10, 200, 200, ImageID())  ; Whatever your dimensions are
            EndIf
      EndSelect
    EndIf
Until Event = #PB_EventCloseWindow       
Note that I am not testing for an event type happening in the tree because I am only performing one use on it so EventType() checking isn't needed.

And when I say "Make sure all the images have the same base name as the node items" I mean that if a node item has the name of "thief", make sure there is an image called "thief.jpg" existing.
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
Mr Tickle
User
User
Posts: 25
Joined: Mon Oct 13, 2003 10:33 pm
Location: England, Derbyshire.

Post by Mr Tickle »

Thanks Fangbeast :wink:

Yes ALL images have the names of node items... A good job cos there's just over 1000 of them 8O . I'll give it a try. Thanks again.


[Edit]
It works 8) Thanks.
Now I just need it to display the tree view path in a text box.
Mr Tickle.
Athlon xp 2500+, Gigabyte KT400-FSB333, Gf3 Ti200, SB Live 5.1
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4789
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Post by Fangbeast »

Mr Tickle wrote:Thanks Fangbeast :wink:

Yes ALL images have the names of node items... A good job cos there's just over 1000 of them 8O . I'll give it a try. Thanks again.


[Edit]
It works 8) Thanks.
Now I just need it to display the tree view path in a text box.
I don't follow you, what do you mean bu "tree view path"??

Do you mean the path the file was loaded from or the name of the current node that you clicked on?
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
Mr Tickle
User
User
Posts: 25
Joined: Mon Oct 13, 2003 10:33 pm
Location: England, Derbyshire.

Post by Mr Tickle »

Sorry :oops:

I need the name of the node and all the parent nodes too if that is possible. So if you look at my pic The node path is :-

Physical>Creature>Animal>Human>Guard>swordsman

Is this possible? :wink:

Cheers, You've been a great help :)
Mr Tickle.
Athlon xp 2500+, Gigabyte KT400-FSB333, Gf3 Ti200, SB Live 5.1
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4789
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Post by Fangbeast »

Mr Tickle wrote:Sorry :oops:

I need the name of the node and all the parent nodes too if that is possible. So if you look at my pic The node path is :-

Physical>Creature>Animal>Human>Guard>swordsman

Is this possible? :wink:

Cheers, You've been a great help :)
Just caught this snippet from freak dealing with getting parent numbers.

You get the handle to the child (the item you clicked) by using the GetGadgetState(#Tree) command.

Code: Select all

hItem.l = GadgetItemID(#Tree, ChildNumber) 
You use an API command to get the handle of the parent.

Code: Select all

hParent.l = SendMessage_(GadgetID(#Tree), #TVM_GETNEXTITEM, #TVGN_PARENT, hItem) 
Then you get the actual number (as would be returned by GetGadgetState) of the tree item that is the parent.

Code: Select all

ParentNumber = TreeGadgetItemNumber(#Tree, hParent) 
Once you know the number of the parent, you can get the text of that parent node (ParentNumber) to build your path with.

I'll see if I can whip up a recursive treegadget walk for this as I haven't tested Freak's code and don't know which parent it gets, the immediate one or the ultimate parent.
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4789
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Backwards treewalk example

Post by Fangbeast »

Have a look at this and modify it to suit yourself, it should do what you want.

It does a backward treewalk from the item clicked and adds all the paths together to give you a current full path.

Code: Select all

;---------------------------------------------------------------------------------------------------------------------------

Enumeration
  #Window_Test_Form                             ; Window Constants
EndEnumeration

#WindowIndex = #PB_Compiler_EnumerationValue

Enumeration                                   ; Gadget Constants
  #Gadget_Test_Form_Creatures                   ; Window_Test_Form
  #Gadget_Test_Form_Messages
  #Gadget_Test_Form_Mainframe
EndEnumeration

#GadgetIndex = #PB_Compiler_EnumerationValue

;---------------------------------------------------------------------------------------------------------------------------

Procedure.l Window_Test_Form()
  If OpenWindow(#Window_Test_Form,175,0,700,400,#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_Invisible,"Test Form")
    If CreateGadgetList(WindowID(#Window_Test_Form))
      TreeGadget(#Gadget_Test_Form_Creatures,15,15,225,370)
      AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Physical")
  OpenTreeGadgetNode(#Gadget_Test_Form_Creatures)
  AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Human")
    OpenTreeGadgetNode(#Gadget_Test_Form_Creatures)
    AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Role")
      OpenTreeGadgetNode(#Gadget_Test_Form_Creatures)
      AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Swordsman")
      AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Magician")
      AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Thief")
      AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Trader")
      AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Asassin")
      AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Politician")
      AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Cleric")
      CloseTreeGadgetNode(#Gadget_Test_Form_Creatures)
    AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Strength")
      OpenTreeGadgetNode(#Gadget_Test_Form_Creatures)
      AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Level")
      AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Maximum")
      CloseTreeGadgetNode(#Gadget_Test_Form_Creatures)
    AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Agility")
    AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Cunning")
    AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Diplomacy")
    AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Evil")
    CloseTreeGadgetNode(#Gadget_Test_Form_Creatures)
;-------------------------------------------
  AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Alien")
    OpenTreeGadgetNode(#Gadget_Test_Form_Creatures)
    AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Role")
      OpenTreeGadgetNode(#Gadget_Test_Form_Creatures)
      AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Swordsman")
      AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Magician")
      AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Thief")
      AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Trader")
      AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Asassin")
      AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Politician")
      AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Cleric")
      CloseTreeGadgetNode(#Gadget_Test_Form_Creatures)
    AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Strength")
      OpenTreeGadgetNode(#Gadget_Test_Form_Creatures)
      AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Level")
      AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Maximum")
      CloseTreeGadgetNode(#Gadget_Test_Form_Creatures)
    AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Agility")
    AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Cunning")
    AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Diplomacy")
    AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Evil")
    CloseTreeGadgetNode(#Gadget_Test_Form_Creatures)
;------------------------------------------              
  AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Animal")
    OpenTreeGadgetNode(#Gadget_Test_Form_Creatures)
    AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Role")
      OpenTreeGadgetNode(#Gadget_Test_Form_Creatures)
      AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Swordsman")
      AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Magician")
      AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Thief")
      AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Trader")
      AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Asassin")
      AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Politician")
      AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Cleric")
      CloseTreeGadgetNode(#Gadget_Test_Form_Creatures)
    AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Strength")
      OpenTreeGadgetNode(#Gadget_Test_Form_Creatures)
      AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Level")
      AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Maximum")
      CloseTreeGadgetNode(#Gadget_Test_Form_Creatures)
    AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Agility")
    AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Cunning")
    AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Diplomacy")
    AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Evil")
    CloseTreeGadgetNode(#Gadget_Test_Form_Creatures)
;------------------------------------------
  AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Mythical")
    OpenTreeGadgetNode(#Gadget_Test_Form_Creatures)
    AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Role")
      OpenTreeGadgetNode(#Gadget_Test_Form_Creatures)
      AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Swordsman")
      AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Magician")
      AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Thief")
      AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Trader")
      AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Asassin")
      AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Politician")
      AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Cleric")
      CloseTreeGadgetNode(#Gadget_Test_Form_Creatures)
    AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Strength")
      OpenTreeGadgetNode(#Gadget_Test_Form_Creatures)
      AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Level")
      AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Maximum")
      CloseTreeGadgetNode(#Gadget_Test_Form_Creatures)
    AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Agility")
    AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Cunning")
    AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Diplomacy")
    AddGadgetItem(#Gadget_Test_Form_Creatures, -1, "Evil")
    CloseTreeGadgetNode(#Gadget_Test_Form_Creatures)
  CloseTreeGadgetNode(#Gadget_Test_Form_Creatures)
        SendMessage_(GadgetID(#Gadget_Test_Form_Creatures),$111D,0,12189133)
      EditorGadget(#Gadget_Test_Form_Messages,250,15,435,370)
        SendMessage_(GadgetID(#Gadget_Test_Form_Messages),#EM_SETBKGNDCOLOR,0,16703173)
      Frame3DGadget(#Gadget_Test_Form_Mainframe,5,0,690,395,"")
      HideWindow(#Window_Test_Form,0)
      ProcedureReturn WindowID()
    EndIf
  EndIf
EndProcedure

;---------------------------------------------------------------------------------------------------------------------------

If Window_Test_Form()                             ; Main Loop

  QuitTest_Form = 0
  
  Repeat
    EventID = WaitWindowEvent()
    Select EventID
      Case #PB_Event_CloseWindow
        If EventWindowID() = #Window_Test_Form
          QuitTest_Form = 1
        EndIf
      Case #PB_Event_Gadget
        Select EventGadgetID()
          Case #Gadget_Test_Form_Creatures
            Select EventType()
              Case #PB_EventType_LeftClick        : Gosub Test_Tree
              Case #PB_EventType_LeftDoubleClick
              Case #PB_EventType_RightDoubleClick
              Case #PB_EventType_RightClick
              Default
            EndSelect
          Case #Gadget_Test_Form_Messages
        EndSelect
    EndSelect
  Until QuitTest_Form
  CloseWindow(#Window_Test_Form)
EndIf
End

Test_Tree:

  If GetGadgetState(#Gadget_Test_Form_Creatures) <> -1
    CurrentItem.l = GetGadgetState(#Gadget_Test_Form_Creatures)
    CurrentText.s = GetGadgetItemText(#Gadget_Test_Form_Creatures, CurrentItem, 0)
    
    ItemToWalk.l = CurrentItem
    FullPath.s   = CurrentText.s
  
    Repeat
      hItem.l        = GadgetItemID(#Gadget_Test_Form_Creatures, ItemToWalk)
      hParent.l      = SendMessage_(GadgetID(#Gadget_Test_Form_Creatures), #TVM_GETNEXTITEM, #TVGN_PARENT, hItem)
      ParentNumber.l = TreeGadgetItemNumber(#Gadget_Test_Form_Creatures, hParent)
      ParentText.s   = GetGadgetItemText(#Gadget_Test_Form_Creatures, ParentNumber, 0)
      FullPath.s     = ParentText + "/" + FullPath
      ItemToWalk     = ParentNumber
    Until ItemToWalk = -1

    If Left(FullPath.s, 1) = "/"
      FullPath.s = Mid(FullPath.s, 2, Len(FullPath.s) - 1)
    EndIf
    AddGadgetItem(#Gadget_Test_Form_Messages, -1, "Line:   " + Str(CurrentItem))
    AddGadgetItem(#Gadget_Test_Form_Messages, -1, "Child:  " + CurrentText)
    AddGadgetItem(#Gadget_Test_Form_Messages, -1, "Parent: " + FullPath.s)
    AddGadgetItem(#Gadget_Test_Form_Messages, -1, "-------------------------------------------")
    
  EndIf

Return

Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
Mr Tickle
User
User
Posts: 25
Joined: Mon Oct 13, 2003 10:33 pm
Location: England, Derbyshire.

Post by Mr Tickle »

8O
Thanks for all your help :wink: I'll see what I can learn from this.
Mr Tickle.
Athlon xp 2500+, Gigabyte KT400-FSB333, Gf3 Ti200, SB Live 5.1
Mr Tickle
User
User
Posts: 25
Joined: Mon Oct 13, 2003 10:33 pm
Location: England, Derbyshire.

Post by Mr Tickle »

Thanks, Works perfectly :wink:
Mr Tickle.
Athlon xp 2500+, Gigabyte KT400-FSB333, Gf3 Ti200, SB Live 5.1
Post Reply