[Xmonad] Re: How to combine xmonad with Ubuntu? (offtopic)

Sébastien Gross seb-xmonad at chezwam.org
Tue Sep 11 10:41:16 EDT 2007


On Tue, Sep 11, 2007 at 03:28:02PM +0100, A.M.Gimblett at swansea.ac.uk wrote:
> That's nice.  Alas, now you have me distracted from my thesis and
> wanting to write something which works similarly but instead pops up a
> "U" or something on my dzen2 statusbar.  ;-)
> 
> (Though, that might be too subtle - my laptop keeps shutting itself
> down because I fail to keep an eye on the statusbar; I need to pop
> something up with xmessage or xosd or something (what's nice for
> this?). More hacking!  Anyway, back to it...)

I wrote a similar tool in python to be used whithin procmail.


put this in your .procmailrc:

:0icw
| mail-popup -y 1024 -x 1280 -f


It is in attachement. It should work out-of-the-box


Cheers

-- 
Sébastien Gross
-------------- next part --------------
#!/usr/bin/python

# Copyright (c) 2007 Sebastien Gross <sjg at easynet.fr>
# Released under GPL, see http://gnu.org for further information.


import email
import email.Header
import sys
import os
from optparse import OptionParser
import locale

def read_mail(opts):
#  print "export LC_ALL='%s'" % opts['locale']
  locale.setlocale(locale.LC_ALL, opts['locale'])
  #locale.setlocale(locale.LANG, opts['locale'])
  # parse msg
  msg_str = sys.stdin.read()
  msg = email.message_from_string(msg_str)
  #get header
  fields = ['From', 'Subject', 'Date']
  lines = opts['lines'] + len(fields)
  header = {}
  for type in fields:
    _h = email.Header.decode_header(msg.get(type))
    line = []
    for part in _h:
      if part[1] is None:
        #pass
        line.append(part[0])
      else:
        line.append(part[0].decode(part[1]).encode('latin-1'))
    header[type] = ' '.join(line)
  cs = msg.get_content_charset()
  if cs is None:
    cs = 'iso8859-15'
  # get the body
  try:
    body = msg.get_payload()[0].get_payload(decode=True).split('\n')
  except:
    body = msg.get_payload(decode=True).split('\n')
  if len(body) > opts['lines']:
    b_str = '\n'.join(body[0:opts['lines'] - 1]).decode(cs).encode('iso8859-15')
  else:
    b_str = '\n'.join(body).decode(cs).encode('iso8859-15')
  if opts['folded']:
    action='entertitle=uncollapse;leaveslave=collapse;button3=togglecollapse;'
    #enterslave=uncollapse;leaveslave=collapse;'
    # assume  status bar=16px font heigth=16 + 1-line title
    y = opts['height'] - 14 #- 16 #+ 1
  else:
    action='onstart=uncollapse;'
    # Assume status bar=16px font heigth=16 + 2-line title
    y = opts['height'] - lines * 14
  # assume window width = 400
  x = opts['width'] - opts['window_width']
  #print "x=%i y=%i" %(x, y)
  cmd_str = (
    'dzen2', '-p', str(opts['peristant']), '-l', str(lines),
    '-fn', '-xos4-terminus-medium-r-normal--12-*-*-*-*-*-iso8859-1',
    '-e', '%sbutton1=exit;' % action,
    '-bg', opts['background'], '-fg', opts['foreground'],
    '-ta', 'l', '-y', str(y), '-x', str(x), '-w', str(opts['window_width']))
  #print ' '.join(cmd_str)
  (c_in, c_out, c_err) = os.popen3(cmd_str)
  if opts['folded']:
    c_in.write('^fg(white) New mail from %s^fg()\n' % (header['From']))
    c_in.write('^fg(red)From: ^fg(green)%s^fg()\n' % (header['From']))
  else:
    c_in.write('^fg(red)From: ^fg(green)%s^fg()\n' % (header['From']))
  for f in fields[1:]:
    c_in.write('^fg(red)%s: ^fg(white)%s^fg()\n' % (f, header[f]))
  c_in.write('\n%s\n' % b_str)
  c_in.close()
  c_out.close()
  c_err.close()

def parse_opts():
  p = OptionParser()
  p.add_option("-x", "--width", help="Width of screen", metavar="PIXEL", default=0, type="int")
  p.add_option("-y", "--height", help="Height of screen", metavar="PIXEL", default=0, type="int")
  p.add_option("-w", "--window-width", help="Width of window", metavar="PIXEL", default=450, type="int")
  p.add_option("-l", "--lines", help="Lines to display", metavar="LINES", default=5, type="int")
  p.add_option("", "--background", help="Background color", metavar="COLOR", default="black")
  p.add_option("", "--foreground", help="Foreground color", metavar="COLOR", default="#a8a3f7")
  p.add_option("-p", "--peristant", help="Delay", metavar="SEC", default=5, type="int")
  p.add_option("-f", "--folded", help="Display folded window", metavar="BOOL", action="store_true", default=False)
  p.add_option("-L", "--locale", help="Locale", metavar="LOCALE", default='fr_FR at euro')
  (options, args) = p.parse_args()
  return options.__dict__


def __init__():
  opts = parse_opts()
  #print opts
  read_mail(opts)

if __name__ == '__main__':
  __init__()

# vim:ts=2:set expandtab:


More information about the Xmonad mailing list