Help with wxGrid

Hello,

I want to put a table on my application. I think that wxGrid is probably the right widget, but I can't get it to work. Based on the wxWidgets C++ documentation I tried doing this:

myTable = wx.Grid(panel, wx.ID_ANY)

Sadly, this failed miserably:

AttributeError: 'module' object has no attribute 'Grid'

So I went to Google and did a search for "grid wxPython" (since lord knows that you can't find anything by browsing the wiki) and I found this page:

http://wiki.wxpython.org/wxGrid%20Manual

This page claims to be a manual, but it isn't. A manual should explain how to use a widget and show code examples. But after reading this page I haven't the faintest clue which of the classes I'm supposed to use to make a table on my application (wxGrid, wxPyGridTableBase, etc).

At best, this page could be called an "API reference" for people who already know which widget they need.

Yes, I did try clicking on "wxGrid", but the resulting page was not any more illuminating. The page has many words, but I have no idea what it is trying to tell me. I think it's some kind of reference for internal developers. Certainly nothing that tells me how to use wxGrid, or whether I'm supposed to be using it at all.

Hoping for a miracle, I went to the "wxPyGridTableBase" page, but again, nothing of use. Many words yes, but I have no idea what it says, and it doesn't tell me whether wxPyGridTableBase is what I want to use in order to add a table to my application, or how to use it.

All very sad. :frowning:

You'd think these things would be documented somewhere, wouldn't you? I mean, wxWidgets and wxPython have been around for a long time, they are well established projects, they certainly have big documentation with many pages. You would think that there would be room somewhere in there to add an organized manual so that someone can come in and say "I want to add a table to my applicaton", or "I want a picture here" or whatever and they can find that in the manual.

I always wondered why wxWidgets and wxPython were not used more widely. A cross-platform toolkit, mature, native widgets, liberal license... what more could a developer want? Well, I guess I'm now getting a sense of why there aren't as many apps written in wx as in Gtk or Qt.

... Yeah, I'm in a bit of a down mood right now.

Daniel.

myTable = wx.Grid(panel, wx.ID_ANY)

Sadly, this failed miserably:

AttributeError: 'module' object has no attribute 'Grid'

This is because in wxPython, the Grid class lives in a subdirectory,
wx.grid. So you have to get to the Grid by a line like this:

grid = wx.grid.Grid(parent)

This idea of some things living not directly in wx, but in
wx.subfolder (where subfolder can = lib, grid, agw, or some other
things I think), is a good thing to know in using wxPython. So it is
a good idea to check to see if a widget is being imported from a
subfolder when you look at sample *wxPython* code (not C++ code, which
may be different?). So if you go to the wxPython demo, for the
simplest grid example, they have
this line:

import wx.grid as gridlib

(that's just I guess a convenience to pack it into one name)

Then they use that when they construct their grid subclass:

gridlib.Grid.__init__(self,parent,-1)

You will see in code examples that one has to call .CreateGrid() on
the grid, too.

Here is an online example of wx.grid.Grid I found by Googling:

There's also a wxPython in Action book, which does discuss the grid
control (and lots else).

The wxPython demo is also invaluable for code examples. Do you have/use that?

Hello,

C M wrote:

AttributeError: 'module' object has no attribute 'Grid'

This is because in wxPython, the Grid class lives in a subdirectory,
wx.grid. So you have to get to the Grid by a line like this:

grid = wx.grid.Grid(parent)

With the "import wx.grid" from further down your email, this line works now. Thanks. More comments below...

This idea of some things living not directly in wx, but in
wx.subfolder (where subfolder can = lib, grid, agw, or some other
things I think), is a good thing to know in using wxPython.

Indeed, thanks.

So it is
a good idea to check to see if a widget is being imported from a
subfolder when you look at sample *wxPython* code (not C++ code, which
may be different?). So if you go to the wxPython demo, for the
simplest grid example, they have
this line:

Wait... where do I find the demos?

I go to wiki.wxpython.org and do a search for "Demo". I find two links. One goes to a dead page, the other goes to a page that talks about how to copy code from "the wxPython Demo". It doesn't say where "the wxPython Demo" is, but even if it did, it doesn't sound useful to have only one demo (what are the chances that this one demo would have a wxGrid in it?).

Failing at documentation, I would really like to see a demo of wxGrid. Otherwise I'm going to be posting a lot of RTFM questions here. I don't like posting RTFM questions, but I do need to know where the FM is...

There's also a wxPython in Action book, which does discuss the grid
control (and lots else).

You have to buy it though, right? Right now I'm just dabbling into wxPython. I don't think I'd buy a book before I know that I actually want to use wxPython.

The wxPython demo is also invaluable for code examples. Do you have/use that?

No, where is it? I just saw it mentioned on the website and it sounded to me like it was *one* code example, so it didn't sound very useful. Where can I find it?

Daniel.

Would I be correct in assuming you’re doing this as a hobby? Many of the questions you’re asking could easily have been answered by reading the book, in much less time than it took to post here, wait for replies, and attempt to decipher random webpages. $40 is not a lot to spend for something that can save you many hours of confusion, and not an unreasonable price for the manual of an otherwise free product. I rarely resort to programming books myself, but for GUI toolkits, my time is far too valuable to spend days trying to figure anything out blindly, and my boss would certainly prefer to spend $40 for a quick answer. And even if I were writing code as a hobby (god forbid), I would still consider the book a much more efficient use of time and money.

You can obtain the demo on the same page as the rest of wxPython:

http://www.wxpython.org/download.php#binaries

It contains examples for nearly every class in the API.

···

On Thu, Jan 14, 2010 at 11:24 AM, Daniel Carrera dcarrera@gmail.com wrote:

There’s also a wxPython in Action book, which does discuss the grid

control (and lots else).

You have to buy it though, right? Right now I’m just dabbling into wxPython. I don’t think I’d buy a book before I know that I actually want to use wxPython.

Daniel Carrera wrote:

Hello,

C M wrote:

AttributeError: 'module' object has no attribute 'Grid'

This is because in wxPython, the Grid class lives in a subdirectory,
wx.grid. So you have to get to the Grid by a line like this:

grid = wx.grid.Grid(parent)

With the "import wx.grid" from further down your email, this line works now. Thanks. More comments below...

This idea of some things living not directly in wx, but in
wx.subfolder (where subfolder can = lib, grid, agw, or some other
things I think), is a good thing to know in using wxPython.

Indeed, thanks.

So it is
a good idea to check to see if a widget is being imported from a
subfolder when you look at sample *wxPython* code (not C++ code, which
may be different?). So if you go to the wxPython demo, for the
simplest grid example, they have
this line:

Wait... where do I find the demos?

I go to wiki.wxpython.org and do a search for "Demo". I find two links. One goes to a dead page, the other goes to a page that talks about how to copy code from "the wxPython Demo". It doesn't say where "the wxPython Demo" is, but even if it did, it doesn't sound useful to have only one demo (what are the chances that this one demo would have a wxGrid in it?).

Failing at documentation, I would really like to see a demo of wxGrid. Otherwise I'm going to be posting a lot of RTFM questions here. I don't like posting RTFM questions, but I do need to know where the FM is...

There's also a wxPython in Action book, which does discuss the grid
control (and lots else).

You have to buy it though, right? Right now I'm just dabbling into wxPython. I don't think I'd buy a book before I know that I actually want to use wxPython.

The wxPython demo is also invaluable for code examples. Do you have/use that?

No, where is it? I just saw it mentioned on the website and it sounded to me like it was *one* code example, so it didn't sound very useful. Where can I find it?

Daniel.

Sir,

I started using Python and wxPython about 1.5 years ago with almost NO programming background. I got the book "wxPython in action", yes that costs about the price of the monthly fee for a decent internet connection), installed wxPython and the invaluable demos that come with (to be found just nearby the wxPython install package in wxpython.org) and after a few weeks, I was able to get a pretty nice GUI with some a grid in it. Also, I found the wxpython-users group very responsive and helpful for more complex things.

One of my collegues, who has more than 20 years experience in programming and is a C++ expert just started with wxPython a few weeks ago for a side project: he got my "wxPython in action" book (so, that was free for him), spent a few hours on it and the demos, and is now enjoying the simplicity and power of it.

I have trouble to understand why you are getting so nervous with the documentation. May be you should just start at the right entrance.

By the way, wxPython is an Open Source project ...

Raphael

Nathaniel Echols wrote:

Would I be correct in assuming you're doing this as a hobby?

That would be correct. There is some chance I could use wxPython for real work in the future, but it's only a chance. First I have to decide that I actually like it.

Many of the questions you're asking could easily have been answered by reading the book, in much less time than it took to post here, wait for replies, and attempt to decipher random webpages.

On the other hand:

1. Waiting for the book to arrive would take a lot longer.

2. How do I know that the book is any good? My best estimate for the quality of the book is the quality of the website.

3. I strongly prefer to use tools with good on-line docs, even if I do buy a book later. For example, I've bought several books on Perl, even though Perl has great online docs and man pages.

4. I generally expect a "mature" product to have reasonably good docs. I'm sure we can list several FOSS tools with good docs.

$40 is not a lot to spend for something that can save you many hours of confusion, and not an unreasonable price for the manual of an otherwise free product.

After I liked Perl, I was willing to buy several books on Perl. If I get to like wxPython, I will be glad to buy the book.

and my boss would certainly prefer to spend $40 for a quick answer.

If this was for work I'd ask my boss to buy the book. If the book is crap... heck, it's not my money, right?

You can obtain the demo on the same page as the rest of wxPython:

Redirecting...

It contains examples for nearly every class in the API.

Thanks. I would strongly recommend making valuable resources visible from the wxPython wiki. I got my wxPython with apt-get.

Daniel.

You can obtain the demo on the same page as the rest of wxPython:

Redirecting...

It contains examples for nearly every class in the API.

Thanks. I would strongly recommend making valuable resources visible
from the wxPython wiki.

   How to Learn wxPython - wxPyWiki

I got my wxPython with apt-get.

You can get the demo that way too.

   sudo apt-get install wx2.8-examples

Although most prefer to get the demo tarball from the website because installing it from the package puts it in a system folder and it is not writable by ordinary users. Being able to fiddle with the demo code is a great way to learn. The demo itself allows you to make modifications to the samples in a way that does not require write-access, but sometimes it's better to edit and run the samples standalone.

···

On 1/14/10 11:53 AM, Daniel Carrera wrote:

--
Robin Dunn
Software Craftsman

Hi Raphael,

I started using Python and wxPython about 1.5 years ago with almost NO programming background.

Ok. I have a fair bit of programming background, though I'm no expert.

and after a few weeks, I was able to get a pretty nice GUI with some a grid in it.

I hope it doesn't take me a few weeks. :frowning:

Also, I found the wxpython-users group very responsive and helpful for more complex things.

Yes, they are very responsive and helpful. You couldn't ask for a better group of people.

One of my collegues, who has more than 20 years experience in programming and is a C++ expert just started with wxPython a few weeks ago for a side project: he got my "wxPython in action" book (so, that was free for him), spent a few hours on it and the demos, and is now enjoying the simplicity and power of it.

I am very glad that your colleague is enjoying wxPython.

I have trouble to understand why you are getting so nervous with the documentation. May be you should just start at the right entrance.

I wouldn't use the word "nervous", but dissatisfied, yes. Perhaps I have a higher standard for good writing than some people. But yet, I don't feel that a well organized on-line manual is too much to ask.

By the way, wxPython is an Open Source project ...

Yes, indeed. I wouldn't use anything else. But I don't think that open source projects *have* to have poor documentation. I used to work with OpenOffice.org. I started and ran the user guide project and we managed to make an excellent manual for OOo. Off the top of my head, I can say that Perl and Gtk are also well documented. So clearly it is possible. I don't expect brand-new projects to have great documentation, but I had it in my mind that wxWidgets and wxPython were well-established projects with a lot of time to write good docs.

Anyways, I do want to thank the helpful people who have tried to answer all my questions. I hope you will not see my complaints about the wiki as a personal complaint against you, or against the software.

Cheers,
Daniel.

Robin Dunn wrote:

Thanks. I would strongly recommend making valuable resources visible
from the wxPython wiki.

  How to Learn wxPython - wxPyWiki

Yes, indeed. That page does mention the demos and I did see that page. In fact, that's the first page I saw after I visited wxpython.org.

I cannot tell you why my brain ignored that link. Maybe I got stuck in the "Learn wxPython" section. I think that in my mind I was thinking, "I want to learn wxPython, right? So what I need must be in this section".

I took the liberty of updating this page in an attempt to avoid confusing for the next person who wants to learn wxPython. I hope that's alright.

Although most prefer to get the demo tarball from the website because installing it from the package puts it in a system folder and it is not writable by ordinary users. Being able to fiddle with the demo code is a great way to learn. The demo itself allows you to make modifications to the samples in a way that does not require write-access, but sometimes it's better to edit and run the samples standalone.

Thanks.

Daniel.

Daniel Carrera wrote:

You can obtain the demo on the same page as the rest of wxPython:

Redirecting...

Thanks. I would strongly recommend making valuable resources visible from the wxPython wiki.

It's wiki -- contributions accepted.

I got my wxPython with apt-get.

is there a wxpython-demos package or the like? if not, I'd see about contributing that to debian (or ubuntu, or...)

But while you are being critical:

http://wiki.wxpython.org/How%20to%20Learn%20wxPython#The_Comprehensive_Demo_Files

Seems to be exactly what you wanted to have "visible from the wxPython wiki". That is on the "How to learn wxPython" page, which is the second link under "Learning wxPython", on the main Wiki page.

Feel free to ask lots of questions here, this is a particularly helpful and friendly group, but please don't be so critical, particularly after not doing much RTFM-ing.

Note that I took a quick look at the the wxGrid pages in the Wiki -- they look really comprehensive, but also were written in 2004 (or even 2002?), and the wxPython API has been updated some since then. So, yes, it could be a bit confusing, and could use an update. What a nice way to contribute!

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Daniel Carrera wrote:

I took the liberty of updating this page in an attempt to avoid confusing for the next person who wants to learn wxPython. I hope that's alright.

More than alright -- that's exactly how we're going to get better docs.

Thanks,

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

and after a few weeks, I was able to get a pretty nice GUI with some a
grid in it.

I hope it doesn't take me a few weeks. :frowning:

I guess that depends a lot on what "pretty nice" means. A simple
"Hello, World!" GUI tutorial can have you running a GUI app in five
minutes; a more extensive one might be an afternoon, then something
better might be a few weeks. A somewhat useful Python/wxPython app
might see numbers changing in the year's place in the calendar! (This
is my personal saga :smiley: )

Maybe I'm off here, but I feel somehow if you try to get the
information "right now" in a sort of feverish way, it has trouble
happening. That reminds me of this favorite zen story:
http://deoxy.org/koan/91

This said, I thought of another possible helper, one that helped me:
Boa Constructor or other GUI builders. Some feel that these are
actually worse for learning, because they do the work for you, but I
felt that Boa was really helpful for me because it would write the GUI
code for a given widget and then I could see what it did. (Note:
You've said you're using Linux, and although Boa does run on Linux, I
have had some unfortunate problems with it, so if you would like to
try it, I will try to walk you through a few little workarounds that
make using it a little suboptimal but still probably a great learning
aid.) If you want to see a bit about Boa in a video, this is a
screencast tutorial series for it:
http://www.showmedo.com/videotutorials/series?name=wKQrywla5

In fact, ShowMeDo has a number of good wxPython (and Python)
screencasts--they are heavily Pythoncentric. So maybe check them out
generally: www.showmedo.com

Che

Christopher Barker wrote:

Thanks. I would strongly recommend making valuable resources visible from the wxPython wiki.

It's wiki -- contributions accepted.

I just edited the "How to Learn wxPython" page. As a noob it is difficult to contribute a lot because I don't know much. I can't help explain things better if I don't understand them myself.

http://wiki.wxpython.org/How%20to%20Learn%20wxPython#The_Comprehensive_Demo_Files

Seems to be exactly what you wanted to have "visible from the wxPython wiki".

Indeed, yet I missed it. Worse, I actually went to the "How to Learn wxPython" page first, and yet I missed it. I was so stuck in the section titled "Learn wxPython" that I didn't see the significance of some of the other sections. I had it in my mind the stuff to learn wxPython was under "Learn wxPython".

I hope that my edit will help the next guy.

Feel free to ask lots of questions here, this is a particularly helpful and friendly group, but please don't be so critical, particularly after not doing much RTFM-ing.

Ah, but you underestimate how much RTFM-ing I've done. I actually really and truly tried to learn the wxGrid myself. I'm not being lazy. I went to the places where I thought I was supposed to go to and clicked and searched everywhere I could think of.

Note that I took a quick look at the the wxGrid pages in the Wiki -- they look really comprehensive, but also were written in 2004 (or even 2002?), and the wxPython API has been updated some since then. So, yes, it could be a bit confusing, and could use an update. What a nice way to contribute!

1. The ones that I've found are not merely outdated, they simply do not tell you how to use wxGrid.

2. There's a chicken and egg problem here. I can't fix the documentation for anything until I understand the concept myself.

Daniel.

Hi Daniel,

grid-demo.py (2.05 KB)

grid-demo2.py (3.09 KB)

grid-demo3.py (2.7 KB)

···

On Thu, Jan 14, 2010 at 12:31 PM, Daniel Carrera dcarrera@gmail.com wrote:

Hello,

I want to put a table on my application. I think that wxGrid is probably the right widget, but I can’t get it to work. Based on the wxWidgets C++ documentation I tried doing this:

myTable = wx.Grid(panel, wx.ID_ANY)

Sadly, this failed miserably:

AttributeError: ‘module’ object has no attribute ‘Grid’

So I went to Google and did a search for “grid wxPython” (since lord knows that you can’t find anything by browsing the wiki) and I found this page:

http://wiki.wxpython.org/wxGrid%20Manual

This page claims to be a manual, but it isn’t. A manual should explain how to use a widget and show code examples. But after reading this page I haven’t the faintest clue which of the classes I’m supposed to use to make a table on my application (wxGrid, wxPyGridTableBase, etc).

At best, this page could be called an “API reference” for people who already know which widget they need.

Yes, I did try clicking on “wxGrid”, but the resulting page was not any more illuminating. The page has many words, but I have no idea what it is trying to tell me. I think it’s some kind of reference for internal developers. Certainly nothing that tells me how to use wxGrid, or whether I’m supposed to be using it at all.

Hoping for a miracle, I went to the “wxPyGridTableBase” page, but again, nothing of use. Many words yes, but I have no idea what it says, and it doesn’t tell me whether wxPyGridTableBase is what I want to use in order to add a table to my application, or how to use it.

All very sad. :frowning:

You’d think these things would be documented somewhere, wouldn’t you? I mean, wxWidgets and wxPython have been around for a long time, they are well established projects, they certainly have big documentation with many pages. You would think that there would be room somewhere in there to add an organized manual so that someone can come in and say “I want to add a table to my applicaton”, or “I want a picture here” or whatever and they can find that in the manual.

I always wondered why wxWidgets and wxPython were not used more widely. A cross-platform toolkit, mature, native widgets, liberal license… what more could a developer want? Well, I guess I’m now getting a sense of why there aren’t as many apps written in wx as in Gtk or Qt.

… Yeah, I’m in a bit of a down mood right now.

Daniel.

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

We’ve had discussions on getting the docs up-to-date. Currently, we’re awaiting Robin’s re-write of that system. In the meantime, the wiki is the place to go. If you see some truly confusing examples on the wiki, pop me an email and I’ll see if I can fix it.

In the mean time, I’ve attached a couple of grid examples you can look at. The first one just shows a little basic usage. The second shows how to do column tooltips and the third shows how to add your own editor to a cell of the grid.

Also, Andrea Gavana came up with this handy documentation supplement:

http://xoomer.virgilio.it/infinity77/wxPython/

And he also wrote some special docs for his AGW stuff:

http://xoomer.virgilio.it/infinity77/AGW_Docs/index.html


Mike Driscoll

Blog: http://blog.pythonlibrary.org

Daniel Carrera wrote:

Christopher Barker wrote:
> It's wiki -- contributions accepted.

I just edited the "How to Learn wxPython" page. As a noob it is difficult to contribute a lot because I don't know much. I can't help explain > things better if I don't understand them myself.

Ah, but this is a double-edged sword. Only a noob can see the real getting-started problems, since once you become familiar with a thing's idiosyncracies, it all looks natural and you wonder why anyone has a problem with it (I taught for enough years to know that knowing something and getting it across to others are two grossly different things)... I say "go for it" and when things get pointed off to neverland, the craftsmen and gurus will step in and realign the compass.

Eric

Fahlgren, Eric wrote:

Ah, but this is a double-edged sword. Only a noob can see the real
getting-started problems, since once you become familiar with a
thing's idiosyncracies, it all looks natural and you wonder why
anyone has a problem with it (I taught for enough years to know
that knowing something and getting it across to others are two grossly
different things)... I say "go for it" and when things get pointed
off to neverland, the craftsmen and gurus will step in and realign
the compass.

True enough. Btw, I've taught for a few years myself. I used to teach math for first year university students. Earlier I mentioned that I founded the user guide project for OpenOffice.org. So I'm fairly aware of what it takes to explain a technical concept to someone. On the down side, this experience has made me very sensitive to poor writing, which often leads me to complain a lot. :stuck_out_tongue:

Cheers,
Daniel.