I am outputting the stderr to a wx.TextCtrl, after 10 lines I want to delete the first line so there is only ever a maximum of 10 lines in my wx.TextCtrl window.
I have a python script which is using multiple threads and classes. I just can’t for the life of me get the below bit of code to work, can someone give me a few hints please?
a = 1
while True:
line = self.process1.stderr.readline().decode(‘utf-8’)
wx.CallAfter(self.frame.running_log1.AppendText, line)
if a >= 10:
s = wx.CallAfter(self.frame.running_log1.GetLineLength, 0) +1
wx.CallAfter(self.frame.running_log1.Remove, 0, s)
print s
a +=1
You seem to be expecting the result of GetLineLength to be returned
from CallAfter - you need to keep in mind that CallAfter queues some
code to be executed later so can not return the results of the code
for later use. You need to keep track of how many lines you have
sent to the control and use that or better would be to have an event
handler on the control that when text is added checks the number of
lines and deletes the first while there are more than 10 - this
would then happen even if multiple threads are adding text.
Gadget/Steve
···
On 29/06/14 15:19, kevjwells wrote:
I am outputting the stderr to a wx.TextCtrl, after 10 lines
I want to delete the first line so there is only ever a
maximum of 10 lines in my wx.TextCtrl window.
I have a python script which is using multiple threads and
classes. I just can’t for the life of me get the below bit of
code to work, can someone give me a few hints please?
a = 1
while True:
line =
self.process1.stderr.readline().decode(‘utf-8’)
wx.CallAfter(self.frame.running_log1.AppendText,
line)
if a >= 10:
s =
wx.CallAfter(self.frame.running_log1.GetLineLength, 0) +1
wx.CallAfter(self.frame.running_log1.Remove, 0,
s)
print s
a +=1
–
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 wxpython-users+unsubscribe@googlegroups.com.
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
Hi, thanks for your reply. I am only trying to delete the whole first line, but I don’t think there is a command for delete the first line, but i have to specify how many characters are in the first line each time, but I am unsure of how to do this. Only one thread is accessing each wx.TextCtrl.
···
On Sunday, June 29, 2014 3:46:35 PM UTC+1, Gadget Steve wrote:
On 29/06/14 15:19, kevjwells wrote:
I am outputting the stderr to a wx.TextCtrl, after 10 lines
I want to delete the first line so there is only ever a
maximum of 10 lines in my wx.TextCtrl window.
I have a python script which is using multiple threads and
classes. I just can’t for the life of me get the below bit of
code to work, can someone give me a few hints please?
a = 1
while True:
line =
self.process1.stderr.readline().decode(‘utf-8’)
wx.CallAfter(self.frame. running_log1.AppendText,
line)
if a >= 10:
s =
wx.CallAfter(self.frame.running_log1.GetLineLength, 0) +1
wx.CallAfter(self.frame. running_log1.Remove, 0,
s)
print s
a +=1
–
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 wxpython-user...@googlegroups.com.
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
You seem to be expecting the result of GetLineLength to be returned
from CallAfter - you need to keep in mind that CallAfter queues some
code to be executed later so can not return the results of the code
for later use. You need to keep track of how many lines you have
sent to the control and use that or better would be to have an event
handler on the control that when text is added checks the number of
lines and deletes the first while there are more than 10 - this
would then happen even if multiple threads are adding text.
Gadget/Steve
As I said you will either have to keep track of it yourself or
better have an event handler for
···
On 29/06/14 15:53, kevjwells wrote:
Hi, thanks for your reply. I am only trying to
delete the whole first line, but I don’t think there is a
command for delete the first line, but i have to specify how
many characters are in the first line each time, but I am unsure
of how to do this. Only one thread is accessing each
wx.TextCtrl.
in your main thread
EVT_TEXT
on the text control that the text gets added to. Anything
that results in a change to the text control will result in a call
to this handler which can safely check the current number of lines
and delete the first line(s) if necessary.
kevjwells wrote:
I am outputting the stderr to a wx.TextCtrl, after 10 lines I want to
delete the first line so there is only ever a maximum of 10 lines in
my wx.TextCtrl window.
I have a python script which is using multiple threads and classes. I
just can't for the life of me get the below bit of code to work, can
someone give me a few hints please?
One very good alternative is to keep your list of 10 lines in a simple
Python list, then every time the list changes, go replace the entire
contents of the TextCtrl.
···
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.