I found a very old post on Display the HTML content on desktop as a widget. This is an updated answer with the help of these two answers Answer-1 and Answer-2.
I tried to run this as a python script "python file.py" (correct me if I am wrong bcz I have no background knowledge, just got fascinated with the post and trying to get the working script)
So After running the script I got some errors which I resolved by DuckDuckGoing but still there are some errors that needed some experts.
Current script
I just updated first three lines, changed WebKit --> WebKit2.
import gi
gi.require_version('Gtk', '3.0')
gi.require_version('WebKit2', '4.0')
from gi.repository import WebKit2, Gtk, Gdk, Gio, GLib
import signal, os
class MainWin(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, skip_pager_hint=True, skip_taskbar_hint=True)
self.set_wmclass("sildesktopwidget","sildesktopwidget")
self.set_type_hint(Gdk.WindowTypeHint.DOCK)
self.set_size_request(600,400)
self.set_keep_below(True)
#Set transparency
screen = self.get_screen()
rgba = screen.get_rgba_visual()
self.set_visual(rgba)
self.override_background_color(Gtk.StateFlags.NORMAL, Gdk.RGBA(0,0,0,0))
#Add all the parts
self.view = WebKit2.WebView()
self.view.set_transparent(True)
self.view.override_background_color(Gtk.StateFlags.NORMAL, Gdk.RGBA(0,0,0,0))
self.view.props.settings.props.enable_default_context_menu = False
self.view.load_uri("file:///home/sai/Downloads/todo.html")
box = Gtk.Box()
self.add(box)
box.pack_start(self.view, True, True, 0)
self.set_decorated(False)
self.connect("destroy", lambda q: Gtk.main_quit())
#Show all the parts
self.show_all()
self.move(100,100)
def refresh_file(*args):
print args
mainwin.view.reload()
def file_changed(monitor, file, unknown, event):
# reload
GLib.timeout_add_seconds(2, refresh_file)
if __name__ == '__main__':
gio_file = Gio.File.new_for_path("/home/sai/Downloads/todo.html")
monitor = gio_file.monitor_file(Gio.FileMonitorFlags.NONE, None)
monitor.connect("changed", file_changed)
mainwin = MainWin()
signal.signal(signal.SIGINT, signal.SIG_DFL) # make ^c work
Gtk.main()
Current Situation
I am getting this error and not able to resolve.
#$ python file.py
Traceback (most recent call last):
File "file.py", line 51, in <module>
mainwin = MainWin()
File "file.py", line 23, in __init__
self.view.set_transparent(True)
AttributeError: 'WebView' object has no attribute 'set_transparent'
Please help me to get the working script to display the HTML page as a desktop widget. I am using Ubuntu Mate 20.04.