classification
Title: Multiple item arguments for selection operations
Type: enhancement Stage: resolved
Components: Library (Lib), Tkinter Versions: Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: python-dev, serhiy.storchaka, terry.reedy
Priority: normal Keywords: patch

Created on 2016-06-14 17:41 by serhiy.storchaka, last changed 2017-09-24 12:03 by serhiy.storchaka. This issue is now closed.

Files
File name Uploaded Description Edit
treeview_selection_items.patch serhiy.storchaka, 2016-06-14 17:40 review
Pull Requests
URL Status Linked Edit
PR 3667 merged serhiy.storchaka, 2017-09-20 08:00
PR 3719 merged python-dev, 2017-09-24 11:34
Messages (12)
msg268574 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-06-14 17:40
For now methods selection_set(), selection_add(), selection_remove() and selection_toggle() of ttk.TreeView take the single argument that should be either the single item id or a tuple or list of item ids. In contrary methods delete() and detach() take item ids as a variable number of arguments. The latter interface looks more pythonic, more consistent and errorproof.

Proposed patch (based on Terry's suggestion in issue26386) makes selection methods accepting a variable number of arguments. For compatibility with older versions a tuple or list of item ids can be specified as a single argument, but this interface is deprecated (with long deprecation period).

In addition deprecated other weird interface. For now the selection() method can take a subcommand name and items, for example tv.selection('add', 'ITEM1'). If the first argument is None, arguments are ignored, tv.selection(None, 'spam') equals to tv.selection(). Now all this is deprecated and will be TypeError in 3.7.
msg268594 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2016-06-15 00:09
Code looks good, just a couple of comments.

But I am puzzled by string return before patch
>>> tv.selection()
''
versus tuple return after patch (which seems correct).
>>> tv.selection()
()
msg268600 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-06-15 02:27
I'm puzzled too.
msg268602 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-06-15 03:02
splitlist() always returns a tuple. How selection() ca return a string?!
msg268603 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2016-06-15 04:00
I reverted the patch, restarted IDLE, and now I get () as I should.  Lets forget about it.  Apply or ignore comments as you wish.
msg268618 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-06-15 12:47
I was puzzled because on one of my machines selection() returned ''.

But after updating the workspace the problem is gone. This is just a consequence of the issue26386 patch.
msg268789 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-06-18 09:59
I'm not sure that passing multiple items as a tuple should be deprecated.
msg268835 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2016-06-19 02:19
Then don't.  Better to do nothing until sure than to deprecate and then undeprecate.  Thinking about it, I am not sure either.
msg268869 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-06-19 21:06
New changeset 7b9ad68db14e by Serhiy Storchaka in branch 'default':
Issue #27319: Methods selection_set(), selection_add(), selection_remove()
https://hg.python.org/cpython/rev/7b9ad68db14e
msg268870 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-06-19 21:07
Thank you for your review Terry.
msg302850 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-09-24 11:34
New changeset 2fad10235460ac394cc8b869c41f47aba3d63594 by Serhiy Storchaka in branch 'master':
bpo-27319, bpo-31508: Document deprecation in Treeview.selection(). (#3667)
https://github.com/python/cpython/commit/2fad10235460ac394cc8b869c41f47aba3d63594
msg302854 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-09-24 12:03
New changeset e31eca45e548bf6f439d540f3751516acbc31689 by Serhiy Storchaka (Miss Islington (bot)) in branch '3.6':
[3.6] bpo-27319, bpo-31508: Document deprecation in Treeview.selection(). (GH-3667) (#3719)
https://github.com/python/cpython/commit/e31eca45e548bf6f439d540f3751516acbc31689
History
Date User Action Args
2017-09-24 12:03:50serhiy.storchakasetmessages: + msg302854
2017-09-24 11:34:19python-devsetpull_requests: + pull_request3702
2017-09-24 11:34:12serhiy.storchakasetmessages: + msg302850
2017-09-20 08:00:44serhiy.storchakasetpull_requests: + pull_request3656
2016-06-19 21:07:37serhiy.storchakasetstatus: open -> closed
resolution: fixed
messages: + msg268870

stage: commit review -> resolved
2016-06-19 21:06:03python-devsetnosy: + python-dev
messages: + msg268869
2016-06-19 02:19:35terry.reedysetmessages: + msg268835
2016-06-18 09:59:44serhiy.storchakasetmessages: + msg268789
2016-06-15 12:47:13serhiy.storchakasetassignee: serhiy.storchaka
messages: + msg268618
2016-06-15 04:00:38terry.reedysetmessages: + msg268603
stage: patch review -> commit review
2016-06-15 03:02:43serhiy.storchakasetmessages: + msg268602
2016-06-15 02:27:12serhiy.storchakasetmessages: + msg268600
2016-06-15 00:09:14terry.reedysetmessages: + msg268594
2016-06-14 17:41:00serhiy.storchakacreate