8

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)

Zanna
  • 69,223
  • 56
  • 216
  • 327
Kewal Shah
  • 1,034
  • 2
  • 13
  • 35
  • Which desktop are you using? Unity? GNOME? – Tsundoku Oct 25 '17 at 14:11
  • 2
    What do you mean by "pin an image"? –  Oct 25 '17 at 14:11
  • @MichaelBay I mean use the image as a sticky note, whenever I view my Desktop – Kewal Shah Oct 25 '17 at 14:15
  • @ChristopheStrobbe I am using Unity – Kewal Shah Oct 25 '17 at 14:17
  • 1
    @KewalShah I think you can simply place an image on desktop, right click on the icon, select resize icon, and increase its size. Is that not enough? – pomsky Oct 25 '17 at 14:55
  • @pomsky No: -There is a limit to resizing icons. - I do not want the the image to be highlighted when I hover my mouse over it, which happens in case of icons. - That being said, the image quality is horrible when I resize the icon to it's maximum size. – Kewal Shah Oct 25 '17 at 15:44
  • 1
    @KewalShah Then try screenlets maybe. Not completely sure but I believe there's something for photos. – pomsky Oct 25 '17 at 15:51
  • @pomsky I do not think there is any suitable app to serve my purpose in screenlets. Can you think of any other possible solution? – Kewal Shah Oct 25 '17 at 16:07
  • A single image? Would you have to be able to set the position? Fixed size or arbitrary? In principle, it could be made easily, but a bit more specifics are needed. – Jacob Vlijm Oct 25 '17 at 16:18
  • @JacobVlijm Yes, a single image which could be resized easily. (Kind of the homescreen photo widget apps availabe on Android) – Kewal Shah Oct 25 '17 at 16:43
  • Ok, not at home atm but will get back. – Jacob Vlijm Oct 25 '17 at 16:44
  • Hi Kewal, sorry for the delay, needed to finish something :) Let me know if you manage. – Jacob Vlijm Oct 28 '17 at 10:11

1 Answers1

8

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.

Jacob Vlijm
  • 82,471
  • 12
  • 195
  • 299
  • Amazing, I just tried your script on UbuntuStudio and it worked so far. Small caveat: as soon as I left-click somewhere on the Desktop the image disappears, the script is still running though. But this is probably related to the different DE. No need to improve the script if works on plain Ubuntu, I was just curious if it would work on my system too, upvoted... Have a nice day! – mook765 Oct 28 '17 at 10:53
  • @mook765 ah, that is interesting, and probably easily fixable. Do you have wmctrl installed? If so, does the window still appear in wmctrl -l ? – Jacob Vlijm Oct 28 '17 at 10:58
  • @mook765 Added one line, does that make a difference? – Jacob Vlijm Oct 28 '17 at 11:05
  • wmctrl was not installed, so I installed it. The window is is listed with `0x03400003 -1 MookPC PortraitonMyDesktop` and stay listed even when the Window disappeared. – mook765 Oct 28 '17 at 11:06
  • Now the Window will stay allways on top. – mook765 Oct 28 '17 at 11:06
  • @mook765 Ah, great! Thanks for testing and confirming :) – Jacob Vlijm Oct 28 '17 at 11:11
  • Let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/67809/discussion-between-mook765-and-jacob-vlijm). – mook765 Oct 28 '17 at 11:11
  • @JacobVlijm Amazing script! While **it did achieve my basic need**, if it's not too much to ask for, **what I exactly wanted was** a more _user friendly_ way of doing it like: + being able to **hold and drag** the image **to reposition** it anywhere + **clicking** on any corner **and dragging to resize** it, instead of the command line arguments + **having a remove image option** (like a button on top or in a right-click menu). If you could try adding any of these features to your script , I think it could become a great utility in Ubuntu. – Kewal Shah Oct 29 '17 at 06:45
  • @KewalShah **Try screenlets. There's something for photos.** (I repeat the tip by Pomsky.) You may find the screenlets tool more user friendly. You must realize that it is a lot of work to make this kind of elegant but simple script into a debugged and polished tool with a graphical user interface. – sudodus Oct 29 '17 at 07:12
  • @sudodus I was hesitant to try it out as I didn't want to install the entire software for image displaying. Nonetheless I tried it and **Picframe**, was the closest I could get to what I want, though it does solve my problem of image repositioning and closing, **it has the following disadvantages** : **+ Image resizing** I need to type in the height and width each time I want to change the size _(which was required in Jacob's solution too)_, instead of simply hold and drag by mouse. **+ Doesn't preserve image proportions** _(which the excellent script of Jacob was capable of doing)_. – Kewal Shah Oct 29 '17 at 10:05
  • @sudodus I do understand it takes a lot of time and effort to create such a tool. I went through Jacob's profile and was awed by the Desktop utils he has made like _wswitcher_ and _Take a Break_ and that is the reason why I thought it would be great if we could have a GUI for this too (there's no hurry whatsoever!). I apologize if I sounded demanding/rude, and I am indeed thankful to Jacob for providing me with such a wonderful solution to my problem. – Kewal Shah Oct 29 '17 at 10:24
  • 1
    @KewalShah, Thanks for trying a screenlet and describing how it works. Let us hope that Jacob will find it interesting and have time to do a GUI version of his python script `showportrait.py` – sudodus Oct 29 '17 at 18:15
  • 1
    Classic Jacob with Gtk.Window, +1 – Sergiy Kolodyazhnyy Oct 30 '17 at 05:11