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