plasma-manager icon indicating copy to clipboard operation
plasma-manager copied to clipboard

How do I configure weather panel widget geographical location?

Open acobster opened this issue 11 months ago • 7 comments

The relevant piece of my system config looks like:

{
  programs.plasma = {
    enable = true;
    overrideConfig = true;

    panels = [
      {
         location = "top";
         # ...
         widgets = [
           {
             # ...
             "org.kde.plasma.weather"
           }
         ]
       }
     ]
  }
}

However, I can't find a way to configure weather location explicitly so that it survives the overrideConfig on login. I could of course disable overrideConfig, but of course that somewhat defeats the purpose of managing Plasma with Nix. In effect, every time I login my geographical weather location gets wiped and I have to set it manually again.

I tried to figure this out on my own, but the Plasma code is vast and frankly overwhelming coming from GNOME. I am not quite sure how to map a widget shape onto whatever the equivalent Plasma output needs to be, nor exactly what form that output is even supposed to take (an XML file? a QML file??).

One thing I did try was configuring my location manually and then running:

$ nix run github:nix-community/plasma-manager | grep -i weather

This does not output anything, which I find odd. Using the old version of the script seems to work...

$ nix run github:mcdonc/plasma-manager/enable-look-and-feel-settings | grep -i weather
      "plasma-org.kde.plasma.desktop-appletsrc"."Containments.546.Applets.549"."plugin" = "org.kde.plasma.weather";
      "plasma-org.kde.plasma.desktop-appletsrc"."Containments.546.Applets.550"."plugin" = "org.kde.plasma.weather";
$ nix run github:mcdonc/plasma-manager/enable-look-and-feel-settings > plasma.txt

...but when I examine plasma.txt I can't find anything indicating the actual location. Is that stored somewhere else? i.e. a database, or somewhere that needs to be mutably set by a KWin script or something?

So, "How do I configure weather panel widget location?" is the "may I have some fish" version of my question. More generally, my "teach me to fish" question is something like: what are the relevant parts of the Plasma code/docs I need to look at to understand how to investigate things like this?

acobster avatar Jan 19 '25 19:01 acobster

The widget location is defined by the order you set the widgets from left to right. That is just the way the plasma scripts work.

HeitorAugustoLN avatar Jan 19 '25 20:01 HeitorAugustoLN

@HeitorAugustoLN I meant the geographical location for the weather itself. I edited the question to clarify.

acobster avatar Jan 19 '25 23:01 acobster

@HeitorAugustoLN I meant the geographical location for the weather itself. I edited the question to clarify.

Understood it now. It is located at: $XDG_CONFIG_HOME/plasmashellrc

you could write:

{
  programs.plasma.configFile."plasmashellrc"."Applets/id/Configuration/WeatherStation".source = "value here";
}

But the problem is that every panel update plasma does with the script, the id of the applets and containments generally get changed to a bigger value. So I don't really know if it would be possible to do it, with overrideConfig, since overrideConfig updates the panel everytime. I think a possible way to do this, but I am not sure if it will work, is doing this:



{
  programs.plasma = {
    enable = true;
    overrideConfig = true;

    panels = [
      {
         location = "top";
         # ...
         widgets = [
           {
             # ...
             {
               name = "org.kde.plasma.weather";
               extraConfig = ''
                 (widget) => {
                    const baseConfig = ConfigFile('plasmashellrc');
                    baseConfig.group = 'Applets';
                    const appletGroup = ConfigFile(baseConfig);
                    appletGroup.group = widget.id.toString();
                    const configGroup = ConfigFile(appletGroup);
                    configGroup.group = 'Configuration';
                    const weatherStation = ConfigFile(configGroup);
                    weatherStation.group = 'WeatherStation';
                    
                    weatherStation.writeEntry('source', 'value here');
                 }
               '';
             }
           }
         ]
       }
     ]
  }
}

I don't know if my javascript syntax is right in here, but it should be it.

HeitorAugustoLN avatar Jan 20 '25 00:01 HeitorAugustoLN

You need to use config.WeatherStation.source, like so:

{
  name = "org.kde.plasma.weather";
  config = {
    WeatherStation.source = "insert value here";
  };
}

Sporif avatar Jan 20 '25 09:01 Sporif

You need to use config.WeatherStation.source, like so:

{
  name = "org.kde.plasma.weather";
  config = {
    WeatherStation.source = "insert value here";
  };
}

I don't think so, the configuration isn't written in the regular location. At least not on my end.

HeitorAugustoLN avatar Jan 20 '25 11:01 HeitorAugustoLN

This is mine, works fine on my end

            {
              name = "org.kde.plasma.weather";
              config = {
                WeatherStation = {
                  updateInterval = 30; # (Mins)
                  source = "bbcukmet|weather|Inverness, Inverness, GB|2644668";
                };
                Appearance = {
                  showTemperatureInCompactMode = true;
                  showTemperatureInBadge = false;
                  showPressureInTooltip = true;
                };
                Units = {
                  temperatureUnit = 6001;
                };
              };
            }

To get the source = ""; string

  1. Manually configure the weather widget & add the weather station via the GUI (by right clicking it)
  2. Immediately apply it & open the file .config/plasma-org.kde.plasma.desktop-appletsrc
  3. Grep/ search for these strings:
[Containments][random number][Applets][random number][Configuration][WeatherStation]
source=bbcukmet|weather|Inverness, Inverness, GB|2646088
  1. put the source string into your "source" attribute string in your nix config as show above @acobster

notjiatan avatar Jun 24 '25 05:06 notjiatan

@notjiatan thanks! That solution works for me. @HeitorAugustoLN feel free to close if you feel this issue is sufficient documentation for this.

acobster avatar Sep 17 '25 17:09 acobster