HT clear some wxPython fram?
Cliff Wells
logiplexsoftware at earthlink.net
Wed Jul 3 14:33:23 EDT 2002
On Wed, 03 Jul 2002 20:16:26 +0200
Klaus Reinhardt wrote:
> Am 03.07.02 20:06:07, schrieb Cliff Wells <logiplexsoftware at earthlink.net>:
>
> >On Wed, 03 Jul 2002 19:39:04 +0200
> >Klaus Reinhardt wrote:
> >
> >> >> HOW I CAN CLEAR SOME FRAME?
> >What do you want to clear from the frame? You've put nothing into it. I
think
> >you are confusing the stdout window with the frame. If you notice, when you
> >run your program, two windows open. The first one with the title "Close me"
is
> >the frame. The second window titled "wxPython stdout/stderr" is not the
frame.
> > I could be wrong, but I don't think there's any way to control the
> >stdout/stderr window. It's mostly for debugging purposes.
> >
> >What you will want to do instead is something more like this:
>
> ---------------------------------------------------------------------
> Hi
> I will try this (here cut).
> BUT:
>
> Aktive Verbindungen
>
> Proto Lokale Adresse Remote-Adresse Status
> TCP 0.0.0.0:1117 0.0.0.0:0 LISTENING
> TCP 127.0.0.1:4711 0.0.0.0:0 LISTENING
> TCP 217.81.119.164:1117 130.149.5.227:22 ESTABLISHED
>
> This is shown in the "wxPython stdout/stderr"-frame.
> (I'm a completely newby to python and OOP)
What you will want to do is modify the source I sent you to display your text
rather than "hello":
def OnTimer(self, evt):
self.panel.write("hello") # <- change this line to display your text
Here is a modified example that adds an additional method writelines() to
MyPanel and will perhaps make it clearer:
from wxPython.wx import *
import os
class MyPanel(wxPanel):
def __init__(self, parent):
wxPanel.__init__(self, parent, -1)
self.SetBackgroundColour(wxWHITE)
self.text = []
EVT_PAINT(self, self.OnPaint)
def OnPaint(self, event):
dc = wxPaintDC(self)
self.draw(dc)
def write(self, text):
self.text.append(text)
if len(self.text) > 10:
del self.text[0]
dc = wxClientDC(self)
self.draw(dc)
def writelines(self, lines):
self.text = lines
dc = wxClientDC(self)
self.draw(dc)
def draw(self, dc):
dc.Clear()
y = 0
for t in self.text:
dc.DrawText(t, 0, y)
y += 15
class MyFrame(wxFrame):
def __init__(self):
wxFrame.__init__(self, None, -1, "MyFrame")
self.panel = MyPanel(self)
self.timer = wxTimer(self, -1)
self.timer.Start(100)
EVT_TIMER(self, -1, self.OnTimer)
def OnTimer(self, evt):
lines = os.popen('netstat -a -n','r').readlines()
# do some filtering/formatting here
lines = filter(lambda l: l.split()[0] == 'tcp', lines)
self.panel.writelines(lines)
def OnClose(self,event):
self.timer.Stop()
self.Destroy()
class MyApp(wxApp):
def OnInit(self):
frame = MyFrame()
frame.Show(true)
return true
app = MyApp()
app.MainLoop()
--
Cliff Wells, Software Engineer
Logiplex Corporation (www.logiplex.net)
(503) 978-6726 x308 (800) 735-0555 x308
More information about the Python-list
mailing list