Grid SetCellAlignment on Boolean formated columns

I've got a wx.grid.Grid subclass that has one text column and a number of
boolean columns that display as checkmarks. On each of the boolean cells I
call mygrid.SetCellAlignment(row,column,wx.ALIGN_CENTER,wx.ALIGN_CENTER).
I'm finding the last cell of the last column is left aligned until the
grid is refreshed or the cell interacted with. Selecting the cell makes it
jump to the correct alignment. I've tried calling Refresh() and Update()
on the grid but that doesn't make the cell update it's alignment.

This happens on Windows 2000 and Solaris, under python 2.3 and 2.4 with
wxPython 2.5.3.1 and 2.5.4.1.

I've attached a sample program that demonstrates the problem.

Any clues on how to force the cell into alignment?

Thanks,

james evans

gridalign.py (1.44 KB)

Hello James,

I've got a wx.grid.Grid subclass that has one text column and a number

of

boolean columns that display as checkmarks. On each of the boolean cells
I
call mygrid.SetCellAlignment(row,column,wx.ALIGN_CENTER,wx.ALIGN_CENTER).
I'm finding the last cell of the last column is left aligned until the
grid is refreshed or the cell interacted with. Selecting the cell makes

it

jump to the correct alignment. I've tried calling Refresh() and Update()
on the grid but that doesn't make the cell update it's alignment.

This happens on Windows 2000 and Solaris, under python 2.3 and 2.4 with
wxPython 2.5.3.1 and 2.5.4.1.

Try to swap the lines in this way:

self.SetColSize(0,100)
self.SetColLabelValue(0,'Text Column')
self.SetColLabelValue(1,'Bool 1')
self.SetColFormatBool(1)
self.SetCellValue(0,0,'Row 1')
self.SetCellAlignment(0,1,wx.ALIGN_CENTER,wx.ALIGN_CENTER)
self.SetCellValue(0,1,'0')
self.SetCellValue(1,0,'Row 2')
self.SetCellAlignment(1,1,wx.ALIGN_CENTER,wx.ALIGN_CENTER)
self.SetCellValue(1,1,'0')
self.SetCellValue(2,0,'Row 3')
self.SetCellAlignment(2,1,wx.ALIGN_CENTER,wx.ALIGN_CENTER)
self.SetCellValue(2,1,'0')
self.ForceRefresh()

In other words, set the alignment BEFORE setting the value...

It works here for wxPython 2.5.4.1, Python 2.3.4 and WinXP.

HTH,
Andrea.

James Evans wrote:

I've got a wx.grid.Grid subclass that has one text column and a number of
boolean columns that display as checkmarks. On each of the boolean cells I
call mygrid.SetCellAlignment(row,column,wx.ALIGN_CENTER,wx.ALIGN_CENTER).
I'm finding the last cell of the last column is left aligned until the
grid is refreshed or the cell interacted with. Selecting the cell makes it
jump to the correct alignment. I've tried calling Refresh() and Update()
on the grid but that doesn't make the cell update it's alignment.

This happens on Windows 2000 and Solaris, under python 2.3 and 2.4 with
wxPython 2.5.3.1 and 2.5.4.1.

        self.SetCellValue(0,0,'Row 1')
        self.SetCellValue(0,1,'0')
        self.SetCellAlignment(0,1,wx.ALIGN_CENTER,wx.ALIGN_CENTER)
        self.SetCellValue(1,0,'Row 2')
        self.SetCellValue(1,1,'0')
        self.SetCellAlignment(1,1,wx.ALIGN_CENTER,wx.ALIGN_CENTER)
        self.SetCellValue(2,0,'Row 3')
        self.SetCellValue(2,1,'0')
        self.SetCellAlignment(2,1,wx.ALIGN_CENTER,wx.ALIGN_CENTER)
        self.Refresh()
        self.Update()

Since at this point in time the frame hasn't been shown yet, telling the window to update itself does no good. (The refresh is optimized out of existance.) So if you tell it to refresh it self "soon" instead of "right now" then you'll probably see what you expect.

         wx.CallAfter(self.Refresh)

ยทยทยท

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

Robin Dunn said:

Since at this point in time the frame hasn't been shown yet, telling the
window to update itself does no good. (The refresh is optimized out of
existance.) So if you tell it to refresh it self "soon" instead of
"right now" then you'll probably see what you expect.

         wx.CallAfter(self.Refresh)

The fact the frame hadn't been shown yet is an artifact of the test
program. In the real program the grid is populated in response to user
actions. Even in the test program using CallAfter didn't fix the problem.

The suggestion from Andrea of setting the alignment before the value did
fix (or at least hide) the problem. Thanks!

I'd think that the display should be the same no matter what order you set
the value and the alignment however.

Thanks again,

james