Skip to content

Commit

Permalink
Merge pull request #211 from dalthviz/fixes_issue_210
Browse files Browse the repository at this point in the history
PR: Handle PySide2 not having `QtGui.QGlyphRun` and add tests jobs with PySide2
  • Loading branch information
ccordoba12 authored Oct 20, 2022
2 parents 18d06ef + e447fbe commit 5a31b9d
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 20 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/linux-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,20 @@ on:

jobs:
linux:
name: Linux Py${{ matrix.PYTHON_VERSION }}
name: Linux Py${{ matrix.PYTHON_VERSION }} - ${{ matrix.QT_BINDING }}
timeout-minutes: 15
runs-on: ubuntu-latest
env:
CI: True
QT_API: ${{ matrix.QT_BINDING }}
PYTHON_VERSION: ${{ matrix.PYTHON_VERSION }}
RUNNER_OS: 'ubuntu'
COVERALLS_REPO_TOKEN: XWVhJf2AsO7iouBLuCsh0pPhwHy81Uz1v
strategy:
fail-fast: false
matrix:
PYTHON_VERSION: ['3.7', '3.8', '3.9', '3.10']
PYTHON_VERSION: ['3.7', '3.10']
QT_BINDING: ['pyqt5', 'pyside2']
steps:
- name: Checkout branch
uses: actions/checkout@v2
Expand All @@ -36,9 +38,11 @@ jobs:
auto-update-conda: false
auto-activate-base: false
python-version: ${{ matrix.PYTHON_VERSION }}
channels: conda-forge
channel-priority: strict
- name: Install dependencies
shell: bash -l {0}
run: conda env update --file requirements/environment.yml
run: conda env update --file requirements/environment_tests.yml
- name: Install Package
shell: bash -l {0}
run: pip install -e .
Expand Down
10 changes: 7 additions & 3 deletions .github/workflows/macos-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@ on:

jobs:
macos:
name: Mac Py${{ matrix.PYTHON_VERSION }}
name: Mac Py${{ matrix.PYTHON_VERSION }} - ${{ matrix.QT_BINDING }}
timeout-minutes: 15
runs-on: macos-latest
env:
CI: True
QT_API: ${{ matrix.QT_BINDING }}
PYTHON_VERSION: ${{ matrix.PYTHON_VERSION }}
RUNNER_OS: 'macos'
strategy:
fail-fast: false
matrix:
PYTHON_VERSION: ['3.7', '3.8', '3.9']
PYTHON_VERSION: ['3.7', '3.10']
QT_BINDING: ['pyqt5', 'pyside2']
steps:
- name: Checkout branch
uses: actions/checkout@v1
Expand All @@ -31,9 +33,11 @@ jobs:
auto-update-conda: false
auto-activate-base: false
python-version: ${{ matrix.PYTHON_VERSION }}
channels: conda-forge
channel-priority: strict
- name: Install package dependencies
shell: bash -l {0}
run: conda env update --file requirements/environment.yml
run: conda env update --file requirements/environment_tests.yml
- name: Install Package
shell: bash -l {0}
run: pip install -e .
Expand Down
10 changes: 7 additions & 3 deletions .github/workflows/windows-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@ on:

jobs:
windows:
name: Windows Py${{ matrix.PYTHON_VERSION }}
name: Windows Py${{ matrix.PYTHON_VERSION }} - ${{ matrix.QT_BINDING }}
timeout-minutes: 15
runs-on: windows-latest
env:
CI: True
QT_API: ${{ matrix.QT_BINDING }}
PYTHON_VERSION: ${{ matrix.PYTHON_VERSION }}
RUNNER_OS: 'windows'
strategy:
fail-fast: false
matrix:
PYTHON_VERSION: ['3.7', '3.8', '3.9', '3.10']
PYTHON_VERSION: ['3.7', '3.10']
QT_BINDING: ['pyqt5', 'pyside2']
steps:
- name: Checkout branch
uses: actions/checkout@v1
Expand All @@ -31,9 +33,11 @@ jobs:
auto-update-conda: false
auto-activate-base: false
python-version: ${{ matrix.PYTHON_VERSION }}
channels: conda-forge
channel-priority: strict
- name: Install package dependencies
shell: bash -l {0}
run: conda env update --file requirements/environment.yml
run: conda env update --file requirements/environment_tests.yml
- name: Install Package
shell: bash -l {0}
run: pip install -e .
Expand Down
2 changes: 1 addition & 1 deletion docs/environment.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: qtawesome_docs

channels:
- https://conda.anaconda.org/spyder-ide
- https://conda.anaconda.org/conda-forge

dependencies:
- pyqt
Expand Down
27 changes: 19 additions & 8 deletions qtawesome/iconic_font.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,16 @@
QSizeF, QRectF, QPointF, QThread)
from qtpy.QtGui import (QColor, QFont, QFontDatabase, QIcon, QIconEngine,
QPainter, QPixmap, QTransform, QPalette, QRawFont,
QGlyphRun, QImage)
QImage)
from qtpy.QtWidgets import QApplication

try:
# Needed since `QGlyphRun` is not available for PySide2
# See spyder-ide/qtawesome#210
from qtpy.QtGui import QGlyphRun
except ImportError:
QGlyphRun = None

# Linux packagers, please set this to True if you want to make qtawesome
# use system fonts
SYSTEM_FONTS = False
Expand Down Expand Up @@ -234,12 +241,16 @@ def try_draw_rawfont():
painter.fillPath(path, painter.pen().color())

elif draw == 'glyphrun':
glyphrun = QGlyphRun()
glyphrun.setRawFont(rawfont)
glyphrun.setGlyphIndexes((glyph,))
glyphrun.setPositions((QPointF(0, ascent),))
painter.drawGlyphRun(QPointF(0, 0), glyphrun)

if QGlyphRun:
glyphrun = QGlyphRun()
glyphrun.setRawFont(rawfont)
glyphrun.setGlyphIndexes((glyph,))
glyphrun.setPositions((QPointF(0, ascent),))
painter.drawGlyphRun(QPointF(0, 0), glyphrun)
else:
warnings.warn("QGlyphRun is unavailable for the current Qt binding! "
"QtAwesome will use the default draw values")
return False
elif draw == 'image':
image = rawfont.alphaMapForGlyph(glyph, QRawFont.PixelAntialiasing) \
.convertToFormat(QImage.Format_ARGB32_Premultiplied)
Expand Down Expand Up @@ -520,7 +531,7 @@ def rawfont(self, prefix, size, hintingPreference=QFont.PreferDefaultHinting):
# (either using a constructor, or by calling loadFromData() or loadFromFile()).
# The QRawFont cannot be moved to a different thread,
# but will have to be recreated in the thread in question.
tid = int(QThread.currentThreadId())
tid = str(QThread.currentThread())
if tid not in cache:
cache[tid] = {}
def clear_cache(): cache.pop(tid)
Expand Down
3 changes: 1 addition & 2 deletions requirements/environment.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
channels:
- defaults
- spyder-ide
- conda-forge
dependencies:
- codecov
- pyqt
Expand Down
10 changes: 10 additions & 0 deletions requirements/environment_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
channels:
- conda-forge
dependencies:
- codecov
- pyqt
- pyside2>=5.12
- pytest
- pytest-cov
- pytest-qt
- qtpy

0 comments on commit 5a31b9d

Please sign in to comment.