I’m trying to create the same effect on a CtrlText when a button is pressed.
import sys
import time
string = “this is a cool test”
s = 0
while s < len(string):
sys.stdout.write(string[s]) ## I have self.changeview as CtrlText
sys.stdout.flush() ## I have self.changeview as CtrlText
time.sleep(0.06) # set the time milliseconds for faster output
s = s + 1
sys.stdout.write(’\n’)
I’ve tried using append, but all I get is a delayed wxpython script.
I need help using this recipe on wxpython.
I’m trying to create the same effect on a CtrlText when a button is pressed.
import sys
import time
string = “this is a cool test”
s = 0
while s < len(string):
sys.stdout.write(string[s]) ## I have self.changeview as CtrlText
sys.stdout.flush() ## I have self.changeview as CtrlText
time.sleep(0.06) # set the time milliseconds for faster output
s = s + 1
sys.stdout.write(‘\n’)
try this
“”"
import wx
class Window(wx.Frame):
def init(self):
super().init(None, -1)
self.SetStatusBar(wx.StatusBar(self))
sizer = wx.BoxSizer()
self.text = wx.TextCtrl(self, -1,
style=wx.TE_MULTILINE|wx.TE_PROCESS_ENTER)
sizer.Add(self.text, 1, wx.EXPAND)
self.SetSizer(sizer)
def f(textctrl, s):
textctrl.SetValue(textctrl.GetValue()+s[0])
wx.CallLater(80, f, textctrl, s[1:])
def main():
a = wx.App(0)
w = Window()
w.Show()
s = ‘cool test indeed…’
wx.CallAfter(f, w.text, s)
a.MainLoop()
if name == ‘main’:
main()
“”"
···
On Sunday, September 15, 2013 10:31:58 PM UTC+3, George McCown wrote:
I’ve tried using append, but all I get is a delayed wxpython script.
I need help using this recipe on wxpython.
I'm trying to create the same effect on a CtrlText when a button is
pressed.
import sys
import time
string = "this is a cool test"
s = 0
while s < len(string):
sys.stdout.write(string[s]) ## I have self.changeview as CtrlText
sys.stdout.flush() ## I have self.changeview as CtrlText
time.sleep(0.06) # set the time milliseconds for faster output
s = s + 1
sys.stdout.write('\n')
def main():
a = wx.App(0)
w = Window()
w.Show()
s = 'cool test indeed...'
wx.CallAfter(f, w.text, s)
a.MainLoop()
if __name__ == '__main__':
main()
"""
Using a timer would work well too, or even just substituting wx.CallLater for wx.CallAfter in your example using a timeout of 60 would more closely approximate the original code.
···
On Sunday, September 15, 2013 10:31:58 PM UTC+3, George McCown wrote:
I’m trying to create the same effect on a CtrlText when a button is pressed.
import sys
import time
string = “this is a cool test”
s = 0
while s < len(string):
sys.stdout.write(string[s]) ## I have self.changeview as CtrlText
sys.stdout.flush() ## I have self.changeview as CtrlText
time.sleep(0.06) # set the time milliseconds for faster output
s = s + 1
sys.stdout.write(‘\n’)
try this
“”"
import wx
class Window(wx.Frame):
def init(self):
super().init(None, -1)
self.SetStatusBar(wx.StatusBar(self))
sizer = wx.BoxSizer()
self.text = wx.TextCtrl(self, -1,
style=wx.TE_MULTILINE|wx.TE_PROCESS_ENTER)
sizer.Add(self.text, 1, wx.EXPAND)
self.SetSizer(sizer)
def f(textctrl, s):
textctrl.SetValue(textctrl.GetValue()+s[0])
wx.CallLater(80, f, textctrl, s[1:])
def main():
a = wx.App(0)
w = Window()
w.Show()
s = ‘cool test indeed…’
wx.CallAfter(f, w.text, s)
a.MainLoop()
if name == ‘main’:
main()
“”"
I’ve tried using append, but all I get is a delayed wxpython script.
I need help using this recipe on wxpython.
I modified another method. You click a button and the effect works without having to flush the data.
def onChange (self, evt):
string = " "
for char in string:
mybyte = "today I will jump and hop but hope I don't fall and plunge"
for bit in mybyte:
self.change_show.write(bit)
time.sleep(0.04)
change_show.write("\n")
···
On Wednesday, September 18, 2013 8:35:03 AM UTC-5, George McCown wrote:
I’m getting a NameError: name ‘main’ is not defined
Whats going on your last two lines?
On Monday, September 16, 2013 1:00:03 PM UTC-5, Glazner wrote:
Hi
On Sunday, September 15, 2013 10:31:58 PM UTC+3, George McCown wrote:
I’m trying to create the same effect on a CtrlText when a button is pressed.
import sys
import time
string = “this is a cool test”
s = 0
while s < len(string):
sys.stdout.write(string[s]) ## I have self.changeview as CtrlText
sys.stdout.flush() ## I have self.changeview as CtrlText
time.sleep(0.06) # set the time milliseconds for faster output
s = s + 1
sys.stdout.write(‘\n’)
try this
“”"
import wx
class Window(wx.Frame):
def init(self):
super().init(None, -1)
self.SetStatusBar(wx.StatusBar(self))
sizer = wx.BoxSizer()
self.text = wx.TextCtrl(self, -1,
style=wx.TE_MULTILINE|wx.TE_PROCESS_ENTER)
sizer.Add(self.text, 1, wx.EXPAND)
self.SetSizer(sizer)
def f(textctrl, s):
textctrl.SetValue(textctrl.GetValue()+s[0])
wx.CallLater(80, f, textctrl, s[1:])
def main():
a = wx.App(0)
w = Window()
w.Show()
s = ‘cool test indeed…’
wx.CallAfter(f, w.text, s)
a.MainLoop()
if name == ‘main’:
main()
“”"
I’ve tried using append, but all I get is a delayed wxpython script.
I need help using this recipe on wxpython.
I modified another method. You click a button and the effect works
without having to flush the data.
def onChange (self, evt):
string = " "
for char in string:
mybyte = "today I will jump and hop but hope I don't fall and plunge"
for bit in mybyte:
self.change_show.write(bit)
time.sleep(0.04)
change_show.write("\n")
Even for small amounts of time like this it is still not a good idea to block the event loop. During that 0.04 seconds times the number of items in mybyte the event loop will not be able to send any events, making the UI seem non-responsive to the user. In an event-driven architecture it is always best to use events to signal when it is time to do something, whether that something is responding to some user action or to a change on the system clock or whatever.