HT clear some wxPython fram?

Cliff Wells logiplexsoftware at earthlink.net
Wed Jul 3 14:06:07 EDT 2002


On Wed, 03 Jul 2002 19:39:04 +0200
Klaus Reinhardt wrote:

> >> HOW I CAN CLEAR SOME FRAME?
> ---------------------------------------------------------------------
> Hi
> 
> >My problem is, that the I want to monitor netstat; this 
> >is in principle working (s.b.). But I don't want the scrolling
> >frame for 2 reasons.
> >  1.) ergonomic
> >  2.) after a while of outputting the display
> >       is stopping, I think for memory-reaons.
> 
> I can use Clear here:
> 
> class MyApp(wxApp):
> 	def OnInit(self):
> 		frame = MyFrame(self.stdioWin)
> 		frame.Show(TRUE)
> 		frame.Clear()    #### OK, but sensless
> 		self.SetTopWindow(frame)
> But I want to clear the frame just bevor each new output
> is given here:
> 
> class MyFrame(wxFrame):
> ..
> 	def OnTimer(self, evt
> 		y=os.popen( 'netstat -a -n','r').read()
> ############# HERE 
> 		print "--------------------------------------------------------------"
> 		yy=y.splitlines()
> 		for i in yy: 
> 			if i[:5]=="  TCP":
> 				ry=string.split(i)
> 				print "%5s %22s %22s %22s" % (ry[0],ry[1],ry[2],ry[3])

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:

from wxPython.wx import *

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 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):
        self.panel.write("hello")
        
    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()
        

Please realize that the apparent complexity of something so simple has more to
do with the nature of GUI programming than with Python.

-- 
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