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
| #!/usr/bin/python
# -*- coding: utf-8 -*-
import wx
import time
class apPrincipale(wx.Frame):
def __init__(self, titre):
wx.Frame.__init__(self, None, 1, title=titre, size=(225,200))
self.SetMinSize((225, 200))
self.SetIcon(wx.Icon("bombe.ico", wx.BITMAP_TYPE_ICO))
self.CentreOnParent()
self.timer = wx.Timer(self, 2)
self.compteurtime = 15
#Code a desindenter a la fin du programme
self.password = "1234"
self.auto = 0
while self.auto != 1:
dlg = wx.PasswordEntryDialog(self, 'Entrez le mot de passe pour activer la bombe :','Erreur, mot de passe requis !')
if dlg.ShowModal() == wx.ID_OK:
if dlg.GetValue() == self.password:
dlg.Destroy()
self.auto = 1
else:
self.auto = 1
dlg.Destroy()
self.Destroy()
self.auto = 0
self.conteneur = wx.Panel(self, 1, size=self.GetClientSize())
self.timetext = wx.StaticText(self.conteneur, -1, "", (50, 5), style=wx.ALIGN_CENTRE)
self.Amorce = wx.Button(self.conteneur, 3, 'Amorcer la bombe', (10, 45))
self.Desamorce = wx.Button(self.conteneur, 4, 'Desamorcer la bombe', (10, 70))
self.Desamorce.Disable()
self.Exit = wx.Button(self.conteneur, 5, 'Exit', (10, 20))
self.Bind(wx.EVT_BUTTON, self.OnExit, id=5)
self.Bind(wx.EVT_SIZE, self.OnSize)
self.Bind(wx.EVT_BUTTON, self.OnAmorcage, id=3)
self.Bind(wx.EVT_BUTTON, self.OnDesamorcage, id=4)
self.Bind(wx.EVT_TIMER, self.OnTimer, id=2)
self.Bind(wx.EVT_CLOSE, self.OnClose)
def OnExit(self, evt):
if self.compteurtime == 0 or not self.timer.IsRunning():
self.Destroy()
else:
dlg4 = wx.MessageDialog(None, "Erreur : Il faut désamorçer la bombe avant de pouvoir quitter !".decode('utf8'), "Erreur", wx.OK|wx.ICON_ERROR)
retCode = dlg4.ShowModal()
if retCode == wx.ID_OK:
dlg4.Destroy
def OnSize(self, evt):
self.conteneur.SetSize(self.GetClientSize())
def OnAmorcage(self, evt):
if self.compteurtime <= 0:
return
self.timer.Start(1000)
self.timetext.SetLabel(str(self.compteurtime)+" segondes")
self.Exit.Disable()
self.Amorce.Disable()
self.Desamorce.Enable()
def OnDesamorcage(self, evt):
while self.auto != 1:
dlg3 = wx.PasswordEntryDialog(self, 'Entrez le mot de passe pour desactiver la bombe :','Erreur, mot de passe requis !')
if dlg3.ShowModal() == wx.ID_OK:
if dlg3.GetValue() == self.password:
dlg3.Destroy()
self.auto = 1
if self.compteurtime == 0 or self.compteurtime <= 0 or not self.timer.IsRunning():
return
self.timer.Stop()
self.timetext.SetLabel(str(self.compteurtime)+" segondes")
wx.Bell()
self.Exit.Enable()
self.Amorce.Enable()
self.Desamorce.Disable()
else:
self.auto = 1
dlg3.Destroy()
self.auto = 0
def OnTimer(self, event):
self.compteurtime = self.compteurtime -1
self.timetext.SetLabel(str(self.compteurtime)+" segondes")
if self.compteurtime == 0:
self.timer.Stop()
self.timetext.SetLabel('Boum !!!')
dlg2 = wx.MessageDialog(None, "Boum !", "Boum !", wx.OK|wx.ICON_ERROR)
retCode = dlg2.ShowModal()
if retCode == wx.ID_OK:
dlg2.Destroy
self.Exit.Enable()
self.Amorce.Enable()
self.Desamorce.Disable()
def OnClose(self, evt):
if self.compteurtime == 0 or not self.timer.IsRunning():
self.Destroy()
else:
dlg4 = wx.MessageDialog(None, "Erreur : Il faut désamorçer la bombe avant de pouvoir quitter !".decode('utf8'), "Erreur", wx.OK|wx.ICON_ERROR)
retCode = dlg4.ShowModal()
if retCode == wx.ID_OK:
dlg4.Destroy
class MonApp(wx.App):
def OnInit(self):
fen = apPrincipale("Bombe")
fen.Show(True)
self.SetTopWindow(fen)
return True
if __name__ == "__main__":
app = MonApp()
app.MainLoop() |
Partager