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

tkinter.font.Font.measure() broken in 3.5 #68596

Closed
vadmium opened this issue Jun 8, 2015 · 12 comments
Closed

tkinter.font.Font.measure() broken in 3.5 #68596

vadmium opened this issue Jun 8, 2015 · 12 comments
Assignees
Labels
topic-tkinter type-bug An unexpected behavior, bug, or error

Comments

@vadmium
Copy link
Member

vadmium commented Jun 8, 2015

BPO 24408
Nosy @ned-deily, @vadmium, @serhiy-storchaka
Files
  • tkinter_test_font.patch
  • families.patch
  • 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/serhiy-storchaka'
    closed_at = <Date 2015-06-21.11:45:33.981>
    created_at = <Date 2015-06-08.13:22:17.886>
    labels = ['type-bug', 'expert-tkinter']
    title = 'tkinter.font.Font.measure() broken in 3.5'
    updated_at = <Date 2015-06-21.21:04:26.927>
    user = 'https://github.com/vadmium'

    bugs.python.org fields:

    activity = <Date 2015-06-21.21:04:26.927>
    actor = 'ned.deily'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2015-06-21.11:45:33.981>
    closer = 'serhiy.storchaka'
    components = ['Tkinter']
    creation = <Date 2015-06-08.13:22:17.886>
    creator = 'martin.panter'
    dependencies = []
    files = ['39660', '39746']
    hgrepos = []
    issue_num = 24408
    keywords = ['patch']
    message_count = 12.0
    messages = ['245003', '245007', '245008', '245042', '245043', '245147', '245152', '245539', '245590', '245591', '245609', '245610']
    nosy_count = 4.0
    nosy_names = ['ned.deily', 'python-dev', 'martin.panter', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue24408'
    versions = ['Python 2.7', 'Python 3.5', 'Python 3.6']

    @vadmium
    Copy link
    Member Author

    vadmium commented Jun 8, 2015

    >>> import tkinter, tkinter.font
    >>> tk = tkinter.Tk()
    >>> tkinter.font.nametofont("TkHeadingFont").measure("string")
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/home/proj/python/cpython/Lib/tkinter/font.py", line 154, in measure
        return self._root.tk.getint(self._call("font", "measure", self.name, *args))
    AttributeError: 'Font' object has no attribute '_root'

    This appears to be broken by revision cb80dd82d3da, bpo-23880, which included this change at the end of the measure() method:

    -return int(self._call("font", "measure", self.name, *args))
    +return self._root.tk.getint(self._call("font", "measure", self.name, *args))

    The Font class does not have a “_root” attribute.

    @vadmium vadmium added topic-tkinter type-bug An unexpected behavior, bug, or error labels Jun 8, 2015
    @serhiy-storchaka serhiy-storchaka self-assigned this Jun 8, 2015
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jun 8, 2015

    New changeset fb05c1355a90 by Serhiy Storchaka in branch '3.5':
    Issue bpo-24408: Fixed AttributeError in measure() and metrics() methods of
    https://hg.python.org/cpython/rev/fb05c1355a90

    New changeset 0dd70c2c44b4 by Serhiy Storchaka in branch 'default':
    Issue bpo-24408: Fixed AttributeError in measure() and metrics() methods of
    https://hg.python.org/cpython/rev/0dd70c2c44b4

    @serhiy-storchaka
    Copy link
    Member

    Thank you for your report Martin. Unfortunately tests for tkinter.Font are almost not existing. Here is a patch that adds more tests (it should be applied to all versions).

    @vadmium
    Copy link
    Member Author

    vadmium commented Jun 9, 2015

    Thanks for the prompt fix!

    The patch with the tests looks good. I left a query about the existing code.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jun 9, 2015

    New changeset 7e2a7f3fecdf by Serhiy Storchaka in branch '3.4':
    Issue bpo-24408: Added more tkinter.Font tests.
    https://hg.python.org/cpython/rev/7e2a7f3fecdf

    New changeset 24bb564469b4 by Serhiy Storchaka in branch '3.5':
    Issue bpo-24408: Added more tkinter.Font tests.
    https://hg.python.org/cpython/rev/24bb564469b4

    New changeset 47f321ec69dc by Serhiy Storchaka in branch 'default':
    Issue bpo-24408: Added more tkinter.Font tests.
    https://hg.python.org/cpython/rev/47f321ec69dc

    New changeset ae1bc5b65e65 by Serhiy Storchaka in branch '2.7':
    Issue bpo-24408: Added more tkinter.Font tests.
    https://hg.python.org/cpython/rev/ae1bc5b65e65

    @ned-deily
    Copy link
    Member

    Test fails on OS X (10.10) with Cocoa Tk 8.6(.4) and 8.5(.18):

    ======================================================================
    FAIL: test_families (test_tkinter.test_font.FontTest)
    ----------------------------------------------------------------------

    Traceback (most recent call last):
      File "/py/dev/27/root/fwd/Library/Frameworks/pytest_10.10.framework/Versions/2.7/lib/python2.7/lib-tk/test/test_tkinter/test_font.py", line 79, in test_families
        self.assertIn(self.font.actual('family'), families)
    AssertionError: '.Helvetica Neue DeskInterface' not found in ('Academy Engraved LET', 'Al Bayan', 'Al Nile', 'Al Tarikh', 'American Typewriter', 'Andale Mono', 'Arial', 'Arial Black', 'Arial Hebrew', 'Arial Hebrew Scholar', 'Arial Narrow', 'Arial Rounded MT Bold', 'Arial Unicode MS', 'Athelas', 'Avenir', 'Avenir Next', 'Avenir Next Condensed', 'Ayuthaya', 'Baghdad', 'Bangla MN', 'Bangla Sangam MN', 'Bank Gothic', 'Baoli SC', 'Baskerville', 'Beirut', 'Big Caslon', 'Blackmoor LET', 'BlairMdITC TT', 'Bodoni 72', 'Bodoni 72 Oldstyle', 'Bodoni 72 Smallcaps', 'Bodoni Ornaments', 'Bordeaux Roman Bold LET', 'Bradley Hand', 'Brush Script MT', 'Capitals', 'Chalkboard', 'Chalkboard SE', 'Chalkduster', 'Charter', 'Cochin', 'Comic Sans MS', 'Copperplate', 'Corsiva Hebrew', 'Courier', 'Courier New', 'Damascus', 'DecoType Naskh', 'Devanagari MT', 'Devanagari Sangam MN', 'Didot', 'DIN Alternate', 'DIN Condensed', 'Diwan Kufi', 'Diwan Thuluth', 'Euphemia UCAS', 'Farah', 'Farisi', 'Futura', 'GB18030 Bitmap', 'Geeza Pro', 'Geneva', 'Georgia', 'Gill Sans', 'Gujarati MT', 'Gujarati Sangam MN', 'GungSeo', 'Gurmukhi MN', 'Gurmukhi MT', 'Gurmukhi Sangam MN', 'Hannotate SC', 'Hannotate TC', 'HanziPen SC', 'HanziPen TC', 'HeadLineA', 'Heiti SC', 'Heiti TC', 'Helvetica', 'Helvetica Neue', 'Herculanum', 'Hiragino Kaku Gothic Pro', [...]

    @ned-deily ned-deily reopened this Jun 10, 2015
    @vadmium
    Copy link
    Member Author

    vadmium commented Jun 10, 2015

    Some quick googling suggests this “.Helvetica Neue DeskInterface” font is real, and because it begins with a full stop it may be normally hidden from the normal list of fonts. Perhaps the test could be modified to just check the two functions separately:

    • families() returns a non-trivial sequence of font names
    • actual("family") returns a non-trivial string

    @vadmium
    Copy link
    Member Author

    vadmium commented Jun 20, 2015

    Here is a patch to decouple the families() and Font.actual("family") tests as I suggested. Ned, can you confirm if this works on the failing OS X setup? I expect it should be fine.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jun 21, 2015

    New changeset 8e90f3ffa784 by Serhiy Storchaka in branch '2.7':
    Issue bpo-24408: Fixed test for tkinter.Font on OS X.
    https://hg.python.org/cpython/rev/8e90f3ffa784

    New changeset 014ee2df443a by Serhiy Storchaka in branch '3.4':
    Issue bpo-24408: Fixed test for tkinter.Font on OS X.
    https://hg.python.org/cpython/rev/014ee2df443a

    New changeset 5b037f934e40 by Serhiy Storchaka in branch '3.5':
    Issue bpo-24408: Fixed test for tkinter.Font on OS X.
    https://hg.python.org/cpython/rev/5b037f934e40

    New changeset 2d072d07dfe2 by Serhiy Storchaka in branch 'default':
    Issue bpo-24408: Fixed test for tkinter.Font on OS X.
    https://hg.python.org/cpython/rev/2d072d07dfe2

    @serhiy-storchaka
    Copy link
    Member

    Thank you Ned and Martin.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jun 21, 2015

    New changeset 20c9290a5de4 by Ned Deily in branch '2.7':
    Issue bpo-24408: Prevent test_font failures with non-ascii font names.
    https://hg.python.org/cpython/rev/20c9290a5de4

    @ned-deily
    Copy link
    Member

    Thanks for the fix, Martin and Serhiy. With Tk 8.4 on OS X, at least, it is possible to have non-ascii font names. I extended the 2.7 test to account for that.

    @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-tkinter type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants