bpo-37903: IDLE: add shell sidebar mouse interactions (GH-25708)

Left click and drag to select lines.  With selection, right click for context menu with copy and copy-with-prompts.
Also add copy-with-prompts to the text-box context menu.

Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
This commit is contained in:
Tal Einat 2021-05-03 05:27:38 +03:00 committed by GitHub
parent 90d523910a
commit b43cc31a27
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 384 additions and 230 deletions

View file

@ -15,7 +15,7 @@ class AutoCompleteWindowTest(unittest.TestCase):
cls.root = Tk()
cls.root.withdraw()
cls.text = Text(cls.root)
cls.acw = acw.AutoCompleteWindow(cls.text)
cls.acw = acw.AutoCompleteWindow(cls.text, tags=None)
@classmethod
def tearDownClass(cls):

View file

@ -270,7 +270,6 @@ class LineNumbersTest(unittest.TestCase):
self.assertEqual(self.get_selection(), ('2.0', '3.0'))
@unittest.skip('test disabled')
def simulate_drag(self, start_line, end_line):
start_x, start_y = self.get_line_screen_position(start_line)
end_x, end_y = self.get_line_screen_position(end_line)
@ -704,6 +703,66 @@ class ShellSidebarTest(unittest.TestCase):
yield
self.assertIsNotNone(text.dlineinfo(text.index(f'{last_lineno}.0')))
@run_in_tk_mainloop
def test_copy(self):
sidebar = self.shell.shell_sidebar
text = self.shell.text
first_line = get_end_linenumber(text)
self.do_input(dedent('''\
if True:
print(1)
'''))
yield
text.tag_add('sel', f'{first_line}.0', 'end-1c')
selected_text = text.get('sel.first', 'sel.last')
self.assertTrue(selected_text.startswith('if True:\n'))
self.assertIn('\n1\n', selected_text)
text.event_generate('<<copy>>')
self.addCleanup(text.clipboard_clear)
copied_text = text.clipboard_get()
self.assertEqual(copied_text, selected_text)
@run_in_tk_mainloop
def test_copy_with_prompts(self):
sidebar = self.shell.shell_sidebar
text = self.shell.text
first_line = get_end_linenumber(text)
self.do_input(dedent('''\
if True:
print(1)
'''))
yield
text.tag_add('sel', f'{first_line}.3', 'end-1c')
selected_text = text.get('sel.first', 'sel.last')
self.assertTrue(selected_text.startswith('True:\n'))
selected_lines_text = text.get('sel.first linestart', 'sel.last')
selected_lines = selected_lines_text.split('\n')
# Expect a block of input, a single output line, and a new prompt
expected_prompts = \
['>>>'] + ['...'] * (len(selected_lines) - 3) + [None, '>>>']
selected_text_with_prompts = '\n'.join(
line if prompt is None else prompt + ' ' + line
for prompt, line in zip(expected_prompts,
selected_lines,
strict=True)
) + '\n'
text.event_generate('<<copy-with-prompts>>')
self.addCleanup(text.clipboard_clear)
copied_text = text.clipboard_get()
self.assertEqual(copied_text, selected_text_with_prompts)
if __name__ == '__main__':
unittest.main(verbosity=2)