~ubuntu-branches/ubuntu/edgy/mailcrypt/edgy

« back to all changes in this revision

Viewing changes to tests/remailer/maildirgtk.py

  • Committer: Bazaar Package Importer
  • Author(s): Davide G. M. Salvetti
  • Date: 2005-10-10 17:49:17 UTC
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20051010174917-rw6qn4l26eodin5q
Tags: upstream-3.5.8+CVS.2005.04.29.1
ImportĀ upstreamĀ versionĀ 3.5.8+CVS.2005.04.29.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/python
 
2
 
 
3
# This is a class which watches a maildir for new messages. It uses the
 
4
# linux dirwatcher API (if available) to look for new files. The
 
5
# .messageReceived method is invoked with the filename of the new message,
 
6
# relative to the top of the maildir (so it will look like "new/blahblah").
 
7
 
 
8
# This form uses the Gtk event loop to handle polling and signal safety
 
9
 
 
10
if __name__ == '__main__':
 
11
    import pygtk
 
12
    pygtk.require("2.0")
 
13
 
 
14
import gtk
 
15
from maildir import Maildir
 
16
 
 
17
class MaildirGtk(Maildir):
 
18
    def __init__(self, basedir):
 
19
        Maildir.__init__(self, basedir)
 
20
        self.idler = None
 
21
    def startTimeout(self):
 
22
        self.timeout = gtk.timeout_add(self.pollinterval*1000, self.doTimeout)
 
23
    def doTimeout(self):
 
24
        self.poll()
 
25
        return gtk.TRUE # keep going
 
26
    def stopTimeout(self):
 
27
        if self.timeout:
 
28
            gtk.timeout_remove(self.timeout)
 
29
            self.timeout = None
 
30
    def dnotify_callback(self):
 
31
        # make it safe
 
32
        self.idler = gtk.idle_add(self.idlePoll)
 
33
    def idlePoll(self):
 
34
        gtk.idle_remove(self.idler)
 
35
        self.idler = None
 
36
        self.poll()
 
37
        return gtk.FALSE
 
38
 
 
39
def test1():
 
40
    class MaildirTest(MaildirGtk):
 
41
        def messageReceived(self, filename):
 
42
            print "changed:", filename
 
43
    m = MaildirTest("ddir")
 
44
    print "watching ddir/new/"
 
45
    m.start()
 
46
    #gtk.main()
 
47
    # to allow the python-side signal handler to run, we must surface from
 
48
    # gtk (which blocks on the C-side) every once in a while.
 
49
    while 1:
 
50
        gtk.mainiteration() # this will block until there is something to do
 
51
    m.stop()
 
52
    print "done"
 
53
    
 
54
if __name__ == '__main__':
 
55
    test1()