source: src/mlx/gui/pirep.py@ 222:08d0fc465f9d

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

Translated the PIREP viewer texts to Hungarian

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