DirectScrolledLists to update text in frame

Could I ask you guys for some help?

My issue is this:
I have a DirectScrolledLists. It contains a list of rpg character classes. In a separate box I have a frame with a list of strings,(a description of each class) .

I want to increment the DirectScrolledLists and when I do, I want the text to change in the frame.

So if I select soldier in DirectScrolledLists a description will appear in the separate frame saying something like “works in military, skilled in hand to hand and weapons”.

Someone might have a quick answer to this. I was hoping someone could post example code so I can learn from it.

Thanks guys!

A simple answer might be to make the items in DirectScrolledList–your class names–as DirectButtons, providing to each a method of our own that updates the text box as appropriate.

The following is an example of how such a thing might be structured–but please note that I haven’t tested this, and so may have made mistakes. If there are errors, just check the documentation for the proper methods and usages of such. ^^;

#  Presume that the DirectScrolledList is named "classList",
# and that your text box is a DirectLabel or TextNode named
# "classDescription".
#
#  I also presume that you have some means of getting
# a class description for a given class; I'm referring to that
# simply as the method "getDescription", and leaving the
# details up to you (a dictionary might work for you here).

# In the relevant initialisation method...

    # Presume that we already have a DirectScrolledList, which we'll here refer to as "classList".

    classBtn = DirectButton(text = "Wizard",
                                       command = self.updateClassDescription,
                                       <other parameters as appropriate>)
    self.classList.addItem(classBtn)

#Elsewhere in the same class...
def updateClassDescription(self):
    selected = self.classList.getSelectedText()
    description = self.getDescription(selected)
    self.classDescription.setText(description)

I thought about doing that but I’d really like to have the increment or decrement buttons change text in a frame

I found this in the manual but there is no info on it
panda3d.org/apiref.php?page= … ButtonDown

Hmm… Have you experimented with the “command” keyword of DirectScrolledList? The manual indicates that it’s fired “when the list is scrolled”, but it may respond to the increment and decrement buttons as one might expect.

Otherwise, have you tried using DirectScrolledListItems? I see that they have an undescribed attribute named “nextCommand”; the name implies that it’s a function callback (much like the “command” attribute in DirectButton or DirectScrolledList), but its use is not entirely clear from the name. (Does it fire when the item below it is selected? That would seem somewhat odd. o_0) One way or another, it might be worth trying it and seeing what causes the callback to be fired.

Food for thought, I’ll check it out Thaumaturge thanks.

Ok I have solved the problem I am having, I dug through the manual for the last few weeks and found it. Hopefully this can help anyone else who wants to make a DirectScrolledList button move to the next data in a list.

My code is still a bit buggy but you treat the button as a Direct button https://www.panda3d.org/manual/index.php/DirectButton

so create a function that does something, in my case I have two functions one goes to the next race description in the list and the other goes backwards through the same list (still buggy :confused: )

Now in your DirectScrolledList add a decButton_command and a incButton_command and make it equal to your functions (but do not put any brackets for your function “nextDescRace()” will cause an error).

def nextDescRace():
	a = raceTable.raceDesc[race.getSelectedIndex() + 1]
	print(a)
	raceInfo.setText(a)

def previousDescRace():
	a = raceTable.raceDesc[race.getSelectedIndex() - 1]
	print(a)
	raceInfo.setText(a)

race = DirectScrolledList(
    decButton_pos= (0.09, 0, 0),
    decButton_text = "<<",
    decButton_text_scale = 0.15,
    decButton_borderWidth = (0.005, 0.005),
    decButton_command = previousDescRace,
 
    incButton_pos= (0.8, 0, 0),
    incButton_text = ">>",
    incButton_text_scale = 0.15,
    incButton_borderWidth = (0.005, 0.005),
    incButton_command = nextDescRace,

	#red frame size
    frameSize = (0.0, 0.9, -0.05, 0.11),
    #frameColor = (1,0,0,0.5),
    pos = (-1.30, 0, 0.35),
    items = [],
    numItemsVisible = numItemsVisible,
    forceHeight = itemHeight,
	
    itemFrame_frameSize = (-0.2, 0.3, -0.05, 0.11),
    itemFrame_pos = (0.40, 0,0),
    )

run your code and you should be able to print to the console the next and previous data from a list, by clicking the increment or decrement buttons.