Pick out items in treeview

Find quick help here to get you started with Hollywood

Pick out items in treeview

Postby delbourg » Fri Sep 01, 2017 6:33 am

I have set up a treeview of animals using RAPAGUI. Here is the MyTreeview.xml file for that

Code: Select all
<?xml version="1.0" encoding="iso-8859-1"?>
<application id="app">            
   <window id="win" title="Treeview" height="400" width="500">
      <vgroup>
         <treeview id="tv">
            <column title="ANIMAL FILES" width="150"/>
            <column title="jpgfile" width="100"/>
            <column title="pdffile" width="100"/>
            <column title="docfile" width="100"/>
            
            <node name="Pet Files">
               <node name="CatFiles">
                  <leaf id="WildCats">
                     <item>Wild Cats</item>
                     <item>Tiger.jpg</item>
                     <item>Leopard.pdf</item>
                     <item>Panther.doc</item>
                  </leaf>
                  <leaf id="TameCats">
                     <item>Tame Cats</item>
                     <item>Ginger.jpg</item>
                     <item>Tonkinese.pdf</item>
                     <item>RagDoll.doc</item>
                                           </leaf>                  
               </node>
               
               <node name="DogFiles">
                  <leaf id="WildDogs">
                     <item>Wild Dogs</item>
                     <item>Jackal.jpg</item>
                     <item>Wolf.jpg</item>
                     <item>Hyena.doc</item>
                  </leaf>   
                  <leaf id="TameDogs">
                     <item>Tame Dogs</item>
                     <item>Labrador.jpg</item>
                     <item>Alsation.pdf</item>
<item>Bulldog.doc</item>
                  </leaf>                  
               </node>      
            </node>
         </treeview>
         <hgroup>
            <button id="viewjpg">View jpg</button>
            <button id="viewpdf">View pdf</button>
            <button id="viewdoc">View doc</button>
         </hgroup>   
      </vgroup>
   </window>
</application>


And now here is my hollywood script (MyTreeview.hws) which will run it:

Code: Select all
@VERSION 6,1
@REQUIRE "RapaGUI"

Function p_EventFunc(msg)
   Switch msg.action
   Case "RapaGUI":
      Switch msg.attribute
      Case "Pressed":
         Switch msg.id
         Case "viewjpg":
            
         Case "viewpdf":
            
         Case "viewdoc":   
               
         EndSwitch                              
       EndSwitch
   EndSwitch
EndFunction

moai.CreateApp(FileToString("MyTreeview.xml"))
InstallEventHandler({RapaGUI = p_EventFunc})
moai.DoMethod("tv", "open", "root", True)

Repeat
   WaitEvent
Forever


What I wish to be able to do is to select a line, then click on one of the buttons at bottom to execute that particular file from the row. For that I need to be able to interrogate the entry (using GetEntry I presume) and parse it to pick out each item on the row. That will allow me to execute the particular item entry when I click on one of the buttons at the bottom. I have no idea how to do this parsing.
I have read the treeview blurb in the RAPAGUI manual but have not been able to follow the logic there (my fault I suppose, though I have done some programming in the past). Can anyone assist me as to how to parse the selected row using GetEntry? Thanks in advance.
delbourg
 
Posts: 21
Joined: Tue Jun 20, 2017 6:07 am
Location: Tasmania

Re: Pick out items in treeview

Postby SamuraiCrow » Fri Sep 01, 2017 5:30 pm

There are two ways to do this: Either make each item clickable by giving it a separate button with a separate ID, or supply the information as a table using the setter and getter methods of MOAI.UserData in your Hollywood code to hold the JPG, PDF, and DOC corresponding to the leaf item. I don't think there is a getter method for the title of each item though. Correction: GetItem method will read the label of a column of a listview.
SamuraiCrow
 
Posts: 120
Joined: Fri May 15, 2015 5:15 pm
Location: Ft. Collins, Colorado USA

Re: Pick out items in treeview

Postby delbourg » Sat Sep 02, 2017 2:42 am

Thanks for the suggestion. However buttons are NOT allowed in treeview, as I understand it. (It is important that I use treeview rather than listview as I ultimately plan to do a genealogy treeview.)
Incidentally the example given in the RAPAGUI manual for Treeview.GetEntry seems to be wrong or at the very least indicates a bug because I cannot get the command to Unpack the table items. Perhaps Airsoft are aware of this?
delbourg
 
Posts: 21
Joined: Tue Jun 20, 2017 6:07 am
Location: Tasmania

Re: Pick out items in treeview

Postby airsoftsoftwair » Sat Sep 02, 2017 12:01 pm

It's a bug in your code. Unpack() will unpack the individual table items so your p_Log() function will receive more than just one argument. A nicer way to do what you want is to use the Concat() function to concatenate the individual table items into a single string which can then be added to your listview. I've fixed the code for you. Here you go:

Code: Select all
@VERSION 6,1
@REQUIRE "RapaGUI"

Function p_DumpListTree(id$, node, indent)
   Local found, t = moai.DoMethod(id$, "GetEntry", node, "Head")
   While found = True
      p_Log(indent, t)
      If t.Node = True Then p_DumpListTree(id$, t.uid, indent + 4)
      found, t = moai.DoMethod(id$, "GetEntry", t.uid, "Next")
   Wend
EndFunction

Function p_Log(indent, t)   

   Local e$
   
   If indent > 0
      e$ = RepeatStr(" ", indent) .. IIf(t.node = True, "+", "") .. Concat(t.items, " ")
   Else
      e$ = IIf(t.node = True, "+", "") .. Concat(t.items, " ")
   EndIf
      
   moai.DoMethod("MessageListbox", "insert", "bottom", e$)
   moai.DoMethod("MessageListbox", "jump", "bottom")   
   
EndFunction
            
Function p_EventFunc(msg)
   Switch msg.action
   Case "RapaGUI":
      Switch msg.attribute
      Case "Pressed":
         Switch msg.id
         Case "viewjpg":
            p_DumpListTree("tv", "root", 0)
         Case "viewpdf":
            p_DumpListTree("tv", "root", 0)
         Case "viewdoc":   
            p_DumpListTree("tv", "root", 0)   
         EndSwitch                              
       EndSwitch
   EndSwitch
EndFunction

moai.CreateApp(FileToString("MyTreeview.xml"))

InstallEventHandler({RapaGUI = p_EventFunc})
moai.DoMethod("tv", "open", "root", True)

Repeat
   WaitEvent
Forever
User avatar
airsoftsoftwair
 
Posts: 2350
Joined: Fri Feb 12, 2010 3:33 pm
Location: Germany

Re: Pick out items in treeview

Postby delbourg » Sun Sep 03, 2017 10:41 am

Ok, I have a treeview and open it right up. So I have various lines with item entries. I click/select a line in this treeview, which now has particular item entries. How to I extract the item entries in succession. The rapagui treeview example shows how to extract the full set of entries of the entire treeview. How to I just extract he entries for just the selected line?

I have had difficulty understanding the blurb about treeview in the manual to be able to figure out the answer to my question.
delbourg
 
Posts: 21
Joined: Tue Jun 20, 2017 6:07 am
Location: Tasmania

Re: Pick out items in treeview

Postby airsoftsoftwair » Sun Sep 03, 2017 12:06 pm

If you only want to get the active item, you don't have to iterate over the complete tree like it is done in the p_DumpListTree() function but just call Treeview.GetEntry() once with "item" and "position" both set to "active". Then you'll get the active item, but note that this can be a node or a leaf.
User avatar
airsoftsoftwair
 
Posts: 2350
Joined: Fri Feb 12, 2010 3:33 pm
Location: Germany

Re: Pick out items in treeview

Postby delbourg » Mon Sep 04, 2017 9:06 am

Thank you airsoft. It is really easy when you know how, but I just could not work it out from the manual (my stupidity). All my treeview questions answered now, so no more bothering questions from me.
delbourg
 
Posts: 21
Joined: Tue Jun 20, 2017 6:07 am
Location: Tasmania

Re: Pick out items in treeview

Postby airsoftsoftwair » Tue Sep 05, 2017 6:30 pm

delbourg wrote:Thank you airsoft. It is really easy when you know how, but I just could not work it out from the manual (my stupidity).


Actually, the Treeview.GetEntry() documentation and the whole method are pretty confusing. It's all the fault of MUI's Listtree.mcc class which has the very same method. RapaGUI just imitates it for other platforms.
User avatar
airsoftsoftwair
 
Posts: 2350
Joined: Fri Feb 12, 2010 3:33 pm
Location: Germany


Return to Newbie questions

Who is online

Users browsing this forum: No registered users and 1 guest