GdkPixBuf.pixbuf_get_from_window() does not work on my Linux Manjaro (Cinnamon) machine. The code below (only the screenshot part) did work perfectly to grab a screenshot in my old Manjaro installation, but recently I reinstalled, and now the same code does not work. I even tried the same code in Linux Mint (Cinnamon) but it didn't work there either.
No exceptions occur in the code when I run/debug it with Visual Studio Code, nothing in .xsession-errors and nothing sticks out in the journalctl log.
So I can only guess that some dependency is missing on my new machine that I had installed on my old machine, but without an error message it is hard to find out what is missing. I get no output when I run the application from the terminal. The application works fine, except the screenshot part.
I have installed PyGObject and PyCairo in my virtual environment of course. So there must be another dependecy that I am missing, anyone know what is missing?
[Edit] I don't know if this is a problem with my virtual environment (somehing that I need to pip install
) or if it something that is missing on my machine (something that I need to sudo pacman -S
). When I had it working on my old machine, I had really just learned about virtual environments and python (still a newbie though), so it might have been working because of something I had installed globally.
from gi.repository import Gdk, GdkPixbuf
class ScreenShotHelper(object):
def __init__(self):
"""Setup the screenshothelper class"""
# Get root window (contains all monitors and windows)
self.root_window = Gdk.get_default_root_window()
def grab_and_scale(self, position, size, requested_size):
"""Grab a screenshot and scale it down to requested size"""
# Get specific area from root window
pb = Gdk.pixbuf_get_from_window(self.root_window,
position.left,
position.top,
size.width,
size.height)
# Scale the image down to the size the user asked for
pb = pb.scale_simple(requested_size.width,
requested_size.height,
GdkPixbuf.InterpType.NEAREST)
return pb