Changeset 864:b154a5d879cb for src


Ignore:
Timestamp:
06/18/17 17:59:30 (7 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

A flight can be deleted from the flight list (re #308)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/gui/flight.py

    r863 r864  
    492492        flightButtonWidthBox.pack_start(self._printButton, True, True, 4)
    493493
     494        self._deleteButton = gtk.Button(xstr("flightsel_delete"))
     495        self._deleteButton.set_use_underline(True)
     496        self._deleteButton.set_sensitive(False)
     497        self._deleteButton.set_tooltip_text(xstr("flightsel_delete_tooltip"))
     498        self._deleteButton.connect("clicked", self._deleteClicked)
     499
     500        flightButtonWidthBox.pack_start(self._deleteButton, True, True, 4)
    494501
    495502        flightButtonWidthAlignment.add(flightButtonWidthBox)
     
    648655    def _printClicked(self, button):
    649656        """Called when the Print briefing button is clicked."""
     657        self._printSelected()
     658
     659    def _printSelected(self):
     660        """Print the briefing for the selected flight."""
    650661        wizard = self._wizard
    651662        flight = self._getSelectedFlight()
     
    843854        cr.stroke()
    844855
     856    def _deleteClicked(self, button):
     857        """Called when the Delete flight button is clicked."""
     858        self._deleteSelected()
     859
     860    def _deleteSelected(self):
     861        """Delete the selected flight."""
     862        if askYesNo(xstr("flightsel_delete_confirm"),
     863                    parent = self._wizard.gui.mainWindow):
     864            flight = self._getSelectedFlight()
     865            gui = self._wizard.gui
     866            gui.beginBusy(xstr("flightsel_delete_busy"))
     867
     868            gui.webHandler.deleteFlights(self._deleteResultCallback,
     869                                         [flight.id])
     870
     871    def _deleteResultCallback(self, returned, result):
     872        """Called when the deletion result is available."""
     873        gobject.idle_add(self._handleDeleteResult, returned, result)
     874
     875    def _handleDeleteResult(self, returned, result):
     876        """Handle the delete result."""
     877        gui = self._wizard.gui
     878        gui.endBusy()
     879
     880        if returned:
     881            indexes = self._flightList.selectedIndexes
     882
     883            flights = [self._flights[index] for index in indexes]
     884
     885            self._flightList.removeFlights(indexes)
     886            for index in indexes[::-1]:
     887                del self._flights[index]
     888        else:
     889            communicationErrorDialog()
     890
     891
    845892    def _refreshClicked(self, button):
    846893        """Called when the refresh button is clicked."""
     
    858905        self._saveButton.set_sensitive(len(indexes)==1)
    859906        self._printButton.set_sensitive(len(indexes)==1)
     907        self._deleteButton.set_sensitive(len(indexes)==1)
    860908        self._updateNextButton()
    861909
     
    10421090        menu.append(menuItem)
    10431091
     1092        menuItem = gtk.MenuItem()
     1093        menuItem.set_label(xstr("flightsel_popup_delete"))
     1094        menuItem.set_use_underline(True)
     1095        menuItem.connect("activate", self._popupDelete)
     1096        menuItem.show()
     1097
     1098        menu.append(menuItem)
     1099
    10441100        return menu
    10451101
     
    10531109        if not self._completed:
    10541110            self._saveSelected()
     1111
     1112    def _popupDelete(self, menuItem):
     1113        """Called when the Delete menu item is activated in the popup menu."""
     1114        if not self._completed:
     1115            self._deleteSelected()
    10551116
    10561117#-----------------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.