YesNoDialog setMessage() cause unexpected result

Is there something wrong with this code? When i called the same function the button just got enlarge everytime i call the looping function.

import direct.directbase.DirectStart
from pandac.PandaModules import *
from direct.gui.DirectGui import *
import sys

yn_dialog = YesNoDialog(
	text="Do you want to close this dialog?"

def reset():
	global yn_dialog
	yn_dialog.setMessage('new message2') #if this line is commented, it will run smoothly



try clicking ke ‘No’ button.
found the same error with panda 1.7 engine too.

If you know what happens, you’d know how to fix it.

setMessage() :

    def setMessage(self, message):
        self['text'] = message

configureDialog() :

        if self.numButtons != 0:
            bpad = self['button_pad']
            # Get button size
            if self['buttonSize']:
                # Either use given size
                buttonSize = self['buttonSize']
                bl = buttonSize[0]
                br = buttonSize[1]
                bb = buttonSize[2]
                bt = buttonSize[3]
                # Or get bounds of union of buttons
                bl = br = bb = bt = 0
                for button in self.buttonList:
                    bounds = button.stateNodePath[0].getTightBounds()
                    bl = min(bl, bounds[0][0])
                    br = max(br, bounds[1][0])
                    bb = min(bb, bounds[0][2])
                    bt = max(bt, bounds[1][2])
                bl -= bpad[0]
                br += bpad[0]
                bb -= bpad[1]
                bt += bpad[1]
                # Now resize buttons to match largest
                for button in self.buttonList:
                    button['frameSize'] = (bl, br, bb, bt)

Since you don’t use buttonSize, each button’s bounds are enlarged by button_pad.
You could set button_pad to (0,0), but that’s ugly.

There’s no way to prevent the padding, but since the buttons are already created and shouldn’t change, I can only prevent the whole process on the buttons, by clearing the dialog’s buttonList.
You must want to say : DON’T TOUCH MY BUTTONS !

def reset():
   global yn_dialog
   # YNJH: temporarily clears buttonList, so no button will be enlarged on .configureDialog()
   bl = yn_dialog.buttonList
   yn_dialog.buttonList = []
   yn_dialog.setMessage('new message2') #if this line is commented, it will run smoothly
   # YNJH: restores buttonList

Well i just begun exploring the GUI, and found something not set properly. But not quite into the core yet.
Then it’s true that its really has ‘unexpected’ result. Its against common logic. In my opinion setMessage() shouldn’t be affecting the buttons but the text only.
I search for similar function other than setMessage() but to no avail. If there is then it would be better than reassigning the buttonList.
But that workaround works perfectly Jo, in the meantime i’ll used that.
Thanks for the advice. :wink: