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

[BUG] Can't save the line chart to an image file in KDE Wayland #530

Open
simprince opened this issue Aug 12, 2024 · 4 comments
Open

[BUG] Can't save the line chart to an image file in KDE Wayland #530

simprince opened this issue Aug 12, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@simprince
Copy link

I have been using finplot to generate a line chart and save to an image file without any problems. Recently I notice that when I use KDE Wayland on Linux, it saves an 0 byte file. When I switch back to X11, it works fine. Any ideas why it doesn't work on Wayland?

@simprince simprince added the bug Something isn't working label Aug 12, 2024
@highfestiva
Copy link
Owner

Sorry about that, and no I do not. If you solve it, please write your solution in here or send me a pull request, as it might help others with the same problem.

@simprince
Copy link
Author

simprince commented Oct 19, 2024

I find out the reason but I can't fix it. I appreciate your help. @highfestiva

Root cause:
In the screenshot() function, grabWindow() doesn't take the screenshot in wayland because wayland disallows pyqt to capture screen content due to the security reason.

Solution (partial):
I google how to capture screenshot on wayland. It turns out that Pillow (PIL) has the ImageGrab to do it. I test below and it works on wayland:

from PIL import ImageGrab
....
im = ImageGrab.grab(bbox=win_box)
im.save(file.name)

Need help:
I've never done any Qt programming and not familiar with pyqt at all. I can't find a way to get the bbox of the window that displays the chart. I tried 1) using the winx, winy, winh, winw; 2) using geometry(); ... Nothing seems to work. The screen captured is quite off from the chart window. If you could point me to how I can get the absolute coordinate of the (x, y) of the top-left pixel of the chart (excluding the title bar of the app) and the bottom-right (x, y). Both are based on the absolute position on screen, I am pretty that it should work. Once it's confirmed to work, I can share the complete solution here.

@highfestiva
Copy link
Owner

print(fplt.windows[0].pos(), fplt.windows[0].size())

prints something like

PyQt6.QtCore.QPoint(406, 197) PyQt6.QtCore.QSize(579, 366)

on my Windows machine. Hope it helps!

@simprince
Copy link
Author

Unfortunately it doesn't work on wayland either. The x,y,w,h from your codes above is

-3 -30 797 370

Among many who complained the same about wayland, I found this eventually (2nd paragraph):
https://wayland-book.com/xdg-shell-in-depth/interactive.html

tl;dr is, wayland intentionally doesn't support positioning/moving of app window programmatically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants