From f9851884bee1e5f4ff83a9748449feb1dbc58ba1 Mon Sep 17 00:00:00 2001 From: jgoerzen Date: Fri, 12 Jul 2002 02:58:51 +0100 Subject: [PATCH] /head: changeset 108 More work on the UIs --- head/offlineimap.conf | 13 +++++++++++ head/offlineimap/ui/Tk.py | 14 ++++++++++-- head/offlineimap/ui/__init__.py | 30 +++++++++++++++++++++++++- head/offlineimap/ui/detector.py | 38 +++++++++++++++++++++++++++++++++ 4 files changed, 92 insertions(+), 3 deletions(-) create mode 100644 head/offlineimap/ui/detector.py diff --git a/head/offlineimap.conf b/head/offlineimap.conf index 7cd3219..d10ecb5 100644 --- a/head/offlineimap.conf +++ b/head/offlineimap.conf @@ -49,6 +49,19 @@ accounts = Test 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 ################################################## diff --git a/head/offlineimap/ui/Tk.py b/head/offlineimap/ui/Tk.py index f8538ce..ac52e88 100644 --- a/head/offlineimap/ui/Tk.py +++ b/head/offlineimap/ui/Tk.py @@ -142,6 +142,15 @@ class ThreadFrame(Frame): class TkUI(UIBase): def __init__(self, verbose = 0): self.verbose = verbose + + def isusable(s): + try: + Tk().destroy() + return 1 + except TclError: + return 0 + + def _createTopWindow(self): self.top = Tk() self.top.title(version.productname + " " + version.versionstr) self.threadframes = {} @@ -149,7 +158,7 @@ class TkUI(UIBase): self.tflock = Lock() self.notdeleted = 1 - t = threadutil.ExitNotifyThread(target = self.runmainloop, + t = threadutil.ExitNotifyThread(target = self._runmainloop, name = "Tk Mainloop") t.setDaemon(1) t.start() @@ -159,7 +168,7 @@ class TkUI(UIBase): t.setDaemon(1) t.start() - def runmainloop(s): + def _runmainloop(s): s.top.mainloop() s.notdeleted = 0 @@ -228,6 +237,7 @@ class TkUI(UIBase): TextOKDialog("Main Program Exception", msg) def init_banner(s): + s._createTopWindow() s._msg(version.productname + " " + version.versionstr + ", " +\ version.copyright) tf = s.gettf().getthreadextraframe() diff --git a/head/offlineimap/ui/__init__.py b/head/offlineimap/ui/__init__.py index 87f226a..72a133c 100644 --- a/head/offlineimap/ui/__init__.py +++ b/head/offlineimap/ui/__init__.py @@ -1 +1,29 @@ -import TTY, UIBase, Tk +# UI module directory +# Copyright (C) 2002 John Goerzen +# +# +# 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 + diff --git a/head/offlineimap/ui/detector.py b/head/offlineimap/ui/detector.py new file mode 100644 index 0000000..ecc98c6 --- /dev/null +++ b/head/offlineimap/ui/detector.py @@ -0,0 +1,38 @@ +# UI base class +# Copyright (C) 2002 John Goerzen +# +# +# 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