Created
July 28, 2012 13:08
-
-
Save metachu/3193306 to your computer and use it in GitHub Desktop.
Org mode agenda for awesome-wm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local string = string | |
--local print = print | |
local tostring = tostring | |
local io = io | |
local table = table | |
local pairs = pairs | |
local capi = { | |
mouse = mouse, | |
screen = screen | |
} | |
local awful = require("awful") | |
local naughty = require("naughty") | |
local beautiful = require('beautiful') | |
local popup | |
-- CHANGE THIS TO POINT TO THE org-agenda.py FILE--!!!!!!!!!!!!!! | |
local script_location = "/home/chu/Dropbox/scripts/org-agenda.py" | |
--^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
module("metachuorg") | |
function addToWidget(mywidget) | |
mywidget:add_signal('mouse::enter', function () | |
local info = create_popup() -- info | |
popup = naughty.notify({ | |
title = '<span font = "monospace 13">Org Mode by Metachu</span>', | |
text = info, | |
timeout = 0, | |
hover_timeout = 0.5, | |
width = (80 + 3) * 10, | |
screen = capi.mouse.screen | |
}) | |
end) | |
mywidget:add_signal('mouse::leave', function () naughty.destroy(popup) end) | |
end | |
function create_popup() | |
local info = "" | |
local count = 0 | |
lines = {} | |
-- Recursively find new messages | |
local f = io.popen("python "..script_location) | |
for line in f:lines() do | |
table.insert(lines,line.."\n") | |
end | |
f:close() | |
for m=1, #lines do | |
info = info .. lines[m] | |
end | |
return info | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import calendar | |
import subprocess | |
import os | |
import re | |
import datetime | |
now = datetime.datetime.now() | |
#Set your emacs path here (.emacs ifyou use one) | |
emacs_path = '~/.emacs.d/init.el' | |
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
#Adjust your org-agenda command. | |
# More info http://orgmode.org/manual/Extracting-agenda-information.html | |
org_command = """(org-batch-agenda-csv "a" org-agenda-span (quote month))""" | |
default_font= "monospace 10" | |
#extract emacs customize variables to determine org files | |
emacs_file = open(os.path.expanduser(emacs_path),'r') | |
data = emacs_file.read() | |
emacs_file.close() | |
org_files = re.findall('org-agenda-files.*(\(".*"\))',data,re.MULTILINE)[0] | |
command = """(progn (setq org-agenda-files '%s) %s )""" % (org_files,org_command) | |
#run batch command with minimal emacs file loading | |
emacs_output= subprocess.check_output(["emacs","-batch","-eval",command],stderr=open(os.devnull,'w')) | |
#Setup empty lists | |
todolist = [] | |
day_agenda_list = [[] for i in range(7)] | |
def format_wrapper(message,fcolor="",bcolor="",weight="normal",font=default_font): | |
'''Handy function to wrap and format to AWESOMES pango script''' | |
if fcolor and bcolor: | |
return '<span weight="%s" font="%s" background="%s" foreground="%s">%s</span>'%(weight,font,bcolor,fcolor,message) | |
elif fcolor: | |
return '<span weight = "%s" font="%s" foreground="%s">%s</span>'%(weight,font,fcolor,message) | |
elif bcolor: | |
return '<span weight = "%s" font="%s" background="%s">%s</span>'%(weight,font,bcolor,message) | |
else: | |
return '<span weight = "%s" font="%s" >%s</span>'%(weight,font,message) | |
#Surround everything by default font size | |
print '<span font = "%s" >'%default_font | |
for item in emacs_output.split("\n"): | |
s = item.split(",") | |
if len(s)>1: | |
todo = {} | |
todo['category'] = s[0] | |
todo['head'] = s[1] | |
todo['type'] = s[2] | |
todo['todo'] = s[3] | |
todo['tags'] = s[4] | |
todo['date'] = s[5] | |
todo['pydate'] = datetime.datetime.strptime(s[5],"%Y-%m-%d") | |
todo['time'] = s[6] | |
todo['fcolor'] = "" | |
todo['bcolor'] = "" | |
#SETUP YOUR TAG SPECIFIC COLORS | |
if "urgent" in todo['tags']: | |
todo['fcolor'] = "#59F030" | |
todo['bcolor'] = "#212121" | |
elif "assignment" in todo ['tags']: | |
todo['fcolor'] = "#ff9800" | |
todo['bcolor'] = "#515151" | |
todolist.append(todo) | |
day_diff = todo['pydate'].day-now.day | |
if day_diff<7: # attach todo items to week agenda | |
day_agenda_list[day_diff].append(todo) | |
#Print the day agenda with formating | |
for idx,day_list in enumerate(day_agenda_list): | |
cdate = now+datetime.timedelta(days=idx) | |
msg = "{0:10}".format(cdate.strftime("%A"))+cdate.strftime("%d %b %y") | |
print format_wrapper(msg,"#33aaff",weight="bold") | |
for todo in day_list: | |
msg = "\t[%s] %s %s"%(todo['type'],todo['head'],todo['tags']) | |
print format_wrapper(msg,todo['fcolor'],todo['bcolor']) | |
#Regex replace script for the calendar | |
def replace(match): | |
fcolor = "" | |
bcolor = "" | |
day = int(match.group(0)) | |
weight="normal" | |
if day == now.day: | |
bcolor = "#CD0074" | |
for todo in todolist: | |
d = todo['pydate'].day | |
if todo['pydate'].month == now.month and d==day : | |
fcolor = todo['fcolor'] | |
weight = "bold" | |
return format_wrapper(day,fcolor,bcolor,weight) | |
# Print out the calendar | |
print re.sub("[0-9]+",replace,calendar.TextCalendar().formatmonth(now.year,now.month)) | |
print "</span>" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--... other stuff above | |
-- Create a textclock widget | |
mytextclock = awful.widget.textclock({ align = "right" }) | |
-- metachu stuff | |
require('metachuorg') | |
metachuorg.addToWidget(mytextclock) | |
-- ... insert code below text clock widget |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment