10000 bpo-37627: Initialize IDLE Custom Run dialog with previous entries (G… · python/cpython@d9086f2 · GitHub
[go: up one dir, main page]

Skip to content

Commit d9086f2

Browse files
bpo-37627: Initialize IDLE Custom Run dialog with previous entries (GH-14870)
Repeat the command line arguments most recently entered before so the user can edit them. (cherry picked from commit 35b87e6) Co-authored-by: Ngalim Siregar <ngalim.siregar@gmail.com>
1 parent 843fd85 commit d9086f2

File tree

4 files changed

+22
-10
lines changed

4 files changed

+22
-10
lines changed

Lib/idlelib/idle_test/test_query.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from idlelib import query
1313
import unittest
1414
from test.support import requires
15-
from tkinter import Tk
15+
from tkinter import Tk, END
1616

1717
import sys
1818
from unittest import mock
@@ -392,10 +392,12 @@ def setUpClass(cls):
392392
def test_click_args(self):
393393
root = Tk()
394394
root.withdraw()
395-
dialog = query.CustomRun(root, 'Title', _utest=True)
396-
dialog.entry.insert(0, 'okay')
395+
dialog = query.CustomRun(root, 'Title',
396+
cli_args=['a', 'b=1'], _utest=True)
397+
self.assertEqual(dialog.entry.get(), 'a b=1')
398+
dialog.entry.insert(END, ' c')
397399
dialog.button_ok.invoke()
398-
self.assertEqual(dialog.result, (['okay'], True))
400+
self.assertEqual(dialog.result, (['a', 'b=1', 'c'], True))
399401
root.destroy()
400402

401403

Lib/idlelib/query.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,9 +325,13 @@ class CustomRun(Query):
325325
"""
326326
# Used in runscript.run_custom_event
327327

328-
def __init__(self, parent, title, *, cli_args='',
328+
def __init__(self, parent, title, *, cli_args=[],
329329
_htest=False, _utest=False):
330-
# TODO Use cli_args to pre-populate entry.
330+
"""cli_args is a list of strings.
331+
332+
The list is assigned to the default Entry StringVar.
333+
The strings are displayed joined by ' ' for display.
334+
"""
331335
message = 'Command Line Arguments for sys.argv:'
332336
super().__init__(
333337
parent, title, message, text0=cli_args,

Lib/idlelib/runscript.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ def __init__(self, editwin):
3939
# XXX This should be done differently
4040
self.flist = self.editwin.flist
4141
self.root = self.editwin.root
42+
# cli_args is list of strings that extends sys.argv
43+
self.cli_args = []
4244

4345
if macosx.isCocoaTk():
4446
self.editwin.text_frame.bind('<<run-module-event-2>>', self._run_module_event)
@@ -137,19 +139,20 @@ def _run_module_event(self, event, *, customize=False):
137139
return 'break'
138140
if customize:
139141
title = f"Customize {self.editwin.short_title()} Run"
140-
run_args = CustomRun(self.shell.text, title).result
142+
run_args = CustomRun(self.she D211 ll.text, title,
143+
cli_args=self.cli_args).result
141144
if not run_args: # User cancelled.
142145
return 'break'
143-
cli_args, restart = run_args if customize else ([], True)
146+
self.cli_args, restart = run_args if customize else ([], True)
144147
interp = self.shell.interp
145148
if pyshell.use_subprocess and restart:
146149
interp.restart_subprocess(
147150
with_cwd=False, filename=
148151
self.editwin._filename_to_unicode(filename))
149152
dirname = os.path.dirname(filename)
150153
argv = [filename]
151-
if cli_args:
152-
argv += cli_args
154+
if self.cli_args:
155+
argv += self.cli_args
153156
interp.runcommand(f"""if 1:
154157
__file__ = {filename!r}
155158
import sys as _sys
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Initialize the Customize Run dialog with the command line arguments
2+
most recently entered before. The user can optionally edit before
3+
submitting them.

0 commit comments

Comments
 (0)
0