/offlineimap/head: changeset 317

Basic Tk.Blinkenlights structure completed. Need to fine-tune the
display. Sleeping API added to Blinkenlights base class.
This commit is contained in:
jgoerzen 2003-01-07 00:04:40 +01:00
parent c381f973f1
commit 6a0bbe2529
2 changed files with 83 additions and 67 deletions

View File

@ -119,4 +119,16 @@ class BlinkenBase:
finally: finally:
s.tflock.release() s.tflock.release()
def sleep(s, sleepsecs):
s.gettf().setcolor('red')
s.getaccountframe().startsleep(sleepsecs)
UIBase.sleep(s, sleepsecs)
def sleeping(s, sleepsecs, remainingsecs):
if remainingsecs and s.gettf().getcolor() == 'black':
s.gettf().setcolor('red')
else:
s.gettf().setcolor('black')
return s.getaccountframe().sleeping(sleepsecs, remainingsecs)

View File

@ -155,12 +155,12 @@ class VerboseUI(UIBase):
return 0 return 0
def _createTopWindow(self, doidlevac = 1): def _createTopWindow(self, doidlevac = 1):
self.threadframes = {}
self.availablethreadframes = []
self.tflock = Lock()
self.notdeleted = 1 self.notdeleted = 1
self.created = threading.Event() self.created = threading.Event()
self.af = {}
self.aflock = Lock()
t = threadutil.ExitNotifyThread(target = self._runmainloop, t = threadutil.ExitNotifyThread(target = self._runmainloop,
name = "Tk Mainloop") name = "Tk Mainloop")
t.setDaemon(1) t.setDaemon(1)
@ -182,6 +182,19 @@ class VerboseUI(UIBase):
s.top.mainloop() s.top.mainloop()
s.notdeleted = 0 s.notdeleted = 0
def getaccountframe(s):
accountname = s.getthreadaccount()
s.aflock.acquire()
try:
if accountname in s.af:
return s.af[accountname]
s.af[accountname] = LEDAccountFrame(s.top, accountname,
s.fontfamily, s.fontsize)
finally:
s.aflock.release()
return s.af[accountname]
def getpass(s, accountname, config, errmsg = None): def getpass(s, accountname, config, errmsg = None):
pd = PasswordDialog(accountname, config, errmsg = errmsg) pd = PasswordDialog(accountname, config, errmsg = errmsg)
return pd.getpassword() return pd.getpassword()
@ -310,7 +323,53 @@ TkUI = VerboseUI
################################################## Blinkenlights ################################################## Blinkenlights
class LEDAccountFrame:
def __init__(self, top, accountname, fontfamily, fontsize):
self.top = top
self.accountname = accountname
self.fontfamily = fontfamily
self.fontsize = fontsize
self.frame = Frame(self.top)
self.frame.pack(side = BOTTOM, expand = 0, fill = X)
self._createcanvas(self.frame)
self.label = Label(self.frame, text = accountname)
self.label.pack()
def getnewthreadframe(s):
return LEDThreadFrame(s.canvas)
def _createcanvas(self, parent):
c = LEDCanvas(parent, background = 'black', height = 20, bd = 0,
highlightthickness = 0)
c.setLEDCount(0)
c.createLEDLock()
self.canvas = c
c.pack(side = BOTTOM, expand = 0, fill = X)
def startsleep(s, sleepsecs):
print 351
s.sleeping_abort = 0
s.button = Button(s.frame, text = "Sync now", command = s.syncnow)
s.button.pack()
def syncnow(s):
print 357
s.sleeping_abort = 1
def sleeping(s, sleepsecs, remainingsecs):
print 360
if remainingsecs:
s.button.config(text = 'Sync now (%d:%02d remain)' % \
(remainingsecs / 60, remainingsecs % 60))
time.sleep(sleepsecs)
else:
s.button.destroy()
del s.button
return s.sleeping_abort
class LEDCanvas(Canvas): class LEDCanvas(Canvas):
"""This holds the different lights."""
def createLEDLock(self): def createLEDLock(self):
self.ledlock = Lock() self.ledlock = Lock()
def acquireLEDLock(self): def acquireLEDLock(self):
@ -325,6 +384,7 @@ class LEDCanvas(Canvas):
self.ledcount += 1 self.ledcount += 1
class LEDThreadFrame: class LEDThreadFrame:
"""There is one of these for each little light."""
def __init__(self, master): def __init__(self, master):
self.canvas = master self.canvas = master
self.color = '' self.color = ''
@ -352,23 +412,6 @@ class LEDThreadFrame:
else: else:
self.setcolor('black') self.setcolor('black')
def destroythreadextraframe(self):
pass
def getthreadextraframe(self):
raise NotImplementedError
def setaccount(self, account):
pass
def setmailbox(self, mailbox):
pass
def updateloclabel(self):
pass
def appendmessage(self, newtext):
pass
def setmessage(self, newtext):
pass
class Blinkenlights(BlinkenBase, VerboseUI): class Blinkenlights(BlinkenBase, VerboseUI):
def __init__(s, config, verbose = 0): def __init__(s, config, verbose = 0):
@ -384,12 +427,7 @@ class Blinkenlights(BlinkenBase, VerboseUI):
VerboseUI._createTopWindow(self, 0) VerboseUI._createTopWindow(self, 0)
#self.top.resizable(width = 0, height = 0) #self.top.resizable(width = 0, height = 0)
self.top.configure(background = 'black', bd = 0) self.top.configure(background = 'black', bd = 0)
c = LEDCanvas(self.top, background = 'black', height = 20, bd = 0,
highlightthickness = 0)
c.setLEDCount(0)
c.createLEDLock()
self.canvas = c
c.pack(side = BOTTOM, expand = 0, fill = X)
widthmetric = tkFont.Font(family = self.fontfamily, size = self.fontsize).measure("0") widthmetric = tkFont.Font(family = self.fontfamily, size = self.fontsize).measure("0")
self.loglines = 5 self.loglines = 5
if self.config.has_option("ui.Tk.Blinkenlights", "loglines"): if self.config.has_option("ui.Tk.Blinkenlights", "loglines"):
@ -414,10 +452,8 @@ class Blinkenlights(BlinkenBase, VerboseUI):
self.tags = [] self.tags = []
self.textlock = Lock() self.textlock = Lock()
def gettf(s, newtype=LEDThreadFrame):
return VerboseUI.gettf(s, newtype, s.canvas)
def init_banner(s): def init_banner(s):
BlinkenBase.init_banner(s)
s._createTopWindow() s._createTopWindow()
menubar = Menu(s.top, activebackground = "black", menubar = Menu(s.top, activebackground = "black",
activeforeground = "white", activeforeground = "white",
@ -436,14 +472,6 @@ class Blinkenlights(BlinkenBase, VerboseUI):
if s.config.has_option("ui.Tk.Blinkenlights", "showlog") and \ if s.config.has_option("ui.Tk.Blinkenlights", "showlog") and \
s.config.getboolean("ui.Tk.Blinkenlights", "showlog"): s.config.getboolean("ui.Tk.Blinkenlights", "showlog"):
s._togglelog() s._togglelog()
#s.tflock.acquire()
#try:
# for i in range(s.top.winfo_reqwidth() / 10 - 1):
# newframe = LEDThreadFrame(s.canvas)
# newframe.setthread(None)
# s.availablethreadframes.append(newframe)
#finally:
# s.tflock.release()
def _togglelog(s): def _togglelog(s):
if s.textenabled: if s.textenabled:
@ -466,25 +494,14 @@ class Blinkenlights(BlinkenBase, VerboseUI):
s._rescroll() s._rescroll()
s.top.resizable(width = 1, height = 1) s.top.resizable(width = 1, height = 1)
def threadExited(s, thread):
threadid = thread.threadid
s.tflock.acquire()
try:
if threadid in s.threadframes:
tf = s.threadframes[threadid]
del s.threadframes[threadid]
s.availablethreadframes.append(tf)
tf.setthread(None)
finally:
s.tflock.release()
def sleep(s, sleepsecs): def sleep(s, sleepsecs):
s.sleeping_abort = 0
s.menubar.add_command(label = "Sync now", command = s._sleep_cancel)
s.gettf().setcolor('red') s.gettf().setcolor('red')
s._msg("Next sync in %d:%02d" % (sleepsecs / 60, sleepsecs % 60)) s._msg("Next sync in %d:%02d" % (sleepsecs / 60, sleepsecs % 60))
UIBase.sleep(s, sleepsecs) BlinkenBase.sleep(s, sleepsecs)
def sleeping(s, sleepsecs, remainingsecs):
print 503
return BlinkenBase.sleeping(s, sleepsecs, remainingsecs)
def _rescroll(s): def _rescroll(s):
s.text.see(END) s.text.see(END)
@ -496,7 +513,7 @@ class Blinkenlights(BlinkenBase, VerboseUI):
for thisline in msg.split("\n"): for thisline in msg.split("\n"):
s._msg(thisline) s._msg(thisline)
return return
VerboseUI._msg(s, msg) #VerboseUI._msg(s, msg)
color = s.gettf().getcolor() color = s.gettf().getcolor()
rescroll = 1 rescroll = 1
s.textlock.acquire() s.textlock.acquire()
@ -520,17 +537,4 @@ class Blinkenlights(BlinkenBase, VerboseUI):
s.text.config(state = DISABLED) s.text.config(state = DISABLED)
s.textlock.release() s.textlock.release()
def sleeping(s, sleepsecs, remainingsecs):
if remainingsecs:
s.menubar.entryconfig('end', label = "Sync now (%d:%02d remain)" % \
(remainingsecs / 60, remainingsecs % 60))
if s.gettf().getcolor() == 'red':
s.gettf().setcolor('black')
else:
s.gettf().setcolor('red')
time.sleep(sleepsecs)
else:
s.menubar.delete('end')
s.gettf().setcolor('black')
return s.sleeping_abort