From f7d50d5593ec2f228b70b9e4d74ce32abbc5c394 Mon Sep 17 00:00:00 2001 From: dalthviz Date: Wed, 19 Oct 2022 14:07:16 -0500 Subject: [PATCH 1/6] Handle PySide2 not having 'QtGui.QGlyphRun'. Add tests jobs with PySide2 --- .github/workflows/linux-tests.yml | 8 +++++--- .github/workflows/macos-tests.yml | 8 +++++--- .github/workflows/windows-tests.yml | 8 +++++--- qtawesome/iconic_font.py | 25 ++++++++++++++++++------- requirements/environment.yml | 2 +- requirements/environment_tests.yml | 11 +++++++++++ 6 files changed, 45 insertions(+), 17 deletions(-) create mode 100644 requirements/environment_tests.yml diff --git a/.github/workflows/linux-tests.yml b/.github/workflows/linux-tests.yml index 1a9d0aa5..34870641 100644 --- a/.github/workflows/linux-tests.yml +++ b/.github/workflows/linux-tests.yml @@ -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 @@ -38,7 +40,7 @@ jobs: python-version: ${{ matrix.PYTHON_VERSION }} - 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 . diff --git a/.github/workflows/macos-tests.yml b/.github/workflows/macos-tests.yml index 65a55a41..c27060ab 100644 --- a/.github/workflows/macos-tests.yml +++ b/.github/workflows/macos-tests.yml @@ -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 @@ -33,7 +35,7 @@ jobs: python-version: ${{ matrix.PYTHON_VERSION }} - 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 . diff --git a/.github/workflows/windows-tests.yml b/.github/workflows/windows-tests.yml index 4f6f05f4..4305a349 100644 --- a/.github/workflows/windows-tests.yml +++ b/.github/workflows/windows-tests.yml @@ -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 @@ -33,7 +35,7 @@ jobs: python-version: ${{ matrix.PYTHON_VERSION }} - 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 . diff --git a/qtawesome/iconic_font.py b/qtawesome/iconic_font.py index 8214d27e..f1bfb194 100644 --- a/qtawesome/iconic_font.py +++ b/qtawesome/iconic_font.py @@ -26,7 +26,14 @@ QSizeF, QRectF, QPointF, QThread) from qtpy.QtGui import (QColor, QFont, QFontDatabase, QIcon, QIconEngine, QPainter, QPixmap, QTransform, QPalette, QRawFont, - QGlyphRun, QImage) + QImage) +try: + # Needed since `QGlyphRun` is not available for PySide2 + # See spyder-ide/qtawesome#210 + from qtpy.QtGui import QGlyphRun +except ImportError: + QGlyphRun = None + from qtpy.QtWidgets import QApplication # Linux packagers, please set this to True if you want to make qtawesome @@ -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 with 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) diff --git a/requirements/environment.yml b/requirements/environment.yml index 978b804e..bc86df88 100644 --- a/requirements/environment.yml +++ b/requirements/environment.yml @@ -1,6 +1,6 @@ channels: - defaults - - spyder-ide + - conda-forge dependencies: - codecov - pyqt diff --git a/requirements/environment_tests.yml b/requirements/environment_tests.yml new file mode 100644 index 00000000..8c28c278 --- /dev/null +++ b/requirements/environment_tests.yml @@ -0,0 +1,11 @@ +channels: + - defaults + - conda-forge +dependencies: +- codecov +- pyqt +- pyside2>=5.12 +- pytest +- pytest-cov +- pytest-qt +- qtpy From c91730e518842a9af2bb110f136275f7b9ce53c7 Mon Sep 17 00:00:00 2001 From: dalthviz Date: Wed, 19 Oct 2022 14:34:28 -0500 Subject: [PATCH 2/6] Use QThread string representation to handle raw font cache --- qtawesome/iconic_font.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qtawesome/iconic_font.py b/qtawesome/iconic_font.py index f1bfb194..28fdf1f1 100644 --- a/qtawesome/iconic_font.py +++ b/qtawesome/iconic_font.py @@ -531,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) From 10b0ad85a8ffb91b4e3bec0cc083d6291c8b3149 Mon Sep 17 00:00:00 2001 From: dalthviz Date: Thu, 20 Oct 2022 11:09:25 -0500 Subject: [PATCH 3/6] Use only conda-forge channel to setup CI --- .github/workflows/linux-tests.yml | 2 ++ .github/workflows/macos-tests.yml | 2 ++ .github/workflows/windows-tests.yml | 2 ++ README.md | 2 +- requirements/environment.yml | 1 - requirements/environment_tests.yml | 1 - 6 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/linux-tests.yml b/.github/workflows/linux-tests.yml index 34870641..966d064a 100644 --- a/.github/workflows/linux-tests.yml +++ b/.github/workflows/linux-tests.yml @@ -38,6 +38,8 @@ 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_tests.yml diff --git a/.github/workflows/macos-tests.yml b/.github/workflows/macos-tests.yml index c27060ab..ab644730 100644 --- a/.github/workflows/macos-tests.yml +++ b/.github/workflows/macos-tests.yml @@ -33,6 +33,8 @@ 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_tests.yml diff --git a/.github/workflows/windows-tests.yml b/.github/workflows/windows-tests.yml index 4305a349..c8e372af 100644 --- a/.github/workflows/windows-tests.yml +++ b/.github/workflows/windows-tests.yml @@ -33,6 +33,8 @@ 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_tests.yml diff --git a/README.md b/README.md index 1ea507a0..9e3d4f9d 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ C++ library by Rick Blommers. Using `conda`: ``` -conda install qtawesome +conda install -c conda-forge qtawesome ``` or using `pip` (only if you don't have conda installed): diff --git a/requirements/environment.yml b/requirements/environment.yml index bc86df88..50e8165e 100644 --- a/requirements/environment.yml +++ b/requirements/environment.yml @@ -1,5 +1,4 @@ channels: - - defaults - conda-forge dependencies: - codecov diff --git a/requirements/environment_tests.yml b/requirements/environment_tests.yml index 8c28c278..6e23f666 100644 --- a/requirements/environment_tests.yml +++ b/requirements/environment_tests.yml @@ -1,5 +1,4 @@ channels: - - defaults - conda-forge dependencies: - codecov From 542004bf29b9c390978cf68005022371d91b18dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Althviz=20Mor=C3=A9?= Date: Thu, 20 Oct 2022 12:13:59 -0500 Subject: [PATCH 4/6] Apply suggestions from code review Co-authored-by: Carlos Cordoba --- qtawesome/iconic_font.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/qtawesome/iconic_font.py b/qtawesome/iconic_font.py index 28fdf1f1..cf5f8987 100644 --- a/qtawesome/iconic_font.py +++ b/qtawesome/iconic_font.py @@ -27,6 +27,8 @@ from qtpy.QtGui import (QColor, QFont, QFontDatabase, QIcon, QIconEngine, QPainter, QPixmap, QTransform, QPalette, QRawFont, QImage) +from qtpy.QtWidgets import QApplication + try: # Needed since `QGlyphRun` is not available for PySide2 # See spyder-ide/qtawesome#210 @@ -34,8 +36,6 @@ except ImportError: QGlyphRun = None -from qtpy.QtWidgets import QApplication - # Linux packagers, please set this to True if you want to make qtawesome # use system fonts SYSTEM_FONTS = False @@ -248,7 +248,7 @@ def try_draw_rawfont(): glyphrun.setPositions((QPointF(0, ascent),)) painter.drawGlyphRun(QPointF(0, 0), glyphrun) else: - warnings.warn("QGlyphRun is unavailable with the current Qt binding! " + warnings.warn("QGlyphRun is unavailable for the current Qt binding! " "QtAwesome will use the default draw values") return False elif draw == 'image': From 17c43797bd849b9c6df8dffd27e3ddbdcec8314b Mon Sep 17 00:00:00 2001 From: dalthviz Date: Thu, 20 Oct 2022 12:19:33 -0500 Subject: [PATCH 5/6] Docs: Change docs environment definiton channel to conda-forge --- docs/environment.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/environment.yml b/docs/environment.yml index 1d57ace2..34e94eb8 100644 --- a/docs/environment.yml +++ b/docs/environment.yml @@ -1,7 +1,7 @@ name: qtawesome_docs channels: - - https://conda.anaconda.org/spyder-ide + - https://conda.anaconda.org/conda-forge dependencies: - pyqt From e447fbe7a3a9948a1137501a0c8bc859143ee2e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Althviz=20Mor=C3=A9?= Date: Thu, 20 Oct 2022 13:59:44 -0500 Subject: [PATCH 6/6] Don't add conda-forge as conda channel for README installation instructions --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9e3d4f9d..1ea507a0 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ C++ library by Rick Blommers. Using `conda`: ``` -conda install -c conda-forge qtawesome +conda install qtawesome ``` or using `pip` (only if you don't have conda installed):