[wxPython-users] need help displaying One Word at a time...
Gary Kline
kline at thought.org
Tue Mar 4 15:21:52 PST 2008
On Tue, Mar 04, 2008 at 12:53:19PM -0800, Robin Dunn wrote:
> Gary Kline wrote:
> >Hi Guys,
> >
> >Well, by trial/error, I'm learning.... what works and what doesn't;
> >and what's necessary and not. But I'm stuck wx. StaticText in a loop.
> >I've got a two-word file: "Hello, world" and want to disply each for a
> >fraction of a sec.
> >
> >
> >
> >
> > def __init__(self, parent, log):
> > wx.Panel.__init__(self, parent, -1)
> > self.log = log
> >
> > f = open("2w.txt", "r")
> > lines = f.readlines()
> >
> > l1 = wx.StaticText(self, -1, "wx.TextCtrl")
> > for line in lines:
> > print "DEBUG: line = %s" % (line);
> > words = string.split(line)
> > for word in words:
> > print "DEBUG: word = %s" % (word);
> > t1 = wx.TextCtrl(self, -1, word);
> > time.sleep(0.99)
> > wx.CallAfter(t1.SetInsertionPoint, 0)
> > self.tc1 = t1
> > space = 4
> > sizer = wx.FlexGridSizer(cols=1, hgap=space, vgap=space)
> > sizer.AddMany([ l1, t1, (0,0), ])
> > border = wx.BoxSizer(wx.VERTICAL)
> > self.SetSizer(border)
> > self.SetAutoLayout(True)
> >
> > f.close()
> >
> >
> >I probably have some unnecessary code in here; but then this is my
> >first attempt at python+X11. I've googled and grep'd around to see
> >if there are any other wx python text function I could try. Thought
> >I'd ask the wizards first:)
>
> Keep in mind that in the __init__ method the window most likely is not
> even visible yet (because the parent frame probably isn't shown yet) so
> sleeping and changing values there will not be able to be seen at all.
> Secondly, you should not us sleep for timing things like this, use a
> timer and events instead. In other words, give the widget your initial
> value, create and start a timer and bind a handler to the timer event,
> and then continue with the normal startup. Then in the timer event
> handler you can just change the value of the widget.
Haven'tt worked with times since my Athena days:)
Would this quasi pseduo-code be close? or am i still too far off the
mark? I probably have a lo
>
def OneWord(self, event)
self.Bind(wx.EVT_TIMER, self.OnTimer)
# Set up a timer
self.timer = wx.Timer(self, -1)
self.timer.Start(750) # variable
f = open("2w.txt", "r")
lines = f.readlines()
l1 = wx.StaticText(self, -1, "wx.TextCtrl")
for line in lines:
print "DEBUG: line = %s" % (line);
words = string.split(line)
for word in words:
print "DEBUG: word = %s" % (word);
t1 = wx.TextCtrl(self, -1, word);
wx.CallAfter(t1.SetInsertionPoint, 0)
self.tc1 = t1
space = 4
sizer = wx.FlexGridSizer(cols=1, hgap=space, vgap=space)
sizer.AddMany([ l1, t1, (0,0), ])
border = wx.BoxSizer(wx.VERTICAL)
>
--
Gary Kline kline at thought.org www.thought.org Public Service Unix
http://jottings.thought.org http://transfinite.thought.org
More information about the wxpython-users
mailing list