Skip to content

Commit 96b6f7d

Browse files
committed
Add high DPI support for the PyMOL openGL widget
1 parent c02969c commit 96b6f7d

File tree

2 files changed

+208
-1
lines changed

2 files changed

+208
-1
lines changed

.github/workflows/nightly_wheels.yaml

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
#A* -------------------------------------------------------------------
2+
#B* This file contains source code for running a GitHub automation
3+
#-* related to the build process of the PyMOL computer program
4+
#C* Copyright 2025 by Martin Urban.
5+
#D* -------------------------------------------------------------------
6+
#E* It is unlawful to modify or remove this copyright notice.
7+
#F* -------------------------------------------------------------------
8+
#G* Please see the accompanying LICENSE file for further information.
9+
#H* -------------------------------------------------------------------
10+
#I* Additional authors of this source file include:
11+
#-*
12+
#-*
13+
#-*
14+
#Z* -------------------------------------------------------------------
15+
name: Build Wheels
16+
17+
on:
18+
push:
19+
branches:
20+
- unstable
21+
22+
env:
23+
VCPKG_ROOT: ${{ github.workspace }}/vendor/vcpkg
24+
25+
jobs:
26+
# ----- Windows build section
27+
build-windows:
28+
strategy:
29+
fail-fast: false
30+
matrix:
31+
win_arch: ['x86', 'x64']
32+
runs-on: windows-latest
33+
steps:
34+
- name: Checkout repository
35+
uses: actions/checkout@v4
36+
with:
37+
submodules: recursive
38+
39+
- name: Initialize vcpkg
40+
run: |
41+
git clone https://github.com/Microsoft/vcpkg.git vendor/vcpkg
42+
43+
- name: Setup Python 3.11
44+
uses: actions/setup-python@v5
45+
with:
46+
python-version: "3.11"
47+
48+
- name: Create virtual environment
49+
run: |
50+
python -m venv .venv
51+
call .venv\Scripts\activate.bat
52+
python -m pip install --upgrade setuptools pip wheel build cibuildwheel
53+
python -m pip install delvewheel
54+
python -m pip install -r requirements.txt
55+
shell: cmd
56+
57+
- name: Bootstrap vcpkg
58+
run: ${{ env.VCPKG_ROOT }}/bootstrap-vcpkg.bat -disableMetrics
59+
60+
- name: Last build environment setup steps
61+
run: |
62+
call .venv\Scripts\activate.bat
63+
python automations\my_automator.py setup dev-env
64+
shell: cmd
65+
66+
- name: Build x86 C extension
67+
if: ${{ matrix.win_arch == 'x86' }}
68+
run: |
69+
${{ env.VCPKG_ROOT }}/vcpkg install --triplet=x86-windows-static
70+
call .venv\Scripts\activate.bat
71+
set WIN_ARCH=x86
72+
cibuildwheel . --platform windows --archs x86
73+
shell: cmd
74+
75+
- name: Build x64 C extension
76+
if: ${{ matrix.win_arch == 'x64' }}
77+
run: |
78+
${{ env.VCPKG_ROOT }}/vcpkg install --triplet=x64-windows-static
79+
call .venv\Scripts\activate.bat
80+
set WIN_ARCH=x64
81+
cibuildwheel . --platform windows --archs AMD64
82+
shell: cmd
83+
84+
- name: Upload artifact
85+
uses: actions/upload-artifact@v4
86+
with:
87+
name: PyMOL-wheel-Windows-${{ matrix.win_arch }}-3.11
88+
path: ./wheelhouse/*.whl
89+
# --- end
90+
91+
# ----- macOS build section
92+
build-macos:
93+
strategy:
94+
fail-fast: false
95+
matrix:
96+
os: [ macos-13, macos-14 ]
97+
runs-on: ${{ matrix.os }}
98+
steps:
99+
- name: Checkout repository
100+
uses: actions/checkout@v4
101+
with:
102+
submodules: recursive
103+
104+
- name: Initialize vcpkg
105+
run: |
106+
git clone https://github.com/Microsoft/vcpkg.git vendor/vcpkg
107+
108+
- name: Setup Python 3.11
109+
uses: actions/setup-python@v5
110+
with:
111+
python-version: "3.11"
112+
113+
- name: Create virtual environment
114+
run: |
115+
python -m venv .venv
116+
source .venv/bin/activate
117+
python -m pip install wheel setuptools cibuildwheel
118+
python -m pip install -r requirements.txt
119+
120+
- name: Bootstrap vcpkg
121+
run: ${{ env.VCPKG_ROOT }}/bootstrap-vcpkg.sh -disableMetrics
122+
123+
- name: Install vcpkg dependencies
124+
run: |
125+
${{ env.VCPKG_ROOT }}/vcpkg install
126+
127+
- name: Last build environment setup steps
128+
run: |
129+
source .venv/bin/activate
130+
python automations/my_automator.py setup dev-env
131+
132+
- name: Build C extension
133+
run: |
134+
source .venv/bin/activate
135+
python automations/my_automator.py setup dev-env
136+
export ARCH=$(uname -m)
137+
export MACOSX_DEPLOYMENT_TARGET=12.0
138+
cibuildwheel .
139+
140+
- name: Upload artifact
141+
uses: actions/upload-artifact@v4
142+
with:
143+
name: PyMOL-wheel-${{ matrix.os }}-3.11
144+
path: ./wheelhouse/*.whl
145+
# --- end
146+
147+
# ----- GNU Linux build section
148+
build-gnu-linux:
149+
runs-on: ubuntu-22.04
150+
steps:
151+
- name: Checkout repository
152+
uses: actions/checkout@v4
153+
with:
154+
submodules: recursive
155+
156+
- name: Install system dependencies
157+
run: |
158+
sudo apt-get update
159+
sudo apt-get install git build-essential libxmu-dev libxi-dev libgl-dev libglew-dev libpng-dev libfreetype6-dev libxml2-dev libmsgpack-dev libglm-dev libnetcdf-dev linux-libc-dev autoconf perl
160+
161+
- name: Initialize vcpkg
162+
run: |
163+
git clone https://github.com/Microsoft/vcpkg.git vendor/vcpkg
164+
165+
- name: Setup Python 3.11
166+
uses: actions/setup-python@v5
167+
with:
168+
python-version: "3.11"
169+
170+
- name: Create virtual environment
171+
run: |
172+
python -m venv .venv
173+
source .venv/bin/activate
174+
python -m pip install wheel setuptools cibuildwheel
175+
python -m pip install -r requirements.txt
176+
177+
- name: Bootstrap vcpkg
178+
run: ${{ env.VCPKG_ROOT }}/bootstrap-vcpkg.sh -disableMetrics
179+
180+
- name: Install vcpkg dependencies
181+
run: |
182+
${{ env.VCPKG_ROOT }}/vcpkg install
183+
184+
- name: Last build environment setup steps
185+
run: |
186+
source .venv/bin/activate
187+
python automations/my_automator.py setup dev-env
188+
189+
- name: Build C extension
190+
run: |
191+
source .venv/bin/activate
192+
python automations/my_automator.py setup dev-env
193+
cibuildwheel .
194+
195+
- name: Upload artifact
196+
uses: actions/upload-artifact@v4
197+
with:
198+
name: PyMOL-wheel-GNU-Linux-3.11
199+
path: ./wheelhouse/*.whl
200+
# --- end

modules/pmg_qt/pymol_gl_widget.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,14 @@ def __exit__(self, exc_type, exc_value, traceback):
6363

6464
def __init__(self, parent):
6565
self.gui = parent
66-
self.fb_scale = 1.0
66+
app = QtWidgets.QApplication.instance()
67+
if app:
68+
screen = app.primaryScreen()
69+
# use the screen's devicePixelRatio as framebuffer scale factor necessary for PyQt6 high DPI support
70+
self.fb_scale = screen.devicePixelRatio()
71+
else:
72+
# fallback if no QApplication instance is available
73+
self.fb_scale = 1.0
6774

6875
# OpenGL context setup
6976
if USE_QOPENGLWIDGET:

0 commit comments

Comments
 (0)