2002-07-11 07:38:14 +02:00
|
|
|
# Tk UI
|
2003-01-05 04:35:36 +01:00
|
|
|
# Copyright (C) 2002, 2003 John Goerzen
|
2002-07-11 07:38:14 +02:00
|
|
|
# <jgoerzen@complete.org>
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
2003-04-16 21:23:45 +02:00
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
2002-07-11 07:38:14 +02:00
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
2003-01-06 23:15:15 +01:00
|
|
|
from __future__ import nested_scopes
|
|
|
|
|
2002-07-11 08:53:09 +02:00
|
|
|
from Tkinter import *
|
2002-07-25 00:04:22 +02:00
|
|
|
import tkFont
|
2002-07-11 08:53:09 +02:00
|
|
|
from threading import *
|
2003-01-03 03:00:23 +01:00
|
|
|
import thread, traceback, time, threading
|
2002-07-11 09:51:24 +02:00
|
|
|
from StringIO import StringIO
|
|
|
|
from ScrolledText import ScrolledText
|
2002-07-11 12:02:36 +02:00
|
|
|
from offlineimap import threadutil, version
|
2002-07-11 08:53:09 +02:00
|
|
|
from Queue import Queue
|
2002-07-11 09:15:57 +02:00
|
|
|
from UIBase import UIBase
|
2003-01-05 04:35:36 +01:00
|
|
|
from offlineimap.ui.Blinkenlights import BlinkenBase
|
2002-07-11 08:53:09 +02:00
|
|
|
|
2003-01-07 04:15:22 +01:00
|
|
|
usabletest = None
|
|
|
|
|
2002-07-11 08:53:09 +02:00
|
|
|
class PasswordDialog:
|
2002-11-05 00:15:42 +01:00
|
|
|
def __init__(self, accountname, config, master=None, errmsg = None):
|
2002-07-11 08:53:09 +02:00
|
|
|
self.top = Toplevel(master)
|
2002-07-11 12:02:36 +02:00
|
|
|
self.top.title(version.productname + " Password Entry")
|
2002-11-05 00:15:42 +01:00
|
|
|
text = ''
|
|
|
|
if errmsg:
|
|
|
|
text = '%s: %s\n' % (accountname, errmsg)
|
2003-04-18 04:43:54 +02:00
|
|
|
text += "%s: Enter password: " % accountname
|
2002-11-05 00:15:42 +01:00
|
|
|
self.label = Label(self.top, text = text)
|
2002-07-11 08:53:09 +02:00
|
|
|
self.label.pack()
|
|
|
|
|
|
|
|
self.entry = Entry(self.top, show='*')
|
2002-07-11 12:02:36 +02:00
|
|
|
self.entry.bind("<Return>", self.ok)
|
2002-07-11 08:53:09 +02:00
|
|
|
self.entry.pack()
|
2002-07-11 12:02:36 +02:00
|
|
|
self.entry.focus_force()
|
2002-07-11 08:53:09 +02:00
|
|
|
|
|
|
|
self.button = Button(self.top, text = "OK", command=self.ok)
|
|
|
|
self.button.pack()
|
|
|
|
|
2002-07-11 12:02:36 +02:00
|
|
|
self.entry.focus_force()
|
2002-07-11 08:53:09 +02:00
|
|
|
self.top.wait_window(self.label)
|
|
|
|
|
2002-07-11 12:02:36 +02:00
|
|
|
def ok(self, args = None):
|
2002-07-11 08:53:09 +02:00
|
|
|
self.password = self.entry.get()
|
|
|
|
self.top.destroy()
|
|
|
|
|
|
|
|
def getpassword(self):
|
|
|
|
return self.password
|
|
|
|
|
2002-07-11 09:51:24 +02:00
|
|
|
class TextOKDialog:
|
2002-07-11 15:25:53 +02:00
|
|
|
def __init__(self, title, message, blocking = 1, master = None):
|
|
|
|
if not master:
|
|
|
|
self.top = Tk()
|
|
|
|
else:
|
|
|
|
self.top = Toplevel(master)
|
2002-07-11 12:02:36 +02:00
|
|
|
self.top.title(title)
|
2002-07-11 09:51:24 +02:00
|
|
|
self.text = ScrolledText(self.top, font = "Courier 10")
|
|
|
|
self.text.pack()
|
|
|
|
self.text.insert(END, message)
|
|
|
|
self.text['state'] = DISABLED
|
|
|
|
self.button = Button(self.top, text = "OK", command=self.ok)
|
|
|
|
self.button.pack()
|
|
|
|
|
2002-07-11 15:25:53 +02:00
|
|
|
if blocking:
|
|
|
|
self.top.wait_window(self.button)
|
2002-07-11 09:51:24 +02:00
|
|
|
|
|
|
|
def ok(self):
|
|
|
|
self.top.destroy()
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-07-11 08:53:09 +02:00
|
|
|
class ThreadFrame(Frame):
|
|
|
|
def __init__(self, master=None):
|
2002-07-11 12:55:32 +02:00
|
|
|
self.threadextraframe = None
|
2002-07-11 08:53:09 +02:00
|
|
|
self.thread = currentThread()
|
|
|
|
self.threadid = thread.get_ident()
|
2002-07-11 12:02:36 +02:00
|
|
|
Frame.__init__(self, master, relief = RIDGE, borderwidth = 2)
|
|
|
|
self.pack(fill = 'x')
|
2002-07-11 12:55:32 +02:00
|
|
|
self.threadlabel = Label(self, foreground = '#FF0000',
|
|
|
|
text ="Thread %d (%s)" % (self.threadid,
|
|
|
|
self.thread.getName()))
|
|
|
|
self.threadlabel.pack()
|
|
|
|
self.setthread(currentThread())
|
2002-07-11 08:53:09 +02:00
|
|
|
|
|
|
|
self.account = "Unknown"
|
|
|
|
self.mailbox = "Unknown"
|
2002-07-11 12:55:32 +02:00
|
|
|
self.loclabel = Label(self,
|
2002-07-11 09:15:57 +02:00
|
|
|
text = "Account/mailbox information unknown")
|
2002-07-11 12:02:36 +02:00
|
|
|
#self.loclabel.pack()
|
2002-07-11 08:53:09 +02:00
|
|
|
|
|
|
|
self.updateloclabel()
|
|
|
|
|
2002-07-11 12:55:32 +02:00
|
|
|
self.message = Label(self, text="Messages will appear here.\n",
|
|
|
|
foreground = '#0000FF')
|
|
|
|
self.message.pack(fill = 'x')
|
|
|
|
|
|
|
|
def setthread(self, newthread):
|
|
|
|
if newthread:
|
|
|
|
self.threadlabel['text'] = newthread.getName()
|
|
|
|
else:
|
|
|
|
self.threadlabel['text'] = "No thread"
|
|
|
|
self.destroythreadextraframe()
|
|
|
|
|
|
|
|
def destroythreadextraframe(self):
|
|
|
|
if self.threadextraframe:
|
|
|
|
self.threadextraframe.destroy()
|
|
|
|
self.threadextraframe = None
|
|
|
|
|
|
|
|
def getthreadextraframe(self):
|
|
|
|
if self.threadextraframe:
|
|
|
|
return self.threadextraframe
|
2002-07-11 15:25:53 +02:00
|
|
|
self.threadextraframe = Frame(self)
|
2002-07-11 12:55:32 +02:00
|
|
|
self.threadextraframe.pack(fill = 'x')
|
2002-07-11 15:25:53 +02:00
|
|
|
return self.threadextraframe
|
2002-07-11 08:53:09 +02:00
|
|
|
|
|
|
|
def setaccount(self, account):
|
|
|
|
self.account = account
|
|
|
|
self.mailbox = "Unknown"
|
|
|
|
self.updateloclabel()
|
|
|
|
|
|
|
|
def setmailbox(self, mailbox):
|
|
|
|
self.mailbox = mailbox
|
|
|
|
self.updateloclabel()
|
|
|
|
|
|
|
|
def updateloclabel(self):
|
|
|
|
self.loclabel['text'] = "Processing %s: %s" % (self.account,
|
|
|
|
self.mailbox)
|
|
|
|
|
|
|
|
def appendmessage(self, newtext):
|
|
|
|
self.message['text'] += "\n" + newtext
|
|
|
|
|
|
|
|
def setmessage(self, newtext):
|
|
|
|
self.message['text'] = newtext
|
|
|
|
|
|
|
|
|
2002-07-24 10:34:59 +02:00
|
|
|
class VerboseUI(UIBase):
|
2002-07-12 03:58:51 +02:00
|
|
|
def isusable(s):
|
2003-01-07 04:15:22 +01:00
|
|
|
global usabletest
|
|
|
|
if usabletest != None:
|
|
|
|
return usabletest
|
|
|
|
|
2002-07-12 03:58:51 +02:00
|
|
|
try:
|
|
|
|
Tk().destroy()
|
2003-01-07 04:15:22 +01:00
|
|
|
usabletest = 1
|
2002-07-12 03:58:51 +02:00
|
|
|
except TclError:
|
2003-01-07 04:15:22 +01:00
|
|
|
usabletest = 0
|
|
|
|
return usabletest
|
|
|
|
|
2002-07-24 22:38:40 +02:00
|
|
|
def _createTopWindow(self, doidlevac = 1):
|
2002-07-11 12:02:36 +02:00
|
|
|
self.notdeleted = 1
|
2003-01-03 03:00:23 +01:00
|
|
|
self.created = threading.Event()
|
2002-07-11 09:15:57 +02:00
|
|
|
|
2003-01-07 00:04:40 +01:00
|
|
|
self.af = {}
|
|
|
|
self.aflock = Lock()
|
|
|
|
|
2002-07-12 03:58:51 +02:00
|
|
|
t = threadutil.ExitNotifyThread(target = self._runmainloop,
|
2002-07-11 09:15:57 +02:00
|
|
|
name = "Tk Mainloop")
|
|
|
|
t.setDaemon(1)
|
|
|
|
t.start()
|
2002-07-11 12:02:36 +02:00
|
|
|
|
2003-01-03 03:00:23 +01:00
|
|
|
self.created.wait()
|
|
|
|
del self.created
|
|
|
|
|
2002-07-24 22:38:40 +02:00
|
|
|
if doidlevac:
|
|
|
|
t = threadutil.ExitNotifyThread(target = self.idlevacuum,
|
|
|
|
name = "Tk idle vacuum")
|
|
|
|
t.setDaemon(1)
|
|
|
|
t.start()
|
2002-07-11 12:02:36 +02:00
|
|
|
|
2002-07-12 03:58:51 +02:00
|
|
|
def _runmainloop(s):
|
2003-01-03 03:00:23 +01:00
|
|
|
s.top = Tk()
|
|
|
|
s.top.title(version.productname + " " + version.versionstr)
|
2003-01-03 08:08:10 +01:00
|
|
|
s.top.after_idle(s.created.set)
|
2002-07-11 12:02:36 +02:00
|
|
|
s.top.mainloop()
|
|
|
|
s.notdeleted = 0
|
2003-01-07 00:04:40 +01:00
|
|
|
|
|
|
|
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]
|
2002-07-11 12:02:36 +02:00
|
|
|
|
2002-11-05 00:15:42 +01:00
|
|
|
def getpass(s, accountname, config, errmsg = None):
|
|
|
|
pd = PasswordDialog(accountname, config, errmsg = errmsg)
|
2002-07-11 08:53:09 +02:00
|
|
|
return pd.getpassword()
|
|
|
|
|
2002-07-24 10:34:59 +02:00
|
|
|
def gettf(s, newtype=ThreadFrame, master = None):
|
|
|
|
if master == None:
|
|
|
|
master = s.top
|
2002-07-11 08:53:09 +02:00
|
|
|
threadid = thread.get_ident()
|
2002-07-11 11:14:29 +02:00
|
|
|
s.tflock.acquire()
|
|
|
|
try:
|
|
|
|
if threadid in s.threadframes:
|
|
|
|
return s.threadframes[threadid]
|
|
|
|
if len(s.availablethreadframes):
|
|
|
|
tf = s.availablethreadframes.pop(0)
|
2002-07-11 12:55:32 +02:00
|
|
|
tf.setthread(currentThread())
|
2002-07-11 11:14:29 +02:00
|
|
|
else:
|
2002-07-24 10:34:59 +02:00
|
|
|
tf = newtype(master)
|
2002-07-11 11:14:29 +02:00
|
|
|
s.threadframes[threadid] = tf
|
|
|
|
return tf
|
|
|
|
finally:
|
|
|
|
s.tflock.release()
|
2002-07-11 08:53:09 +02:00
|
|
|
|
2003-06-02 21:06:18 +02:00
|
|
|
def _display(s, msg):
|
2002-07-11 08:53:09 +02:00
|
|
|
s.gettf().setmessage(msg)
|
|
|
|
|
|
|
|
def threadExited(s, thread):
|
2002-07-11 09:51:24 +02:00
|
|
|
threadid = thread.threadid
|
2002-07-11 11:14:29 +02:00
|
|
|
s.tflock.acquire()
|
2002-07-11 09:15:57 +02:00
|
|
|
if threadid in s.threadframes:
|
|
|
|
tf = s.threadframes[threadid]
|
2002-07-11 12:55:32 +02:00
|
|
|
tf.setthread(None)
|
2002-07-11 11:14:29 +02:00
|
|
|
tf.setaccount("Unknown")
|
|
|
|
tf.setmessage("Idle")
|
|
|
|
s.availablethreadframes.append(tf)
|
2002-07-11 09:51:24 +02:00
|
|
|
del s.threadframes[threadid]
|
2002-07-11 11:14:29 +02:00
|
|
|
s.tflock.release()
|
2002-10-17 01:27:27 +02:00
|
|
|
UIBase.threadExited(s, thread)
|
2002-07-11 12:02:36 +02:00
|
|
|
|
|
|
|
def idlevacuum(s):
|
|
|
|
while s.notdeleted:
|
|
|
|
time.sleep(10)
|
|
|
|
s.tflock.acquire()
|
|
|
|
while len(s.availablethreadframes):
|
|
|
|
tf = s.availablethreadframes.pop()
|
|
|
|
tf.destroy()
|
|
|
|
s.tflock.release()
|
2002-07-11 09:51:24 +02:00
|
|
|
|
|
|
|
def threadException(s, thread):
|
2002-10-17 01:27:27 +02:00
|
|
|
exceptionstr = s.getThreadExceptionString(thread)
|
|
|
|
print exceptionstr
|
2002-07-11 08:53:09 +02:00
|
|
|
|
2002-07-11 09:51:24 +02:00
|
|
|
s.top.destroy()
|
2002-07-11 15:25:53 +02:00
|
|
|
s.top = None
|
2002-10-17 01:27:27 +02:00
|
|
|
TextOKDialog("Thread Exception", exceptionstr)
|
|
|
|
s.delThreadDebugLog(thread)
|
2002-07-11 09:51:24 +02:00
|
|
|
s.terminate(100)
|
|
|
|
|
|
|
|
def mainException(s):
|
2002-10-17 01:27:27 +02:00
|
|
|
exceptionstr = s.getMainExceptionString()
|
|
|
|
print exceptionstr
|
2002-07-11 09:51:24 +02:00
|
|
|
|
|
|
|
s.top.destroy()
|
2002-07-11 15:25:53 +02:00
|
|
|
s.top = None
|
2002-10-17 01:27:27 +02:00
|
|
|
TextOKDialog("Main Program Exception", exceptionstr)
|
2002-07-11 09:51:24 +02:00
|
|
|
|
2004-07-26 22:37:45 +02:00
|
|
|
def warn(s, msg, minor = 0):
|
2002-10-30 05:26:49 +01:00
|
|
|
if minor:
|
|
|
|
# Just let the default handler catch it
|
|
|
|
UIBase.warn(s, msg, minor)
|
|
|
|
else:
|
|
|
|
TextOKDialog("OfflineIMAP Warning", msg)
|
2002-07-12 15:20:09 +02:00
|
|
|
|
2002-07-24 22:38:40 +02:00
|
|
|
def showlicense(s):
|
|
|
|
TextOKDialog(version.productname + " License",
|
|
|
|
version.bigcopyright + "\n" +
|
|
|
|
version.homepage + "\n\n" + version.license,
|
|
|
|
blocking = 0, master = s.top)
|
|
|
|
|
|
|
|
|
2002-07-11 15:25:53 +02:00
|
|
|
def init_banner(s):
|
2003-01-08 10:15:18 +01:00
|
|
|
s.threadframes = {}
|
|
|
|
s.availablethreadframes = []
|
|
|
|
s.tflock = Lock()
|
2002-07-12 03:58:51 +02:00
|
|
|
s._createTopWindow()
|
2002-07-11 15:25:53 +02:00
|
|
|
s._msg(version.productname + " " + version.versionstr + ", " +\
|
|
|
|
version.copyright)
|
|
|
|
tf = s.gettf().getthreadextraframe()
|
|
|
|
|
2002-07-24 22:38:40 +02:00
|
|
|
b = Button(tf, text = "About", command = s.showlicense)
|
2002-07-11 15:25:53 +02:00
|
|
|
b.pack(side = LEFT)
|
|
|
|
|
|
|
|
b = Button(tf, text = "Exit", command = s.terminate)
|
|
|
|
b.pack(side = RIGHT)
|
2003-01-06 23:15:15 +01:00
|
|
|
s.sleeping_abort = {}
|
2002-07-11 15:25:53 +02:00
|
|
|
|
2002-07-11 11:42:27 +02:00
|
|
|
def deletingmessages(s, uidlist, destlist):
|
|
|
|
ds = s.folderlist(destlist)
|
|
|
|
s._msg("Deleting %d messages in %s" % (len(uidlist), ds))
|
2002-07-11 09:51:24 +02:00
|
|
|
|
2002-07-11 15:25:53 +02:00
|
|
|
def _sleep_cancel(s, args = None):
|
2003-01-06 23:15:15 +01:00
|
|
|
s.sleeping_abort[thread.get_ident()] = 1
|
2002-07-11 15:25:53 +02:00
|
|
|
|
|
|
|
def sleep(s, sleepsecs):
|
2003-01-06 23:15:15 +01:00
|
|
|
threadid = thread.get_ident()
|
|
|
|
s.sleeping_abort[threadid] = 0
|
2002-07-11 15:25:53 +02:00
|
|
|
tf = s.gettf().getthreadextraframe()
|
|
|
|
|
2003-01-06 23:15:15 +01:00
|
|
|
def sleep_cancel():
|
|
|
|
s.sleeping_abort[threadid] = 1
|
|
|
|
|
2002-07-11 15:25:53 +02:00
|
|
|
sleepbut = Button(tf, text = 'Sync immediately',
|
2003-01-06 23:15:15 +01:00
|
|
|
command = sleep_cancel)
|
2002-07-11 15:25:53 +02:00
|
|
|
sleepbut.pack()
|
|
|
|
UIBase.sleep(s, sleepsecs)
|
|
|
|
|
|
|
|
def sleeping(s, sleepsecs, remainingsecs):
|
2003-01-06 23:15:15 +01:00
|
|
|
retval = s.sleeping_abort[thread.get_ident()]
|
2002-07-11 15:25:53 +02:00
|
|
|
if remainingsecs:
|
|
|
|
s._msg("Next sync in %d:%02d" % (remainingsecs / 60,
|
|
|
|
remainingsecs % 60))
|
|
|
|
else:
|
|
|
|
s._msg("Wait done; synchronizing now.")
|
|
|
|
s.gettf().destroythreadextraframe()
|
2003-01-06 23:15:15 +01:00
|
|
|
del s.sleeping_abort[thread.get_ident()]
|
2002-07-11 15:25:53 +02:00
|
|
|
time.sleep(sleepsecs)
|
2003-01-06 23:15:15 +01:00
|
|
|
return retval
|
2002-07-11 15:25:53 +02:00
|
|
|
|
2002-07-24 10:34:59 +02:00
|
|
|
TkUI = VerboseUI
|
|
|
|
|
2002-08-07 10:08:16 +02:00
|
|
|
################################################## Blinkenlights
|
|
|
|
|
2003-01-07 00:04:40 +01:00
|
|
|
class LEDAccountFrame:
|
|
|
|
def __init__(self, top, accountname, fontfamily, fontsize):
|
|
|
|
self.top = top
|
|
|
|
self.accountname = accountname
|
|
|
|
self.fontfamily = fontfamily
|
|
|
|
self.fontsize = fontsize
|
2003-01-07 00:14:17 +01:00
|
|
|
self.frame = Frame(self.top, background = 'black')
|
2003-01-07 01:18:06 +01:00
|
|
|
self.frame.pack(side = BOTTOM, expand = 1, fill = X)
|
2003-01-07 00:04:40 +01:00
|
|
|
self._createcanvas(self.frame)
|
|
|
|
|
2003-01-07 00:14:17 +01:00
|
|
|
self.label = Label(self.frame, text = accountname,
|
|
|
|
background = "black", foreground = "blue",
|
|
|
|
font = (self.fontfamily, self.fontsize))
|
2003-01-07 01:18:06 +01:00
|
|
|
self.label.grid(sticky = E, row = 0, column = 1)
|
2003-01-07 00:04:40 +01:00
|
|
|
|
|
|
|
def getnewthreadframe(s):
|
|
|
|
return LEDThreadFrame(s.canvas)
|
|
|
|
|
|
|
|
def _createcanvas(self, parent):
|
2003-01-07 01:00:43 +01:00
|
|
|
c = LEDFrame(parent)
|
2003-01-07 00:04:40 +01:00
|
|
|
self.canvas = c
|
2003-01-07 01:18:06 +01:00
|
|
|
c.grid(sticky = E, row = 0, column = 0)
|
|
|
|
parent.grid_columnconfigure(1, weight = 1)
|
2003-01-07 01:00:43 +01:00
|
|
|
#c.pack(side = LEFT, expand = 0, fill = X)
|
2003-01-07 00:04:40 +01:00
|
|
|
|
|
|
|
def startsleep(s, sleepsecs):
|
|
|
|
s.sleeping_abort = 0
|
2003-01-07 00:14:17 +01:00
|
|
|
s.button = Button(s.frame, text = "Sync now", command = s.syncnow,
|
|
|
|
background = "black", activebackground = "black",
|
|
|
|
activeforeground = "white",
|
2003-01-07 00:31:19 +01:00
|
|
|
foreground = "blue", highlightthickness = 0,
|
|
|
|
padx = 0, pady = 0,
|
|
|
|
font = (s.fontfamily, s.fontsize), borderwidth = 0,
|
|
|
|
relief = 'solid')
|
2003-01-07 01:18:06 +01:00
|
|
|
s.button.grid(sticky = E, row = 0, column = 2)
|
2003-01-07 00:04:40 +01:00
|
|
|
|
|
|
|
def syncnow(s):
|
|
|
|
s.sleeping_abort = 1
|
|
|
|
|
|
|
|
def sleeping(s, sleepsecs, remainingsecs):
|
|
|
|
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
|
|
|
|
|
2003-01-07 01:00:43 +01:00
|
|
|
class LEDFrame(Frame):
|
2003-01-07 00:04:40 +01:00
|
|
|
"""This holds the different lights."""
|
2003-01-07 01:00:43 +01:00
|
|
|
def getnewobj(self):
|
|
|
|
retval = Canvas(self, background = 'black', height = 20, bd = 0,
|
|
|
|
highlightthickness = 0, width = 10)
|
|
|
|
retval.pack(side = LEFT, padx = 0, pady = 0, ipadx = 0, ipady = 0)
|
|
|
|
return retval
|
2002-07-24 10:34:59 +02:00
|
|
|
|
|
|
|
class LEDThreadFrame:
|
2003-01-07 00:04:40 +01:00
|
|
|
"""There is one of these for each little light."""
|
2002-07-24 10:34:59 +02:00
|
|
|
def __init__(self, master):
|
2003-01-07 01:00:43 +01:00
|
|
|
self.canvas = master.getnewobj()
|
2002-07-24 23:00:02 +02:00
|
|
|
self.color = ''
|
2003-01-07 04:37:27 +01:00
|
|
|
self.ovalid = self.canvas.create_oval(4, 4, 9,
|
|
|
|
9, fill = 'gray',
|
2002-07-24 10:34:59 +02:00
|
|
|
outline = '#303030')
|
|
|
|
|
2002-07-24 22:38:40 +02:00
|
|
|
def setcolor(self, newcolor):
|
2002-07-24 23:00:02 +02:00
|
|
|
if newcolor != self.color:
|
|
|
|
self.canvas.itemconfigure(self.ovalid, fill = newcolor)
|
|
|
|
self.color = newcolor
|
|
|
|
|
|
|
|
def getcolor(self):
|
|
|
|
return self.color
|
2002-07-24 10:34:59 +02:00
|
|
|
|
|
|
|
def setthread(self, newthread):
|
|
|
|
if newthread:
|
2002-07-24 22:38:40 +02:00
|
|
|
self.setcolor('gray')
|
2002-07-24 10:34:59 +02:00
|
|
|
else:
|
2002-07-24 22:38:40 +02:00
|
|
|
self.setcolor('black')
|
2002-07-24 10:34:59 +02:00
|
|
|
|
|
|
|
|
2003-01-05 04:35:36 +01:00
|
|
|
class Blinkenlights(BlinkenBase, VerboseUI):
|
2002-08-27 03:06:02 +02:00
|
|
|
def __init__(s, config, verbose = 0):
|
|
|
|
VerboseUI.__init__(s, config, verbose)
|
|
|
|
s.fontfamily = 'Helvetica'
|
|
|
|
s.fontsize = 8
|
|
|
|
if config.has_option('ui.Tk.Blinkenlights', 'fontfamily'):
|
|
|
|
s.fontfamily = config.get('ui.Tk.Blinkenlights', 'fontfamily')
|
|
|
|
if config.has_option('ui.Tk.Blinkenlights', 'fontsize'):
|
|
|
|
s.fontsize = config.getint('ui.Tk.Blinkenlights', 'fontsize')
|
2003-01-03 03:00:23 +01:00
|
|
|
|
2003-01-07 04:15:22 +01:00
|
|
|
def isusable(s):
|
|
|
|
return VerboseUI.isusable(s)
|
|
|
|
|
2002-07-24 10:34:59 +02:00
|
|
|
def _createTopWindow(self):
|
2002-07-24 22:38:40 +02:00
|
|
|
VerboseUI._createTopWindow(self, 0)
|
2002-07-25 09:36:24 +02:00
|
|
|
#self.top.resizable(width = 0, height = 0)
|
2002-07-24 22:38:40 +02:00
|
|
|
self.top.configure(background = 'black', bd = 0)
|
2003-01-07 00:04:40 +01:00
|
|
|
|
2002-08-27 03:35:21 +02:00
|
|
|
widthmetric = tkFont.Font(family = self.fontfamily, size = self.fontsize).measure("0")
|
2003-01-07 04:15:22 +01:00
|
|
|
self.loglines = self.config.getdefaultint("ui.Tk.Blinkenlights",
|
|
|
|
"loglines", 5)
|
|
|
|
self.bufferlines = self.config.getdefaultint("ui.Tk.Blinkenlights",
|
|
|
|
"bufferlines", 500)
|
2002-07-25 06:46:27 +02:00
|
|
|
self.text = ScrolledText(self.top, bg = 'black', #scrollbar = 'y',
|
2002-08-27 03:35:21 +02:00
|
|
|
font = (self.fontfamily, self.fontsize),
|
2002-07-25 07:06:01 +02:00
|
|
|
bd = 0, highlightthickness = 0, setgrid = 0,
|
|
|
|
state = DISABLED, height = self.loglines,
|
2002-08-27 03:35:21 +02:00
|
|
|
wrap = NONE, width = 60)
|
2002-07-25 06:46:27 +02:00
|
|
|
self.text.vbar.configure(background = '#000050',
|
|
|
|
activebackground = 'blue',
|
|
|
|
highlightbackground = 'black',
|
|
|
|
troughcolor = "black", bd = 0,
|
|
|
|
elementborderwidth = 2)
|
|
|
|
|
2002-07-25 00:04:22 +02:00
|
|
|
self.textenabled = 0
|
|
|
|
self.tags = []
|
|
|
|
self.textlock = Lock()
|
2002-07-24 10:34:59 +02:00
|
|
|
|
|
|
|
def init_banner(s):
|
2003-01-07 00:04:40 +01:00
|
|
|
BlinkenBase.init_banner(s)
|
2002-07-24 10:34:59 +02:00
|
|
|
s._createTopWindow()
|
2002-07-24 22:38:40 +02:00
|
|
|
menubar = Menu(s.top, activebackground = "black",
|
|
|
|
activeforeground = "white",
|
2002-07-25 07:06:01 +02:00
|
|
|
activeborderwidth = 0,
|
2002-07-24 22:38:40 +02:00
|
|
|
background = "black", foreground = "blue",
|
2002-08-27 03:35:21 +02:00
|
|
|
font = (s.fontfamily, s.fontsize), bd = 0)
|
2002-07-24 22:38:40 +02:00
|
|
|
menubar.add_command(label = "About", command = s.showlicense)
|
2002-07-25 00:04:22 +02:00
|
|
|
menubar.add_command(label = "Show Log", command = s._togglelog)
|
2002-07-24 22:38:40 +02:00
|
|
|
menubar.add_command(label = "Exit", command = s.terminate)
|
|
|
|
s.top.config(menu = menubar)
|
|
|
|
s.menubar = menubar
|
2002-07-25 06:46:27 +02:00
|
|
|
s.text.see(END)
|
2003-01-07 04:15:22 +01:00
|
|
|
if s.config.getdefaultboolean("ui.Tk.Blinkenlights", "showlog", 1):
|
2002-07-25 00:20:42 +02:00
|
|
|
s._togglelog()
|
2003-01-07 01:00:43 +01:00
|
|
|
s.gettf().setcolor('red')
|
|
|
|
s.top.resizable(width = 0, height = 0)
|
|
|
|
s._msg(version.banner)
|
2002-07-24 22:38:40 +02:00
|
|
|
|
2002-07-25 00:04:22 +02:00
|
|
|
def _togglelog(s):
|
|
|
|
if s.textenabled:
|
2002-07-25 06:46:27 +02:00
|
|
|
s.oldtextheight = s.text.winfo_height()
|
2002-07-25 00:04:22 +02:00
|
|
|
s.text.pack_forget()
|
|
|
|
s.textenabled = 0
|
2002-07-25 07:37:54 +02:00
|
|
|
s.menubar.entryconfig('Hide Log', label = 'Show Log')
|
2002-07-25 06:46:27 +02:00
|
|
|
s.top.update()
|
2002-07-25 09:36:24 +02:00
|
|
|
s.top.geometry("")
|
2002-07-25 07:06:01 +02:00
|
|
|
s.top.update()
|
|
|
|
s.top.resizable(width = 0, height = 0)
|
2002-07-25 07:37:54 +02:00
|
|
|
s.top.update()
|
2002-07-25 06:46:27 +02:00
|
|
|
|
2002-07-25 07:37:54 +02:00
|
|
|
else:
|
2003-01-07 01:00:43 +01:00
|
|
|
s.text.pack(side = TOP, expand = 1, fill = BOTH)
|
2002-07-25 00:04:22 +02:00
|
|
|
s.textenabled = 1
|
2002-07-25 06:46:27 +02:00
|
|
|
s.top.update()
|
2002-07-25 09:36:24 +02:00
|
|
|
s.top.geometry("")
|
2002-07-25 07:37:54 +02:00
|
|
|
s.menubar.entryconfig('Show Log', label = 'Hide Log')
|
2002-07-25 06:46:27 +02:00
|
|
|
s._rescroll()
|
2002-07-25 07:06:01 +02:00
|
|
|
s.top.resizable(width = 1, height = 1)
|
|
|
|
|
2002-07-24 23:00:02 +02:00
|
|
|
def sleep(s, sleepsecs):
|
2002-07-25 02:40:58 +02:00
|
|
|
s.gettf().setcolor('red')
|
2002-07-25 00:04:22 +02:00
|
|
|
s._msg("Next sync in %d:%02d" % (sleepsecs / 60, sleepsecs % 60))
|
2003-01-07 00:04:40 +01:00
|
|
|
BlinkenBase.sleep(s, sleepsecs)
|
|
|
|
|
|
|
|
def sleeping(s, sleepsecs, remainingsecs):
|
|
|
|
return BlinkenBase.sleeping(s, sleepsecs, remainingsecs)
|
2002-07-24 23:00:02 +02:00
|
|
|
|
2002-07-25 06:46:27 +02:00
|
|
|
def _rescroll(s):
|
|
|
|
s.text.see(END)
|
|
|
|
lo, hi = s.text.vbar.get()
|
|
|
|
s.text.vbar.set(1.0 - (hi - lo), 1.0)
|
|
|
|
|
2003-06-02 21:06:18 +02:00
|
|
|
def _display(s, msg):
|
2002-07-25 00:04:22 +02:00
|
|
|
if "\n" in msg:
|
|
|
|
for thisline in msg.split("\n"):
|
|
|
|
s._msg(thisline)
|
|
|
|
return
|
2003-01-07 00:04:40 +01:00
|
|
|
#VerboseUI._msg(s, msg)
|
2002-07-25 00:04:22 +02:00
|
|
|
color = s.gettf().getcolor()
|
2002-07-25 06:46:27 +02:00
|
|
|
rescroll = 1
|
2002-07-25 00:04:22 +02:00
|
|
|
s.textlock.acquire()
|
|
|
|
try:
|
2002-08-08 02:46:18 +02:00
|
|
|
if s.text.vbar.get()[1] != 1.0:
|
|
|
|
rescroll = 0
|
2002-07-25 00:04:22 +02:00
|
|
|
s.text.config(state = NORMAL)
|
|
|
|
if not color in s.tags:
|
|
|
|
s.text.tag_config(color, foreground = color)
|
|
|
|
s.tags.append(color)
|
2002-07-25 06:46:27 +02:00
|
|
|
s.text.insert(END, "\n" + msg, color)
|
2002-07-25 00:04:22 +02:00
|
|
|
|
|
|
|
# Trim down. Not quite sure why I have to say 7 instead of 5,
|
|
|
|
# but so it is.
|
2002-07-25 06:46:27 +02:00
|
|
|
while float(s.text.index(END)) > s.bufferlines + 2.0:
|
2002-07-25 00:04:22 +02:00
|
|
|
s.text.delete(1.0, 2.0)
|
2002-07-25 06:46:27 +02:00
|
|
|
|
|
|
|
if rescroll:
|
|
|
|
s._rescroll()
|
2002-07-25 00:04:22 +02:00
|
|
|
finally:
|
|
|
|
s.text.config(state = DISABLED)
|
|
|
|
s.textlock.release()
|
|
|
|
|
2002-07-24 23:00:02 +02:00
|
|
|
|