source: src/mlx/gui/pirep.py@ 234:9e75e8bff310

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

Removed unnecessary printout

File size: 21.1 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
134 self._notebook = gtk.Notebook()
135 contentArea.pack_start(self._notebook, False, False, 4)
136
137 dataTab = self._buildDataTab()
138 label = gtk.Label(xstr("pirepView_tab_data"))
139 label.set_use_underline(True)
140 label.set_tooltip_text(xstr("pirepView_tab_data_tooltip"))
141 self._notebook.append_page(dataTab, label)
142
143 commentsTab = self._buildCommentsTab()
144 label = gtk.Label(xstr("pirepView_tab_comments"))
145 label.set_use_underline(True)
146 label.set_tooltip_text(xstr("pirepView_tab_comments_tooltip"))
147 self._notebook.append_page(commentsTab, label)
148
149 logTab = self._buildLogTab()
150 label = gtk.Label(xstr("pirepView_tab_log"))
151 label.set_use_underline(True)
152 label.set_tooltip_text(xstr("pirepView_tab_log_tooltip"))
153 self._notebook.append_page(logTab, label)
154
155 self._okButton = self.add_button(xstr("button_ok"), RESPONSETYPE_OK)
156 self._okButton.set_can_default(True)
157
158 def setPIREP(self, pirep):
159 """Setup the data in the dialog from the given PIREP."""
160 bookedFlight = pirep.bookedFlight
161
162 self._callsign.set_text(bookedFlight.callsign)
163 self._tailNumber.set_text(bookedFlight.tailNumber)
164 aircraftType = xstr("aircraft_" + icaoCodes[bookedFlight.aircraftType].lower())
165 self._aircraftType.set_text(aircraftType)
166
167 self._departureICAO.set_text(bookedFlight.departureICAO)
168 self._departureTime.set_text("%02d:%02d" % \
169 (bookedFlight.departureTime.hour,
170 bookedFlight.departureTime.minute))
171
172 self._arrivalICAO.set_text(bookedFlight.arrivalICAO)
173 self._arrivalTime.set_text("%02d:%02d" % \
174 (bookedFlight.arrivalTime.hour,
175 bookedFlight.arrivalTime.minute))
176
177 self._numPassengers.set_text(str(bookedFlight.numPassengers))
178 self._numCrew.set_text(str(bookedFlight.numCrew))
179 self._bagWeight.set_text(str(bookedFlight.bagWeight))
180 self._cargoWeight.set_text(str(bookedFlight.cargoWeight))
181 self._mailWeight.set_text(str(bookedFlight.mailWeight))
182
183 self._route.get_buffer().set_text(bookedFlight.route)
184
185 self._filedCruiseLevel.set_text("FL" + str(pirep.filedCruiseAltitude/100))
186
187 if pirep.cruiseAltitude != pirep.filedCruiseAltitude:
188 self._modifiedCruiseLevel.set_text("FL" + str(pirep.cruiseAltitude/100))
189 else:
190 self._modifiedCruiseLevel.set_text("-")
191
192 self._userRoute.get_buffer().set_text(pirep.route)
193
194 self._departureMETAR.get_buffer().set_text(pirep.departureMETAR)
195
196 self._arrivalMETAR.get_buffer().set_text(pirep.arrivalMETAR)
197 self._departureRunway.set_text(pirep.departureRunway)
198 self._sid.set_text(pirep.sid)
199
200 self._star.set_text("-" if pirep.star is None else pirep.star)
201 self._transition.set_text("-" if pirep.transition is None else pirep.transition)
202 self._approachType.set_text(pirep.approachType)
203 self._arrivalRunway.set_text(pirep.arrivalRunway)
204
205 PIREPViewer.timestamp2text(self._blockTimeStart, pirep.blockTimeStart)
206 PIREPViewer.timestamp2text(self._blockTimeEnd, pirep.blockTimeEnd)
207 PIREPViewer.timestamp2text(self._flightTimeStart, pirep.flightTimeStart)
208 PIREPViewer.timestamp2text(self._flightTimeEnd, pirep.flightTimeEnd)
209
210 self._flownDistance.set_text("%.1f" % (pirep.flownDistance,))
211 self._fuelUsed.set_text("%.0f" % (pirep.fuelUsed,))
212
213 rating = pirep.rating
214 if rating<0:
215 self._rating.set_markup('<b><span foreground="red">NO GO</span></b>')
216 else:
217 self._rating.set_text("%.1f %%" % (rating,))
218
219 self._flownCargoWeight.set_text("%.0f" % (pirep.cargoWeight,))
220 self._flightType.set_text(xstr("flighttype_" +
221 flightType2string(pirep.flightType)))
222 self._online.set_text(xstr("pirepView_" +
223 ("yes" if pirep.online else "no")))
224
225 delayCodes = ""
226 for code in pirep.delayCodes:
227 if delayCodes: delayCodes += ", "
228 delayCodes += PIREP.delayCodes[code]
229
230 self._delayCodes.get_buffer().set_text(delayCodes)
231
232 self._comments.get_buffer().set_text(pirep.comments)
233 self._flightDefects.get_buffer().set_text(pirep.flightDefects)
234
235 logBuffer = self._log.get_buffer()
236 logBuffer.set_text("")
237 lineIndex = 0
238 for (timeStr, line) in pirep.logLines:
239 isFault = lineIndex in pirep.faultLineIndexes
240 appendTextBuffer(logBuffer,
241 formatFlightLogLine(timeStr, line),
242 isFault = isFault)
243 lineIndex += 1
244
245 self._notebook.set_current_page(0)
246 self._okButton.grab_default()
247
248 def _buildDataTab(self):
249 """Build the data tab of the viewer."""
250 table = gtk.Table(1, 2)
251 table.set_row_spacings(4)
252 table.set_col_spacings(16)
253 table.set_homogeneous(True)
254
255 box1 = gtk.VBox()
256 table.attach(box1, 0, 1, 0, 1)
257
258 box2 = gtk.VBox()
259 table.attach(box2, 1, 2, 0, 1)
260
261 flightFrame = self._buildFlightFrame()
262 box1.pack_start(flightFrame, False, False, 4)
263
264 routeFrame = self._buildRouteFrame()
265 box1.pack_start(routeFrame, False, False, 4)
266
267 departureFrame = self._buildDepartureFrame()
268 box2.pack_start(departureFrame, True, True, 4)
269
270 arrivalFrame = self._buildArrivalFrame()
271 box2.pack_start(arrivalFrame, True, True, 4)
272
273 statisticsFrame = self._buildStatisticsFrame()
274 box2.pack_start(statisticsFrame, False, False, 4)
275
276 miscellaneousFrame = self._buildMiscellaneousFrame()
277 box1.pack_start(miscellaneousFrame, False, False, 4)
278
279 return table
280
281 def _buildFlightFrame(self):
282 """Build the frame for the flight data."""
283
284 (frame, mainBox) = PIREPViewer.createFrame(xstr("pirepView_frame_flight"))
285
286 dataBox = gtk.HBox()
287 mainBox.pack_start(dataBox, False, False, 0)
288
289 self._callsign = \
290 PIREPViewer.addLabeledData(dataBox,
291 xstr("pirepView_callsign"),
292 width = 8)
293
294 self._tailNumber = \
295 PIREPViewer.addLabeledData(dataBox,
296 xstr("pirepView_tailNumber"),
297 width = 7)
298
299 PIREPViewer.addVFiller(mainBox)
300
301 dataBox = gtk.HBox()
302 mainBox.pack_start(dataBox, False, False, 0)
303
304 self._aircraftType = \
305 PIREPViewer.addLabeledData(dataBox,
306 xstr("pirepView_aircraftType"),
307 width = 25)
308
309 PIREPViewer.addVFiller(mainBox)
310
311 table = gtk.Table(3, 2)
312 mainBox.pack_start(table, False, False, 0)
313 table.set_row_spacings(4)
314 table.set_col_spacings(8)
315
316 self._departureICAO = \
317 PIREPViewer.tableAttach(table, 0, 0,
318 xstr("pirepView_departure"),
319 width = 5)
320
321 self._departureTime = \
322 PIREPViewer.tableAttach(table, 1, 0,
323 xstr("pirepView_departure_time"),
324 width = 6)
325
326 self._arrivalICAO = \
327 PIREPViewer.tableAttach(table, 0, 1,
328 xstr("pirepView_arrival"),
329 width = 5)
330
331 self._arrivalTime = \
332 PIREPViewer.tableAttach(table, 1, 1,
333 xstr("pirepView_arrival_time"),
334 width = 6)
335
336 table = gtk.Table(3, 2)
337 mainBox.pack_start(table, False, False, 0)
338 table.set_row_spacings(4)
339 table.set_col_spacings(8)
340
341 self._numPassengers = \
342 PIREPViewer.tableAttach(table, 0, 0,
343 xstr("pirepView_numPassengers"),
344 width = 4)
345
346 self._numCrew = \
347 PIREPViewer.tableAttach(table, 1, 0,
348 xstr("pirepView_numCrew"),
349 width = 3)
350
351 self._bagWeight = \
352 PIREPViewer.tableAttach(table, 0, 1,
353 xstr("pirepView_bagWeight"),
354 width = 5)
355
356 self._cargoWeight = \
357 PIREPViewer.tableAttach(table, 1, 1,
358 xstr("pirepView_cargoWeight"),
359 width = 5)
360
361 self._mailWeight = \
362 PIREPViewer.tableAttach(table, 2, 1,
363 xstr("pirepView_mailWeight"),
364 width = 5)
365
366 PIREPViewer.addVFiller(mainBox)
367
368 mainBox.pack_start(PIREPViewer.getLabel(xstr("pirepView_route")),
369 False, False, 0)
370
371 (routeWindow, self._route) = PIREPViewer.getTextWindow()
372 mainBox.pack_start(routeWindow, False, False, 0)
373
374 return frame
375
376 def _buildRouteFrame(self):
377 """Build the frame for the user-specified route and flight
378 level."""
379
380 (frame, mainBox) = PIREPViewer.createFrame(xstr("pirepView_frame_route"))
381
382 levelBox = gtk.HBox()
383 mainBox.pack_start(levelBox, False, False, 0)
384
385 self._filedCruiseLevel = \
386 PIREPViewer.addLabeledData(levelBox,
387 xstr("pirepView_filedCruiseLevel"),
388 width = 6)
389
390 self._modifiedCruiseLevel = \
391 PIREPViewer.addLabeledData(levelBox,
392 xstr("pirepView_modifiedCruiseLevel"),
393 width = 6)
394
395 PIREPViewer.addVFiller(mainBox)
396
397 (routeWindow, self._userRoute) = PIREPViewer.getTextWindow()
398 mainBox.pack_start(routeWindow, False, False, 0)
399
400 return frame
401
402 def _buildDepartureFrame(self):
403 """Build the frame for the departure data."""
404 (frame, mainBox) = PIREPViewer.createFrame(xstr("pirepView_frame_departure"))
405
406 mainBox.pack_start(PIREPViewer.getLabel("METAR:"),
407 False, False, 0)
408 (metarWindow, self._departureMETAR) = \
409 PIREPViewer.getTextWindow(heightRequest = -1)
410 mainBox.pack_start(metarWindow, True, True, 0)
411
412 PIREPViewer.addVFiller(mainBox)
413
414 dataBox = gtk.HBox()
415 mainBox.pack_start(dataBox, False, False, 0)
416
417 self._departureRunway = \
418 PIREPViewer.addLabeledData(dataBox,
419 xstr("pirepView_runway"),
420 width = 5)
421
422 self._sid = \
423 PIREPViewer.addLabeledData(dataBox,
424 xstr("pirepView_sid"),
425 width = 12)
426
427 return frame
428
429 def _buildArrivalFrame(self):
430 """Build the frame for the arrival data."""
431 (frame, mainBox) = PIREPViewer.createFrame(xstr("pirepView_frame_arrival"))
432
433 mainBox.pack_start(PIREPViewer.getLabel("METAR:"),
434 False, False, 0)
435 (metarWindow, self._arrivalMETAR) = \
436 PIREPViewer.getTextWindow(heightRequest = -1)
437 mainBox.pack_start(metarWindow, True, True, 0)
438
439 PIREPViewer.addVFiller(mainBox)
440
441 table = gtk.Table(2, 2)
442 mainBox.pack_start(table, False, False, 0)
443 table.set_row_spacings(4)
444 table.set_col_spacings(8)
445
446 self._star = \
447 PIREPViewer.tableAttach(table, 0, 0,
448 xstr("pirepView_star"),
449 width = 12)
450
451 self._transition = \
452 PIREPViewer.tableAttach(table, 1, 0,
453 xstr("pirepView_transition"),
454 width = 12)
455
456 self._approachType = \
457 PIREPViewer.tableAttach(table, 0, 1,
458 xstr("pirepView_approachType"),
459 width = 7)
460
461 self._arrivalRunway = \
462 PIREPViewer.tableAttach(table, 1, 1,
463 xstr("pirepView_runway"),
464 width = 5)
465
466 return frame
467
468 def _buildStatisticsFrame(self):
469 """Build the frame for the statistics data."""
470 (frame, mainBox) = PIREPViewer.createFrame(xstr("pirepView_frame_statistics"))
471
472 table = gtk.Table(4, 2)
473 mainBox.pack_start(table, False, False, 0)
474 table.set_row_spacings(4)
475 table.set_col_spacings(8)
476 table.set_homogeneous(False)
477
478 self._blockTimeStart = \
479 PIREPViewer.tableAttach(table, 0, 0,
480 xstr("pirepView_blockTimeStart"),
481 width = 6)
482
483 self._blockTimeEnd = \
484 PIREPViewer.tableAttach(table, 1, 0,
485 xstr("pirepView_blockTimeEnd"),
486 width = 8)
487
488 self._flightTimeStart = \
489 PIREPViewer.tableAttach(table, 0, 1,
490 xstr("pirepView_flightTimeStart"),
491 width = 6)
492
493 self._flightTimeEnd = \
494 PIREPViewer.tableAttach(table, 1, 1,
495 xstr("pirepView_flightTimeEnd"),
496 width = 6)
497
498 self._flownDistance = \
499 PIREPViewer.tableAttach(table, 0, 2,
500 xstr("pirepView_flownDistance"),
501 width = 8)
502
503 self._fuelUsed = \
504 PIREPViewer.tableAttach(table, 1, 2,
505 xstr("pirepView_fuelUsed"),
506 width = 6)
507
508 self._rating = \
509 PIREPViewer.tableAttach(table, 0, 3,
510 xstr("pirepView_rating"),
511 width = 7)
512 return frame
513
514 def _buildMiscellaneousFrame(self):
515 """Build the frame for the miscellaneous data."""
516 (frame, mainBox) = PIREPViewer.createFrame(xstr("pirepView_frame_miscellaneous"))
517
518 dataBox = gtk.HBox()
519 mainBox.pack_start(dataBox, False, False, 0)
520
521 self._flownCargoWeight = \
522 PIREPViewer.addLabeledData(dataBox,
523 xstr("pirepView_cargoWeight"),
524 width = 6)
525
526 self._flightType = \
527 PIREPViewer.addLabeledData(dataBox,
528 xstr("pirepView_flightType"),
529 width = 10)
530
531 self._online = \
532 PIREPViewer.addLabeledData(dataBox,
533 xstr("pirepView_online"),
534 width = 5)
535
536 PIREPViewer.addVFiller(mainBox)
537
538 mainBox.pack_start(PIREPViewer.getLabel(xstr("pirepView_delayCodes")),
539 False, False, 0)
540
541 (textWindow, self._delayCodes) = PIREPViewer.getTextWindow()
542 mainBox.pack_start(textWindow, False, False, 0)
543
544 return frame
545
546 def _buildCommentsTab(self):
547 """Build the tab with the comments and flight defects."""
548 table = gtk.Table(2, 1)
549 table.set_col_spacings(16)
550
551 (frame, commentsBox) = \
552 PIREPViewer.createFrame(xstr("pirepView_comments"))
553 table.attach(frame, 0, 1, 0, 1)
554
555 (commentsWindow, self._comments) = \
556 PIREPViewer.getTextWindow(heightRequest = -1)
557 commentsBox.pack_start(commentsWindow, True, True, 0)
558
559 (frame, flightDefectsBox) = \
560 PIREPViewer.createFrame(xstr("pirepView_flightDefects"))
561 table.attach(frame, 1, 2, 0, 1)
562
563 (flightDefectsWindow, self._flightDefects) = \
564 PIREPViewer.getTextWindow(heightRequest = -1)
565 flightDefectsBox.pack_start(flightDefectsWindow, True, True, 0)
566
567 return table
568
569 def _buildLogTab(self):
570 """Build the log tab."""
571 mainBox = gtk.VBox()
572
573 (logWindow, self._log) = PIREPViewer.getTextWindow(heightRequest = -1)
574 addFaultTag(self._log.get_buffer())
575 mainBox.pack_start(logWindow, True, True, 0)
576
577 return mainBox
578
579#------------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.