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

PR: Properly disable editing in Variable Explorer for values in immutable collections (e.g. tuples) #5991

Merged
merged 4 commits into from
Dec 26, 2017

Conversation

CAM-Gerlach
Copy link
Member

Fixes #5953

@ccordoba12 @Prikers

First "real" (code) PR. Before, values in immutable (readonly=True) collections were able to be "edited" in a textbox on doubleclick in a Variable Explorer subwindow, but the changes wouldn't stick (as they shouldn't) once enter/etc was pressed, leading to inconsistency and potential user confusion.

To remedy this, a naive fix as presented here would be to simply check if the readonly property is set when attempting to edit a directly editable value (i.e. not an object that can itself be inspected in a variable explorer subwindow, which might be desired even inside a tuple), and if so, do nothing. Took about 60 seconds to actually write and test the relevant line, and 60 minutes to manually track down where to stick said line...no surprise, lol.

Is this the best approach? Does it break anything else? I ran some simple manual tests with mutable and immutable objects, and viewable objects inside tuples, and everything check out okay, but I'm sure there's edge/corner cases this isn't covering. I rarely do much OO programing, and virtually never anything with a GUI/Qt, so not really sure...

As an aside, I couldn't run the test suite myself since (whether I ran it on the various base branches or on my test branch, directly through py.test, or runtests.py), the first test would run, a spyder window would open with various actions performed, and then it would stop and get stuck either doing nothing (on, py.test), or on a "Save/Don't Save/Cancel" dialog, and it would either timeout (in the first case), or fail (no matter what I pressed on the dialog, or if I waited several minutes)...not sure what's going on there.

Thanks!

@ccordoba12 ccordoba12 added this to the v3.2.6 milestone Dec 15, 2017
@CAM-Gerlach CAM-Gerlach changed the title Disable doubleclick, spacebar etc editing in Variable Explorer for values in immutable collections (e.g. str, numeric, bool in tuples) PR: Disable doubleclick, spacebar etc editing in Variable Explorer for values in immutable collections (e.g. str, numeric, bool in tuples) Dec 15, 2017
@CAM-Gerlach
Copy link
Member Author

CAM-Gerlach commented Dec 15, 2017

Looking more into it, this naive approach doesn't account for dates/datetimes and long text strings that are handled separately. Accordingly, I'll amend this commit (ETA later tonight) to deal with those cases too, and do some more hands-on testing.

With regard to the latter, I'll see if I can get long text to open to a textbox for easier/more complete viewing, but not actually be editable which can presumably be done through the appropriate methods of the TextEditor object.

For dates and times, however, is that currently Spyder does not display datetime objects in a "pretty" format when viewing inline in the variable explorer, only in "edit" mode, so not sure if the best approach is to make it non-editable for now and then in another PR improve the display of dates when not selected (probably not a bad idea anyway at some point), or to enable edit mode as now but just not allow the user to change values, if that is easily implementable.

@CAM-Gerlach CAM-Gerlach changed the title PR: Disable doubleclick, spacebar etc editing in Variable Explorer for values in immutable collections (e.g. str, numeric, bool in tuples) PR: Disable editing in Variable Explorer for values in immutable collections (e.g. tuples) Dec 16, 2017
@CAM-Gerlach CAM-Gerlach changed the title PR: Disable editing in Variable Explorer for values in immutable collections (e.g. tuples) PR: Properly disable editing in Variable Explorer for values in immutable collections (e.g. tuples) Dec 16, 2017
@CAM-Gerlach
Copy link
Member Author

For long text strings, the fix was quite simple—just pass the readonly argument through to the TextEditor constructor, and bam, read-only text editor to allow full viewing, just not editing.

For dates/datetimes, currently I just have them do nothing when edited as I couldn't find an easy way to make the resultant QDate(Time)Edit object, well, uneditable, and aside from looking prettier there appears to be little point. However, I can look into making the static representation of dates and times more pretty/human readable like in the QDate(Time)Editor rather than just the raw format, either in this or a separate PR.

@pep8speaks
Copy link

pep8speaks commented Dec 16, 2017

Hello @CAM-Gerlach! Thanks for updating the PR.

Line 477:9: E265 block comment should start with '# '

Comment last updated on December 26, 2017 at 00:13 Hours UTC

@CAM-Gerlach
Copy link
Member Author

Seeing that the date and datetime editor branches are (now) entirely duplicate code except for one line, I refactored it to unify them. Good idea? Bad idea? I can rollback if you disagree, but I figured I'd put it out there for your feedback.

Also, can the pep8speaks warning be ignored, given that I didn't change the format of the comment line and all the others use the same format?

if readonly:
return None
else:
if isinstance(value, datetime.datetime):
Copy link
Member

Choose a reason for hiding this comment

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

Is datetime.datetime an instance of datetime.date?

Copy link
Member

Choose a reason for hiding this comment

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

If this is the case, then your refactoring is correct. Else, you have to revert it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes indeed, and I tested to confirm.

@ccordoba12
Copy link
Member

ccordoba12 commented Dec 16, 2017

Please try to do that in another PR. PRs should stay as simple and focused and possible so we can merge them quickly.

@CAM-Gerlach
Copy link
Member Author

CAM-Gerlach commented Dec 18, 2017

@ccordoba12 Just realized while checking the status of this PR that I must have accidentally edited your comment thinking it was mine, not being used to my new Member powers, x(

Please try to do that in another PR. PRs should stay as simple and focused and possible so we can merge them quickly.

Yes indeed; already working on it. Should be simple enough, but well out of scope of this one. [Already done a while ago, PR #6000 )

@CAM-Gerlach
Copy link
Member Author

CAM-Gerlach commented Dec 19, 2017

I assume I'll want to add tests to check that directly editable values (and perhaps such values inside of sub-objects, lists, etc) really are treated as uneditable when part of an immutable object (e.g. a tuple)?

@ccordoba12
Copy link
Member

@CAM-Gerlach, it seems a really hard test to create. I think what you've done so far is really good for now.

@CAM-Gerlach
Copy link
Member Author

CAM-Gerlach commented Dec 19, 2017

Okay. Wouldn't a simple way to unit test my proximate change be to just assert that, when readonly=True, the createEditor method of CollectionsDelegate returns None for directly editable values (and properly returns an editor when readonly=False, and for collections types). Of course, that wouldn't catch everything that could go wrong, but it would ensure there isn't a regression on the current change....but if you think it isn't worth it, then its up to you of course and feel free to merge as is.

@ccordoba12
Copy link
Member

Nice! I think it's a good compromise, so please go ahead with it.

@CAM-Gerlach
Copy link
Member Author

Sure, will do...

@ccordoba12
Copy link
Member

Is this one ready?

@CAM-Gerlach
Copy link
Member Author

Yup, if you think so.

Copy link
Member

@ccordoba12 ccordoba12 left a comment

Choose a reason for hiding this comment

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

Really nice job with the test you added @CAM-Gerlach! You finally made it work 👍

@ccordoba12 ccordoba12 merged commit b5af395 into spyder-ide:3.x Dec 26, 2017
@goanpeca
Copy link
Member

Awesome work @CAM-Gerlach :-)

ccordoba12 added a commit that referenced this pull request Dec 26, 2017
@CAM-Gerlach
Copy link
Member Author

^_^ Sorry I got a tad frustrated; really, the only tough part where I got stuck was knowing (how) to monkeypatch the relative rather than absolute paths to the modules. After I took a break to get some sleep I figured that had to be it...I just should have taken a step back earlier instead of getting too sucked in, heh.

@CAM-Gerlach CAM-Gerlach deleted the tuples-uneditable branch December 29, 2017 03:27
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.

4 participants