Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 815d2bf

Browse files
committed
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.
1 parent c71efe0 commit 815d2bf

8 files changed

Lines changed: 71 additions & 38 deletions

File tree

Mac/Tools/IDE/PyConsole.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,11 @@ def key(self, char, event):
7575
if char == Wkeys.returnkey:
7676
text = self.get()[self._inputstart:selstart]
7777
text = string.join(string.split(text, "\r"), "\n")
78-
saveyield = MacOS.EnableAppswitch(0)
78+
if hasattr(MacOS, 'EnableAppswitch'):
79+
saveyield = MacOS.EnableAppswitch(0)
7980
self.pyinteractive.executeline(text, self, self._namespace)
80-
MacOS.EnableAppswitch(saveyield)
81+
if hasattr(MacOS, 'EnableAppswitch'):
82+
MacOS.EnableAppswitch(saveyield)
8183
selstart, selend = self.getselection()
8284
self._inputstart = selstart
8385

@@ -275,13 +277,15 @@ def setupwidgets(self):
275277
self.w.bind("<activate>", self.activate)
276278

277279
def write(self, text):
278-
oldyield = MacOS.EnableAppswitch(-1)
280+
if hasattr(MacOS, 'EnableAppswitch'):
281+
oldyield = MacOS.EnableAppswitch(-1)
279282
try:
280283
self._buf = self._buf + text
281284
if '\n' in self._buf:
282285
self.flush()
283286
finally:
284-
MacOS.EnableAppswitch(oldyield)
287+
if hasattr(MacOS, 'EnableAppswitch'):
288+
MacOS.EnableAppswitch(oldyield)
285289

286290
def flush(self):
287291
self.show()

Mac/Tools/IDE/PyDebugger.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,8 @@ def trace_dispatch(self, frame, event, arg, TickCount = Evt.TickCount):
496496
self.w.panes.bottom.tracingmonitor.toggle()
497497
try:
498498
try:
499-
MacOS.EnableAppswitch(0)
499+
if hasattr(MacOS, 'EnableAppswitch'):
500+
MacOS.EnableAppswitch(0)
500501
if self.quitting:
501502
# returning None is not enough, a former BdbQuit exception
502503
# might have been eaten by the print statement
@@ -512,7 +513,8 @@ def trace_dispatch(self, frame, event, arg, TickCount = Evt.TickCount):
512513
print 'bdb.Bdb.dispatch: unknown debugging event:', `event`
513514
return self.trace_dispatch
514515
finally:
515-
MacOS.EnableAppswitch(-1)
516+
if hasattr(MacOS, 'EnableAppswitch'):
517+
MacOS.EnableAppswitch(-1)
516518
except KeyboardInterrupt:
517519
self.set_step()
518520
return self.trace_dispatch

Mac/Tools/IDE/PyDocSearch.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ def dosearch(docpath, searchstring, settings):
122122
_open = open
123123
hits = {}
124124
try:
125-
MacOS.EnableAppswitch(0)
125+
if hasattr(MacOS, 'EnableAppswitch'):
126+
MacOS.EnableAppswitch(0)
126127
try:
127128
for do, name in books:
128129
if not do:
@@ -145,7 +146,8 @@ def dosearch(docpath, searchstring, settings):
145146
if filehits:
146147
hits[fullpath] = filehits
147148
finally:
148-
MacOS.EnableAppswitch(-1)
149+
if hasattr(MacOS, 'EnableAppswitch'):
150+
MacOS.EnableAppswitch(-1)
149151
status.close()
150152
except KeyboardInterrupt:
151153
pass

Mac/Tools/IDE/PyEdit.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,7 +1128,8 @@ def execstring(pytext, globals, locals, filename="<string>", debugging=0,
11281128
else:
11291129
PyDebugger.startfromhere()
11301130
elif not haveThreading:
1131-
MacOS.EnableAppswitch(0)
1131+
if hasattr(MacOS, 'EnableAppswitch'):
1132+
MacOS.EnableAppswitch(0)
11321133
try:
11331134
if profiling:
11341135
import profile, ProfileBrowser
@@ -1145,7 +1146,8 @@ def execstring(pytext, globals, locals, filename="<string>", debugging=0,
11451146
exec code in globals, locals
11461147
finally:
11471148
if not haveThreading:
1148-
MacOS.EnableAppswitch(-1)
1149+
if hasattr(MacOS, 'EnableAppswitch'):
1150+
MacOS.EnableAppswitch(-1)
11491151
except W.AlertError, detail:
11501152
raise W.AlertError, detail
11511153
except (KeyboardInterrupt, BdbQuit):

Mac/Tools/IDE/PythonIDE.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,27 @@
44
# it like the "normal" interpreter.
55

66
__version__ = '1.0.1'
7-
7+
import sys
8+
import os
89

910
def init():
1011
import MacOS
11-
MacOS.EnableAppswitch(-1)
12+
if hasattr(MacOS, 'EnableAppswitch'):
13+
MacOS.EnableAppswitch(-1)
1214

1315
from Carbon import Qd, QuickDraw
1416
Qd.SetCursor(Qd.GetCursor(QuickDraw.watchCursor).data)
1517

1618
import macresource
1719
import sys, os
1820
macresource.need('DITL', 468, "PythonIDE.rsrc")
19-
widgetresfile = os.path.join(sys.exec_prefix, ":Mac:Tools:IDE:Widgets.rsrc")
21+
widgetrespathsegs = [sys.exec_prefix, "Mac", "Tools", "IDE", "Widgets.rsrc"]
22+
widgetresfile = os.path.join(*widgetrespathsegs)
2023
refno = macresource.need('CURS', 468, widgetresfile)
2124
if refno:
2225
# We're not a fullblown application
23-
ide_path = os.path.join(sys.exec_prefix, ":Mac:Tools:IDE")
26+
idepathsegs = [sys.exec_prefix, "Mac", "Tools", "IDE"]
27+
ide_path = os.path.join(*idepathsegs)
2428
else:
2529
# We are a fully frozen application
2630
ide_path = sys.argv[0]

Mac/Tools/IDE/PythonIDEMain.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
import W
88
import os
99
import macfs
10+
import MacOS
1011

12+
if MacOS.runtimemodel == 'macho':
13+
ELIPSES = '...'
14+
else:
15+
ELIPSES = '\xc9'
1116

1217
class PythonIDE(Wapplication.Application):
1318

@@ -50,13 +55,13 @@ def __init__(self):
5055
def makeusermenus(self):
5156
m = Wapplication.Menu(self.menubar, "File")
5257
newitem = FrameWork.MenuItem(m, "New", "N", 'new')
53-
openitem = FrameWork.MenuItem(m, "Open\xc9", "O", 'open')
58+
openitem = FrameWork.MenuItem(m, "Open"+ELIPSES, "O", 'open')
5459
FrameWork.Separator(m)
5560
closeitem = FrameWork.MenuItem(m, "Close", "W", 'close')
5661
saveitem = FrameWork.MenuItem(m, "Save", "S", 'save')
57-
saveasitem = FrameWork.MenuItem(m, "Save as\xc9", None, 'save_as')
62+
saveasitem = FrameWork.MenuItem(m, "Save as"+ELIPSES, None, 'save_as')
5863
FrameWork.Separator(m)
59-
saveasappletitem = FrameWork.MenuItem(m, "Save as Applet\xc9", None, 'save_as_applet')
64+
saveasappletitem = FrameWork.MenuItem(m, "Save as Applet"+ELIPSES, None, 'save_as_applet')
6065
FrameWork.Separator(m)
6166
quititem = FrameWork.MenuItem(m, "Quit", "Q", 'quit')
6267

@@ -71,7 +76,7 @@ def makeusermenus(self):
7176
selallitem = FrameWork.MenuItem(m, "Select all", "A", "selectall")
7277
sellineitem = FrameWork.MenuItem(m, "Select line", "L", "selectline")
7378
FrameWork.Separator(m)
74-
finditem = FrameWork.MenuItem(m, "Find\xc9", "F", "find")
79+
finditem = FrameWork.MenuItem(m, "Find"+ELIPSES, "F", "find")
7580
findagainitem = FrameWork.MenuItem(m, "Find again", 'G', "findnext")
7681
enterselitem = FrameWork.MenuItem(m, "Enter search string", "E", "entersearchstring")
7782
replaceitem = FrameWork.MenuItem(m, "Replace", None, "replace")
@@ -84,12 +89,12 @@ def makeusermenus(self):
8489
runitem = FrameWork.MenuItem(m, "Run window", "R", 'run')
8590
runselitem = FrameWork.MenuItem(m, "Run selection", None, 'runselection')
8691
FrameWork.Separator(m)
87-
moditem = FrameWork.MenuItem(m, "Module browser\xc9", "M", self.domenu_modulebrowser)
92+
moditem = FrameWork.MenuItem(m, "Module browser"+ELIPSES, "M", self.domenu_modulebrowser)
8893
FrameWork.Separator(m)
8994
mm = FrameWork.SubMenu(m, "Preferences")
90-
FrameWork.MenuItem(mm, "Set Scripts folder\xc9", None, self.do_setscriptsfolder)
91-
FrameWork.MenuItem(mm, "Editor default settings\xc9", None, self.do_editorprefs)
92-
FrameWork.MenuItem(mm, "Set default window font\xc9", None, self.do_setwindowfont)
95+
FrameWork.MenuItem(mm, "Set Scripts folder"+ELIPSES, None, self.do_setscriptsfolder)
96+
FrameWork.MenuItem(mm, "Editor default settings"+ELIPSES, None, self.do_editorprefs)
97+
FrameWork.MenuItem(mm, "Set default window font"+ELIPSES, None, self.do_setwindowfont)
9398

9499
self.openwindowsmenu = Wapplication.Menu(self.menubar, 'Windows')
95100
self.makeopenwindowsmenu()
@@ -110,7 +115,7 @@ def makeusermenus(self):
110115
path = os.path.join(os.getcwd(), "Scripts")
111116
if not os.path.exists(path):
112117
os.mkdir(path)
113-
f = open(os.path.join(path, "Place your scripts here\xc9"), "w")
118+
f = open(os.path.join(path, "Place your scripts here"+ELIPSES), "w")
114119
f.close()
115120
fss = macfs.FSSpec(path)
116121
self.scriptsfolder = fss.NewAlias()
@@ -159,7 +164,7 @@ def opendoc(self, path):
159164
W.Message("Can't open file of type '%s'." % ftype)
160165

161166
def getabouttext(self):
162-
return "About Python IDE\xc9"
167+
return "About Python IDE"+ELIPSES
163168

164169
def do_about(self, id, item, window, event):
165170
Splash.about()

Mac/Tools/IDE/Wapplication.py

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,33 @@ def __init__(self, signature='Pyth'):
2828
def mainloop(self, mask=FrameWork.everyEvent, wait=None):
2929
import W
3030
self.quitting = 0
31-
saveyield = MacOS.EnableAppswitch(-1)
31+
if hasattr(MacOS, 'EnableAppswitch'):
32+
saveyield = MacOS.EnableAppswitch(-1)
3233
try:
3334
while not self.quitting:
3435
try:
3536
self.do1event(mask, wait)
3637
except W.AlertError, detail:
37-
MacOS.EnableAppswitch(-1)
38+
if hasattr(MacOS, 'EnableAppswitch'):
39+
MacOS.EnableAppswitch(-1)
3840
W.Message(detail)
3941
except self.DebuggerQuit:
40-
MacOS.EnableAppswitch(-1)
42+
if hasattr(MacOS, 'EnableAppswitch'):
43+
MacOS.EnableAppswitch(-1)
4144
except:
42-
MacOS.EnableAppswitch(-1)
45+
if hasattr(MacOS, 'EnableAppswitch'):
46+
MacOS.EnableAppswitch(-1)
4347
import PyEdit
4448
PyEdit.tracebackwindow.traceback()
4549
finally:
46-
MacOS.EnableAppswitch(1)
50+
if hasattr(MacOS, 'EnableAppswitch'):
51+
MacOS.EnableAppswitch(1)
4752

4853
def debugger_mainloop(self, mask=FrameWork.everyEvent, wait=None):
4954
import W
5055
self.debugger_quitting = 0
51-
saveyield = MacOS.EnableAppswitch(-1)
56+
if hasattr(MacOS, 'EnableAppswitch'):
57+
saveyield = MacOS.EnableAppswitch(-1)
5258
try:
5359
while not self.quitting and not self.debugger_quitting:
5460
try:
@@ -59,7 +65,8 @@ def debugger_mainloop(self, mask=FrameWork.everyEvent, wait=None):
5965
import PyEdit
6066
PyEdit.tracebackwindow.traceback()
6167
finally:
62-
MacOS.EnableAppswitch(saveyield)
68+
if hasattr(MacOS, 'EnableAppswitch'):
69+
MacOS.EnableAppswitch(saveyield)
6370

6471
def breathe(self, wait=1):
6572
import W
@@ -309,19 +316,24 @@ def domenu_script(self, id, item, window, event):
309316
# exec in that window's namespace.
310317
# xxx what to do when it's not saved???
311318
# promt to save?
312-
MacOS.EnableAppswitch(0)
319+
if hasattr(MacOS, 'EnableAppswitch'):
320+
MacOS.EnableAppswitch(0)
313321
execfile(path, {'__name__': '__main__', '__file__': path})
314322
except W.AlertError, detail:
315-
MacOS.EnableAppswitch(-1)
323+
if hasattr(MacOS, 'EnableAppswitch'):
324+
MacOS.EnableAppswitch(-1)
316325
raise W.AlertError, detail
317326
except KeyboardInterrupt:
318-
MacOS.EnableAppswitch(-1)
327+
if hasattr(MacOS, 'EnableAppswitch'):
328+
MacOS.EnableAppswitch(-1)
319329
except:
320-
MacOS.EnableAppswitch(-1)
330+
if hasattr(MacOS, 'EnableAppswitch'):
331+
MacOS.EnableAppswitch(-1)
321332
import PyEdit
322333
PyEdit.tracebackwindow.traceback(1)
323334
else:
324-
MacOS.EnableAppswitch(-1)
335+
if hasattr(MacOS, 'EnableAppswitch'):
336+
MacOS.EnableAppswitch(-1)
325337
#os.chdir(cwd)
326338

327339
def openscript(self, filename, lineno=None, charoffset=0, modname=""):

Mac/Tools/IDE/Wwindows.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,8 @@ def close(self):
455455
Dialog.close(self)
456456

457457
def mainloop(self):
458-
saveyield = MacOS.EnableAppswitch(-1)
458+
if hasattr(MacOS, 'EnableAppswitch'):
459+
saveyield = MacOS.EnableAppswitch(-1)
459460
while not self.done:
460461
#self.do1event()
461462
self.do1event( Events.keyDownMask +
@@ -465,7 +466,8 @@ def mainloop(self):
465466
Events.mDownMask +
466467
Events.mUpMask,
467468
10)
468-
MacOS.EnableAppswitch(saveyield)
469+
if hasattr(MacOS, 'EnableAppswitch'):
470+
MacOS.EnableAppswitch(saveyield)
469471

470472
def do1event(self, mask = Events.everyEvent, wait = 0):
471473
ok, event = self.app.getevent(mask, wait)

0 commit comments

Comments
 (0)