classification
Title: Better default font for editor
Type: enhancement Stage: resolved
Components: IDLE Versions: Python 3.6, Python 3.5, Python 3.4, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: terry.reedy Nosy List: benjamin.peterson, kbk, larry, markroseman, ned.deily, python-dev, roger.serwy, terry.reedy
Priority: normal Keywords: patch

Created on 2015-07-29 00:17 by markroseman, last changed 2016-05-09 16:10 by terry.reedy. This issue is now closed.

Files
File name Uploaded Description Edit
defaultfont.png markroseman, 2015-07-29 00:17 Screenshots of default and proposed improved fonts on OS X, Windows, Linux
defaultfont.patch markroseman, 2015-07-31 23:22 Patch to look for TkFixedFont in config file review
Messages (20)
msg247549 - (view) Author: Mark Roseman (markroseman) * Date: 2015-07-29 00:17
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.
msg247555 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2015-07-29 03:14
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 #20580 so they become links. The overlap is minimal; in any case, that issue will need several patches and subissues.
msg247556 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2015-07-29 04:12
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.
msg247614 - (view) Author: Mark Roseman (markroseman) * Date: 2015-07-29 20:04
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?
msg247639 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2015-07-29 22:42
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).
msg247679 - (view) Author: Mark Roseman (markroseman) * Date: 2015-07-30 15:05
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?
msg247787 - (view) Author: Mark Roseman (markroseman) * Date: 2015-07-31 23:22
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.
msg247835 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-08-01 22:59
New changeset 55e5f7766d2c by Terry Jan Reedy in branch '2.7':
Issue 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':
Issue 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':
Issue 24745: Merge with 3.4
https://hg.python.org/cpython/rev/90c02a0bec08

New changeset 3a731756f9cc by Terry Jan Reedy in branch 'default':
Issue 24745: Merge with 3.5
https://hg.python.org/cpython/rev/3a731756f9cc
msg247836 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2015-08-01 23:06
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.
msg247837 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-08-01 23:16
New changeset 82198ae039cd by Terry Jan Reedy in branch '3.4':
Issue 24745: Add ACKS entry.
https://hg.python.org/cpython/rev/82198ae039cd

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

New changeset 5744985ad8dc by Terry Jan Reedy in branch '2.7':
Issue 24745: Add ACKS entry.
https://hg.python.org/cpython/rev/5744985ad8dc
msg248333 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2015-08-09 19:43
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.
msg248336 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2015-08-09 20:46
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).
msg248347 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-08-10 03:25
New changeset e39c4373b83f by Ned Deily in branch '3.5':
Issue #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 #24745: merge from 3.5
https://hg.python.org/cpython/rev/8c55fb5a11d8
msg248348 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2015-08-10 03:31
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.
msg248466 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2015-08-12 17:30
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?
msg249727 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2015-09-04 07:10
Anything happening with this?  We tag 3.5.0rc3 in about 36 hours.
msg249742 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-09-04 08:40
New changeset 34a8078f6249 by Terry Jan Reedy in branch '2.7':
Issue #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 #24745: Prevent IDLE initialization crash with Tk 8.4; patch by Ned Deily.
https://hg.python.org/cpython/rev/b4830b9f8c10
msg249743 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2015-09-04 08:42
I backported change already in 3.5.0+.
msg263200 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2016-04-11 19:38
The change from "Courier" to "TkDefaultFont" causes Options => Configure IDLE to fail at least on Arch Linux (#26673) and Fedora 23 (also #24951).  The reason is still obscure to me.  I will leave this closed, close #24951 as duplicate, and patch on #26673 (which has more information).
msg265205 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2016-05-09 16:10
This change caused a regression on Linux with 8.6.4 because TkFixedFont ends up with size = 0.  Cannot open configuration file.  See #26673.
History
Date User Action Args
2016-05-09 16:10:12terry.reedysetmessages: + msg265205
2016-04-11 19:38:32terry.reedysetmessages: + msg263200
2015-09-04 08:42:25terry.reedysetstatus: open -> closed
priority: deferred blocker -> normal
messages: + msg249743

resolution: fixed
stage: needs patch -> resolved
2015-09-04 08:40:00python-devsetmessages: + msg249742
2015-09-04 07:10:16larrysetmessages: + msg249727
2015-08-12 17:30:07terry.reedysetmessages: + msg248466
2015-08-10 03:31:25ned.deilysetpriority: release blocker -> deferred blocker

messages: + msg248348
2015-08-10 03:25:19python-devsetmessages: + msg248347
2015-08-09 20:46:59larrysetmessages: + msg248336
2015-08-09 19:44:02ned.deilysetmessages: - msg248332
2015-08-09 19:43:50ned.deilysetmessages: + msg248333
2015-08-09 19:39:16ned.deilysetstatus: closed -> open
priority: normal -> release blocker


nosy: + benjamin.peterson, larry
messages: + msg248332
resolution: fixed -> (no value)
stage: resolved -> needs patch
2015-08-01 23:16:07python-devsetmessages: + msg247837
2015-08-01 23:06:37terry.reedysetstatus: open -> closed
resolution: fixed
messages: + msg247836

stage: resolved
2015-08-01 22:59:06python-devsetnosy: + python-dev
messages: + msg247835
2015-07-31 23:22:01markrosemansetfiles: + defaultfont.patch
keywords: + patch
messages: + msg247787
2015-07-30 15:05:37markrosemansetmessages: + msg247679
2015-07-30 03:39:18terry.reedysetmessages: - msg247648
2015-07-30 03:38:07terry.reedysetmessages: + msg247648
2015-07-29 22:42:59terry.reedysetmessages: + msg247639
2015-07-29 21:21:52terry.reedysetversions: + Python 3.6
2015-07-29 20:04:14markrosemansetmessages: + msg247614
2015-07-29 04:12:43ned.deilysetmessages: + msg247556
2015-07-29 03:14:25terry.reedysetassignee: terry.reedy

messages: + msg247555
nosy: + ned.deily
2015-07-29 00:17:08markrosemancreate