[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[pygame] PGU Updateable Text Class



Hi. I'm trying to build a widget using PGU that will allow me to display a large block of text, and change that text during the program in response to strings sent from elsewhere in the program. How do I do that?

I started with the Dialog class, and said:

class TextDisplay(gui.Dialog):
    def __init__(self,**params):
        self.title = gui.Label( params.get("title","Untitled") )
        self.space = self.title.style.font.size(" ")
        self.textblock = gui.Document(width=400)
        self.AddText("This is a journey into sound.")
        gui.Dialog.__init__(self,self.title,self.textblock)

    def AddText(self,text="Foo?"):
        print "Calling AddText."
        self.textblock.block(align=-1)
        for word in text.split():
            self.textblock.add(gui.Label(word))
            self.textblock.space(self.space)
        self.textblock.br( self.space[1] )

app = gui.Desktop()
app.connect(gui.QUIT,app.quit,None)

c = gui.Table(width=640,height=480)
c.tr()

t = TextDisplay()
t.connect(gui.CLICK,t.AddText,"Foobar")
c.td(t)

app.run(c)

pygame.display.quit()


Result: The widget comes up with the default text (printing out "Calling AddText" in the console), but clicking on the widget's upper-right button prints "Calling AddText" without any other visible effect. What am I doing wrong? Is there a better way to do this?


By the way, it's helpful to call pygame.display.quit() at the end of the demo programs, so that the graphics window closes for users trying the program in IDLE.

Thanks for any help.

Kris