source: src/mlx/gui/pirep.py@ 220:96ad81e11b85

Last change on this file since 220:96ad81e11b85 was 220:96ad81e11b85, checked in by István Váradi <ivaradi@…>, 12 years ago

The Data tab of the PIREP viewer works

File size: 18.5 KB
Line 
1# Module for the detailed PIREP viewer
2
3#------------------------------------------------------------------------------
4
5from common import *
6
7from mlx.const import *
8
9import time
10
11#------------------------------------------------------------------------------
12
13class PIREPViewer(gtk.Dialog):
14 """The dialog for PIREP viewing."""
15 @staticmethod
16 def createFrame(label):
17 """Create a frame with the given label.
18
19 The frame will contain an alignment to properly distance the
20 insides. The alignment will contain a VBox to contain the real
21 contents.
22
23 The function returns a tuple with the following items:
24 - the frame,
25 - the inner VBox."""
26 frame = gtk.Frame(label = label)
27
28 alignment = gtk.Alignment(xalign = 0.0, yalign = 0.0,
29 xscale = 1.0, yscale = 1.0)
30 frame.add(alignment)
31 alignment.set_padding(padding_top = 4, padding_bottom = 4,
32 padding_left = 4, padding_right = 4)
33 box = gtk.VBox()
34 alignment.add(box)
35
36 return (frame, box)
37
38 @staticmethod
39 def getLabel(text):
40 """Get a bold label with the given text."""
41 label = gtk.Label("<b>" + text + "</b>")
42 label.set_use_markup(True)
43 label.set_alignment(0.0, 0.5)
44 return label
45
46 @staticmethod
47 def getDataLabel(width = None, xAlignment = 0.0):
48 """Get a bold label with the given text."""
49 label = gtk.Label()
50 if width is not None:
51 label.set_width_chars(width)
52 label.set_alignment(xAlignment, 0.5)
53 return label
54
55 @staticmethod
56 def getTextWindow(heightRequest = 40):
57 """Get a scrollable text window.
58
59 Returns a tuple of the following items:
60 - the window,
61 - the text view."""
62 scrolledWindow = gtk.ScrolledWindow()
63 scrolledWindow.set_shadow_type(SHADOW_IN)
64 scrolledWindow.set_policy(POLICY_AUTOMATIC, POLICY_AUTOMATIC)
65
66 textView = gtk.TextView()
67 textView.set_wrap_mode(WRAP_WORD)
68 textView.set_editable(False)
69 textView.set_cursor_visible(False)
70 textView.set_size_request(-1, heightRequest)
71 scrolledWindow.add(textView)
72
73 return (scrolledWindow, textView)
74
75 @staticmethod
76 def tableAttach(table, column, row, labelText, width = None,
77 dataLabelXAlignment = 0.0):
78 """Attach a labeled data to the given column and row of the
79 table.
80
81 If width is given, that will be the width of the data
82 label.
83
84 Returns the data label attached."""
85 dataBox = gtk.HBox()
86 table.attach(dataBox, column, column+1, row, row+1)
87
88 dataLabel = PIREPViewer.addLabeledData(dataBox, labelText,
89 width = width)
90 dataLabel.set_alignment(dataLabelXAlignment, 0.5)
91
92 return dataLabel
93
94 @staticmethod
95 def addLabeledData(hBox, labelText, width = None, dataPadding = 8):
96 """Add a label and a data label to the given HBox.
97
98 Returnsd the data label."""
99 label = PIREPViewer.getLabel(labelText)
100 hBox.pack_start(label, False, False, 0)
101
102 dataLabel = PIREPViewer.getDataLabel(width = width)
103 hBox.pack_start(dataLabel, False, False, dataPadding)
104
105 return dataLabel
106
107 @staticmethod
108 def addVFiller(vBox, height = 4):
109 """Add a filler eventbox to the given vertical box."""
110 filler = gtk.EventBox()
111 filler.set_size_request(-1, height)
112 vBox.pack_start(filler, False, False, 0)
113
114 @staticmethod
115 def timestamp2text(label, timestamp):
116 """Convert the given timestamp into a text containing the hour
117 and minute in UTC and put that text into the given label."""
118 tm = time.gmtime(timestamp)
119 label.set_text("%02d:%02d" % (tm.tm_hour, tm.tm_min))
120
121 def __init__(self, gui):
122 """Construct the PIREP viewer."""
123 super(PIREPViewer, self).__init__(title = WINDOW_TITLE_BASE +
124 " - " +
125 xstr("pirepView_title"),
126 parent = gui.mainWindow)
127
128 self.set_resizable(False)
129
130 self._gui = gui
131
132 contentArea = self.get_content_area()
133 dataTab = self._buildDataTab()
134 contentArea.pack_start(dataTab, False, False, 0)
135
136 def setPIREP(self, pirep):
137 """Setup the data in the dialog from the given PIREP."""
138 bookedFlight = pirep.bookedFlight
139
140 self._callsign.set_text(bookedFlight.callsign)
141 self._tailNumber.set_text(bookedFlight.tailNumber)
142 aircraftType = xstr("aircraft_" + icaoCodes[bookedFlight.aircraftType].lower())
143 self._aircraftType.set_text(aircraftType)
144
145 self._departureICAO.set_text(bookedFlight.departureICAO)
146 self._departureTime.set_text("%02d:%02d" % \
147 (bookedFlight.departureTime.hour,
148 bookedFlight.departureTime.minute))
149
150 self._arrivalICAO.set_text(bookedFlight.arrivalICAO)
151 self._arrivalTime.set_text("%02d:%02d" % \
152 (bookedFlight.arrivalTime.hour,
153 bookedFlight.arrivalTime.minute))
154
155 self._numPassengers.set_text(str(bookedFlight.numPassengers))
156 self._numCrew.set_text(str(bookedFlight.numCrew))
157 self._bagWeight.set_text(str(bookedFlight.bagWeight))
158 self._cargoWeight.set_text(str(bookedFlight.cargoWeight))
159 self._mailWeight.set_text(str(bookedFlight.mailWeight))
160
161 self._route.get_buffer().set_text(bookedFlight.route)
162
163 self._filedCruiseLevel.set_text("FL" + str(pirep.filedCruiseAltitude/100))
164
165 if pirep.cruiseAltitude != pirep.filedCruiseAltitude:
166 self._modifiedCruiseLevel.set_text("FL" + str(pirep.cruiseAltitude/100))
167 else:
168 self._modifiedCruiseLevel.set_text("-")
169
170 self._userRoute.get_buffer().set_text(pirep.route)
171
172 self._departureMETAR.get_buffer().set_text(pirep.departureMETAR)
173
174 self._arrivalMETAR.get_buffer().set_text(pirep.arrivalMETAR)
175 self._departureRunway.set_text(pirep.departureRunway)
176 self._sid.set_text(pirep.sid)
177
178 self._star.set_text("-" if pirep.star is None else pirep.star)
179 self._transition.set_text("-" if pirep.transition is None else pirep.transition)
180 self._approachType.set_text(pirep.approachType)
181 self._arrivalRunway.set_text(pirep.arrivalRunway)
182
183 PIREPViewer.timestamp2text(self._blockTimeStart, pirep.blockTimeStart)
184 PIREPViewer.timestamp2text(self._blockTimeEnd, pirep.blockTimeEnd)
185 PIREPViewer.timestamp2text(self._flightTimeStart, pirep.flightTimeStart)
186 PIREPViewer.timestamp2text(self._flightTimeEnd, pirep.flightTimeEnd)
187
188 self._flownDistance.set_text("%.1f" % (pirep.flownDistance,))
189 self._fuelUsed.set_text("%.0f" % (pirep.fuelUsed,))
190
191 rating = pirep.rating
192 if rating<0:
193 self._rating.set_markup('<b><span foreground="red">NO GO</span></b>')
194 else:
195 self._rating.set_text("%.1f %%" % (rating,))
196
197 self._flightType.set_text(xstr("flighttype_" +
198 flightType2string(pirep.flightType)))
199 self._online.set_text(xstr("pirepView_" +
200 ("yes" if pirep.online else "no")))
201
202 delayCodes = ""
203 for code in pirep.delayCodes:
204 if delayCodes: delayCodes += ", "
205 delayCodes += PIREP.delayCodes[code]
206
207 self._delayCodes.get_buffer().set_text(delayCodes)
208
209 def _buildDataTab(self):
210 """Build the data tab of the viewer."""
211 table = gtk.Table(1, 2)
212 table.set_row_spacings(4)
213 table.set_col_spacings(16)
214 table.set_homogeneous(True)
215
216 box1 = gtk.VBox()
217 table.attach(box1, 0, 1, 0, 1)
218
219 box2 = gtk.VBox()
220 table.attach(box2, 1, 2, 0, 1)
221
222 flightFrame = self._buildFlightFrame()
223 box1.pack_start(flightFrame, False, False, 4)
224
225 routeFrame = self._buildRouteFrame()
226 box1.pack_start(routeFrame, False, False, 4)
227
228 departureFrame = self._buildDepartureFrame()
229 box2.pack_start(departureFrame, True, True, 4)
230
231 arrivalFrame = self._buildArrivalFrame()
232 box2.pack_start(arrivalFrame, True, True, 4)
233
234 statisticsFrame = self._buildStatisticsFrame()
235 box2.pack_start(statisticsFrame, False, False, 4)
236
237 miscellaneousFrame = self._buildMiscellaneousFrame()
238 box1.pack_start(miscellaneousFrame, False, False, 4)
239
240 return table
241
242 def _buildFlightFrame(self):
243 """Build the frame for the flight data."""
244
245 (frame, mainBox) = PIREPViewer.createFrame(xstr("pirepView_frame_flight"))
246
247 dataBox = gtk.HBox()
248 mainBox.pack_start(dataBox, False, False, 0)
249
250 self._callsign = \
251 PIREPViewer.addLabeledData(dataBox,
252 xstr("pirepView_callsign"),
253 width = 8)
254
255 self._tailNumber = \
256 PIREPViewer.addLabeledData(dataBox,
257 xstr("pirepView_tailNumber"),
258 width = 7)
259
260 PIREPViewer.addVFiller(mainBox)
261
262 dataBox = gtk.HBox()
263 mainBox.pack_start(dataBox, False, False, 0)
264
265 self._aircraftType = \
266 PIREPViewer.addLabeledData(dataBox,
267 xstr("pirepView_aircraftType"),
268 width = 25)
269
270 PIREPViewer.addVFiller(mainBox)
271
272 table = gtk.Table(3, 2)
273 mainBox.pack_start(table, False, False, 0)
274 table.set_row_spacings(4)
275 table.set_col_spacings(8)
276
277 self._departureICAO = \
278 PIREPViewer.tableAttach(table, 0, 0,
279 xstr("pirepView_departure"),
280 width = 5)
281
282 self._departureTime = \
283 PIREPViewer.tableAttach(table, 1, 0,
284 xstr("pirepView_departure_time"),
285 width = 6)
286
287 self._arrivalICAO = \
288 PIREPViewer.tableAttach(table, 0, 1,
289 xstr("pirepView_arrival"),
290 width = 5)
291
292 self._arrivalTime = \
293 PIREPViewer.tableAttach(table, 1, 1,
294 xstr("pirepView_arrival_time"),
295 width = 6)
296
297 PIREPViewer.addVFiller(mainBox)
298
299 table = gtk.Table(3, 2)
300 mainBox.pack_start(table, False, False, 0)
301 table.set_row_spacings(4)
302 table.set_col_spacings(8)
303
304 self._numPassengers = \
305 PIREPViewer.tableAttach(table, 0, 0,
306 xstr("pirepView_numPassengers"),
307 width = 4)
308
309 self._numCrew = \
310 PIREPViewer.tableAttach(table, 1, 0,
311 xstr("pirepView_numCrew"),
312 width = 3)
313
314 self._bagWeight = \
315 PIREPViewer.tableAttach(table, 0, 1,
316 xstr("pirepView_bagWeight"),
317 width = 5)
318
319 self._cargoWeight = \
320 PIREPViewer.tableAttach(table, 1, 1,
321 xstr("pirepView_cargoWeight"),
322 width = 5)
323
324 self._mailWeight = \
325 PIREPViewer.tableAttach(table, 2, 1,
326 xstr("pirepView_mailWeight"),
327 width = 5)
328
329 PIREPViewer.addVFiller(mainBox)
330
331 mainBox.pack_start(PIREPViewer.getLabel(xstr("pirepView_route")),
332 False, False, 0)
333
334 (routeWindow, self._route) = PIREPViewer.getTextWindow()
335 mainBox.pack_start(routeWindow, False, False, 0)
336
337 return frame
338
339 def _buildRouteFrame(self):
340 """Build the frame for the user-specified route and flight
341 level."""
342
343 (frame, mainBox) = PIREPViewer.createFrame(xstr("pirepView_frame_route"))
344
345 levelBox = gtk.HBox()
346 mainBox.pack_start(levelBox, False, False, 0)
347
348 self._filedCruiseLevel = \
349 PIREPViewer.addLabeledData(levelBox,
350 xstr("pirepView_filedCruiseLevel"),
351 width = 6)
352
353 self._modifiedCruiseLevel = \
354 PIREPViewer.addLabeledData(levelBox,
355 xstr("pirepView_modifiedCruiseLevel"),
356 width = 6)
357
358 PIREPViewer.addVFiller(mainBox)
359
360 (routeWindow, self._userRoute) = PIREPViewer.getTextWindow()
361 mainBox.pack_start(routeWindow, False, False, 0)
362
363 return frame
364
365 def _buildDepartureFrame(self):
366 """Build the frame for the departure data."""
367 (frame, mainBox) = PIREPViewer.createFrame(xstr("pirepView_frame_departure"))
368
369 mainBox.pack_start(PIREPViewer.getLabel("METAR:"),
370 False, False, 0)
371 (metarWindow, self._departureMETAR) = \
372 PIREPViewer.getTextWindow(heightRequest = -1)
373 mainBox.pack_start(metarWindow, True, True, 0)
374
375 PIREPViewer.addVFiller(mainBox)
376
377 dataBox = gtk.HBox()
378 mainBox.pack_start(dataBox, False, False, 0)
379
380 self._departureRunway = \
381 PIREPViewer.addLabeledData(dataBox,
382 xstr("pirepView_runway"),
383 width = 5)
384
385 self._sid = \
386 PIREPViewer.addLabeledData(dataBox,
387 xstr("pirepView_sid"),
388 width = 12)
389
390 return frame
391
392 def _buildArrivalFrame(self):
393 """Build the frame for the arrival data."""
394 (frame, mainBox) = PIREPViewer.createFrame(xstr("pirepView_frame_arrival"))
395
396 mainBox.pack_start(PIREPViewer.getLabel("METAR:"),
397 False, False, 0)
398 (metarWindow, self._arrivalMETAR) = \
399 PIREPViewer.getTextWindow(heightRequest = -1)
400 mainBox.pack_start(metarWindow, True, True, 0)
401
402 PIREPViewer.addVFiller(mainBox)
403
404 table = gtk.Table(2, 2)
405 mainBox.pack_start(table, False, False, 0)
406 table.set_row_spacings(4)
407 table.set_col_spacings(8)
408
409 self._star = \
410 PIREPViewer.tableAttach(table, 0, 0,
411 xstr("pirepView_star"),
412 width = 12)
413
414 self._transition = \
415 PIREPViewer.tableAttach(table, 1, 0,
416 xstr("pirepView_transition"),
417 width = 12)
418
419 self._approachType = \
420 PIREPViewer.tableAttach(table, 0, 1,
421 xstr("pirepView_approachType"),
422 width = 7)
423
424 self._arrivalRunway = \
425 PIREPViewer.tableAttach(table, 1, 1,
426 xstr("pirepView_runway"),
427 width = 5)
428
429 return frame
430
431 def _buildStatisticsFrame(self):
432 """Build the frame for the statistics data."""
433 (frame, mainBox) = PIREPViewer.createFrame(xstr("pirepView_frame_statistics"))
434
435 table = gtk.Table(4, 2)
436 mainBox.pack_start(table, False, False, 0)
437 table.set_row_spacings(4)
438 table.set_col_spacings(8)
439
440 self._blockTimeStart = \
441 PIREPViewer.tableAttach(table, 0, 0,
442 xstr("pirepView_blockTimeStart"),
443 width = 6)
444
445 self._blockTimeEnd = \
446 PIREPViewer.tableAttach(table, 1, 0,
447 xstr("pirepView_blockTimeEnd"),
448 width = 8)
449
450 self._flightTimeStart = \
451 PIREPViewer.tableAttach(table, 0, 1,
452 xstr("pirepView_flightTimeStart"),
453 width = 6)
454
455 self._flightTimeEnd = \
456 PIREPViewer.tableAttach(table, 1, 1,
457 xstr("pirepView_flightTimeEnd"),
458 width = 6)
459
460 self._flownDistance = \
461 PIREPViewer.tableAttach(table, 0, 2,
462 xstr("pirepView_flownDistance"),
463 width = 8)
464
465 self._fuelUsed = \
466 PIREPViewer.tableAttach(table, 1, 2,
467 xstr("pirepView_fuelUsed"),
468 width = 6)
469
470 self._rating = \
471 PIREPViewer.tableAttach(table, 0, 3,
472 xstr("pirepView_rating"),
473 width = 7)
474 return frame
475
476 def _buildMiscellaneousFrame(self):
477 """Build the frame for the miscellaneous data."""
478 (frame, mainBox) = PIREPViewer.createFrame(xstr("pirepView_frame_miscellaneous"))
479
480 dataBox = gtk.HBox()
481 mainBox.pack_start(dataBox, False, False, 0)
482
483 self._flightType = \
484 PIREPViewer.addLabeledData(dataBox,
485 xstr("pirepView_flightType"),
486 width = 10)
487
488 self._online = \
489 PIREPViewer.addLabeledData(dataBox,
490 xstr("pirepView_online"),
491 width = 5)
492
493 PIREPViewer.addVFiller(mainBox)
494
495 mainBox.pack_start(PIREPViewer.getLabel(xstr("pirepView_delayCodes")),
496 False, False, 0)
497
498 (textWindow, self._delayCodes) = PIREPViewer.getTextWindow()
499 mainBox.pack_start(textWindow, False, False, 0)
500
501 return frame
502
503#------------------------------------------------------------------------------
504#------------------------------------------------------------------------------
505#------------------------------------------------------------------------------
506#------------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.