Added minimal support for floating windows.

This commit is contained in:
Just van Rossum 2002-02-04 12:52:44 +00:00
parent bf0a9084c5
commit 4014401c6c
4 changed files with 39 additions and 18 deletions

View File

@ -27,6 +27,11 @@ import types
import EasyDialogs import EasyDialogs
try:
MyFrontWindow = FrontNonFloatingWindow
except NameError:
MyFrontWindow = FrontWindow
kHighLevelEvent = 23 # Don't know what header file this should come from kHighLevelEvent = 23 # Don't know what header file this should come from
SCROLLBARWIDTH = 16 # Again, not a clue... SCROLLBARWIDTH = 16 # Again, not a clue...
@ -348,7 +353,7 @@ class Application:
return return
else: else:
# See whether the front window wants it # See whether the front window wants it
w = FrontWindow() w = MyFrontWindow()
if w and self._windows.has_key(w): if w and self._windows.has_key(w):
window = self._windows[w] window = self._windows[w]
try: try:
@ -393,7 +398,7 @@ class Application:
def do_suspendresume(self, event): def do_suspendresume(self, event):
(what, message, when, where, modifiers) = event (what, message, when, where, modifiers) = event
wid = FrontWindow() wid = MyFrontWindow()
if wid and self._windows.has_key(wid): if wid and self._windows.has_key(wid):
window = self._windows[wid] window = self._windows[wid]
window.do_activate(message & 1, event) window.do_activate(message & 1, event)
@ -497,7 +502,7 @@ class MenuBar:
for i in range(len(menu.items)): for i in range(len(menu.items)):
label, shortcut, callback, kind = menu.items[i] label, shortcut, callback, kind = menu.items[i]
if type(callback) == types.StringType: if type(callback) == types.StringType:
wid = Win.FrontWindow() wid = MyFrontWindow()
if wid and self.parent._windows.has_key(wid): if wid and self.parent._windows.has_key(wid):
window = self.parent._windows[wid] window = self.parent._windows[wid]
if hasattr(window, "domenu_" + callback): if hasattr(window, "domenu_" + callback):
@ -589,7 +594,7 @@ class Menu:
menuhandler = callback menuhandler = callback
else: else:
# callback is string # callback is string
wid = Win.FrontWindow() wid = MyFrontWindow()
if wid and self.bar.parent._windows.has_key(wid): if wid and self.bar.parent._windows.has_key(wid):
window = self.bar.parent._windows[wid] window = self.bar.parent._windows[wid]
if hasattr(window, "domenu_" + callback): if hasattr(window, "domenu_" + callback):
@ -634,7 +639,7 @@ class PopupMenu(Menu):
id = (reply & 0xffff0000) >> 16 id = (reply & 0xffff0000) >> 16
item = reply & 0xffff item = reply & 0xffff
if not window: if not window:
wid = Win.FrontWindow() wid = MyFrontWindow()
try: try:
window = self.bar.parent._windows[wid] window = self.bar.parent._windows[wid]
except: except:
@ -797,7 +802,7 @@ class Window:
# If we're not frontmost, select ourselves and wait for # If we're not frontmost, select ourselves and wait for
# the activate event. # the activate event.
# #
if FrontWindow() <> window: if MyFrontWindow() <> window:
window.SelectWindow() window.SelectWindow()
return return
# We are. Handle the event. # We are. Handle the event.
@ -846,7 +851,7 @@ class ControlsWindow(Window):
if DEBUG: print "control hit in", window, "on", control, "; pcode =", pcode if DEBUG: print "control hit in", window, "on", control, "; pcode =", pcode
def do_inContent(self, partcode, window, event): def do_inContent(self, partcode, window, event):
if FrontWindow() <> window: if MyFrontWindow() <> window:
window.SelectWindow() window.SelectWindow()
return return
(what, message, when, where, modifiers) = event (what, message, when, where, modifiers) = event

View File

@ -17,6 +17,12 @@ import string
import marshal import marshal
import re import re
if hasattr(Win, "FrontNonFloatingWindow"):
MyFrontWindow = Win.FrontNonFloatingWindow
else:
MyFrontWindow = Win.FrontWindow
try: try:
import Wthreading import Wthreading
except ImportError: except ImportError:
@ -1189,7 +1195,7 @@ def _filename_as_modname(fname):
return string.join(string.split(modname, '.'), '_') return string.join(string.split(modname, '.'), '_')
def findeditor(topwindow, fromtop = 0): def findeditor(topwindow, fromtop = 0):
wid = Win.FrontWindow() wid = MyFrontWindow()
if not fromtop: if not fromtop:
if topwindow.w and wid == topwindow.w.wid: if topwindow.w and wid == topwindow.w.wid:
wid = topwindow.w.wid.GetNextWindow() wid = topwindow.w.wid.GetNextWindow()

View File

@ -6,9 +6,14 @@ import MacOS
from Carbon import Events from Carbon import Events
import traceback import traceback
from types import * from types import *
from Carbon import Menu; MenuToolbox = Menu; del Menu 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. KILLUNKNOWNWINDOWS = 0 # Set to 0 for debugging.
class Application(FrameWork.Application): class Application(FrameWork.Application):
@ -115,7 +120,7 @@ class Application(FrameWork.Application):
break break
def do_frontWindowMethod(self, attr, *args): def do_frontWindowMethod(self, attr, *args):
wid = Win.FrontWindow() wid = MyFrontWindow()
if wid and self._windows.has_key(wid): if wid and self._windows.has_key(wid):
window = self._windows[wid] window = self._windows[wid]
if hasattr(window, attr): if hasattr(window, attr):
@ -146,7 +151,7 @@ class Application(FrameWork.Application):
if keycode in self.fkeymaps.keys(): # JJS if keycode in self.fkeymaps.keys(): # JJS
ch = self.fkeymaps[keycode] ch = self.fkeymaps[keycode]
modifiers = modifiers | FrameWork.cmdKey modifiers = modifiers | FrameWork.cmdKey
wid = Win.FrontWindow() wid = MyFrontWindow()
if modifiers & FrameWork.cmdKey and not modifiers & FrameWork.shiftKey: if modifiers & FrameWork.cmdKey and not modifiers & FrameWork.shiftKey:
if wid and self._windows.has_key(wid): if wid and self._windows.has_key(wid):
self.checkmenus(self._windows[wid]) self.checkmenus(self._windows[wid])
@ -175,7 +180,7 @@ class Application(FrameWork.Application):
Qd.InitCursor() Qd.InitCursor()
(what, message, when, where, modifiers) = event (what, message, when, where, modifiers) = event
self.checkopenwindowsmenu() self.checkopenwindowsmenu()
wid = Win.FrontWindow() wid = MyFrontWindow()
if wid and self._windows.has_key(wid): if wid and self._windows.has_key(wid):
self.checkmenus(self._windows[wid]) self.checkmenus(self._windows[wid])
else: else:
@ -209,7 +214,7 @@ class Application(FrameWork.Application):
def checkopenwindowsmenu(self): def checkopenwindowsmenu(self):
if self._openwindowscheckmark: if self._openwindowscheckmark:
self.openwindowsmenu.menu.CheckMenuItem(self._openwindowscheckmark, 0) self.openwindowsmenu.menu.CheckMenuItem(self._openwindowscheckmark, 0)
window = Win.FrontWindow() window = MyFrontWindow()
if window: if window:
for item, wid in self._openwindows.items(): for item, wid in self._openwindows.items():
if wid == window: if wid == window:
@ -441,7 +446,7 @@ class Menu(FrameWork.Menu):
def _getmenuhandler(self, callback): def _getmenuhandler(self, callback):
menuhandler = None menuhandler = None
wid = Win.FrontWindow() wid = MyFrontWindow()
if wid and self.bar.parent._windows.has_key(wid): if wid and self.bar.parent._windows.has_key(wid):
window = self.bar.parent._windows[wid] window = self.bar.parent._windows[wid]
if hasattr(window, "domenu_" + callback): if hasattr(window, "domenu_" + callback):

View File

@ -7,6 +7,11 @@ import struct
import traceback import traceback
from types import InstanceType, StringType from types import InstanceType, StringType
if hasattr(Win, "FrontNonFloatingWindow"):
MyFrontWindow = Win.FrontNonFloatingWindow
else:
MyFrontWindow = Win.FrontWindow
class Window(FrameWork.Window, Wbase.SelectableWidget): class Window(FrameWork.Window, Wbase.SelectableWidget):
@ -488,9 +493,9 @@ class ModalDialog(Dialog):
def do_key(self, event): def do_key(self, event):
(what, message, when, where, modifiers) = event (what, message, when, where, modifiers) = event
w = Win.FrontWindow() #w = Win.FrontWindow()
if w <> self.wid: #if w <> self.wid:
return # return
c = chr(message & Events.charCodeMask) c = chr(message & Events.charCodeMask)
if modifiers & Events.cmdKey: if modifiers & Events.cmdKey:
self.app.checkmenus(self) self.app.checkmenus(self)
@ -552,7 +557,7 @@ def FrontWindowInsert(stuff):
raise TypeError, 'string expected' raise TypeError, 'string expected'
import W import W
app = W.getapplication() app = W.getapplication()
wid = Win.FrontWindow() wid = MyFrontWindow()
if wid and app._windows.has_key(wid): if wid and app._windows.has_key(wid):
window = app._windows[wid] window = app._windows[wid]
if hasattr(window, "insert"): if hasattr(window, "insert"):