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

Better default font for editor #68933

Closed
roseman mannequin opened this issue Jul 29, 2015 · 20 comments
Closed

Better default font for editor #68933

roseman mannequin opened this issue Jul 29, 2015 · 20 comments
Assignees
Labels
topic-IDLE type-feature A feature request or enhancement

Comments

@roseman
Copy link
Mannequin

roseman mannequin commented Jul 29, 2015

BPO 24745
Nosy @terryjreedy, @kbkaiser, @larryhastings, @benjaminp, @ned-deily, @serwy, @roseman
Files
  • defaultfont.png: Screenshots of default and proposed improved fonts on OS X, Windows, Linux
  • defaultfont.patch: Patch to look for TkFixedFont in config file
  • 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:

    assignee = 'https://github.com/terryjreedy'
    closed_at = <Date 2015-09-04.08:42:25.063>
    created_at = <Date 2015-07-29.00:17:07.792>
    labels = ['expert-IDLE', 'type-feature']
    title = 'Better default font for editor'
    updated_at = <Date 2016-05-09.16:10:12.632>
    user = 'https://github.com/roseman'

    bugs.python.org fields:

    activity = <Date 2016-05-09.16:10:12.632>
    actor = 'terry.reedy'
    assignee = 'terry.reedy'
    closed = True
    closed_date = <Date 2015-09-04.08:42:25.063>
    closer = 'terry.reedy'
    components = ['IDLE']
    creation = <Date 2015-07-29.00:17:07.792>
    creator = 'markroseman'
    dependencies = []
    files = ['40048', '40091']
    hgrepos = []
    issue_num = 24745
    keywords = ['patch']
    message_count = 20.0
    messages = ['247549', '247555', '247556', '247614', '247639', '247679', '247787', '247835', '247836', '247837', '248333', '248336', '248347', '248348', '248466', '249727', '249742', '249743', '263200', '265205']
    nosy_count = 8.0
    nosy_names = ['terry.reedy', 'kbk', 'larry', 'benjamin.peterson', 'ned.deily', 'roger.serwy', 'markroseman', 'python-dev']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue24745'
    versions = ['Python 2.7', 'Python 3.4', 'Python 3.5', 'Python 3.6']

    @roseman
    Copy link
    Mannequin Author

    roseman mannequin commented Jul 29, 2015

    By default, IDLE chooses courier for the text editor font.

    As you'll see from the attached screenshot, while this looks ok on Windows, it's inconsistent with the standard fixed width fonts on Linux and OS X, and borders on unreadable particularly on the latter.

    While this can be changed via the configuration dialog (the 'fixed' versions in the screenshots do just that), this is one of the things that really jumps out at you the first time you run IDLE, and not in a good way.

    Tk defines a font named 'TkFixedFont', which we should take advantage of instead of hardcoding courier; details of the font can be retrieved via

    tkinter.font.nametofont('TkFixedFont').actual()
    

    Note there's a bit of an overlap here with #<20580>, but suggests that there may be some cases where determining defaults programmatically rather than hardcoding multiple defaults may be appropriate.

    @roseman roseman mannequin added topic-IDLE type-feature A feature request or enhancement labels Jul 29, 2015
    @terryjreedy
    Copy link
    Member

    I agree that Courier is ugly and a bad thing to hardcode. I long ago switched to Lucida Console, which other than i and l is very close to the Mac/linux examples. I had forgotten that Courier was the default.

    Ned, am I correct in thinking you would like this?

    Mark, please submit a patch. Too bad that tk does not use something better for Windows too, but I agree that Courier is least bad here.

    PS. Leave brackets off issue references like bpo-20580 so they become links. The overlap is minimal; in any case, that issue will need several patches and subissues.

    @terryjreedy terryjreedy self-assigned this Jul 29, 2015
    @ned-deily
    Copy link
    Member

    With current ActiveTcl 8.5.18 on OS X, "TkFixedFont" translates to Monaco 11 point which looks fine on my laptop. I don't have a Retina display handy to see how it looks there but it's probably an improvement over Courier so changing the default sounds good to me.

    @roseman
    Copy link
    Mannequin Author

    roseman mannequin commented Jul 29, 2015

    Quick question how best to represent this in the config-main.def file. My thought is to leave a "font=" line there so that the GetOption call returns an empty string. The editor code can then detect that and substitute TkFixedFont.

    Would this break anything and/or would there be a more preferred approach?

    @terryjreedy
    Copy link
    Member

    For the benefit of anyone reading the file, I would prefer "font = TkFixedFont", though I notice that LoadFontConfig has a backup default.

    Just as important, I think: IDLE Preferences => Font/Tabs => Editor Base Font needs a [Default] button so people can unselect a non-default selection without remembering what the default was. Other changes (re-arrangements) are needed to use the space better, but for now, I think increasing the height to make room would be sufficient. Or perhaps 'TkFixedFont could be added to the top of the list before adding the sorted list of those available.

    The tricky issue is this: when a user changes a setting, the change is saved to a change dictionary. When [Apply] or [OK] are clicked, the new values are compared to the defaults and non-defaults are written to the user file. (Some files get sets of values written). So a user needs to be able to select 'TkFixedFont' to avoid having a specific font written to the user file (which might be the only item in the file, and which would override a future change to the binding of TkFixedFont).

    @roseman
    Copy link
    Mannequin Author

    roseman mannequin commented Jul 30, 2015

    I'm ok with putting TkFixedFont in the config file. Only potential downside I see is that the code will look for this specific value, but people may read the config file and assume it could be changed to any Tk*Font.

    I'd strongly argue against putting in a default button and/or including TkFixedFont in the list for the following reasons:

    1. The config dialog should really be using the platform-specific font chooser for this anyway. (Tk 8.6 does include this dialog btw). The default dialogs don't allow anything like that, and I can't off the top of my head think of any common applications that allow you to revert back to a default.

    2. I see no real advantage to being able to switch 'back' to a default. In fact, from the user perspective, there isn't conceptually a default font separate than whatever the 'actual' version of TkFixedFont is (courier, monaco, whatever). What they know is it starts with a certain font, and if they go into the dialog, it shows that font. If they change to a different font (or even back to the original font), that's what shows up next time they start the app.

    Is there actually a downside to writing out the per-user config file even if there isn't a "real" change in the font?

    @roseman
    Copy link
    Mannequin Author

    roseman mannequin commented Jul 31, 2015

    I've attached defaultfont.patch which will look for the magic value 'TkFixedFont' in the configuration file and do some appropriate magic with it. Most of the font handling smarts are now in a 'GetFont' call in configHandler, which as a bonus reduces some of the complexity and duplication elsewhere.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Aug 1, 2015

    New changeset 55e5f7766d2c by Terry Jan Reedy in branch '2.7':
    bpo-24745: Switch from Courier to platform-sensitive TkFixedFont as default
    https://hg.python.org/cpython/rev/55e5f7766d2c

    New changeset 5c992189414f by Terry Jan Reedy in branch '3.4':
    bpo-24745: Switch from Courier to platform-sensitive TkFixedFont as default
    https://hg.python.org/cpython/rev/5c992189414f

    New changeset 90c02a0bec08 by Terry Jan Reedy in branch '3.5':
    bpo-24745: Merge with 3.4
    https://hg.python.org/cpython/rev/90c02a0bec08

    New changeset 3a731756f9cc by Terry Jan Reedy in branch 'default':
    bpo-24745: Merge with 3.5
    https://hg.python.org/cpython/rev/3a731756f9cc

    @terryjreedy
    Copy link
    Member

    Review published with the changes I made, tested, and committed.

    I am not convinced that writing all 3 font attributes is needed, which is good since existing user files do not have all 3. But safer for future. Part of my preference to avoid user file when not needed (because only config matches default) is because user files are an occasional point of failure. But we should fix bugs noted in TODOs and on tracker.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Aug 1, 2015

    New changeset 82198ae039cd by Terry Jan Reedy in branch '3.4':
    bpo-24745: Add ACKS entry.
    https://hg.python.org/cpython/rev/82198ae039cd

    New changeset bf14b74d6fc0 by Terry Jan Reedy in branch '3.5':
    bpo-24745: Add ACKS entry.
    https://hg.python.org/cpython/rev/bf14b74d6fc0

    New changeset 5744985ad8dc by Terry Jan Reedy in branch '2.7':
    bpo-24745: Add ACKS entry.
    https://hg.python.org/cpython/rev/5744985ad8dc

    @ned-deily
    Copy link
    Member

    Unfortunately, we didn't test this change with Tk 8.4: TkFixedFont does not exist in 8.4. This means that, unless the user has already modified the IDLE configuration to use an explicit font, IDLE linked with Tk 8.4 crashes in initialization.

    $ mv .idlerc/ .idlerc-OLD
    $ idle3.5
    Traceback (most recent call last):
      File "/usr/local/bin/idle3.5", line 5, in <module>
        main()
      File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/idlelib/PyShell.py", line 1560, in main
        shell = flist.open_shell()
      File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/idlelib/PyShell.py", line 320, in open_shell
        self.pyshell = PyShell(self)
      File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/idlelib/PyShell.py", line 867, in __init__
        OutputWindow.__init__(self, flist, None, None)
      File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/idlelib/OutputWindow.py", line 16, in __init__
        EditorWindow.__init__(self, *args)
      File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/idlelib/EditorWindow.py", line 233, in __init__
        text['font'] = idleConf.GetFont(self.root, 'main', 'EditorWindow')
      File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/idlelib/configHandler.py", line 691, in GetFont
        f = Font(name='TkFixedFont', exists=True, root=root)
      File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/tkinter/font.py", line 87, in __init__
        "named font %s does not already exist" % (self.name,))
    _tkinter.TclError: named font TkFixedFont does not already exist
    n

    A workaround is to manually create or edit the IDLE configuration file and define an explicit font, for example on OS X:

    $ cat > ~/.idlerc/config-main.cfg <<EOF
    [EditorWindow]
    font-size = 11
    font = monaco
    EOF

    This is a release blocker for 3.5.0, first seen in 3.5.0rc1.

    @larryhastings
    Copy link
    Contributor

    We're retagging 3.5.0rc1 to fix this and one other regression. Can someone step up and get this fix checked in in the next six or eight hours? You can just check in to the 3.5 branch on hg.python.org/cpython like normal (you won't have to use Bitbucket and "pull requests" for this).

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Aug 10, 2015

    New changeset e39c4373b83f by Ned Deily in branch '3.5':
    Issue bpo-24745: Prevent IDLE initialization crash with Tk 8.4:
    https://hg.python.org/cpython/rev/e39c4373b83f

    New changeset 8c55fb5a11d8 by Ned Deily in branch 'default':
    Issue bpo-24745: merge from 3.5
    https://hg.python.org/cpython/rev/8c55fb5a11d8

    @ned-deily
    Copy link
    Member

    At Larry's request so that we can get 3.5.0rc1 out the door, I've checked in a temporary fix for 3.5 (and for 3.6) that should prevent the IDLE crash when linked with Tk 8.4. I'll leave the issue open for Terry to review and provide the final fix for all branches.

    @terryjreedy
    Copy link
    Member

    I just returned from a trip. I think restoring the status quo is sufficient, so I will likely apply to 2.7 and 3.4 and null merge forward.

    Is there anyway to get test run with 8.4 automatically, as least intermittantly, before the rc?

    @larryhastings
    Copy link
    Contributor

    Anything happening with this? We tag 3.5.0rc3 in about 36 hours.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Sep 4, 2015

    New changeset 34a8078f6249 by Terry Jan Reedy in branch '2.7':
    Issue bpo-24745: Prevent IDLE initialization crash with Tk 8.4; patch by Ned Deily.
    https://hg.python.org/cpython/rev/34a8078f6249

    New changeset b4830b9f8c10 by Terry Jan Reedy in branch '3.4':
    Issue bpo-24745: Prevent IDLE initialization crash with Tk 8.4; patch by Ned Deily.
    https://hg.python.org/cpython/rev/b4830b9f8c10

    @terryjreedy
    Copy link
    Member

    I backported change already in 3.5.0+.

    @terryjreedy
    Copy link
    Member

    The change from "Courier" to "TkDefaultFont" causes Options => Configure IDLE to fail at least on Arch Linux (bpo-26673) and Fedora 23 (also bpo-24951). The reason is still obscure to me. I will leave this closed, close bpo-24951 as duplicate, and patch on bpo-26673 (which has more information).

    @terryjreedy
    Copy link
    Member

    This change caused a regression on Linux with 8.6.4 because TkFixedFont ends up with size = 0. Cannot open configuration file. See bpo-26673.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    topic-IDLE type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants