Better widgets
This commit is contained in:
35
awesome-wm-widgets/email-widget/README.md
Normal file
35
awesome-wm-widgets/email-widget/README.md
Normal file
@@ -0,0 +1,35 @@
|
||||
# Email widget
|
||||
|
||||
This widget consists of an icon with counter which shows number of unread emails: 
|
||||
and a popup message which appears when mouse hovers over an icon: 
|
||||
|
||||
Note that widget uses the Arc icon theme, so it should be [installed](https://github.com/horst3180/arc-icon-theme#installation) first under **/usr/share/icons/Arc/** folder.
|
||||
|
||||
## Installation
|
||||
|
||||
To install it put **email.lua** and **email-widget** folder under **~/.config/awesome**. Then
|
||||
|
||||
- in **email.lua** cahnge path to python scripts;
|
||||
- in python scripts add your credentials (note that password should be encrypted using pgp for example);
|
||||
- add widget to awesome:
|
||||
|
||||
```lua
|
||||
require("email")
|
||||
...
|
||||
s.mytasklist, -- Middle widget
|
||||
{ -- Right widgets
|
||||
layout = wibox.layout.fixed.horizontal,
|
||||
...
|
||||
email_icon,
|
||||
email_widget,
|
||||
...
|
||||
```
|
||||
|
||||
## How it works
|
||||
|
||||
This widget uses the output of two python scripts, first is called every 20 seconds - it returns number of unread emails and second is called when mouse hovers over an icon and displays content of those emails. For both of them you'll need to provide your credentials and imap server. For testing they can simply be called from console:
|
||||
|
||||
``` bash
|
||||
python ~/.config/awesome/email/count_unread_emails.py
|
||||
python ~/.config/awesome/email/read_emails.py
|
||||
```
|
||||
16
awesome-wm-widgets/email-widget/count_unread_emails.py
Normal file
16
awesome-wm-widgets/email-widget/count_unread_emails.py
Normal file
@@ -0,0 +1,16 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import imaplib
|
||||
import email
|
||||
|
||||
M=imaplib.IMAP4_SSL("mail.teenagemutantninjaturtles.com", 993)
|
||||
M.login("mickey@tmnt.com","cowabunga")
|
||||
|
||||
status, counts = M.status("INBOX","(MESSAGES UNSEEN)")
|
||||
|
||||
if status == "OK":
|
||||
unread = counts[0].split()[4][:-1]
|
||||
else:
|
||||
unread = "N/A"
|
||||
|
||||
print(unread)
|
||||
BIN
awesome-wm-widgets/email-widget/em-wid-1.png
Normal file
BIN
awesome-wm-widgets/email-widget/em-wid-1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.8 KiB |
BIN
awesome-wm-widgets/email-widget/em-wid-2.png
Normal file
BIN
awesome-wm-widgets/email-widget/em-wid-2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 38 KiB |
42
awesome-wm-widgets/email-widget/email.lua
Normal file
42
awesome-wm-widgets/email-widget/email.lua
Normal file
@@ -0,0 +1,42 @@
|
||||
local wibox = require("wibox")
|
||||
local awful = require("awful")
|
||||
local naughty = require("naughty")
|
||||
local watch = require("awful.widget.watch")
|
||||
|
||||
local path_to_icons = "/usr/share/icons/Arc/actions/22/"
|
||||
|
||||
email_widget = wibox.widget.textbox()
|
||||
email_widget:set_font('Play 9')
|
||||
|
||||
email_icon = wibox.widget.imagebox()
|
||||
email_icon:set_image(path_to_icons .. "/mail-mark-new.png")
|
||||
|
||||
watch(
|
||||
"python /home/<username>/.config/awesome/email-widget/count_unread_emails.py", 20,
|
||||
function(widget, stdout, stderr, exitreason, exitcode)
|
||||
local unread_emails_num = tonumber(stdout) or 0
|
||||
if (unread_emails_num > 0) then
|
||||
email_icon:set_image(path_to_icons .. "/mail-mark-unread.png")
|
||||
email_widget:set_text(stdout)
|
||||
elseif (unread_emails_num == 0) then
|
||||
email_icon:set_image(path_to_icons .. "/mail-message-new.png")
|
||||
email_widget:set_text("")
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
|
||||
function show_emails()
|
||||
awful.spawn.easy_async([[bash -c 'python /home/<username>/.config/awesome/email-widget/read_unread_emails.py']],
|
||||
function(stdout, stderr, reason, exit_code)
|
||||
naughty.notify{
|
||||
text = stdout,
|
||||
title = "Unread Emails",
|
||||
timeout = 5, hover_timeout = 0.5,
|
||||
width = 400,
|
||||
}
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
email_icon:connect_signal("mouse::enter", function() show_emails() end)
|
||||
42
awesome-wm-widgets/email-widget/read_unread_emails.py
Normal file
42
awesome-wm-widgets/email-widget/read_unread_emails.py
Normal file
@@ -0,0 +1,42 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import imaplib
|
||||
import email
|
||||
import datetime
|
||||
|
||||
def process_mailbox(M):
|
||||
rv, data = M.search(None, "(UNSEEN)")
|
||||
if rv != 'OK':
|
||||
print "No messages found!"
|
||||
return
|
||||
|
||||
for num in data[0].split():
|
||||
rv, data = M.fetch(num, '(BODY.PEEK[])')
|
||||
if rv != 'OK':
|
||||
print "ERROR getting message", num
|
||||
return
|
||||
|
||||
msg = email.message_from_string(data[0][1])
|
||||
print 'From:', msg['From']
|
||||
print 'Subject: %s' % (msg['Subject'])
|
||||
date_tuple = email.utils.parsedate_tz(msg['Date'])
|
||||
if date_tuple:
|
||||
local_date = datetime.datetime.fromtimestamp(email.utils.mktime_tz(date_tuple))
|
||||
print "Local Date:", local_date.strftime("%a, %d %b %Y %H:%M:%S")
|
||||
# with code below you can process text of email
|
||||
# if msg.is_multipart():
|
||||
# for payload in msg.get_payload():
|
||||
# if payload.get_content_maintype() == 'text':
|
||||
# print payload.get_payload()
|
||||
# else:
|
||||
# print msg.get_payload()
|
||||
|
||||
|
||||
M=imaplib.IMAP4_SSL("mail.teenagemutantninjaturtles.com", 993)
|
||||
M.login("mickey@tmnt.com","cowabunga")
|
||||
|
||||
rv, data = M.select("INBOX")
|
||||
if rv == 'OK':
|
||||
process_mailbox(M)
|
||||
M.close()
|
||||
M.logout()
|
||||
Reference in New Issue
Block a user