Mercurial > cpython-lru_cache-weakref
annotate Mac/Tools/IDE/PythonIDEMain.py @ 21772:ec750e37671b legacy-trunk
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.
| author | Jack Jansen <jack.jansen@cwi.nl> |
|---|---|
| date | Mon, 21 Jan 2002 23:00:52 +0000 |
| parents | c1ebc0285a5e |
| children | da008b5c5035 |
| rev | line source |
|---|---|
|
20836
c1ebc0285a5e
removed import display hackery
Just van Rossum <just@letterror.com>
parents:
19488
diff
changeset
|
1 # copyright 1997-2001 Just van Rossum, Letterror. just@letterror.com |
| 10047 | 2 |
| 3 import Splash | |
| 4 | |
| 5 import FrameWork | |
| 6 import Wapplication | |
| 7 import W | |
| 8 import os | |
| 9 import macfs | |
|
21772
ec750e37671b
Changes by Donovan Preston (and a few minor ones by me) to make IDE run under
Jack Jansen <jack.jansen@cwi.nl>
parents:
20836
diff
changeset
|
10 import MacOS |
| 10047 | 11 |
|
21772
ec750e37671b
Changes by Donovan Preston (and a few minor ones by me) to make IDE run under
Jack Jansen <jack.jansen@cwi.nl>
parents:
20836
diff
changeset
|
12 if MacOS.runtimemodel == 'macho': |
|
ec750e37671b
Changes by Donovan Preston (and a few minor ones by me) to make IDE run under
Jack Jansen <jack.jansen@cwi.nl>
parents:
20836
diff
changeset
|
13 ELIPSES = '...' |
|
ec750e37671b
Changes by Donovan Preston (and a few minor ones by me) to make IDE run under
Jack Jansen <jack.jansen@cwi.nl>
parents:
20836
diff
changeset
|
14 else: |
|
ec750e37671b
Changes by Donovan Preston (and a few minor ones by me) to make IDE run under
Jack Jansen <jack.jansen@cwi.nl>
parents:
20836
diff
changeset
|
15 ELIPSES = '\xc9' |
| 10047 | 16 |
| 17 class PythonIDE(Wapplication.Application): | |
| 18 | |
| 19 def __init__(self): | |
| 20 self.preffilepath = ":Python:PythonIDE preferences" | |
|
10322
a87cfea30b04
changed creator to 'Pide' -- jvr
Just van Rossum <just@lettererror.com>
parents:
10310
diff
changeset
|
21 Wapplication.Application.__init__(self, 'Pide') |
|
19488
42b2f1936254
Import the MacOS toolbox modules from the Carbon package.
Jack Jansen <jack.jansen@cwi.nl>
parents:
18167
diff
changeset
|
22 from Carbon import AE |
|
42b2f1936254
Import the MacOS toolbox modules from the Carbon package.
Jack Jansen <jack.jansen@cwi.nl>
parents:
18167
diff
changeset
|
23 from Carbon import AppleEvents |
| 10047 | 24 |
| 25 AE.AEInstallEventHandler(AppleEvents.kCoreEventClass, AppleEvents.kAEOpenApplication, | |
| 26 self.ignoreevent) | |
|
17015
3c650d9c38e7
Handle the ReopenApplication event (by ignoring it).
Jack Jansen <jack.jansen@cwi.nl>
parents:
15284
diff
changeset
|
27 AE.AEInstallEventHandler(AppleEvents.kCoreEventClass, AppleEvents.kAEReopenApplication, |
|
3c650d9c38e7
Handle the ReopenApplication event (by ignoring it).
Jack Jansen <jack.jansen@cwi.nl>
parents:
15284
diff
changeset
|
28 self.ignoreevent) |
| 10047 | 29 AE.AEInstallEventHandler(AppleEvents.kCoreEventClass, AppleEvents.kAEPrintDocuments, |
| 30 self.ignoreevent) | |
| 31 AE.AEInstallEventHandler(AppleEvents.kCoreEventClass, AppleEvents.kAEOpenDocuments, | |
| 32 self.opendocsevent) | |
| 33 AE.AEInstallEventHandler(AppleEvents.kCoreEventClass, AppleEvents.kAEQuitApplication, | |
| 34 self.quitevent) | |
| 35 import PyConsole, PyEdit | |
| 36 Splash.wait() | |
| 37 PyConsole.installoutput() | |
| 38 PyConsole.installconsole() | |
| 39 import sys | |
| 40 for path in sys.argv[1:]: | |
| 41 self.opendoc(path) | |
|
12308
ddc4e62b216b
added experimental microthread support for use with stackless python -- bw compatible (jvr)
Just van Rossum <just@lettererror.com>
parents:
11949
diff
changeset
|
42 try: |
|
15284
b940a0fc29e3
Cleaned uthread dependencies (jvr)
Just van Rossum <just@lettererror.com>
parents:
12308
diff
changeset
|
43 import Wthreading |
|
12308
ddc4e62b216b
added experimental microthread support for use with stackless python -- bw compatible (jvr)
Just van Rossum <just@lettererror.com>
parents:
11949
diff
changeset
|
44 except ImportError: |
|
ddc4e62b216b
added experimental microthread support for use with stackless python -- bw compatible (jvr)
Just van Rossum <just@lettererror.com>
parents:
11949
diff
changeset
|
45 self.mainloop() |
|
ddc4e62b216b
added experimental microthread support for use with stackless python -- bw compatible (jvr)
Just van Rossum <just@lettererror.com>
parents:
11949
diff
changeset
|
46 else: |
|
15284
b940a0fc29e3
Cleaned uthread dependencies (jvr)
Just van Rossum <just@lettererror.com>
parents:
12308
diff
changeset
|
47 if Wthreading.haveThreading: |
|
b940a0fc29e3
Cleaned uthread dependencies (jvr)
Just van Rossum <just@lettererror.com>
parents:
12308
diff
changeset
|
48 self.mainthread = Wthreading.Thread("IDE event loop", self.mainloop) |
|
b940a0fc29e3
Cleaned uthread dependencies (jvr)
Just van Rossum <just@lettererror.com>
parents:
12308
diff
changeset
|
49 self.mainthread.start() |
|
b940a0fc29e3
Cleaned uthread dependencies (jvr)
Just van Rossum <just@lettererror.com>
parents:
12308
diff
changeset
|
50 #self.mainthread.setResistant(1) |
|
b940a0fc29e3
Cleaned uthread dependencies (jvr)
Just van Rossum <just@lettererror.com>
parents:
12308
diff
changeset
|
51 Wthreading.run() |
|
b940a0fc29e3
Cleaned uthread dependencies (jvr)
Just van Rossum <just@lettererror.com>
parents:
12308
diff
changeset
|
52 else: |
|
b940a0fc29e3
Cleaned uthread dependencies (jvr)
Just van Rossum <just@lettererror.com>
parents:
12308
diff
changeset
|
53 self.mainloop() |
| 10047 | 54 |
| 55 def makeusermenus(self): | |
| 56 m = Wapplication.Menu(self.menubar, "File") | |
| 57 newitem = FrameWork.MenuItem(m, "New", "N", 'new') | |
|
21772
ec750e37671b
Changes by Donovan Preston (and a few minor ones by me) to make IDE run under
Jack Jansen <jack.jansen@cwi.nl>
parents:
20836
diff
changeset
|
58 openitem = FrameWork.MenuItem(m, "Open"+ELIPSES, "O", 'open') |
| 10047 | 59 FrameWork.Separator(m) |
| 60 closeitem = FrameWork.MenuItem(m, "Close", "W", 'close') | |
| 61 saveitem = FrameWork.MenuItem(m, "Save", "S", 'save') | |
|
21772
ec750e37671b
Changes by Donovan Preston (and a few minor ones by me) to make IDE run under
Jack Jansen <jack.jansen@cwi.nl>
parents:
20836
diff
changeset
|
62 saveasitem = FrameWork.MenuItem(m, "Save as"+ELIPSES, None, 'save_as') |
| 10047 | 63 FrameWork.Separator(m) |
|
21772
ec750e37671b
Changes by Donovan Preston (and a few minor ones by me) to make IDE run under
Jack Jansen <jack.jansen@cwi.nl>
parents:
20836
diff
changeset
|
64 saveasappletitem = FrameWork.MenuItem(m, "Save as Applet"+ELIPSES, None, 'save_as_applet') |
| 10047 | 65 FrameWork.Separator(m) |
| 66 quititem = FrameWork.MenuItem(m, "Quit", "Q", 'quit') | |
| 67 | |
| 68 m = Wapplication.Menu(self.menubar, "Edit") | |
| 69 undoitem = FrameWork.MenuItem(m, "Undo", 'Z', "undo") | |
| 70 FrameWork.Separator(m) | |
| 71 cutitem = FrameWork.MenuItem(m, "Cut", 'X', "cut") | |
| 72 copyitem = FrameWork.MenuItem(m, "Copy", "C", "copy") | |
| 73 pasteitem = FrameWork.MenuItem(m, "Paste", "V", "paste") | |
| 74 FrameWork.MenuItem(m, "Clear", None, "clear") | |
| 75 FrameWork.Separator(m) | |
| 76 selallitem = FrameWork.MenuItem(m, "Select all", "A", "selectall") | |
| 77 sellineitem = FrameWork.MenuItem(m, "Select line", "L", "selectline") | |
| 78 FrameWork.Separator(m) | |
|
21772
ec750e37671b
Changes by Donovan Preston (and a few minor ones by me) to make IDE run under
Jack Jansen <jack.jansen@cwi.nl>
parents:
20836
diff
changeset
|
79 finditem = FrameWork.MenuItem(m, "Find"+ELIPSES, "F", "find") |
| 10047 | 80 findagainitem = FrameWork.MenuItem(m, "Find again", 'G', "findnext") |
| 81 enterselitem = FrameWork.MenuItem(m, "Enter search string", "E", "entersearchstring") | |
| 82 replaceitem = FrameWork.MenuItem(m, "Replace", None, "replace") | |
| 83 replacefinditem = FrameWork.MenuItem(m, "Replace & find again", 'T', "replacefind") | |
| 84 FrameWork.Separator(m) | |
| 85 shiftleftitem = FrameWork.MenuItem(m, "Shift left", "[", "shiftleft") | |
| 86 shiftrightitem = FrameWork.MenuItem(m, "Shift right", "]", "shiftright") | |
| 87 | |
| 88 m = Wapplication.Menu(self.menubar, "Python") | |
| 89 runitem = FrameWork.MenuItem(m, "Run window", "R", 'run') | |
| 90 runselitem = FrameWork.MenuItem(m, "Run selection", None, 'runselection') | |
| 91 FrameWork.Separator(m) | |
|
21772
ec750e37671b
Changes by Donovan Preston (and a few minor ones by me) to make IDE run under
Jack Jansen <jack.jansen@cwi.nl>
parents:
20836
diff
changeset
|
92 moditem = FrameWork.MenuItem(m, "Module browser"+ELIPSES, "M", self.domenu_modulebrowser) |
| 10047 | 93 FrameWork.Separator(m) |
| 94 mm = FrameWork.SubMenu(m, "Preferences") | |
|
21772
ec750e37671b
Changes by Donovan Preston (and a few minor ones by me) to make IDE run under
Jack Jansen <jack.jansen@cwi.nl>
parents:
20836
diff
changeset
|
95 FrameWork.MenuItem(mm, "Set Scripts folder"+ELIPSES, None, self.do_setscriptsfolder) |
|
ec750e37671b
Changes by Donovan Preston (and a few minor ones by me) to make IDE run under
Jack Jansen <jack.jansen@cwi.nl>
parents:
20836
diff
changeset
|
96 FrameWork.MenuItem(mm, "Editor default settings"+ELIPSES, None, self.do_editorprefs) |
|
ec750e37671b
Changes by Donovan Preston (and a few minor ones by me) to make IDE run under
Jack Jansen <jack.jansen@cwi.nl>
parents:
20836
diff
changeset
|
97 FrameWork.MenuItem(mm, "Set default window font"+ELIPSES, None, self.do_setwindowfont) |
| 10047 | 98 |
| 99 self.openwindowsmenu = Wapplication.Menu(self.menubar, 'Windows') | |
| 100 self.makeopenwindowsmenu() | |
| 101 self._menustocheck = [closeitem, saveitem, saveasitem, saveasappletitem, | |
| 102 undoitem, cutitem, copyitem, pasteitem, | |
| 103 selallitem, sellineitem, | |
| 104 finditem, findagainitem, enterselitem, replaceitem, replacefinditem, | |
| 105 shiftleftitem, shiftrightitem, | |
| 106 runitem, runselitem] | |
| 107 | |
| 108 prefs = self.getprefs() | |
| 109 try: | |
| 110 fss, fss_changed = macfs.RawAlias(prefs.scriptsfolder).Resolve() | |
|
10310
a4d99607344f
fixed "crashing" bug when scripts folder as stored in prefs file does not exist.
Just van Rossum <just@lettererror.com>
parents:
10087
diff
changeset
|
111 self.scriptsfolder = fss.NewAlias() |
| 10047 | 112 except: |
|
11325
c702a12d318d
1 - added "set default window font" menu
Just van Rossum <just@lettererror.com>
parents:
11031
diff
changeset
|
113 path = os.path.join(os.getcwd(), ":Mac:IDE scripts") |
| 10047 | 114 if not os.path.exists(path): |
|
11325
c702a12d318d
1 - added "set default window font" menu
Just van Rossum <just@lettererror.com>
parents:
11031
diff
changeset
|
115 path = os.path.join(os.getcwd(), "Scripts") |
|
c702a12d318d
1 - added "set default window font" menu
Just van Rossum <just@lettererror.com>
parents:
11031
diff
changeset
|
116 if not os.path.exists(path): |
|
c702a12d318d
1 - added "set default window font" menu
Just van Rossum <just@lettererror.com>
parents:
11031
diff
changeset
|
117 os.mkdir(path) |
|
21772
ec750e37671b
Changes by Donovan Preston (and a few minor ones by me) to make IDE run under
Jack Jansen <jack.jansen@cwi.nl>
parents:
20836
diff
changeset
|
118 f = open(os.path.join(path, "Place your scripts here"+ELIPSES), "w") |
|
11325
c702a12d318d
1 - added "set default window font" menu
Just van Rossum <just@lettererror.com>
parents:
11031
diff
changeset
|
119 f.close() |
| 10047 | 120 fss = macfs.FSSpec(path) |
| 121 self.scriptsfolder = fss.NewAlias() | |
| 122 self.scriptsfoldermodtime = fss.GetDates()[1] | |
| 123 else: | |
| 124 self.scriptsfoldermodtime = fss.GetDates()[1] | |
| 125 prefs.scriptsfolder = self.scriptsfolder.data | |
| 126 self._scripts = {} | |
| 127 self.scriptsmenu = None | |
| 128 self.makescriptsmenu() | |
| 129 | |
| 130 def quitevent(self, theAppleEvent, theReply): | |
|
19488
42b2f1936254
Import the MacOS toolbox modules from the Carbon package.
Jack Jansen <jack.jansen@cwi.nl>
parents:
18167
diff
changeset
|
131 from Carbon import AE |
| 10047 | 132 AE.AEInteractWithUser(50000000) |
| 133 self._quit() | |
| 134 | |
| 135 def suspendresume(self, onoff): | |
| 136 if onoff: | |
| 137 fss, fss_changed = self.scriptsfolder.Resolve() | |
| 138 modtime = fss.GetDates()[1] | |
| 139 if self.scriptsfoldermodtime <> modtime or fss_changed: | |
| 140 self.scriptsfoldermodtime = modtime | |
| 141 W.SetCursor('watch') | |
| 142 self.makescriptsmenu() | |
| 143 | |
| 144 def ignoreevent(self, theAppleEvent, theReply): | |
| 145 pass | |
| 146 | |
| 147 def opendocsevent(self, theAppleEvent, theReply): | |
| 148 W.SetCursor('watch') | |
| 149 import aetools | |
| 150 parameters, args = aetools.unpackevent(theAppleEvent) | |
| 151 docs = parameters['----'] | |
| 152 if type(docs) <> type([]): | |
| 153 docs = [docs] | |
| 154 for doc in docs: | |
| 155 fss, a = doc.Resolve() | |
| 156 path = fss.as_pathname() | |
| 157 self.opendoc(path) | |
| 158 | |
| 159 def opendoc(self, path): | |
| 160 fcreator, ftype = macfs.FSSpec(path).GetCreatorType() | |
| 161 if ftype == 'TEXT': | |
| 162 self.openscript(path) | |
| 163 else: | |
|
18167
c5ac6f055c62
Some long overdue maintainance. Made all IDE sources 7-bit-clean, to avoid any further encoding conversion troubles.
Just van Rossum <just@letterror.com>
parents:
17844
diff
changeset
|
164 W.Message("Can't open file of type '%s'." % ftype) |
| 10047 | 165 |
| 166 def getabouttext(self): | |
|
21772
ec750e37671b
Changes by Donovan Preston (and a few minor ones by me) to make IDE run under
Jack Jansen <jack.jansen@cwi.nl>
parents:
20836
diff
changeset
|
167 return "About Python IDE"+ELIPSES |
| 10047 | 168 |
| 169 def do_about(self, id, item, window, event): | |
| 170 Splash.about() | |
| 171 | |
| 172 def do_setscriptsfolder(self, *args): | |
| 173 fss, ok = macfs.GetDirectory("Select Scripts Folder") | |
| 174 if ok: | |
| 175 prefs = self.getprefs() | |
| 176 alis = fss.NewAlias() | |
| 177 prefs.scriptsfolder = alis.data | |
| 178 self.scriptsfolder = alis | |
| 179 self.makescriptsmenu() | |
| 180 prefs.save() | |
| 181 | |
| 182 def domenu_modulebrowser(self, *args): | |
| 183 W.SetCursor('watch') | |
| 184 import ModuleBrowser | |
| 185 ModuleBrowser.ModuleBrowser() | |
| 186 | |
| 187 def domenu_open(self, *args): | |
| 188 fss, ok = macfs.StandardGetFile("TEXT") | |
| 189 if ok: | |
| 190 self.openscript(fss.as_pathname()) | |
| 191 | |
| 192 def domenu_new(self, *args): | |
| 193 W.SetCursor('watch') | |
| 194 import PyEdit | |
| 195 return PyEdit.Editor() | |
| 196 | |
| 197 def makescriptsmenu(self): | |
| 198 W.SetCursor('watch') | |
| 199 if self._scripts: | |
| 200 for id, item in self._scripts.keys(): | |
| 201 if self.menubar.menus.has_key(id): | |
| 202 m = self.menubar.menus[id] | |
| 203 m.delete() | |
| 204 self._scripts = {} | |
| 205 if self.scriptsmenu: | |
| 206 if hasattr(self.scriptsmenu, 'id') and self.menubar.menus.has_key(self.scriptsmenu.id): | |
| 207 self.scriptsmenu.delete() | |
| 208 self.scriptsmenu = FrameWork.Menu(self.menubar, "Scripts") | |
| 209 #FrameWork.MenuItem(self.scriptsmenu, "New script", None, self.domenu_new) | |
| 210 #self.scriptsmenu.addseparator() | |
| 211 fss, fss_changed = self.scriptsfolder.Resolve() | |
| 212 self.scriptswalk(fss.as_pathname(), self.scriptsmenu) | |
| 213 | |
| 214 def makeopenwindowsmenu(self): | |
| 215 for i in range(len(self.openwindowsmenu.items)): | |
| 216 self.openwindowsmenu.menu.DeleteMenuItem(1) | |
| 217 self.openwindowsmenu.items = [] | |
| 218 windows = [] | |
| 219 self._openwindows = {} | |
| 220 for window in self._windows.keys(): | |
| 221 title = window.GetWTitle() | |
| 222 if not title: | |
| 223 title = "<no title>" | |
|
11949
5e48d83c0fce
Fixed multi-arg appends.
Jack Jansen <jack.jansen@cwi.nl>
parents:
11325
diff
changeset
|
224 windows.append((title, window)) |
| 10047 | 225 windows.sort() |
| 226 for title, window in windows: | |
| 227 if title == "Python Interactive": # ugly but useful hack by Joe Strout | |
| 228 shortcut = '0' | |
| 229 else: | |
| 230 shortcut = None | |
| 231 item = FrameWork.MenuItem(self.openwindowsmenu, title, shortcut, callback = self.domenu_openwindows) | |
| 232 self._openwindows[item.item] = window | |
| 233 self._openwindowscheckmark = 0 | |
| 234 self.checkopenwindowsmenu() | |
| 235 | |
| 236 def domenu_openwindows(self, id, item, window, event): | |
| 237 w = self._openwindows[item] | |
| 238 w.ShowWindow() | |
| 239 w.SelectWindow() | |
| 240 | |
| 241 def domenu_quit(self): | |
| 242 self._quit() | |
| 243 | |
| 244 def domenu_save(self, *args): | |
| 245 print "Save" | |
| 246 | |
| 247 def _quit(self): | |
| 248 import PyConsole, PyEdit | |
| 249 PyConsole.console.writeprefs() | |
| 250 PyConsole.output.writeprefs() | |
| 251 PyEdit.searchengine.writeprefs() | |
| 252 for window in self._windows.values(): | |
|
11031
8b7f65b0db18
mod from Joe Strout: when quitting, catch errors in window.close() methods and ignore them. Otherwise one can never quit.
Just van Rossum <just@lettererror.com>
parents:
10322
diff
changeset
|
253 try: |
|
8b7f65b0db18
mod from Joe Strout: when quitting, catch errors in window.close() methods and ignore them. Otherwise one can never quit.
Just van Rossum <just@lettererror.com>
parents:
10322
diff
changeset
|
254 rv = window.close() # ignore any errors while quitting |
|
8b7f65b0db18
mod from Joe Strout: when quitting, catch errors in window.close() methods and ignore them. Otherwise one can never quit.
Just van Rossum <just@lettererror.com>
parents:
10322
diff
changeset
|
255 except: |
|
8b7f65b0db18
mod from Joe Strout: when quitting, catch errors in window.close() methods and ignore them. Otherwise one can never quit.
Just van Rossum <just@lettererror.com>
parents:
10322
diff
changeset
|
256 rv = 0 # (otherwise, we can get stuck!) |
| 10047 | 257 if rv and rv > 0: |
| 258 return | |
| 259 self.quitting = 1 | |
| 260 | |
| 261 PythonIDE() | |
| 262 |
