Mercurial > cpython-lru_cache-weakref
annotate Mac/Tools/IDE/PythonIDEMain.py @ 27998:e27f58a50737 legacy-trunk
SF bug #690377: Dud footnote reference in distutils docs
| author | Raymond Hettinger <python@rcn.com> |
|---|---|
| date | Fri, 21 Feb 2003 02:47:09 +0000 |
| parents | 5d2d24a73825 |
| children | f8fc5e14bfe8 |
| 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 | |
|
22672
86ce9ee14045
Allow file without filetype as long as they end in ".py".
Jack Jansen <jack.jansen@cwi.nl>
parents:
21867
diff
changeset
|
9 import sys |
|
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 |
| 27408 | 11 import EasyDialogs |
|
27737
4367f805db09
Got rid of macfs and FSSpecs in general (pathnames or FSRefs are now
Jack Jansen <jack.jansen@cwi.nl>
parents:
27697
diff
changeset
|
12 from Carbon import File |
|
4367f805db09
Got rid of macfs and FSSpecs in general (pathnames or FSRefs are now
Jack Jansen <jack.jansen@cwi.nl>
parents:
27697
diff
changeset
|
13 from Carbon import Files |
| 10047 | 14 |
|
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
|
15 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
|
16 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
|
17 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
|
18 ELIPSES = '\xc9' |
| 10047 | 19 |
|
21867
da008b5c5035
Don't append quit menu when on OSX, it is special and automatic there.
Just van Rossum <just@letterror.com>
parents:
21772
diff
changeset
|
20 def runningOnOSX(): |
|
da008b5c5035
Don't append quit menu when on OSX, it is special and automatic there.
Just van Rossum <just@letterror.com>
parents:
21772
diff
changeset
|
21 from gestalt import gestalt |
|
da008b5c5035
Don't append quit menu when on OSX, it is special and automatic there.
Just van Rossum <just@letterror.com>
parents:
21772
diff
changeset
|
22 gestaltMenuMgrAquaLayoutBit = 1 # menus have the Aqua 1.0 layout |
|
da008b5c5035
Don't append quit menu when on OSX, it is special and automatic there.
Just van Rossum <just@letterror.com>
parents:
21772
diff
changeset
|
23 gestaltMenuMgrAquaLayoutMask = (1L << gestaltMenuMgrAquaLayoutBit) |
|
da008b5c5035
Don't append quit menu when on OSX, it is special and automatic there.
Just van Rossum <just@letterror.com>
parents:
21772
diff
changeset
|
24 value = gestalt("menu") & gestaltMenuMgrAquaLayoutMask |
|
da008b5c5035
Don't append quit menu when on OSX, it is special and automatic there.
Just van Rossum <just@letterror.com>
parents:
21772
diff
changeset
|
25 return not not value |
|
da008b5c5035
Don't append quit menu when on OSX, it is special and automatic there.
Just van Rossum <just@letterror.com>
parents:
21772
diff
changeset
|
26 |
|
27737
4367f805db09
Got rid of macfs and FSSpecs in general (pathnames or FSRefs are now
Jack Jansen <jack.jansen@cwi.nl>
parents:
27697
diff
changeset
|
27 def getmodtime(file): |
|
4367f805db09
Got rid of macfs and FSSpecs in general (pathnames or FSRefs are now
Jack Jansen <jack.jansen@cwi.nl>
parents:
27697
diff
changeset
|
28 file = File.FSRef(file) |
|
4367f805db09
Got rid of macfs and FSSpecs in general (pathnames or FSRefs are now
Jack Jansen <jack.jansen@cwi.nl>
parents:
27697
diff
changeset
|
29 catinfo, d1, d2, d3 = file.FSGetCatalogInfo(Files.kFSCatInfoContentMod) |
|
4367f805db09
Got rid of macfs and FSSpecs in general (pathnames or FSRefs are now
Jack Jansen <jack.jansen@cwi.nl>
parents:
27697
diff
changeset
|
30 return catinfo.contentModDate |
|
21867
da008b5c5035
Don't append quit menu when on OSX, it is special and automatic there.
Just van Rossum <just@letterror.com>
parents:
21772
diff
changeset
|
31 |
| 10047 | 32 class PythonIDE(Wapplication.Application): |
| 33 | |
| 34 def __init__(self): | |
|
24226
62d8f974811f
fixed wrong classic MacOS pathname assumption
Just van Rossum <just@letterror.com>
parents:
22675
diff
changeset
|
35 self.preffilepath = os.path.join("Python", "PythonIDE preferences") |
|
10322
a87cfea30b04
changed creator to 'Pide' -- jvr
Just van Rossum <just@lettererror.com>
parents:
10310
diff
changeset
|
36 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
|
37 from Carbon import AE |
|
42b2f1936254
Import the MacOS toolbox modules from the Carbon package.
Jack Jansen <jack.jansen@cwi.nl>
parents:
18167
diff
changeset
|
38 from Carbon import AppleEvents |
| 10047 | 39 |
| 40 AE.AEInstallEventHandler(AppleEvents.kCoreEventClass, AppleEvents.kAEOpenApplication, | |
| 41 self.ignoreevent) | |
|
17015
3c650d9c38e7
Handle the ReopenApplication event (by ignoring it).
Jack Jansen <jack.jansen@cwi.nl>
parents:
15284
diff
changeset
|
42 AE.AEInstallEventHandler(AppleEvents.kCoreEventClass, AppleEvents.kAEReopenApplication, |
|
3c650d9c38e7
Handle the ReopenApplication event (by ignoring it).
Jack Jansen <jack.jansen@cwi.nl>
parents:
15284
diff
changeset
|
43 self.ignoreevent) |
| 10047 | 44 AE.AEInstallEventHandler(AppleEvents.kCoreEventClass, AppleEvents.kAEPrintDocuments, |
| 45 self.ignoreevent) | |
| 46 AE.AEInstallEventHandler(AppleEvents.kCoreEventClass, AppleEvents.kAEOpenDocuments, | |
| 47 self.opendocsevent) | |
| 48 AE.AEInstallEventHandler(AppleEvents.kCoreEventClass, AppleEvents.kAEQuitApplication, | |
| 49 self.quitevent) | |
| 50 import PyConsole, PyEdit | |
| 51 Splash.wait() | |
|
25869
2bcb41611fae
cd to users home dir if no current dir has been set. Fixes bug #625734
Just van Rossum <just@letterror.com>
parents:
25224
diff
changeset
|
52 if sys.platform == "darwin": |
|
2bcb41611fae
cd to users home dir if no current dir has been set. Fixes bug #625734
Just van Rossum <just@letterror.com>
parents:
25224
diff
changeset
|
53 if sys.argv and sys.argv[0].startswith("-psn"): |
|
2bcb41611fae
cd to users home dir if no current dir has been set. Fixes bug #625734
Just van Rossum <just@letterror.com>
parents:
25224
diff
changeset
|
54 home = os.getenv("HOME") |
|
2bcb41611fae
cd to users home dir if no current dir has been set. Fixes bug #625734
Just van Rossum <just@letterror.com>
parents:
25224
diff
changeset
|
55 if home: |
|
2bcb41611fae
cd to users home dir if no current dir has been set. Fixes bug #625734
Just van Rossum <just@letterror.com>
parents:
25224
diff
changeset
|
56 os.chdir(home) |
|
22672
86ce9ee14045
Allow file without filetype as long as they end in ".py".
Jack Jansen <jack.jansen@cwi.nl>
parents:
21867
diff
changeset
|
57 # With -D option (OSX command line only) keep stderr, for debugging the IDE |
|
86ce9ee14045
Allow file without filetype as long as they end in ".py".
Jack Jansen <jack.jansen@cwi.nl>
parents:
21867
diff
changeset
|
58 # itself. |
|
86ce9ee14045
Allow file without filetype as long as they end in ".py".
Jack Jansen <jack.jansen@cwi.nl>
parents:
21867
diff
changeset
|
59 debug_stderr = None |
|
22675
57811c355f3a
repair damage: now works again as a CFM app.
Just van Rossum <just@letterror.com>
parents:
22672
diff
changeset
|
60 if len(sys.argv) >= 2 and sys.argv[1] == '-D': |
|
22672
86ce9ee14045
Allow file without filetype as long as they end in ".py".
Jack Jansen <jack.jansen@cwi.nl>
parents:
21867
diff
changeset
|
61 debug_stderr = sys.stderr |
|
86ce9ee14045
Allow file without filetype as long as they end in ".py".
Jack Jansen <jack.jansen@cwi.nl>
parents:
21867
diff
changeset
|
62 del sys.argv[1] |
| 10047 | 63 PyConsole.installoutput() |
| 64 PyConsole.installconsole() | |
|
22672
86ce9ee14045
Allow file without filetype as long as they end in ".py".
Jack Jansen <jack.jansen@cwi.nl>
parents:
21867
diff
changeset
|
65 if debug_stderr: |
|
86ce9ee14045
Allow file without filetype as long as they end in ".py".
Jack Jansen <jack.jansen@cwi.nl>
parents:
21867
diff
changeset
|
66 sys.stderr = debug_stderr |
| 10047 | 67 for path in sys.argv[1:]: |
|
26346
547de407c133
workaround so the (otherwise still broken) IDE can at least quit in the Python 2.2 Jaguar addon install
Just van Rossum <just@letterror.com>
parents:
25869
diff
changeset
|
68 if path.startswith("-p"): |
|
547de407c133
workaround so the (otherwise still broken) IDE can at least quit in the Python 2.2 Jaguar addon install
Just van Rossum <just@letterror.com>
parents:
25869
diff
changeset
|
69 # process number added by the OS |
|
547de407c133
workaround so the (otherwise still broken) IDE can at least quit in the Python 2.2 Jaguar addon install
Just van Rossum <just@letterror.com>
parents:
25869
diff
changeset
|
70 continue |
| 10047 | 71 self.opendoc(path) |
|
26346
547de407c133
workaround so the (otherwise still broken) IDE can at least quit in the Python 2.2 Jaguar addon install
Just van Rossum <just@letterror.com>
parents:
25869
diff
changeset
|
72 self.mainloop() |
| 10047 | 73 |
| 74 def makeusermenus(self): | |
| 75 m = Wapplication.Menu(self.menubar, "File") | |
| 76 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
|
77 openitem = FrameWork.MenuItem(m, "Open"+ELIPSES, "O", 'open') |
|
27697
43143d4dd6b1
Added "Open File by Name" command which presens a filename dialog. If
Jack Jansen <jack.jansen@cwi.nl>
parents:
27408
diff
changeset
|
78 openbynameitem = FrameWork.MenuItem(m, "Open File by Name"+ELIPSES, "D", 'openbyname') |
| 10047 | 79 FrameWork.Separator(m) |
| 80 closeitem = FrameWork.MenuItem(m, "Close", "W", 'close') | |
| 81 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
|
82 saveasitem = FrameWork.MenuItem(m, "Save as"+ELIPSES, None, 'save_as') |
| 10047 | 83 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
|
84 saveasappletitem = FrameWork.MenuItem(m, "Save as Applet"+ELIPSES, None, 'save_as_applet') |
|
27835
5d2d24a73825
Renamed InstallManager to PackageManager, finished a first stab at the
Jack Jansen <jack.jansen@cwi.nl>
parents:
27737
diff
changeset
|
85 FrameWork.Separator(m) |
|
5d2d24a73825
Renamed InstallManager to PackageManager, finished a first stab at the
Jack Jansen <jack.jansen@cwi.nl>
parents:
27737
diff
changeset
|
86 instmgritem = FrameWork.MenuItem(m, "Package Manager", None, 'openpackagemanager') |
|
21867
da008b5c5035
Don't append quit menu when on OSX, it is special and automatic there.
Just van Rossum <just@letterror.com>
parents:
21772
diff
changeset
|
87 if not runningOnOSX(): |
|
da008b5c5035
Don't append quit menu when on OSX, it is special and automatic there.
Just van Rossum <just@letterror.com>
parents:
21772
diff
changeset
|
88 # On OSX there's a special "magic" quit menu, so we shouldn't add |
|
da008b5c5035
Don't append quit menu when on OSX, it is special and automatic there.
Just van Rossum <just@letterror.com>
parents:
21772
diff
changeset
|
89 # it to the File menu. |
|
da008b5c5035
Don't append quit menu when on OSX, it is special and automatic there.
Just van Rossum <just@letterror.com>
parents:
21772
diff
changeset
|
90 FrameWork.Separator(m) |
|
da008b5c5035
Don't append quit menu when on OSX, it is special and automatic there.
Just van Rossum <just@letterror.com>
parents:
21772
diff
changeset
|
91 quititem = FrameWork.MenuItem(m, "Quit", "Q", 'quit') |
| 10047 | 92 |
| 93 m = Wapplication.Menu(self.menubar, "Edit") | |
| 94 undoitem = FrameWork.MenuItem(m, "Undo", 'Z', "undo") | |
| 95 FrameWork.Separator(m) | |
| 96 cutitem = FrameWork.MenuItem(m, "Cut", 'X', "cut") | |
| 97 copyitem = FrameWork.MenuItem(m, "Copy", "C", "copy") | |
| 98 pasteitem = FrameWork.MenuItem(m, "Paste", "V", "paste") | |
| 99 FrameWork.MenuItem(m, "Clear", None, "clear") | |
| 100 FrameWork.Separator(m) | |
| 101 selallitem = FrameWork.MenuItem(m, "Select all", "A", "selectall") | |
| 102 sellineitem = FrameWork.MenuItem(m, "Select line", "L", "selectline") | |
| 103 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
|
104 finditem = FrameWork.MenuItem(m, "Find"+ELIPSES, "F", "find") |
| 10047 | 105 findagainitem = FrameWork.MenuItem(m, "Find again", 'G', "findnext") |
| 106 enterselitem = FrameWork.MenuItem(m, "Enter search string", "E", "entersearchstring") | |
| 107 replaceitem = FrameWork.MenuItem(m, "Replace", None, "replace") | |
| 108 replacefinditem = FrameWork.MenuItem(m, "Replace & find again", 'T', "replacefind") | |
| 109 FrameWork.Separator(m) | |
| 110 shiftleftitem = FrameWork.MenuItem(m, "Shift left", "[", "shiftleft") | |
| 111 shiftrightitem = FrameWork.MenuItem(m, "Shift right", "]", "shiftright") | |
| 112 | |
| 113 m = Wapplication.Menu(self.menubar, "Python") | |
| 114 runitem = FrameWork.MenuItem(m, "Run window", "R", 'run') | |
| 115 runselitem = FrameWork.MenuItem(m, "Run selection", None, 'runselection') | |
| 116 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
|
117 moditem = FrameWork.MenuItem(m, "Module browser"+ELIPSES, "M", self.domenu_modulebrowser) |
| 10047 | 118 FrameWork.Separator(m) |
| 119 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
|
120 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
|
121 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
|
122 FrameWork.MenuItem(mm, "Set default window font"+ELIPSES, None, self.do_setwindowfont) |
| 10047 | 123 |
| 124 self.openwindowsmenu = Wapplication.Menu(self.menubar, 'Windows') | |
| 125 self.makeopenwindowsmenu() | |
| 126 self._menustocheck = [closeitem, saveitem, saveasitem, saveasappletitem, | |
| 127 undoitem, cutitem, copyitem, pasteitem, | |
| 128 selallitem, sellineitem, | |
| 129 finditem, findagainitem, enterselitem, replaceitem, replacefinditem, | |
| 130 shiftleftitem, shiftrightitem, | |
| 131 runitem, runselitem] | |
| 132 | |
| 133 prefs = self.getprefs() | |
| 134 try: | |
|
27737
4367f805db09
Got rid of macfs and FSSpecs in general (pathnames or FSRefs are now
Jack Jansen <jack.jansen@cwi.nl>
parents:
27697
diff
changeset
|
135 fsr, d = File.Alias(rawdata=prefs.scriptsfolder).FSResolveAlias(None) |
|
4367f805db09
Got rid of macfs and FSSpecs in general (pathnames or FSRefs are now
Jack Jansen <jack.jansen@cwi.nl>
parents:
27697
diff
changeset
|
136 self.scriptsfolder = fsr.FSNewAliasMinimal() |
| 10047 | 137 except: |
|
27737
4367f805db09
Got rid of macfs and FSSpecs in general (pathnames or FSRefs are now
Jack Jansen <jack.jansen@cwi.nl>
parents:
27697
diff
changeset
|
138 path = os.path.join(os.getcwd(), "Mac", "IDE scripts") |
| 10047 | 139 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
|
140 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
|
141 if not os.path.exists(path): |
|
c702a12d318d
1 - added "set default window font" menu
Just van Rossum <just@lettererror.com>
parents:
11031
diff
changeset
|
142 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
|
143 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
|
144 f.close() |
|
27737
4367f805db09
Got rid of macfs and FSSpecs in general (pathnames or FSRefs are now
Jack Jansen <jack.jansen@cwi.nl>
parents:
27697
diff
changeset
|
145 fsr = File.FSRef(path) |
|
4367f805db09
Got rid of macfs and FSSpecs in general (pathnames or FSRefs are now
Jack Jansen <jack.jansen@cwi.nl>
parents:
27697
diff
changeset
|
146 self.scriptsfolder = fsr.FSNewAliasMinimal() |
|
4367f805db09
Got rid of macfs and FSSpecs in general (pathnames or FSRefs are now
Jack Jansen <jack.jansen@cwi.nl>
parents:
27697
diff
changeset
|
147 self.scriptsfoldermodtime = getmodtime(fsr) |
| 10047 | 148 else: |
|
27737
4367f805db09
Got rid of macfs and FSSpecs in general (pathnames or FSRefs are now
Jack Jansen <jack.jansen@cwi.nl>
parents:
27697
diff
changeset
|
149 self.scriptsfoldermodtime = getmodtime(fsr) |
| 10047 | 150 prefs.scriptsfolder = self.scriptsfolder.data |
| 151 self._scripts = {} | |
| 152 self.scriptsmenu = None | |
| 153 self.makescriptsmenu() | |
|
25084
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
154 self.makehelpmenu() |
| 10047 | 155 |
| 156 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
|
157 from Carbon import AE |
| 10047 | 158 AE.AEInteractWithUser(50000000) |
| 159 self._quit() | |
| 160 | |
| 161 def suspendresume(self, onoff): | |
| 162 if onoff: | |
|
27737
4367f805db09
Got rid of macfs and FSSpecs in general (pathnames or FSRefs are now
Jack Jansen <jack.jansen@cwi.nl>
parents:
27697
diff
changeset
|
163 fsr, changed = self.scriptsfolder.FSResolveAlias(None) |
|
4367f805db09
Got rid of macfs and FSSpecs in general (pathnames or FSRefs are now
Jack Jansen <jack.jansen@cwi.nl>
parents:
27697
diff
changeset
|
164 modtime = getmodtime(fsr) |
|
4367f805db09
Got rid of macfs and FSSpecs in general (pathnames or FSRefs are now
Jack Jansen <jack.jansen@cwi.nl>
parents:
27697
diff
changeset
|
165 if self.scriptsfoldermodtime <> modtime or changed: |
| 10047 | 166 self.scriptsfoldermodtime = modtime |
| 167 W.SetCursor('watch') | |
| 168 self.makescriptsmenu() | |
| 169 | |
| 170 def ignoreevent(self, theAppleEvent, theReply): | |
| 171 pass | |
| 172 | |
| 173 def opendocsevent(self, theAppleEvent, theReply): | |
| 174 W.SetCursor('watch') | |
| 175 import aetools | |
| 176 parameters, args = aetools.unpackevent(theAppleEvent) | |
| 177 docs = parameters['----'] | |
| 178 if type(docs) <> type([]): | |
| 179 docs = [docs] | |
| 180 for doc in docs: | |
|
27737
4367f805db09
Got rid of macfs and FSSpecs in general (pathnames or FSRefs are now
Jack Jansen <jack.jansen@cwi.nl>
parents:
27697
diff
changeset
|
181 fsr, a = doc.FSResolveAlias(None) |
|
4367f805db09
Got rid of macfs and FSSpecs in general (pathnames or FSRefs are now
Jack Jansen <jack.jansen@cwi.nl>
parents:
27697
diff
changeset
|
182 path = fsr.as_pathname() |
| 10047 | 183 self.opendoc(path) |
| 184 | |
| 185 def opendoc(self, path): | |
|
27737
4367f805db09
Got rid of macfs and FSSpecs in general (pathnames or FSRefs are now
Jack Jansen <jack.jansen@cwi.nl>
parents:
27697
diff
changeset
|
186 fcreator, ftype = MacOS.GetCreatorAndType(path) |
| 10047 | 187 if ftype == 'TEXT': |
| 188 self.openscript(path) | |
|
22672
86ce9ee14045
Allow file without filetype as long as they end in ".py".
Jack Jansen <jack.jansen@cwi.nl>
parents:
21867
diff
changeset
|
189 elif ftype == '\0\0\0\0' and path[-3:] == '.py': |
|
86ce9ee14045
Allow file without filetype as long as they end in ".py".
Jack Jansen <jack.jansen@cwi.nl>
parents:
21867
diff
changeset
|
190 self.openscript(path) |
| 10047 | 191 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
|
192 W.Message("Can't open file of type '%s'." % ftype) |
| 10047 | 193 |
| 194 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
|
195 return "About Python IDE"+ELIPSES |
| 10047 | 196 |
| 197 def do_about(self, id, item, window, event): | |
| 198 Splash.about() | |
| 199 | |
| 200 def do_setscriptsfolder(self, *args): | |
|
27737
4367f805db09
Got rid of macfs and FSSpecs in general (pathnames or FSRefs are now
Jack Jansen <jack.jansen@cwi.nl>
parents:
27697
diff
changeset
|
201 fsr = EasyDialogs.AskFolder(message="Select Scripts Folder", |
|
4367f805db09
Got rid of macfs and FSSpecs in general (pathnames or FSRefs are now
Jack Jansen <jack.jansen@cwi.nl>
parents:
27697
diff
changeset
|
202 wanted=File.FSRef) |
|
4367f805db09
Got rid of macfs and FSSpecs in general (pathnames or FSRefs are now
Jack Jansen <jack.jansen@cwi.nl>
parents:
27697
diff
changeset
|
203 if fsr: |
| 10047 | 204 prefs = self.getprefs() |
|
27737
4367f805db09
Got rid of macfs and FSSpecs in general (pathnames or FSRefs are now
Jack Jansen <jack.jansen@cwi.nl>
parents:
27697
diff
changeset
|
205 alis = fsr.FSNewAliasMinimal() |
| 10047 | 206 prefs.scriptsfolder = alis.data |
| 207 self.scriptsfolder = alis | |
| 208 self.makescriptsmenu() | |
| 209 prefs.save() | |
| 210 | |
| 211 def domenu_modulebrowser(self, *args): | |
| 212 W.SetCursor('watch') | |
| 213 import ModuleBrowser | |
| 214 ModuleBrowser.ModuleBrowser() | |
| 215 | |
| 216 def domenu_open(self, *args): | |
| 27408 | 217 filename = EasyDialogs.AskFileForOpen(typeList=("TEXT",)) |
| 218 if filename: | |
| 219 self.openscript(filename) | |
| 10047 | 220 |
|
27697
43143d4dd6b1
Added "Open File by Name" command which presens a filename dialog. If
Jack Jansen <jack.jansen@cwi.nl>
parents:
27408
diff
changeset
|
221 def domenu_openbyname(self, *args): |
|
43143d4dd6b1
Added "Open File by Name" command which presens a filename dialog. If
Jack Jansen <jack.jansen@cwi.nl>
parents:
27408
diff
changeset
|
222 # Open a file by name. If the clipboard contains a filename |
|
43143d4dd6b1
Added "Open File by Name" command which presens a filename dialog. If
Jack Jansen <jack.jansen@cwi.nl>
parents:
27408
diff
changeset
|
223 # use that as the default. |
|
43143d4dd6b1
Added "Open File by Name" command which presens a filename dialog. If
Jack Jansen <jack.jansen@cwi.nl>
parents:
27408
diff
changeset
|
224 from Carbon import Scrap |
|
43143d4dd6b1
Added "Open File by Name" command which presens a filename dialog. If
Jack Jansen <jack.jansen@cwi.nl>
parents:
27408
diff
changeset
|
225 try: |
|
43143d4dd6b1
Added "Open File by Name" command which presens a filename dialog. If
Jack Jansen <jack.jansen@cwi.nl>
parents:
27408
diff
changeset
|
226 sc = Scrap.GetCurrentScrap() |
|
43143d4dd6b1
Added "Open File by Name" command which presens a filename dialog. If
Jack Jansen <jack.jansen@cwi.nl>
parents:
27408
diff
changeset
|
227 dft = sc.GetScrapFlavorData("TEXT") |
|
43143d4dd6b1
Added "Open File by Name" command which presens a filename dialog. If
Jack Jansen <jack.jansen@cwi.nl>
parents:
27408
diff
changeset
|
228 except Scrap.Error: |
|
43143d4dd6b1
Added "Open File by Name" command which presens a filename dialog. If
Jack Jansen <jack.jansen@cwi.nl>
parents:
27408
diff
changeset
|
229 dft = "" |
|
43143d4dd6b1
Added "Open File by Name" command which presens a filename dialog. If
Jack Jansen <jack.jansen@cwi.nl>
parents:
27408
diff
changeset
|
230 else: |
|
43143d4dd6b1
Added "Open File by Name" command which presens a filename dialog. If
Jack Jansen <jack.jansen@cwi.nl>
parents:
27408
diff
changeset
|
231 if not os.path.exists(dft): |
|
43143d4dd6b1
Added "Open File by Name" command which presens a filename dialog. If
Jack Jansen <jack.jansen@cwi.nl>
parents:
27408
diff
changeset
|
232 dft = "" |
|
43143d4dd6b1
Added "Open File by Name" command which presens a filename dialog. If
Jack Jansen <jack.jansen@cwi.nl>
parents:
27408
diff
changeset
|
233 filename = EasyDialogs.AskString("Open File Named:", default=dft, ok="Open") |
|
43143d4dd6b1
Added "Open File by Name" command which presens a filename dialog. If
Jack Jansen <jack.jansen@cwi.nl>
parents:
27408
diff
changeset
|
234 if filename: |
|
43143d4dd6b1
Added "Open File by Name" command which presens a filename dialog. If
Jack Jansen <jack.jansen@cwi.nl>
parents:
27408
diff
changeset
|
235 self.openscript(filename) |
|
43143d4dd6b1
Added "Open File by Name" command which presens a filename dialog. If
Jack Jansen <jack.jansen@cwi.nl>
parents:
27408
diff
changeset
|
236 |
| 10047 | 237 def domenu_new(self, *args): |
| 238 W.SetCursor('watch') | |
| 239 import PyEdit | |
| 240 return PyEdit.Editor() | |
| 241 | |
| 242 def makescriptsmenu(self): | |
| 243 W.SetCursor('watch') | |
| 244 if self._scripts: | |
| 245 for id, item in self._scripts.keys(): | |
| 246 if self.menubar.menus.has_key(id): | |
| 247 m = self.menubar.menus[id] | |
| 248 m.delete() | |
| 249 self._scripts = {} | |
| 250 if self.scriptsmenu: | |
| 251 if hasattr(self.scriptsmenu, 'id') and self.menubar.menus.has_key(self.scriptsmenu.id): | |
| 252 self.scriptsmenu.delete() | |
| 253 self.scriptsmenu = FrameWork.Menu(self.menubar, "Scripts") | |
| 254 #FrameWork.MenuItem(self.scriptsmenu, "New script", None, self.domenu_new) | |
| 255 #self.scriptsmenu.addseparator() | |
|
27737
4367f805db09
Got rid of macfs and FSSpecs in general (pathnames or FSRefs are now
Jack Jansen <jack.jansen@cwi.nl>
parents:
27697
diff
changeset
|
256 fsr, d1 = self.scriptsfolder.FSResolveAlias(None) |
|
4367f805db09
Got rid of macfs and FSSpecs in general (pathnames or FSRefs are now
Jack Jansen <jack.jansen@cwi.nl>
parents:
27697
diff
changeset
|
257 self.scriptswalk(fsr.as_pathname(), self.scriptsmenu) |
| 10047 | 258 |
| 259 def makeopenwindowsmenu(self): | |
| 260 for i in range(len(self.openwindowsmenu.items)): | |
| 261 self.openwindowsmenu.menu.DeleteMenuItem(1) | |
| 262 self.openwindowsmenu.items = [] | |
| 263 windows = [] | |
| 264 self._openwindows = {} | |
| 265 for window in self._windows.keys(): | |
| 266 title = window.GetWTitle() | |
| 267 if not title: | |
| 268 title = "<no title>" | |
|
11949
5e48d83c0fce
Fixed multi-arg appends.
Jack Jansen <jack.jansen@cwi.nl>
parents:
11325
diff
changeset
|
269 windows.append((title, window)) |
| 10047 | 270 windows.sort() |
| 271 for title, window in windows: | |
| 272 if title == "Python Interactive": # ugly but useful hack by Joe Strout | |
| 273 shortcut = '0' | |
| 274 else: | |
| 275 shortcut = None | |
| 276 item = FrameWork.MenuItem(self.openwindowsmenu, title, shortcut, callback = self.domenu_openwindows) | |
| 277 self._openwindows[item.item] = window | |
| 278 self._openwindowscheckmark = 0 | |
| 279 self.checkopenwindowsmenu() | |
| 280 | |
| 281 def domenu_openwindows(self, id, item, window, event): | |
| 282 w = self._openwindows[item] | |
| 283 w.ShowWindow() | |
| 284 w.SelectWindow() | |
| 285 | |
| 286 def domenu_quit(self): | |
| 287 self._quit() | |
| 288 | |
| 289 def domenu_save(self, *args): | |
| 290 print "Save" | |
| 291 | |
| 292 def _quit(self): | |
| 293 import PyConsole, PyEdit | |
| 294 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
|
295 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
|
296 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
|
297 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
|
298 rv = 0 # (otherwise, we can get stuck!) |
| 10047 | 299 if rv and rv > 0: |
| 300 return | |
|
26346
547de407c133
workaround so the (otherwise still broken) IDE can at least quit in the Python 2.2 Jaguar addon install
Just van Rossum <just@letterror.com>
parents:
25869
diff
changeset
|
301 try: |
|
547de407c133
workaround so the (otherwise still broken) IDE can at least quit in the Python 2.2 Jaguar addon install
Just van Rossum <just@letterror.com>
parents:
25869
diff
changeset
|
302 PyConsole.console.writeprefs() |
|
547de407c133
workaround so the (otherwise still broken) IDE can at least quit in the Python 2.2 Jaguar addon install
Just van Rossum <just@letterror.com>
parents:
25869
diff
changeset
|
303 PyConsole.output.writeprefs() |
|
547de407c133
workaround so the (otherwise still broken) IDE can at least quit in the Python 2.2 Jaguar addon install
Just van Rossum <just@letterror.com>
parents:
25869
diff
changeset
|
304 PyEdit.searchengine.writeprefs() |
|
547de407c133
workaround so the (otherwise still broken) IDE can at least quit in the Python 2.2 Jaguar addon install
Just van Rossum <just@letterror.com>
parents:
25869
diff
changeset
|
305 except: |
|
547de407c133
workaround so the (otherwise still broken) IDE can at least quit in the Python 2.2 Jaguar addon install
Just van Rossum <just@letterror.com>
parents:
25869
diff
changeset
|
306 # Write to __stderr__ so the msg end up in Console.app and has |
|
547de407c133
workaround so the (otherwise still broken) IDE can at least quit in the Python 2.2 Jaguar addon install
Just van Rossum <just@letterror.com>
parents:
25869
diff
changeset
|
307 # at least _some_ chance of getting read... |
|
547de407c133
workaround so the (otherwise still broken) IDE can at least quit in the Python 2.2 Jaguar addon install
Just van Rossum <just@letterror.com>
parents:
25869
diff
changeset
|
308 # But: this is a workaround for way more serious problems with |
|
547de407c133
workaround so the (otherwise still broken) IDE can at least quit in the Python 2.2 Jaguar addon install
Just van Rossum <just@letterror.com>
parents:
25869
diff
changeset
|
309 # the Python 2.2 Jaguar addon. |
|
547de407c133
workaround so the (otherwise still broken) IDE can at least quit in the Python 2.2 Jaguar addon install
Just van Rossum <just@letterror.com>
parents:
25869
diff
changeset
|
310 sys.__stderr__.write("*** PythonIDE: Can't write preferences ***\n") |
| 10047 | 311 self.quitting = 1 |
|
25084
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
312 |
|
27835
5d2d24a73825
Renamed InstallManager to PackageManager, finished a first stab at the
Jack Jansen <jack.jansen@cwi.nl>
parents:
27737
diff
changeset
|
313 def domenu_openpackagemanager(self): |
|
5d2d24a73825
Renamed InstallManager to PackageManager, finished a first stab at the
Jack Jansen <jack.jansen@cwi.nl>
parents:
27737
diff
changeset
|
314 import PackageManager |
|
5d2d24a73825
Renamed InstallManager to PackageManager, finished a first stab at the
Jack Jansen <jack.jansen@cwi.nl>
parents:
27737
diff
changeset
|
315 PackageManager.PackageBrowser() |
|
5d2d24a73825
Renamed InstallManager to PackageManager, finished a first stab at the
Jack Jansen <jack.jansen@cwi.nl>
parents:
27737
diff
changeset
|
316 print "Done" |
|
5d2d24a73825
Renamed InstallManager to PackageManager, finished a first stab at the
Jack Jansen <jack.jansen@cwi.nl>
parents:
27737
diff
changeset
|
317 |
|
25084
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
318 def makehelpmenu(self): |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
319 docs = self.installdocumentation() |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
320 self.helpmenu = m = self.gethelpmenu() |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
321 docitem = FrameWork.MenuItem(m, "Python Documentation", None, self.domenu_localdocs) |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
322 docitem.enable(docs) |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
323 finditem = FrameWork.MenuItem(m, "Lookup in Python Documentation", None, 'lookuppython') |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
324 finditem.enable(docs) |
|
25156
bf90fb71aa76
Reorganized order of help menu, and don't show Carbon documentation
Jack Jansen <jack.jansen@cwi.nl>
parents:
25084
diff
changeset
|
325 if runningOnOSX(): |
|
bf90fb71aa76
Reorganized order of help menu, and don't show Carbon documentation
Jack Jansen <jack.jansen@cwi.nl>
parents:
25084
diff
changeset
|
326 FrameWork.Separator(m) |
|
bf90fb71aa76
Reorganized order of help menu, and don't show Carbon documentation
Jack Jansen <jack.jansen@cwi.nl>
parents:
25084
diff
changeset
|
327 doc2item = FrameWork.MenuItem(m, "Apple Developer Documentation", None, self.domenu_appledocs) |
|
bf90fb71aa76
Reorganized order of help menu, and don't show Carbon documentation
Jack Jansen <jack.jansen@cwi.nl>
parents:
25084
diff
changeset
|
328 find2item = FrameWork.MenuItem(m, "Lookup in Carbon Documentation", None, 'lookupcarbon') |
|
25084
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
329 FrameWork.Separator(m) |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
330 webitem = FrameWork.MenuItem(m, "Python Documentation on the Web", None, self.domenu_webdocs) |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
331 web2item = FrameWork.MenuItem(m, "Python on the Web", None, self.domenu_webpython) |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
332 web3item = FrameWork.MenuItem(m, "MacPython on the Web", None, self.domenu_webmacpython) |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
333 |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
334 def domenu_localdocs(self, *args): |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
335 from Carbon import AH |
|
25224
e709a3c8bfec
Pass None to AHGotoPage().
Jack Jansen <jack.jansen@cwi.nl>
parents:
25156
diff
changeset
|
336 AH.AHGotoPage("Python Help", None, None) |
|
25084
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
337 |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
338 def domenu_appledocs(self, *args): |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
339 from Carbon import AH, AppleHelp |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
340 try: |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
341 AH.AHGotoMainTOC(AppleHelp.kAHTOCTypeDeveloper) |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
342 except AH.Error, arg: |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
343 if arg[0] == -50: |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
344 W.Message("Developer documentation not installed") |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
345 else: |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
346 W.Message("AppleHelp Error: %s" % `arg`) |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
347 |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
348 def domenu_lookuppython(self, *args): |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
349 from Carbon import AH |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
350 searchstring = self._getsearchstring() |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
351 if not searchstring: |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
352 return |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
353 try: |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
354 AH.AHSearch("Python Help", searchstring) |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
355 except AH.Error, arg: |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
356 W.Message("AppleHelp Error: %s" % `arg`) |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
357 |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
358 def domenu_lookupcarbon(self, *args): |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
359 from Carbon import AH |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
360 searchstring = self._getsearchstring() |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
361 if not searchstring: |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
362 return |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
363 try: |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
364 AH.AHSearch("Carbon", searchstring) |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
365 except AH.Error, arg: |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
366 W.Message("AppleHelp Error: %s" % `arg`) |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
367 |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
368 def _getsearchstring(self): |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
369 import PyEdit |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
370 editor = PyEdit.findeditor(None, fromtop=1) |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
371 if editor: |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
372 text = editor.getselectedtext() |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
373 if text: |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
374 return text |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
375 # This is a cop-out. We should have disabled the menus |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
376 # if there is no selection, but the can_ methods only seem |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
377 # to work for Windows. Or not for the Help menu, maybe? |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
378 text = EasyDialogs.AskString("Search documentation for", ok="Search") |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
379 return text |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
380 |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
381 def domenu_webdocs(self, *args): |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
382 import webbrowser |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
383 major, minor, micro, state, nano = sys.version_info |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
384 if state in ('alpha', 'beta'): |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
385 docversion = 'dev/doc/devel' |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
386 elif micro == 0: |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
387 docversion = 'doc/%d.%d' % (major, minor) |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
388 else: |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
389 docversion = 'doc/%d.%d.%d' % (major, minor, micro) |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
390 webbrowser.open("http://www.python.org/%s" % docversion) |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
391 |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
392 def domenu_webpython(self, *args): |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
393 import webbrowser |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
394 webbrowser.open("http://www.python.org/") |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
395 |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
396 def domenu_webmacpython(self, *args): |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
397 import webbrowser |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
398 webbrowser.open("http://www.cwi.nl/~jack/macpython.html") |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
399 |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
400 def installdocumentation(self): |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
401 # This is rather much of a hack. Someone has to tell the Help Viewer |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
402 # about the Python documentation, so why not us. The documentation |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
403 # is located in the framework, but there's a symlink in Python.app. |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
404 # And as AHRegisterHelpBook wants a bundle (with the right bits in |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
405 # the plist file) we refer it to Python.app |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
406 python_app = os.path.join(sys.prefix, 'Resources/Python.app') |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
407 doc_source = os.path.join(python_app, 'Contents/Resources/English.lproj/Documentation') |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
408 if not os.path.isdir(doc_source): |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
409 return 0 |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
410 try: |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
411 from Carbon import AH |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
412 AH.AHRegisterHelpBook(python_app) |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
413 except (ImportError, MacOS.Error), arg: |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
414 W.Message("Cannot register Python documentation: %s" % `arg`) |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
415 return 0 |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
416 return 1 |
|
b337ef16c0d2
Implemented the Help menu. The Python manual can be viewed (if installed)
Jack Jansen <jack.jansen@cwi.nl>
parents:
24226
diff
changeset
|
417 |
| 10047 | 418 |
| 419 PythonIDE() | |
| 420 |
