How to draw on budgie-desktop
Just like ShowTime and WeatherShow, how can I draw on budgie-desktop using python ?
Just like ShowTime and WeatherShow, how can I draw on budgie-desktop using python ?
To have the content of a window be on the desktop, you need to set type_hint
Desktop: https://valadoc.org/gdk-3.0/Gdk.WindowTypeHint.html and https://valadoc.org/gdk-3.0/Gdk.WindowTypeHint.html.
You’d also need to have a transparent window though, without decorators.
Are you coding python?
Yes , I am using Python 3.8 right now and have barebone knowledge in C# ( and people told Vala is like C# ).
I learnt a bit too much of vala in thise half an hour. And I think so this will suffice.
…Let me dig in the commits, when showtime was python…
Here you are, a stripped down example. Note that the method to set font color & style is ancient history, you need to use css these days, but the principle is clear I gues:
#!/usr/bin/env python3
import gi
gi.require_version("Gtk", "3.0")
gi.require_version("Gdk", "3.0")
from gi.repository import Gtk, Gdk, Pango
import cairo
class ShowTimeWin(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="PrVflash")
# window props, bindings
self.set_type_hint(Gdk.WindowTypeHint.DESKTOP)
self.set_decorated(False)
self.connect("destroy", Gtk.main_quit)
self.set_skip_taskbar_hint(True)
# transparency
screen = self.get_screen()
visual = screen.get_rgba_visual()
if all([visual, screen.is_composited()]):
self.set_visual(visual)
self.set_app_paintable(True)
self.connect("draw", self.area_draw)
# main grid
self.timegrid = Gtk.Grid()
self.timelabel = Gtk.Label(label="Monkey eats banana")
self.timelabel.modify_font(Pango.FontDescription("Waree 60"))
self.timelabel.modify_fg(Gtk.StateFlags.NORMAL, Gdk.color_parse("white"))
self.timegrid.attach(self.timelabel, 0, 0, 1, 1)
self.add(self.timegrid)
self.set_position(Gtk.WindowPosition.CENTER)
self.show_all()
def area_draw(self, widget, cr):
# set transparent color
cr.set_source_rgba(0.2, 0.2, 0.2, 0)
cr.set_operator(cairo.OPERATOR_SOURCE)
cr.paint()
cr.set_operator(cairo.OPERATOR_OVER)
def show():
ShowTimeWin()
Gtk.main()
show()
So you mean the applet should behave like a seperate window ( But skipping the taskbar and being transparent ) ?
Oh, wait, I assumed this was about drawing on desktop? But yes, it is a standalone window in all applets that show on the desktop. It is controlled from the applet though.