wx.Grid Displays, But Not Correctly

In a module I have the following:

import wx.grid as gridlib

class MyGrid(gridlib.Grid):
   def __init__(self, prnt, ID):
     gridlib.Grid.__init__(self, prnt, wx.ID_ANY)

     self.CreateGrid(10, 8)
     self.SetRowSize(4, 45)
     self.SetColSize(3, 200)
     self.SetColLabelValue(0, '')
     self.SetColLabelValue(1,'Exist. Cond.')
     self.SetColLabelValue(2, 'No Action')
     self.SetColLabelValue(3, 'Alt. 2')
     self.SetRowLabelValue(1, 'Component 1')
     self.SetRowLabelValue(2, 'Component 2')
   # end of MyGrid class

(plus a bunch more code). It all interprets and displays, but I'm not seeing
what I thought I defined. Instead, there's only one cell and some scroll
bars. See the attached screenshot.

   What have I left out so far?

Thanks,

Rich

screenshot.png

···

--
Richard B. Shepard, Ph.D. | Author of "Quantifying Environmental
Applied Ecosystem Services, Inc. (TM) | Impact Assessments Using Fuzzy Logic"
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863

Data? How have you populated it?

-- Ed Leafe
-- http://leafe.com
-- http://dabodev.com

···

On Dec 6, 2005, at 7:16 PM, Rich Shepard wrote:

  What have I left out so far?

Ed,

   I want it blank for now; nothing in the cells, but titles on the rows and
columns. Can't I do that?

Thanks,

Rich

···

On Tue, 6 Dec 2005, Ed Leafe wrote:

   Data? How have you populated it?

--
Richard B. Shepard, Ph.D. | Author of "Quantifying Environmental
Applied Ecosystem Services, Inc. (TM) | Impact Assessments Using Fuzzy Logic"
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863

Well, I thought it might need self.Fit(), but that does not do the trick.
Perhaps the grid needs to be in a sizer ... no, that's not it.

Rich

···

On Tue, 6 Dec 2005, Rich Shepard wrote:

   Data? How have you populated it?

I want it blank for now; nothing in the cells, but titles on the rows and
columns. Can't I do that?

--
Richard B. Shepard, Ph.D. | Author of "Quantifying Environmental
Applied Ecosystem Services, Inc. (TM) | Impact Assessments Using Fuzzy Logic"
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863

Unless you provide some dummy data, no, the grid will not look like much. It's been a long time since I used a raw wxPython grid, but I do remember that much.

-- Ed Leafe
-- http://leafe.com
-- http://dabodev.com

···

On Dec 6, 2005, at 7:36 PM, Rich Shepard wrote:

  I want it blank for now; nothing in the cells, but titles on the rows and
columns. Can't I do that?

Ed,

   I added an additional line, 'self.SetCellValue(4, 4, 'Some text')', but
that made no difference.

   Andrea's example, and that in the wxWidgets book show blank cells in
addition to the cells with text and numbers. If one wants to provide a
spreadsheet tool for users, then the empty grid needs to be displayed on the
notebook page's panel.

   Don't let me discourage you! Keep those cards and letters of encouragement
coming. :slight_smile:

Thanks,

Rich

···

On Tue, 6 Dec 2005, Ed Leafe wrote:

  Unless you provide some dummy data, no, the grid will not look like much.
It's been a long time since I used a raw wxPython grid, but I do remember
that much.

--
Richard B. Shepard, Ph.D. | Author of "Quantifying Environmental
Applied Ecosystem Services, Inc. (TM) | Impact Assessments Using Fuzzy Logic"
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863

When I've needed to display an empty grid, I first create an empty data set with the right number of columns, and the number of rows that I want, and call dGrid.DataSet = ds. That's all you need to do in Dabo.

-- Ed Leafe
-- http://leafe.com
-- http://dabodev.com

···

On Dec 6, 2005, at 8:07 PM, Rich Shepard wrote:

  I added an additional line, 'self.SetCellValue(4, 4, 'Some text')', but
that made no difference.

  Andrea's example, and that in the wxWidgets book show blank cells in
addition to the cells with text and numbers. If one wants to provide a
spreadsheet tool for users, then the empty grid needs to be displayed on the
notebook page's panel.

Rich Shepard schrieb:

   Data? How have you populated it?

I want it blank for now; nothing in the cells, but titles on the rows and
columns. Can't I do that?

  Well, I thought it might need self.Fit(), but that does not do the trick.
Perhaps the grid needs to be in a sizer ... no, that's not it.

Rich

Hi,

I am a newbie, too. But here is a working example:

class GridExample(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self,None,wx.ID_ANY,'Grid Example')
        self.addgrid()
     def addgrid(self):
        sizer = wx.BoxSizer(wx.HORIZONTAL) self.SetSizer(sizer)
        self.grid = wx.grid.Grid(self,-1)
        self.grid.CreateGrid(10,8) 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)

Ralf Schoenian

···

On Tue, 6 Dec 2005, Rich Shepard wrote:

Hi,

I would say a simple but complete working example is "must have" thing then
you looking for a help. Otherwise we are in trouble because any little
detail can be relevant...

Seems like your grid is just happened to be too small. I notice your grid is
placed as notebook page. This may trigger an issue. From my expirence some
"complex" widgets (grid at least) which don't have a strong idea about their
"best size" can behave strangely (in regard of sizing) then placed on
notebook page.

Sorry, I don't have a simple recipe.

    Vladimir Ignatov
    www.colorpilot.com

I have grids in notebook controls. They display their headings ok when there is no data.

The source is at brewsta - make beer not war download | SourceForge.net

cheers

Vladimir Ignatov wrote:

···

Hi,

I would say a simple but complete working example is "must have" thing then
you looking for a help. Otherwise we are in trouble because any little
detail can be relevant...

Seems like your grid is just happened to be too small. I notice your grid is
placed as notebook page. This may trigger an issue. From my expirence some
"complex" widgets (grid at least) which don't have a strong idea about their
"best size" can behave strangely (in regard of sizing) then placed on
notebook page.

Sorry, I don't have a simple recipe.

   Vladimir Ignatov
   www.colorpilot.com

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

Thank you, all. I have it working just fine now. A key problem (perhaps the
major problem) was trying to put the wx.Grid on a wx.Panel, then place that
on the wx.Notebook page.

   I followed what Andrea created for his SimpleGrid in the NotebookCtrlDemo,
and created what I needed. Seeing a working example, and futzing with the
code to observe the changes, made it all perfectly clear to me.

   The one thing I could not get right was the set of arguments to pass to
self.SetColMinimalWidth(). The wxWidgets book does not provide the arguments,
and the column number and width (in pixels) are only 2 of the required 3.
I've no idea what that third one is, so I set the minimum column width for
each column. I hope that the wxPython book provides the answer to this!

   One more notebook pane and the visual component of the UI is done. Thanks
again for all your patient help.

Rich

···

On Tue, 6 Dec 2005, Rich Shepard wrote:

What have I left out so far?

--
Richard B. Shepard, Ph.D. | Author of "Quantifying Environmental
Applied Ecosystem Services, Inc. (TM) | Impact Assessments Using Fuzzy Logic"
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863

Rich Shepard wrote:

  The one thing I could not get right was the set of arguments to pass to
self.SetColMinimalWidth(). The wxWidgets book does not provide the arguments,
and the column number and width (in pixels) are only 2 of the required 3.
I've no idea what that third one is, so I set the minimum column width for
each column. I hope that the wxPython book provides the answer to this!

Help on method SetColMinimalWidth in module wx.grid:

SetColMinimalWidth(*args, **kwargs) unbound wx.grid.Grid method
     SetColMinimalWidth(self, int col, int width)

I don't see the third argument you are referring to. Beyond the standard 'self', I see 'col' and 'width'.

BTW, I got the above "documentation" using:

pmcnett@sol:~$ python
Python 2.4.2 (#2, Sep 30 2005, 21:19:01)
[GCC 4.0.2 20050808 (prerelease) (Ubuntu 4.0.1-4ubuntu8)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import wx.grid
help(wx.grid.Grid.SetColMinimalWidth)

···

--
Paul McNett
http://paulmcnett.com
http://dabodev.com

SetColMinimalWidth(*args, **kwargs) unbound wx.grid.Grid method
   SetColMinimalWidth(self, int col, int width)

I don't see the third argument you are referring to. Beyond the standard 'self', I see 'col' and 'width'.

   Thanks, Paul. I was calling it incorrectly.

BTW, I got the above "documentation" using:

pmcnett@sol:~$ python
Python 2.4.2 (#2, Sep 30 2005, 21:19:01)
[GCC 4.0.2 20050808 (prerelease) (Ubuntu 4.0.1-4ubuntu8)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

import wx.grid

help(wx.grid.Grid.SetColMinimalWidth)

   I'm still not used to this; but I'll get there.

Rich

···

On Wed, 7 Dec 2005, Paul McNett wrote:

--
Richard B. Shepard, Ph.D. | Author of "Quantifying Environmental
Applied Ecosystem Services, Inc. (TM) | Impact Assessments Using Fuzzy Logic"
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863

From what I remember, basically all wrapped methods have that exact same
call signature as seen from help(). One would likely be better off
paying attent to the wxWindows docs, or even the new wxPython docs
(which are more accurate, but have very little actual documentation):
    wxPython API Documentation — wxPython Phoenix 4.2.2 documentation

    "SetColMinimalWidth(self, col, width)"

- Josiah

···

Paul McNett <p@ulmcnett.com> wrote:

Rich Shepard wrote:
> The one thing I could not get right was the set of arguments to pass to
> self.SetColMinimalWidth(). The wxWidgets book does not provide the
> arguments,
> and the column number and width (in pixels) are only 2 of the required 3.
> I've no idea what that third one is, so I set the minimum column width for
> each column. I hope that the wxPython book provides the answer to this!

Help on method SetColMinimalWidth in module wx.grid:

SetColMinimalWidth(*args, **kwargs) unbound wx.grid.Grid method
     SetColMinimalWidth(self, int col, int width)

Wednesday, December 7, 2005, 3:43:54 PM, Rich Shepard wrote:

Thank you, all. I have it working just fine now. A key problem
(perhaps the major problem) was trying to put the wx.Grid on a
wx.Panel, then place that on the wx.Notebook page.

If the grid is the only child of your panel this should also work:

class MyPanel(wx.Panel):
    def __init__(foo, bar):
        ...
        self.grid = MyGrid(spam, eggs)
        ...
        self.Bind(wx.EVT_SIZE, self.OnSize)
        
    def OnSize(self, evt):
        self.grid.SetSize(self.GetClientSize())

-- tacao

No bits were harmed during the making of this e-mail.

tacao,

   Thank you. I'll save this for future reference.

Rich

···

On Wed, 7 Dec 2005, E. A. Tacao wrote:

If the grid is the only child of your panel this should also work:

class MyPanel(wx.Panel):
   def __init__(foo, bar):
       ...
       self.grid = MyGrid(spam, eggs)
       ...
       self.Bind(wx.EVT_SIZE, self.OnSize)

   def OnSize(self, evt):
       self.grid.SetSize(self.GetClientSize())

--
Richard B. Shepard, Ph.D. | Author of "Quantifying Environmental
Applied Ecosystem Services, Inc. (TM) | Impact Assessments Using Fuzzy Logic"
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863