Mercurial > cpython-lru_cache-weakref
annotate Mac/Tools/IDE/PyEdit.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 | 233ed6cc8e14 |
| children | 21a50c308db4 |
| rev | line source |
|---|---|
| 10047 | 1 """A (less & less) simple Python editor""" |
| 2 | |
| 3 import W | |
| 4 import Wtraceback | |
| 5 from Wkeys import * | |
| 6 | |
| 7 import MacOS | |
| 27408 | 8 import EasyDialogs |
|
19488
42b2f1936254
Import the MacOS toolbox modules from the Carbon package.
Jack Jansen <jack.jansen@cwi.nl>
parents:
18781
diff
changeset
|
9 from Carbon import Win |
|
42b2f1936254
Import the MacOS toolbox modules from the Carbon package.
Jack Jansen <jack.jansen@cwi.nl>
parents:
18781
diff
changeset
|
10 from Carbon import Res |
|
42b2f1936254
Import the MacOS toolbox modules from the Carbon package.
Jack Jansen <jack.jansen@cwi.nl>
parents:
18781
diff
changeset
|
11 from Carbon import Evt |
|
24212
296dd32425d6
minor fixes, removed obsolete warning
Just van Rossum <just@letterror.com>
parents:
22715
diff
changeset
|
12 from Carbon import Qd |
|
27737
4367f805db09
Got rid of macfs and FSSpecs in general (pathnames or FSRefs are now
Jack Jansen <jack.jansen@cwi.nl>
parents:
27408
diff
changeset
|
13 from Carbon import File |
| 10047 | 14 import os |
| 15 import imp | |
| 16 import sys | |
| 17 import string | |
| 18 import marshal | |
|
16725
d170c1e772c5
Use re in stead of regex, so we get rid of the annoying warning during startup.
Jack Jansen <jack.jansen@cwi.nl>
parents:
16344
diff
changeset
|
19 import re |
| 10047 | 20 |
|
27737
4367f805db09
Got rid of macfs and FSSpecs in general (pathnames or FSRefs are now
Jack Jansen <jack.jansen@cwi.nl>
parents:
27408
diff
changeset
|
21 smAllScripts = -3 |
|
4367f805db09
Got rid of macfs and FSSpecs in general (pathnames or FSRefs are now
Jack Jansen <jack.jansen@cwi.nl>
parents:
27408
diff
changeset
|
22 |
|
21868
3cd0b4bb5e34
Added minimal support for floating windows.
Just van Rossum <just@letterror.com>
parents:
21772
diff
changeset
|
23 if hasattr(Win, "FrontNonFloatingWindow"): |
|
3cd0b4bb5e34
Added minimal support for floating windows.
Just van Rossum <just@letterror.com>
parents:
21772
diff
changeset
|
24 MyFrontWindow = Win.FrontNonFloatingWindow |
|
3cd0b4bb5e34
Added minimal support for floating windows.
Just van Rossum <just@letterror.com>
parents:
21772
diff
changeset
|
25 else: |
|
3cd0b4bb5e34
Added minimal support for floating windows.
Just van Rossum <just@letterror.com>
parents:
21772
diff
changeset
|
26 MyFrontWindow = Win.FrontWindow |
|
3cd0b4bb5e34
Added minimal support for floating windows.
Just van Rossum <just@letterror.com>
parents:
21772
diff
changeset
|
27 |
|
3cd0b4bb5e34
Added minimal support for floating windows.
Just van Rossum <just@letterror.com>
parents:
21772
diff
changeset
|
28 |
|
12308
ddc4e62b216b
added experimental microthread support for use with stackless python -- bw compatible (jvr)
Just van Rossum <just@lettererror.com>
parents:
11629
diff
changeset
|
29 try: |
|
15283
4c7c779bad87
Hm, I never checked in my incomplete "run with interpreter" mods. UI is there (but is disabled), functionality is not there.
Just van Rossum <just@lettererror.com>
parents:
12972
diff
changeset
|
30 import Wthreading |
|
12308
ddc4e62b216b
added experimental microthread support for use with stackless python -- bw compatible (jvr)
Just van Rossum <just@lettererror.com>
parents:
11629
diff
changeset
|
31 except ImportError: |
|
15283
4c7c779bad87
Hm, I never checked in my incomplete "run with interpreter" mods. UI is there (but is disabled), functionality is not there.
Just van Rossum <just@lettererror.com>
parents:
12972
diff
changeset
|
32 haveThreading = 0 |
|
4c7c779bad87
Hm, I never checked in my incomplete "run with interpreter" mods. UI is there (but is disabled), functionality is not there.
Just van Rossum <just@lettererror.com>
parents:
12972
diff
changeset
|
33 else: |
|
4c7c779bad87
Hm, I never checked in my incomplete "run with interpreter" mods. UI is there (but is disabled), functionality is not there.
Just van Rossum <just@lettererror.com>
parents:
12972
diff
changeset
|
34 haveThreading = Wthreading.haveThreading |
|
12308
ddc4e62b216b
added experimental microthread support for use with stackless python -- bw compatible (jvr)
Just van Rossum <just@lettererror.com>
parents:
11629
diff
changeset
|
35 |
| 10047 | 36 _scriptuntitledcounter = 1 |
|
18781
01ae962df885
Use string.ascii_letters instead of string.letters (SF bug #226706).
Fred Drake <fdrake@acm.org>
parents:
18453
diff
changeset
|
37 _wordchars = string.ascii_letters + string.digits + "_" |
| 10047 | 38 |
| 39 | |
|
12308
ddc4e62b216b
added experimental microthread support for use with stackless python -- bw compatible (jvr)
Just van Rossum <just@lettererror.com>
parents:
11629
diff
changeset
|
40 runButtonLabels = ["Run all", "Stop!"] |
|
ddc4e62b216b
added experimental microthread support for use with stackless python -- bw compatible (jvr)
Just van Rossum <just@lettererror.com>
parents:
11629
diff
changeset
|
41 runSelButtonLabels = ["Run selection", "Pause!", "Resume"] |
|
ddc4e62b216b
added experimental microthread support for use with stackless python -- bw compatible (jvr)
Just van Rossum <just@lettererror.com>
parents:
11629
diff
changeset
|
42 |
|
ddc4e62b216b
added experimental microthread support for use with stackless python -- bw compatible (jvr)
Just van Rossum <just@lettererror.com>
parents:
11629
diff
changeset
|
43 |
| 10047 | 44 class Editor(W.Window): |
| 45 | |
| 46 def __init__(self, path = "", title = ""): | |
| 47 defaultfontsettings, defaulttabsettings, defaultwindowsize = geteditorprefs() | |
| 48 global _scriptuntitledcounter | |
| 49 if not path: | |
| 50 if title: | |
| 51 self.title = title | |
| 52 else: | |
| 53 self.title = "Untitled Script " + `_scriptuntitledcounter` | |
| 54 _scriptuntitledcounter = _scriptuntitledcounter + 1 | |
| 55 text = "" | |
| 56 self._creator = W._signature | |
|
22673
b96740c42e80
Completely revamped newline handling. PyEdit is now newline-preserving
Jack Jansen <jack.jansen@cwi.nl>
parents:
21868
diff
changeset
|
57 self._eoln = os.linesep |
| 10047 | 58 elif os.path.exists(path): |
| 59 path = resolvealiases(path) | |
| 60 dir, name = os.path.split(path) | |
| 61 self.title = name | |
| 62 f = open(path, "rb") | |
| 63 text = f.read() | |
| 64 f.close() | |
|
27737
4367f805db09
Got rid of macfs and FSSpecs in general (pathnames or FSRefs are now
Jack Jansen <jack.jansen@cwi.nl>
parents:
27408
diff
changeset
|
65 self._creator, filetype = MacOS.GetCreatorAndType(path) |
| 10047 | 66 else: |
| 67 raise IOError, "file '%s' does not exist" % path | |
| 68 self.path = path | |
| 69 | |
|
10874
8634ea2ec4e2
Oliver Steele writes:
Just van Rossum <just@lettererror.com>
parents:
10705
diff
changeset
|
70 if '\n' in text: |
|
8634ea2ec4e2
Oliver Steele writes:
Just van Rossum <just@lettererror.com>
parents:
10705
diff
changeset
|
71 if string.find(text, '\r\n') >= 0: |
|
22673
b96740c42e80
Completely revamped newline handling. PyEdit is now newline-preserving
Jack Jansen <jack.jansen@cwi.nl>
parents:
21868
diff
changeset
|
72 self._eoln = '\r\n' |
|
10874
8634ea2ec4e2
Oliver Steele writes:
Just van Rossum <just@lettererror.com>
parents:
10705
diff
changeset
|
73 else: |
|
22673
b96740c42e80
Completely revamped newline handling. PyEdit is now newline-preserving
Jack Jansen <jack.jansen@cwi.nl>
parents:
21868
diff
changeset
|
74 self._eoln = '\n' |
|
b96740c42e80
Completely revamped newline handling. PyEdit is now newline-preserving
Jack Jansen <jack.jansen@cwi.nl>
parents:
21868
diff
changeset
|
75 text = string.replace(text, self._eoln, '\r') |
|
b96740c42e80
Completely revamped newline handling. PyEdit is now newline-preserving
Jack Jansen <jack.jansen@cwi.nl>
parents:
21868
diff
changeset
|
76 change = 0 |
|
10874
8634ea2ec4e2
Oliver Steele writes:
Just van Rossum <just@lettererror.com>
parents:
10705
diff
changeset
|
77 else: |
|
8634ea2ec4e2
Oliver Steele writes:
Just van Rossum <just@lettererror.com>
parents:
10705
diff
changeset
|
78 change = 0 |
|
22673
b96740c42e80
Completely revamped newline handling. PyEdit is now newline-preserving
Jack Jansen <jack.jansen@cwi.nl>
parents:
21868
diff
changeset
|
79 self._eoln = '\r' |
|
10874
8634ea2ec4e2
Oliver Steele writes:
Just van Rossum <just@lettererror.com>
parents:
10705
diff
changeset
|
80 |
| 10047 | 81 self.settings = {} |
| 82 if self.path: | |
| 83 self.readwindowsettings() | |
| 84 if self.settings.has_key("windowbounds"): | |
| 85 bounds = self.settings["windowbounds"] | |
| 86 else: | |
| 87 bounds = defaultwindowsize | |
| 88 if self.settings.has_key("fontsettings"): | |
| 89 self.fontsettings = self.settings["fontsettings"] | |
| 90 else: | |
| 91 self.fontsettings = defaultfontsettings | |
| 92 if self.settings.has_key("tabsize"): | |
| 93 try: | |
| 94 self.tabsettings = (tabsize, tabmode) = self.settings["tabsize"] | |
| 95 except: | |
| 96 self.tabsettings = defaulttabsettings | |
| 97 else: | |
| 98 self.tabsettings = defaulttabsettings | |
| 99 | |
|
10874
8634ea2ec4e2
Oliver Steele writes:
Just van Rossum <just@lettererror.com>
parents:
10705
diff
changeset
|
100 W.Window.__init__(self, bounds, self.title, minsize = (330, 120), tabbable = 0) |
| 10047 | 101 self.setupwidgets(text) |
|
10874
8634ea2ec4e2
Oliver Steele writes:
Just van Rossum <just@lettererror.com>
parents:
10705
diff
changeset
|
102 if change > 0: |
|
20835
3fbd253dea5d
some support for syntax coloring, disabled for now
Just van Rossum <just@letterror.com>
parents:
19488
diff
changeset
|
103 self.editgroup.editor.textchanged() |
|
10874
8634ea2ec4e2
Oliver Steele writes:
Just van Rossum <just@lettererror.com>
parents:
10705
diff
changeset
|
104 |
| 10047 | 105 if self.settings.has_key("selection"): |
| 106 selstart, selend = self.settings["selection"] | |
| 107 self.setselection(selstart, selend) | |
| 108 self.open() | |
| 109 self.setinfotext() | |
| 110 self.globals = {} | |
| 111 self._buf = "" # for write method | |
| 112 self.debugging = 0 | |
| 113 self.profiling = 0 | |
|
22715
e0edfeea5183
Added a "run with commandline Python" flag. Works in MachoPython, should work
Jack Jansen <jack.jansen@cwi.nl>
parents:
22676
diff
changeset
|
114 self.run_as_main = self.settings.get("run_as_main", 0) |
|
e0edfeea5183
Added a "run with commandline Python" flag. Works in MachoPython, should work
Jack Jansen <jack.jansen@cwi.nl>
parents:
22676
diff
changeset
|
115 self.run_with_interpreter = self.settings.get("run_with_interpreter", 0) |
|
e0edfeea5183
Added a "run with commandline Python" flag. Works in MachoPython, should work
Jack Jansen <jack.jansen@cwi.nl>
parents:
22676
diff
changeset
|
116 self.run_with_cl_interpreter = self.settings.get("run_with_cl_interpreter", 0) |
|
12308
ddc4e62b216b
added experimental microthread support for use with stackless python -- bw compatible (jvr)
Just van Rossum <just@lettererror.com>
parents:
11629
diff
changeset
|
117 self._threadstate = (0, 0) |
|
ddc4e62b216b
added experimental microthread support for use with stackless python -- bw compatible (jvr)
Just van Rossum <just@lettererror.com>
parents:
11629
diff
changeset
|
118 self._thread = None |
| 10047 | 119 |
| 120 def readwindowsettings(self): | |
| 121 try: | |
|
12972
fc77e34ef274
Replaced OpenResFile calls with FSpOpenResFile calls (which are carbon-compatible).
Jack Jansen <jack.jansen@cwi.nl>
parents:
12879
diff
changeset
|
122 resref = Res.FSpOpenResFile(self.path, 1) |
| 10047 | 123 except Res.Error: |
| 124 return | |
| 125 try: | |
| 126 Res.UseResFile(resref) | |
| 127 data = Res.Get1Resource('PyWS', 128) | |
| 128 self.settings = marshal.loads(data.data) | |
| 129 except: | |
| 130 pass | |
| 131 Res.CloseResFile(resref) | |
| 132 | |
| 133 def writewindowsettings(self): | |
| 134 try: | |
|
12972
fc77e34ef274
Replaced OpenResFile calls with FSpOpenResFile calls (which are carbon-compatible).
Jack Jansen <jack.jansen@cwi.nl>
parents:
12879
diff
changeset
|
135 resref = Res.FSpOpenResFile(self.path, 3) |
| 10047 | 136 except Res.Error: |
|
27737
4367f805db09
Got rid of macfs and FSSpecs in general (pathnames or FSRefs are now
Jack Jansen <jack.jansen@cwi.nl>
parents:
27408
diff
changeset
|
137 Res.FSpCreateResFile(self.path, self._creator, 'TEXT', smAllScripts) |
|
12972
fc77e34ef274
Replaced OpenResFile calls with FSpOpenResFile calls (which are carbon-compatible).
Jack Jansen <jack.jansen@cwi.nl>
parents:
12879
diff
changeset
|
138 resref = Res.FSpOpenResFile(self.path, 3) |
| 10047 | 139 try: |
| 140 data = Res.Resource(marshal.dumps(self.settings)) | |
| 141 Res.UseResFile(resref) | |
| 142 try: | |
| 143 temp = Res.Get1Resource('PyWS', 128) | |
| 144 temp.RemoveResource() | |
| 145 except Res.Error: | |
| 146 pass | |
| 147 data.AddResource('PyWS', 128, "window settings") | |
| 148 finally: | |
| 149 Res.UpdateResFile(resref) | |
| 150 Res.CloseResFile(resref) | |
| 151 | |
| 152 def getsettings(self): | |
| 153 self.settings = {} | |
| 154 self.settings["windowbounds"] = self.getbounds() | |
| 155 self.settings["selection"] = self.getselection() | |
| 156 self.settings["fontsettings"] = self.editgroup.editor.getfontsettings() | |
| 157 self.settings["tabsize"] = self.editgroup.editor.gettabsettings() | |
| 158 self.settings["run_as_main"] = self.run_as_main | |
|
15283
4c7c779bad87
Hm, I never checked in my incomplete "run with interpreter" mods. UI is there (but is disabled), functionality is not there.
Just van Rossum <just@lettererror.com>
parents:
12972
diff
changeset
|
159 self.settings["run_with_interpreter"] = self.run_with_interpreter |
|
22715
e0edfeea5183
Added a "run with commandline Python" flag. Works in MachoPython, should work
Jack Jansen <jack.jansen@cwi.nl>
parents:
22676
diff
changeset
|
160 self.settings["run_with_cl_interpreter"] = self.run_with_cl_interpreter |
| 10047 | 161 |
| 162 def get(self): | |
| 163 return self.editgroup.editor.get() | |
| 164 | |
| 165 def getselection(self): | |
| 166 return self.editgroup.editor.ted.WEGetSelection() | |
| 167 | |
| 168 def setselection(self, selstart, selend): | |
| 169 self.editgroup.editor.setselection(selstart, selend) | |
| 170 | |
| 171 def getfilename(self): | |
| 172 if self.path: | |
| 173 return self.path | |
| 174 return '<%s>' % self.title | |
| 175 | |
| 176 def setupwidgets(self, text): | |
|
21013
41b8d66730d6
a whole bunch of OSX tweaks
Just van Rossum <just@letterror.com>
parents:
20852
diff
changeset
|
177 topbarheight = 24 |
| 10047 | 178 popfieldwidth = 80 |
| 179 self.lastlineno = None | |
| 180 | |
| 181 # make an editor | |
| 182 self.editgroup = W.Group((0, topbarheight + 1, 0, 0)) | |
| 183 editor = W.PyEditor((0, 0, -15,-15), text, | |
| 184 fontsettings = self.fontsettings, | |
| 185 tabsettings = self.tabsettings, | |
| 186 file = self.getfilename()) | |
| 187 | |
| 188 # make the widgets | |
| 189 self.popfield = ClassFinder((popfieldwidth - 17, -15, 16, 16), [], self.popselectline) | |
| 190 self.linefield = W.EditText((-1, -15, popfieldwidth - 15, 16), inset = (6, 1)) | |
| 191 self.editgroup._barx = W.Scrollbar((popfieldwidth - 2, -15, -14, 16), editor.hscroll, max = 32767) | |
| 192 self.editgroup._bary = W.Scrollbar((-15, 14, 16, -14), editor.vscroll, max = 32767) | |
| 193 self.editgroup.editor = editor # add editor *after* scrollbars | |
| 194 | |
| 195 self.editgroup.optionsmenu = W.PopupMenu((-15, -1, 16, 16), []) | |
| 196 self.editgroup.optionsmenu.bind('<click>', self.makeoptionsmenu) | |
| 197 | |
| 198 self.bevelbox = W.BevelBox((0, 0, 0, topbarheight)) | |
| 199 self.hline = W.HorizontalLine((0, topbarheight, 0, 0)) | |
|
21013
41b8d66730d6
a whole bunch of OSX tweaks
Just van Rossum <just@letterror.com>
parents:
20852
diff
changeset
|
200 self.infotext = W.TextBox((175, 6, -4, 14), backgroundcolor = (0xe000, 0xe000, 0xe000)) |
|
41b8d66730d6
a whole bunch of OSX tweaks
Just van Rossum <just@letterror.com>
parents:
20852
diff
changeset
|
201 self.runbutton = W.BevelButton((6, 4, 80, 16), runButtonLabels[0], self.run) |
|
41b8d66730d6
a whole bunch of OSX tweaks
Just van Rossum <just@letterror.com>
parents:
20852
diff
changeset
|
202 self.runselbutton = W.BevelButton((90, 4, 80, 16), runSelButtonLabels[0], self.runselection) |
| 10047 | 203 |
| 204 # bind some keys | |
| 205 editor.bind("cmdr", self.runbutton.push) | |
| 206 editor.bind("enter", self.runselbutton.push) | |
| 207 editor.bind("cmdj", self.domenu_gotoline) | |
| 208 editor.bind("cmdd", self.domenu_toggledebugger) | |
| 209 editor.bind("<idle>", self.updateselection) | |
| 210 | |
| 211 editor.bind("cmde", searchengine.setfindstring) | |
| 212 editor.bind("cmdf", searchengine.show) | |
| 213 editor.bind("cmdg", searchengine.findnext) | |
| 214 editor.bind("cmdshiftr", searchengine.replace) | |
| 215 editor.bind("cmdt", searchengine.replacefind) | |
| 216 | |
| 217 self.linefield.bind("return", self.dolinefield) | |
| 218 self.linefield.bind("enter", self.dolinefield) | |
| 219 self.linefield.bind("tab", self.dolinefield) | |
| 220 | |
| 221 # intercept clicks | |
| 222 editor.bind("<click>", self.clickeditor) | |
| 223 self.linefield.bind("<click>", self.clicklinefield) | |
| 224 | |
| 225 def makeoptionsmenu(self): | |
|
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:
17961
diff
changeset
|
226 menuitems = [('Font settings\xc9', self.domenu_fontsettings), |
|
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:
17961
diff
changeset
|
227 ("Save options\xc9", self.domenu_options), |
|
10323
fed66bddce63
added "Save options" menu to popup so users can set the creator of scripts -- jvr
Just van Rossum <just@lettererror.com>
parents:
10105
diff
changeset
|
228 '-', |
| 10047 | 229 ('\0' + chr(self.run_as_main) + 'Run as __main__', self.domenu_toggle_run_as_main), |
|
22715
e0edfeea5183
Added a "run with commandline Python" flag. Works in MachoPython, should work
Jack Jansen <jack.jansen@cwi.nl>
parents:
22676
diff
changeset
|
230 #('\0' + chr(self.run_with_interpreter) + 'Run with Interpreter', self.domenu_dtoggle_run_with_interpreter), |
|
e0edfeea5183
Added a "run with commandline Python" flag. Works in MachoPython, should work
Jack Jansen <jack.jansen@cwi.nl>
parents:
22676
diff
changeset
|
231 ('\0' + chr(self.run_with_cl_interpreter) + 'Run with commandline Python', self.domenu_toggle_run_with_cl_interpreter), |
|
e0edfeea5183
Added a "run with commandline Python" flag. Works in MachoPython, should work
Jack Jansen <jack.jansen@cwi.nl>
parents:
22676
diff
changeset
|
232 '-', |
| 10047 | 233 ('Modularize', self.domenu_modularize), |
|
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:
17961
diff
changeset
|
234 ('Browse namespace\xc9', self.domenu_browsenamespace), |
| 10047 | 235 '-'] |
| 236 if self.profiling: | |
| 237 menuitems = menuitems + [('Disable profiler', self.domenu_toggleprofiler)] | |
| 238 else: | |
| 239 menuitems = menuitems + [('Enable profiler', self.domenu_toggleprofiler)] | |
| 240 if self.editgroup.editor._debugger: | |
| 241 menuitems = menuitems + [('Disable debugger', self.domenu_toggledebugger), | |
| 242 ('Clear breakpoints', self.domenu_clearbreakpoints), | |
|
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:
17961
diff
changeset
|
243 ('Edit breakpoints\xc9', self.domenu_editbreakpoints)] |
| 10047 | 244 else: |
| 245 menuitems = menuitems + [('Enable debugger', self.domenu_toggledebugger)] | |
| 246 self.editgroup.optionsmenu.set(menuitems) | |
| 247 | |
| 248 def domenu_toggle_run_as_main(self): | |
| 249 self.run_as_main = not self.run_as_main | |
|
15283
4c7c779bad87
Hm, I never checked in my incomplete "run with interpreter" mods. UI is there (but is disabled), functionality is not there.
Just van Rossum <just@lettererror.com>
parents:
12972
diff
changeset
|
250 self.run_with_interpreter = 0 |
|
22715
e0edfeea5183
Added a "run with commandline Python" flag. Works in MachoPython, should work
Jack Jansen <jack.jansen@cwi.nl>
parents:
22676
diff
changeset
|
251 self.run_with_cl_interpreter = 0 |
|
20835
3fbd253dea5d
some support for syntax coloring, disabled for now
Just van Rossum <just@letterror.com>
parents:
19488
diff
changeset
|
252 self.editgroup.editor.selectionchanged() |
|
15283
4c7c779bad87
Hm, I never checked in my incomplete "run with interpreter" mods. UI is there (but is disabled), functionality is not there.
Just van Rossum <just@lettererror.com>
parents:
12972
diff
changeset
|
253 |
|
22715
e0edfeea5183
Added a "run with commandline Python" flag. Works in MachoPython, should work
Jack Jansen <jack.jansen@cwi.nl>
parents:
22676
diff
changeset
|
254 def XXdomenu_toggle_run_with_interpreter(self): |
|
15283
4c7c779bad87
Hm, I never checked in my incomplete "run with interpreter" mods. UI is there (but is disabled), functionality is not there.
Just van Rossum <just@lettererror.com>
parents:
12972
diff
changeset
|
255 self.run_with_interpreter = not self.run_with_interpreter |
|
4c7c779bad87
Hm, I never checked in my incomplete "run with interpreter" mods. UI is there (but is disabled), functionality is not there.
Just van Rossum <just@lettererror.com>
parents:
12972
diff
changeset
|
256 self.run_as_main = 0 |
|
22715
e0edfeea5183
Added a "run with commandline Python" flag. Works in MachoPython, should work
Jack Jansen <jack.jansen@cwi.nl>
parents:
22676
diff
changeset
|
257 self.run_with_cl_interpreter = 0 |
|
e0edfeea5183
Added a "run with commandline Python" flag. Works in MachoPython, should work
Jack Jansen <jack.jansen@cwi.nl>
parents:
22676
diff
changeset
|
258 self.editgroup.editor.selectionchanged() |
|
e0edfeea5183
Added a "run with commandline Python" flag. Works in MachoPython, should work
Jack Jansen <jack.jansen@cwi.nl>
parents:
22676
diff
changeset
|
259 |
|
e0edfeea5183
Added a "run with commandline Python" flag. Works in MachoPython, should work
Jack Jansen <jack.jansen@cwi.nl>
parents:
22676
diff
changeset
|
260 def domenu_toggle_run_with_cl_interpreter(self): |
|
e0edfeea5183
Added a "run with commandline Python" flag. Works in MachoPython, should work
Jack Jansen <jack.jansen@cwi.nl>
parents:
22676
diff
changeset
|
261 self.run_with_cl_interpreter = not self.run_with_cl_interpreter |
|
e0edfeea5183
Added a "run with commandline Python" flag. Works in MachoPython, should work
Jack Jansen <jack.jansen@cwi.nl>
parents:
22676
diff
changeset
|
262 self.run_as_main = 0 |
|
e0edfeea5183
Added a "run with commandline Python" flag. Works in MachoPython, should work
Jack Jansen <jack.jansen@cwi.nl>
parents:
22676
diff
changeset
|
263 self.run_with_interpreter = 0 |
|
20835
3fbd253dea5d
some support for syntax coloring, disabled for now
Just van Rossum <just@letterror.com>
parents:
19488
diff
changeset
|
264 self.editgroup.editor.selectionchanged() |
| 10047 | 265 |
| 266 def showbreakpoints(self, onoff): | |
| 267 self.editgroup.editor.showbreakpoints(onoff) | |
| 268 self.debugging = onoff | |
| 269 | |
| 270 def domenu_clearbreakpoints(self, *args): | |
| 271 self.editgroup.editor.clearbreakpoints() | |
| 272 | |
| 273 def domenu_editbreakpoints(self, *args): | |
| 274 self.editgroup.editor.editbreakpoints() | |
| 275 | |
| 276 def domenu_toggledebugger(self, *args): | |
| 277 if not self.debugging: | |
| 278 W.SetCursor('watch') | |
| 279 self.debugging = not self.debugging | |
| 280 self.editgroup.editor.togglebreakpoints() | |
| 281 | |
| 282 def domenu_toggleprofiler(self, *args): | |
| 283 self.profiling = not self.profiling | |
| 284 | |
| 285 def domenu_browsenamespace(self, *args): | |
| 286 import PyBrowser, W | |
| 287 W.SetCursor('watch') | |
| 288 globals, file, modname = self.getenvironment() | |
| 289 if not modname: | |
| 290 modname = self.title | |
| 291 PyBrowser.Browser(globals, "Object browser: " + modname) | |
| 292 | |
| 293 def domenu_modularize(self, *args): | |
| 294 modname = _filename_as_modname(self.title) | |
| 295 if not modname: | |
|
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:
17961
diff
changeset
|
296 raise W.AlertError, "Can't modularize \"%s\"" % self.title |
| 10047 | 297 run_as_main = self.run_as_main |
| 298 self.run_as_main = 0 | |
| 299 self.run() | |
| 300 self.run_as_main = run_as_main | |
| 301 if self.path: | |
| 302 file = self.path | |
| 303 else: | |
| 304 file = self.title | |
| 305 | |
| 306 if self.globals and not sys.modules.has_key(modname): | |
| 307 module = imp.new_module(modname) | |
| 308 for attr in self.globals.keys(): | |
| 309 setattr(module,attr,self.globals[attr]) | |
| 310 sys.modules[modname] = module | |
| 311 self.globals = {} | |
| 312 | |
| 313 def domenu_fontsettings(self, *args): | |
| 314 import FontSettings | |
| 315 fontsettings = self.editgroup.editor.getfontsettings() | |
| 316 tabsettings = self.editgroup.editor.gettabsettings() | |
| 317 settings = FontSettings.FontDialog(fontsettings, tabsettings) | |
| 318 if settings: | |
| 319 fontsettings, tabsettings = settings | |
| 320 self.editgroup.editor.setfontsettings(fontsettings) | |
| 321 self.editgroup.editor.settabsettings(tabsettings) | |
| 322 | |
|
10323
fed66bddce63
added "Save options" menu to popup so users can set the creator of scripts -- jvr
Just van Rossum <just@lettererror.com>
parents:
10105
diff
changeset
|
323 def domenu_options(self, *args): |
|
22676
0b58ea07495c
repair damage: canceling the "save options" dialog now works again.
Just van Rossum <just@letterror.com>
parents:
22673
diff
changeset
|
324 rv = SaveOptions(self._creator, self._eoln) |
|
0b58ea07495c
repair damage: canceling the "save options" dialog now works again.
Just van Rossum <just@letterror.com>
parents:
22673
diff
changeset
|
325 if rv: |
|
20835
3fbd253dea5d
some support for syntax coloring, disabled for now
Just van Rossum <just@letterror.com>
parents:
19488
diff
changeset
|
326 self.editgroup.editor.selectionchanged() # ouch... |
|
22676
0b58ea07495c
repair damage: canceling the "save options" dialog now works again.
Just van Rossum <just@letterror.com>
parents:
22673
diff
changeset
|
327 self._creator, self._eoln = rv |
|
10323
fed66bddce63
added "Save options" menu to popup so users can set the creator of scripts -- jvr
Just van Rossum <just@lettererror.com>
parents:
10105
diff
changeset
|
328 |
| 10047 | 329 def clicklinefield(self): |
| 330 if self._currentwidget <> self.linefield: | |
| 331 self.linefield.select(1) | |
| 332 self.linefield.selectall() | |
| 333 return 1 | |
| 334 | |
| 335 def clickeditor(self): | |
| 336 if self._currentwidget <> self.editgroup.editor: | |
| 337 self.dolinefield() | |
| 338 return 1 | |
| 339 | |
| 340 def updateselection(self, force = 0): | |
| 341 sel = min(self.editgroup.editor.getselection()) | |
| 342 lineno = self.editgroup.editor.offsettoline(sel) | |
| 343 if lineno <> self.lastlineno or force: | |
| 344 self.lastlineno = lineno | |
| 345 self.linefield.set(str(lineno + 1)) | |
| 346 self.linefield.selview() | |
| 347 | |
| 348 def dolinefield(self): | |
| 349 try: | |
| 350 lineno = string.atoi(self.linefield.get()) - 1 | |
| 351 if lineno <> self.lastlineno: | |
| 352 self.editgroup.editor.selectline(lineno) | |
| 353 self.updateselection(1) | |
| 354 except: | |
| 355 self.updateselection(1) | |
| 356 self.editgroup.editor.select(1) | |
| 357 | |
| 358 def setinfotext(self): | |
| 359 if not hasattr(self, 'infotext'): | |
| 360 return | |
| 361 if self.path: | |
| 362 self.infotext.set(self.path) | |
| 363 else: | |
| 364 self.infotext.set("") | |
| 365 | |
| 366 def close(self): | |
| 367 if self.editgroup.editor.changed: | |
|
18390
1e02e2014e36
- minor cleanup, removed bogus comments
Just van Rossum <just@letterror.com>
parents:
18167
diff
changeset
|
368 Qd.InitCursor() |
|
1e02e2014e36
- minor cleanup, removed bogus comments
Just van Rossum <just@letterror.com>
parents:
18167
diff
changeset
|
369 save = EasyDialogs.AskYesNoCancel('Save window "%s" before closing?' % self.title, |
|
1e02e2014e36
- minor cleanup, removed bogus comments
Just van Rossum <just@letterror.com>
parents:
18167
diff
changeset
|
370 default=1, no="Don\xd5t save") |
| 10047 | 371 if save > 0: |
| 372 if self.domenu_save(): | |
| 373 return 1 | |
| 374 elif save < 0: | |
| 375 return 1 | |
|
18390
1e02e2014e36
- minor cleanup, removed bogus comments
Just van Rossum <just@letterror.com>
parents:
18167
diff
changeset
|
376 self.globals = None |
| 10047 | 377 W.Window.close(self) |
| 378 | |
| 379 def domenu_close(self, *args): | |
| 380 return self.close() | |
| 381 | |
| 382 def domenu_save(self, *args): | |
| 383 if not self.path: | |
| 384 # Will call us recursively | |
| 385 return self.domenu_save_as() | |
| 386 data = self.editgroup.editor.get() | |
|
22673
b96740c42e80
Completely revamped newline handling. PyEdit is now newline-preserving
Jack Jansen <jack.jansen@cwi.nl>
parents:
21868
diff
changeset
|
387 if self._eoln != '\r': |
|
b96740c42e80
Completely revamped newline handling. PyEdit is now newline-preserving
Jack Jansen <jack.jansen@cwi.nl>
parents:
21868
diff
changeset
|
388 data = string.replace(data, '\r', self._eoln) |
| 10047 | 389 fp = open(self.path, 'wb') # open file in binary mode, data has '\r' line-endings |
| 390 fp.write(data) | |
| 391 fp.close() | |
|
27737
4367f805db09
Got rid of macfs and FSSpecs in general (pathnames or FSRefs are now
Jack Jansen <jack.jansen@cwi.nl>
parents:
27408
diff
changeset
|
392 MacOS.SetCreatorAndType(self.path, self._creator, 'TEXT') |
| 10047 | 393 self.getsettings() |
| 394 self.writewindowsettings() | |
| 395 self.editgroup.editor.changed = 0 | |
| 396 self.editgroup.editor.selchanged = 0 | |
| 397 import linecache | |
| 398 if linecache.cache.has_key(self.path): | |
| 399 del linecache.cache[self.path] | |
| 400 import macostools | |
| 401 macostools.touched(self.path) | |
| 402 | |
| 403 def can_save(self, menuitem): | |
| 404 return self.editgroup.editor.changed or self.editgroup.editor.selchanged | |
| 405 | |
| 406 def domenu_save_as(self, *args): | |
| 27408 | 407 path = EasyDialogs.AskFileForSave(message='Save as:', savedFileName=self.title) |
| 408 if not path: | |
| 10047 | 409 return 1 |
| 410 self.showbreakpoints(0) | |
| 27408 | 411 self.path = path |
| 10047 | 412 self.setinfotext() |
| 413 self.title = os.path.split(self.path)[-1] | |
| 414 self.wid.SetWTitle(self.title) | |
| 415 self.domenu_save() | |
| 416 self.editgroup.editor.setfile(self.getfilename()) | |
| 417 app = W.getapplication() | |
| 418 app.makeopenwindowsmenu() | |
| 419 if hasattr(app, 'makescriptsmenu'): | |
| 420 app = W.getapplication() | |
|
27737
4367f805db09
Got rid of macfs and FSSpecs in general (pathnames or FSRefs are now
Jack Jansen <jack.jansen@cwi.nl>
parents:
27408
diff
changeset
|
421 fsr, changed = app.scriptsfolder.FSResolveAlias(None) |
|
4367f805db09
Got rid of macfs and FSSpecs in general (pathnames or FSRefs are now
Jack Jansen <jack.jansen@cwi.nl>
parents:
27408
diff
changeset
|
422 path = fsr.as_pathname() |
| 10047 | 423 if path == self.path[:len(path)]: |
| 424 W.getapplication().makescriptsmenu() | |
| 425 | |
| 426 def domenu_save_as_applet(self, *args): | |
|
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:
17961
diff
changeset
|
427 import buildtools |
| 10047 | 428 |
| 429 buildtools.DEBUG = 0 # ouch. | |
| 430 | |
| 431 if self.title[-3:] == ".py": | |
| 432 destname = self.title[:-3] | |
| 433 else: | |
| 434 destname = self.title + ".applet" | |
| 27408 | 435 destname = EasyDialogs.AskFileForSave(message='Save as Applet:', |
| 436 savedFileName=destname) | |
| 437 if not destname: | |
| 10047 | 438 return 1 |
| 439 W.SetCursor("watch") | |
| 440 if self.path: | |
| 441 filename = self.path | |
| 442 if filename[-3:] == ".py": | |
| 443 rsrcname = filename[:-3] + '.rsrc' | |
| 444 else: | |
| 445 rsrcname = filename + '.rsrc' | |
| 446 else: | |
| 447 filename = self.title | |
| 448 rsrcname = "" | |
| 449 | |
| 450 pytext = self.editgroup.editor.get() | |
| 451 pytext = string.split(pytext, '\r') | |
| 452 pytext = string.join(pytext, '\n') + '\n' | |
| 453 try: | |
| 454 code = compile(pytext, filename, "exec") | |
| 455 except (SyntaxError, EOFError): | |
| 456 raise buildtools.BuildError, "Syntax error in script %s" % `filename` | |
|
27838
b51970ba2180
Create applets slightly differently: by saving the sourcecode to a
Jack Jansen <jack.jansen@cwi.nl>
parents:
27737
diff
changeset
|
457 |
|
b51970ba2180
Create applets slightly differently: by saving the sourcecode to a
Jack Jansen <jack.jansen@cwi.nl>
parents:
27737
diff
changeset
|
458 import tempfile |
|
b51970ba2180
Create applets slightly differently: by saving the sourcecode to a
Jack Jansen <jack.jansen@cwi.nl>
parents:
27737
diff
changeset
|
459 tmpdir = tempfile.mkdtemp() |
|
b51970ba2180
Create applets slightly differently: by saving the sourcecode to a
Jack Jansen <jack.jansen@cwi.nl>
parents:
27737
diff
changeset
|
460 |
|
b51970ba2180
Create applets slightly differently: by saving the sourcecode to a
Jack Jansen <jack.jansen@cwi.nl>
parents:
27737
diff
changeset
|
461 if filename[-3:] != ".py": |
|
b51970ba2180
Create applets slightly differently: by saving the sourcecode to a
Jack Jansen <jack.jansen@cwi.nl>
parents:
27737
diff
changeset
|
462 filename = filename + ".py" |
|
b51970ba2180
Create applets slightly differently: by saving the sourcecode to a
Jack Jansen <jack.jansen@cwi.nl>
parents:
27737
diff
changeset
|
463 filename = os.path.join(tmpdir, os.path.split(filename)[1]) |
|
b51970ba2180
Create applets slightly differently: by saving the sourcecode to a
Jack Jansen <jack.jansen@cwi.nl>
parents:
27737
diff
changeset
|
464 fp = open(filename, "w") |
|
b51970ba2180
Create applets slightly differently: by saving the sourcecode to a
Jack Jansen <jack.jansen@cwi.nl>
parents:
27737
diff
changeset
|
465 fp.write(pytext) |
|
b51970ba2180
Create applets slightly differently: by saving the sourcecode to a
Jack Jansen <jack.jansen@cwi.nl>
parents:
27737
diff
changeset
|
466 fp.close() |
| 10047 | 467 |
| 468 # Try removing the output file | |
| 469 try: | |
| 470 os.remove(destname) | |
| 471 except os.error: | |
| 472 pass | |
| 473 template = buildtools.findtemplate() | |
|
27838
b51970ba2180
Create applets slightly differently: by saving the sourcecode to a
Jack Jansen <jack.jansen@cwi.nl>
parents:
27737
diff
changeset
|
474 buildtools.process(template, filename, destname, rsrcname=rsrcname, progress=None) |
|
27905
233ed6cc8e14
When building an applet clear out the tempfile and dir afterwards.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27838
diff
changeset
|
475 try: |
|
233ed6cc8e14
When building an applet clear out the tempfile and dir afterwards.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27838
diff
changeset
|
476 os.remove(filename) |
|
233ed6cc8e14
When building an applet clear out the tempfile and dir afterwards.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27838
diff
changeset
|
477 os.rmdir(tmpdir) |
|
233ed6cc8e14
When building an applet clear out the tempfile and dir afterwards.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27838
diff
changeset
|
478 except os.error: |
|
233ed6cc8e14
When building an applet clear out the tempfile and dir afterwards.
Jack Jansen <jack.jansen@cwi.nl>
parents:
27838
diff
changeset
|
479 pass |
| 10047 | 480 |
| 481 def domenu_gotoline(self, *args): | |
| 482 self.linefield.selectall() | |
| 483 self.linefield.select(1) | |
| 484 self.linefield.selectall() | |
| 485 | |
| 486 def domenu_selectline(self, *args): | |
| 487 self.editgroup.editor.expandselection() | |
| 488 | |
| 489 def domenu_find(self, *args): | |
| 490 searchengine.show() | |
| 491 | |
| 492 def domenu_entersearchstring(self, *args): | |
| 493 searchengine.setfindstring() | |
| 494 | |
| 495 def domenu_replace(self, *args): | |
| 496 searchengine.replace() | |
| 497 | |
| 498 def domenu_findnext(self, *args): | |
| 499 searchengine.findnext() | |
| 500 | |
| 501 def domenu_replacefind(self, *args): | |
| 502 searchengine.replacefind() | |
| 503 | |
| 504 def domenu_run(self, *args): | |
| 505 self.runbutton.push() | |
| 506 | |
| 507 def domenu_runselection(self, *args): | |
| 508 self.runselbutton.push() | |
| 509 | |
| 510 def run(self): | |
|
12308
ddc4e62b216b
added experimental microthread support for use with stackless python -- bw compatible (jvr)
Just van Rossum <just@lettererror.com>
parents:
11629
diff
changeset
|
511 if self._threadstate == (0, 0): |
|
ddc4e62b216b
added experimental microthread support for use with stackless python -- bw compatible (jvr)
Just van Rossum <just@lettererror.com>
parents:
11629
diff
changeset
|
512 self._run() |
|
ddc4e62b216b
added experimental microthread support for use with stackless python -- bw compatible (jvr)
Just van Rossum <just@lettererror.com>
parents:
11629
diff
changeset
|
513 else: |
|
15283
4c7c779bad87
Hm, I never checked in my incomplete "run with interpreter" mods. UI is there (but is disabled), functionality is not there.
Just van Rossum <just@lettererror.com>
parents:
12972
diff
changeset
|
514 lock = Wthreading.Lock() |
|
4c7c779bad87
Hm, I never checked in my incomplete "run with interpreter" mods. UI is there (but is disabled), functionality is not there.
Just van Rossum <just@lettererror.com>
parents:
12972
diff
changeset
|
515 lock.acquire() |
|
4c7c779bad87
Hm, I never checked in my incomplete "run with interpreter" mods. UI is there (but is disabled), functionality is not there.
Just van Rossum <just@lettererror.com>
parents:
12972
diff
changeset
|
516 self._thread.postException(KeyboardInterrupt) |
|
4c7c779bad87
Hm, I never checked in my incomplete "run with interpreter" mods. UI is there (but is disabled), functionality is not there.
Just van Rossum <just@lettererror.com>
parents:
12972
diff
changeset
|
517 if self._thread.isBlocked(): |
|
12308
ddc4e62b216b
added experimental microthread support for use with stackless python -- bw compatible (jvr)
Just van Rossum <just@lettererror.com>
parents:
11629
diff
changeset
|
518 self._thread.start() |
|
15283
4c7c779bad87
Hm, I never checked in my incomplete "run with interpreter" mods. UI is there (but is disabled), functionality is not there.
Just van Rossum <just@lettererror.com>
parents:
12972
diff
changeset
|
519 lock.release() |
| 10047 | 520 |
| 521 def _run(self): | |
|
15283
4c7c779bad87
Hm, I never checked in my incomplete "run with interpreter" mods. UI is there (but is disabled), functionality is not there.
Just van Rossum <just@lettererror.com>
parents:
12972
diff
changeset
|
522 if self.run_with_interpreter: |
|
4c7c779bad87
Hm, I never checked in my incomplete "run with interpreter" mods. UI is there (but is disabled), functionality is not there.
Just van Rossum <just@lettererror.com>
parents:
12972
diff
changeset
|
523 if self.editgroup.editor.changed: |
|
24212
296dd32425d6
minor fixes, removed obsolete warning
Just van Rossum <just@letterror.com>
parents:
22715
diff
changeset
|
524 Qd.InitCursor() |
|
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:
17961
diff
changeset
|
525 save = EasyDialogs.AskYesNoCancel('Save "%s" before running?' % self.title, 1) |
|
15283
4c7c779bad87
Hm, I never checked in my incomplete "run with interpreter" mods. UI is there (but is disabled), functionality is not there.
Just van Rossum <just@lettererror.com>
parents:
12972
diff
changeset
|
526 if save > 0: |
|
4c7c779bad87
Hm, I never checked in my incomplete "run with interpreter" mods. UI is there (but is disabled), functionality is not there.
Just van Rossum <just@lettererror.com>
parents:
12972
diff
changeset
|
527 if self.domenu_save(): |
|
4c7c779bad87
Hm, I never checked in my incomplete "run with interpreter" mods. UI is there (but is disabled), functionality is not there.
Just van Rossum <just@lettererror.com>
parents:
12972
diff
changeset
|
528 return |
|
4c7c779bad87
Hm, I never checked in my incomplete "run with interpreter" mods. UI is there (but is disabled), functionality is not there.
Just van Rossum <just@lettererror.com>
parents:
12972
diff
changeset
|
529 elif save < 0: |
|
4c7c779bad87
Hm, I never checked in my incomplete "run with interpreter" mods. UI is there (but is disabled), functionality is not there.
Just van Rossum <just@lettererror.com>
parents:
12972
diff
changeset
|
530 return |
|
4c7c779bad87
Hm, I never checked in my incomplete "run with interpreter" mods. UI is there (but is disabled), functionality is not there.
Just van Rossum <just@lettererror.com>
parents:
12972
diff
changeset
|
531 if not self.path: |
|
4c7c779bad87
Hm, I never checked in my incomplete "run with interpreter" mods. UI is there (but is disabled), functionality is not there.
Just van Rossum <just@lettererror.com>
parents:
12972
diff
changeset
|
532 raise W.AlertError, "Can't run unsaved file" |
|
4c7c779bad87
Hm, I never checked in my incomplete "run with interpreter" mods. UI is there (but is disabled), functionality is not there.
Just van Rossum <just@lettererror.com>
parents:
12972
diff
changeset
|
533 self._run_with_interpreter() |
|
22715
e0edfeea5183
Added a "run with commandline Python" flag. Works in MachoPython, should work
Jack Jansen <jack.jansen@cwi.nl>
parents:
22676
diff
changeset
|
534 elif self.run_with_cl_interpreter: |
|
e0edfeea5183
Added a "run with commandline Python" flag. Works in MachoPython, should work
Jack Jansen <jack.jansen@cwi.nl>
parents:
22676
diff
changeset
|
535 if self.editgroup.editor.changed: |
|
24212
296dd32425d6
minor fixes, removed obsolete warning
Just van Rossum <just@letterror.com>
parents:
22715
diff
changeset
|
536 Qd.InitCursor() |
|
22715
e0edfeea5183
Added a "run with commandline Python" flag. Works in MachoPython, should work
Jack Jansen <jack.jansen@cwi.nl>
parents:
22676
diff
changeset
|
537 save = EasyDialogs.AskYesNoCancel('Save "%s" before running?' % self.title, 1) |
|
e0edfeea5183
Added a "run with commandline Python" flag. Works in MachoPython, should work
Jack Jansen <jack.jansen@cwi.nl>
parents:
22676
diff
changeset
|
538 if save > 0: |
|
e0edfeea5183
Added a "run with commandline Python" flag. Works in MachoPython, should work
Jack Jansen <jack.jansen@cwi.nl>
parents:
22676
diff
changeset
|
539 if self.domenu_save(): |
|
e0edfeea5183
Added a "run with commandline Python" flag. Works in MachoPython, should work
Jack Jansen <jack.jansen@cwi.nl>
parents:
22676
diff
changeset
|
540 return |
|
e0edfeea5183
Added a "run with commandline Python" flag. Works in MachoPython, should work
Jack Jansen <jack.jansen@cwi.nl>
parents:
22676
diff
changeset
|
541 elif save < 0: |
|
e0edfeea5183
Added a "run with commandline Python" flag. Works in MachoPython, should work
Jack Jansen <jack.jansen@cwi.nl>
parents:
22676
diff
changeset
|
542 return |
|
e0edfeea5183
Added a "run with commandline Python" flag. Works in MachoPython, should work
Jack Jansen <jack.jansen@cwi.nl>
parents:
22676
diff
changeset
|
543 if not self.path: |
|
e0edfeea5183
Added a "run with commandline Python" flag. Works in MachoPython, should work
Jack Jansen <jack.jansen@cwi.nl>
parents:
22676
diff
changeset
|
544 raise W.AlertError, "Can't run unsaved file" |
|
e0edfeea5183
Added a "run with commandline Python" flag. Works in MachoPython, should work
Jack Jansen <jack.jansen@cwi.nl>
parents:
22676
diff
changeset
|
545 self._run_with_cl_interpreter() |
|
15283
4c7c779bad87
Hm, I never checked in my incomplete "run with interpreter" mods. UI is there (but is disabled), functionality is not there.
Just van Rossum <just@lettererror.com>
parents:
12972
diff
changeset
|
546 else: |
|
4c7c779bad87
Hm, I never checked in my incomplete "run with interpreter" mods. UI is there (but is disabled), functionality is not there.
Just van Rossum <just@lettererror.com>
parents:
12972
diff
changeset
|
547 pytext = self.editgroup.editor.get() |
|
4c7c779bad87
Hm, I never checked in my incomplete "run with interpreter" mods. UI is there (but is disabled), functionality is not there.
Just van Rossum <just@lettererror.com>
parents:
12972
diff
changeset
|
548 globals, file, modname = self.getenvironment() |
|
4c7c779bad87
Hm, I never checked in my incomplete "run with interpreter" mods. UI is there (but is disabled), functionality is not there.
Just van Rossum <just@lettererror.com>
parents:
12972
diff
changeset
|
549 self.execstring(pytext, globals, globals, file, modname) |
|
4c7c779bad87
Hm, I never checked in my incomplete "run with interpreter" mods. UI is there (but is disabled), functionality is not there.
Just van Rossum <just@lettererror.com>
parents:
12972
diff
changeset
|
550 |
|
4c7c779bad87
Hm, I never checked in my incomplete "run with interpreter" mods. UI is there (but is disabled), functionality is not there.
Just van Rossum <just@lettererror.com>
parents:
12972
diff
changeset
|
551 def _run_with_interpreter(self): |
|
4c7c779bad87
Hm, I never checked in my incomplete "run with interpreter" mods. UI is there (but is disabled), functionality is not there.
Just van Rossum <just@lettererror.com>
parents:
12972
diff
changeset
|
552 interp_path = os.path.join(sys.exec_prefix, "PythonInterpreter") |
|
4c7c779bad87
Hm, I never checked in my incomplete "run with interpreter" mods. UI is there (but is disabled), functionality is not there.
Just van Rossum <just@lettererror.com>
parents:
12972
diff
changeset
|
553 if not os.path.exists(interp_path): |
|
4c7c779bad87
Hm, I never checked in my incomplete "run with interpreter" mods. UI is there (but is disabled), functionality is not there.
Just van Rossum <just@lettererror.com>
parents:
12972
diff
changeset
|
554 raise W.AlertError, "Can't find interpreter" |
|
4c7c779bad87
Hm, I never checked in my incomplete "run with interpreter" mods. UI is there (but is disabled), functionality is not there.
Just van Rossum <just@lettererror.com>
parents:
12972
diff
changeset
|
555 import findertools |
|
4c7c779bad87
Hm, I never checked in my incomplete "run with interpreter" mods. UI is there (but is disabled), functionality is not there.
Just van Rossum <just@lettererror.com>
parents:
12972
diff
changeset
|
556 XXX |
|
22715
e0edfeea5183
Added a "run with commandline Python" flag. Works in MachoPython, should work
Jack Jansen <jack.jansen@cwi.nl>
parents:
22676
diff
changeset
|
557 |
|
e0edfeea5183
Added a "run with commandline Python" flag. Works in MachoPython, should work
Jack Jansen <jack.jansen@cwi.nl>
parents:
22676
diff
changeset
|
558 def _run_with_cl_interpreter(self): |
|
e0edfeea5183
Added a "run with commandline Python" flag. Works in MachoPython, should work
Jack Jansen <jack.jansen@cwi.nl>
parents:
22676
diff
changeset
|
559 import Terminal |
|
e0edfeea5183
Added a "run with commandline Python" flag. Works in MachoPython, should work
Jack Jansen <jack.jansen@cwi.nl>
parents:
22676
diff
changeset
|
560 interp_path = os.path.join(sys.exec_prefix, "bin", "python") |
|
e0edfeea5183
Added a "run with commandline Python" flag. Works in MachoPython, should work
Jack Jansen <jack.jansen@cwi.nl>
parents:
22676
diff
changeset
|
561 file_path = self.path |
|
e0edfeea5183
Added a "run with commandline Python" flag. Works in MachoPython, should work
Jack Jansen <jack.jansen@cwi.nl>
parents:
22676
diff
changeset
|
562 if not os.path.exists(interp_path): |
|
27737
4367f805db09
Got rid of macfs and FSSpecs in general (pathnames or FSRefs are now
Jack Jansen <jack.jansen@cwi.nl>
parents:
27408
diff
changeset
|
563 # This "can happen" if we are running IDE under MacPython-OS9. |
|
4367f805db09
Got rid of macfs and FSSpecs in general (pathnames or FSRefs are now
Jack Jansen <jack.jansen@cwi.nl>
parents:
27408
diff
changeset
|
564 raise W.AlertError, "Can't find command-line Python" |
|
22715
e0edfeea5183
Added a "run with commandline Python" flag. Works in MachoPython, should work
Jack Jansen <jack.jansen@cwi.nl>
parents:
22676
diff
changeset
|
565 cmd = '"%s" "%s" ; exit' % (interp_path, file_path) |
|
e0edfeea5183
Added a "run with commandline Python" flag. Works in MachoPython, should work
Jack Jansen <jack.jansen@cwi.nl>
parents:
22676
diff
changeset
|
566 t = Terminal.Terminal() |
|
e0edfeea5183
Added a "run with commandline Python" flag. Works in MachoPython, should work
Jack Jansen <jack.jansen@cwi.nl>
parents:
22676
diff
changeset
|
567 t.do_script(with_command=cmd) |
| 10047 | 568 |
| 569 def runselection(self): | |
|
12308
ddc4e62b216b
added experimental microthread support for use with stackless python -- bw compatible (jvr)
Just van Rossum <just@lettererror.com>
parents:
11629
diff
changeset
|
570 if self._threadstate == (0, 0): |
|
ddc4e62b216b
added experimental microthread support for use with stackless python -- bw compatible (jvr)
Just van Rossum <just@lettererror.com>
parents:
11629
diff
changeset
|
571 self._runselection() |
|
ddc4e62b216b
added experimental microthread support for use with stackless python -- bw compatible (jvr)
Just van Rossum <just@lettererror.com>
parents:
11629
diff
changeset
|
572 elif self._threadstate == (1, 1): |
|
15283
4c7c779bad87
Hm, I never checked in my incomplete "run with interpreter" mods. UI is there (but is disabled), functionality is not there.
Just van Rossum <just@lettererror.com>
parents:
12972
diff
changeset
|
573 self._thread.block() |
|
12308
ddc4e62b216b
added experimental microthread support for use with stackless python -- bw compatible (jvr)
Just van Rossum <just@lettererror.com>
parents:
11629
diff
changeset
|
574 self.setthreadstate((1, 2)) |
|
ddc4e62b216b
added experimental microthread support for use with stackless python -- bw compatible (jvr)
Just van Rossum <just@lettererror.com>
parents:
11629
diff
changeset
|
575 elif self._threadstate == (1, 2): |
|
ddc4e62b216b
added experimental microthread support for use with stackless python -- bw compatible (jvr)
Just van Rossum <just@lettererror.com>
parents:
11629
diff
changeset
|
576 self._thread.start() |
|
ddc4e62b216b
added experimental microthread support for use with stackless python -- bw compatible (jvr)
Just van Rossum <just@lettererror.com>
parents:
11629
diff
changeset
|
577 self.setthreadstate((1, 1)) |
| 10047 | 578 |
| 579 def _runselection(self): | |
|
22715
e0edfeea5183
Added a "run with commandline Python" flag. Works in MachoPython, should work
Jack Jansen <jack.jansen@cwi.nl>
parents:
22676
diff
changeset
|
580 if self.run_with_interpreter or self.run_with_cl_interpreter: |
|
15283
4c7c779bad87
Hm, I never checked in my incomplete "run with interpreter" mods. UI is there (but is disabled), functionality is not there.
Just van Rossum <just@lettererror.com>
parents:
12972
diff
changeset
|
581 raise W.AlertError, "Can't run selection with Interpreter" |
| 10047 | 582 globals, file, modname = self.getenvironment() |
| 583 locals = globals | |
| 584 # select whole lines | |
| 585 self.editgroup.editor.expandselection() | |
| 586 | |
| 587 # get lineno of first selected line | |
| 588 selstart, selend = self.editgroup.editor.getselection() | |
| 589 selstart, selend = min(selstart, selend), max(selstart, selend) | |
| 590 selfirstline = self.editgroup.editor.offsettoline(selstart) | |
| 591 alltext = self.editgroup.editor.get() | |
| 592 pytext = alltext[selstart:selend] | |
| 593 lines = string.split(pytext, '\r') | |
| 594 indent = getminindent(lines) | |
| 595 if indent == 1: | |
| 596 classname = '' | |
| 597 alllines = string.split(alltext, '\r') | |
| 598 for i in range(selfirstline - 1, -1, -1): | |
| 599 line = alllines[i] | |
| 600 if line[:6] == 'class ': | |
| 601 classname = string.split(string.strip(line[6:]))[0] | |
| 602 classend = identifieRE_match(classname) | |
| 603 if classend < 1: | |
|
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:
17961
diff
changeset
|
604 raise W.AlertError, "Can't find a class." |
| 10047 | 605 classname = classname[:classend] |
| 606 break | |
| 607 elif line and line[0] not in '\t#': | |
|
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:
17961
diff
changeset
|
608 raise W.AlertError, "Can't find a class." |
| 10047 | 609 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:
17961
diff
changeset
|
610 raise W.AlertError, "Can't find a class." |
| 10047 | 611 if globals.has_key(classname): |
|
18390
1e02e2014e36
- minor cleanup, removed bogus comments
Just van Rossum <just@letterror.com>
parents:
18167
diff
changeset
|
612 klass = globals[classname] |
| 10047 | 613 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:
17961
diff
changeset
|
614 raise W.AlertError, "Can't find class \"%s\"." % classname |
|
18390
1e02e2014e36
- minor cleanup, removed bogus comments
Just van Rossum <just@letterror.com>
parents:
18167
diff
changeset
|
615 # add class def |
|
1e02e2014e36
- minor cleanup, removed bogus comments
Just van Rossum <just@letterror.com>
parents:
18167
diff
changeset
|
616 pytext = ("class %s:\n" % classname) + pytext |
|
1e02e2014e36
- minor cleanup, removed bogus comments
Just van Rossum <just@letterror.com>
parents:
18167
diff
changeset
|
617 selfirstline = selfirstline - 1 |
| 10047 | 618 elif indent > 0: |
|
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:
17961
diff
changeset
|
619 raise W.AlertError, "Can't run indented code." |
| 10047 | 620 |
| 621 # add "newlines" to fool compile/exec: | |
| 622 # now a traceback will give the right line number | |
| 623 pytext = selfirstline * '\r' + pytext | |
| 624 self.execstring(pytext, globals, locals, file, modname) | |
|
18390
1e02e2014e36
- minor cleanup, removed bogus comments
Just van Rossum <just@letterror.com>
parents:
18167
diff
changeset
|
625 if indent == 1 and globals[classname] is not klass: |
|
1e02e2014e36
- minor cleanup, removed bogus comments
Just van Rossum <just@letterror.com>
parents:
18167
diff
changeset
|
626 # update the class in place |
|
1e02e2014e36
- minor cleanup, removed bogus comments
Just van Rossum <just@letterror.com>
parents:
18167
diff
changeset
|
627 klass.__dict__.update(globals[classname].__dict__) |
|
1e02e2014e36
- minor cleanup, removed bogus comments
Just van Rossum <just@letterror.com>
parents:
18167
diff
changeset
|
628 globals[classname] = klass |
| 10047 | 629 |
|
12308
ddc4e62b216b
added experimental microthread support for use with stackless python -- bw compatible (jvr)
Just van Rossum <just@lettererror.com>
parents:
11629
diff
changeset
|
630 def setthreadstate(self, state): |
|
ddc4e62b216b
added experimental microthread support for use with stackless python -- bw compatible (jvr)
Just van Rossum <just@lettererror.com>
parents:
11629
diff
changeset
|
631 oldstate = self._threadstate |
|
ddc4e62b216b
added experimental microthread support for use with stackless python -- bw compatible (jvr)
Just van Rossum <just@lettererror.com>
parents:
11629
diff
changeset
|
632 if oldstate[0] <> state[0]: |
|
ddc4e62b216b
added experimental microthread support for use with stackless python -- bw compatible (jvr)
Just van Rossum <just@lettererror.com>
parents:
11629
diff
changeset
|
633 self.runbutton.settitle(runButtonLabels[state[0]]) |
|
ddc4e62b216b
added experimental microthread support for use with stackless python -- bw compatible (jvr)
Just van Rossum <just@lettererror.com>
parents:
11629
diff
changeset
|
634 if oldstate[1] <> state[1]: |
|
ddc4e62b216b
added experimental microthread support for use with stackless python -- bw compatible (jvr)
Just van Rossum <just@lettererror.com>
parents:
11629
diff
changeset
|
635 self.runselbutton.settitle(runSelButtonLabels[state[1]]) |
|
ddc4e62b216b
added experimental microthread support for use with stackless python -- bw compatible (jvr)
Just van Rossum <just@lettererror.com>
parents:
11629
diff
changeset
|
636 self._threadstate = state |
|
ddc4e62b216b
added experimental microthread support for use with stackless python -- bw compatible (jvr)
Just van Rossum <just@lettererror.com>
parents:
11629
diff
changeset
|
637 |
|
ddc4e62b216b
added experimental microthread support for use with stackless python -- bw compatible (jvr)
Just van Rossum <just@lettererror.com>
parents:
11629
diff
changeset
|
638 def _exec_threadwrapper(self, *args, **kwargs): |
|
ddc4e62b216b
added experimental microthread support for use with stackless python -- bw compatible (jvr)
Just van Rossum <just@lettererror.com>
parents:
11629
diff
changeset
|
639 apply(execstring, args, kwargs) |
|
ddc4e62b216b
added experimental microthread support for use with stackless python -- bw compatible (jvr)
Just van Rossum <just@lettererror.com>
parents:
11629
diff
changeset
|
640 self.setthreadstate((0, 0)) |
|
ddc4e62b216b
added experimental microthread support for use with stackless python -- bw compatible (jvr)
Just van Rossum <just@lettererror.com>
parents:
11629
diff
changeset
|
641 self._thread = None |
|
ddc4e62b216b
added experimental microthread support for use with stackless python -- bw compatible (jvr)
Just van Rossum <just@lettererror.com>
parents:
11629
diff
changeset
|
642 |
| 10047 | 643 def execstring(self, pytext, globals, locals, file, modname): |
| 644 tracebackwindow.hide() | |
| 645 # update windows | |
| 646 W.getapplication().refreshwindows() | |
| 647 if self.run_as_main: | |
| 648 modname = "__main__" | |
| 649 if self.path: | |
| 650 dir = os.path.dirname(self.path) | |
| 651 savedir = os.getcwd() | |
| 652 os.chdir(dir) | |
|
10058
ee6256081366
better sys.path munging when running scripts -- jvr
Just van Rossum <just@lettererror.com>
parents:
10047
diff
changeset
|
653 sys.path.insert(0, dir) |
| 10047 | 654 else: |
| 655 cwdindex = None | |
| 656 try: | |
|
15283
4c7c779bad87
Hm, I never checked in my incomplete "run with interpreter" mods. UI is there (but is disabled), functionality is not there.
Just van Rossum <just@lettererror.com>
parents:
12972
diff
changeset
|
657 if haveThreading: |
|
4c7c779bad87
Hm, I never checked in my incomplete "run with interpreter" mods. UI is there (but is disabled), functionality is not there.
Just van Rossum <just@lettererror.com>
parents:
12972
diff
changeset
|
658 self._thread = Wthreading.Thread(os.path.basename(file), |
|
12308
ddc4e62b216b
added experimental microthread support for use with stackless python -- bw compatible (jvr)
Just van Rossum <just@lettererror.com>
parents:
11629
diff
changeset
|
659 self._exec_threadwrapper, pytext, globals, locals, file, self.debugging, |
|
ddc4e62b216b
added experimental microthread support for use with stackless python -- bw compatible (jvr)
Just van Rossum <just@lettererror.com>
parents:
11629
diff
changeset
|
660 modname, self.profiling) |
|
ddc4e62b216b
added experimental microthread support for use with stackless python -- bw compatible (jvr)
Just van Rossum <just@lettererror.com>
parents:
11629
diff
changeset
|
661 self.setthreadstate((1, 1)) |
|
ddc4e62b216b
added experimental microthread support for use with stackless python -- bw compatible (jvr)
Just van Rossum <just@lettererror.com>
parents:
11629
diff
changeset
|
662 self._thread.start() |
|
ddc4e62b216b
added experimental microthread support for use with stackless python -- bw compatible (jvr)
Just van Rossum <just@lettererror.com>
parents:
11629
diff
changeset
|
663 else: |
|
ddc4e62b216b
added experimental microthread support for use with stackless python -- bw compatible (jvr)
Just van Rossum <just@lettererror.com>
parents:
11629
diff
changeset
|
664 execstring(pytext, globals, locals, file, self.debugging, |
|
ddc4e62b216b
added experimental microthread support for use with stackless python -- bw compatible (jvr)
Just van Rossum <just@lettererror.com>
parents:
11629
diff
changeset
|
665 modname, self.profiling) |
| 10047 | 666 finally: |
| 667 if self.path: | |
| 668 os.chdir(savedir) | |
|
10058
ee6256081366
better sys.path munging when running scripts -- jvr
Just van Rossum <just@lettererror.com>
parents:
10047
diff
changeset
|
669 del sys.path[0] |
| 10047 | 670 |
| 671 def getenvironment(self): | |
| 672 if self.path: | |
| 673 file = self.path | |
| 674 dir = os.path.dirname(file) | |
| 675 # check if we're part of a package | |
| 676 modname = "" | |
| 677 while os.path.exists(os.path.join(dir, "__init__.py")): | |
| 678 dir, dirname = os.path.split(dir) | |
|
10105
e6bba02ff624
fixed problem with "reloading" sub-sub-modules -- jvr
Just van Rossum <just@lettererror.com>
parents:
10087
diff
changeset
|
679 modname = dirname + '.' + modname |
| 10047 | 680 subname = _filename_as_modname(self.title) |
|
20835
3fbd253dea5d
some support for syntax coloring, disabled for now
Just van Rossum <just@letterror.com>
parents:
19488
diff
changeset
|
681 if subname is None: |
|
3fbd253dea5d
some support for syntax coloring, disabled for now
Just van Rossum <just@letterror.com>
parents:
19488
diff
changeset
|
682 return self.globals, file, None |
| 10047 | 683 if modname: |
| 684 if subname == "__init__": | |
|
10105
e6bba02ff624
fixed problem with "reloading" sub-sub-modules -- jvr
Just van Rossum <just@lettererror.com>
parents:
10087
diff
changeset
|
685 # strip trailing period |
|
e6bba02ff624
fixed problem with "reloading" sub-sub-modules -- jvr
Just van Rossum <just@lettererror.com>
parents:
10087
diff
changeset
|
686 modname = modname[:-1] |
| 10047 | 687 else: |
|
10105
e6bba02ff624
fixed problem with "reloading" sub-sub-modules -- jvr
Just van Rossum <just@lettererror.com>
parents:
10087
diff
changeset
|
688 modname = modname + subname |
| 10047 | 689 else: |
| 690 modname = subname | |
| 691 if sys.modules.has_key(modname): | |
| 692 globals = sys.modules[modname].__dict__ | |
| 693 self.globals = {} | |
| 694 else: | |
| 695 globals = self.globals | |
|
12308
ddc4e62b216b
added experimental microthread support for use with stackless python -- bw compatible (jvr)
Just van Rossum <just@lettererror.com>
parents:
11629
diff
changeset
|
696 modname = subname |
| 10047 | 697 else: |
| 698 file = '<%s>' % self.title | |
| 699 globals = self.globals | |
| 700 modname = file | |
| 701 return globals, file, modname | |
| 702 | |
| 703 def write(self, stuff): | |
| 704 """for use as stdout""" | |
| 705 self._buf = self._buf + stuff | |
| 706 if '\n' in self._buf: | |
| 707 self.flush() | |
| 708 | |
| 709 def flush(self): | |
| 710 stuff = string.split(self._buf, '\n') | |
| 711 stuff = string.join(stuff, '\r') | |
| 712 end = self.editgroup.editor.ted.WEGetTextLength() | |
| 713 self.editgroup.editor.ted.WESetSelection(end, end) | |
| 714 self.editgroup.editor.ted.WEInsert(stuff, None, None) | |
| 715 self.editgroup.editor.updatescrollbars() | |
| 716 self._buf = "" | |
| 717 # ? optional: | |
| 718 #self.wid.SelectWindow() | |
| 719 | |
| 720 def getclasslist(self): | |
| 721 from string import find, strip | |
|
11629
d7e96cde6b47
changed the "method find" algorithm so the function/class/method popup menu also works with space-indented source files -- jvr
Just van Rossum <just@lettererror.com>
parents:
11423
diff
changeset
|
722 methodRE = re.compile(r"\r[ \t]+def ") |
|
d7e96cde6b47
changed the "method find" algorithm so the function/class/method popup menu also works with space-indented source files -- jvr
Just van Rossum <just@lettererror.com>
parents:
11423
diff
changeset
|
723 findMethod = methodRE.search |
| 10047 | 724 editor = self.editgroup.editor |
| 725 text = editor.get() | |
| 726 list = [] | |
| 727 append = list.append | |
| 728 functag = "func" | |
| 729 classtag = "class" | |
| 730 methodtag = "method" | |
| 731 pos = -1 | |
| 732 if text[:4] == 'def ': | |
| 733 append((pos + 4, functag)) | |
| 734 pos = 4 | |
| 735 while 1: | |
| 736 pos = find(text, '\rdef ', pos + 1) | |
| 737 if pos < 0: | |
| 738 break | |
| 739 append((pos + 5, functag)) | |
| 740 pos = -1 | |
| 741 if text[:6] == 'class ': | |
| 742 append((pos + 6, classtag)) | |
| 743 pos = 6 | |
| 744 while 1: | |
| 745 pos = find(text, '\rclass ', pos + 1) | |
| 746 if pos < 0: | |
| 747 break | |
| 748 append((pos + 7, classtag)) | |
| 749 pos = 0 | |
| 750 while 1: | |
|
11629
d7e96cde6b47
changed the "method find" algorithm so the function/class/method popup menu also works with space-indented source files -- jvr
Just van Rossum <just@lettererror.com>
parents:
11423
diff
changeset
|
751 m = findMethod(text, pos + 1) |
|
d7e96cde6b47
changed the "method find" algorithm so the function/class/method popup menu also works with space-indented source files -- jvr
Just van Rossum <just@lettererror.com>
parents:
11423
diff
changeset
|
752 if m is None: |
| 10047 | 753 break |
|
11629
d7e96cde6b47
changed the "method find" algorithm so the function/class/method popup menu also works with space-indented source files -- jvr
Just van Rossum <just@lettererror.com>
parents:
11423
diff
changeset
|
754 pos = m.regs[0][0] |
|
d7e96cde6b47
changed the "method find" algorithm so the function/class/method popup menu also works with space-indented source files -- jvr
Just van Rossum <just@lettererror.com>
parents:
11423
diff
changeset
|
755 #pos = find(text, '\r\tdef ', pos + 1) |
|
d7e96cde6b47
changed the "method find" algorithm so the function/class/method popup menu also works with space-indented source files -- jvr
Just van Rossum <just@lettererror.com>
parents:
11423
diff
changeset
|
756 append((m.regs[0][1], methodtag)) |
| 10047 | 757 list.sort() |
| 758 classlist = [] | |
| 759 methodlistappend = None | |
| 760 offsetToLine = editor.ted.WEOffsetToLine | |
| 761 getLineRange = editor.ted.WEGetLineRange | |
| 762 append = classlist.append | |
| 763 for pos, tag in list: | |
| 764 lineno = offsetToLine(pos) | |
| 765 lineStart, lineEnd = getLineRange(lineno) | |
| 766 line = strip(text[pos:lineEnd]) | |
| 767 line = line[:identifieRE_match(line)] | |
| 768 if tag is functag: | |
| 769 append(("def " + line, lineno + 1)) | |
| 770 methodlistappend = None | |
| 771 elif tag is classtag: | |
| 772 append(["class " + line]) | |
| 773 methodlistappend = classlist[-1].append | |
| 774 elif methodlistappend and tag is methodtag: | |
| 775 methodlistappend(("def " + line, lineno + 1)) | |
| 776 return classlist | |
| 777 | |
| 778 def popselectline(self, lineno): | |
| 779 self.editgroup.editor.selectline(lineno - 1) | |
| 780 | |
| 781 def selectline(self, lineno, charoffset = 0): | |
| 782 self.editgroup.editor.selectline(lineno - 1, charoffset) | |
| 783 | |
|
10323
fed66bddce63
added "Save options" menu to popup so users can set the creator of scripts -- jvr
Just van Rossum <just@lettererror.com>
parents:
10105
diff
changeset
|
784 class _saveoptions: |
|
fed66bddce63
added "Save options" menu to popup so users can set the creator of scripts -- jvr
Just van Rossum <just@lettererror.com>
parents:
10105
diff
changeset
|
785 |
|
22673
b96740c42e80
Completely revamped newline handling. PyEdit is now newline-preserving
Jack Jansen <jack.jansen@cwi.nl>
parents:
21868
diff
changeset
|
786 def __init__(self, creator, eoln): |
|
10323
fed66bddce63
added "Save options" menu to popup so users can set the creator of scripts -- jvr
Just van Rossum <just@lettererror.com>
parents:
10105
diff
changeset
|
787 self.rv = None |
|
22673
b96740c42e80
Completely revamped newline handling. PyEdit is now newline-preserving
Jack Jansen <jack.jansen@cwi.nl>
parents:
21868
diff
changeset
|
788 self.eoln = eoln |
|
b96740c42e80
Completely revamped newline handling. PyEdit is now newline-preserving
Jack Jansen <jack.jansen@cwi.nl>
parents:
21868
diff
changeset
|
789 self.w = w = W.ModalDialog((260, 160), 'Save options') |
|
10323
fed66bddce63
added "Save options" menu to popup so users can set the creator of scripts -- jvr
Just van Rossum <just@lettererror.com>
parents:
10105
diff
changeset
|
790 radiobuttons = [] |
|
fed66bddce63
added "Save options" menu to popup so users can set the creator of scripts -- jvr
Just van Rossum <just@lettererror.com>
parents:
10105
diff
changeset
|
791 w.label = W.TextBox((8, 8, 80, 18), "File creator:") |
|
10705
4788fd070a30
- made "Save options..." dialog more generic, so it's also usable from RoboFog
Just van Rossum <just@lettererror.com>
parents:
10323
diff
changeset
|
792 w.ide_radio = W.RadioButton((8, 22, 160, 18), "This application", radiobuttons, self.ide_hit) |
|
22673
b96740c42e80
Completely revamped newline handling. PyEdit is now newline-preserving
Jack Jansen <jack.jansen@cwi.nl>
parents:
21868
diff
changeset
|
793 w.interp_radio = W.RadioButton((8, 42, 160, 18), "MacPython Interpreter", radiobuttons, self.interp_hit) |
|
b96740c42e80
Completely revamped newline handling. PyEdit is now newline-preserving
Jack Jansen <jack.jansen@cwi.nl>
parents:
21868
diff
changeset
|
794 w.interpx_radio = W.RadioButton((8, 62, 160, 18), "OSX PythonW Interpreter", radiobuttons, self.interpx_hit) |
|
b96740c42e80
Completely revamped newline handling. PyEdit is now newline-preserving
Jack Jansen <jack.jansen@cwi.nl>
parents:
21868
diff
changeset
|
795 w.other_radio = W.RadioButton((8, 82, 50, 18), "Other:", radiobuttons) |
|
b96740c42e80
Completely revamped newline handling. PyEdit is now newline-preserving
Jack Jansen <jack.jansen@cwi.nl>
parents:
21868
diff
changeset
|
796 w.other_creator = W.EditText((62, 82, 40, 20), creator, self.otherselect) |
|
b96740c42e80
Completely revamped newline handling. PyEdit is now newline-preserving
Jack Jansen <jack.jansen@cwi.nl>
parents:
21868
diff
changeset
|
797 w.none_radio = W.RadioButton((8, 102, 160, 18), "None", radiobuttons, self.none_hit) |
|
10323
fed66bddce63
added "Save options" menu to popup so users can set the creator of scripts -- jvr
Just van Rossum <just@lettererror.com>
parents:
10105
diff
changeset
|
798 w.cancelbutton = W.Button((-180, -30, 80, 16), "Cancel", self.cancelbuttonhit) |
|
fed66bddce63
added "Save options" menu to popup so users can set the creator of scripts -- jvr
Just van Rossum <just@lettererror.com>
parents:
10105
diff
changeset
|
799 w.okbutton = W.Button((-90, -30, 80, 16), "Done", self.okbuttonhit) |
|
fed66bddce63
added "Save options" menu to popup so users can set the creator of scripts -- jvr
Just van Rossum <just@lettererror.com>
parents:
10105
diff
changeset
|
800 w.setdefaultbutton(w.okbutton) |
|
fed66bddce63
added "Save options" menu to popup so users can set the creator of scripts -- jvr
Just van Rossum <just@lettererror.com>
parents:
10105
diff
changeset
|
801 if creator == 'Pyth': |
|
fed66bddce63
added "Save options" menu to popup so users can set the creator of scripts -- jvr
Just van Rossum <just@lettererror.com>
parents:
10105
diff
changeset
|
802 w.interp_radio.set(1) |
|
10705
4788fd070a30
- made "Save options..." dialog more generic, so it's also usable from RoboFog
Just van Rossum <just@lettererror.com>
parents:
10323
diff
changeset
|
803 elif creator == W._signature: |
|
10323
fed66bddce63
added "Save options" menu to popup so users can set the creator of scripts -- jvr
Just van Rossum <just@lettererror.com>
parents:
10105
diff
changeset
|
804 w.ide_radio.set(1) |
|
22673
b96740c42e80
Completely revamped newline handling. PyEdit is now newline-preserving
Jack Jansen <jack.jansen@cwi.nl>
parents:
21868
diff
changeset
|
805 elif creator == 'PytX': |
|
b96740c42e80
Completely revamped newline handling. PyEdit is now newline-preserving
Jack Jansen <jack.jansen@cwi.nl>
parents:
21868
diff
changeset
|
806 w.interpx_radio.set(1) |
|
b96740c42e80
Completely revamped newline handling. PyEdit is now newline-preserving
Jack Jansen <jack.jansen@cwi.nl>
parents:
21868
diff
changeset
|
807 elif creator == '\0\0\0\0': |
|
b96740c42e80
Completely revamped newline handling. PyEdit is now newline-preserving
Jack Jansen <jack.jansen@cwi.nl>
parents:
21868
diff
changeset
|
808 w.none_radio.set(1) |
|
10323
fed66bddce63
added "Save options" menu to popup so users can set the creator of scripts -- jvr
Just van Rossum <just@lettererror.com>
parents:
10105
diff
changeset
|
809 else: |
|
fed66bddce63
added "Save options" menu to popup so users can set the creator of scripts -- jvr
Just van Rossum <just@lettererror.com>
parents:
10105
diff
changeset
|
810 w.other_radio.set(1) |
|
22673
b96740c42e80
Completely revamped newline handling. PyEdit is now newline-preserving
Jack Jansen <jack.jansen@cwi.nl>
parents:
21868
diff
changeset
|
811 |
|
b96740c42e80
Completely revamped newline handling. PyEdit is now newline-preserving
Jack Jansen <jack.jansen@cwi.nl>
parents:
21868
diff
changeset
|
812 w.eolnlabel = W.TextBox((168, 8, 80, 18), "Newline style:") |
|
b96740c42e80
Completely revamped newline handling. PyEdit is now newline-preserving
Jack Jansen <jack.jansen@cwi.nl>
parents:
21868
diff
changeset
|
813 radiobuttons = [] |
|
b96740c42e80
Completely revamped newline handling. PyEdit is now newline-preserving
Jack Jansen <jack.jansen@cwi.nl>
parents:
21868
diff
changeset
|
814 w.unix_radio = W.RadioButton((168, 22, 80, 18), "Unix", radiobuttons, self.unix_hit) |
|
b96740c42e80
Completely revamped newline handling. PyEdit is now newline-preserving
Jack Jansen <jack.jansen@cwi.nl>
parents:
21868
diff
changeset
|
815 w.mac_radio = W.RadioButton((168, 42, 80, 18), "Macintosh", radiobuttons, self.mac_hit) |
|
b96740c42e80
Completely revamped newline handling. PyEdit is now newline-preserving
Jack Jansen <jack.jansen@cwi.nl>
parents:
21868
diff
changeset
|
816 w.win_radio = W.RadioButton((168, 62, 80, 18), "Windows", radiobuttons, self.win_hit) |
|
b96740c42e80
Completely revamped newline handling. PyEdit is now newline-preserving
Jack Jansen <jack.jansen@cwi.nl>
parents:
21868
diff
changeset
|
817 if self.eoln == '\n': |
|
b96740c42e80
Completely revamped newline handling. PyEdit is now newline-preserving
Jack Jansen <jack.jansen@cwi.nl>
parents:
21868
diff
changeset
|
818 w.unix_radio.set(1) |
|
b96740c42e80
Completely revamped newline handling. PyEdit is now newline-preserving
Jack Jansen <jack.jansen@cwi.nl>
parents:
21868
diff
changeset
|
819 elif self.eoln == '\r\n': |
|
b96740c42e80
Completely revamped newline handling. PyEdit is now newline-preserving
Jack Jansen <jack.jansen@cwi.nl>
parents:
21868
diff
changeset
|
820 w.win_radio.set(1) |
|
b96740c42e80
Completely revamped newline handling. PyEdit is now newline-preserving
Jack Jansen <jack.jansen@cwi.nl>
parents:
21868
diff
changeset
|
821 else: |
|
b96740c42e80
Completely revamped newline handling. PyEdit is now newline-preserving
Jack Jansen <jack.jansen@cwi.nl>
parents:
21868
diff
changeset
|
822 w.mac_radio.set(1) |
|
b96740c42e80
Completely revamped newline handling. PyEdit is now newline-preserving
Jack Jansen <jack.jansen@cwi.nl>
parents:
21868
diff
changeset
|
823 |
|
10323
fed66bddce63
added "Save options" menu to popup so users can set the creator of scripts -- jvr
Just van Rossum <just@lettererror.com>
parents:
10105
diff
changeset
|
824 w.bind("cmd.", w.cancelbutton.push) |
|
fed66bddce63
added "Save options" menu to popup so users can set the creator of scripts -- jvr
Just van Rossum <just@lettererror.com>
parents:
10105
diff
changeset
|
825 w.open() |
|
fed66bddce63
added "Save options" menu to popup so users can set the creator of scripts -- jvr
Just van Rossum <just@lettererror.com>
parents:
10105
diff
changeset
|
826 |
|
fed66bddce63
added "Save options" menu to popup so users can set the creator of scripts -- jvr
Just van Rossum <just@lettererror.com>
parents:
10105
diff
changeset
|
827 def ide_hit(self): |
|
10705
4788fd070a30
- made "Save options..." dialog more generic, so it's also usable from RoboFog
Just van Rossum <just@lettererror.com>
parents:
10323
diff
changeset
|
828 self.w.other_creator.set(W._signature) |
|
10323
fed66bddce63
added "Save options" menu to popup so users can set the creator of scripts -- jvr
Just van Rossum <just@lettererror.com>
parents:
10105
diff
changeset
|
829 |
|
fed66bddce63
added "Save options" menu to popup so users can set the creator of scripts -- jvr
Just van Rossum <just@lettererror.com>
parents:
10105
diff
changeset
|
830 def interp_hit(self): |
|
fed66bddce63
added "Save options" menu to popup so users can set the creator of scripts -- jvr
Just van Rossum <just@lettererror.com>
parents:
10105
diff
changeset
|
831 self.w.other_creator.set("Pyth") |
|
fed66bddce63
added "Save options" menu to popup so users can set the creator of scripts -- jvr
Just van Rossum <just@lettererror.com>
parents:
10105
diff
changeset
|
832 |
|
22673
b96740c42e80
Completely revamped newline handling. PyEdit is now newline-preserving
Jack Jansen <jack.jansen@cwi.nl>
parents:
21868
diff
changeset
|
833 def interpx_hit(self): |
|
b96740c42e80
Completely revamped newline handling. PyEdit is now newline-preserving
Jack Jansen <jack.jansen@cwi.nl>
parents:
21868
diff
changeset
|
834 self.w.other_creator.set("PytX") |
|
b96740c42e80
Completely revamped newline handling. PyEdit is now newline-preserving
Jack Jansen <jack.jansen@cwi.nl>
parents:
21868
diff
changeset
|
835 |
|
b96740c42e80
Completely revamped newline handling. PyEdit is now newline-preserving
Jack Jansen <jack.jansen@cwi.nl>
parents:
21868
diff
changeset
|
836 def none_hit(self): |
|
b96740c42e80
Completely revamped newline handling. PyEdit is now newline-preserving
Jack Jansen <jack.jansen@cwi.nl>
parents:
21868
diff
changeset
|
837 self.w.other_creator.set("\0\0\0\0") |
|
b96740c42e80
Completely revamped newline handling. PyEdit is now newline-preserving
Jack Jansen <jack.jansen@cwi.nl>
parents:
21868
diff
changeset
|
838 |
|
10323
fed66bddce63
added "Save options" menu to popup so users can set the creator of scripts -- jvr
Just van Rossum <just@lettererror.com>
parents:
10105
diff
changeset
|
839 def otherselect(self, *args): |
|
fed66bddce63
added "Save options" menu to popup so users can set the creator of scripts -- jvr
Just van Rossum <just@lettererror.com>
parents:
10105
diff
changeset
|
840 sel_from, sel_to = self.w.other_creator.getselection() |
|
fed66bddce63
added "Save options" menu to popup so users can set the creator of scripts -- jvr
Just van Rossum <just@lettererror.com>
parents:
10105
diff
changeset
|
841 creator = self.w.other_creator.get()[:4] |
|
fed66bddce63
added "Save options" menu to popup so users can set the creator of scripts -- jvr
Just van Rossum <just@lettererror.com>
parents:
10105
diff
changeset
|
842 creator = creator + " " * (4 - len(creator)) |
|
fed66bddce63
added "Save options" menu to popup so users can set the creator of scripts -- jvr
Just van Rossum <just@lettererror.com>
parents:
10105
diff
changeset
|
843 self.w.other_creator.set(creator) |
|
fed66bddce63
added "Save options" menu to popup so users can set the creator of scripts -- jvr
Just van Rossum <just@lettererror.com>
parents:
10105
diff
changeset
|
844 self.w.other_creator.setselection(sel_from, sel_to) |
|
fed66bddce63
added "Save options" menu to popup so users can set the creator of scripts -- jvr
Just van Rossum <just@lettererror.com>
parents:
10105
diff
changeset
|
845 self.w.other_radio.set(1) |
|
fed66bddce63
added "Save options" menu to popup so users can set the creator of scripts -- jvr
Just van Rossum <just@lettererror.com>
parents:
10105
diff
changeset
|
846 |
|
22673
b96740c42e80
Completely revamped newline handling. PyEdit is now newline-preserving
Jack Jansen <jack.jansen@cwi.nl>
parents:
21868
diff
changeset
|
847 def mac_hit(self): |
|
b96740c42e80
Completely revamped newline handling. PyEdit is now newline-preserving
Jack Jansen <jack.jansen@cwi.nl>
parents:
21868
diff
changeset
|
848 self.eoln = '\r' |
|
b96740c42e80
Completely revamped newline handling. PyEdit is now newline-preserving
Jack Jansen <jack.jansen@cwi.nl>
parents:
21868
diff
changeset
|
849 |
|
b96740c42e80
Completely revamped newline handling. PyEdit is now newline-preserving
Jack Jansen <jack.jansen@cwi.nl>
parents:
21868
diff
changeset
|
850 def unix_hit(self): |
|
b96740c42e80
Completely revamped newline handling. PyEdit is now newline-preserving
Jack Jansen <jack.jansen@cwi.nl>
parents:
21868
diff
changeset
|
851 self.eoln = '\n' |
|
b96740c42e80
Completely revamped newline handling. PyEdit is now newline-preserving
Jack Jansen <jack.jansen@cwi.nl>
parents:
21868
diff
changeset
|
852 |
|
b96740c42e80
Completely revamped newline handling. PyEdit is now newline-preserving
Jack Jansen <jack.jansen@cwi.nl>
parents:
21868
diff
changeset
|
853 def win_hit(self): |
|
b96740c42e80
Completely revamped newline handling. PyEdit is now newline-preserving
Jack Jansen <jack.jansen@cwi.nl>
parents:
21868
diff
changeset
|
854 self.eoln = '\r\n' |
|
b96740c42e80
Completely revamped newline handling. PyEdit is now newline-preserving
Jack Jansen <jack.jansen@cwi.nl>
parents:
21868
diff
changeset
|
855 |
|
10323
fed66bddce63
added "Save options" menu to popup so users can set the creator of scripts -- jvr
Just van Rossum <just@lettererror.com>
parents:
10105
diff
changeset
|
856 def cancelbuttonhit(self): |
|
fed66bddce63
added "Save options" menu to popup so users can set the creator of scripts -- jvr
Just van Rossum <just@lettererror.com>
parents:
10105
diff
changeset
|
857 self.w.close() |
|
fed66bddce63
added "Save options" menu to popup so users can set the creator of scripts -- jvr
Just van Rossum <just@lettererror.com>
parents:
10105
diff
changeset
|
858 |
|
fed66bddce63
added "Save options" menu to popup so users can set the creator of scripts -- jvr
Just van Rossum <just@lettererror.com>
parents:
10105
diff
changeset
|
859 def okbuttonhit(self): |
|
22673
b96740c42e80
Completely revamped newline handling. PyEdit is now newline-preserving
Jack Jansen <jack.jansen@cwi.nl>
parents:
21868
diff
changeset
|
860 self.rv = (self.w.other_creator.get()[:4], self.eoln) |
|
10323
fed66bddce63
added "Save options" menu to popup so users can set the creator of scripts -- jvr
Just van Rossum <just@lettererror.com>
parents:
10105
diff
changeset
|
861 self.w.close() |
|
fed66bddce63
added "Save options" menu to popup so users can set the creator of scripts -- jvr
Just van Rossum <just@lettererror.com>
parents:
10105
diff
changeset
|
862 |
|
fed66bddce63
added "Save options" menu to popup so users can set the creator of scripts -- jvr
Just van Rossum <just@lettererror.com>
parents:
10105
diff
changeset
|
863 |
|
22673
b96740c42e80
Completely revamped newline handling. PyEdit is now newline-preserving
Jack Jansen <jack.jansen@cwi.nl>
parents:
21868
diff
changeset
|
864 def SaveOptions(creator, eoln): |
|
b96740c42e80
Completely revamped newline handling. PyEdit is now newline-preserving
Jack Jansen <jack.jansen@cwi.nl>
parents:
21868
diff
changeset
|
865 s = _saveoptions(creator, eoln) |
|
10323
fed66bddce63
added "Save options" menu to popup so users can set the creator of scripts -- jvr
Just van Rossum <just@lettererror.com>
parents:
10105
diff
changeset
|
866 return s.rv |
|
fed66bddce63
added "Save options" menu to popup so users can set the creator of scripts -- jvr
Just van Rossum <just@lettererror.com>
parents:
10105
diff
changeset
|
867 |
| 10047 | 868 |
| 869 def _escape(where, what) : | |
| 870 return string.join(string.split(where, what), '\\' + what) | |
| 871 | |
| 872 def _makewholewordpattern(word): | |
| 873 # first, escape special regex chars | |
|
18453
e78a51268c81
- fixed some re usage, partly so it'll still work when re uses pre instead
Just van Rossum <just@letterror.com>
parents:
18390
diff
changeset
|
874 for esc in "\\[]()|.*^+$?": |
| 10047 | 875 word = _escape(word, esc) |
| 876 notwordcharspat = '[^' + _wordchars + ']' | |
|
16725
d170c1e772c5
Use re in stead of regex, so we get rid of the annoying warning during startup.
Jack Jansen <jack.jansen@cwi.nl>
parents:
16344
diff
changeset
|
877 pattern = '(' + word + ')' |
| 10047 | 878 if word[0] in _wordchars: |
| 879 pattern = notwordcharspat + pattern | |
| 880 if word[-1] in _wordchars: | |
| 881 pattern = pattern + notwordcharspat | |
|
16725
d170c1e772c5
Use re in stead of regex, so we get rid of the annoying warning during startup.
Jack Jansen <jack.jansen@cwi.nl>
parents:
16344
diff
changeset
|
882 return re.compile(pattern) |
| 10047 | 883 |
|
21013
41b8d66730d6
a whole bunch of OSX tweaks
Just van Rossum <just@letterror.com>
parents:
20852
diff
changeset
|
884 |
| 10047 | 885 class SearchEngine: |
| 886 | |
| 887 def __init__(self): | |
| 888 self.visible = 0 | |
| 889 self.w = None | |
| 890 self.parms = { "find": "", | |
| 891 "replace": "", | |
| 892 "wrap": 1, | |
| 893 "casesens": 1, | |
| 894 "wholeword": 1 | |
| 895 } | |
| 896 import MacPrefs | |
| 897 prefs = MacPrefs.GetPrefs(W.getapplication().preffilepath) | |
| 898 if prefs.searchengine: | |
| 899 self.parms["casesens"] = prefs.searchengine.casesens | |
| 900 self.parms["wrap"] = prefs.searchengine.wrap | |
| 901 self.parms["wholeword"] = prefs.searchengine.wholeword | |
| 902 | |
| 903 def show(self): | |
| 904 self.visible = 1 | |
| 905 if self.w: | |
| 906 self.w.wid.ShowWindow() | |
| 907 self.w.wid.SelectWindow() | |
| 908 self.w.find.edit.select(1) | |
| 909 self.w.find.edit.selectall() | |
| 910 return | |
| 911 self.w = W.Dialog((420, 150), "Find") | |
| 912 | |
| 913 self.w.find = TitledEditText((10, 4, 300, 36), "Search for:") | |
| 914 self.w.replace = TitledEditText((10, 100, 300, 36), "Replace with:") | |
| 915 | |
| 916 self.w.boxes = W.Group((10, 50, 300, 40)) | |
| 917 self.w.boxes.casesens = W.CheckBox((0, 0, 100, 16), "Case sensitive") | |
| 918 self.w.boxes.wholeword = W.CheckBox((0, 20, 100, 16), "Whole word") | |
| 919 self.w.boxes.wrap = W.CheckBox((110, 0, 100, 16), "Wrap around") | |
| 920 | |
| 921 self.buttons = [ ("Find", "cmdf", self.find), | |
| 922 ("Replace", "cmdr", self.replace), | |
| 923 ("Replace all", None, self.replaceall), | |
|
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:
17961
diff
changeset
|
924 ("Don't find", "cmdd", self.dont), |
| 10047 | 925 ("Cancel", "cmd.", self.cancel) |
| 926 ] | |
| 927 for i in range(len(self.buttons)): | |
| 928 bounds = -90, 22 + i * 24, 80, 16 | |
| 929 title, shortcut, callback = self.buttons[i] | |
| 930 self.w[title] = W.Button(bounds, title, callback) | |
| 931 if shortcut: | |
| 932 self.w.bind(shortcut, self.w[title].push) | |
|
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:
17961
diff
changeset
|
933 self.w.setdefaultbutton(self.w["Don't find"]) |
| 10047 | 934 self.w.find.edit.bind("<key>", self.key) |
| 935 self.w.bind("<activate>", self.activate) | |
| 936 self.w.bind("<close>", self.close) | |
| 937 self.w.open() | |
| 938 self.setparms() | |
| 939 self.w.find.edit.select(1) | |
| 940 self.w.find.edit.selectall() | |
| 941 self.checkbuttons() | |
| 942 | |
| 943 def close(self): | |
| 944 self.hide() | |
| 945 return -1 | |
| 946 | |
| 947 def key(self, char, modifiers): | |
| 948 self.w.find.edit.key(char, modifiers) | |
| 949 self.checkbuttons() | |
| 950 return 1 | |
| 951 | |
| 952 def activate(self, onoff): | |
| 953 if onoff: | |
| 954 self.checkbuttons() | |
| 955 | |
| 956 def checkbuttons(self): | |
| 957 editor = findeditor(self) | |
| 958 if editor: | |
| 959 if self.w.find.get(): | |
| 960 for title, cmd, call in self.buttons[:-2]: | |
| 961 self.w[title].enable(1) | |
| 962 self.w.setdefaultbutton(self.w["Find"]) | |
| 963 else: | |
| 964 for title, cmd, call in self.buttons[:-2]: | |
| 965 self.w[title].enable(0) | |
|
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:
17961
diff
changeset
|
966 self.w.setdefaultbutton(self.w["Don't find"]) |
| 10047 | 967 else: |
| 968 for title, cmd, call in self.buttons[:-2]: | |
| 969 self.w[title].enable(0) | |
|
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:
17961
diff
changeset
|
970 self.w.setdefaultbutton(self.w["Don't find"]) |
| 10047 | 971 |
| 972 def find(self): | |
| 973 self.getparmsfromwindow() | |
| 974 if self.findnext(): | |
| 975 self.hide() | |
| 976 | |
| 977 def replace(self): | |
| 978 editor = findeditor(self) | |
| 979 if not editor: | |
| 980 return | |
| 981 if self.visible: | |
| 982 self.getparmsfromwindow() | |
| 983 text = editor.getselectedtext() | |
| 984 find = self.parms["find"] | |
| 985 if not self.parms["casesens"]: | |
| 986 find = string.lower(find) | |
| 987 text = string.lower(text) | |
| 988 if text == find: | |
| 989 self.hide() | |
| 990 editor.insert(self.parms["replace"]) | |
| 991 | |
| 992 def replaceall(self): | |
| 993 editor = findeditor(self) | |
| 994 if not editor: | |
| 995 return | |
| 996 if self.visible: | |
| 997 self.getparmsfromwindow() | |
| 998 W.SetCursor("watch") | |
| 999 find = self.parms["find"] | |
| 1000 if not find: | |
| 1001 return | |
| 1002 findlen = len(find) | |
| 1003 replace = self.parms["replace"] | |
| 1004 replacelen = len(replace) | |
| 1005 Text = editor.get() | |
| 1006 if not self.parms["casesens"]: | |
| 1007 find = string.lower(find) | |
| 1008 text = string.lower(Text) | |
| 1009 else: | |
| 1010 text = Text | |
| 1011 newtext = "" | |
| 1012 pos = 0 | |
| 1013 counter = 0 | |
| 1014 while 1: | |
| 1015 if self.parms["wholeword"]: | |
| 1016 wholewordRE = _makewholewordpattern(find) | |
|
16725
d170c1e772c5
Use re in stead of regex, so we get rid of the annoying warning during startup.
Jack Jansen <jack.jansen@cwi.nl>
parents:
16344
diff
changeset
|
1017 match = wholewordRE.search(text, pos) |
|
d170c1e772c5
Use re in stead of regex, so we get rid of the annoying warning during startup.
Jack Jansen <jack.jansen@cwi.nl>
parents:
16344
diff
changeset
|
1018 if match: |
|
d170c1e772c5
Use re in stead of regex, so we get rid of the annoying warning during startup.
Jack Jansen <jack.jansen@cwi.nl>
parents:
16344
diff
changeset
|
1019 pos = match.start(1) |
| 10047 | 1020 else: |
| 1021 pos = -1 | |
| 1022 else: | |
| 1023 pos = string.find(text, find, pos) | |
| 1024 if pos < 0: | |
| 1025 break | |
| 1026 counter = counter + 1 | |
| 1027 text = text[:pos] + replace + text[pos + findlen:] | |
| 1028 Text = Text[:pos] + replace + Text[pos + findlen:] | |
| 1029 pos = pos + replacelen | |
| 1030 W.SetCursor("arrow") | |
| 1031 if counter: | |
| 1032 self.hide() | |
|
19488
42b2f1936254
Import the MacOS toolbox modules from the Carbon package.
Jack Jansen <jack.jansen@cwi.nl>
parents:
18781
diff
changeset
|
1033 from Carbon import Res |
|
20835
3fbd253dea5d
some support for syntax coloring, disabled for now
Just van Rossum <just@letterror.com>
parents:
19488
diff
changeset
|
1034 editor.textchanged() |
|
3fbd253dea5d
some support for syntax coloring, disabled for now
Just van Rossum <just@letterror.com>
parents:
19488
diff
changeset
|
1035 editor.selectionchanged() |
|
25903
03c3f610e054
'Replace all' in the find dialog didn't properly update the text view (it used to, though...). Fixed.
Just van Rossum <just@letterror.com>
parents:
24212
diff
changeset
|
1036 editor.set(Text) |
| 10047 | 1037 EasyDialogs.Message("Replaced %d occurrences" % counter) |
| 1038 | |
| 1039 def dont(self): | |
| 1040 self.getparmsfromwindow() | |
| 1041 self.hide() | |
| 1042 | |
| 1043 def replacefind(self): | |
| 1044 self.replace() | |
| 1045 self.findnext() | |
| 1046 | |
| 1047 def setfindstring(self): | |
| 1048 editor = findeditor(self) | |
| 1049 if not editor: | |
| 1050 return | |
| 1051 find = editor.getselectedtext() | |
| 1052 if not find: | |
| 1053 return | |
| 1054 self.parms["find"] = find | |
| 1055 if self.w: | |
| 1056 self.w.find.edit.set(self.parms["find"]) | |
| 1057 self.w.find.edit.selectall() | |
| 1058 | |
| 1059 def findnext(self): | |
| 1060 editor = findeditor(self) | |
| 1061 if not editor: | |
| 1062 return | |
| 1063 find = self.parms["find"] | |
| 1064 if not find: | |
| 1065 return | |
| 1066 text = editor.get() | |
| 1067 if not self.parms["casesens"]: | |
| 1068 find = string.lower(find) | |
| 1069 text = string.lower(text) | |
| 1070 selstart, selend = editor.getselection() | |
| 1071 selstart, selend = min(selstart, selend), max(selstart, selend) | |
| 1072 if self.parms["wholeword"]: | |
| 1073 wholewordRE = _makewholewordpattern(find) | |
|
16725
d170c1e772c5
Use re in stead of regex, so we get rid of the annoying warning during startup.
Jack Jansen <jack.jansen@cwi.nl>
parents:
16344
diff
changeset
|
1074 match = wholewordRE.search(text, selend) |
|
d170c1e772c5
Use re in stead of regex, so we get rid of the annoying warning during startup.
Jack Jansen <jack.jansen@cwi.nl>
parents:
16344
diff
changeset
|
1075 if match: |
|
d170c1e772c5
Use re in stead of regex, so we get rid of the annoying warning during startup.
Jack Jansen <jack.jansen@cwi.nl>
parents:
16344
diff
changeset
|
1076 pos = match.start(1) |
| 10047 | 1077 else: |
| 1078 pos = -1 | |
| 1079 else: | |
| 1080 pos = string.find(text, find, selend) | |
| 1081 if pos >= 0: | |
| 1082 editor.setselection(pos, pos + len(find)) | |
| 1083 return 1 | |
| 1084 elif self.parms["wrap"]: | |
| 1085 if self.parms["wholeword"]: | |
|
16725
d170c1e772c5
Use re in stead of regex, so we get rid of the annoying warning during startup.
Jack Jansen <jack.jansen@cwi.nl>
parents:
16344
diff
changeset
|
1086 match = wholewordRE.search(text, 0) |
|
d170c1e772c5
Use re in stead of regex, so we get rid of the annoying warning during startup.
Jack Jansen <jack.jansen@cwi.nl>
parents:
16344
diff
changeset
|
1087 if match: |
|
d170c1e772c5
Use re in stead of regex, so we get rid of the annoying warning during startup.
Jack Jansen <jack.jansen@cwi.nl>
parents:
16344
diff
changeset
|
1088 pos = match.start(1) |
| 10047 | 1089 else: |
| 1090 pos = -1 | |
| 1091 else: | |
| 1092 pos = string.find(text, find) | |
| 1093 if selstart > pos >= 0: | |
| 1094 editor.setselection(pos, pos + len(find)) | |
| 1095 return 1 | |
| 1096 | |
| 1097 def setparms(self): | |
| 1098 for key, value in self.parms.items(): | |
| 1099 try: | |
| 1100 self.w[key].set(value) | |
| 1101 except KeyError: | |
| 1102 self.w.boxes[key].set(value) | |
| 1103 | |
| 1104 def getparmsfromwindow(self): | |
| 1105 if not self.w: | |
| 1106 return | |
| 1107 for key, value in self.parms.items(): | |
| 1108 try: | |
| 1109 value = self.w[key].get() | |
| 1110 except KeyError: | |
| 1111 value = self.w.boxes[key].get() | |
| 1112 self.parms[key] = value | |
| 1113 | |
| 1114 def cancel(self): | |
| 1115 self.hide() | |
| 1116 self.setparms() | |
| 1117 | |
| 1118 def hide(self): | |
| 1119 if self.w: | |
| 1120 self.w.wid.HideWindow() | |
| 1121 self.visible = 0 | |
| 1122 | |
| 1123 def writeprefs(self): | |
| 1124 import MacPrefs | |
| 1125 self.getparmsfromwindow() | |
| 1126 prefs = MacPrefs.GetPrefs(W.getapplication().preffilepath) | |
| 1127 prefs.searchengine.casesens = self.parms["casesens"] | |
| 1128 prefs.searchengine.wrap = self.parms["wrap"] | |
| 1129 prefs.searchengine.wholeword = self.parms["wholeword"] | |
| 1130 prefs.save() | |
| 1131 | |
| 1132 | |
| 1133 class TitledEditText(W.Group): | |
| 1134 | |
| 1135 def __init__(self, possize, title, text = ""): | |
| 1136 W.Group.__init__(self, possize) | |
| 1137 self.title = W.TextBox((0, 0, 0, 16), title) | |
| 1138 self.edit = W.EditText((0, 16, 0, 0), text) | |
| 1139 | |
| 1140 def set(self, value): | |
| 1141 self.edit.set(value) | |
| 1142 | |
| 1143 def get(self): | |
| 1144 return self.edit.get() | |
| 1145 | |
| 1146 | |
| 1147 class ClassFinder(W.PopupWidget): | |
| 1148 | |
| 1149 def click(self, point, modifiers): | |
| 1150 W.SetCursor("watch") | |
| 1151 self.set(self._parentwindow.getclasslist()) | |
| 1152 W.PopupWidget.click(self, point, modifiers) | |
| 1153 | |
| 1154 | |
| 1155 def getminindent(lines): | |
| 1156 indent = -1 | |
| 1157 for line in lines: | |
| 1158 stripped = string.strip(line) | |
| 1159 if not stripped or stripped[0] == '#': | |
| 1160 continue | |
| 1161 if indent < 0 or line[:indent] <> indent * '\t': | |
| 1162 indent = 0 | |
| 1163 for c in line: | |
| 1164 if c <> '\t': | |
| 1165 break | |
| 1166 indent = indent + 1 | |
| 1167 return indent | |
| 1168 | |
| 1169 | |
| 1170 def getoptionkey(): | |
| 1171 return not not ord(Evt.GetKeys()[7]) & 0x04 | |
| 1172 | |
| 1173 | |
| 1174 def execstring(pytext, globals, locals, filename="<string>", debugging=0, | |
| 1175 modname="__main__", profiling=0): | |
| 1176 if debugging: | |
| 1177 import PyDebugger, bdb | |
| 1178 BdbQuit = bdb.BdbQuit | |
| 1179 else: | |
| 1180 BdbQuit = 'BdbQuitDummyException' | |
| 1181 pytext = string.split(pytext, '\r') | |
| 1182 pytext = string.join(pytext, '\n') + '\n' | |
| 1183 W.SetCursor("watch") | |
| 1184 globals['__name__'] = modname | |
| 1185 globals['__file__'] = filename | |
| 1186 sys.argv = [filename] | |
| 1187 try: | |
| 1188 code = compile(pytext, filename, "exec") | |
| 1189 except: | |
| 1190 # XXXX BAAAADDD.... We let tracebackwindow decide to treat SyntaxError | |
| 1191 # special. That's wrong because THIS case is special (could be literal | |
| 1192 # overflow!) and SyntaxError could mean we need a traceback (syntax error | |
| 1193 # in imported module!!! | |
| 1194 tracebackwindow.traceback(1, filename) | |
| 1195 return | |
| 1196 try: | |
| 1197 if debugging: | |
|
15283
4c7c779bad87
Hm, I never checked in my incomplete "run with interpreter" mods. UI is there (but is disabled), functionality is not there.
Just van Rossum <just@lettererror.com>
parents:
12972
diff
changeset
|
1198 if haveThreading: |
|
4c7c779bad87
Hm, I never checked in my incomplete "run with interpreter" mods. UI is there (but is disabled), functionality is not there.
Just van Rossum <just@lettererror.com>
parents:
12972
diff
changeset
|
1199 lock = Wthreading.Lock() |
|
4c7c779bad87
Hm, I never checked in my incomplete "run with interpreter" mods. UI is there (but is disabled), functionality is not there.
Just van Rossum <just@lettererror.com>
parents:
12972
diff
changeset
|
1200 lock.acquire() |
|
12308
ddc4e62b216b
added experimental microthread support for use with stackless python -- bw compatible (jvr)
Just van Rossum <just@lettererror.com>
parents:
11629
diff
changeset
|
1201 PyDebugger.startfromhere() |
|
15283
4c7c779bad87
Hm, I never checked in my incomplete "run with interpreter" mods. UI is there (but is disabled), functionality is not there.
Just van Rossum <just@lettererror.com>
parents:
12972
diff
changeset
|
1202 lock.release() |
|
12308
ddc4e62b216b
added experimental microthread support for use with stackless python -- bw compatible (jvr)
Just van Rossum <just@lettererror.com>
parents:
11629
diff
changeset
|
1203 else: |
|
ddc4e62b216b
added experimental microthread support for use with stackless python -- bw compatible (jvr)
Just van Rossum <just@lettererror.com>
parents:
11629
diff
changeset
|
1204 PyDebugger.startfromhere() |
|
15283
4c7c779bad87
Hm, I never checked in my incomplete "run with interpreter" mods. UI is there (but is disabled), functionality is not there.
Just van Rossum <just@lettererror.com>
parents:
12972
diff
changeset
|
1205 elif not haveThreading: |
|
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:
21013
diff
changeset
|
1206 if hasattr(MacOS, 'EnableAppswitch'): |
|
ec750e37671b
Changes by Donovan Preston (and a few minor ones by me) to make IDE run under
Jack Jansen <jack.jansen@cwi.nl>
parents:
21013
diff
changeset
|
1207 MacOS.EnableAppswitch(0) |
| 10047 | 1208 try: |
| 1209 if profiling: | |
| 1210 import profile, ProfileBrowser | |
| 1211 p = profile.Profile() | |
| 1212 p.set_cmd(filename) | |
| 1213 try: | |
| 1214 p.runctx(code, globals, locals) | |
| 1215 finally: | |
| 1216 import pstats | |
| 1217 | |
| 1218 stats = pstats.Stats(p) | |
| 1219 ProfileBrowser.ProfileBrowser(stats) | |
| 1220 else: | |
| 1221 exec code in globals, locals | |
| 1222 finally: | |
|
15283
4c7c779bad87
Hm, I never checked in my incomplete "run with interpreter" mods. UI is there (but is disabled), functionality is not there.
Just van Rossum <just@lettererror.com>
parents:
12972
diff
changeset
|
1223 if not haveThreading: |
|
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:
21013
diff
changeset
|
1224 if hasattr(MacOS, 'EnableAppswitch'): |
|
ec750e37671b
Changes by Donovan Preston (and a few minor ones by me) to make IDE run under
Jack Jansen <jack.jansen@cwi.nl>
parents:
21013
diff
changeset
|
1225 MacOS.EnableAppswitch(-1) |
| 10047 | 1226 except W.AlertError, detail: |
| 1227 raise W.AlertError, detail | |
| 1228 except (KeyboardInterrupt, BdbQuit): | |
| 1229 pass | |
|
20835
3fbd253dea5d
some support for syntax coloring, disabled for now
Just van Rossum <just@letterror.com>
parents:
19488
diff
changeset
|
1230 except SystemExit, arg: |
|
3fbd253dea5d
some support for syntax coloring, disabled for now
Just van Rossum <just@letterror.com>
parents:
19488
diff
changeset
|
1231 if arg.code: |
|
3fbd253dea5d
some support for syntax coloring, disabled for now
Just van Rossum <just@letterror.com>
parents:
19488
diff
changeset
|
1232 sys.stderr.write("Script exited with status code: %s\n" % repr(arg.code)) |
| 10047 | 1233 except: |
|
15283
4c7c779bad87
Hm, I never checked in my incomplete "run with interpreter" mods. UI is there (but is disabled), functionality is not there.
Just van Rossum <just@lettererror.com>
parents:
12972
diff
changeset
|
1234 if haveThreading: |
|
4c7c779bad87
Hm, I never checked in my incomplete "run with interpreter" mods. UI is there (but is disabled), functionality is not there.
Just van Rossum <just@lettererror.com>
parents:
12972
diff
changeset
|
1235 import continuation |
|
4c7c779bad87
Hm, I never checked in my incomplete "run with interpreter" mods. UI is there (but is disabled), functionality is not there.
Just van Rossum <just@lettererror.com>
parents:
12972
diff
changeset
|
1236 lock = Wthreading.Lock() |
|
4c7c779bad87
Hm, I never checked in my incomplete "run with interpreter" mods. UI is there (but is disabled), functionality is not there.
Just van Rossum <just@lettererror.com>
parents:
12972
diff
changeset
|
1237 lock.acquire() |
| 10047 | 1238 if debugging: |
| 1239 sys.settrace(None) | |
| 1240 PyDebugger.postmortem(sys.exc_type, sys.exc_value, sys.exc_traceback) | |
| 1241 return | |
| 1242 else: | |
| 1243 tracebackwindow.traceback(1, filename) | |
|
15283
4c7c779bad87
Hm, I never checked in my incomplete "run with interpreter" mods. UI is there (but is disabled), functionality is not there.
Just van Rossum <just@lettererror.com>
parents:
12972
diff
changeset
|
1244 if haveThreading: |
|
4c7c779bad87
Hm, I never checked in my incomplete "run with interpreter" mods. UI is there (but is disabled), functionality is not there.
Just van Rossum <just@lettererror.com>
parents:
12972
diff
changeset
|
1245 lock.release() |
| 10047 | 1246 if debugging: |
| 1247 sys.settrace(None) | |
| 1248 PyDebugger.stop() | |
| 1249 | |
| 1250 | |
|
18453
e78a51268c81
- fixed some re usage, partly so it'll still work when re uses pre instead
Just van Rossum <just@letterror.com>
parents:
18390
diff
changeset
|
1251 _identifieRE = re.compile(r"[A-Za-z_][A-Za-z_0-9]*") |
|
16725
d170c1e772c5
Use re in stead of regex, so we get rid of the annoying warning during startup.
Jack Jansen <jack.jansen@cwi.nl>
parents:
16344
diff
changeset
|
1252 |
|
d170c1e772c5
Use re in stead of regex, so we get rid of the annoying warning during startup.
Jack Jansen <jack.jansen@cwi.nl>
parents:
16344
diff
changeset
|
1253 def identifieRE_match(str): |
|
d170c1e772c5
Use re in stead of regex, so we get rid of the annoying warning during startup.
Jack Jansen <jack.jansen@cwi.nl>
parents:
16344
diff
changeset
|
1254 match = _identifieRE.match(str) |
|
d170c1e772c5
Use re in stead of regex, so we get rid of the annoying warning during startup.
Jack Jansen <jack.jansen@cwi.nl>
parents:
16344
diff
changeset
|
1255 if not match: |
|
d170c1e772c5
Use re in stead of regex, so we get rid of the annoying warning during startup.
Jack Jansen <jack.jansen@cwi.nl>
parents:
16344
diff
changeset
|
1256 return -1 |
|
d170c1e772c5
Use re in stead of regex, so we get rid of the annoying warning during startup.
Jack Jansen <jack.jansen@cwi.nl>
parents:
16344
diff
changeset
|
1257 return match.end() |
| 10047 | 1258 |
| 1259 def _filename_as_modname(fname): | |
| 1260 if fname[-3:] == '.py': | |
| 1261 modname = fname[:-3] | |
|
16725
d170c1e772c5
Use re in stead of regex, so we get rid of the annoying warning during startup.
Jack Jansen <jack.jansen@cwi.nl>
parents:
16344
diff
changeset
|
1262 match = _identifieRE.match(modname) |
|
d170c1e772c5
Use re in stead of regex, so we get rid of the annoying warning during startup.
Jack Jansen <jack.jansen@cwi.nl>
parents:
16344
diff
changeset
|
1263 if match and match.start() == 0 and match.end() == len(modname): |
| 10047 | 1264 return string.join(string.split(modname, '.'), '_') |
| 1265 | |
| 1266 def findeditor(topwindow, fromtop = 0): | |
|
21868
3cd0b4bb5e34
Added minimal support for floating windows.
Just van Rossum <just@letterror.com>
parents:
21772
diff
changeset
|
1267 wid = MyFrontWindow() |
| 10047 | 1268 if not fromtop: |
| 1269 if topwindow.w and wid == topwindow.w.wid: | |
| 1270 wid = topwindow.w.wid.GetNextWindow() | |
| 1271 if not wid: | |
| 1272 return | |
| 1273 app = W.getapplication() | |
| 1274 if app._windows.has_key(wid): # KeyError otherwise can happen in RoboFog :-( | |
| 1275 window = W.getapplication()._windows[wid] | |
| 1276 else: | |
| 1277 return | |
| 1278 if not isinstance(window, Editor): | |
| 1279 return | |
| 1280 return window.editgroup.editor | |
| 1281 | |
| 1282 | |
| 1283 class _EditorDefaultSettings: | |
| 1284 | |
| 1285 def __init__(self): | |
| 1286 self.template = "%s, %d point" | |
| 1287 self.fontsettings, self.tabsettings, self.windowsize = geteditorprefs() | |
| 1288 self.w = W.Dialog((328, 120), "Editor default settings") | |
|
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:
17961
diff
changeset
|
1289 self.w.setfontbutton = W.Button((8, 8, 80, 16), "Set font\xc9", self.dofont) |
| 10047 | 1290 self.w.fonttext = W.TextBox((98, 10, -8, 14), self.template % (self.fontsettings[0], self.fontsettings[2])) |
| 1291 | |
| 1292 self.w.picksizebutton = W.Button((8, 50, 80, 16), "Front window", self.picksize) | |
| 1293 self.w.xsizelabel = W.TextBox((98, 32, 40, 14), "Width:") | |
| 1294 self.w.ysizelabel = W.TextBox((148, 32, 40, 14), "Height:") | |
| 1295 self.w.xsize = W.EditText((98, 48, 40, 20), `self.windowsize[0]`) | |
| 1296 self.w.ysize = W.EditText((148, 48, 40, 20), `self.windowsize[1]`) | |
| 1297 | |
| 1298 self.w.cancelbutton = W.Button((-180, -26, 80, 16), "Cancel", self.cancel) | |
| 1299 self.w.okbutton = W.Button((-90, -26, 80, 16), "Done", self.ok) | |
| 1300 self.w.setdefaultbutton(self.w.okbutton) | |
| 1301 self.w.bind('cmd.', self.w.cancelbutton.push) | |
| 1302 self.w.open() | |
| 1303 | |
| 1304 def picksize(self): | |
| 1305 app = W.getapplication() | |
| 1306 editor = findeditor(self) | |
| 1307 if editor is not None: | |
| 1308 width, height = editor._parentwindow._bounds[2:] | |
| 1309 self.w.xsize.set(`width`) | |
| 1310 self.w.ysize.set(`height`) | |
| 1311 else: | |
| 1312 raise W.AlertError, "No edit window found" | |
| 1313 | |
| 1314 def dofont(self): | |
| 1315 import FontSettings | |
| 1316 settings = FontSettings.FontDialog(self.fontsettings, self.tabsettings) | |
| 1317 if settings: | |
| 1318 self.fontsettings, self.tabsettings = settings | |
| 1319 sys.exc_traceback = None | |
| 1320 self.w.fonttext.set(self.template % (self.fontsettings[0], self.fontsettings[2])) | |
| 1321 | |
| 1322 def close(self): | |
| 1323 self.w.close() | |
| 1324 del self.w | |
| 1325 | |
| 1326 def cancel(self): | |
| 1327 self.close() | |
| 1328 | |
| 1329 def ok(self): | |
| 1330 try: | |
| 1331 width = string.atoi(self.w.xsize.get()) | |
| 1332 except: | |
| 1333 self.w.xsize.select(1) | |
| 1334 self.w.xsize.selectall() | |
| 1335 raise W.AlertError, "Bad number for window width" | |
| 1336 try: | |
| 1337 height = string.atoi(self.w.ysize.get()) | |
| 1338 except: | |
| 1339 self.w.ysize.select(1) | |
| 1340 self.w.ysize.selectall() | |
| 1341 raise W.AlertError, "Bad number for window height" | |
| 1342 self.windowsize = width, height | |
| 1343 seteditorprefs(self.fontsettings, self.tabsettings, self.windowsize) | |
| 1344 self.close() | |
| 1345 | |
| 1346 def geteditorprefs(): | |
| 1347 import MacPrefs | |
| 1348 prefs = MacPrefs.GetPrefs(W.getapplication().preffilepath) | |
| 1349 try: | |
| 1350 fontsettings = prefs.pyedit.fontsettings | |
| 1351 tabsettings = prefs.pyedit.tabsettings | |
| 1352 windowsize = prefs.pyedit.windowsize | |
| 1353 except: | |
|
20835
3fbd253dea5d
some support for syntax coloring, disabled for now
Just van Rossum <just@letterror.com>
parents:
19488
diff
changeset
|
1354 fontsettings = prefs.pyedit.fontsettings = ("Geneva", 0, 10, (0, 0, 0)) |
| 10047 | 1355 tabsettings = prefs.pyedit.tabsettings = (8, 1) |
| 1356 windowsize = prefs.pyedit.windowsize = (500, 250) | |
| 1357 sys.exc_traceback = None | |
| 1358 return fontsettings, tabsettings, windowsize | |
| 1359 | |
| 1360 def seteditorprefs(fontsettings, tabsettings, windowsize): | |
| 1361 import MacPrefs | |
| 1362 prefs = MacPrefs.GetPrefs(W.getapplication().preffilepath) | |
| 1363 prefs.pyedit.fontsettings = fontsettings | |
| 1364 prefs.pyedit.tabsettings = tabsettings | |
| 1365 prefs.pyedit.windowsize = windowsize | |
| 1366 prefs.save() | |
| 1367 | |
| 1368 _defaultSettingsEditor = None | |
| 1369 | |
| 1370 def EditorDefaultSettings(): | |
| 1371 global _defaultSettingsEditor | |
| 1372 if _defaultSettingsEditor is None or not hasattr(_defaultSettingsEditor, "w"): | |
| 1373 _defaultSettingsEditor = _EditorDefaultSettings() | |
| 1374 else: | |
| 1375 _defaultSettingsEditor.w.select() | |
| 1376 | |
| 1377 def resolvealiases(path): | |
| 1378 try: | |
|
27737
4367f805db09
Got rid of macfs and FSSpecs in general (pathnames or FSRefs are now
Jack Jansen <jack.jansen@cwi.nl>
parents:
27408
diff
changeset
|
1379 fsr, d1, d2 = File.FSResolveAliasFile(path, 1) |
|
4367f805db09
Got rid of macfs and FSSpecs in general (pathnames or FSRefs are now
Jack Jansen <jack.jansen@cwi.nl>
parents:
27408
diff
changeset
|
1380 path = fsr.as_pathname() |
|
4367f805db09
Got rid of macfs and FSSpecs in general (pathnames or FSRefs are now
Jack Jansen <jack.jansen@cwi.nl>
parents:
27408
diff
changeset
|
1381 return path |
|
4367f805db09
Got rid of macfs and FSSpecs in general (pathnames or FSRefs are now
Jack Jansen <jack.jansen@cwi.nl>
parents:
27408
diff
changeset
|
1382 except (File.Error, ValueError), (error, str): |
| 10047 | 1383 if error <> -120: |
| 1384 raise | |
| 1385 dir, file = os.path.split(path) | |
| 1386 return os.path.join(resolvealiases(dir), file) | |
| 1387 | |
| 1388 searchengine = SearchEngine() | |
| 1389 tracebackwindow = Wtraceback.TraceBack() |
