]> code.delx.au - offlineimap/blob - offlineimap/head/offlineimap/ui/Blinkenlights.py
f5814f52706628eca7e8ec51e0577ccc567cfd11
[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 import thread
21
22 class BlinkenBase:
23 """This is a mix-in class that should be mixed in with either UIBase
24 or another appropriate base class. The Tk interface, for instance,
25 will probably mix it in with VerboseUI."""
26
27 def acct(s, accountname):
28 s.gettf().setcolor('purple')
29 s.__class__.__bases__[-1].acct(s, accountname)
30
31 def connecting(s, hostname, port):
32 s.gettf().setcolor('gray')
33 s.__class__.__bases__[-1].connecting(s, hostname, port)
34
35 def syncfolders(s, srcrepos, destrepos):
36 s.gettf().setcolor('blue')
37 s.__class__.__bases__[-1].syncfolders(s, srcrepos, destrepos)
38
39 def syncingfolder(s, srcrepos, srcfolder, destrepos, destfolder):
40 s.gettf().setcolor('cyan')
41 s.__class__.__bases__[-1].syncingfolder(s, srcrepos, srcfolder, destrepos, destfolder)
42
43 def loadmessagelist(s, repos, folder):
44 s.gettf().setcolor('green')
45 s._msg("Scanning folder [%s/%s]" % (s.getnicename(repos),
46 folder.getvisiblename()))
47
48 def syncingmessages(s, sr, sf, dr, df):
49 s.gettf().setcolor('blue')
50 s.__class__.__bases__[-1].syncingmessages(s, sr, sf, dr, df)
51
52 def copyingmessage(s, uid, src, destlist):
53 s.gettf().setcolor('orange')
54 s.__class__.__bases__[-1].copyingmessage(s, uid, src, destlist)
55
56 def deletingmessages(s, uidlist, destlist):
57 s.gettf().setcolor('red')
58 s.__class__.__bases__[-1].deletingmessages(s, uidlist, destlist)
59
60 def deletingmessage(s, uid, destlist):
61 s.gettf().setcolor('red')
62 s.__class__.__bases__[-1].deletingmessage(s, uid, destlist)
63
64 def addingflags(s, uid, flags, destlist):
65 s.gettf().setcolor('yellow')
66 s.__class__.__bases__[-1].addingflags(s, uid, flags, destlist)
67
68 def deletingflags(s, uid, flags, destlist):
69 s.gettf().setcolor('pink')
70 s.__class__.__bases__[-1].deletingflags(s, uid, flags, destlist)
71
72 def init_banner(s):
73 s.availablethreadframes = {}
74 s.threadframes = {}
75 s.tflock = Lock()
76
77 def threadExited(s, thread):
78 threadid = thread.threadid
79 accountname = s.getthreadaccount(thread)
80 s.tflock.acquire()
81 try:
82 if threadid in s.threadframes[accountname]:
83 tf = s.threadframes[accountname][threadid]
84 del s.threadframes[accountname][threadid]
85 s.availablethreadframes[accountname].append(tf)
86 tf.setthread(None)
87 finally:
88 s.tflock.release()
89
90 UIBase.threadExited(s, thread)
91
92 def gettf(s):
93 threadid = thread.get_ident()
94 accountname = s.getthreadaccount()
95
96 s.tflock.acquire()
97
98 try:
99 if not accountname in s.threadframes:
100 s.threadframes[accountname] = {}
101
102 if threadid in s.threadframes[accountname]:
103 return s.threadframes[accountname][threadid]
104
105 if not accountname in s.availablethreadframes:
106 s.availablethreadframes[accountname] = []
107
108 if len(s.availablethreadframes[accountname]):
109 tf = s.availablethreadframes[accountname].pop(0)
110 tf.setthread(currentThread())
111 else:
112 tf = s.getaccountframe().getnewthreadframe()
113 s.threadframes[accountname][threadid] = tf
114 return tf
115
116 finally:
117 s.tflock.release()
118
119