Bugs item #1010370, was opened at 2004-08-16 18:15 Message generated for change (Comment added) made by kbk You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1010370&group_id=5470
Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: IDLE Group: Python 2.3 >Status: Closed >Resolution: Fixed Priority: 5 Submitted By: Dave Florek (d_florek) Assigned to: Kurt B. Kaiser (kbk) Summary: sys.ps1 not protected in EditorWindow.py Initial Comment: Python 2.3.4 on Linux <host> 2.4.19-xfs-p3-929 #1 SMP Thu Oct 24 11:29:34 PDT 2002 i686 unknown (RedHat 7.3, patched) Auto-indenting fails (and dumps errors to the shell) when idle is started as a file editor. I've wrapped original lines 987 and 1057 of EditorWindow.py (last_line_of_prompt = sys.ps1.split('\n')[-1]) with if self.context_use_ps1: last_line_of_prompt = sys.ps1.split('\n')[-1] else: last_line_of_prompt = '>>> ' This seems to fix it (might want to double-check other attempts to access sys.ps1 and make sure they're likewise protected). FYI, the errors I got (other than incorrect line numbers -- I was tracking down a different problem when I stumbled across this) are: Exception in Tkinter callback Traceback (most recent call last): File "/usr/local/lib/python2.3/lib-tk/Tkinter.py", line 1345, in __call__ return self.func(*args) File "/work/florek/dev/python2.3/idlelib/EditorWindow.py", line 1069, in newline_and_indent_event last_line_of_prompt = sys.ps1.split('\n')[-1] AttributeError: 'module' object has no attribute 'ps1' ---------------------------------------------------------------------- >Comment By: Kurt B. Kaiser (kbk) Date: 2006-07-24 13:14 Message: Logged In: YES user_id=149084 Rev 50804 moved sys.ps1 test to EditorWindow init. ---------------------------------------------------------------------- Comment By: Dave Florek (d_florek) Date: 2004-08-18 16:48 Message: Logged In: YES user_id=1105316 Whatever fixes the problem is fine with me. Knock yourself out. Seems to me that cases which are specific to run-as-shell or run-as-editor should be sensibly divided rather than "if there isn't a prompt then create a fake one" hacks, but you're the one who has to maintain it down the road. As I illustrated, I already have a fix in place. ---------------------------------------------------------------------- Comment By: Kurt B. Kaiser (kbk) Date: 2004-08-17 22:15 Message: Logged In: YES user_id=149084 I'm thinking that it might be best to move the code which sets sys.ps1 from PyShell.main() to the EditorWindow module toplevel. Do you see a downside to that? (sys.ps1 is only defined for the python interactive interpreter, so it's undefined in IDLE until set.) ---------------------------------------------------------------------- Comment By: Dave Florek (d_florek) Date: 2004-08-17 13:10 Message: Logged In: YES user_id=1105316 We have a Tk-based app that integrates IDLE as the default text editor for python "scriptlets". We create a new idlelib.FileList attached to the parent gui, and then on-demand from a button do a editor = self.parentGui.flist.open(file) editor.set_close_hook(lambda self=self: self.parentGui.close_idle(self)) self.editor = editor the close_idle callback, among other things, calls flist.close_edit(widget.editor) I'll look at idle.py and PyShell.py for more ideas, but it seems to me if there's a valid "context" flag that indicates whether IDLE is acting as a Python shell interface or as a text-editor, then that flag should be used in this particular case, since there won't be a prompt when acting as a text-editor, and then there's no need to ensure that sys.ps1 is currently defined. Thanks, Dave ---------------------------------------------------------------------- Comment By: Kurt B. Kaiser (kbk) Date: 2004-08-17 02:36 Message: Logged In: YES user_id=149084 When IDLE starts via PyShell.main() sys.ps1 is set to '>>>' at line 1273. How are you "starting idle as a file editor?" It may be started either with the idle script (probably in /usr/bin/ if IDLE was installed from the rpm) or by calling ../../python ./PyShell.py from .../Lib/idlelib. Also, take a look at idle.py, it's pretty flexible. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1010370&group_id=5470 _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com