8000 Qt embedding example: processEvents, to make sure GUI is smooth · matplotlib/matplotlib@d2dd466 · GitHub
[go: up one dir, main page]

Skip to content

Commit d2dd466

Browse files
committed
Qt embedding example: processEvents, to make sure GUI is smooth
See also pyqtgraph/pyqtgraph#3092
1 parent 0da7d89 commit d2dd466

File tree

4 files changed

+149
-0
lines changed

4 files changed

+149
-0
lines changed

.envrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
use flake
2+
export PYTHONPATH="$PYTHONPATH:$PWD/$INSTALLDIR";

flake.lock

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
{
2+
inputs = {
3+
utils.url = "github:numtide/flake-utils";
4+
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
5+
};
6+
outputs = { self, nixpkgs, utils }: utils.lib.eachDefaultSystem (system:
7+
let
8+
pkgs = nixpkgs.legacyPackages.${system};
9+
python = pkgs.python3;
10+
in
11+
{
12+
devShell = pkgs.mkShell {
13+
# Use these variables in ./src/_c_internal_utils.cpp
14+
LIBX11_REPLACEMENT = "${pkgs.xorg.libX11}/lib/libX11.so.6";
15+
LIBWAYLAND_EPLACEMENT = "${pkgs.wayland}/lib/libwayland-client.so.0";
16+
nativeBuildInputs = [
17+
python.pkgs.pytest
18+
python.pkgs.meson-python
19+
python.pkgs.pip
20+
python.pkgs.mypy
21+
python.pkgs.flake8
22+
pkgs.ninja
23+
]
24+
++ python.pkgs.matplotlib.nativeBuildInputs
25+
;
26+
buildInputs = [
27+
]
28+
++ python.pkgs.matplotlib.buildInputs
29+
;
30+
propagatedBuildInputs = [
31+
# To test qt backend related scripts
32+
python.pkgs.pyqt6
33+
]
34+
++ python.pkgs.matplotlib.propagatedBuildInputs
35+
++ python.pkgs.matplotlib.dependencies
36+
;
37+
QT_PLUGIN_PATH = pkgs.lib.pipe [
38+
pkgs.qt6.qtbase
39+
pkgs.qt6.qtwayland
40+
] [
41+
(map (p: "${pkgs.lib.getBin p}/${pkgs.qt6.qtbase.qtPluginPrefix}"))
42+
(pkgs.lib.concatStringsSep ":")
43+
];
44+
QT_QPA_PLATFORM="wayland";
45+
XDG_DATA_DIRS = pkgs.lib.concatStringsSep ":" [
46+
# So we'll be able to save figures from the plot dialog
47+
"${pkgs.gsettings-desktop-schemas}/share/gsettings-schemas/${pkgs.gsettings-desktop-schemas.name}"
48+
"${pkgs.gtk3}/share/gsettings-schemas/${pkgs.gtk3.name}"
49+
# So pdf mime types and perhaps others could be detected by 'gio open'
50+
# / xdg-open. TODO: Is this the best way to overcome this issue -
51+
# manually every time we generate a devShell?
52+
"${pkgs.shared-mime-info}/share"
53+
"${pkgs.hicolor-icon-theme}/share"
54+
];
55+
GDK_PIXBUF_MODULE_FILE = "${pkgs.librsvg}/${pkgs.gdk-pixbuf.moduleDir}.cache";
56+
# Install to this path with (in contrast to upstream's documentation):
57+
#
58+
# python -m pip install \
59+
# --config-settings=setup-args="-Dsystem-freetype=true" \
60+
# --config-settings=setup-args="-Dsystem-qhull=true" \
61+
# --config-settings=setup-args="-Db_lto=false" \
62+
# --config-settings=builddir=build \
63+
# --prefix dist/nix \
64+
# --no-build-isolation \
65+
# ".[dev]"
66+
#
67+
#
68+
# Run test(s) with (e.g):
69+
#
70+
# pytest \
71+
# --import-mode=append \
72+
# --showlocals \
73+
# $INSTALLDIR/matplotlib/tests/test_ticker.py \
74+
# -k 'TestLogFormatterMathtext'
75+
INSTALLDIR = "dist/nix/${python.sitePackages}";
76+
};
77+
}
78+
);
79+
}

galleries/examples/user_interfaces/embedding_in_qt_sgskip.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ def _update_canvas(self):
5656
# Shift the sinusoid as a function of time.
5757
self._line.set_data(t, np.sin(t + time.time()))
5858
self._line.figure.canvas.draw()
59+
# If the timer frequency is fast enough for the Qt platform (in case
60+
# the frequency is increased or if the desktop is overloaded), the GUI
61+
# might get stuck because the event loop won't manage to respond to
62+
# events such as window resize etc while the timer is running. This
63+
# forces the timer to process the GUI events and to provide a smooth
64+
# experience.
65+
qapp.processEvents()
5966

6067

6168
if __name__ == "__main__":

0 commit comments

Comments
 (0)
0