views:

44

answers:

2

I'm working on an GUI program, and I use AppendText to update status in a multi-line text box(made of wx.TextCtrl). I noticed each time there's a new line written in this box, instead of smoothly adding this line to the end, the whole texts in the box just disappear(not in real, just visually) and I have to click the scroll button to check the newly updated/written status line. Why this happening? Should I add some styles? Hopefully you guys can help me out.

Here's my sample code:

import wx
import thread
import time

class TestFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, parent = None, id = -1, title = "Testing", pos=(350, 110), size=(490,530), style=wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX | wx.MINIMIZE_BOX)
        panel = wx.Panel(self)

        self.StartButton = wx.Button(parent = panel, id = -1, label = "Start", pos = (110, 17), size = (50, 20))
        self.MultiLine = wx.TextCtrl(parent = panel, id = -1, pos = (38, 70), size = (410, 90), style = wx.TE_MULTILINE|wx.TE_READONLY|wx.TE_AUTO_URL)

        self.Bind(wx.EVT_BUTTON, self.OnStart, self.StartButton)

    def OnStart(self, event):
        self.StartButton.Disable()
        thread.start_new_thread(self.LongRunning, ())

    def LongRunning(self):
        Counter = 1
        while True:
            self.MultiLine.AppendText("Hi," + str(Counter) + "\n")
            Counter = Counter + 1
            time.sleep(2)


class TestApp(wx.App):
    def OnInit(self):
        self.TestFrame = TestFrame()
        self.TestFrame.Show()
        self.SetTopWindow(self.TestFrame)
        return True

def main():
    App = TestApp(redirect = False)
    App.MainLoop()

if __name__ == "__main__":
    main()
A: 

try this:

self.logs = wx.TextCtrl(self, id=-1, value='', pos=wx.DefaultPosition,
                            size=(-1,300),
                            style= wx.TE_MULTILINE | wx.SUNKEN_BORDER)
self.logs.AppendText(text + "\n")
Carolus89
Not working either... Anybody can help?
Shane
A: 

Try calling the Refresh() method on the textCtrl

Update:

A question has already been asked regarding this problem, here is the answer which pretty much solves it, -its not perfect but maybe you can improve on it...

Here is a thread from the wxpython mailing list regarding the problem which may also be of interest to you.

volting
It's not working... I still get blank and have to use the scrollbar to check status...
Shane
If you can add a runnable sample, then it shouldn't take me or someone else long or figure outs what wrong. Without code its a guessing game!
volting
I've just added my code, please give it a look. : )
Shane
Sorry for the delay, see my updated answer for a link that pretty much solves your problem.
volting
@volting: Thanks a lot!
Shane
@Shane Your Welcome!
volting