Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-32585: Add ttk::spinbox #5221

Merged
merged 28 commits into from
Feb 9, 2018
Merged

bpo-32585: Add ttk::spinbox #5221

merged 28 commits into from
Feb 9, 2018

Conversation

alandmoore
Copy link
Contributor

@alandmoore alandmoore commented Jan 17, 2018

Added support for ttk::spinbox in Python ttk. Fixes https://bugs.python.org/issue32585.

https://bugs.python.org/issue32585

Added support for ttk::spinbox in Python ttk.
@the-knights-who-say-ni
Copy link

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA).

Unfortunately we couldn't find an account corresponding to your GitHub username on bugs.python.org (b.p.o) to verify you have signed the CLA (this might be simply due to a missing "GitHub Name" entry in your b.p.o account settings). This is necessary for legal reasons before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

Thanks again to your contribution and we look forward to looking at it!

@alandmoore
Copy link
Contributor Author

I have just signed the CLA, I don't know if the bot will remove that tag or if I need to.

Copy link
Member

@terryjreedy terryjreedy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to see this added unless there is a good reason for the omission. Still needed are patches for doc and tests.

@@ -1151,6 +1151,24 @@ def __init__(self, master=None, **kw):
Widget.__init__(self, master, "ttk::sizegrip", kw)


class Spinbox(Entry):
"""Ttk Spinbox is an Entry with increment and decrement arrows, used
for number entry"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have the impression that a spinbox 'returns' a string that in normally a number but could be selected from a list of strings.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, I'd forgotten it can take a list of values, just like a combobox. I think the relevant methods are already in ttk.combobox, would it make sense to inherit from that class or would it be better to reimplement them here? It's not much code, but I don't think there's anything unique to add.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that the tk docs say that ttk spinbox is a ttk entry with added arrow buttons, I would think that Entry rather than Combobox is the correct baseclass.


STANDARD OPTIONS

class, cursor, style, takefocus
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://www.tcl.tk/man/tcl8.6/TkCmd/ttk_spinbox.htm adds
validate, validatecommand, xscrollcommand
although validate and validatecommand are listed as widget-specific for ttk.Entry.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

invalidcommand is another standard option. Will correct this in spinbox.


WIDGET-SPECIFIC OPTIONS

to, from_, increment
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto adds
values, wrap, format, command
plus "all the features of the ttk::entry widget", which has a few more specific options not listed.

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

Copy link
Contributor

@csabella csabella left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the top of ttk.py, there is a __all__ defined, which Spinbox would need to be added to.


to, from_, increment, values, wrap, format, command
"""
Entry.__init__(self, master, "ttk::spinbox", **kw)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be Combobox.__init__ now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quite right. Is there a particular reason why none of the classes in this library use super()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm actually going to revert the base class to Entry per @terryjreedy 's comment.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am pretty sure super came years later than the original Tkinter module. In 2.x it was a bit harder to use. For single inheritance, I don't think that there is much advantage. (I believe that there are cases of multiple inheritance in tkinter.init, but have not rechecked.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree this should have a base class of Entry, but with that, I also think current and set from Combobox should be included here. It would probably be overkill, but maybe Spinbox and Combobox should both inherit from an Entry subclass that has current and set?

The tests will be able to use current and set.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current and set methods correspond the current and set subcommands of Ttk widgets. The ttk::entry widget doesn't have these commands.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I meant that both Spinbox and Combobox have current and set. I didn't know if it was better to implement them both directly from Entry or to have another class in between, that is a subclass of Entry that implements current and set and is the superclass to Combobox and Spinbox.

@@ -19,7 +19,7 @@
__all__ = ["Button", "Checkbutton", "Combobox", "Entry", "Frame", "Label",
"Labelframe", "LabelFrame", "Menubutton", "Notebook", "Panedwindow",
"PanedWindow", "Progressbar", "Radiobutton", "Scale", "Scrollbar",
"Separator", "Sizegrip", "Style", "Treeview",
"Separator", "Sizegrip", "Style", "Treeview", "Spinbox",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These look alphabetized.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

corrected this

@alandmoore
Copy link
Contributor Author

So I've added a .current() method, following the same approach used in Combobox, since this is supposed to be a valid method on ttk::spinbox (c.f. https://www.tcl.tk/man/tcl/TkCmd/ttk_spinbox.htm )

But when I call this method Tcl/Tk says "current" is not a valid method. Anyone know what I'm doing wrong here?

 File "/home/alanm/src/cpython/Lib/tkinter/ttk.py", line 1181, in current
    return self.tk.getint(self.tk.call(self._w, "current"))
_tkinter.TclError: bad command "current": must be bbox, cget, configure, delete, get, icursor, identify, index, insert, instate, selection, state, set, validate, or xview

Currently crashing due to "current" not being a valid ttk::spinbox
command, contrary to Ttk documentation.
@alandmoore
Copy link
Contributor Author

alandmoore commented Jan 21, 2018

I've pushed a test class, but there are two problems which I cannot figure out:

  • The test suite is complaining that 'exportselection', 'font', and 'foreground' are not in the OPTIONS list, but these are not valid Spinbox arguments.
  • As mentioned in a previous comment, trying to use Spinbox.current is throwing a TclError saying that current is not a valid method. This is contrary to the Ttk documentation.

If anyone can take a look and help me figure out what's going on here, I would be grateful.

EDIT: I can only conclude that the Ttk docs are wrong. I tried this in tclsh:

$ tclsh
% package require Tk
8.6.8
% package require Ttk
8.6.8
% grid [ttk::spinbox .myspinbox]
% .myspinbox current
bad command "current": must be bbox, cget, configure, delete, get, icursor, identify, index, insert, instate, selection, state, set, validate, or xview

Granted, this is my first foray into Tcl/Tk so I may have done something wrong, but it appears that current is not a valid spinbox command. Can anyone confirm?

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an entry in the What's New document and your name in Misc/ACKS.

I confirm that current is not supported.

@@ -692,6 +692,92 @@ Bugs
* This widget supports only "southeast" resizing.


Spinbox
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add the description of Spinbox right after the description of Combobox. And the same for the Spinbox class and the test class.

Virtual events
^^^^^^^^^^^^^^

The spinbox widget generates a **<<Increment>>** virtual event when the user presses <Up>, and a **<<Decrement>>** virtual event when the user presses <Down>.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too long line.

@@ -908,19 +994,19 @@ ttk.Treeview
The valid options/values are:

* id
Returns the column name. This is a read-only option.
Returns the column name. This is a read-only option.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated change. Don't use tabs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, had some bad editor settings.

self.assertEqual(self.spin.get(), '1')

def test_values(self):

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too much empty lines.

@csabella
Copy link
Contributor

csabella commented Jan 21, 2018

@serhiy-storchaka I thought current was supported because of this page: https://www.tcl.tk/man/tcl/TkCmd/ttk_spinbox.htm

Sorry about that.

@serhiy-storchaka
Copy link
Member

Seems there is just a documentation bug. Tk sources doesn't contain implementation of the current subcommand of the ttk::spinbox widget.

Removed from code, docs, and tests.  This method is documented in Ttk
docs, but does not actually exist.
@alandmoore
Copy link
Contributor Author

I see. @serhiy-storchaka is it too late for this one in 3.7?

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SpinboxTest test is omitted when run the test_ttk_guionly test. After adding it into the tests_gui tuple it produces many failures.

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@alandmoore
Copy link
Contributor Author

@serhiy-storchaka Sorry, was not aware of that tuple. I have added to the tuple, but I don't get any failing tests on my system. I notice that appveyor has 1 fail, and that it's executing on Windows (I'm on Linux). This suggests to me that the problem is either platform-related or a race condition.

If tests are failing on your system, I would appreciate the error output, since I cannot reproduce.

@bedevere-bot
Copy link

@serhiy-storchaka: Please replace # with GH- in the commit message next time. Thanks!

@miss-islington
Copy link
Contributor

Thanks @alandmoore for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.7.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Feb 9, 2018
(cherry picked from commit a48e78a)

Co-authored-by: Alan D Moore <me@alandmoore.com>
@bedevere-bot
Copy link

GH-5592 is a backport of this pull request to the 3.7 branch.

@miss-islington
Copy link
Contributor

Thanks @alandmoore for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.7.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

serhiy-storchaka pushed a commit that referenced this pull request Feb 9, 2018
(cherry picked from commit a48e78a)

Co-authored-by: Alan D Moore <me@alandmoore.com>
@alandmoore alandmoore deleted the fix-issue-32585 branch February 20, 2018 22:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-feature A feature request or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants