/head: changeset 108

More work on the UIs
This commit is contained in:
jgoerzen 2002-07-12 02:58:51 +01:00
parent 1953d0f76f
commit f9851884be
4 changed files with 92 additions and 3 deletions

View File

@ -49,6 +49,19 @@ accounts = Test
maxsyncaccounts = 1 maxsyncaccounts = 1
# You can specify one or more user interface modules for OfflineIMAP
# to use. OfflineIMAP will try the first in the list, and if it
# fails, the second, and so forth.
#
# The pre-defined options are:
# Tk.TKUI -- A graphical interface
# TTY.TTYUI -- a text-based (terminal) interface
#
# You can override this with a command-line option -u.
ui = Tk.TKUI, TTY.TTYUI
################################################## ##################################################
# Mailbox name recorder # Mailbox name recorder
################################################## ##################################################

View File

@ -142,6 +142,15 @@ class ThreadFrame(Frame):
class TkUI(UIBase): class TkUI(UIBase):
def __init__(self, verbose = 0): def __init__(self, verbose = 0):
self.verbose = verbose self.verbose = verbose
def isusable(s):
try:
Tk().destroy()
return 1
except TclError:
return 0
def _createTopWindow(self):
self.top = Tk() self.top = Tk()
self.top.title(version.productname + " " + version.versionstr) self.top.title(version.productname + " " + version.versionstr)
self.threadframes = {} self.threadframes = {}
@ -149,7 +158,7 @@ class TkUI(UIBase):
self.tflock = Lock() self.tflock = Lock()
self.notdeleted = 1 self.notdeleted = 1
t = threadutil.ExitNotifyThread(target = self.runmainloop, t = threadutil.ExitNotifyThread(target = self._runmainloop,
name = "Tk Mainloop") name = "Tk Mainloop")
t.setDaemon(1) t.setDaemon(1)
t.start() t.start()
@ -159,7 +168,7 @@ class TkUI(UIBase):
t.setDaemon(1) t.setDaemon(1)
t.start() t.start()
def runmainloop(s): def _runmainloop(s):
s.top.mainloop() s.top.mainloop()
s.notdeleted = 0 s.notdeleted = 0
@ -228,6 +237,7 @@ class TkUI(UIBase):
TextOKDialog("Main Program Exception", msg) TextOKDialog("Main Program Exception", msg)
def init_banner(s): def init_banner(s):
s._createTopWindow()
s._msg(version.productname + " " + version.versionstr + ", " +\ s._msg(version.productname + " " + version.versionstr + ", " +\
version.copyright) version.copyright)
tf = s.gettf().getthreadextraframe() tf = s.gettf().getthreadextraframe()

View File

@ -1 +1,29 @@
import TTY, UIBase, Tk # UI module directory
# Copyright (C) 2002 John Goerzen
# <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
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# 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
import TTY, UIBase, detector
availableUIs = {'TTY': TTY, 'UIBase': UIBase}
try:
import Tkinter
except ImportError:
pass
else:
import Tk
availableUIs['Tk'] = Tk

View File

@ -0,0 +1,38 @@
# UI base class
# Copyright (C) 2002 John Goerzen
# <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
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# 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
from offlineimap.ui import *
import sys
def findUI(config):
uistrlist = ['Tk.TKUI', 'TTY.TTYUI']
if config.has_option("general", "ui"):
uistrlist = config.get("general", "ui").replace(" ", "").split(",")
for uistr in uistrlist:
uimod = getUImod(uistr)
if uimod and uimod.isusable():
return uimod
sys.stderr.write("ERROR: No UIs were found usable!\n")
sys.exit(200)
def getUImod(uistr):
try:
uimod = eval(uistr)
except AttributeError, NameError:
return None
return uimod