diff options
author | Tal Einat <532281+taleinat@users.noreply.github.com> | 2021-05-03 02:27:38 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-03 02:27:38 (GMT) |
commit | b43cc31a270d0dacbc69e35d6c6fbdb5edd7e711 (patch) | |
tree | f656c691cf80d2b927037808ea51d4f75ae20a16 /Lib/idlelib/idle_test | |
parent | 90d523910a61290597b4599f17363b532f0a4411 (diff) | |
download | cpython-b43cc31a270d0dacbc69e35d6c6fbdb5edd7e711.zip cpython-b43cc31a270d0dacbc69e35d6c6fbdb5edd7e711.tar.gz cpython-b43cc31a270d0dacbc69e35d6c6fbdb5edd7e711.tar.bz2 |
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>
Diffstat (limited to 'Lib/idlelib/idle_test')
-rw-r--r-- | Lib/idlelib/idle_test/test_autocomplete_w.py | 2 | ||||
-rw-r--r-- | Lib/idlelib/idle_test/test_sidebar.py | 61 |
2 files changed, 61 insertions, 2 deletions
diff --git a/Lib/idlelib/idle_test/test_autocomplete_w.py b/Lib/idlelib/idle_test/test_autocomplete_w.py index b1bdc6c..a59a375 100644 --- a/Lib/idlelib/idle_test/test_autocomplete_w.py +++ b/Lib/idlelib/idle_test/test_autocomplete_w.py @@ -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): diff --git a/Lib/idlelib/idle_test/test_sidebar.py b/Lib/idlelib/idle_test/test_sidebar.py index 0497f6d..43e8137 100644 --- a/Lib/idlelib/idle_test/test_sidebar.py +++ b/Lib/idlelib/idle_test/test_sidebar.py @@ -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) |