wxColumnSorterMixin and XRCed

Hi,

The wxList controls generated by XRCed are just that, and if I want to
use column sorting like the wxDemo list control demo I appear to need
multiple inheritance of wxColumnSorterMixin as well.

Is there a neat way to "retrospectively" insert the mixin into the list
control after creation, or some other way around the problem?

Many thanks for any input.

···

--
Pythonologist

In article <diy7IGA4lcn$EwcC@octave.demon.co.uk>, Pythonologist
<pythonologist@octave.demon.co.uk> writes

Hi,

The wxList controls generated by XRCed are just that, and if I want to
use column sorting like the wxDemo list control demo I appear to need
multiple inheritance of wxColumnSorterMixin as well.

Is there a neat way to "retrospectively" insert the mixin into the list
control after creation, or some other way around the problem?

Many thanks for any input.

Actually, I found a solution as one can control the list from an
external class, viz;

···

########################################################################

class MyListSorter( wx.lib.mixins.listctrl.ColumnSorterMixin ) :
    def __init__( self, list, itemDataMap, sortImages ) :
        self.list = list
        self.itemDataMap = itemDataMap
        self.sortImages = sortImages
        wx.lib.mixins.listctrl.ColumnSorterMixin.__init__(
           self, self.list.GetColumnCount( ) )
        
    def GetListCtrl( self ) :
        return self.list

    def GetSortImages( self ) :
        return self.sortImages

########################################################################

However, I've now found another problem: the sorter zaps the alignment
of the column if it is anything other than the default (left aligned).
You can see this in the wxPython ListCtrl demo, where if you click the
music "Title" header, it makes it left aligned. This can't be correct
for numeric columns. So, how to reinstate alignment?

--
Pythonologist

Pythonologist wrote:

Hi,

The wxList controls generated by XRCed are just that, and if I want to
use column sorting like the wxDemo list control demo I appear to need
multiple inheritance of wxColumnSorterMixin as well.

Is there a neat way to "retrospectively" insert the mixin into the list
control after creation, or some other way around the problem?

Take a look at the XRC subclass example that I posted here last week. You can create a subclass of wxListCtrl and wxColumnSorterMixin and then refer to that class in the XRC with the subclass attribute of the object tag.

···

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

Pythonologist wrote:

In article <diy7IGA4lcn$EwcC@octave.demon.co.uk>, Pythonologist
<pythonologist@octave.demon.co.uk> writes

Hi,

The wxList controls generated by XRCed are just that, and if I want to
use column sorting like the wxDemo list control demo I appear to need
multiple inheritance of wxColumnSorterMixin as well.

Is there a neat way to "retrospectively" insert the mixin into the list
control after creation, or some other way around the problem?

Many thanks for any input.

Actually, I found a solution as one can control the list from an
external class, viz;

I knew there was a good reason why I did it that way... :slight_smile:

However, I've now found another problem: the sorter zaps the alignment
of the column if it is anything other than the default (left aligned).
You can see this in the wxPython ListCtrl demo, where if you click the
music "Title" header, it makes it left aligned. This can't be correct
for numeric columns. So, how to reinstate alignment?

What platform BTW?

Probably a bug, and it probably has to do with changing the column's image. wxColumnSorterMixin.__updateImages uses wxListCtrl.ClearColumnImage and SetColumnImage which look like this:

     def SetColumnImage(self, col, image):
         item = wxListItem()
         item.SetMask(wxLIST_MASK_IMAGE)
         item.SetImage(image)
         self.SetColumn(col, item)

     def ClearColumnImage(self, col):
         self.SetColumnImage(col, -1)

I would expect that to preserve the other column attributes, but apparently not. Can you experiment with this and see if you can come up with a workaround?

···

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

Robin,

I've had a dabble with the code fragment, adding the two lines marked #@
which I thought necessary:

        item = wxListItem()
        ok = self.GetColumn(col, item) #@
        assert ok #@
        item.SetMask(wxLIST_MASK_IMAGE)
        item.SetImage(image)
        self.SetColumn(col, item)

I've also tried this alternative to SetImage:
        item.m_mask |= wxLIST_MASK_IMAGE
        item.m_image = image

What happens with these options is that the RightAlignment is now
correctly preserved, as desired, but the images don't display !!!

Platform is Win2K, BTW.

Regards.

···

--
Pythonologist

Pythonologist wrote:

Robin,

I've had a dabble with the code fragment, adding the two lines marked #@
which I thought necessary:

        item = wxListItem()
        ok = self.GetColumn(col, item) #@
        assert ok #@
        item.SetMask(wxLIST_MASK_IMAGE)
        item.SetImage(image)
        self.SetColumn(col, item)

I've also tried this alternative to SetImage:
        item.m_mask |= wxLIST_MASK_IMAGE
        item.m_image = image

What happens with these options is that the RightAlignment is now
correctly preserved, as desired, but the images don't display !!!

Your attempt reminded me of something so I tried it out and it does work. Here is the fix:

     def SetColumnImage(self, col, image):
         item = self.GetColumn(col)
         # preserve all other attributes too
         item.SetMask( wxLIST_MASK_STATE |
                       wxLIST_MASK_TEXT |
                       wxLIST_MASK_IMAGE |
                       wxLIST_MASK_DATA |
                       wxLIST_SET_ITEM |
                       wxLIST_MASK_WIDTH |
                       wxLIST_MASK_FORMAT
                       )
         item.SetImage(image)
         self.SetColumn(col, item)

···

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

Robin,

I'm pleased to say the fix works fine - many thanks.

However, I ran into another unrelated problem in this area: when trying
to use the images.py file from the demo in my own application via:

sys.path.insert(0, "E:/software/python/Lib/site-packages/wxPython/demo")
import images
...
   test_sm_up = self.il.Add( images.getSmallUpArrowBitmap( ) )
...

then it blows up as follows:

  Traceback (most recent call last):
  File "mailgui.py", line 473, in OnMenuFileExit
    test_sm_up = self.il.Add( images.getSmallUpArrowBitmap( ) )
  File "E:\software\python\Lib\site-packages\wxPython\demo\images.py",
    line 3576, in getSmallUpArrowBitmap
    return wxBitmapFromImage(getSmallUpArrowImage())
  File "E:\software\python\lib\site-packages\wxPython\image.py",
    line 394, in wxBitmapFromImage
    val = imagec.wxBitmapFromImage(*_args,**_kwargs)
  wxPython.wxc.wxPyAssertionError: C++ assertion "wxAssertFailure"
    failed in e:\Projects\wx2.4\src\msw\bitmap.cpp(507): invalid image

I am able to get round this by using:

  bmp_up = wx.ArtProvider_GetBitmap( wx.ART_GO_UP, size = bmp_size )

which works OK, but obviously the range of images is less than in your
excellent collection.

Any input welcomed.

···

--
Pythonologist

Pythonologist wrote:

However, I ran into another unrelated problem in this area: when trying
to use the images.py file from the demo in my own application via:

sys.path.insert(0, "E:/software/python/Lib/site-packages/wxPython/demo")
import images
...
   test_sm_up = self.il.Add( images.getSmallUpArrowBitmap( ) )
...

then it blows up as follows:

  Traceback (most recent call last):
  File "mailgui.py", line 473, in OnMenuFileExit
    test_sm_up = self.il.Add( images.getSmallUpArrowBitmap( ) )
  File "E:\software\python\Lib\site-packages\wxPython\demo\images.py",
    line 3576, in getSmallUpArrowBitmap
    return wxBitmapFromImage(getSmallUpArrowImage())
  File "E:\software\python\lib\site-packages\wxPython\image.py",
    line 394, in wxBitmapFromImage
    val = imagec.wxBitmapFromImage(*_args,**_kwargs)
  wxPython.wxc.wxPyAssertionError: C++ assertion "wxAssertFailure"
    failed in e:\Projects\wx2.4\src\msw\bitmap.cpp(507): invalid image

Does your app call wxInitAllImageHandlers?

···

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