[wxPython] wxListCtrl cannot display first row?

Hi!

I've two question about wxListCtrl:

1. Why can't show the first data-record (row) the ListCtrl? (It seems
like the header hides the first row.)

2. When I re-sorting data with many header-clicks, why can I select
multiple rows (switch several rows to ACTIVE state)?
(the ListCtrl style is wxSIMPLE_SEL) Or how can I avoid this?

I've browsed the archives, but couldn't find any solution.

The attached file reproduce my problem. (this uses Robin's
wxColumnSorterMixin)

Any help welcome!

Thanks:
    Attila Szüts

myListCtrl.py (3.47 KB)

I believe this is a bug in wxListCtrl and the solution to the problem is
to specify an EVT_SIZE handler which sets the size of the list control
-- see the demo for details... :slight_smile:

···

On Mon, 2002-09-16 at 04:15, Szüts Attila wrote:

Hi!

I've two question about wxListCtrl:

1. Why can't show the first data-record (row) the ListCtrl? (It seems
like the header hides the first row.)

2. When I re-sorting data with many header-clicks, why can I select
multiple rows (switch several rows to ACTIVE state)?
(the ListCtrl style is wxSIMPLE_SEL) Or how can I avoid this?

I've browsed the archives, but couldn't find any solution.

The attached file reproduce my problem. (this uses Robin's
wxColumnSorterMixin)

Any help welcome!

Thanks:
    Attila Szüts

----

# Testing sorted ListCtrl?

from wxPython.wx import *
from wxPython.lib.mixins.listctrl import wxColumnSorterMixin

import cPickle, zlib

#----------------------------------------------------------------------
def getSmallUpArrowData():
    return cPickle.loads(zlib.decompress(
'x\xda\xd3\xc8)0\xe4\nV74S\x00"#\x05Cu\xae\xc4`u=\x85d\x05\xa7\x9c\xc4\xe4l0\
O\x01\xc8\xf3\xcb\xcfK\x85rP\x015\x05\xf5\xb0\x08\xea\xe9\xe9a\x08\xea\xe9\
\xc1D\t\x08\xea\xe9\xc1E\xe1\x82zz\x08Q\x9a\xfb\x88\x90\xa0\x1e\x00\xca\xb2=\
\x88' ))

def getSmallUpArrowBitmap():
    return wxBitmapFromXPMData(getSmallUpArrowData())

#----------------------------------------------------------------------
def getSmallDnArrowData():
    return cPickle.loads(zlib.decompress(
'x\xda\xd3\xc8)0\xe4\nV74S\x00"#\x05Cu\xae\xc4`u=\x85d\x05\xa7\x9c\xc4\xe4l0\
O\x01\xc8\xf3\xcb\xcfK\x85rP\x01\xfd\x05\xf5`\x00E%B\x0cY;\\\x8c\xa0\xa0\x02\
L\x0c\xd5v=\xda\xfaH\x0f\x00\xc1\x82=\x88' ))

def getSmallDnArrowBitmap():
    return wxBitmapFromXPMData(getSmallDnArrowData())

#----------------------------------------------------------------------

#----------------

class App(wxApp):

  def OnInit(self):
    frame = myframe(None, -1, "Testing ListCtrl behaviour")
    frame.Show(true)
    self.SetTopWindow(frame)

    return true

#----------------

class myframe(wxFrame, wxColumnSorterMixin):

  def __init__(self,parent,id,title):
    wxFrame.__init__(self, parent, -1, title)
    
    self.Panel = wxPanel(self, -1, style=wxTAB_TRAVERSAL)
    
    header = ('First', 'Second', 'Third', 'Fourth')
    data = [('1', 'a', 'b', 'c'), ('2', 'a', 'a', 'a'), ('3', 'b', 'b', 'b'), ('4', 'c', 'c', 'c'), ('5', 'd', 'd', 'd')]
        
    self.Dsp_result('Title', header, data)

  def Dsp_result(self, title, header=None, data=None):
    """ Display results in a ListCtrl """
    
    self.Panel.DestroyChildren()
    self.SetTitle(title)
    w, h = 300, 300
    self.SetClientSize(wxSize(w, h))
    
    # Arrows
    self.il = wxImageList(16,16)
    self.sm_up = self.il.Add(getSmallUpArrowBitmap())
    self.sm_dn = self.il.Add(getSmallDnArrowBitmap())
    
    # itemDataMap
    self.itemDataMap = {}
    for i in range(len(data)):
      self.itemDataMap[i] = data[i]
    
    # ListControl
    self.lc = wxListCtrl(self.Panel, -1, wxPoint(10, 10), wxSize(w-20, h-20), style=wxLC_REPORT|wxSUNKEN_BORDER|wxLC_SINGLE_SEL)
    self.lc.SetImageList(self.il, wxIMAGE_LIST_SMALL)
    
    # Header
    for x in range(len(header)):
      info = wxListItem()
      info.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_IMAGE | wxLIST_MASK_FORMAT
      info.m_image = -1
      info.m_format = 0
      info.m_text = header
      self.lc.InsertColumnInfo(x, info)
      
    # Insert rows
    items = self.itemDataMap.items()
    for x in range(len(items)):
      key, data = items
      self.lc.InsertStringItem(x, 'fake entry')
      self.lc.SetItemData(x, key)
      col = 0
      for y in data:
        self.lc.SetStringItem(x, col, str(y))
        #print i, y
        col += 1

    # Init the other Class
    wxColumnSorterMixin.__init__(self, len(header))
    
    # Column sizes
    for x in range(len(header)):
      self.lc.SetColumnWidth(x, 70)
    
  # Used by the wxColumnSorterMixin,
  def GetListCtrl(self):
    return self.lc

  # Used by the wxColumnSorterMixin,
  def GetSortImages(self):
    return (self.sm_dn, self.sm_up)
  
#------------------------------

def main():
  application = App(0)
  application.MainLoop()

if __name__ == '__main__':
  main()

--
Anthony Tuininga
anthony@computronix.com

Computronix
Distinctive Software. Real People.
Suite 200, 10216 - 124 Street NW
Edmonton, AB, Canada T5N 4A3
Phone: (780) 454-3700
Fax: (780) 454-3838

1. Why can't show the first data-record (row) the ListCtrl? (It seems
like the header hides the first row.)

It's there, you just can't see it when the control is first shown. As has
been mentioned alread the fix is simple, just make sure that the list
control gets a resize after is is created. A good way to do this is use a
sizer or something to manage your layout instead of using fixed positions
and sizes. (OTOH, I seem to recall that this has been fixed for 2.3.3...)

2. When I re-sorting data with many header-clicks, why can I select
multiple rows (switch several rows to ACTIVE state)?
(the ListCtrl style is wxSIMPLE_SEL) Or how can I avoid this?

Please enter a bug report about this.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!