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