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

Work around a difference between PyQt4 and PySide QFont #54

Merged
merged 2 commits into from
Sep 24, 2013
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions enaml/qt/q_resource_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,27 @@
from .QtGui import QColor, QFont, QImage, QIcon, QPixmap


from ..fontext import FontStyle, FontCaps
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you change this to "from enaml.fontext import ..."? I'm not fan of relative imports above the current (sub)package level.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.



# Mapping from enaml font styles to Qt font styles.
_qfont_style_mapping = {
FontStyle.Normal: QFont.Style.StyleNormal,
FontStyle.Italic: QFont.Style.StyleItalic,
FontStyle.Oblique: QFont.Style.StyleOblique,
}


# Mapping from enaml capitalization modes to Qt capitalization modes.
_qfont_capitalization_mapping = {
FontCaps.MixedCase: QFont.Capitalization.MixedCase,
FontCaps.AllUppercase: QFont.Capitalization.AllUppercase,
FontCaps.AllLowercase: QFont.Capitalization.AllLowercase,
FontCaps.SmallCaps: QFont.Capitalization.SmallCaps,
FontCaps.Capitalize: QFont.Capitalization.Capitalize,
}


ASPECT_RATIO_MODE = {
'ignore': Qt.IgnoreAspectRatio,
'keep': Qt.KeepAspectRatio,
Expand Down Expand Up @@ -185,8 +206,8 @@ def QFont_from_Font(font):

"""
qfont = QFont(font.family, font.pointsize, font.weight)
qfont.setStyle(font.style)
qfont.setCapitalization(font.caps)
qfont.setStyle(_qfont_style_mapping[font.style])
qfont.setCapitalization(_qfont_capitalization_mapping[font.caps])
return qfont


Expand Down
17 changes: 17 additions & 0 deletions tests/test_q_resource_helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#------------------------------------------------------------------------------
# Copyright (c) 2013, Nucleic Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING.txt, distributed with this software.
#------------------------------------------------------------------------------
from enaml.fontext import Font
from enaml.qt.q_resource_helpers import QFont_from_Font


def test_QFont_from_Font():
# Regression test for PySide: QFont_from_Font was raising a TypeError
# in its call to qfont.setStyle(font.style). This test passes if it
# does not raise an exception.
f = Font(family="bold")
qf = QFont_from_Font(f)