Taking screenshots with a command-line tool
Niels De Graef
ndegraef at redhat.com
Fri Mar 17 12:01:18 UTC 2023
Hi Maxim,
Taken from https://stackoverflow.com/questions/72216896/how-can-i-get-a-screenshot-on-wayland-with-pure-python
```
import dbus
from gi.repository import GLib
import dbus.mainloop.glib
def response_handler(response, result):
if response == 0:
print(f'Screenshot file: {result.get("uri")}')
else:
print("Failed to get screenshot")
def main():
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
bus = dbus.SessionBus()
my_name = bus.get_connection().get_unique_name()[1:].replace(".", "_")
response_path =
f"/org/freedesktop/portal/desktop/request/{my_name}/my_token"
bus.add_signal_receiver(
response_handler,
dbus_interface="org.freedesktop.portal.Request",
path=response_path,
)
desktop = bus.get_object("org.freedesktop.portal.Desktop",
"/org/freedesktop/portal/desktop")
desktop.Screenshot("Screenshot", {"handle_token": "my_token"},
dbus_interface="org.freedesktop.portal.Screenshot")
loop = GLib.MainLoop()
loop.run()
if __name__ == "__main__":
main()
```
-- Niels
On Fri, Mar 17, 2023 at 12:36 PM Maxim Kartashev
<maxim.kartashev at jetbrains.com> wrote:
>
> Does anyone know if there's a command-line for taking screenshots/screencasts that works under Gnome 42+? A thing like that would be immensely useful for analyzing automated test failures.
>
> Thanks in advance,
> Maxim.
>
More information about the wakefield-dev
mailing list