User interface¶
Windows¶
WeatherMainWindow(ui/window.py, anAdw.ApplicationWindow) has the header bar and amain_stackthat shows one view state at a time:loader,welcome(no locations),error_no_internet,error_apiandcontent. Switch with_update_view_state(state, message); no extra spinners on top. Content sits in cards inside anAdw.Clamp(max 1400 px).CompactWeatherWindow(ui/compact_window.py) is the minimal window.app.pyswitches between normal and compact mode with theshow-compactandshow-normalactions. The main window is hidden, not closed, while compact mode is on.- Dialogs use
Adw.Dialogand its subclasses (Adw.PreferencesDialog,Adw.AboutDialog), shown withpresent(parent): Preferences, Locations (and the city search), About, air-quality details and shortcuts.
Errors the user can fix say how ("Please check your connection.") and offer Retry. There is one suggested-action button per page.
The main grid¶
_render_weather_grid in ui/window.py rebuilds the content page on every ready status:
| Place | Piece |
|---|---|
| top, full width | CurrentCondition in an Adw.Clamp |
| left, below | HourlyDetails |
| right, two rows | Forecast |
| middle, small grid | wind, humidity, pressure and UV cards |
| middle, wide | CardAirPollution, CardDayNight |
The window also sets the dynamic background class from the weather code and is_day before building the grid.
Sections and cards¶
| Piece | Where | Use |
|---|---|---|
| Current conditions and the overview pill | ui/sections/current.py |
CurrentCondition |
| Hourly graphs with tabs (temperature, wind, precipitation) | ui/sections/hourly.py |
HourlyDetails(hourly) |
| Tomorrow and 7-day list | ui/sections/forecast.py |
Forecast(daily, hourly) |
| Metric card (title, value, unit, level, sub line, gauge) | ui/cards/metric.py |
CardSquare(..., visual=widget).card; wind_card, humidity_card, pressure_card, uv_card |
| Sun and moon | ui/cards/day_night.py |
CardDayNight(daily, timezone_name, latitude).card |
| Air quality | ui/cards/air_quality.py |
CardAirPollution(air).card |
A component gets its data through its constructor, from the window that builds the grid, and is ready when the constructor returns. Sections with state, timers or handlers subclass a GTK widget; connect on map, disconnect and remove sources on unmap. HourlyDetails and Forecast build a tab's page the first time it is chosen.
Create a component only when it is reused, makes a window easier to read, or is a clear UI concept. No tiny one-off components.
Drawing¶
CSS can't draw graphs, gauges or arcs, so they are Cairo in a Gtk.DrawingArea, in ui/drawing/. Each piece owns its drawing area, sets the draw function with safe_set_draw_func, builds everything in __init__ and hands the widget out as .widget.
| Need | Use |
|---|---|
| Vertical level gauge | DrawLevelBar(...) |
| Small bar | DrawBar(...) |
| Line graph with a "now" marker | LineGraph(...) |
| Rotated icon (wind direction) | DrawImage(...) |
| Day/night arc | DrawDayNight(...) |
| Pollutant level bar | PollutionBar (a Gtk.DrawingArea subclass) |
| A day's low–high range on the week's scale | DrawTempRange(low, high, week_min, week_max) |
| Tick gauge centred on the best value (pressure) | DrawTickGauge(fill_fr) |
| Chance of rain as one to four drops | DrawRainDrops(count, height) (rain_drop_count gives count); DrawSnowflakes for snow |
| Theme text colour, text and knobs | theme_rgba, text_layout, draw_text, draw_knob in ui/gtk_utils.py |
Cairo colours are [r, g, b] floats from 0 to 1. Prefer the existing blue [0.38, 0.7, 1] and the level colours already used.
Icons and backgrounds¶
Weather icons go only through ui/icons.py: create_weather_icon(code, theme, size) or get_icon_path(...), with condition[code] for a name and bg_css[code] for the background class (append n to the code at night). Both icon themes (default and Material) must look right: Material icons are drawn smaller, so use get_icon_pixel_size. Buttons use symbolic theme icons (view-refresh-symbolic). Cards add bg-dark-overlay so text stays readable on any gradient.
Styling¶
All custom styling is in src/css/style.css, loaded once in WeatherApplication.do_activate. Apply it with add_css_class / set_css_classes.
- libadwaita and the HIG first: stock widgets and style classes (
card,view,pill,suggested-action,flat,linked,dim-label) before custom CSS. - Reuse the utility classes: typography (
text-xs…text-8xl,font-light…font-bold), spacing (m-*,mt-*, …), opacity,btn-sm/btn-md/btn-lg,bg-weather-*,compact-*. - Sizes in
rem, so they follow text scaling. Named colours (@accent_color,@window_fg_color, …) orcurrentColor, not hex. The weather gradients are the exception. - A repeating pattern gets a class in
style.css, not repeated widget calls.
Text hierarchy on cards:
| Text | Classes |
|---|---|
| title | text-lg opacity-80 font-medium |
| value | text-3xl font-medium |
| unit | text-sm opacity-80 |
| level | text-base opacity-90 font-semibold |
Every number has its unit; every level colour has words ("Moderate", "High"). Levels come from classify_* in core/levels.py, AQI colours from THRESHOLDS in config.py. Layout properties (expand, align, grid spans) and drawing-area sizes are set from code (set_hexpand, Gtk.Grid.attach, set_size_request).
Quality bar¶
Every screen works in light and dark, with dynamic backgrounds on and off, metric and imperial, 12h and 24h, and from about 360 px wide to full screen without clipping. Long translated strings wrap or ellipsize. Follow the GNOME HIG.
Check APIs before using them¶
Widgets get deprecated between releases. Before using an API, find the oldest runtime we build on (runtime-version in io.github.amit9838.mousam.json, the image: in .github/workflows/flatpak.yml, and the Snap's gnome extension on core26) and use nothing newer. Check the official docs, not memory: GTK 4, libadwaita, PyGObject.
Window layouts¶
Window and dialog layouts are meant to move into Gtk.Template .ui files in ui/templates/ over time (only shortcuts.ui is there today), each as its own refactor.