Better widgets

This commit is contained in:
2018-11-28 15:31:35 +01:00
parent 0801659f6c
commit eff92f7e09
70 changed files with 2564 additions and 5 deletions

View File

@@ -0,0 +1,35 @@
# Email widget
This widget consists of an icon with counter which shows number of unread emails: ![email icon](./em-wid-1.png)
and a popup message which appears when mouse hovers over an icon: ![email popup](./em-wid-2.png)
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
```

View 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)

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

View 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)

View 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()