]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Backport of 1.15 and 1.16:
authorJack Jansen <jack.jansen@cwi.nl>
Sun, 24 Feb 2002 23:21:35 +0000 (23:21 +0000)
committerJack Jansen <jack.jansen@cwi.nl>
Sun, 24 Feb 2002 23:21:35 +0000 (23:21 +0000)
- Added minimal support for floating windows.
- Changes by Donovan Preston (and a few minor ones by me) to make IDE run under
MachoPython. Mainly making sure we don't call routines that don't exist
and representing pathnames in a os.separator-neutral format.

These shouldn't interfere too much with Just's work on the next generation IDE,
I hope.

Mac/Tools/IDE/Wapplication.py
Mac/Tools/IDE/Wwindows.py

index 8839c90a8b90d804f617dbef12025250218eb833..fdcd9fbcc8b5cc2fb56a54457d632803e087aa6b 100644 (file)
@@ -6,9 +6,14 @@ import MacOS
 from Carbon import Events
 import traceback
 from types import *
-
 from Carbon import Menu; MenuToolbox = Menu; del Menu
 
+if hasattr(Win, "FrontNonFloatingWindow"):
+       MyFrontWindow = Win.FrontNonFloatingWindow
+else:
+       MyFrontWindow = Win.FrontWindow
+
+
 KILLUNKNOWNWINDOWS = 0  # Set to 0 for debugging.
 
 class Application(FrameWork.Application):
@@ -28,27 +33,33 @@ class Application(FrameWork.Application):
        def mainloop(self, mask=FrameWork.everyEvent, wait=None):
                import W
                self.quitting = 0
-               saveyield = MacOS.EnableAppswitch(-1)
+               if hasattr(MacOS, 'EnableAppswitch'):
+                       saveyield = MacOS.EnableAppswitch(-1)
                try:
                        while not self.quitting:
                                try:
                                        self.do1event(mask, wait)
                                except W.AlertError, detail:
-                                       MacOS.EnableAppswitch(-1)
+                                       if hasattr(MacOS, 'EnableAppswitch'):
+                                               MacOS.EnableAppswitch(-1)
                                        W.Message(detail)
                                except self.DebuggerQuit:
-                                       MacOS.EnableAppswitch(-1)
+                                       if hasattr(MacOS, 'EnableAppswitch'):
+                                               MacOS.EnableAppswitch(-1)
                                except:
-                                       MacOS.EnableAppswitch(-1)
+                                       if hasattr(MacOS, 'EnableAppswitch'):
+                                               MacOS.EnableAppswitch(-1)
                                        import PyEdit
                                        PyEdit.tracebackwindow.traceback()
                finally:
-                       MacOS.EnableAppswitch(1)
+                       if hasattr(MacOS, 'EnableAppswitch'):
+                               MacOS.EnableAppswitch(1)
        
        def debugger_mainloop(self, mask=FrameWork.everyEvent, wait=None):
                import W
                self.debugger_quitting = 0
-               saveyield = MacOS.EnableAppswitch(-1)
+               if hasattr(MacOS, 'EnableAppswitch'):
+                       saveyield = MacOS.EnableAppswitch(-1)
                try:
                        while not self.quitting and not self.debugger_quitting:
                                try:
@@ -59,7 +70,8 @@ class Application(FrameWork.Application):
                                        import PyEdit
                                        PyEdit.tracebackwindow.traceback()
                finally:
-                       MacOS.EnableAppswitch(saveyield)
+                       if hasattr(MacOS, 'EnableAppswitch'):
+                               MacOS.EnableAppswitch(saveyield)
        
        def breathe(self, wait=1):
                import W
@@ -108,7 +120,7 @@ class Application(FrameWork.Application):
                                        break
        
        def do_frontWindowMethod(self, attr, *args):
-               wid = Win.FrontWindow()
+               wid = MyFrontWindow()
                if wid and self._windows.has_key(wid):
                        window = self._windows[wid]
                        if hasattr(window, attr):
@@ -139,7 +151,7 @@ class Application(FrameWork.Application):
                if keycode in self.fkeymaps.keys():             # JJS
                        ch = self.fkeymaps[keycode]
                        modifiers = modifiers | FrameWork.cmdKey
-               wid = Win.FrontWindow()
+               wid = MyFrontWindow()
                if modifiers & FrameWork.cmdKey and not modifiers & FrameWork.shiftKey:
                        if wid and self._windows.has_key(wid):
                                self.checkmenus(self._windows[wid])
@@ -168,7 +180,7 @@ class Application(FrameWork.Application):
                Qd.InitCursor()
                (what, message, when, where, modifiers) = event
                self.checkopenwindowsmenu()
-               wid = Win.FrontWindow()
+               wid = MyFrontWindow()
                if wid and self._windows.has_key(wid):
                        self.checkmenus(self._windows[wid])
                else:
@@ -202,7 +214,7 @@ class Application(FrameWork.Application):
        def checkopenwindowsmenu(self):
                if self._openwindowscheckmark:
                        self.openwindowsmenu.menu.CheckMenuItem(self._openwindowscheckmark, 0)
-               window = Win.FrontWindow()
+               window = MyFrontWindow()
                if window:
                        for item, wid in self._openwindows.items():
                                if wid == window:
@@ -309,19 +321,24 @@ class Application(FrameWork.Application):
                                # exec in that window's namespace.
                                # xxx what to do when it's not saved???
                                # promt to save?
-                               MacOS.EnableAppswitch(0)
+                               if hasattr(MacOS, 'EnableAppswitch'):
+                                       MacOS.EnableAppswitch(0)
                                execfile(path, {'__name__': '__main__', '__file__': path})
                        except W.AlertError, detail:
-                               MacOS.EnableAppswitch(-1)
+                               if hasattr(MacOS, 'EnableAppswitch'):
+                                       MacOS.EnableAppswitch(-1)
                                raise W.AlertError, detail
                        except KeyboardInterrupt:
-                               MacOS.EnableAppswitch(-1)
+                               if hasattr(MacOS, 'EnableAppswitch'):
+                                       MacOS.EnableAppswitch(-1)
                        except:
-                               MacOS.EnableAppswitch(-1)
+                               if hasattr(MacOS, 'EnableAppswitch'):
+                                       MacOS.EnableAppswitch(-1)
                                import PyEdit
                                PyEdit.tracebackwindow.traceback(1)
                        else:
-                               MacOS.EnableAppswitch(-1)
+                               if hasattr(MacOS, 'EnableAppswitch'):
+                                       MacOS.EnableAppswitch(-1)
                        #os.chdir(cwd)
        
        def openscript(self, filename, lineno=None, charoffset=0, modname=""):
@@ -429,7 +446,7 @@ class Menu(FrameWork.Menu):
        
        def _getmenuhandler(self, callback):
                menuhandler = None
-               wid = Win.FrontWindow()
+               wid = MyFrontWindow()
                if wid and self.bar.parent._windows.has_key(wid):
                        window = self.bar.parent._windows[wid]
                        if hasattr(window, "domenu_" + callback):
index 1494187bca89884b52015d1e56e501e109cb886f..653499bf3a9d74a523aab4c31c70fedc52b6c8cd 100644 (file)
@@ -7,6 +7,11 @@ import struct
 import traceback
 from types import InstanceType, StringType
 
+if hasattr(Win, "FrontNonFloatingWindow"):
+       MyFrontWindow = Win.FrontNonFloatingWindow
+else:
+       MyFrontWindow = Win.FrontWindow
+
 
 class Window(FrameWork.Window, Wbase.SelectableWidget):
        
@@ -455,7 +460,8 @@ class ModalDialog(Dialog):
                Dialog.close(self)
        
        def mainloop(self):
-               saveyield = MacOS.EnableAppswitch(-1)
+               if hasattr(MacOS, 'EnableAppswitch'):
+                       saveyield = MacOS.EnableAppswitch(-1)
                while not self.done:
                        #self.do1event()
                        self.do1event(  Events.keyDownMask + 
@@ -465,7 +471,8 @@ class ModalDialog(Dialog):
                                                Events.mDownMask +
                                                Events.mUpMask, 
                                                10)
-               MacOS.EnableAppswitch(saveyield)
+               if hasattr(MacOS, 'EnableAppswitch'):
+                       MacOS.EnableAppswitch(saveyield)
        
        def do1event(self, mask = Events.everyEvent, wait = 0):
                ok, event = self.app.getevent(mask, wait)
@@ -486,9 +493,9 @@ class ModalDialog(Dialog):
        
        def do_key(self, event):
                (what, message, when, where, modifiers) = event
-               w = Win.FrontWindow()
-               if w <> self.wid:
-                       return
+               #w = Win.FrontWindow()
+               #if w <> self.wid:
+               #       return
                c = chr(message & Events.charCodeMask)
                if modifiers & Events.cmdKey:
                        self.app.checkmenus(self)
@@ -550,7 +557,7 @@ def FrontWindowInsert(stuff):
                raise TypeError, 'string expected'
        import W
        app = W.getapplication()
-       wid = Win.FrontWindow()
+       wid = MyFrontWindow()
        if wid and app._windows.has_key(wid):
                window = app._windows[wid]
                if hasattr(window, "insert"):
@@ -564,8 +571,13 @@ def FrontWindowInsert(stuff):
                        "Can't find window or widget to insert text into; copy to clipboard instead?", 
                        1) == 1:
                from Carbon import Scrap
-               Scrap.ZeroScrap()
-               Scrap.PutScrap('TEXT', stuff)
+               if hasattr(Scrap, 'PutScrap'):
+                       Scrap.ZeroScrap()
+                       Scrap.PutScrap('TEXT', stuff)
+               else:
+                       Scrap.ClearCurrentScrap()
+                       sc = Scrap.GetCurrentScrap()
+                       sc.PutScrapFlavor('TEXT', 0, stuff)
 
 
 # not quite based on the same function in FrameWork