awesome-wm-widgets icon indicating copy to clipboard operation
awesome-wm-widgets copied to clipboard

question on widget integration

Open adrien-barret opened this issue 2 years ago • 1 comments

Hi,

I'm not so familiar with awesome but after trying to integrate a weather widget, it seems that weathre is not showing up on my wibar but no error when I relead awesome.

ani ydeas?

local awful = require("awful")
local wibox = require("wibox")
local beautiful = require("beautiful")
local xresources = require("beautiful.xresources")
local dpi = xresources.apply_dpi
local helpers = require("helpers")
local weather_widget = require("awesome-wm-widgets.weather-widget.weather")

-- Keyboard map indicator and switcher
mykeyboardlayout = awful.widget.keyboardlayout()

-- Text clock
local time = wibox.widget {
    widget = wibox.container.background,
    bg = beautiful.bg_normal,
    buttons = {
        awful.button({}, 1, function()
            require "ui.popup.calender" ()
        end),
    },
    {
        widget = wibox.container.margin,
        margins = 10,
        {
            widget = wibox.widget.textclock "%d %B - %l:%M %p",
            font = beautiful.font_name .. " Bold 11",
            align = "center",
        },
    },
}
local weather = wibox.widget {
    widget = wibox.container.background,
    bg = beautiful.bg_normal,
    buttons = {
        awful.button({}, 1, function()
            require "ui.popup.calender" ()
        end),
    },
    {
        widget = wibox.container.margin,
        margins = 10,
        {
            widget = wibox.widget.textclock "%d %B - %l:%M %p",
            font = beautiful.font_name .. " Bold 11",
            align = "center",
        },
    },
    weather_widget({
        api_key="ApiKey'',
        coordinates = {44.5017, -73.5675},
        time_format_12h = true,
        units = 'metric',
        both_units_widget = true,
        font_name = 'Carter One',
        icons = 'VitalyGorbachev',
        icons_extension = '.svg',
        show_hourly_forecast = true,
        show_daily_forecast = true,
    }),  
}

        


helpers.add_hover_cursor(time, "hand1")

local action_icon = require("ui.gooey").make_button {
    icon = "bell2",
    --bg = beautiful.background,
    --fg = beautiful.white,
    width = 34,
    margins = 6.9,
    hover = true,
    exec = function()
        F.action.toggle()
    end,
}

-- Battery
battery = require("config.battery")

battery_widget = wibox.widget.textbox()
battery_widget:set_align("right")
battery_closure = battery.closure()

function battery_update()
    battery_widget:set_text(" " .. battery_closure() .. " ")
end

battery_update()
battery_timer = timer({ timeout = 15 })
battery_timer:connect_signal("timeout", battery_update)
battery_timer:start()
--

helpers.add_hover_cursor(action_icon, "hand1")

screen.connect_signal("request::desktop_decoration", function(s)

    awful.tag({ " ", "  ", "  ", "  ", " " }, s,
        awful.layout.layouts[1])

    -- Create a promptbox for each screen
    s.mypromptbox = awful.widget.prompt()

    -- Create an imagebox widget which will contain an icon indicating which layout we're using.
    -- We need one layoutbox per screen.
    s.mylayoutbox = awful.widget.layoutbox {
        screen  = s,
        buttons = {
            awful.button({}, 1, function() awful.layout.inc(1) end),
            awful.button({}, 3, function() awful.layout.inc(-1) end),
            awful.button({}, 4, function() awful.layout.inc(-1) end),
            awful.button({}, 5, function() awful.layout.inc(1) end),
        }
    }

    -- Create a taglist widget
    s.mytaglist = awful.widget.taglist {
        screen  = s,
        filter  = awful.widget.taglist.filter.all,
        buttons = {
            awful.button({}, 1, function(t) t:view_only() end),
            awful.button({ modkey }, 1, function(t)
                if client.focus then
                    client.focus:move_to_tag(t)
                end
            end),
            awful.button({}, 3, awful.tag.viewtoggle),
            awful.button({ modkey }, 3, function(t)
                if client.focus then
                    client.focus:toggle_tag(t)
                end
            end),
            awful.button({}, 4, function(t) awful.tag.viewprev(t.screen) end),
            awful.button({}, 5, function(t) awful.tag.viewnext(t.screen) end),
        }
    }

    -- Create a tasklist widget
    s.mytasklist = awful.widget.tasklist {
        screen  = s,
        filter  = awful.widget.tasklist.filter.currenttags,
        buttons = {
            awful.button({}, 1, function(c)
                c:activate { context = "tasklist", action = "toggle_minimization" }
            end),
            awful.button({}, 3, function() awful.menu.client_list { theme = { width = 250 } } end),
            awful.button({}, 4, function() awful.client.focus.byidx(-1) end),
            awful.button({}, 5, function() awful.client.focus.byidx(1) end),
        },         
    }

    s.mywibar = awful.wibar({
        type = "dock",
        ontop = true,
        stretch = false,
        visible = true,
        height = dpi(35),
        width =  dpi(1200),-- s.geometry.width,
        position = "bottom",
        shape = helpers.rrect(15),
        -- shape = helpers.rrect(6),        
        screen = s,
    })

    -- awful.placement.bottom(s.mywibar, { margins = beautiful.useless_gap * 1 })
    -- awful.placement.bottom(s.mywibar)
    
    --{{{ Remove wibar on full screen
    local function remove_wibar(c)
        if c.fullscreen or c.maximized then
            c.screen.mywibar.visible = false
        else
            c.screen.mywibar.visible = true
        end
    end

    local function add_wibar(c)
        if c.fullscreen or c.maximized then
            c.screen.mywibar.visible = true
        end
    end

    ---}}}

    -- Hide bar when a splash widget is visible
    awesome.connect_signal("widgets::splash::visibility", function(vis)
        screen.primary.mywibar.visible = not vis
    end)

    client.connect_signal("property::fullscreen", remove_wibar)

    client.connect_signal("request::unmanage", add_wibar)

    -- Create the wibox
    s.mywibar:setup({
        {
            {
                layout = wibox.layout.align.horizontal,
                expand = "none",
                {
                    s.mytaglist,
                    margins = dpi(2),
                    widget = wibox.container.margin,
                },
                time,
                weather,
                {
                    {
                        margins = dpi(9.7),
                        widget = wibox.container.margin,
                    },           
                    battery_widget,
                    action_icon,
                    layout = wibox.layout.fixed.horizontal,
                },
            },
            left = dpi(15),
            right = dpi(15),
            widget = wibox.container.margin,
        },
        shape = helpers.rrect(beautiful.border_radius),
        widget = wibox.container.background,
    })
end)

adrien-barret avatar Dec 05 '22 14:12 adrien-barret

I recently encountered the same issue. After investigating, it seems like the OpenWeather API has changed a lot. Here are some observations:

  • The OpenWeather free plan no longer provides hourly or daily forecasts. Instead it only provides a 3-hour/5-day forecast. This forecast is only accurate down to 3-hour intervals, and I had to aggregate the data client-side to get a bespoke daily forecast.
  • The format of the JSON responses have changed.
  • There is a separate API for current weather included in the free plan.
  • UVI data is no longer free

I have a few commits in my fork to get things working with the free plan: https://github.com/alexbox23/awesome-wm-widgets Feel free to use it. For now I'm not submitting a PR, since it will break any users paying for the true hourly/daily forecast. Someone with the paid subscription would have to implement and test support for both free and paid APIs.

Hope this helps. Friendly ping @streetturtle in case you aren't aware :)

alexbox23 avatar Jan 26 '23 08:01 alexbox23