Created
October 2, 2021 03:52
-
-
Save JuniorPolegato/9323f51fc807309ec85d337d2577b24d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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()) | |
w.set_type_hint(Gdk.WindowTypeHint.DESKTOP) | |
return True | |
def now_label(): | |
global r | |
now = datetime.datetime.now() | |
now1 = now.strftime('%T') | |
now2 = now.strftime('%A, %d %B %y').title().replace(' ', ' de ') | |
r.set_markup('<span color="yellow" size="50000">%s</span>\n' | |
'<span color="yellow" size="15000">%s</span>\n' | |
% (now1, now2)) | |
return True | |
w = Gtk.Window() | |
# UTILITY / DOCK / DESKTOP / NORMAL / DIALOG | |
w.set_type_hint(Gdk.WindowTypeHint.DIALOG) | |
w.set_title('Relógio @JuniorPolegato') | |
w.set_position(Gtk.WindowPosition.CENTER) | |
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) | |
now_label() | |
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