Ubuntu – way to add an image as a sticky note to the Unity Desktop

customizationscriptssoftware-recommendationunitywidgets

Please suggest me a way to use any image like a re-sizable sticky note so that I can view it whenever I open my Unity Desktop.

I want it to be used like a homescreen photo widget app available on Android. So that even after rebooting my system, the image stays where it was positioned before, just like a sticky note.

What I want is depicted in the picture below:

enter image description here

In the above picture I placed the image on my Desktop, and resized the image icon to its maximum size, however this does not solve my problem as:

  • I cannot enlarge the image any further as this is the maximum size for resizing icons.

  • When I hover over the icon, the image gets highlighted which happens in case of icons, which I do not want

  • Even with the maximum icon size, the quality of the image becomes really poor as the image is distorted.

I want the image to be easily re-sized and re-positioned without having any of the disadvantages mentioned above.

I hope I am clear about my question now. If there is still any problem in understanding what I want please let me know.

(Ubuntu 16.04)

Best Answer

Showing an image on your desktop

Windows can be of different types. We do not only have "normal" windows, but also windows of (in our case) type "DESKTOP".

Windows of type "DESKTOP" stay below everyting; even all items on your desktop show up above them. Therefore showing an image in a window then results into:

enter image description here

...where the sundew image, pinned on the desktop, is actually a window (just like the desktop clock in the image btw).

The code

#!/usr/bin/env python3
import gi
gi.require_version('GdkPixbuf', '2.0')
from gi.repository import GdkPixbuf
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, Gdk
import sys

img = sys.argv[1]
xpos = int(sys.argv[2])
ypos = int(sys.argv[3])
w = int(sys.argv[4])
h = int(sys.argv[5])

class ShowPortrait(Gtk.Window):

    def __init__(self):
        Gtk.Window.__init__(self, title="PortraitonMyDesktop")
        self.set_type_hint(Gdk.WindowTypeHint.DESKTOP)
        self.connect("destroy", Gtk.main_quit)
        self.set_skip_taskbar_hint(True)
        pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(
            img, w, h, preserve_aspect_ratio=True,
            )
        image = Gtk.Image.new_from_pixbuf(pixbuf)
        self.add(image)
        self.move(xpos, ypos)
        self.show_all()

ShowPortrait()
Gtk.main()

How to use

  1. Copy the script into an empty file, save it as showportrait.py
  2. Test- run it with the image, the x-position, y-position, width and height as arguments:

    python3 /path/to/showportrait.py /path/to/image x y width height
    

    for example:

    python3 '/home/jacob/Desktop/showportrait.py' '/home/jacob/Thema/Wallpapers/sundew.jpg' 1000 200 400 400
    

    The image should show on your desktop.

  3. If all works fine, add the command to Startup Applications.

Closing the window

Is easyest done by the command:

kill "$(pgrep -f showportrait.py)"

Note

Setting the width/hight, the script will scale the image until the first is reached, preserving the image' proportions.

Related Question