| 12
 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
 
 | #!/usr/bin/python
# -*- coding: iso-8859-15 -*-
 
import wx
 
ID_PLUS = 100
ID_MOINS = 101
 
phrase1 = "Ramener l'image a sa taille d'origine"
phrase2 = "Operation 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):#Initialiser l'instance
		wx.ScrolledWindow.__init__(self, parent = conteneur)
		self.bmp = None
		self.image = None
 
 
	def Affiche(self, bmp, ratio):#Afficher l'image
		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):#Effacer l'image
		self.image.Destroy()
		self.bmp = None
		self.SetScrollRate(0, 0)
 
class Principale(wx.Frame):
	def __init__(self, titre):#Initialisation l'instance
		wx.Frame.__init__(self, None, -1, title = titre, size = (499,399))
		self.imgORIG = None
		self.imgORIX = 0
		self.imgORIY = 0
		self.bmpRESU = None
		self.ratio = 100
		self.inc = 5
 
		menuFichier = wx.Menu()#Création d'un onglet menu
		menuFichier.Append(wx.ID_OPEN, "&Ouvrir\tCTRL+o", "Ouvrir un fichier image")
		menuFichier.Append(wx.ID_CLOSE, "&Fermer\CTRL+f", "Fermer le fichier en cours de lecture")
		menuFichier.AppendSeparator()
		menuFichier.Append(wx.ID_EXIT, "&Quitter\CTRL+q", "Quitter l'application")
 
		menuAfficher = wx.Menu(style = wx.MENU_TEAROFF)#Création d'un onglet Affichage
		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, "&Réduire\tCTRL+r", "Réduire l'image")
 
		menuBarre = wx.MenuBar()#Création d'une barre
		menuBarre.Append(menuFichier, "&Fichier")
		menuBarre.Append(menuAfficher, "&Afficher")
		self.SetMenuBar(menuBarre)
 
		self.barre = wx.StatusBar(self, -1)#Création d'une barre d'état
		self.barre.SetFieldsCount(2)
		self.barre.SetStatusWidths([-1, -1])
		self.SetStatusBar(self.barre)
		#création d'une barre d'outils
		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 en cors de lecture")
		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()#Création d'une boîte de placement
		self.panneau = Visu(self)#Crétion d'une instance de classe Visu
		sizer.Add(self.panneau, 1, wx.EXPAND|wx.ALL, 2)#On ajoute l'instance de classe Visu à la boîte de placement
		self.SetSizer(sizer)#On lie la boîte de placement à la fenêtre
 
		wx.EVT_MENU(self, wx.ID_OPEN, self.OnOpen)#Interception des évements et attribution à des fonctions
		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)
 
 
	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 ouver", 
					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("PogoImageViewer [%s]"% fihier)
				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("PogoImageViewer")
			self.barre.SetStatusText("", 1)
 
	def OnExit(self, evt):
		self.Destroy()# Erreur inconnue
 
 
class MonApp(wx.App):# Erreur d'indentation ?!?!
	#def __init__(self, redirect=True, filename=None):
		#wx.App.__init__(self, redirect, filename)
	def OnInit(self):
		wx.InitAllImageHandlers()
		fen = Principale("PogoImageViewer")
		fen.Show(True)
		self.SetTopWindow(fen)
		return True
 
app = MonApp()#Instanciation de l'appli
#app = MonApp(redirect=False)#Instanciation de l'appli
app.MainLoop()#Démarrage de l'appli | 
Partager