Bonjour,

j'avance dans ma découverte de Python. La pente est rude

J'essaye de créer une application de gestion de strips pour le contrôle aérien (c'est de la simulation). Les avions prêts au départ apparaissent dans un couloir : Attente. Au premier contact radio avec le pilote, je souhaite basculer la boîte correspondant à mon avion dans le couloir Clairance. Avec les événements, je réussi à cliquer sur une boîte, l'identifier, ajouter un bouton : Assume mais comment faire pour que le Strip passe d'un couloir à l'autre ?

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
#!/usr/bin/python
# -*- coding: utf-8 -*- 
 
###########################################################################
## Dépendances
###########################################################################
 
import wx
import wx.xrc
import wx.html
import urllib2
import re
from urllib2 import Request, urlopen, URLError, HTTPError
 
###########################################################################
## Lecture des messages
###########################################################################
 
messages = """VOE2514:375331:375331:47.5515:7.58546:31738:464:1/A319/M-SDE1FGHIJ1RWXYZ/LB1:N0474:LFST:F230:LFML:I:0104:0159:LFMT:PBN/A1B1C1D1L1O1S1 NAV/RNVD1E2A1 DOF/161223 REG/EIFMT EET/EDGG0005 LSAS0012 LFFF0028 LFMM0049 RVR/75 PER/C:LUPEN Y711 NATOR N850 TRA/N0447F370 UZ669 MILPA UZ66 ARGIS UY105 LSE A6 MTL:S:227:0:D
LIT079:133709:133709:46.4471:4.16915:3015:184:1/TB30/L-SADE1FGIRWY/S:N0450:LFBR:VFR:LFST:V:0230:0330:LFGA:CS/LITTORAL AIRLINES RMK/TCAS EQUIPPED:TLF TIS DJL LUL STR:S:36:0:A
KVL77RG:424342:regis GANDAHO:48.5342:2.86754:6560:286:1/B77L/H-SDRWY/S:M084:LFST:F280:LFPO:I:0035:0130::RMK/TCAS EQUIPPED:POGOL UM164 EPL:S:333:0:D
AFR500:464274:464274:48.0093:6.68491:26574:383:1/A320/M-SDEHIRWXYZ/S:N0300:LFST:F310:LFMN:I:0115:0230::EET/LFFF0008 LECM0122 LPPC0148 REG/CSTTN SEL/BLMC COM/ACAS II EQPD DOF/030710 SRC/RQP ORGN/LISOWTP:MIRGU UN852 TIRSO UZ24 ARPUS UN852 TORPA UZ24 MOROK UN852 MILPA UM730 KOGAS UQ225 VEVAR:S:195:0:D
AEL002:215663:Jean Pierre Nicole:49.3007:3.82777:12094:356:1/A320/M-SDE3FGHIRWY/LB1:N0429:LFST:F250:LFOB:I:0042:0212:LFQQ:CS/AIR EUROPE PBN/A1B1C1D1O1S1S2  REG/FHBNJ EET/LFFF0007 OPR/AEL RMK/TCAS:POGOL UM164 TRO:N:275:0:D"""
 
## Mettre les messages en multi array
lines = re.split("[!\n]",messages)
nbStrip = len(lines)
 
stock = []
for line in lines:
	valeurs = re.split("[!\:]",line)
	new = []
	for valeur in valeurs:
		new.append(valeur)
	stock.append(new)
 
###########################################################################
## Design page
###########################################################################
 
class MyFrame1 ( wx.Frame ):
 
	def __init__( self, parent ):
		wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = u"ATCx", pos =(800,200), size = wx.Size( 1500,745 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )
 
		self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )
		self.SetBackgroundColour( wx.Colour( 223, 255, 223 ) )
 
		# menu
		self.m_menubar1 = wx.MenuBar( 0 )
		self.m_menu1 = wx.Menu()
		self.m_menuItem1 = wx.MenuItem( self.m_menu1, wx.ID_ANY, u"Paramètres", wx.EmptyString, wx.ITEM_NORMAL )
		self.m_menu1.AppendItem( self.m_menuItem1 )
 
		self.m_menubar1.Append( self.m_menu1, u"Fonctions" ) 
 
		self.SetMenuBar( self.m_menubar1 )
 
		# grid
		grille = wx.FlexGridSizer( 6, 7, 0, 0 )
		grille.SetFlexibleDirection( wx.BOTH )
		grille.SetNonFlexibleGrowMode( wx.FLEX_GROWMODE_SPECIFIED )
 
		# lanes
		attente = wx.StaticBoxSizer( wx.StaticBox( self, wx.ID_ANY, u"Attente" ), wx.VERTICAL )
		attente.SetMinSize( wx.Size( 140,12 ) )
		grille.Add( attente, 1, wx.EXPAND, 5 )
 
		clairance = wx.StaticBoxSizer( wx.StaticBox( self, wx.ID_ANY, u"Clairance" ), wx.VERTICAL )
		clairance.SetMinSize( wx.Size( 140,12 ) ) 
		grille.Add( clairance, 1, wx.EXPAND, 5 )
 
		repoussage = wx.StaticBoxSizer( wx.StaticBox( self, wx.ID_ANY, u"Repoussage" ), wx.VERTICAL )
		repoussage.SetMinSize( wx.Size( 140,12 ) ) 
		grille.Add( repoussage, 1, wx.EXPAND, 5 )
 
		taxi = wx.StaticBoxSizer( wx.StaticBox( self, wx.ID_ANY, u"Taxi" ), wx.VERTICAL )
		taxi.SetMinSize( wx.Size( 140,12 ) ) 
		grille.Add( taxi, 1, wx.EXPAND, 5 )
 
		luto = wx.StaticBoxSizer( wx.StaticBox( self, wx.ID_ANY, u"LU & TO" ), wx.VERTICAL )
		luto.SetMinSize( wx.Size( 140,12 ) ) 
		grille.Add( luto, 1, wx.EXPAND, 5 )
 
		transfert = wx.StaticBoxSizer( wx.StaticBox( self, wx.ID_ANY, u"Transfert" ), wx.VERTICAL )
		transfert.SetMinSize( wx.Size( 140,12 ) ) 
		grille.Add( transfert, 1, wx.EXPAND, 5 )
 
		blabla = wx.StaticBoxSizer( wx.StaticBox( self, wx.ID_ANY, u"Commandes" ), wx.VERTICAL )
		blabla.SetMinSize( wx.Size( 600,12 ) ) 
		grille.Add( blabla, 1, wx.EXPAND, 5 )
 
		################################################################
		## Strips
		################################################################
		for i in range(nbStrip-1):
			self.aircraft = wx.html.HtmlWindow( attente.GetStaticBox(), i, wx.DefaultPosition, wx.Size( 150,100 ), 0 )
			if stock[i][21]=="D":
				couleur = "Yellow"
				SID = stock[i][17].split(' ', 1)[0]
				if SID.isalpha() == False:
					couleur = "Red"
			else:
				couleur = "White"
				SID =""
 
			# si pas déjà assumé	    
			callsign = stock[i][0]
			aboutText = """<strong>""" + callsign + """</strong> - """ + stock[i][7][2:6]  + """<br/>""" + SID + """"""
			self.aircraft.SetPage(aboutText)
 
			attente.Add( self.aircraft, 0, wx.ALL, 5 )
			self.aircraft.SetBackgroundColour(couleur)
 
			# afficher les éléments
			self.SetSizer( grille )
			self.Layout()
 
			self.Centre( wx.BOTH )
 
			# Connect Events
			self.aircraft.Bind( wx.EVT_LEFT_DOWN, lambda evt = wx.EVT_LEFT_DOWN, arg =(i, stock[i], blabla) : self.Details(evt, arg), self.aircraft )
			# http://www.developpez.net/forums/d34285/autres-langages/python-zope/gui/wxpython/wxpython-ev-nement-bouton/
 
		self.Show(True)	
 
	def __del__( self ):
		pass
 
	# Afficher les détails et les boutons de commande
	def Details( self, event, argument ):
		print argument
		i = str(argument[0])
		stock = argument[1]
		blabla = argument[2]
		aboutText = """<p>Appareil : """ + stock[0] + """</p>"""
		self.detail = wx.html.HtmlWindow( blabla.GetStaticBox(), wx.ID_ANY, wx.Point(5,20) , wx.Size( 590,650 ), 0 )
		self.detail.SetPage(aboutText)
		self.button=wx.Button( self.detail, label="Clairance", pos=(130,10), size=(60,60) )
		self.detail.Bind( wx.EVT_BUTTON, lambda evt = wx.EVT_BUTTON, arg =(i, stock) : self.Assume(evt, arg), self.button )
		blabla.Add( self.detail, 0, wx.ALL, 5 )
 
	def Assume(  self, event, argument ):
		print argument
                # ICI LE CODE SUIVANT NE FONCTIONNE PAS : AttributeError: 'MyFrame1' object has no attribute 'clairance'
                aircraft  = wx.html.HtmlWindow( self.clairance.GetStaticBox(), wx.ID_ANY,  wx.Point(5,20), wx.Size( 150,100 ), 0 )
		aircraft.SetPage(aboutText)
		aircraft.Add( clairance, 0, wx.ALL, 5 )
		aircraft.SetBackgroundColour("Yellow")	
 
 
def main():
 
	ex = wx.App()
	MyFrame1(None)
	ex.MainLoop()
 
if __name__ == '__main__':
	main()