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
IDLE: modernize textview module #74680
Comments
First get issue #. |
The initial patch, #1839, adds missing docstrings to textview and changes names to conform to PEP-8. It was originally attached to bpo-30290. I changed the bpo # in the title to 30495. We will see if Belvedere bot corrects the linkage. Cheryl: I forgot to mention something very important. When we change externally accessible names -- those of functions, classes, and attributes -- in module xyz (here textview), we must grep idlelib *recursively* to find modules and test modules that import xyz and then check all accesses to names within xyz to discover and fix any that we have broken. (If everything were perfectly tested, discovery would be trivial: run test_idlelib. But it is not, so we must grep.) In this case, the change from textview.TextViewer.textView to textview.TextViewer.textview broke the two copies of I will change the attribute name to 'text' both to avoid confusion with the module name and since the value is a Text instance. I will also change all the new uses of 'textview' as an attribute. |
Grepping shows that other references to textview objects (other than in test_textview) are to unchanged class and function names. |
I plan to merge when checks pass. Not reusing module names avoids noise when grepping for a module name ;-). A final search for 'textview', match case, whole word, gave 18 hits, which were easy to check. |
Thanks Terry! I had done a search in Spyder using "textView" and only found those files that I changed, but now I see what I did wrong. If I do it within a different git branch that isn't up to update with the master, it won't show up, but if I do it in the proper branch, it does show up. I'm learning git, so now I know to be more careful when searching. I should grep it too, just to see how git and grep work together. I ran the test on the one file I changed, but now I know to run it on the whole test suite. I should have realized that. Thanks again for all your patience. |
What I have learned:
One can often, perhaps even 'usually', get away with not doing the above, but occasional mysterious glitches can occur. Example: when I created a branch from your bdb docstring PR, 9 days later, and did not update, 'import re' failed in the new branch. Problem disappeared after update. By 'grep', I mean any multi-file search, starting in a specified directory, such as IDLE's 'Find in Files', not the specific unix program. I develop code and test for x by repeatedly running just 'test_x', but grepping and running test_idle before commit is essential. As we expand test files, test_idle will become more and more useful. |
I believe you said elsewhere that you would like to try the refactoring that splits a window+frame class into a window class and a frame class. It would be great if you became good at doing this. If the current class name is used externally, I might consider reusing it for the window class. But since the external interface for textview is the two wrapper functions, 'TextView' is not used externally. F:\dev\cpython\lib\idlelib\idle_test\test_textview.py: 3: Since all methods and functions create (or destroy) a TextViewer, which So lets try TextviewWindow and TextviewFrame. Make the obvious substitutions, except in the PyShell and line 78 and 91 comments, 'TextViewer' should become a generic 'text viewer' that would apply to TextviewFrame if that became the main entry point. If you want to show me an incomplete patch, you can still upload diffs here. |
I've attached a patch for textview for your review. Thanks for suggesting that. I still need to work on test_textview. Some comments/questions:
|
Responses (without yet testing the code):
So we don't need the new ButtonFrame class. I suspect that we do not even need the current button frame containing just one button. But removing that can be deferred.
6&7. I prefer the newer, more Pythonic, subscript access and, as I said before, string literals. There main issue is making isolated changes in untested code versus doing the same in well-tested code as part of refactoring and line-by-line examination.
+ x = parent.winfo_rootx() + 10,
Are you aware that running gui code files runs a visual sanity check that brings up an instance of the window? One can quickly check the effects of changing gui code.
|
Thanks for all the info. I've made another patch for textfile.py with removing ButtonFrame. I've also included test_textfile.py and help_about.py in the patch. I had worked on help_about yesterday, so if you don't like the button classes, I may need to undo it. However, since they do a lot of 'stuff' maybe it would be similar to the HelpText class in help.py? It seems more readable to me compared to when I first looked at the file. Although, the place_widgets is still messy. 2: Need to bookmark and spend time with this. For #5 and #8, it sounds like using f-strings is OK even though it only is 3.6+, so then super() should be OK too? 9: Yes, I've been doing that to test all my changes. It's nice to use since at times, I've lost the window entirely. And I get feedback in the console with the line error when it doesn't work. I also get to play with the settings to understand what something does. :-) New questions:
Thanks! |
|
Old 2, references; my other main bookmark is the tk reference. |
Hi Terry, Were you waiting on me for changes to the patch or would you like me to make a PR? Thanks! |
You were waiting on my review of the revised patch.
Test_help_about needs two insertions of '.textframe' to solve Traceback (most recent call last):
File "f:\dev\3x\lib\idlelib\idle_test\test_help_about.py", line 67, in test_file_buttons
dialog._current_textview.text.get('1.0', '1.end'))
AttributeError: 'TextviewWindow' object has no attribute 'text' ====================================================================== Traceback (most recent call last):
File "f:\dev\3x\lib\idlelib\idle_test\test_help_about.py", line 48, in test_printer_buttons
dialog._current_textview.text.get('1.0', '1.end'))
AttributeError: 'TextviewWindow' object has no attribute 'text' Make a PR this time so I can review a side-by-side diff and retest. |
Thanks, Terry. I've pulled the textview changes out and made a PR. I know I'll take a look at help_about separately. On Mon, Jun 19, 2017 at 6:16 PM, Cheryl Sabella <report@bugs.python.org>
|
I have some questions about the final version:
Thanks! |
I was trying to think of 2 possible future uses of ViewFrame in addition to current embedding in in ViewWindows: embedded in a tab, and tiled in a panel. With no window close [X] buttom, the button in a frame will be needed, so I left it. Since the button is now [Close] rather than [OK], the function should be close rather than ok. I copied, rather than cut, before pasting and editing. The Windows button is not needed. The window ok is for the protocol call, but I don't really know if that is needed. Tk apps seem to work without it. I may investigate more someday. Leave it for now. By calling window destroy directly, the frame close will survive window close being deleted, but not window close being edited to add other actions. |
Ping? ISTM this could be considered done. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: