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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
| # -*- coding: iso-8859-15 -*-
import wx
ID_PLUS = 100
ID_MOINS = 101
ID_APROPOS = 102
phrase1 = u"Ramener l'image à sa taille d'origine"
phrase2 = u"Opération interdite"
if not wx.USE_UNICODE:
phrase1 = phrase1.encode("iso8859-15", "replace")
phrase2 = phrase2.encode("iso8859-15", "replace")
class Visu(wx.ScrolledWindow):
def __init__(self, conteneur):
wx.ScrolledWindow.__init__(self,parent = conteneur)
#self.parent = conteneur
self.bmp = None
self.image = None
#self.tailleImg = None
def Affiche(self, bmp, ratio):
if self.bmp != None:
posX, posY = self.GetViewStart()
self.image.Destroy()
self.SetScrollRate(0, 0)
else:
posX = 0
posY = 0
self.bmp = bmp
self.SetVirtualSize(wx.Size(bmp.GetWidth(), bmp.GetHeight()))
self.image = wx.StaticBitmap(self, -1, self.bmp)
self.SetScrollRate((10*ratio)/100, (10*ratio)/100)
self.Scroll(posX, posY)
self.Refresh()
def Efface(self):
self.image.Destroy()
self.bmp = None
self.SetScrollRate(0, 0)
class Principale(wx.Frame):
def __init__(self, titre):
wx.Frame.__init__(self, None, -1, title = titre, size = (699,599), pos = (20,20))
self.imgORIG = None
self.imgORIX = 0
self.imgORIY = 0
self.bmpRESU = None
self.ratio = 100
self.inc = 5
menuFichier = wx.Menu(style = wx.MENU_TEAROFF)
menuFichier.Append(wx.ID_OPEN, "&Ouvrir\tCtrl+O", "Ouvrir un fichier image")
menuFichier.Append(wx.ID_CLOSE, "&Fermer\tCtrl+W", "Fermer le fichier ouvert")
menuFichier.AppendSeparator()
menuFichier.Append(wx.ID_EXIT, "&Quitter\tCtrl+Q", "Quitter l'application")
menuAfficher = wx.Menu(style = wx.MENU_TEAROFF)
menuAfficher.Append(wx.ID_UNDO, "&Taille d'origine\tCtrl+T", phrase1)
menuAfficher.Append(ID_PLUS, "&Agrandir\tCtrl+A", "Agrandir l'image")
menuAfficher.Append(ID_MOINS, "&Diminuer\tCtrl+D", "Diminuer l'image")
menuHelp = wx.Menu(style = wx.MENU_TEAROFF)
menuHelp.Append(ID_APROPOS, "A propos")
menuBarre = wx.MenuBar()
menuBarre.Append(menuFichier, "&Fichier")
menuBarre.Append(menuAfficher, "&Afficher")
menuBarre.Append(menuHelp, "&?")
self.SetMenuBar(menuBarre)
self.barre = wx.StatusBar(self, -1)
self.barre.SetFieldsCount(2)
self.barre.SetStatusWidths([-1, -1])
self.SetStatusBar(self.barre)
outils = wx.ToolBar(self, -1, style = wx.TB_HORIZONTAL | wx.NO_BORDER)
outils.AddSimpleTool(wx.ID_OPEN,
wx.Bitmap("Open.png", wx.BITMAP_TYPE_PNG),
shortHelpString = "Ouvrir",
longHelpString = "Ouvrir un fichier image")
outils.AddSimpleTool(wx.ID_CLOSE,
wx.Bitmap("Close.png", wx.BITMAP_TYPE_PNG),
shortHelpString = "Fermer",
longHelpString = "Fermer le fichier ouvert")
outils.AddSeparator()
outils.AddSimpleTool(wx.ID_UNDO ,
wx.Bitmap("Origine.png", wx.BITMAP_TYPE_PNG),
shortHelpString = "Taille originale",
longHelpString = phrase1)
outils.AddSimpleTool(ID_PLUS,
wx.Bitmap("plus.png", wx.BITMAP_TYPE_PNG),
shortHelpString = "Agrandir",
longHelpString = "Agrandir l'image")
outils.AddSimpleTool(ID_MOINS,
wx.Bitmap("moins.png", wx.BITMAP_TYPE_PNG),
shortHelpString = "Diminuer",
longHelpString = "Diminuer l'image")
outils.AddSeparator()
outils.AddSimpleTool(wx.ID_EXIT,
wx.Bitmap("Exit.png", wx.BITMAP_TYPE_PNG),
shortHelpString = "Quitter",
longHelpString = "Quitter l'application")
outils.Realize()
self.SetToolBar(outils)
sizer = wx.BoxSizer()
self.panneau = Visu(self)
sizer.Add(self.panneau, 1, wx.EXPAND|wx.ALL, 2)
self.SetSizer(sizer)
wx.EVT_MENU(self, wx.ID_OPEN, self.OnOpen)
wx.EVT_MENU(self, wx.ID_CLOSE, self.OnClose)
wx.EVT_MENU(self, wx.ID_EXIT, self.OnExit)
wx.EVT_MENU(self, wx.ID_UNDO, self.Retour)
wx.EVT_MENU(self, ID_PLUS, self.Plus)
wx.EVT_MENU(self, ID_MOINS, self.Moins)
wx.EVT_MENU(self, ID_APROPOS, self.OnAbout)
def OnAbout(self, evt):
msgbox = wx.MessageBox("\nVersion : 1.0.0\nAuteur : ", "A propos", wxOK)
msgbox.ShowModal()
msgbox.Destroy()
def Retour(self, evt):
if self.imgORIG != None:
self.ratio = 100
self.bmpRESU = self.imgORIG.ConvertToBitmap()
self.panneau.Affiche(self.bmpRESU, self.ratio)
self.barre.SetStatusText("(%s, %s) %s %%"%(self.imgORIX, self.imgORIY, self.ratio), 1)
def Plus(self, evt):
if self.imgORIG != None:
self.ratio = self.ratio + self.inc
largeur = (self.imgORIX * self.ratio)/100
hauteur = (self.imgORIY * self.ratio)/100
self.bmpRESU = self.imgORIG.Scale(largeur, hauteur).ConvertToBitmap()
self.panneau.Affiche(self.bmpRESU, self.ratio)
self.barre.SetStatusText("(%s, %s) %s %%"%(self.imgORIX, self.imgORIY, self.ratio), 1)
def Moins(self, evt):
if self.ratio > 5 and self.imgORIG != None:
self.ratio = self.ratio - self.inc
largeur = (self.imgORIX * self.ratio)/100
hauteur = (self.imgORIY * self.ratio)/100
self.bmpRESU = self.imgORIG.Scale(largeur, hauteur).ConvertToBitmap()
self.panneau.Affiche(self.bmpRESU, self.ratio)
self.barre.SetStatusText("(%s, %s) %s %%"%(self.imgORIX, self.imgORIY, self.ratio), 1)
def OnOpen(self, evt):
if self.imgORIG != None :
dlg = wx.MessageDialog(self, "Vous devez d'abord fermer l'image en cours d'utilisation",
phrase2, style = wx.OK)
retour = dlg.ShowModal()
dlg.Destroy()
else:
dlg = wx.FileDialog(self, "Choisissez un fichier",
wildcard = "*.*",
style = wx.OPEN)
retour = dlg.ShowModal()
chemin = dlg.GetPath()
fichier = dlg.GetFilename()
dlg.Destroy()
if retour == wx.ID_OK and fichier != "":
self.imgORIG = wx.Image(chemin, wx.BITMAP_TYPE_ANY)
self.imgORIX = self.imgORIG.GetWidth()
self.imgORIY = self.imgORIG.GetHeight()
self.bmpRESU = self.imgORIG.ConvertToBitmap()
self.panneau.Affiche(self.bmpRESU, self.ratio)
self.SetTitle("Visualiseur d'images [%s]"% fichier)
self.barre.SetStatusText("(%s, %s) %s %%"%(self.imgORIX, self.imgORIY, self.ratio), 1)
def OnClose(self, evt):
if self.imgORIG != None :
self.panneau.Efface()
self.imgORIG = None
self.imgORIX = 0
self.imgORIY = 0
self.bmpRESU = None
self.ratio = 100
self.SetTitle("Visualiseur d'images")
self.barre.SetStatusText("", 1)
def OnExit(self, evt):
self.Destroy()
class MonApp(wx.App):
def OnInit(self):
wx.InitAllImageHandlers()
fen = Principale("Visualiseur d'images")
fenicon = wx.Icon("./xvid.ico", wx.BITMAP_TYPE_ICO)
fen.SetIcon(fenicon)
fen.Show(True)
self.SetTopWindow(fen)
return True
app = MonApp()
app.MainLoop() |
Partager