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.
This commit is contained in:
Jack Jansen 2002-01-21 23:00:52 +00:00
parent c71efe0116
commit 815d2bf067
8 changed files with 71 additions and 38 deletions

View File

@ -75,9 +75,11 @@ def key(self, char, event):
if char == Wkeys.returnkey:
text = self.get()[self._inputstart:selstart]
text = string.join(string.split(text, "\r"), "\n")
saveyield = MacOS.EnableAppswitch(0)
if hasattr(MacOS, 'EnableAppswitch'):
saveyield = MacOS.EnableAppswitch(0)
self.pyinteractive.executeline(text, self, self._namespace)
MacOS.EnableAppswitch(saveyield)
if hasattr(MacOS, 'EnableAppswitch'):
MacOS.EnableAppswitch(saveyield)
selstart, selend = self.getselection()
self._inputstart = selstart
@ -275,13 +277,15 @@ def setupwidgets(self):
self.w.bind("<activate>", self.activate)
def write(self, text):
oldyield = MacOS.EnableAppswitch(-1)
if hasattr(MacOS, 'EnableAppswitch'):
oldyield = MacOS.EnableAppswitch(-1)
try:
self._buf = self._buf + text
if '\n' in self._buf:
self.flush()
finally:
MacOS.EnableAppswitch(oldyield)
if hasattr(MacOS, 'EnableAppswitch'):
MacOS.EnableAppswitch(oldyield)
def flush(self):
self.show()

View File

@ -496,7 +496,8 @@ def trace_dispatch(self, frame, event, arg, TickCount = Evt.TickCount):
self.w.panes.bottom.tracingmonitor.toggle()
try:
try:
MacOS.EnableAppswitch(0)
if hasattr(MacOS, 'EnableAppswitch'):
MacOS.EnableAppswitch(0)
if self.quitting:
# returning None is not enough, a former BdbQuit exception
# might have been eaten by the print statement
@ -512,7 +513,8 @@ def trace_dispatch(self, frame, event, arg, TickCount = Evt.TickCount):
print 'bdb.Bdb.dispatch: unknown debugging event:', `event`
return self.trace_dispatch
finally:
MacOS.EnableAppswitch(-1)
if hasattr(MacOS, 'EnableAppswitch'):
MacOS.EnableAppswitch(-1)
except KeyboardInterrupt:
self.set_step()
return self.trace_dispatch

View File

@ -122,7 +122,8 @@ def dosearch(docpath, searchstring, settings):
_open = open
hits = {}
try:
MacOS.EnableAppswitch(0)
if hasattr(MacOS, 'EnableAppswitch'):
MacOS.EnableAppswitch(0)
try:
for do, name in books:
if not do:
@ -145,7 +146,8 @@ def dosearch(docpath, searchstring, settings):
if filehits:
hits[fullpath] = filehits
finally:
MacOS.EnableAppswitch(-1)
if hasattr(MacOS, 'EnableAppswitch'):
MacOS.EnableAppswitch(-1)
status.close()
except KeyboardInterrupt:
pass

View File

@ -1128,7 +1128,8 @@ def execstring(pytext, globals, locals, filename="<string>", debugging=0,
else:
PyDebugger.startfromhere()
elif not haveThreading:
MacOS.EnableAppswitch(0)
if hasattr(MacOS, 'EnableAppswitch'):
MacOS.EnableAppswitch(0)
try:
if profiling:
import profile, ProfileBrowser
@ -1145,7 +1146,8 @@ def execstring(pytext, globals, locals, filename="<string>", debugging=0,
exec code in globals, locals
finally:
if not haveThreading:
MacOS.EnableAppswitch(-1)
if hasattr(MacOS, 'EnableAppswitch'):
MacOS.EnableAppswitch(-1)
except W.AlertError, detail:
raise W.AlertError, detail
except (KeyboardInterrupt, BdbQuit):

View File

@ -4,11 +4,13 @@
# it like the "normal" interpreter.
__version__ = '1.0.1'
import sys
import os
def init():
import MacOS
MacOS.EnableAppswitch(-1)
if hasattr(MacOS, 'EnableAppswitch'):
MacOS.EnableAppswitch(-1)
from Carbon import Qd, QuickDraw
Qd.SetCursor(Qd.GetCursor(QuickDraw.watchCursor).data)
@ -16,11 +18,13 @@ def init():
import macresource
import sys, os
macresource.need('DITL', 468, "PythonIDE.rsrc")
widgetresfile = os.path.join(sys.exec_prefix, ":Mac:Tools:IDE:Widgets.rsrc")
widgetrespathsegs = [sys.exec_prefix, "Mac", "Tools", "IDE", "Widgets.rsrc"]
widgetresfile = os.path.join(*widgetrespathsegs)
refno = macresource.need('CURS', 468, widgetresfile)
if refno:
# We're not a fullblown application
ide_path = os.path.join(sys.exec_prefix, ":Mac:Tools:IDE")
idepathsegs = [sys.exec_prefix, "Mac", "Tools", "IDE"]
ide_path = os.path.join(*idepathsegs)
else:
# We are a fully frozen application
ide_path = sys.argv[0]

View File

@ -7,7 +7,12 @@
import W
import os
import macfs
import MacOS
if MacOS.runtimemodel == 'macho':
ELIPSES = '...'
else:
ELIPSES = '\xc9'
class PythonIDE(Wapplication.Application):
@ -50,13 +55,13 @@ def __init__(self):
def makeusermenus(self):
m = Wapplication.Menu(self.menubar, "File")
newitem = FrameWork.MenuItem(m, "New", "N", 'new')
openitem = FrameWork.MenuItem(m, "Open\xc9", "O", 'open')
openitem = FrameWork.MenuItem(m, "Open"+ELIPSES, "O", 'open')
FrameWork.Separator(m)
closeitem = FrameWork.MenuItem(m, "Close", "W", 'close')
saveitem = FrameWork.MenuItem(m, "Save", "S", 'save')
saveasitem = FrameWork.MenuItem(m, "Save as\xc9", None, 'save_as')
saveasitem = FrameWork.MenuItem(m, "Save as"+ELIPSES, None, 'save_as')
FrameWork.Separator(m)
saveasappletitem = FrameWork.MenuItem(m, "Save as Applet\xc9", None, 'save_as_applet')
saveasappletitem = FrameWork.MenuItem(m, "Save as Applet"+ELIPSES, None, 'save_as_applet')
FrameWork.Separator(m)
quititem = FrameWork.MenuItem(m, "Quit", "Q", 'quit')
@ -71,7 +76,7 @@ def makeusermenus(self):
selallitem = FrameWork.MenuItem(m, "Select all", "A", "selectall")
sellineitem = FrameWork.MenuItem(m, "Select line", "L", "selectline")
FrameWork.Separator(m)
finditem = FrameWork.MenuItem(m, "Find\xc9", "F", "find")
finditem = FrameWork.MenuItem(m, "Find"+ELIPSES, "F", "find")
findagainitem = FrameWork.MenuItem(m, "Find again", 'G', "findnext")
enterselitem = FrameWork.MenuItem(m, "Enter search string", "E", "entersearchstring")
replaceitem = FrameWork.MenuItem(m, "Replace", None, "replace")
@ -84,12 +89,12 @@ def makeusermenus(self):
runitem = FrameWork.MenuItem(m, "Run window", "R", 'run')
runselitem = FrameWork.MenuItem(m, "Run selection", None, 'runselection')
FrameWork.Separator(m)
moditem = FrameWork.MenuItem(m, "Module browser\xc9", "M", self.domenu_modulebrowser)
moditem = FrameWork.MenuItem(m, "Module browser"+ELIPSES, "M", self.domenu_modulebrowser)
FrameWork.Separator(m)
mm = FrameWork.SubMenu(m, "Preferences")
FrameWork.MenuItem(mm, "Set Scripts folder\xc9", None, self.do_setscriptsfolder)
FrameWork.MenuItem(mm, "Editor default settings\xc9", None, self.do_editorprefs)
FrameWork.MenuItem(mm, "Set default window font\xc9", None, self.do_setwindowfont)
FrameWork.MenuItem(mm, "Set Scripts folder"+ELIPSES, None, self.do_setscriptsfolder)
FrameWork.MenuItem(mm, "Editor default settings"+ELIPSES, None, self.do_editorprefs)
FrameWork.MenuItem(mm, "Set default window font"+ELIPSES, None, self.do_setwindowfont)
self.openwindowsmenu = Wapplication.Menu(self.menubar, 'Windows')
self.makeopenwindowsmenu()
@ -110,7 +115,7 @@ def makeusermenus(self):
path = os.path.join(os.getcwd(), "Scripts")
if not os.path.exists(path):
os.mkdir(path)
f = open(os.path.join(path, "Place your scripts here\xc9"), "w")
f = open(os.path.join(path, "Place your scripts here"+ELIPSES), "w")
f.close()
fss = macfs.FSSpec(path)
self.scriptsfolder = fss.NewAlias()
@ -159,7 +164,7 @@ def opendoc(self, path):
W.Message("Can't open file of type '%s'." % ftype)
def getabouttext(self):
return "About Python IDE\xc9"
return "About Python IDE"+ELIPSES
def do_about(self, id, item, window, event):
Splash.about()

View File

@ -28,27 +28,33 @@ def __init__(self, signature='Pyth'):
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 +65,8 @@ def debugger_mainloop(self, mask=FrameWork.everyEvent, wait=None):
import PyEdit
PyEdit.tracebackwindow.traceback()
finally:
MacOS.EnableAppswitch(saveyield)
if hasattr(MacOS, 'EnableAppswitch'):
MacOS.EnableAppswitch(saveyield)
def breathe(self, wait=1):
import W
@ -309,19 +316,24 @@ def domenu_script(self, id, item, window, event):
# 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=""):

View File

@ -455,7 +455,8 @@ def close(self):
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 +466,8 @@ def mainloop(self):
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)