Changeset 214:19fb20505b1a for src/mlx/gui
- Timestamp:
- 05/31/12 18:02:17 (12 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 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."""
Note:
See TracChangeset
for help on using the changeset viewer.