labelvariable. And add a template child to
shuffle_imagewhich gets a random wallpaper (from
unsplash_service.py) and saves it to the disk in the designated path and then call the GSettings change function from wallpaper(using
Gtk.Imageand you will find yourself on this page. Jump to the methods section and go through the method list to get an taste of what methods exist for
Gtk.Image. You will notice that there is a method called set_from_file. Since we have the complete path of the file, we can use that file path and use
set_from_fileto set the image container with the image. But set_from_file does not care about aspect ratio. But if we use set_from_pixbuf, and create a pixbuf, set it to preserve aspect ratio and can dictate the width and height of the Pixbuf. Then it will look better
set_from_pixbufand click on PixBuf. You will be redirected here. Jump to methods and you will find the method we want. We can create a new pixbuf using
new_from_file_at_scaleand specify all our parameters. And use that PixBuf to set the image in
This is a process which you will find yourself doing repeatedly, currently the state of autocomplete is not very good(although work is underway trying to make it better). So to understand what methods exist for a Gtk/Gio/Glib class. You should jump to the API docs and explore.
shuffle_imagefunction which get's a
random_wallpaper_url, set's the
wallpaper_from_url(which inturn also saves to disk and sets the Gsetting) and later created a pixbuf from the file and set it to our
shuffle_button_on_clickedfunction which just calls back
shuffle_imageand connected the signal clicked from the button to trigger shuffle.
shuffle_imagefunction in the
__init__method so that we get a random image on application load.
src/meson.buid. That is the reason this folder never was in the installed location. Let us quickly add this folder to the module so that the application can find it when installed using meson's install_subdir method.
__init__method blocks on
shuffle_image, loads the image and then let's the window rendering resume. This is bad user experience. Ideally we should load the image in the background and show a loading spinner until the image is loaded. Let us see how we can run background tasks using python next!