wx.richtext.RichTextCtrl real-time display text

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

wx.richtext.RichTextCtrl real-time display text

wxPython-users mailing list-2
Hi, there, 
I want to use wx.richtext.RichTextCtrl to display real-time(running-time) texts. But it seems wx.richtext.RichTextCtrl can not display texts until the task is done, please look at the following sample code. Did I miss something? However, I tried wx.TextCtrl and it can display texts during running time without any problem. In following code, you can switch two self.log to see difference. 

Your clue is appreciated. 

Eddy H.
 

import wx
import wx.richtext
import sys

 
class MyForm(wx.Frame):
 
    def __init__(self):
        wx.Frame.__init__(self, None, wx.ID_ANY, "wxPython Redirect Tutorial")
 
        # Add a panel so it looks the correct on all platforms
        panel = wx.Panel(self, wx.ID_ANY)
        self.log = wx.richtext.RichTextCtrl(panel, wx.ID_ANY, size=(300,100), style = wx.TE_MULTILINE|wx.TE_READONLY|wx.HSCROLL)
        #self.log = wx.TextCtrl(panel, wx.ID_ANY, size=(300,100), style = wx.TE_MULTILINE|wx.TE_READONLY|wx.HSCROLL)        
        btn = wx.Button(panel, wx.ID_ANY, 'Push me!')
        self.Bind(wx.EVT_BUTTON, self.onButton, btn)
 
        # Add widgets to a sizer        
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.log, 1, wx.ALL|wx.EXPAND, 5)
        sizer.Add(btn, 0, wx.ALL|wx.CENTER, 5)
        panel.SetSizer(sizer)
 
 
    def onButton(self, event):
        for i in range(3000):
            self.log.WriteText("You pressed the button!\n")
        self.Refresh();
            
 
# Run the program
if __name__ == "__main__":
    app = wx.App(False)
    frame = MyForm().Show()
    app.MainLoop()

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: wx.richtext.RichTextCtrl real-time display text

Adrian Hill
Eddy,

Add a line
wx.Yield()
after the WriteText() line, within the "for i in range(3000):" loop.

Adrian


On Friday, February 3, 2017 at 9:47:05 PM UTC-7, SL Huang wrote:
Hi, there, 
I want to use wx.richtext.RichTextCtrl to display real-time(running-time) texts. But it seems wx.richtext.RichTextCtrl can not display texts until the task is done, please look at the following sample code. Did I miss something? However, I tried wx.TextCtrl and it can display texts during running time without any problem. In following code, you can switch two self.log to see difference. 

Your clue is appreciated. 

Eddy H.
 

import wx
import wx.richtext
import sys

 
class MyForm(wx.Frame):
 
    def __init__(self):
        wx.Frame.__init__(self, None, wx.ID_ANY, "wxPython Redirect Tutorial")
 
        # Add a panel so it looks the correct on all platforms
        panel = wx.Panel(self, wx.ID_ANY)
        self.log = wx.richtext.RichTextCtrl(panel, wx.ID_ANY, size=(300,100), style = wx.TE_MULTILINE|wx.TE_READONLY|wx.HSCROLL)
        #self.log = wx.TextCtrl(panel, wx.ID_ANY, size=(300,100), style = wx.TE_MULTILINE|wx.TE_READONLY|wx.HSCROLL)        
        btn = wx.Button(panel, wx.ID_ANY, 'Push me!')
        self.Bind(wx.EVT_BUTTON, self.onButton, btn)
 
        # Add widgets to a sizer        
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.log, 1, wx.ALL|wx.EXPAND, 5)
        sizer.Add(btn, 0, wx.ALL|wx.CENTER, 5)
        panel.SetSizer(sizer)
 
 
    def onButton(self, event):
        for i in range(3000):
            self.log.WriteText("You pressed the button!\n")
        self.Refresh();
            
 
# Run the program
if __name__ == "__main__":
    app = wx.App(False)
    frame = MyForm().Show()
    app.MainLoop()

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: wx.richtext.RichTextCtrl real-time display text

wxPython-users mailing list-2
Hi, Adrian, 
Thank you so much! That saved me lots of time to continuously search around. 

Eddy


On Sunday, February 5, 2017 2:40 PM, Adrian Hill <[hidden email]> wrote:


Eddy,

Add a line
wx.Yield()
after the WriteText() line, within the "for i in range(3000):" loop.

Adrian


On Friday, February 3, 2017 at 9:47:05 PM UTC-7, SL Huang wrote:
Hi, there, 
I want to use wx.richtext.RichTextCtrl to display real-time(running-time) texts. But it seems wx.richtext.RichTextCtrl can not display texts until the task is done, please look at the following sample code. Did I miss something? However, I tried wx.TextCtrl and it can display texts during running time without any problem. In following code, you can switch two self.log to see difference. 

Your clue is appreciated. 

Eddy H.
 

import wx
import wx.richtext
import sys

 
class MyForm(wx.Frame):
 
    def __init__(self):
        wx.Frame.__init__(self, None, wx.ID_ANY, "wxPython Redirect Tutorial")
 
        # Add a panel so it looks the correct on all platforms
        panel = wx.Panel(self, wx.ID_ANY)
        self.log = wx.richtext.RichTextCtrl( panel, wx.ID_ANY, size=(300,100), style = wx.TE_MULTILINE|wx.TE_ READONLY|wx.HSCROLL)
        #self.log = wx.TextCtrl(panel, wx.ID_ANY, size=(300,100), style = wx.TE_MULTILINE|wx.TE_ READONLY|wx.HSCROLL)        
        btn = wx.Button(panel, wx.ID_ANY, 'Push me!')
        self.Bind(wx.EVT_BUTTON, self.onButton, btn)
 
        # Add widgets to a sizer        
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.log, 1, wx.ALL|wx.EXPAND, 5)
        sizer.Add(btn, 0, wx.ALL|wx.CENTER, 5)
        panel.SetSizer(sizer)
 
 
    def onButton(self, event):
        for i in range(3000):
            self.log.WriteText("You pressed the button!\n")
        self.Refresh();
            
 
# Run the program
if __name__ == "__main__":
    app = wx.App(False)
    frame = MyForm().Show()
    app.MainLoop()

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.