1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
| import pygame, time, threading, os, sys, traceback, multiprocessing
import win32gui
from win32api import GetSystemMetrics
#os.environ['SDL_VIDEODRIVER'] = 'windib'
#os.environ['SDL_VIDEO_CENTERED'] = '1'
chemin = os.path.expanduser('~\Notif')
sc_size = (500, 150)
start_pos = (GetSystemMetrics(0),GetSystemMetrics(1))
x,y = start_pos
final_pos = (GetSystemMetrics(0)-510,GetSystemMetrics(1)-215)
#os.environ['SDL_VIDEO_WINDOW_POS'] = '%i,%i' % start_pos
#os.environ['SDL_VIDEO_CENTERED'] = '0'
pygame.init()
pygame.display.set_caption('Notif')
bg_color = 57, 59, 61
logo = pygame.image.load(chemin+"\\icone.png")
default_font = pygame.font.get_default_font()
font1 = pygame.font.SysFont("gabriola", 25, False)
font2 = pygame.font.SysFont("arial", 19, True)
font3 = pygame.font.SysFont("agency fb", 20, False)
#Création de la fenêtre
screen = pygame.display.set_mode(sc_size, pygame.NOFRAME)
def windowEnumerationHandler(hwnd, top_windows):
top_windows.append((hwnd, win32gui.GetWindowText(hwnd)))
def get_hwnd():
top_windows = []
win32gui.EnumWindows(windowEnumerationHandler, top_windows)
for i in top_windows:
if 'Notif' in i[1] :
#print(i[0],i[1])
return i[0]
hwnd = get_hwnd()
win32gui.MoveWindow(hwnd , x, y, sc_size[0], sc_size[1], True)
clock = pygame.time.Clock()
def notification(Title='Notification', Subtitle=None, Message1=None, Message2=None, Icone=False, Lien=False):
title = font1.render(Title, True, (225, 225, 225))
subtitle = font2.render(Subtitle, True, (255, 255, 255))
message1 = font3.render(Message1, True, (200, 200, 200))
message2 = font3.render(Message2, True, (200, 200, 200))
end_time = False
done = False
end_time = False
retract = False
icone = Icone
lien = Lien
while 1:
screen.fill(bg_color)
screen.blit(logo, (10,5))
screen.blit(title,(50,9))
screen.blit(subtitle,(5,40))
if not icone:
screen.blit(message1,(5,70))
screen.blit(message2,(5,95))
else:
img = pygame.image.load(icone)
screen.blit(img,(5,70))
screen.blit(message1,(75,70))
screen.blit(message2,(75,95))
if not done:
done = True
#hwnd = get_hwnd()
x, y = start_pos
while x != final_pos[0]:
x -= 1
win32gui.MoveWindow(hwnd, x, y, sc_size[0], sc_size[1], True)
if y > final_pos[1]:
y -= 1
#pygame.display.update()
if not end_time:
end_time = time.time()+5
if time.time() > end_time and not retract:
retract = True
while win32gui.GetWindowRect(hwnd)[0] != start_pos[0]:
win32gui.MoveWindow(hwnd, win32gui.GetWindowRect(hwnd)[0]+1, y, sc_size[0], sc_size[1], True)
win32gui.MoveWindow(hwnd, start_pos[0], start_pos[1], sc_size[0], sc_size[1], True)
break
pygame.display.flip()
clock.tick(60)
def exit():
# Be IDLE friendly
pygame.quit() |
Partager