]> code.delx.au - offlineimap/blob - offlineimap/head/offlineimap/ui/Blinkenlights.py
/offlineimap/head: changeset 314
[offlineimap] / offlineimap / head / offlineimap / ui / Blinkenlights.py
1 # Blinkenlights base classes
2 # Copyright (C) 2003 John Goerzen
3 # <jgoerzen@complete.org>
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19 from threading import *
20 from offlineimap.ui.UIBase import UIBase
21 import thread
22 from offlineimap.threadutil import MultiLock
23
24 from debuglock import DebuggingLock
25
26 class BlinkenBase:
27 """This is a mix-in class that should be mixed in with either UIBase
28 or another appropriate base class. The Tk interface, for instance,
29 will probably mix it in with VerboseUI."""
30
31 def acct(s, accountname):
32 s.gettf().setcolor('purple')
33 s.__class__.__bases__[-1].acct(s, accountname)
34
35 def connecting(s, hostname, port):
36 s.gettf().setcolor('gray')
37 s.__class__.__bases__[-1].connecting(s, hostname, port)
38
39 def syncfolders(s, srcrepos, destrepos):
40 s.gettf().setcolor('blue')
41 s.__class__.__bases__[-1].syncfolders(s, srcrepos, destrepos)
42
43 def syncingfolder(s, srcrepos, srcfolder, destrepos, destfolder):
44 s.gettf().setcolor('cyan')
45 s.__class__.__bases__[-1].syncingfolder(s, srcrepos, srcfolder, destrepos, destfolder)
46
47 def loadmessagelist(s, repos, folder):
48 s.gettf().setcolor('green')
49 s._msg("Scanning folder [%s/%s]" % (s.getnicename(repos),
50 folder.getvisiblename()))
51
52 def syncingmessages(s, sr, sf, dr, df):
53 s.gettf().setcolor('blue')
54 s.__class__.__bases__[-1].syncingmessages(s, sr, sf, dr, df)
55
56 def copyingmessage(s, uid, src, destlist):
57 s.gettf().setcolor('orange')
58 s.__class__.__bases__[-1].copyingmessage(s, uid, src, destlist)
59
60 def deletingmessages(s, uidlist, destlist):
61 s.gettf().setcolor('red')
62 s.__class__.__bases__[-1].deletingmessages(s, uidlist, destlist)
63
64 def deletingmessage(s, uid, destlist):
65 s.gettf().setcolor('red')
66 s.__class__.__bases__[-1].deletingmessage(s, uid, destlist)
67
68 def addingflags(s, uid, flags, destlist):
69 s.gettf().setcolor('yellow')
70 s.__class__.__bases__[-1].addingflags(s, uid, flags, destlist)
71
72 def deletingflags(s, uid, flags, destlist):
73 s.gettf().setcolor('pink')
74 s.__class__.__bases__[-1].deletingflags(s, uid, flags, destlist)
75
76 def init_banner(s):
77 s.availablethreadframes = {}
78 s.threadframes = {}
79 s.tflock = MultiLock()
80
81 def threadExited(s, thread):
82 threadid = thread.threadid
83 accountname = s.getthreadaccount(thread)
84 s.tflock.acquire()
85 try:
86 if threadid in s.threadframes[accountname]:
87 tf = s.threadframes[accountname][threadid]
88 del s.threadframes[accountname][threadid]
89 s.availablethreadframes[accountname].append(tf)
90 tf.setthread(None)
91 finally:
92 s.tflock.release()
93
94 UIBase.threadExited(s, thread)
95
96 def gettf(s):
97 threadid = thread.get_ident()
98 accountname = s.getthreadaccount()
99
100 s.tflock.acquire()
101
102 try:
103 if not accountname in s.threadframes:
104 s.threadframes[accountname] = {}
105
106 if threadid in s.threadframes[accountname]:
107 return s.threadframes[accountname][threadid]
108
109 if not accountname in s.availablethreadframes:
110 s.availablethreadframes[accountname] = []
111
112 if len(s.availablethreadframes[accountname]):
113 tf = s.availablethreadframes[accountname].pop(0)
114 tf.setthread(currentThread())
115 else:
116 tf = s.getaccountframe().getnewthreadframe()
117 s.threadframes[accountname][threadid] = tf
118 return tf
119 finally:
120 s.tflock.release()
121
122