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-31004: IDLE: Factor out FontPage class from configdialog (step 1) #2905

Merged
merged 10 commits into from
Jul 30, 2017

Conversation

csabella
Copy link
Contributor

@csabella csabella commented Jul 27, 2017

@@ -1849,6 +1849,219 @@ def save_all_changed_extensions(self):
self.ext_userCfg.Save()


class FontPage:
Copy link
Contributor

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

Copy link
Contributor Author

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."

Copy link
Member

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.

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.

Looks fine so far. My comments are mostly about looking ahead to the next two steps to anticipate possible problems.

@@ -1849,6 +1849,219 @@ def save_all_changed_extensions(self):
self.ext_userCfg.Save()


class FontPage:
Copy link
Member

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.

@@ -1853,6 +1853,219 @@ def save_all_changed_extensions(self):
self.ext_userCfg.Save()


class FontPage:

def __init__(self, parent, tab_pages, highlight_sample):
Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Contributor Author

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)

Copy link
Member

@terryjreedy terryjreedy Jul 28, 2017

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.

def __init__(self, parent, tab_pages, highlight_sample):
self.parent = parent
self.tab_pages = tab_pages
self.highlight_sample = highlight_sample
Copy link
Member

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.

self.highlight_sample = highlight_sample
self.create_page_font_tab()
self.load_font_cfg()
self.load_tab_cfg()
Copy link
Member

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.)

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)
Copy link
Member

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.

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 about that. I was severely git-challenged yesterday. I thought I had restored everything correctly, but I must have missed this.

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.

Please test on *nix. Otherwise, I believe this is ready to merge.

@@ -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
Copy link
Member

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()
Copy link
Member

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.

@csabella
Copy link
Contributor Author

Looks on good Ubuntu. Ran the testsuite and the htests.

@terryjreedy terryjreedy merged commit 9397e2a into python:master Jul 30, 2017
terryjreedy pushed a commit to terryjreedy/cpython that referenced this pull request Jul 30, 2017
…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)
terryjreedy added a commit that referenced this pull request Jul 30, 2017
…tep 1) (GH-2905) (#2950)

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)
@csabella csabella deleted the bpo31004 branch July 30, 2017 19:32
@mlouielu
Copy link
Contributor

mlouielu commented Aug 1, 2017

Test on MacOS, works well.

@terryjreedy
Copy link
Member

Thanks for the Mac test. That should tests everything prior to this also.

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