/head: changeset 97

More work with the Tk UI
This commit is contained in:
jgoerzen 2002-07-11 08:15:57 +01:00
parent 6b40bf7973
commit 6605b3d659
2 changed files with 20 additions and 13 deletions

View File

@ -26,7 +26,7 @@ from threading import *
if '-d' in sys.argv: if '-d' in sys.argv:
imaplib.Debug = 5 imaplib.Debug = 5
# ui = offlineimap.ui.TTY.TTYUI() #ui = offlineimap.ui.TTY.TTYUI()
ui = offlineimap.ui.Tk.TkUI() ui = offlineimap.ui.Tk.TkUI()
ui.init_banner() ui.init_banner()

View File

@ -21,12 +21,12 @@ from threading import *
import thread import thread
from offlineimap import threadutil from offlineimap import threadutil
from Queue import Queue from Queue import Queue
import UIBase from UIBase import UIBase
class PasswordDialog: class PasswordDialog:
def __init__(self, accountname, config, master=None): def __init__(self, accountname, config, master=None):
self.top = Toplevel(master) self.top = Toplevel(master)
self.label = Label(self.frame, self.label = Label(self.top,
text = "%s: Enter password for %s on %s: " % \ text = "%s: Enter password for %s on %s: " % \
(accountname, config.get(accountname, "remoteuser"), (accountname, config.get(accountname, "remoteuser"),
config.get(accountname, "remotehost"))) config.get(accountname, "remotehost")))
@ -54,21 +54,23 @@ class ThreadFrame(Frame):
def __init__(self, master=None): def __init__(self, master=None):
self.thread = currentThread() self.thread = currentThread()
self.threadid = thread.get_ident() self.threadid = thread.get_ident()
Frame.__init__(self, master) Frame.__init__(self, master, relief = RIDGE, borderwidth = 1)
self.pack() self.pack()
self.threadlabel = Label(self, text ="Thread %d (%s)" % (self.threadid, self.threadlabel = Label(self, foreground = '#FF0000',
text ="Thread %d (%s)" % (self.threadid,
self.thread.getName())) self.thread.getName()))
self.threadlabel.pack() self.threadlabel.pack()
self.account = "Unknown" self.account = "Unknown"
self.mailbox = "Unknown" self.mailbox = "Unknown"
self.loclabel = Label(self, text = "Account/mailbox information unknown") self.loclabel = Label(self, foreground = '#0000FF',
text = "Account/mailbox information unknown")
self.loclabel.pack() self.loclabel.pack()
self.updateloclabel() self.updateloclabel()
self.messages = Label(self, text="Messages will appear here.\n") self.message = Label(self, text="Messages will appear here.\n")
self.messages.pack() self.message.pack()
def setaccount(self, account): def setaccount(self, account):
self.account = account self.account = account
@ -89,12 +91,17 @@ class ThreadFrame(Frame):
def setmessage(self, newtext): def setmessage(self, newtext):
self.message['text'] = newtext self.message['text'] = newtext
class TkUI(UIBase): class TkUI(UIBase):
def __init__(self): def __init__(self):
self.top = Tk() self.top = Tk()
self.threadframes = {} self.threadframes = {}
t = threadutil.ExitNotifyThread(target = self.top.mainloop,
name = "Tk Mainloop")
t.setDaemon(1)
t.start()
print "TkUI mainloop started."
def getpass(s, accountname, config): def getpass(s, accountname, config):
pd = PasswordDialog(accountname, config, Tk()) pd = PasswordDialog(accountname, config, Tk())
@ -102,7 +109,7 @@ class TkUI(UIBase):
def gettf(s): def gettf(s):
threadid = thread.get_ident() threadid = thread.get_ident()
if threadid in self.threadframes: if threadid in s.threadframes:
return s.threadframes[threadid] return s.threadframes[threadid]
tf = ThreadFrame(s.top) tf = ThreadFrame(s.top)
s.threadframes[threadid] = tf s.threadframes[threadid] = tf
@ -112,9 +119,9 @@ class TkUI(UIBase):
s.gettf().setmessage(msg) s.gettf().setmessage(msg)
def threadExited(s, thread): def threadExited(s, thread):
threadid = self.threadid threadid = s.threadid
if threadid in self.threadframes: if threadid in s.threadframes:
tf = self.threadframes[threadid] tf = s.threadframes[threadid]
tf.destroy() tf.destroy()
del tf[threadid] del tf[threadid]