Clean the config code.
This commit is contained in:
parent
3b1ebf63c1
commit
ec35d5c8e1
|
@ -1,126 +0,0 @@
|
|||
local wibox = wibox
|
||||
local widget = widget
|
||||
local screen = screen
|
||||
local image = image
|
||||
local button = button
|
||||
local table = table
|
||||
local ipairs = ipairs
|
||||
local awful = require("awful")
|
||||
local utils = require("freedesktop.utils")
|
||||
|
||||
module("freedesktop.desktop")
|
||||
|
||||
local current_pos = {}
|
||||
local iconsize = { width = 48, height = 48 }
|
||||
local labelsize = { width = 130, height = 20 }
|
||||
local margin = { x = 20, y = 20 }
|
||||
|
||||
function add_icon(settings)
|
||||
|
||||
local s = settings.screen
|
||||
|
||||
if not current_pos[s] then
|
||||
current_pos[s] = { x = (screen[s].geometry.width - iconsize.width - margin.x), y = 40 }
|
||||
end
|
||||
|
||||
local totheight = (settings.icon and iconsize.height or 0) + (settings.label and labelsize.height or 0)
|
||||
if totheight == 0 then return end
|
||||
|
||||
if current_pos[s].y + totheight > screen[s].geometry.height - 40 then
|
||||
current_pos[s].x = current_pos[s].x - labelsize.width - iconsize.width - margin.x
|
||||
current_pos[s].y = 40
|
||||
end
|
||||
|
||||
if (settings.icon) then
|
||||
icon = awful.widget.button({ image = settings.icon })
|
||||
local newbuttons = icon:buttons()
|
||||
table.insert(newbuttons, button({}, 1, nil, settings.click));
|
||||
icon:buttons(newbuttons)
|
||||
|
||||
icon_container = wibox({ position = "floating", screen = s, bg = "#00000000" })
|
||||
icon_container.widgets = { icon }
|
||||
icon_container:geometry({
|
||||
width = iconsize.width,
|
||||
height = iconsize.height,
|
||||
y = current_pos[s].y,
|
||||
x = current_pos[s].x
|
||||
})
|
||||
icon_container.screen = s
|
||||
|
||||
current_pos[s].y = current_pos[s].y + iconsize.height + 5
|
||||
end
|
||||
|
||||
if (settings.label) then
|
||||
caption = widget({ type="textbox", align="right", width=labelsize.width })
|
||||
caption.ellipsize = "middle"
|
||||
caption.text = settings.label
|
||||
caption:buttons({
|
||||
button({ }, 1, settings.click)
|
||||
})
|
||||
|
||||
caption_container = wibox({ position = "floating", screen = s, bg = "#00000000" })
|
||||
caption_container.widgets = { caption }
|
||||
caption_container:geometry({
|
||||
width = labelsize.width,
|
||||
height = labelsize.height,
|
||||
y = current_pos[s].y,
|
||||
x = current_pos[s].x - labelsize.width + iconsize.width
|
||||
})
|
||||
caption_container.screen = s
|
||||
end
|
||||
|
||||
current_pos[s].y = current_pos[s].y + labelsize.height + margin.y
|
||||
end
|
||||
|
||||
--- Adds subdirs and files icons to the desktop
|
||||
-- @param dir The directory to parse, (default is ~/Desktop)
|
||||
-- @param showlabels Shows icon captions (default is false)
|
||||
function add_applications_icons(arg)
|
||||
for i, program in ipairs(utils.parse_desktop_files({
|
||||
dir = arg.dir or '~/Desktop/',
|
||||
icon_sizes = {
|
||||
iconsize.width .. "x" .. iconsize.height,
|
||||
"128x128", "96x96", "72x72", "64x64", "48x48",
|
||||
"36x36", "32x32", "24x24", "22x22", "16x6"
|
||||
}
|
||||
})) do
|
||||
if program.show then
|
||||
add_icon({
|
||||
label = arg.showlabels and program.Name or nil,
|
||||
icon = program.icon_path,
|
||||
screen = arg.screen,
|
||||
click = function () awful.util.spawn(program.cmdline) end
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--- Adds subdirs and files icons to the desktop
|
||||
-- @param dir The directory to parse
|
||||
-- @param showlabels Shows icon captions
|
||||
-- @param open_with The program to use to open clicked files and dirs (i.e. xdg_open, thunar, etc.)
|
||||
function add_dirs_and_files_icons(arg)
|
||||
arg.open_with = arg.open_width or 'thunar'
|
||||
for i, file in ipairs(utils.parse_dirs_and_files({
|
||||
dir = arg.dir or '~/Desktop/',
|
||||
icon_sizes = {
|
||||
iconsize.width .. "x" .. iconsize.height,
|
||||
"128x128", "96x96", "72x72", "64x64", "48x48",
|
||||
"36x36", "32x32", "24x24", "22x22", "16x6"
|
||||
}
|
||||
})) do
|
||||
if file.show then
|
||||
add_icon({
|
||||
label = arg.showlabels and file.filename or nil,
|
||||
icon = file.icon,
|
||||
screen = arg.screen,
|
||||
click = function () awful.util.spawn(arg.open_with .. ' ' .. file.path) end
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function add_desktop_icons(args)
|
||||
add_applications_icons(args)
|
||||
add_dirs_and_files_icons(args)
|
||||
end
|
|
@ -1 +0,0 @@
|
|||
*.swp
|
|
@ -1,43 +0,0 @@
|
|||
Perceptive, a weather notification module for awesome
|
||||
================================
|
||||
|
||||
Perceptive is a module for awesome wm for brief and compact
|
||||
weather notification via naughty lib and Yahoo! Weather API.
|
||||
|
||||
Requirements
|
||||
------------
|
||||
- awesome 3.4 (awesome 3.5 is not supported yet)
|
||||
- /tmp directory (I'll store a temporary file over there.)
|
||||
- python 2.7
|
||||
|
||||
Usage
|
||||
-----
|
||||
Clone perceptive repository into your $XDG_CONFIG_HOME/awesome (awesome config dir).
|
||||
Then, add on top of rc.lua :
|
||||
|
||||
require("perceptive")
|
||||
|
||||
Bind perceptive notification to some widget:
|
||||
|
||||
perceptive.register(mytextclock, 2123260)
|
||||
|
||||
Where the second argument is so-called WOEID code of your city.
|
||||
To obtain it you can google 'yahoo weather %CITYNAME%' and follow the first link.
|
||||
It will look like http://weather.yahoo.com/united-states/california/san-diego-2487889/
|
||||
and the last number in that link will be the ID you need.
|
||||
|
||||
Screenshot
|
||||
-----
|
||||
![Screenshot][1]
|
||||
|
||||
[1]: http://github.com/ioga/perceptive/raw/master/screenshot.png
|
||||
|
||||
License
|
||||
-----
|
||||
Copyright (C) 2011-2013 Ilia Glazkov.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@ -1,83 +0,0 @@
|
|||
-- Perceptive, a weather notification module for Awesome WM.
|
||||
--
|
||||
-- Author: Ilia Glazkov
|
||||
|
||||
local naughty = naughty
|
||||
local timer = timer
|
||||
local io = require("io")
|
||||
local debug = require("debug")
|
||||
local string = string
|
||||
local print = print
|
||||
|
||||
module('perceptive')
|
||||
|
||||
local project_path = debug.getinfo(1, 'S').source:match[[^@(.*/).*$]]
|
||||
local script_path = project_path .. 'weather-fetcher.py'
|
||||
local script_cmd = script_path .. ' --id='
|
||||
local tmpfile = '/tmp/.awesome.weather'
|
||||
local weather_data = ""
|
||||
local notification = nil
|
||||
local pattern = '%a.+'
|
||||
local city_id = nil
|
||||
|
||||
|
||||
function execute(cmd, output, callback)
|
||||
-- Executes command line, writes its output to temporary file, and
|
||||
-- runs the callback with output as an argument.
|
||||
local cmdline = cmd .. " &> " .. output .. " & "
|
||||
io.popen(cmdline):close()
|
||||
|
||||
local execute_timer = timer({ timeout = 7 })
|
||||
execute_timer:add_signal("timeout", function()
|
||||
execute_timer:stop()
|
||||
local f = io.open(output)
|
||||
callback(f:read("*all"))
|
||||
f:close()
|
||||
end)
|
||||
execute_timer:start()
|
||||
end
|
||||
|
||||
|
||||
function fetch_weather()
|
||||
execute(script_cmd .. city_id, tmpfile, function(text)
|
||||
old_weather_data = weather_data
|
||||
weather_data = string.gsub(text, "[\n]$", "")
|
||||
if notification ~= nil and old_weather_data ~= weather_data then
|
||||
show_notification()
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
function remove_notification()
|
||||
if notification ~= nil then
|
||||
naughty.destroy(notification)
|
||||
notification = nil
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function show_notification()
|
||||
remove_notification()
|
||||
notification = naughty.notify({
|
||||
text = weather_data,
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
function register(widget, id)
|
||||
city_id = id
|
||||
update_timer = timer({ timeout = 600 })
|
||||
update_timer:add_signal("timeout", function()
|
||||
fetch_weather()
|
||||
end)
|
||||
update_timer:start()
|
||||
fetch_weather()
|
||||
|
||||
widget:add_signal("mouse::enter", function()
|
||||
show_notification()
|
||||
end)
|
||||
widget:add_signal("mouse::leave", function()
|
||||
remove_notification()
|
||||
end)
|
||||
end
|
Binary file not shown.
Before Width: | Height: | Size: 6.2 KiB |
|
@ -1,87 +0,0 @@
|
|||
#!/usr/bin/env python2.7
|
||||
# coding=utf-8
|
||||
"""Fetch weather using Yandex XML API."""
|
||||
|
||||
__author__ = "Ilia Glazkov"
|
||||
|
||||
import argparse
|
||||
from urllib2 import urlopen
|
||||
from xml.etree.ElementTree import ElementTree
|
||||
|
||||
|
||||
WEATHER_API_PREFIX = "http://weather.yahooapis.com/forecastrss?u=f&w="
|
||||
URLOPEN_TIMEOUT = 5
|
||||
|
||||
CELSIUS = '°F'
|
||||
DASH = "—"
|
||||
|
||||
CURRENT_DAY = 'Now'
|
||||
|
||||
|
||||
def weather_url_by_id(id):
|
||||
return WEATHER_API_PREFIX + str(id)
|
||||
|
||||
|
||||
def fetch_weather_tree(id):
|
||||
return ElementTree().parse(
|
||||
urlopen(weather_url_by_id(id), timeout=URLOPEN_TIMEOUT))
|
||||
|
||||
|
||||
def format_date_string(day, text, temp, max_temp=None):
|
||||
day = day or 'Now'
|
||||
|
||||
if max_temp:
|
||||
temp_string = DASH.join((str(temp), str(max_temp)))
|
||||
else:
|
||||
temp_string = str(temp)
|
||||
|
||||
return '%s: %s, %s%s.' % (day, text, temp_string, CELSIUS)
|
||||
|
||||
|
||||
class WeatherElement(object):
|
||||
def __init__(self, element):
|
||||
self.element = element
|
||||
|
||||
@property
|
||||
def day(self):
|
||||
return self.element.get('day') or CURRENT_DAY
|
||||
|
||||
@property
|
||||
def text(self):
|
||||
return self.element.get('text')
|
||||
|
||||
@property
|
||||
def temp(self):
|
||||
temp = self.element.get('temp')
|
||||
if temp is not None:
|
||||
return str(temp)
|
||||
|
||||
low, high = self.element.get('low'), self.element.get('high')
|
||||
if low is not None and high is not None:
|
||||
return DASH.join((str(low), str(high)))
|
||||
|
||||
def get_format_string(self):
|
||||
return '%s: %s, %s%s.' % (self.day, self.text, self.temp, CELSIUS)
|
||||
|
||||
|
||||
def get_weather_string(tree):
|
||||
condition = next(el for el in tree.iter()
|
||||
if el.tag.endswith('condition'))
|
||||
forecast = [el for el in tree.iter()
|
||||
if el.tag.endswith('forecast')]
|
||||
forecast.insert(0, condition)
|
||||
|
||||
return '\n'.join((
|
||||
WeatherElement(element).get_format_string()
|
||||
for element in forecast))
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--id', type=int, required=True,
|
||||
help='Yahoo WEOID of the city')
|
||||
args = parser.parse_args()
|
||||
print get_weather_string(fetch_weather_tree(args.id))
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
|
@ -1,54 +0,0 @@
|
|||
--Bitcoin
|
||||
--local t = timer({timeout = 300})
|
||||
--t:add_signal("timeout", function()
|
||||
--local f = io.popen("echo Bitcoin: $(/etc/wmii/bitcoin)", "r")
|
||||
--local s = f:read('*a')
|
||||
--f:close()
|
||||
--BTC.text = s
|
||||
--end)
|
||||
--t:emit_signal("timeout")
|
||||
--t:start()
|
||||
|
||||
--Return
|
||||
|
||||
--{BTC:"s",}
|
||||
|
||||
-- {{{ Grab environment
|
||||
local pairs = pairs
|
||||
local tonumber = tonumber
|
||||
local io = { popen = io.popen }
|
||||
local math = { ceil = math.ceil }
|
||||
local los = { getenv = os.getenv }
|
||||
local setmetatable = setmetatable
|
||||
local helpers = require("vicious.helpers")
|
||||
local string = {
|
||||
gsub = string.gsub,
|
||||
match = string.match
|
||||
}
|
||||
-- }}}
|
||||
|
||||
|
||||
-- OS: provides operating system information
|
||||
-- vicious.widgets.os
|
||||
local BTC = {}
|
||||
|
||||
|
||||
-- {{{ BTC widget type
|
||||
local function worker(format)
|
||||
local system = {
|
||||
["BTC"] = "N/A"
|
||||
}
|
||||
|
||||
-- BTC Command.
|
||||
if system["BTC"] == "N/A" then
|
||||
local f = io.popen("echo Bitcoin: $(/etc/wmii/bitcoin)")
|
||||
local uname = f:read("*line")
|
||||
f:close()
|
||||
|
||||
system["BTC"]
|
||||
|
||||
return {system["BTC"]}
|
||||
end
|
||||
-- }}}
|
||||
|
||||
return setmetatable(BTC, { __call = function(_, ...) return worker(...) end })
|
|
@ -1,11 +0,0 @@
|
|||
--Bitcoin
|
||||
BTC = widget({type="textbox"})
|
||||
local t = timer({timeout = 300})
|
||||
t:add_signal("timeout", function()
|
||||
local f = io.popen("echo Bitcoin: $(/etc/wmii/bitcoin)", "r")
|
||||
local s = f:read('*a')
|
||||
f:close()
|
||||
BTC.text = s
|
||||
end)
|
||||
t:emit_signal("timeout")
|
||||
t:start()
|
Loading…
Reference in New Issue