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
|
# -*- coding: utf-8 -*-
import wx, os
from PIL import Image
class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None)
self.pathImg = "./"
#liste des images
self.listPathImg = self.getImgsPath()
#pour récupérer l'image en cours d'affichage
self.photoEnCours = 0
sizer = wx.BoxSizer(wx.VERTICAL)
#taille des images
self.widthImg = 800
self.heightImg = 600
btnQuit = wx.Button(self, -1, "quitter")
self.canvas = wx.StaticBitmap(self, -1, wx.EmptyBitmap(self.widthImg, self.heightImg))
sizer.Add(self.canvas)
sizer.Add(btnQuit)
self.SetSizerAndFit(sizer)
self.timer = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.onTimer, self.timer)
self.Bind(wx.EVT_BUTTON, self.onQuit, btnQuit)
self.timer.Start(1000)
self.Show()
#retourne la liste des *.jpg présent dans le dossier
def getImgsPath(self):
listPath = []
for img in os.listdir(self.pathImg):
if os.path.splitext(img)[1].lower() == ".jpg":
listPath.append(os.path.join(self.pathImg, img))
return listPath
#redimmentionne l'image et retourne un wx.Bitmap
def resize(self, pathImg):
im = Image.open(pathImg)
im.thumbnail((self.widthImg, self.heightImg), Image.ANTIALIAS)
image = wx.EmptyImage(im.size[0], im.size[1])
image.SetData(im.convert('RGB').tostring())
return image.ConvertToBitmap()
#méthode appelée toutes les seconde, et affiche la nouvelle image
def onTimer(self, event):
if self.photoEnCours == len(self.listPathImg):
self.photoEnCours = 0
self.canvas.SetBitmap(self.resize(self.listPathImg[self.photoEnCours]))
self.photoEnCours += 1
def onQuit(self, event):
self.timer.Stop()
self.Destroy()
app = wx.App(0)
MyFrame()
app.MainLoop() |
Partager