Hello. I'm having trouble about drawing a border around a listctrl

"""Main module for psutils GUI"""

__version__ = "$Revision: 8 $"
# $Source$

import random

import wx
import psutil

ID_EXIT = 110

class MainGUIFrame(wx.Frame):
    """Main frame. Shows processes and graph"""
    def __init__(self):
        """Initialization of the frame"""
        wx.Frame.__init__(self, None, -1, "psutils", wx.Point(wx.CENTER_ON_SCREEN), (430, 500))

        #Main panel
        self.panel = wx.Panel(self, -1)
        self.panel.SetBackgroundColour(wx.NamedColor('white'))
        self.panel.Bind(wx.EVT_PAINT, self.paint_panel)

            #Process list
        self.process_list = wx.ListCtrl(self.panel, -1, style=wx.LC_REPORT|wx.BORDER_NONE|wx.LC_EDIT_LABELS)
        self.process_list.InsertColumn(0, "PID")
        self.process_list.InsertColumn(1, "Path")
        self.process_list.InsertColumn(3, "uid")
        self.process_list.InsertColumn(4, "gid")
        self.process_list.InsertColumn(9, "% CPU")
        
        self.process_list.SetColumnWidth(4, 50)
        
            #self.panel sizer
        pso = wx.BoxSizer(wx.HORIZONTAL)
        pso.AddStretchSpacer(1)
        pso.Add(self.process_list, 30, wx.EXPAND)
        pso.AddStretchSpacer(1)
        
        psv = wx.BoxSizer(wx.VERTICAL)
        psv.AddStretchSpacer(1)
        psv.Add(pso, 30, wx.EXPAND)
        psv.AddStretchSpacer(1)
        
        self.panel.SetSizer(psv)
        
        #Menu bar
        menu_bar = wx.MenuBar()

        file_menu = wx.Menu()
        file_menu.AppendSeparator()
        file_menu.Append(ID_EXIT, "E&xit \tCtrl+X", "Closes the application")

        menu_bar.Append(file_menu, "&File")

            #Binding menu bar entries with functions
        wx.EVT_MENU(self, ID_EXIT, self.on_exit)


        self.SetMenuBar(menu_bar)

        #Status bar
        self.status_bar = wx.StatusBar(self)

        self.states = ['','','0% CPU']

        self.status_bar.SetFields(self.states)

        self.SetStatusBar(self.status_bar)

        #Timers
        self.cpu_timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self.cpu_time, self.cpu_timer)
        self.cpu_timer.Start(1000)

    #self.panel handlers
    def paint_panel(self, event):
        dc = wx.PaintDC(self.panel)
        
        dc.SetBrush(wx.Brush(wx.NamedColor('white')))
        
        dc.Clear()
        
        x, y = self.process_list.GetPositionTuple()
        xs, ys = self.process_list.GetSize()
        
        dc.SetPen(wx.Pen(wx.NamedColor('#6d6d6d')))
        
        dc.DrawLine(x-1, y-1, xs+1, y-1)
        

    #Timer handlers
    def cpu_time(self, event):
        """Handles the cpu usage timer's events"""
        
        self.states[2] = "%d%s CPU"%(psutil.cpu_percent(), "%")
        
        self.status_bar.SetFields(self.states)

    #Menu bar handlers
    def on_exit(self, event):
        """Closes the frame"""
        self.Destroy()

    
            

class Application(wx.App):
    """wx application class. Hosts the wx windows"""
    def OnInit(self):
        main = MainGUIFrame()
        main.Show()
        return True

app=Application(redirect=False)
app.MainLoop()

the problem is that i need it to clear the whole panel at every redraw, but it does not. and i can't figure whats wrong

Clear clears the canvas not the panel. Your listbox is on the panel and not the canvas.

If you want to clear the listbox, use self.process_list.Clear()

you did not understand. i want to draw a line on the panel given the size of the listbox. when i ask to clear the panel for redrawing the line, nothing happens, and the old draws remain.

This article has been dead for over six months. Start a new discussion instead.