Skip to content

Instantly share code, notes, and snippets.

@JuniorPolegato
Created October 2, 2021 03:20
Show Gist options
  • Save JuniorPolegato/f3114489408f27c566333bde0ff400a6 to your computer and use it in GitHub Desktop.
Save JuniorPolegato/f3114489408f27c566333bde0ff400a6 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import gi
import cairo
import datetime
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gdk, GLib
_SUPPORTS_ALPHA = False
def on_draw(w, cr):
cr.save()
if _SUPPORTS_ALPHA:
cr.set_source_rgba(0.5, 1.0, 0.5, 0.5) # transparent
else:
cr.set_source_rgb(0.5, 1.0, 0.5) # opaque
cr.set_operator(cairo.OPERATOR_SOURCE)
cr.paint()
cr.restore()
def on_screen_changed(previous_screen):
global w, _SUPPORTS_ALPHA
screen = w.get_screen()
visual = screen.get_rgba_visual()
if visual:
# print('Your screen supports alpha channels!')
_SUPPORTS_ALPHA = True
else:
print('Your screen does not support alpha channels!')
w.set_visual(visual)
def on_window_clicked(w, e):
w.set_decorated(not w.get_decorated())
return True
def now_label():
global r
now = datetime.datetime.now().strftime('%B\n%A\n%d/%m/%y\n%T').title()
r.set_markup('<span color="yellow" size="50000">%s</span>' % now)
return True
w = Gtk.Window()
# UTILITY / DOCK / DESKTOP / NORMAL / DIALOG
w.set_type_hint(Gdk.WindowTypeHint.DESKTOP)
w.set_title('Relógio @JuniorPolegato')
w.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
w.add_events(Gdk.EventMask.BUTTON_PRESS_MASK)
w.set_app_paintable(True)
w.connect('delete-event', Gtk.main_quit)
w.connect('draw', on_draw)
w.connect('screen_changed', on_screen_changed)
w.connect('button_press_event', on_window_clicked)
a = Gtk.Alignment(xalign=0.5, yalign=0.5, xscale=0.0, yscale=0.0)
w.add(a)
r = Gtk.Label()
r.set_justify(Gtk.Justification.CENTER)
GLib.timeout_add(1000, now_label)
a.add(r)
on_screen_changed(w.get_screen())
w.show_all()
Gtk.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment