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