]> granicus.if.org Git - python/commitdiff
Import MacOS at the top instead of insize Tk.__init__() -- the latter
authorGuido van Rossum <guido@python.org>
Wed, 29 Apr 1998 21:43:36 +0000 (21:43 +0000)
committerGuido van Rossum <guido@python.org>
Wed, 29 Apr 1998 21:43:36 +0000 (21:43 +0000)
repeats the I/O for the failed import on each interpreter creation.

Lib/lib-tk/Tkinter.py

index bc7dae753fb00231fc1c891463942eb6d9dba2b6..583e2263095336ecea47cb857e709b08dac62083 100644 (file)
@@ -8,6 +8,10 @@ TclError = _tkinter.TclError
 from types import *
 from Tkconstants import *
 import string; _string = string; del string
+try:
+       import MacOS; _MacOS = MacOS; del MacOS
+except ImportError:
+       _MacOS = None
 
 TkVersion = _string.atof(_tkinter.TK_VERSION)
 TclVersion = _string.atof(_tkinter.TCL_VERSION)
@@ -845,18 +849,11 @@ class Tk(Misc, Wm):
                        baseName, ext = os.path.splitext(baseName)
                        if ext not in ('.py', 'pyc'): baseName = baseName + ext
                self.tk = _tkinter.create(screenName, baseName, className)
-               try:
+               if _MacOS:
                        # Disable event scanning except for Command-Period
-                       import MacOS
-                       try:
-                               MacOS.SchedParams(1, 0)
-                       except AttributeError:
-                               # pre-1.5, use old routine
-                               MacOS.EnableAppswitch(0)
-               except ImportError:
-                       pass
-               else:
+                       _MacOS.SchedParams(1, 0)
                        # Work around nasty MacTk bug
+                       # XXX Is this one still needed?
                        self.update()
                # Version sanity checks
                tk_version = self.tk.getvar('tk_version')