MindWrapper

I'm just starting on an app that will need to do the same thing. Is there a generic table-aware wxPyGridTableBase that you used that you are willing to make public?

How did you link it to the database tables?

It would save me a lot of hard work (and there are plenty of other areas in this app that need the hard work).

Chris.

···

----- Original Message -----
From: Frank Millman
To: wxPython-users@lists.wxwindows.org
Sent: Tuesday, April 01, 2003 4:53 AM
Subject: Re: [wxPython-users] Help wth wxPyGridTableBase

----- Original Message -----
From: "Mike C. Fletcher" <mcfletch@rogers.com>
To: <wxPython-users@lists.wxwindows.org>
Sent: Sunday, March 30, 2003 6:08 PM
Subject: Re: [wxPython-users] Help wth wxPyGridTableBase

See section:
    1.4.1 Cursor Manipulation
from http://wiki.wxpython.org/index.cgi/wxGrid .

Particularly:
    SetGridCursor, and MakeCellVisible

HTH,
Mike

Many thanks to Mike and to Chuck for the replies - SetGridCursor was the
answer. According to the docs, MakeCellVisible is called automatically by
SetGridCursor, so I left it out and it works fine without it.

I should have found it myself, but I was looking in the wxPyGridTableBase
class for a method, forgetting that all the methods in wxGrid are
available - twit.

The results are spectacular. I can scroll through a table of 20 000 rows,
and jump to any row I want to based on a search string, at blazing speed,
using both PostgreSQL and SQL Server. If I push it to 50 000 rows, searching
through the cursor slows down a bit, but in practice no-one will scroll
through such a big table without applying some filtering first, so I do not
think it will be a problem.

Thanks again, guys.

Frank Millman

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

That's interesting cuz I did the same thing and it didn't work for me
(wxPython 2402 at the time). So I put makeCellVisible() back in.

Just a note in case it stops working at some point.

···

On Monday 31 March 2003 11:23 am, Frank Millman wrote:

Many thanks to Mike and to Chuck for the replies - SetGridCursor was
the answer. According to the docs, MakeCellVisible is called
automatically by SetGridCursor, so I left it out and it works fine
without it.

--
Chuck
http://ChuckEsterbrook.com

I'm just starting on an app that will need to do the same thing. Is there a
generic table-aware wxPyGridTableBase that you used that you are willing to
make public?

How did you link it to the database tables?

It would save me a lot of hard work (and there are plenty of other areas in
this app that need the hard work).

Chris.

Hi Chris

I am quite happy to share the code that I have developed so far. It is still
a "work in progress", but it does work as is. If it helps someone, that will
be great. If anyone can recommend any improvements, that will be even better
:slight_smile:

I have attached the following files.

db_browse.py - this contains the generic classes to set up a database
cursor, to return the data for any particular row/column, and to take a
search string and return the row number that starts with that string. There
are separate classes for PostgreSQL and for SQL Server, as there is a big
difference in the syntax for moving around in a cursor.

grid_table.py - this is a test program that sets up a grid and then calls
the routines in db_browse.py

db_browse.txt - notes on some areas that you will probably need to tweak to
make it work in your environment.

Hope you find it useful.

Frank Millman

db_browse.py (6.62 KB)

grid_table.py (2.07 KB)

db_browse.txt (2.77 KB)

···

----- Original Message -----
From: "Chris Munchenberg" <cjm@ava.com.au>
To: <wxPython-users@lists.wxwindows.org>
Sent: Tuesday, April 01, 2003 1:11 AM
Subject: Re: [wxPython-users] Help wth wxPyGridTableBase

I have a panel with some text controls and a grid. When tabbing off the text
control just prior to the grid, focus is passed to the first cell of the
grid, but EVT_GRID_SELECT_CELL is not triggered.

Question 1 - is there any way to force this to happen?

Question 2 - if not, I have been experimenting with generating the event by
calling wxPostEvent() when tabbing off the previous text control.
Unfortunately I cannot get it to work. I can find plenty of examples of
creating your own custom event, and then using wxPostEvent to fire it, but I
cannot find an example of using it to generate a built-in event. Please can
someone point me in the right direction.

Thanks

Frank Millman

Frank Millman wrote:

I have a panel with some text controls and a grid. When tabbing off the text
control just prior to the grid, focus is passed to the first cell of the
grid, but EVT_GRID_SELECT_CELL is not triggered.

Because it is already the current cell.

Question 1 - is there any way to force this to happen?

No.

Question 2 - if not, I have been experimenting with generating the event by
calling wxPostEvent() when tabbing off the previous text control.
Unfortunately I cannot get it to work. I can find plenty of examples of
creating your own custom event, and then using wxPostEvent to fire it, but I
cannot find an example of using it to generate a built-in event. Please can
someone point me in the right direction.

Something like this:

evt = wxGridEvent(grid.GetId(), wxEVT_GRID_SELECT_CELL, grid, row=0, col=0)
grid.GetEventHandler().ProcessEvent(evt)

···

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

Frank Millman wrote:
> I have a panel with some text controls and a grid. When tabbing off the

text

> control just prior to the grid, focus is passed to the first cell of the
> grid, but EVT_GRID_SELECT_CELL is not triggered.

Because it is already the current cell.

I could debate the logic of this. If it is the current cell, it must have
been "selected" at some point. However, it is a minor issue which I can live
with, so I do not want to waste anyone's time over it.

Something like this:

evt = wxGridEvent(grid.GetId(), wxEVT_GRID_SELECT_CELL, grid, row=0,

col=0)

grid.GetEventHandler().ProcessEvent(evt)

This works perfectly. It also prompted me to read the docs on
GetEventHandler(), and I now have a clearer (though still imperfect)
understanding of events.

So a double thanks, Robin.Your assistance is outstanding, as always.

Frank Millman

···

----- Original Message -----
From: "Robin Dunn" <robin@alldunn.com>
To: <wxPython-users@lists.wxwindows.org>
Sent: Saturday, April 05, 2003 2:28 AM
Subject: Re: [wxPython-users] Grid cell 0,0 not selected

Hi Frank,

Sorry for the slow reply. This is a quick note of thanks for your files notes - it has helped a lot.

I'm going to ask another favour. You have Table & Column classes which you use. I'm still learning when it comes to databases, and would appreciate the chance to look at how you've done it. I find it often saves me groping around in the dark for hours trying to find perfectly obvious solutions to simple problems (at least, thats how it always looks in hindsight).

Thanks for your help - you've made it all look pretty simple.

Chris.

···

----- Original Message -----
From: Frank Millman
To: wxPython-users@lists.wxwindows.org
Sent: Wednesday, April 02, 2003 7:25 PM
Subject: Re: [wxPython-users] Help wth wxPyGridTableBase

----- Original Message -----
From: "Chris Munchenberg" <cjm@ava.com.au>
To: <wxPython-users@lists.wxwindows.org>
Sent: Tuesday, April 01, 2003 1:11 AM
Subject: Re: [wxPython-users] Help wth wxPyGridTableBase

I'm just starting on an app that will need to do the same thing. Is there a
generic table-aware wxPyGridTableBase that you used that you are willing to
make public?

How did you link it to the database tables?

It would save me a lot of hard work (and there are plenty of other areas in
this app that need the hard work).

Chris.

Hi Chris

I am quite happy to share the code that I have developed so far. It is still
a "work in progress", but it does work as is. If it helps someone, that will
be great. If anyone can recommend any improvements, that will be even better
:slight_smile:

I have attached the following files.

db_browse.py - this contains the generic classes to set up a database
cursor, to return the data for any particular row/column, and to take a
search string and return the row number that starts with that string. There
are separate classes for PostgreSQL and for SQL Server, as there is a big
difference in the syntax for moving around in a cursor.

grid_table.py - this is a test program that sets up a grid and then calls
the routines in db_browse.py

db_browse.txt - notes on some areas that you will probably need to tweak to
make it work in your environment.

Hope you find it useful.

Frank Millman

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

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

Hi Frank,

Sorry for the slow reply. This is a quick note of thanks for your files

notes - it has helped a lot.

I'm going to ask another favour. You have Table & Column classes which you

use. I'm still learning when it >comes to databases, and would appreciate
the chance to look at how you've done it. I find it often saves me >groping
around in the dark for hours trying to find perfectly obvious solutions to
simple problems (at least, >thats how it always looks in hindsight).

Thanks for your help - you've made it all look pretty simple.

Chris.

Hi Chris,

I'm glad you found it useful.

You are welcome to have a look at what I have developed so far. It is
designed to handle reading, editing, and updating of single records/rows in
a table. As the table is implemented as a class, you can have many instances
of it, so you can have many tables open at the same time, but each instance
can only handle a single row at a time.

Attached are table.py, containing the code, and table.txt, explaining the
methods and attributes of the table class.

Hope it works for youl.

Frank Millman

table.py (5.37 KB)

table.txt (1.63 KB)

···

----- Original Message -----
From: "Chris Munchenberg" <cjm@ava.com.au>
To: <wxPython-users@lists.wxwindows.org>
Sent: Monday, April 07, 2003 4:36 PM
Subject: Re: [wxPython-users] Help wth wxPyGridTableBase

Hi all,

I have a grid, inside a horizontal box sizer, inside a panel. I want to
adjust the width of the grid so that it fits neatly across the panel on
initial display. I do this by juggling the column widths.

If I make it too wide, a horizontal scroll bar appears. If I make it too
narrow, there is an ugly gap on the right hand side.

My problem is that, if I get it just right, so that all the columns are
visible, the horizontal scroll bar sometimes still appears. It is not
consistent. I can have a case where it does not appear. If I then increase a
single column width and the frame width by the same amount, it reappears.

Is there any way I can force the scroll bar to disappear? I have tried
AdjustScrollbars(), but this did not help.

Platforms are Windows 2000, Python 2.2.2, wxPython 2.4.0.2u, and Linux
(Redhat 8), Python 2.2.2, wxPython 2.4.0.2.

Thanks

Frank Millman

Frank Millman wrote:

Hi all,

I have a grid, inside a horizontal box sizer, inside a panel. I want to
adjust the width of the grid so that it fits neatly across the panel on
initial display. I do this by juggling the column widths.

If I make it too wide, a horizontal scroll bar appears. If I make it too
narrow, there is an ugly gap on the right hand side.

My problem is that, if I get it just right, so that all the columns are
visible, the horizontal scroll bar sometimes still appears. It is not
consistent. I can have a case where it does not appear. If I then increase a
single column width and the frame width by the same amount, it reappears.

Is there any way I can force the scroll bar to disappear? I have tried
AdjustScrollbars(), but this did not help.

You could try setting the virtual size to be the same as the client size, but I don't know if that will screw anything up in the grid code...

···

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

Hi all,

I have a grid, inside a horizontal box sizer, inside a panel. I want to
adjust the width of the grid so that it fits neatly across the panel on
initial display. I do this by juggling the column widths.

If I make it too wide, a horizontal scroll bar appears. If I make it too
narrow, there is an ugly gap on the right hand side.

My problem is that, if I get it just right, so that all the columns are
visible, the horizontal scroll bar sometimes still appears. It is not
consistent. I can have a case where it does not appear. If I then
increase a
single column width and the frame width by the same amount, it
reappears.

Is there any way I can force the scroll bar to disappear? I have tried
AdjustScrollbars(), but this did not help.

Platforms are Windows 2000, Python 2.2.2, wxPython 2.4.0.2u, and Linux
(Redhat 8), Python 2.2.2, wxPython 2.4.0.2.

Thanks

Frank Millman

I recall a similar problem when I was developing a Mixin to expand the
last grid column to just fill the available width as sized. There is
something deep in the wxWindows C++ code that jumps in increments of,
ISTR, 15 pixels. So when the available width is divided by 15, if the
remainder is 1-7 you get the scrollbar and when 0 or 8+ you get the gap -
or the other way round :�) I fudged the calculation inside my app so I at
least got the right hand gap consistently. Not ideal but it's on my list
of non-urgent things to revisit.

        winwidth = self.GetSize().width
        rem = winwidth % 15 # Fiddle factors
        if rem == 0 or rem > 8: #
            self.SetMargins(7,0) #
        else: #
            self.SetMargins(0,0) #

Regards,

David Hughes
Forestfield Software Ltd
www.forestfield.co.uk

Frank Millman wrote:
> My problem is that, if I get it just right, so that all the columns are
> visible, the horizontal scroll bar sometimes still appears. It is not
> consistent. I can have a case where it does not appear. If I then

increase a

> single column width and the frame width by the same amount, it

reappears.

You could try setting the virtual size to be the same as the client

size, but I don't know if that will screw anything up in the grid code...

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

Thanks for the suggestion, Robin. I tried it, but it does not make any
difference. Don't worry, I can live with it for now.

I also read Chuck's reply. Thanks for the FYI, Chuck, it is always nice to
know that someone else has the same problem, otherwise I worry that I am
just making a silly mistake somewhere.

Frank Millman

···

----- Original Message -----
From: "Robin Dunn" <robin@alldunn.com>
To: <wxPython-users@lists.wxwindows.org>
Sent: Wednesday, April 09, 2003 6:30 PM
Subject: Re: [wxPython-users] Problem with scrollbar

>
> My problem is that, if I get it just right, so that all the columns are
> visible, the horizontal scroll bar sometimes still appears It is not

consistent.

I recall a similar problem when I was developing a Mixin to expand the
last grid column to just fill the available width as sized. There is
something deep in the wxWindows C++ code that jumps in increments of,
ISTR, 15 pixels. So when the available width is divided by 15, if the
remainder is 1-7 you get the scrollbar and when 0 or 8+ you get the gap -
or the other way round :,) I fudged the calculation inside my app so I at
least got the right hand gap consistently. Not ideal but it's on my list
of non-urgent things to revisit.

        winwidth = self.GetSize().width
        rem = winwidth % 15 # Fiddle factors
        if rem == 0 or rem > 8: #
            self.SetMargins(7,0) #
        else: #
            self.SetMargins(0,0) #

Regards,

David Hughes
Forestfield Software Ltd
www.forestfield.co.uk

Thanks, David, this helped a lot. It encouraged me to do what I should have
done in the first place. The results may appear to be inconsistent, but they
cannot be random, so it must be possible to figure out, as you did, the
precise conditions under which the scroll bar appears or disappears. The
results are interesting.

My scenario is slightly different from yours. I build a grid, place it
inside a StaticBoxSizer, which I then place inside a vertical BoxSizer with
wxEXPAND and a left and right border of 5. The whole thing is linked to a
panel which is attached to a frame. I then calculate the width of the grid,
and set the Frame width to the same value. I found by trial and error that
summing the individual column widths and adding 38 for the vertical scroll
bar, left and right borders, etc, gives the correct width on both Linux and
Windows.

The question is when does the scroll bar appear and when does it disappear.
This is what I found out. This is a specific case. I have not yet created a
general rule out of it, but it should not be difficult to do so.

If the Frame width is 442, there is no scroll bar in Windows or in Linux,
which is the desired situation. If I increase it to 443, it appears on both
platforms. From that point on, the behaviour differs.

With Windows, the scroll bar appears for values from 443-448, then it
disappears for values from 449-457, then it reappears for values 458-463.
This follows more or less the pattern that you reported, though it moves in
cycles of 6 and 9 rather than 7 and 8.

With Linux, the scroll bar appears for values from 443-471, disappears for
472, appears for 473-501, and disappears for 502. In other words, it moves
in a cycle of 30, and only disappears if it matches a precise value.

To make it cross-platform, I will just cater for the Linux behaviour.
Whatever the width, I will round it up to the nearest multiple of 30 + x,
adjust one of the column widths by the same amount, and it should always
work.

Thanks again, David, this has solved an annoying problem for me.

Frank Millman

···

----- Original Message -----
From: "David Hughes" <dfh@forestfield.co.uk>
To: <wxpython-users@lists.wxwindows.org>
Sent: Thursday, April 10, 2003 7:23 PM
Subject: Re: [wxPython-users] Problem with scrollbar