[Python-checkins] bpo-37627: Initialize IDLE Custom Run dialog with previous entries (GH-14870)
Miss Islington (bot)
webhook-mailer at python.org
Sun Jul 21 12:09:24 EDT 2019
https://github.com/python/cpython/commit/d9086f2324264e93155dd81f4484975215e38f00
commit: d9086f2324264e93155dd81f4484975215e38f00
branch: 3.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2019-07-21T09:09:17-07:00
summary:
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 35b87e6001bd991f625abe305951c77ddeb9a9c5)
Co-authored-by: Ngalim Siregar <ngalim.siregar at gmail.com>
files:
A Misc/NEWS.d/next/IDLE/2019-07-20-23-33-53.bpo-37627.dQhUNB.rst
M Lib/idlelib/idle_test/test_query.py
M Lib/idlelib/query.py
M Lib/idlelib/runscript.py
diff --git a/Lib/idlelib/idle_test/test_query.py b/Lib/idlelib/idle_test/test_query.py
index 3b444de15d7c..f957585190dc 100644
--- a/Lib/idlelib/idle_test/test_query.py
+++ b/Lib/idlelib/idle_test/test_query.py
@@ -12,7 +12,7 @@
from idlelib import query
import unittest
from test.support import requires
-from tkinter import Tk
+from tkinter import Tk, END
import sys
from unittest import mock
@@ -392,10 +392,12 @@ def setUpClass(cls):
def test_click_args(self):
root = Tk()
root.withdraw()
- dialog = query.CustomRun(root, 'Title', _utest=True)
- dialog.entry.insert(0, 'okay')
+ dialog = query.CustomRun(root, 'Title',
+ cli_args=['a', 'b=1'], _utest=True)
+ self.assertEqual(dialog.entry.get(), 'a b=1')
+ dialog.entry.insert(END, ' c')
dialog.button_ok.invoke()
- self.assertEqual(dialog.result, (['okay'], True))
+ self.assertEqual(dialog.result, (['a', 'b=1', 'c'], True))
root.destroy()
diff --git a/Lib/idlelib/query.py b/Lib/idlelib/query.py
index d74084feed76..097e6e61e356 100644
--- a/Lib/idlelib/query.py
+++ b/Lib/idlelib/query.py
@@ -325,9 +325,13 @@ class CustomRun(Query):
"""
# Used in runscript.run_custom_event
- def __init__(self, parent, title, *, cli_args='',
+ def __init__(self, parent, title, *, cli_args=[],
_htest=False, _utest=False):
- # TODO Use cli_args to pre-populate entry.
+ """cli_args is a list of strings.
+
+ The list is assigned to the default Entry StringVar.
+ The strings are displayed joined by ' ' for display.
+ """
message = 'Command Line Arguments for sys.argv:'
super().__init__(
parent, title, message, text0=cli_args,
diff --git a/Lib/idlelib/runscript.py b/Lib/idlelib/runscript.py
index b041e56fb840..f97cf528cce6 100644
--- a/Lib/idlelib/runscript.py
+++ b/Lib/idlelib/runscript.py
@@ -39,6 +39,8 @@ def __init__(self, editwin):
# XXX This should be done differently
self.flist = self.editwin.flist
self.root = self.editwin.root
+ # cli_args is list of strings that extends sys.argv
+ self.cli_args = []
if macosx.isCocoaTk():
self.editwin.text_frame.bind('<<run-module-event-2>>', self._run_module_event)
@@ -137,10 +139,11 @@ def _run_module_event(self, event, *, customize=False):
return 'break'
if customize:
title = f"Customize {self.editwin.short_title()} Run"
- run_args = CustomRun(self.shell.text, title).result
+ run_args = CustomRun(self.shell.text, title,
+ cli_args=self.cli_args).result
if not run_args: # User cancelled.
return 'break'
- cli_args, restart = run_args if customize else ([], True)
+ self.cli_args, restart = run_args if customize else ([], True)
interp = self.shell.interp
if pyshell.use_subprocess and restart:
interp.restart_subprocess(
@@ -148,8 +151,8 @@ def _run_module_event(self, event, *, customize=False):
self.editwin._filename_to_unicode(filename))
dirname = os.path.dirname(filename)
argv = [filename]
- if cli_args:
- argv += cli_args
+ if self.cli_args:
+ argv += self.cli_args
interp.runcommand(f"""if 1:
__file__ = {filename!r}
import sys as _sys
diff --git a/Misc/NEWS.d/next/IDLE/2019-07-20-23-33-53.bpo-37627.dQhUNB.rst b/Misc/NEWS.d/next/IDLE/2019-07-20-23-33-53.bpo-37627.dQhUNB.rst
new file mode 100644
index 000000000000..d864d07f60ef
--- /dev/null
+++ b/Misc/NEWS.d/next/IDLE/2019-07-20-23-33-53.bpo-37627.dQhUNB.rst
@@ -0,0 +1,3 @@
+Initialize the Customize Run dialog with the command line arguments
+most recently entered before. The user can optionally edit before
+submitting them.
More information about the Python-checkins
mailing list