From c633db548fa718b9fb21bff06948e3d834ee6fc9 Mon Sep 17 00:00:00 2001 From: elenapan Date: Thu, 18 Jul 2024 18:32:42 +0300 Subject: [PATCH] Move weather icon dictionary to icons init.lua --- config/awesome/icons/init.lua | 42 ++++++++++++++++- config/awesome/noodle/text_weather.lua | 65 +++----------------------- 2 files changed, 46 insertions(+), 61 deletions(-) diff --git a/config/awesome/icons/init.lua b/config/awesome/icons/init.lua index 7a3b537..ce58b7b 100644 --- a/config/awesome/icons/init.lua +++ b/config/awesome/icons/init.lua @@ -14,8 +14,46 @@ local icons = {} icons.image = {} icons.text = {} --- TODO Set up weather text icons here instead of in ../noodle/text_weather.lua --- icons.text.weather = {} +-- 'Icomoon' font (filled variant) +local sun_icon = "" +local moon_icon = "" +local dcloud_icon = "" +local ncloud_icon = "" +local cloud_icon = "" +local rain_icon = "" +local storm_icon = "" +local snow_icon = "" +local mist_icon = "" +local whatever_icon = "" + +-- Icon codes of openweathermap +icons.text.weather = { + ["01d"] = { symbol = sun_icon, color = x.color3 }, + ["01n"] = { symbol = moon_icon, color = x.color4 }, + ["02d"] = { symbol = dcloud_icon, color = x.color3 }, + ["02n"] = { symbol = ncloud_icon, color = x.color6 }, + ["03d"] = { symbol = cloud_icon, color = x.color1 }, + ["03n"] = { symbol = cloud_icon, color = x.color1 }, + ["04d"] = { symbol = cloud_icon, color = x.color1 }, + ["04n"] = { symbol = cloud_icon, color = x.color1 }, + ["09d"] = { symbol = rain_icon, color = x.color4 }, + ["09n"] = { symbol = rain_icon, color = x.color4 }, + ["10d"] = { symbol = rain_icon, color = x.color4 }, + ["10n"] = { symbol = rain_icon, color = x.color4 }, + ["11d"] = { symbol = storm_icon, color = x.color1 }, + ["11n"] = { symbol = storm_icon, color = x.color1 }, + ["13d"] = { symbol = snow_icon, color = x.color6 }, + ["13n"] = { symbol = snow_icon, color = x.color6 }, + ["40d"] = { symbol = mist_icon, color = x.color5 }, + ["40n"] = { symbol = mist_icon, color = x.color5 }, + ["50d"] = { symbol = mist_icon, color = x.color5 }, + ["50n"] = { symbol = mist_icon, color = x.color5 }, + ["_"] = { symbol = whatever_icon, color = x.color2 } +} + +icons.text.get_weather_icon = function(code) + return icons.text.weather[code] or icons.text.weather["_"] +end -- Set up text symbols and accent colors to be used in tasklists or docks -- instead of awful.widget.clienticon diff --git a/config/awesome/noodle/text_weather.lua b/config/awesome/noodle/text_weather.lua index ab2ff48..7b6f1a7 100644 --- a/config/awesome/noodle/text_weather.lua +++ b/config/awesome/noodle/text_weather.lua @@ -2,6 +2,8 @@ local gears = require("gears") local wibox = require("wibox") local beautiful = require("beautiful") local helpers = require("helpers") +local icons = require("icons") +local get_weather_icon = icons.text.get_weather_icon local weather_temperature_symbol if user.weather_units == "metric" then @@ -10,31 +12,6 @@ elseif user.weather_units == "imperial" then weather_temperature_symbol = "°F" end --- Text icons --- 'Typicons' font --- local sun_icon = "" --- local moon_icon = "" --- local dcloud_icon = "" --- local ncloud_icon = "" --- local cloud_icon = "" --- local rain_icon = "" --- local storm_icon = "" --- local snow_icon = "" --- local mist_icon = "" --- local whatever_icon = "" - --- 'Icomoon' font (filled variant) -local sun_icon = "" -local moon_icon = "" -local dcloud_icon = "" -local ncloud_icon = "" -local cloud_icon = "" -local rain_icon = "" -local storm_icon = "" -local snow_icon = "" -local mist_icon = "" -local whatever_icon = "" - local weather_description = wibox.widget{ -- text = "Weather unavailable", text = "Loading weather...", @@ -66,42 +43,12 @@ local weather = wibox.widget{ layout = wibox.layout.fixed.horizontal } -local weather_icons = { - ["01d"] = { icon = sun_icon, color = x.color3 }, - ["01n"] = { icon = moon_icon, color = x.color4 }, - ["02d"] = { icon = dcloud_icon, color = x.color3 }, - ["02n"] = { icon = ncloud_icon, color = x.color6 }, - ["03d"] = { icon = cloud_icon, color = x.color1 }, - ["03n"] = { icon = cloud_icon, color = x.color1 }, - ["04d"] = { icon = cloud_icon, color = x.color1 }, - ["04n"] = { icon = cloud_icon, color = x.color1 }, - ["09d"] = { icon = rain_icon, color = x.color4 }, - ["09n"] = { icon = rain_icon, color = x.color4 }, - ["10d"] = { icon = rain_icon, color = x.color4 }, - ["10n"] = { icon = rain_icon, color = x.color4 }, - ["11d"] = { icon = storm_icon, color = x.color1 }, - ["11n"] = { icon = storm_icon, color = x.color1 }, - ["13d"] = { icon = snow_icon, color = x.color6 }, - ["13n"] = { icon = snow_icon, color = x.color6 }, - ["40d"] = { icon = mist_icon, color = x.color5 }, - ["40n"] = { icon = mist_icon, color = x.color5 }, - ["50d"] = { icon = mist_icon, color = x.color5 }, - ["50n"] = { icon = mist_icon, color = x.color5 }, - ["_"] = { icon = whatever_icon, color = x.color2 }, -} - awesome.connect_signal("evil::weather", function(temperature, description, icon_code) - local icon - local color - if weather_icons[icon_code] then - icon = weather_icons[icon_code].icon - color = weather_icons[icon_code].color - else - icon = weather_icons['_'].icon - color = weather_icons['_'].color - end + local icon = get_weather_icon(icon_code) + local symbol = icon.symbol + local color = icon.color - weather_icon.markup = helpers.colorize_text(icon, color) + weather_icon.markup = helpers.colorize_text(symbol, color) weather_description.markup = description weather_temperature.markup = temperature -- weather_temperature.markup = helpers.colorize_text(tostring(temperature)..weather_temperature_symbol, color)