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
| #!/usr/bin/env python
# _*_ coding: utf-8 _*_
import wx
import images
import sys, traceback
import time
class PosFrame(wx.Frame):
def __init__(self, x=0, y=0, tempo = 5):
self.tempo = tempo
wx.Frame.__init__(self, None, -1, "pos",
style = wx.FRAME_SHAPED | wx.SIMPLE_BORDER | wx.STAY_ON_TOP | wx.FRAME_NO_TASKBAR,
pos = (x,y))
self.hasShaped = False
#Charge l'image
self.bmp = images.getVippiBitmap()
self.SetClientSize((self.bmp.GetWidth(), self.bmp.GetHeight()))
dc = wx.ClientDC(self)
dc.DrawBitmap(self.bmp, 0, 0, True)
self.SetWindowsShape()
self.Bind(wx.EVT_PAINT, self.OnPaint)
self.Bind(wx.EVT_WINDOW_CREATE, self.SetWindowsShape)
#timer pour fermer la fenetre au bout du temps tempo
self.timer = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.TimeOut)
#rend transparent
self.SetTransparent(150)
self.Show()
#Fonction appeler lors du timeout du timer
def TimeOut(self, evt):
print "time out"
self.Close()
def SetWindowsShape(self, evt = None):
r = wx.RegionFromBitmap(self.bmp)
self.hasShaped = self.SetShape(r)
def OnPaint(self, evt):
dc = wx.PaintDC(self)
dc.DrawBitmap(self.bmp, 0, 0, True)
if self.tempo>0:
self.timer.Start(self.tempo * 1000, True)
#Fonction qui permet de deplacer la fenetre aux coordonées x, y
def SetPos(self, x, y):
self.Move( (x,y) )
try:
if __name__ == '__main__':
app = wx.PySimpleApp()
posFrame = PosFrame(x=200,y=200,tempo=3)
app.MainLoop()
except SystemExit:
pass
except:
traceback.print_exc (file=open('error.txt', 'w')) |
Partager