Mercurial > cpython-lru_cache-weakref
annotate Mac/Tools/IDE/PyConsole.py @ 27408:ea5ee3e7bfb1 legacy-trunk
Use new file dialogs.
| author | Jack Jansen <jack.jansen@cwi.nl> |
|---|---|
| date | Sun, 26 Jan 2003 22:15:48 +0000 |
| parents | 9220098f0327 |
| children | 4367f805db09 |
| rev | line source |
|---|---|
| 10047 | 1 import W |
| 2 import Wkeys | |
|
19488
42b2f1936254
Import the MacOS toolbox modules from the Carbon package.
Jack Jansen <jack.jansen@cwi.nl>
parents:
19009
diff
changeset
|
3 from Carbon import Fm |
| 10047 | 4 import WASTEconst |
| 5 from types import * | |
|
19488
42b2f1936254
Import the MacOS toolbox modules from the Carbon package.
Jack Jansen <jack.jansen@cwi.nl>
parents:
19009
diff
changeset
|
6 from Carbon import Events |
| 10047 | 7 import string |
| 8 import sys | |
| 9 import traceback | |
| 10 import MacOS | |
| 11 import MacPrefs | |
|
19488
42b2f1936254
Import the MacOS toolbox modules from the Carbon package.
Jack Jansen <jack.jansen@cwi.nl>
parents:
19009
diff
changeset
|
12 from Carbon import Qd |
| 27408 | 13 import EasyDialogs |
| 10047 | 14 import PyInteractive |
| 15 | |
| 16 if not hasattr(sys, 'ps1'): | |
| 17 sys.ps1 = '>>> ' | |
| 18 if not hasattr(sys, 'ps2'): | |
| 19 sys.ps2 = '... ' | |
| 20 | |
| 21 def inspect(foo): # JJS 1/25/99 | |
| 22 "Launch the browser on the given object. This is a general built-in function." | |
| 23 import PyBrowser | |
| 24 PyBrowser.Browser(foo) | |
| 25 | |
| 26 class ConsoleTextWidget(W.EditText): | |
| 27 | |
| 28 def __init__(self, *args, **kwargs): | |
| 29 apply(W.EditText.__init__, (self,) + args, kwargs) | |
| 30 self._inputstart = 0 | |
| 31 self._buf = '' | |
| 32 self.pyinteractive = PyInteractive.PyInteractive() | |
| 33 | |
| 34 import __main__ | |
| 35 self._namespace = __main__.__dict__ | |
| 36 self._namespace['inspect'] = inspect # JJS 1/25/99 | |
| 37 | |
| 38 def insert(self, text): | |
| 39 self.checkselection() | |
| 40 self.ted.WEInsert(text, None, None) | |
| 41 self.changed = 1 | |
| 42 self.selchanged = 1 | |
| 43 | |
| 44 def set_namespace(self, dict): | |
| 45 if type(dict) <> DictionaryType: | |
| 46 raise TypeError, "The namespace needs to be a dictionary" | |
| 47 if 'inspect' not in dict.keys(): dict['inspect'] = inspect # JJS 1/25/99 | |
| 48 self._namespace = dict | |
| 49 | |
| 50 def open(self): | |
|
19009
1bc67cf57d0a
Show the MacPython IDE version in the interactive banner.
Just van Rossum <just@letterror.com>
parents:
18167
diff
changeset
|
51 import __main__ |
| 10047 | 52 W.EditText.open(self) |
|
19009
1bc67cf57d0a
Show the MacPython IDE version in the interactive banner.
Just van Rossum <just@letterror.com>
parents:
18167
diff
changeset
|
53 self.write('Python %s\n' % sys.version) |
|
1bc67cf57d0a
Show the MacPython IDE version in the interactive banner.
Just van Rossum <just@letterror.com>
parents:
18167
diff
changeset
|
54 self.write('Type "copyright", "credits" or "license" for more information.\n') |
|
1bc67cf57d0a
Show the MacPython IDE version in the interactive banner.
Just van Rossum <just@letterror.com>
parents:
18167
diff
changeset
|
55 self.write('MacPython IDE %s\n' % __main__.__version__) |
| 10047 | 56 self.write(sys.ps1) |
| 57 self.flush() | |
| 58 | |
| 59 def key(self, char, event): | |
| 60 (what, message, when, where, modifiers) = event | |
| 61 if self._enabled and not modifiers & Events.cmdKey or char in Wkeys.arrowkeys: | |
| 62 if char not in Wkeys.navigationkeys: | |
| 63 self.checkselection() | |
| 64 if char == Wkeys.enterkey: | |
| 65 char = Wkeys.returnkey | |
| 66 selstart, selend = self.getselection() | |
| 67 if char == Wkeys.backspacekey: | |
| 68 if selstart <= (self._inputstart - (selstart <> selend)): | |
| 69 return | |
| 70 self.ted.WEKey(ord(char), modifiers) | |
| 71 if char not in Wkeys.navigationkeys: | |
| 72 self.changed = 1 | |
| 73 if char not in Wkeys.scrollkeys: | |
| 74 self.selchanged = 1 | |
| 75 self.updatescrollbars() | |
| 76 if char == Wkeys.returnkey: | |
| 77 text = self.get()[self._inputstart:selstart] | |
| 78 text = string.join(string.split(text, "\r"), "\n") | |
|
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:
21549
diff
changeset
|
79 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:
21549
diff
changeset
|
80 saveyield = MacOS.EnableAppswitch(0) |
| 10047 | 81 self.pyinteractive.executeline(text, self, self._namespace) |
|
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:
21549
diff
changeset
|
82 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:
21549
diff
changeset
|
83 MacOS.EnableAppswitch(saveyield) |
| 10047 | 84 selstart, selend = self.getselection() |
| 85 self._inputstart = selstart | |
| 86 | |
| 87 def domenu_save_as(self, *args): | |
| 88 import macfs | |
| 27408 | 89 filename = EasyDialogs.AskFileForSave(message='Save console text as:', |
| 90 savedFileName='console.txt') | |
| 91 if not filename: | |
| 10047 | 92 return |
| 27408 | 93 f = open(filename, 'wb') |
| 10047 | 94 f.write(self.get()) |
| 95 f.close() | |
| 96 fss.SetCreatorType(W._signature, 'TEXT') | |
| 97 | |
| 98 def write(self, text): | |
| 99 self._buf = self._buf + text | |
| 100 if '\n' in self._buf: | |
| 101 self.flush() | |
| 102 | |
| 103 def flush(self): | |
| 104 stuff = string.split(self._buf, '\n') | |
| 105 stuff = string.join(stuff, '\r') | |
| 106 self.setselection_at_end() | |
| 107 self.ted.WEInsert(stuff, None, None) | |
| 108 selstart, selend = self.getselection() | |
| 109 self._inputstart = selstart | |
| 110 self._buf = "" | |
| 111 self.ted.WEClearUndo() | |
| 112 self.updatescrollbars() | |
|
26466
418a7ec92599
Lots of minor tweaks for the pep252 checkins, mainly because Qd
Jack Jansen <jack.jansen@cwi.nl>
parents:
21866
diff
changeset
|
113 if self._parentwindow.wid.GetWindowPort().QDIsPortBuffered(): |
|
418a7ec92599
Lots of minor tweaks for the pep252 checkins, mainly because Qd
Jack Jansen <jack.jansen@cwi.nl>
parents:
21866
diff
changeset
|
114 self._parentwindow.wid.GetWindowPort().QDFlushPortBuffer(None) |
| 10047 | 115 |
| 116 def selection_ok(self): | |
| 117 selstart, selend = self.getselection() | |
| 118 return not (selstart < self._inputstart or selend < self._inputstart) | |
| 119 | |
| 120 def checkselection(self): | |
| 121 if not self.selection_ok(): | |
| 122 self.setselection_at_end() | |
| 123 | |
| 124 def setselection_at_end(self): | |
| 125 end = self.ted.WEGetTextLength() | |
| 126 self.setselection(end, end) | |
| 127 self.updatescrollbars() | |
| 128 | |
| 129 def domenu_cut(self, *args): | |
| 130 if not self.selection_ok(): | |
| 131 return | |
| 132 W.EditText.domenu_cut(self) | |
| 133 | |
| 134 def domenu_paste(self, *args): | |
| 135 if not self.selection_ok(): | |
| 136 self.setselection_at_end() | |
| 137 W.EditText.domenu_paste(self) | |
| 138 | |
| 139 def domenu_clear(self, *args): | |
| 140 if not self.selection_ok(): | |
| 141 return | |
| 142 W.EditText.domenu_clear(self) | |
| 143 | |
| 144 | |
| 145 class PyConsole(W.Window): | |
| 146 | |
| 147 def __init__(self, bounds, show = 1, fontsettings = ("Monaco", 0, 9, (0, 0, 0)), | |
| 148 tabsettings = (32, 0), unclosable = 0): | |
| 149 W.Window.__init__(self, | |
| 150 bounds, | |
| 151 "Python Interactive", | |
| 152 minsize = (200, 100), | |
| 153 tabbable = 0, | |
| 154 show = show) | |
| 155 | |
| 156 self._unclosable = unclosable | |
| 157 consoletext = ConsoleTextWidget((-1, -1, -14, 1), inset = (6, 5), | |
| 158 fontsettings = fontsettings, tabsettings = tabsettings) | |
| 159 self._bary = W.Scrollbar((-15, 14, 16, -14), consoletext.vscroll, max = 32767) | |
| 160 self.consoletext = consoletext | |
| 161 self.namespacemenu = W.PopupMenu((-15, -1, 16, 16), [], self.consoletext.set_namespace) | |
| 162 self.namespacemenu.bind('<click>', self.makenamespacemenu) | |
| 163 self.open() | |
| 164 | |
| 165 def makenamespacemenu(self, *args): | |
| 166 W.SetCursor('watch') | |
| 167 namespacelist = self.getnamespacelist() | |
|
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:
17972
diff
changeset
|
168 self.namespacemenu.set([("Clear window", self.clearbuffer), ("Font settings\xc9", self.dofontsettings), |
|
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:
17972
diff
changeset
|
169 ["Namespace"] + namespacelist, ("Browse namespace\xc9", self.browsenamespace)]) |
| 10047 | 170 currentname = self.consoletext._namespace["__name__"] |
| 171 for i in range(len(namespacelist)): | |
| 172 if namespacelist[i][0] == currentname: | |
| 173 break | |
| 174 else: | |
| 175 return | |
| 176 # XXX this functionality should be generally available in Wmenus | |
| 177 submenuid = self.namespacemenu.menu.menu.GetItemMark(3) | |
| 178 menu = self.namespacemenu.menu.bar.menus[submenuid] | |
|
16336
2d8e02902d67
Replace {Enable,Disable,Check}Item with their carbon-compatible equivalents {Enable,Disable,Check}MenuItem.
Jack Jansen <jack.jansen@cwi.nl>
parents:
10087
diff
changeset
|
179 menu.menu.CheckMenuItem(i + 1, 1) |
| 10047 | 180 |
| 181 def browsenamespace(self): | |
| 182 import PyBrowser, W | |
| 183 W.SetCursor('watch') | |
| 184 PyBrowser.Browser(self.consoletext._namespace, self.consoletext._namespace["__name__"]) | |
| 185 | |
| 186 def clearbuffer(self): | |
|
19488
42b2f1936254
Import the MacOS toolbox modules from the Carbon package.
Jack Jansen <jack.jansen@cwi.nl>
parents:
19009
diff
changeset
|
187 from Carbon import Res |
| 10047 | 188 self.consoletext.ted.WEUseText(Res.Resource('')) |
| 189 self.consoletext.write(sys.ps1) | |
| 190 self.consoletext.flush() | |
| 191 | |
| 192 def getnamespacelist(self): | |
| 193 import os | |
| 194 import __main__ | |
| 195 editors = filter(lambda x: x.__class__.__name__ == "Editor", self.parent._windows.values()) | |
| 196 | |
| 197 namespaces = [ ("__main__",__main__.__dict__) ] | |
| 198 for ed in editors: | |
| 199 modname = os.path.splitext(ed.title)[0] | |
| 200 if sys.modules.has_key(modname): | |
| 201 module = sys.modules[modname] | |
| 202 namespaces.append((modname, module.__dict__)) | |
| 203 else: | |
| 204 if ed.title[-3:] == '.py': | |
| 205 modname = ed.title[:-3] | |
| 206 else: | |
| 207 modname = ed.title | |
| 208 ed.globals["__name__"] = modname | |
| 209 namespaces.append((modname, ed.globals)) | |
| 210 return namespaces | |
| 211 | |
| 212 def dofontsettings(self): | |
| 213 import FontSettings | |
| 214 settings = FontSettings.FontDialog(self.consoletext.getfontsettings(), | |
| 215 self.consoletext.gettabsettings()) | |
| 216 if settings: | |
| 217 fontsettings, tabsettings = settings | |
| 218 self.consoletext.setfontsettings(fontsettings) | |
| 219 self.consoletext.settabsettings(tabsettings) | |
| 220 | |
| 221 def show(self, onoff = 1): | |
| 222 W.Window.show(self, onoff) | |
| 223 if onoff: | |
| 224 self.select() | |
| 225 | |
| 226 def close(self): | |
| 227 if self._unclosable: | |
| 228 self.show(0) | |
| 229 return -1 | |
| 230 W.Window.close(self) | |
| 231 | |
| 232 def writeprefs(self): | |
| 233 prefs = MacPrefs.GetPrefs(W.getapplication().preffilepath) | |
| 234 prefs.console.show = self.isvisible() | |
| 235 prefs.console.windowbounds = self.getbounds() | |
| 236 prefs.console.fontsettings = self.consoletext.getfontsettings() | |
| 237 prefs.console.tabsettings = self.consoletext.gettabsettings() | |
| 238 prefs.save() | |
| 239 | |
| 240 | |
| 241 class OutputTextWidget(W.EditText): | |
| 242 | |
| 243 def domenu_save_as(self, *args): | |
| 244 title = self._parentwindow.gettitle() | |
| 245 import macfs | |
| 27408 | 246 filename = EasyDialogs.AskFileForSave(message='Save %s text as:' % title, |
| 247 savedFileName=title + '.txt') | |
| 248 if not filename: | |
| 10047 | 249 return |
| 27408 | 250 f = open(filename, 'wb') |
| 10047 | 251 f.write(self.get()) |
| 252 f.close() | |
| 253 fss.SetCreatorType(W._signature, 'TEXT') | |
| 254 | |
|
27312
9220098f0327
Fix bug #670845: cut & clear in the output window now work, in that
Just van Rossum <just@letterror.com>
parents:
26466
diff
changeset
|
255 def domenu_cut(self, *args): |
|
9220098f0327
Fix bug #670845: cut & clear in the output window now work, in that
Just van Rossum <just@letterror.com>
parents:
26466
diff
changeset
|
256 self.domenu_copy(*args) |
|
9220098f0327
Fix bug #670845: cut & clear in the output window now work, in that
Just van Rossum <just@letterror.com>
parents:
26466
diff
changeset
|
257 |
|
9220098f0327
Fix bug #670845: cut & clear in the output window now work, in that
Just van Rossum <just@letterror.com>
parents:
26466
diff
changeset
|
258 def domenu_clear(self, *args): |
|
9220098f0327
Fix bug #670845: cut & clear in the output window now work, in that
Just van Rossum <just@letterror.com>
parents:
26466
diff
changeset
|
259 self.set('') |
|
9220098f0327
Fix bug #670845: cut & clear in the output window now work, in that
Just van Rossum <just@letterror.com>
parents:
26466
diff
changeset
|
260 |
| 10047 | 261 |
| 262 class PyOutput: | |
| 263 | |
| 264 def __init__(self, bounds, show = 1, fontsettings = ("Monaco", 0, 9, (0, 0, 0)), tabsettings = (32, 0)): | |
| 265 self.bounds = bounds | |
| 266 self.fontsettings = fontsettings | |
| 267 self.tabsettings = tabsettings | |
| 268 self.w = None | |
| 269 self.closed = 1 | |
| 270 self._buf = '' | |
| 271 # should be able to set this | |
| 272 self.savestdout, self.savestderr = sys.stdout, sys.stderr | |
| 273 sys.stderr = sys.stdout = self | |
| 274 if show: | |
| 275 self.show() | |
| 276 | |
| 277 def setupwidgets(self): | |
| 278 self.w = W.Window(self.bounds, "Output", | |
| 279 minsize = (200, 100), | |
| 280 tabbable = 0) | |
| 281 self.w.outputtext = OutputTextWidget((-1, -1, -14, 1), inset = (6, 5), | |
| 282 fontsettings = self.fontsettings, tabsettings = self.tabsettings, readonly = 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:
17972
diff
changeset
|
283 menuitems = [("Clear window", self.clearbuffer), ("Font settings\xc9", self.dofontsettings)] |
| 10047 | 284 self.w.popupmenu = W.PopupMenu((-15, -1, 16, 16), menuitems) |
| 285 | |
| 286 self.w._bary = W.Scrollbar((-15, 14, 16, -14), self.w.outputtext.vscroll, max = 32767) | |
| 287 self.w.bind("<close>", self.close) | |
| 288 self.w.bind("<activate>", self.activate) | |
| 289 | |
| 290 def write(self, text): | |
|
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:
21549
diff
changeset
|
291 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:
21549
diff
changeset
|
292 oldyield = MacOS.EnableAppswitch(-1) |
| 10047 | 293 try: |
| 294 self._buf = self._buf + text | |
| 295 if '\n' in self._buf: | |
| 296 self.flush() | |
| 297 finally: | |
|
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:
21549
diff
changeset
|
298 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:
21549
diff
changeset
|
299 MacOS.EnableAppswitch(oldyield) |
| 10047 | 300 |
| 301 def flush(self): | |
| 302 self.show() | |
| 303 stuff = string.split(self._buf, '\n') | |
| 304 stuff = string.join(stuff, '\r') | |
| 305 end = self.w.outputtext.ted.WEGetTextLength() | |
| 306 self.w.outputtext.setselection(end, end) | |
| 307 self.w.outputtext.ted.WEFeatureFlag(WASTEconst.weFReadOnly, 0) | |
| 308 self.w.outputtext.ted.WEInsert(stuff, None, None) | |
| 309 self._buf = "" | |
| 310 self.w.outputtext.updatescrollbars() | |
| 311 self.w.outputtext.ted.WEFeatureFlag(WASTEconst.weFReadOnly, 1) | |
|
26466
418a7ec92599
Lots of minor tweaks for the pep252 checkins, mainly because Qd
Jack Jansen <jack.jansen@cwi.nl>
parents:
21866
diff
changeset
|
312 if self.w.wid.GetWindowPort().QDIsPortBuffered(): |
|
418a7ec92599
Lots of minor tweaks for the pep252 checkins, mainly because Qd
Jack Jansen <jack.jansen@cwi.nl>
parents:
21866
diff
changeset
|
313 self.w.wid.GetWindowPort().QDFlushPortBuffer(None) |
| 10047 | 314 |
| 315 def show(self): | |
| 316 if self.closed: | |
| 317 if not self.w: | |
| 318 self.setupwidgets() | |
| 319 self.w.open() | |
| 320 self.w.outputtext.updatescrollbars() | |
| 321 self.closed = 0 | |
| 322 else: | |
| 323 self.w.show(1) | |
| 324 self.closed = 0 | |
| 325 self.w.select() | |
| 326 | |
| 327 def writeprefs(self): | |
| 328 if self.w is not None: | |
| 329 prefs = MacPrefs.GetPrefs(W.getapplication().preffilepath) | |
| 330 prefs.output.show = self.w.isvisible() | |
| 331 prefs.output.windowbounds = self.w.getbounds() | |
| 332 prefs.output.fontsettings = self.w.outputtext.getfontsettings() | |
| 333 prefs.output.tabsettings = self.w.outputtext.gettabsettings() | |
| 334 prefs.save() | |
| 335 | |
| 336 def dofontsettings(self): | |
| 337 import FontSettings | |
| 338 settings = FontSettings.FontDialog(self.w.outputtext.getfontsettings(), | |
| 339 self.w.outputtext.gettabsettings()) | |
| 340 if settings: | |
| 341 fontsettings, tabsettings = settings | |
| 342 self.w.outputtext.setfontsettings(fontsettings) | |
| 343 self.w.outputtext.settabsettings(tabsettings) | |
| 344 | |
| 345 def clearbuffer(self): | |
|
19488
42b2f1936254
Import the MacOS toolbox modules from the Carbon package.
Jack Jansen <jack.jansen@cwi.nl>
parents:
19009
diff
changeset
|
346 from Carbon import Res |
| 10047 | 347 self.w.outputtext.set('') |
| 348 | |
| 349 def activate(self, onoff): | |
| 350 if onoff: | |
| 351 self.closed = 0 | |
| 352 | |
| 353 def close(self): | |
| 354 self.w.show(0) | |
| 355 self.closed = 1 | |
| 356 return -1 | |
| 357 | |
| 358 | |
| 359 class SimpleStdin: | |
| 360 | |
| 361 def readline(self): | |
| 362 import EasyDialogs | |
|
17972
401ccfcf28c3
When reading from stdin (with the dialog box) use any partial line on
Jack Jansen <jack.jansen@cwi.nl>
parents:
17845
diff
changeset
|
363 # A trick to make the input dialog box a bit more palatable |
|
401ccfcf28c3
When reading from stdin (with the dialog box) use any partial line on
Jack Jansen <jack.jansen@cwi.nl>
parents:
17845
diff
changeset
|
364 if hasattr(sys.stdout, '_buf'): |
|
401ccfcf28c3
When reading from stdin (with the dialog box) use any partial line on
Jack Jansen <jack.jansen@cwi.nl>
parents:
17845
diff
changeset
|
365 prompt = sys.stdout._buf |
|
401ccfcf28c3
When reading from stdin (with the dialog box) use any partial line on
Jack Jansen <jack.jansen@cwi.nl>
parents:
17845
diff
changeset
|
366 else: |
|
401ccfcf28c3
When reading from stdin (with the dialog box) use any partial line on
Jack Jansen <jack.jansen@cwi.nl>
parents:
17845
diff
changeset
|
367 prompt = "" |
|
401ccfcf28c3
When reading from stdin (with the dialog box) use any partial line on
Jack Jansen <jack.jansen@cwi.nl>
parents:
17845
diff
changeset
|
368 if not prompt: |
|
401ccfcf28c3
When reading from stdin (with the dialog box) use any partial line on
Jack Jansen <jack.jansen@cwi.nl>
parents:
17845
diff
changeset
|
369 prompt = "Stdin input:" |
| 10047 | 370 sys.stdout.flush() |
|
17972
401ccfcf28c3
When reading from stdin (with the dialog box) use any partial line on
Jack Jansen <jack.jansen@cwi.nl>
parents:
17845
diff
changeset
|
371 rv = EasyDialogs.AskString(prompt) |
| 10047 | 372 if rv is None: |
| 373 return "" | |
|
21549
68842d295d2c
Modified version of patch #496882: echo SimpleStdin readline()
Just van Rossum <just@letterror.com>
parents:
19488
diff
changeset
|
374 rv = rv + "\n" # readline should include line terminator |
|
68842d295d2c
Modified version of patch #496882: echo SimpleStdin readline()
Just van Rossum <just@letterror.com>
parents:
19488
diff
changeset
|
375 sys.stdout.write(rv) # echo user's reply |
|
68842d295d2c
Modified version of patch #496882: echo SimpleStdin readline()
Just van Rossum <just@letterror.com>
parents:
19488
diff
changeset
|
376 return rv |
| 10047 | 377 |
| 378 | |
| 379 def installconsole(defaultshow = 1): | |
| 380 global console | |
| 381 prefs = MacPrefs.GetPrefs(W.getapplication().preffilepath) | |
| 382 if not prefs.console or not hasattr(prefs.console, 'show'): | |
| 383 prefs.console.show = defaultshow | |
| 384 if not hasattr(prefs.console, "windowbounds"): | |
| 385 prefs.console.windowbounds = (450, 250) | |
| 386 if not hasattr(prefs.console, "fontsettings"): | |
| 387 prefs.console.fontsettings = ("Monaco", 0, 9, (0, 0, 0)) | |
| 388 if not hasattr(prefs.console, "tabsettings"): | |
| 389 prefs.console.tabsettings = (32, 0) | |
| 390 console = PyConsole(prefs.console.windowbounds, prefs.console.show, | |
| 391 prefs.console.fontsettings, prefs.console.tabsettings, 1) | |
| 392 | |
| 393 def installoutput(defaultshow = 0, OutPutWindow = PyOutput): | |
| 394 global output | |
| 395 | |
| 396 # quick 'n' dirty std in emulation | |
| 397 sys.stdin = SimpleStdin() | |
| 398 | |
| 399 prefs = MacPrefs.GetPrefs(W.getapplication().preffilepath) | |
| 400 if not prefs.output or not hasattr(prefs.output, 'show'): | |
| 401 prefs.output.show = defaultshow | |
| 402 if not hasattr(prefs.output, "windowbounds"): | |
| 403 prefs.output.windowbounds = (450, 250) | |
| 404 if not hasattr(prefs.output, "fontsettings"): | |
| 405 prefs.output.fontsettings = ("Monaco", 0, 9, (0, 0, 0)) | |
| 406 if not hasattr(prefs.output, "tabsettings"): | |
| 407 prefs.output.tabsettings = (32, 0) | |
| 408 output = OutPutWindow(prefs.output.windowbounds, prefs.output.show, | |
| 409 prefs.output.fontsettings, prefs.output.tabsettings) |
