Newbie grid question - keys not working

Please look at this grid:

http://mess.hu/download/python/grid_selectcell.png

The grid was created with self.grid.wxGridSelectRows. The selected row is 6 ("FloatFieldType"). The grid has its own renderer. The black border is around the topleft cell, which is the active cell. If I use the arrow keys, the active cell won't change. When I try to click on a cell with mouse (row 6, in this example), EVT_GRID_CELL_CHANGE event handler gets called. The cell is drawn as selected, because my renderer was called with isSelected=True, this is why it has blue background. But, the active cell won't change (black border is still around the topleft cell) and wx.Grid.GetSelectedRows() returns an empty list. (GetSelectedCells is empty too).

It is very strange because the in wxPython demo, there is a custom grid cell renderer example; and the arrow keys are working there (and if you select a cell with your mouse in that example, it becomes the active cell.) I created my grid from that example and I'm not sure what am I doing wrong. I expected that in row select mode, clicking on a cell will select the whole row. I would also like to move the active cell (row) with arrow keys. Can you please help?

   Les

I still cannot move the active cell with arrow keys. I attached an example. In the dialog, you can move the active cell with arrow keys, on the other frame you can't. Sometimes, it is the other way (works on a frame but does not work in a dialog). Is this a wxPython bug?

(Windows XP, Python 2.4.1, wxPython 2.6.0)

Thanks,

   Les

test.py (903 Bytes)

Hello László,

I saw (on Windows):
If you destroy the dialog, the frame has the focus,
but the cursor keys don't move the active (selected) cell.

If I switch to another app and then back to this sample,
the cursor keys work.

The same applies, if you click once with the mouse
into any cell (then the cursor keys work).

class FrameMain(wx.Frame):
   def __init__(self, *args,**kwargs):
       wx.Frame.__init__(self, *args,**kwargs)
       addgrid(self)
       dlg = DialogMain(self,-1,title="Dialog")
       dlg.ShowModal()

if you add here:
        self.grid.SetFocus()

then it seems to work.

Not sure, if this is a bug.

One should presume, if the frame gets the focus,
the cursor keys should work at once.

···

On Mon, 26 Sep 2005 10:05:34 +0200, László Nagy <nagylzs@freemail.hu> wrote:

--
Franz Steinhaeusler

if you add here:
       self.grid.SetFocus()

then it seems to work.

Not sure, if this is a bug.

One should presume, if the frame gets the focus,
the cursor keys should work at once.

Or at least, I would presume that if I click into the grid (or anything else), it should get the focus.
Thank you, it is working now!

  Les

I don't entirely understand the issue. But!

Dialogs have a built-in panel, frames do not.

Panels are responsible for managing navigation.

Since the frame does not have a panel enclosing the grid, I expect this sort of issue will arise.

This *may* resolve the issue.

class FrameMain(wx.Frame):
     def __init__(self, *args,**kwargs):
         wx.Frame.__init__(self, *args,**kwargs)
  p = wx.Panel(self, -1)
         addgrid(p)
         dlg = DialogMain(self,-1,title="Dialog")
         dlg.ShowModal()

-Joe

László Nagy wrote:

···

I still cannot move the active cell with arrow keys. I attached an example. In the dialog, you can move the active cell with arrow keys, on the other frame you can't. Sometimes, it is the other way (works on a frame but does not work in a dialog). Is this a wxPython bug?

(Windows XP, Python 2.4.1, wxPython 2.6.0)

Thanks,

  Les

------------------------------------------------------------------------

import wx
import wx.grid

def addgrid(self):
    sizer = wx.BoxSizer(wx.HORIZONTAL) self.SetSizer(sizer)
    self.grid = wx.grid.Grid(self,-1)
    self.grid.CreateGrid(10,1) for index in range(10):
        self.grid.SetCellValue(index,0,str(index))
    self.grid.SetColLabelValue(0,"Values")
    self.grid.AutoSizeRows(True)
    self.grid.AutoSizeColumns(True) sizer.Add(self.grid,flag=wx.EXPAND,proportion=1)

class DialogMain(wx.Dialog):
    def __init__(self,*args,**kwargs):
        wx.Dialog.__init__(self, *args,**kwargs)
        addgrid(self)
        
class FrameMain(wx.Frame):
    def __init__(self, *args,**kwargs):
        wx.Frame.__init__(self, *args,**kwargs)
        addgrid(self)
        dlg = DialogMain(self,-1,title="Dialog")
        dlg.ShowModal()
        
app = wx.PySimpleApp()
frame = FrameMain(None, -1, "Frame")
frame.Show(True)
app.MainLoop()

------------------------------------------------------------------------

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org