-
-
Notifications
You must be signed in to change notification settings - Fork 31.5k
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-31004: IDLE: Factor out FontPage class from configdialog (step 1) #2905
Conversation
Lib/idlelib/configdialog.py
Outdated
@@ -1849,6 +1849,219 @@ def save_all_changed_extensions(self): | |||
self.ext_userCfg.Save() | |||
|
|||
|
|||
class FontPage: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class FontPage(object)
for new style of class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, but I honestly don't know the preference for this in Python 3. The new style class is for compatibility with Python 2.
https://stackoverflow.com/questions/4015417/python-class-inherits-object#9448136
"In Python 3, apart from compatibility between Python 2 and 3, no. In Python 2, yes."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are writing 3.6+ code, including using f-strings, so '(object)' is just noise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine so far. My comments are mostly about looking ahead to the next two steps to anticipate possible problems.
Lib/idlelib/configdialog.py
Outdated
@@ -1849,6 +1849,219 @@ def save_all_changed_extensions(self): | |||
self.ext_userCfg.Save() | |||
|
|||
|
|||
class FontPage: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are writing 3.6+ code, including using f-strings, so '(object)' is just noise.
Lib/idlelib/configdialog.py
Outdated
@@ -1853,6 +1853,219 @@ def save_all_changed_extensions(self): | |||
self.ext_userCfg.Save() | |||
|
|||
|
|||
class FontPage: | |||
|
|||
def __init__(self, parent, tab_pages, highlight_sample): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At step 2, testing FontPage isolated, passing in Func() when creating an instance of FontPage would work. But the mock could also be set on the instance after creating it. At step 3, testing FontPage live, FontPage will be created by ConfigDialog. highlight_sample will not exist until PageHighlight is called to create and initialize its widgits, first. At that point, it can be retrieved using tab_pages. Lets leave this for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there anything that would allow us to create highlight_sample outside of both FontPage and ThemePage and let both of them access it? A superclass would seem a bit much, but I don't know if can just be in ConfigDialog and then have self.highlight_sample sent to the 2 classes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One other thing that I wasn't sure about - whether to send all of tab_pages to FontPage or to just send the frame as the parameter. The main reason is this line in FontPage:
frame = self.tab_pages.pages['Fonts/Tabs'].frame
Since the pages['Fonts/Tabs']
is defined in ConfigDialog.create_widgets invokes TabbedPageSet, I'm not sure if it's correct to reference it within another class.
So, then the init would be def __init__(self, parent, frame, highlight_sample):
and the instantiation would be font_page = FontPage(self.parent, self.tab_pages.pages['Fonts/Tabs'].frame, self.highlight_sample)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Creating a default Text in create_widgets would work for setting the options (in the two pages). However, 'parent' is not a resettable 'option' and it must be the frame the widget is to appear in. So the Text call must be where it is.
I believe you are referencing issues in https://en.wikipedia.org/wiki/Law_of_Demeter.
A ttk notebook is initialized empty. Tabs are added with note.add(someframe, text='tab title'). If we used that, the new classed would be Frame subclasses. I will try a quick experiment with Notebook.
There would still be the issue that the hightlight frame must exist before the font frame is initialized. We can always stick with the current design of calling all the load methods after all the frames are created.
Lib/idlelib/configdialog.py
Outdated
def __init__(self, parent, tab_pages, highlight_sample): | ||
self.parent = parent | ||
self.tab_pages = tab_pages | ||
self.highlight_sample = highlight_sample |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And remove this statement. change my mind for now.
Lib/idlelib/configdialog.py
Outdated
self.highlight_sample = highlight_sample | ||
self.create_page_font_tab() | ||
self.load_font_cfg() | ||
self.load_tab_cfg() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Loading immediately instead of waiting until all pages are created should be ok. requires that self.highlight exist, because set_samples is called. Making ConfigDialog pass tab_pages.pages['highlight'].highlight_sample
is messy (such a detail should normally be hidden) but makes the creation order requirement obvious. As long as there are no circular dependencies, immediate loading is okay, but I can see why something decided to punt on the issue. (As far as I know, this is the only cross-page dependency.)
Lib/idlelib/configdialog.py
Outdated
def var_changed_space_num(self, *params): | ||
"Store change to indentation size." | ||
value = self.space_num.get() | ||
changes.add_option('main', 'Indent', 'num-spaces', value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not have been deleted here or in the original. It was an error in the test that it could still pass.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry about that. I was severely git-challenged yesterday. I thought I had restored everything correctly, but I must have missed this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please test on *nix. Otherwise, I believe this is ready to merge.
Lib/idlelib/configdialog.py
Outdated
@@ -1894,7 +1894,8 @@ def create_page_font_tab(self): | |||
|
|||
# Create widgets: | |||
# body and body section frames. | |||
frame = self.tab_pages.pages['Fonts/Tabs'].frame | |||
# frame = self.tab_pages.pages['Fonts/Tabs'].frame | |||
frame = self.parent |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
frame = self once class is made a frame
@@ -57,10 +57,12 @@ class FontTest(unittest.TestCase): | |||
@classmethod | |||
def setUpClass(cls): | |||
dialog.set_samples = Func() # Mask instance method. | |||
tracers.attach() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tracers for everything except FontFrame are already attached by ConfigDialog. The new FontPage must leave this true. I am adjusting it to make it do so. All tracers are detached in tearDownModule.
Looks on good Ubuntu. Ran the testsuite and the htests. |
…tep 1) (pythonGH-2905) The slightly modified tests continue to pass. The General test broken by the switch to Notebook is fixed. Patch mostly by Cheryl Sabella. (cherry picked from commit 9397e2a)
Test on MacOS, works well. |
Thanks for the Mac test. That should tests everything prior to this also. |
https://bugs.python.org/issue31004