Changeset 214:19fb20505b1a for src/mlx
- Timestamp:
- 05/31/12 18:02:17 (12 years ago)
- Branch:
- default
- Phase:
- public
- Location:
- src/mlx
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mlx/gui/flight.py
r208 r214 375 375 self.setMainWidget(alignment) 376 376 377 self._saveButton = self.addButton(xstr("flightsel_save"), 378 sensitive = False, 379 clicked = self._saveClicked, 380 tooltip = xstr("flightsel_save_tooltip")) 381 self._saveDialog = None 382 377 383 self._refreshButton = self.addButton(xstr("flightsel_refresh"), 378 384 sensitive = True, … … 419 425 flight.arrivalICAO]) 420 426 427 def _saveClicked(self, button): 428 """Called when the Save flight button is clicked.""" 429 flight = self._getSelectedFlight() 430 date = flight.departureTime.date() 431 name = "%04d-%02d-%02d %s %s-%s.vaflight" % \ 432 (date.year, date.month, date.day, flight.callsign, 433 flight.departureICAO, flight.arrivalICAO) 434 435 dialog = self._getSaveDialog() 436 dialog.set_current_name(name) 437 dialog.show_all() 438 response = dialog.run() 439 dialog.hide() 440 441 if response==RESPONSETYPE_OK: 442 fileName = dialog.get_filename() 443 print "Saving", fileName 444 try: 445 with open(fileName, "wt") as f: 446 flight.writeIntoFile(f) 447 except Exception, e: 448 print "Failed to save flight:", str(e) 449 dialog = gtk.MessageDialog(parent = self._wizard.gui.mainWindow, 450 type = MESSAGETYPE_ERROR, 451 message_format = 452 xstr("flightsel_save_failed")) 453 dialog.add_button(xstr("button_ok"), RESPONSETYPE_OK) 454 dialog.set_title(WINDOW_TITLE_BASE) 455 secondary = xstr("flightsel_save_failed_sec") 456 dialog.format_secondary_markup(secondary) 457 dialog.run() 458 dialog.hide() 459 421 460 def _refreshClicked(self, button): 422 461 """Called when the refresh button is clicked.""" … … 430 469 def _selectionChanged(self, selection): 431 470 """Called when the selection is changed.""" 432 self._button.set_sensitive(selection.count_selected_rows()==1) 471 selected = selection.count_selected_rows()==1 472 self._saveButton.set_sensitive(selected) 473 self._button.set_sensitive(selected) 433 474 434 475 def _loadButtonClicked(self, loadButton): … … 465 506 self._wizard.jumpPage(self._nextDistance, finalize = False) 466 507 else: 467 selection = self._flightList.get_selection() 468 (listStore, iter) = selection.get_selected() 469 path = listStore.get_path(iter) 470 [index] = path.get_indices() if pygobject else path 471 472 flight = self._flights[index] 508 flight = self._getSelectedFlight() 473 509 self._wizard._bookedFlight = flight 474 510 self._wizard.gui.enableFlightInfo() 475 511 476 512 self._updateDepartureGate() 513 514 def _getSelectedFlight(self): 515 """Get the currently selected flight.""" 516 selection = self._flightList.get_selection() 517 (listStore, iter) = selection.get_selected() 518 path = listStore.get_path(iter) 519 [index] = path.get_indices() if pygobject else path 520 521 return self._flights[index] 477 522 478 523 def _updateDepartureGate(self): … … 515 560 self._wizard.jumpPage(2) 516 561 562 def _getSaveDialog(self): 563 """Get the dialog to load a flight file.""" 564 if self._saveDialog is not None: 565 return self._saveDialog 566 567 gui = self._wizard.gui 568 dialog = gtk.FileChooserDialog(title = WINDOW_TITLE_BASE + " - " + 569 xstr("flightsel_save_title"), 570 action = FILE_CHOOSER_ACTION_SAVE, 571 buttons = (gtk.STOCK_CANCEL, 572 RESPONSETYPE_CANCEL, 573 gtk.STOCK_OK, RESPONSETYPE_OK), 574 parent = gui.mainWindow) 575 dialog.set_modal(True) 576 dialog.set_do_overwrite_confirmation(True) 577 578 filter = gtk.FileFilter() 579 filter.set_name(xstr("flightsel_filter_flights")) 580 filter.add_pattern("*.vaflight") 581 dialog.add_filter(filter) 582 583 filter = gtk.FileFilter() 584 filter.set_name(xstr("file_filter_all")) 585 filter.add_pattern("*.*") 586 dialog.add_filter(filter) 587 588 self._saveDialog = dialog 589 590 return dialog 591 517 592 def _getLoadDialog(self): 518 593 """Get the dialog to load a flight file.""" -
src/mlx/i18n.py
r208 r214 274 274 self.add("flightsel_from", "From") 275 275 self.add("flightsel_to", "To") 276 self.add("flightsel_save", "_Save flight") 277 self.add("flightsel_save_tooltip", 278 "Click here to save the currently selected flight into " 279 "a file that can be loaded later.") 280 self.add("flightsel_save_title", "Save a flight into a file") 281 self.add("flightsel_save_failed", 282 "Could not save the flight into a file.") 283 self.add("flightsel_save_failed_sec", 284 "Check the debug log for more details.") 276 285 self.add("flightsel_refresh", "_Refresh flights") 277 286 self.add("flightsel_refresh_tooltip", -
src/mlx/web.py
r208 r214 151 151 elif key=="departure_time": departureTime = value 152 152 elif key=="arrival_time": arrivalTime = value 153 elif key=="foglalas_id": pass 153 elif key=="foglalas_id": 154 self.id = None if value=="0" else value 154 155 elif key=="planetype": pass 155 156 else: lineOK = False … … 178 179 raise Exception("Attribute %s could not be read" % (attribute,)) 179 180 181 def writeIntoFile(self, f): 182 """Write the flight into a file.""" 183 print >> f, "callsign=%s" % (self.callsign,) 184 date = self.departureTime.date() 185 print >> f, "date=%04d-%02d-%0d" % (date.year, date.month, date.day) 186 print >> f, "dep_airport=%s" % (self.departureICAO,) 187 print >> f, "dest_airport=%s" % (self.arrivalICAO,) 188 print >> f, "planecode=%s" % \ 189 (BookedFlight.TYPE2TYPECODE[self.aircraftType],) 190 print >> f, "tail_nr=%s" % (self.tailNumber,) 191 print >> f, "passenger=%d" % (self.numPassengers,) 192 print >> f, "crew=%d" % (self.numCrew,) 193 print >> f, "bag=%d" % (self.bagWeight,) 194 print >> f, "cargo=%d" % (self.cargoWeight,) 195 print >> f, "mail=%d" % (self.mailWeight,) 196 print >> f, "flight_route=%s" % (self.route,) 197 departureTime = self.departureTime 198 print >> f, "departure_time=%02d\\:%02d\\:%02d" % \ 199 (departureTime.hour, departureTime.minute, departureTime.second) 200 arrivalTime = self.arrivalTime 201 print >> f, "arrival_time=%02d\\:%02d\\:%02d" % \ 202 (arrivalTime.hour, arrivalTime.minute, arrivalTime.second) 203 print >> f, "foglalas_id=%s" % ("0" if self.id is None else self.id,) 204 180 205 def _readAircraftType(self, f): 181 206 """Read the aircraft type from the given file."""
Note:
See TracChangeset
for help on using the changeset viewer.