[wxPython] Help on wxGrid needed :(

Hi,
writing gui apps with wxPython is really a lot of fun, but I've got a problem with
the new wxGrid, which is a wonderfull piece of art, but hell to use without a doc :(.

I have to write an Business application. One part of it enables the user to enter
the articles a customer orderes, that is title, price, number, discount ... . I want
to use wxGrid for that. My problem is I have to change the keymapping somewhat. That is
on ENTER the focus should go to the cell right of the current one. But if it is already
in the last cell (I mean in cell on the very right (the number of columns is fixed)),
the leftmost cell of the row below should become focus.
  Is that possible ?
  If it is, how ?
  What calls do I have to do, which events do I have to handle ... ?

Here a little sketch of the grid:

Focus is were the X is
+-Title------------+-Price-+-Number-+-Disc.-+

···

Line 1 | | X | |

+------------------+----------------+-------+

After the user hit ENTER:
+-Title------------+-Price-+-Number-+-Disc.-+
> Line 1 | | | X |
+------------------+-------+--------+-------+

One more time and it should look like this:
+-Title------------+-Price-+-Number-+-Disc.-+
> Line 1 | | | |
+------------------+-------+--------+-------+
> Line 2 X | | | |
+------------------+-------+--------+-------+

Ok, I think you got the idea.

Happy python

Hi,
writing gui apps with wxPython is really a lot of fun, but I've got a

problem with

the new wxGrid, which is a wonderfull piece of art, but hell to use

without a doc :(.

It is supposedly being written right now, but I havn't seen them yet.

I have to write an Business application. One part of it enables the user

to enter

the articles a customer orderes, that is title, price, number, discount

... . I want

to use wxGrid for that. My problem is I have to change the keymapping

somewhat. That is

on ENTER the focus should go to the cell right of the current one. But if

it is already

in the last cell (I mean in cell on the very right (the number of columns

is fixed)),

the leftmost cell of the row below should become focus.
Is that possible ?

It is probably doable in C++, but I'm not sure if there is enough exposed to
Python to be able to do it. One possible trouble is that there are actually
5 windows involved, so focus might be an issue. Let me think about it for a
bit to see what I can come up with.

···

--
Robin Dunn
Software Craftsman
robin@AllDunn.com
http://wxpython.org Java give you jitters?
http://wxpros.com Relax with wxPython!

Thanks, in advance and my compliment on your work on wxPython it is really cool :slight_smile:

···

On Wed, May 17, 2000 at 11:41:40AM -0700, Robin Dunn wrote:

> Hi,
> writing gui apps with wxPython is really a lot of fun, but I've got a
problem with
> the new wxGrid, which is a wonderfull piece of art, but hell to use
without a doc :(.

It is supposedly being written right now, but I havn't seen them yet.

>
> I have to write an Business application. One part of it enables the user
to enter
> the articles a customer orderes, that is title, price, number, discount
... . I want
> to use wxGrid for that. My problem is I have to change the keymapping
somewhat. That is
> on ENTER the focus should go to the cell right of the current one. But if
it is already
> in the last cell (I mean in cell on the very right (the number of columns
is fixed)),
> the leftmost cell of the row below should become focus.
> Is that possible ?

It is probably doable in C++, but I'm not sure if there is enough exposed to
Python to be able to do it. One possible trouble is that there are actually
5 windows involved, so focus might be an issue. Let me think about it for a
bit to see what I can come up with.

>
> It is probably doable in C++, but I'm not sure if there is enough

exposed to

> Python to be able to do it. One possible trouble is that there are

actually

> 5 windows involved, so focus might be an issue. Let me think about it

for a

> bit to see what I can come up with.
>

Thanks, in advance and my compliment on your work on wxPython it is really

cool :slight_smile:

It was easier than I thought. Here it is:

class NewEnterHandlingGrid(wxGrid):
    def __init__(self, parent, log):
        wxGrid.__init__(self, parent, -1)
        self.log = log

        self.CreateGrid(20, 6)

        self.SetCellValue(0, 0, "Enter moves to the right")
        self.SetCellValue(0, 5, "Enter wraps to next row")
        self.SetColSize(0, 150)
        self.SetColSize(5, 150)

        EVT_KEY_DOWN(self, self.OnKeyDown)

    def OnKeyDown(self, evt):
        if evt.KeyCode() != WXK_RETURN:
            evt.Skip()
            return

        if evt.ControlDown(): # the edit control needs this key
            evt.Skip()
            return

        success = self.MoveCursorRight(evt.ShiftDown())
        if not success:
            newRow = self.GetGridCursorRow() + 1
            if newRow < self.GetTable().GetNumberRows():
                self.SetGridCursor(newRow, 0)
                self.MakeCellVisible(newRow, 0)
            else:
                # this would be a good place to add a new row if your app
                # needs to do that
                pass

···

--
Robin Dunn
Software Craftsman
robin@AllDunn.com
http://wxpython.org Java give you jitters?
http://wxpros.com Relax with wxPython!