height control of a wxGridBox

Hey people,

I'm relatively new to wxPython, trying to populate a panel with a small
grid of data, specifically weather data. It should look something
like...

Cloudy

     Temp: 20
     Wind: 8 S
Visbility: Unlimited
Humidity: 83

  Sunrise: 6:09 AM
   Sunset: 8:02 PM

UV index: 0
     risk: Low

Now, a wxGridBoxSizer filled with wxStaticText widgets right and left aligned
have worked well to get the vertical alignment like above. However, the
grid expands vertically to fill the panel, so I don't get the tight
placement like you see above.

I tried a wxGridBagSizer, but the vertical alignment didn't work. All
the text widgets were left aligned, regardless of my forcing
wxALIGN_RIGHT in the wxStaticText call.

Here's the relevant code. Any hints on getting tight placement like
above?

Thanks,
Mike

  def make_left_panel(self):
    left_panel = wxPanel(self, -1, size=(50,50), style=wxNO_BORDER)
    left_panel.SetBackgroundColour("WHITE")

    left_panelbox = wxStaticBox(left_panel,
                                -1,
                                "Current Conditions",
                                size=(50,50))
    left_panelbox.SetFont(self.bfont)

    left_panelbox_sizer = wxStaticBoxSizer(left_panelbox, wxVERTICAL)

    # Add the current conditions grid
    grid_sizer = self.pop_current(left_panel, left_panelbox_sizer)
    left_panelbox_sizer.Add(grid_sizer,
                            1,
                            wxALIGN_CENTER,
                            4)

    left_panel.SetAutoLayout(true)
    left_panel.SetSizer(left_panelbox_sizer)
    left_panel.Layout()

    return left_panel

  def pop_current(self, left_panel, left_sizer):
    """This method is responsible for populating the display of the weather's
    current conditions."""
    grid_sizer = wxGridSizer(9, 2, 1, 1)
    # Temperature
    temp_h = wxStaticText(left_panel, -1, "Temperature:", style=wxALIGN_RIGHT)
    temp_v = wxStaticText(left_panel,
                          -1,
                          'Unknown',
                          style=wxALIGN_LEFT)
    # Wind
    wind_h = wxStaticText(left_panel, -1, "Wind:", style=wxALIGN_RIGHT)
    wind_v = wxStaticText(left_panel,
                          -1,
                          'Unknown',
                          style=wxALIGN_LEFT)

    # Visibility
    vis_h = wxStaticText(left_panel, -1, "Visibility:", style=wxALIGN_RIGHT)
    vis_v = wxStaticText(left_panel,
                         -1,
                         'Unknown',
                         style=wxALIGN_LEFT)

    # Humidity
    hum_h = wxStaticText(left_panel, -1, "Humidity:", style=wxALIGN_RIGHT)
    hum_v = wxStaticText(left_panel,
                         -1,
                         'Unknown',
                         style=wxALIGN_LEFT)

    # Sunrise
    sunr_h = wxStaticText(left_panel, -1, "Sunrise:", style=wxALIGN_RIGHT)
    sunr_v = wxStaticText(left_panel,
                          -1,
                          'Unknown',
                          style=wxALIGN_LEFT)

    # Sunset
    suns_h = wxStaticText(left_panel, -1, "Sunset:", style=wxALIGN_RIGHT)
    suns_v = wxStaticText(left_panel,
                          -1,
                          'Unknown',
                          style=wxALIGN_LEFT)

    # UV Index
    uvi_h = wxStaticText(left_panel, -1, "UV Index:", style=wxALIGN_RIGHT)
    uvi_v = wxStaticText(left_panel,
                         -1,
                         'Unknown',
                         style=wxALIGN_LEFT)

    # Risk
    risk_h = wxStaticText(left_panel, -1, "Risk:", style=wxALIGN_RIGHT)
    risk_v = wxStaticText(left_panel,
                          -1,
                          'Unknown',
                          style=wxALIGN_LEFT)

    # Temperature
    grid_sizer.Add(temp_h, 0, wxEXPAND)
    grid_sizer.Add(temp_v, 0, wxEXPAND)

    # Wind
    grid_sizer.Add(wind_h, 0, wxEXPAND)
    grid_sizer.Add(wind_v, 0, wxEXPAND)

    # Visibility
    grid_sizer.Add(vis_h, 0, wxEXPAND)
    grid_sizer.Add(vis_v, 0, wxEXPAND)

    # Humidity
    grid_sizer.Add(hum_h, 0, wxEXPAND)
    grid_sizer.Add(hum_v, 0, wxEXPAND)

    # Blank row
    grid_sizer.Add(
        wxStaticText(left_panel, -1, '', style=wxALIGN_RIGHT),
        1,
        wxEXPAND
        )
    grid_sizer.Add(
        wxStaticText(left_panel, -1, '', style=wxALIGN_LEFT),
        1,
        wxEXPAND
        )

    # Sunrise
    grid_sizer.Add(sunr_h, 0, wxEXPAND)
    grid_sizer.Add(sunr_v, 0, wxEXPAND)

    # Sunset
    grid_sizer.Add(suns_h, 0, wxEXPAND)
    grid_sizer.Add(suns_v, 0, wxEXPAND)

    # Blank row
    grid_sizer.Add(
        wxStaticText(left_panel, -1, '', style=wxALIGN_RIGHT),
        1,
        wxEXPAND
        )
    grid_sizer.Add(
        wxStaticText(left_panel, -1, '', style=wxALIGN_LEFT),
        1,
        wxEXPAND
        )

    grid_sizer.Add(uvi_h, 0, wxEXPAND)
    grid_sizer.Add(uvi_v, 0, wxEXPAND)

    grid_sizer.Add(risk_h, 0, wxEXPAND)
    grid_sizer.Add(risk_v, 0, wxEXPAND)

    return grid_sizer

···

--
Michael P. Soulier <msoulier@digitaltorque.ca>
The major advances in civilization are processes that all but wreck the
societies in which they occur.
-- Albert North Whitehead

Now, a wxGridBoxSizer filled with wxStaticText widgets right and left aligned
have worked well to get the vertical alignment like above. However, the
grid expands vertically to fill the panel, so I don't get the tight
placement like you see above.

I don't see a problem in your code, so I suspect the problem is how you are putting your panel in the frame. Did you call Frame.Fit()? (and maybe .Fit() on the Panel too.

In general, you'll have more luck getting help if you put your problematic code into a complete app that we can run. If you had, I would have run it and tried to figure out the problem, and I would have been able to see how you are using what's generated by this code which may be the source of your problem.

A few notes on your code:

    left_panel = wxPanel(self, -1, size=(50,50), style=wxNO_BORDER)

you're using sizers, you don't need to set an explicit size. I'd use wx.DefaultSize

       left_panelbox = wxStaticBox(left_panel,
                                -1,
                                "Current Conditions",
                                size=(50,50))

same comment here.

    left_panelbox.SetFont(self.bfont)

    left_panelbox_sizer = wxStaticBoxSizer(left_panelbox, wxVERTICAL)

    # Add the current conditions grid
    grid_sizer = self.pop_current(left_panel, left_panelbox_sizer)

This is a little odd. I'd be inclined to make the current conditions grid a subclass of wx.Panel. the nyou could just construct it and put it in here. For that matter, why not make the StaticBoxSizer part of the conditions Panel?

-Chris

Christopher Barker, Ph.D.
Oceanographer
                                         
NOAA/OR&R/HAZMAT (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

···

On Aug 18, 2004, at 8:03 PM, Michael P. Soulier wrote:

Michael P. Soulier wrote:

Hey people,

I'm relatively new to wxPython, trying to populate a panel with a small
grid of data, specifically weather data. It should look something
like...

Cloudy

     Temp: 20
     Wind: 8 S
Visbility: Unlimited
Humidity: 83

  Sunrise: 6:09 AM
   Sunset: 8:02 PM

UV index: 0
     risk: Low

Now, a wxGridBoxSizer filled with wxStaticText widgets right and left aligned
have worked well to get the vertical alignment like above. However, the
grid expands vertically to fill the panel, so I don't get the tight
placement like you see above.

Try a wx.FlexGridSizer.

I tried a wxGridBagSizer, but the vertical alignment didn't work. All
the text widgets were left aligned, regardless of my forcing
wxALIGN_RIGHT in the wxStaticText call.

Probably due to the items not being expanded to fill the grid cell by default, as they are with the wx.GridSizer.

···

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