Skip to content
Edit this page

How to…

Short recipes for the changes people make most. Each lists every file that is easy to forget.

Add a weather value to a card

Example: show the dew point on its own card.

  1. Ask for it. Add the field to CURRENT_FIELDS, HOURLY_FIELDS or DAILY_FIELDS in services/open_meteo.py. (Tests that check the URL may need updating: tests/test_api.py.)
  2. Model it. Add the annotation to the model in core/models.py. The attribute itself is set automatically.
  3. Derive it, if needed. A value the current API doesn't give is filled in from the hourly forecast in add_hourly_fields in state/weather_store.py, in the store's worker. A level goes in core/levels.py as a classify_* function, with a test in tests/test_levels.py.
  4. Convert units in the API layer, core/units.py or the store, never in a widget.
  5. Show it. A metric card is a function in ui/cards/metric.py that returns CardSquare(title, value, unit, desc, …, visual=…).card; follow uv_card or humidity_card. Add it to the small-widget grid in _render_weather_grid in ui/window.py.
  6. Strings. Wrap them in _(), then run ./update-pot.
  7. Check both units, light and dark, and with dynamic backgrounds on and off.

Add a setting

  1. A <key> in data/io.github.amit9838.mousam.gschema.xml, then glib-compile-schemas --strict --dry-run data/. Never rename or retype an existing key.
  2. A property on Settings in services/settings.py.
  3. A row in ui/dialogs/preferences.py, if the user can change it.
  4. Whoever shows the value reacts with settings.connect("changed::<key>", …) (through weak_connect on rebuilt widgets).
  5. A test, if a decision depends on it: pass the value in as an argument and test the function.

Add an overview rule

  1. Describe it in docs/overview-rules.md in the app repo first (its sections 9 to 11 cover the rules, writing messages and adding a rule).
  2. Add its message key and 2 to 5 wordings to core/overview/messages.py, all with the same placeholders.
  3. Add a priority to OVERVIEW_PRIORITIES and any numbers to config.py (metric).
  4. Build the rule. "The first hour that…" is a FirstHourRule with an HourTest and a Phrasing; otherwise subclass Rule. Register it in RuleBook.default().
  5. Add a case to tests/test_overview_rules.py.
  6. ./update-pot.

See Overview architecture.

Add a weather code

A WMO code must be added to all four tables in ui/icons.py together: icons_default, icons_material, bg_css and condition. Add the night variant ("61n") where the others have one. Add the icon files under data/icons/, and the background class in src/css/style.css.

Add a card to the grid

The main window builds its grid in _render_weather_grid (ui/window.py): current conditions on top, hourly graphs and the 7-day forecast, a grid of small cards, and air quality and the sun card. A card gets its data through its constructor and is ready when the constructor returns. Add it with add_card(widget, column, row, width). If it draws with Cairo, use a piece from ui/drawing/ or a new one that follows the same pattern (own drawing area, safe_set_draw_func, everything computed in __init__).

The compact window (ui/compact_window.py) has its own, smaller layout.

Add a file

See Architecture: the folder's meson.build, po/POTFILES and mousam.gresource.xml.

Add a language

Add the language code to po/LINGUAS with its .po file (run ./update-pot then ./update-po). Don't machine-translate; translators maintain the files, also through Weblate.

Debug a problem

  1. Turn on debug mode (Preferences → Advanced → Debug Mode, or gsettings set io.github.amit9838.mousam debug-mode true).
  2. Read the console or mousam.log; each module logs under its own area name (data_manager for the store, overview for the engine, API_Weather, main, …).
  3. For the overview (section 12 of docs/overview-rules.md explains the log), the log lists every insight with its level and what the memory knows, then what was shown and where it went (Overview channel: … -> window).
  4. For leaks or a busy CPU after a refresh, see the checks in Data flow and threads.