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

Added acceptance of string anchors/sides for TkInter such as "w" and "top" #158

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Added acceptance of string anchors/sides for TkInter such as "w" and "top" #158

wants to merge 3 commits into from

Conversation

TRManderson
Copy link
Contributor

TKInter accepts string arguments for anchor and sides, but our tests do not. This fixes our inflexibility so that students can write x.pack(side="left"), which Tk accepts.

@sapi
Copy link
Contributor

sapi commented Apr 21, 2015

This was actually intentional. Hard-coding string keywords is bad style, and I was hoping to discourage it. (I also suspect it might be deprecated in a version or two, seeing as PEP 435 has been accepted.)

For the same reason, I suspect some of the other tk tests might require tk.TRUE and tk.FALSE, though it's possible that I've been more flexible with the truthy constants.

My personal preference would be to require the constants, and perhaps to add some static analysis warnings explicitly telling students to use them (by checking for, eg, 'left'). However, if this is becoming a big issue, there's no harm in merging this.

If @pjritee uses string literals in the lectures, then this should definitely be merged.

@starsnabove
Copy link

On 21/04/15 15:39, Sean Purdon wrote:

This was actually intentional. Hard-coding string keywords is bad
style, and I was hoping to discourage it. (I also suspect it might be
deprecated in a version or two, seeing as PEP 435
https://www.python.org/dev/peps/pep-0435/ has been accepted.)

For the same reason, I suspect some of the other tk tests might
require |tk.TRUE| and |tk.FALSE|, though it's possible that I've been
more flexible with the truthy constants.

I concur

My personal preference would be to require the constants, and perhaps
to add some static analysis warnings explicitly telling students to
use them (by checking for, eg, |'left'|). However, if this is becoming
a big issue, there's no harm in merging this.

If @pjritee https://github.com/pjritee uses string literals in the
lectures, then this should /definitely/ be merged.

For above reasons I would hope that this is not happening


Reply to this email directly or view it on GitHub
#158 (comment).

@TRManderson
Copy link
Contributor Author

I just had a student point this out to me today. Peter isn't yet up to teaching GUIs, so we don't need to worry for now.

Perhaps the best course of action would be to modify my change to give a more detailed warning message when using "w" and "top", for example "You should use tk.TOP instead of {}"?

@sapi
Copy link
Contributor

sapi commented Apr 21, 2015

Yeah, that would probably be a good idea.

You could even generalise this somewhat (up to you whether it's worth the effort):

def validate_pack_arg(self, required, actual):
    _, _, required_arg = required.partition('.')

    if actual.lower() == required_arg.lower():
        self.add_warning(
            'You will need to specify your pack argument as {}, not {}'.format(
                required, actual
            )
        )

@TRManderson
Copy link
Contributor Author

How do people feel about the messages below? I intend to do similar things in other places.

elif pack.keywords['anchor'] != 'tk.W':
    if pack.keywords['anchor'].lower() == "w":
        self.add_warning(
            'You appear to be using \'w\' as your anchor value. '
            ' (in {}). Please use tk.W'.format(pack.function_name)
        )
    else:
        self.add_error(
            'You appear to be using the wrong value for anchor '
            '(in {})'.format(pack.function_name)
    )

@sapi
Copy link
Contributor

sapi commented Apr 21, 2015

If you do it like that (if/else), then the first one needs to be an error,
not a warning, otherwise the student will be able to submit without fixing
the issue.

On 21 April 2015 at 18:54, Tom Manderson [email protected] wrote:

How do people feel about the messages below? I intend to do similar things
in other places.

elif pack.keywords['anchor'] != 'tk.W':
if pack.keywords['anchor'].lower() == "w":
self.add_warning(
'You appear to be using 'w' as your anchor value. '
' (in {}). Please use tk.W'.format(pack.function_name)
)
else:
self.add_error(
'You appear to be using the wrong value for anchor '
'(in {})'.format(pack.function_name)
)


Reply to this email directly or view it on GitHub
#158 (comment).

@TRManderson
Copy link
Contributor Author

That was intentional. Do you think error is the way to go? If so, I defer to the wisdom of the more experienced tutor and will do that in other cases.

@TRManderson
Copy link
Contributor Author

Also, should we modify the expand check in GUI 3 so it only accepts tk.TRUE, or keep letting it accept True and 1?

Now gives a more detailed error on "w" instead of tk.W, etc (anchors and sides)
@TRManderson
Copy link
Contributor Author

Is this okay to be merged?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants