]> code.delx.au - offlineimap/blob - offlineimap/ui/Blinkenlights.py
Merge branch 'master' of http://git.complete.org/offlineimap
[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 skippingfolder(s, folder):
46 s.gettf().setcolor('cyan')
47 s.__class__.__bases__[-1].skippingfolder(s, folder)
48
49 def loadmessagelist(s, repos, folder):
50 s.gettf().setcolor('green')
51 s._msg("Scanning folder [%s/%s]" % (s.getnicename(repos),
52 folder.getvisiblename()))
53
54 def syncingmessages(s, sr, sf, dr, df):
55 s.gettf().setcolor('blue')
56 s.__class__.__bases__[-1].syncingmessages(s, sr, sf, dr, df)
57
58 def copyingmessage(s, uid, src, destlist):
59 s.gettf().setcolor('orange')
60 s.__class__.__bases__[-1].copyingmessage(s, uid, src, destlist)
61
62 def deletingmessages(s, uidlist, destlist):
63 s.gettf().setcolor('red')
64 s.__class__.__bases__[-1].deletingmessages(s, uidlist, destlist)
65
66 def deletingmessage(s, uid, destlist):
67 s.gettf().setcolor('red')
68 s.__class__.__bases__[-1].deletingmessage(s, uid, destlist)
69
70 def addingflags(s, uidlist, flags, destlist):
71 s.gettf().setcolor('yellow')
72 s.__class__.__bases__[-1].addingflags(s, uidlist, flags, destlist)
73
74 def deletingflags(s, uidlist, flags, destlist):
75 s.gettf().setcolor('pink')
76 s.__class__.__bases__[-1].deletingflags(s, uidlist, flags, destlist)
77
78 def warn(s, msg, minor = 0):
79 if minor:
80 s.gettf().setcolor('pink')
81 else:
82 s.gettf().setcolor('red')
83 s.__class__.__bases__[-1].warn(s, msg, minor)
84
85 def init_banner(s):
86 s.availablethreadframes = {}
87 s.threadframes = {}
88 s.tflock = MultiLock()
89
90 def threadExited(s, thread):
91 threadid = thread.threadid
92 accountname = s.getthreadaccount(thread)
93 s.tflock.acquire()
94 try:
95 if threadid in s.threadframes[accountname]:
96 tf = s.threadframes[accountname][threadid]
97 del s.threadframes[accountname][threadid]
98 s.availablethreadframes[accountname].append(tf)
99 tf.setthread(None)
100 finally:
101 s.tflock.release()
102
103 UIBase.threadExited(s, thread)
104
105 def gettf(s):
106 threadid = thread.get_ident()
107 accountname = s.getthreadaccount()
108
109 s.tflock.acquire()
110
111 try:
112 if not accountname in s.threadframes:
113 s.threadframes[accountname] = {}
114
115 if threadid in s.threadframes[accountname]:
116 return s.threadframes[accountname][threadid]
117
118 if not accountname in s.availablethreadframes:
119 s.availablethreadframes[accountname] = []
120
121 if len(s.availablethreadframes[accountname]):
122 tf = s.availablethreadframes[accountname].pop(0)
123 tf.setthread(currentThread())
124 else:
125 tf = s.getaccountframe().getnewthreadframe()
126 s.threadframes[accountname][threadid] = tf
127 return tf
128 finally:
129 s.tflock.release()
130
131 def callhook(s, msg):
132 s.gettf().setcolor('white')
133 s.__class__.__bases__[-1].callhook(s, msg)
134
135 def sleep(s, sleepsecs, siglistener):
136 s.gettf().setcolor('red')
137 s.getaccountframe().startsleep(sleepsecs)
138 return UIBase.sleep(s, sleepsecs, siglistener)
139
140 def sleeping(s, sleepsecs, remainingsecs):
141 if remainingsecs and s.gettf().getcolor() == 'black':
142 s.gettf().setcolor('red')
143 else:
144 s.gettf().setcolor('black')
145 return s.getaccountframe().sleeping(sleepsecs, remainingsecs)
146
147