Changeset 823:7a9ce7d89ece


Ignore:
Timestamp:
09/25/16 07:08:29 (8 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

Multiple flights can be selected in a flight list (re #307).

Location:
src/mlx/gui
Files:
3 edited

Legend:

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

    r790 r823  
    101101
    102102    UPDATE_IF_VALID = gtk.UPDATE_IF_VALID
     103
     104    SELECTION_MULTIPLE = gtk.SELECTION_MULTIPLE
    103105
    104106    pixbuf_new_from_file = gdk.pixbuf_new_from_file
     
    177179
    178180    UPDATE_IF_VALID = gtk.SpinButtonUpdatePolicy.IF_VALID
     181
     182    SELECTION_MULTIPLE = gtk.SelectionMode.MULTIPLE
    179183
    180184    pixbuf_new_from_file = gdkPixbuf.Pixbuf.new_from_file
  • src/mlx/gui/flight.py

    r821 r823  
    608608                self._buildFlights()
    609609
    610     def _selectionChanged(self, flightList, index):
     610    def _selectionChanged(self, flightList, indexes):
    611611        """Called when the selection is changed."""
    612         selected = index is not None
    613         self._saveButton.set_sensitive(selected)
     612        self._saveButton.set_sensitive(len(indexes)==1)
    614613        self._updateNextButton()
    615614
     
    620619    def _updateNextButton(self):
    621620        """Update the sensitivity of the Next button."""
    622         sensitive = self._flightList.selectedIndex is not None and \
     621        sensitive = len(self._flightList.selectedIndexes)==1 and \
    623622          not self._pendingFlightsWindowShown
    624623        self._button.set_sensitive(sensitive)
     
    674673    def _getSelectedFlight(self):
    675674        """Get the currently selected flight."""
    676         index = self._flightList.selectedIndex
    677         return self._flights[index]
     675        indexes = self._flightList.selectedIndexes
     676        assert(len(indexes)==1)
     677        return self._flights[indexes[0]]
    678678
    679679    def _updateDepartureGate(self):
  • src/mlx/gui/flightlist.py

    r822 r823  
    7979
    8080    def __init__(self, columnDescriptors = defaultColumnDescriptors,
    81                  popupMenuProducer = None, widthRequest = None):
     81                 popupMenuProducer = None, widthRequest = None,
     82                 multiSelection = False):
    8283        """Construct the flight list with the given column descriptors."""
    8384
     
    114115        selection = self._view.get_selection()
    115116        selection.connect("changed", self._selectionChanged)
     117        if multiSelection:
     118            selection.set_mode(SELECTION_MULTIPLE)
    116119
    117120        scrolledWindow = gtk.ScrolledWindow()
     
    132135
    133136    @property
    134     def selectedIndex(self):
    135         """Get the index of the selected entry, if any."""
     137    def selectedIndexes(self):
     138        """Get the indexes of the selected entries, if any.
     139
     140        The indexes are sorted."""
    136141        selection = self._view.get_selection()
    137         (model, iter) = selection.get_selected()
    138         if iter is None:
    139             return None
    140         else:
    141             index = model.get_value(iter, 0)
    142             return index
     142        (model, rows) = selection.get_selected_rows()
     143
     144        indexes = [self._getIndexForPath(path) for path in rows]
     145        indexes.sort()
     146        return indexes
    143147
    144148    @property
     
    158162        self._model.append(values)
    159163
    160     def removeFlight(self, index):
    161         """Remove the flight with the given index."""
     164    def removeFlights(self, indexes):
     165        """Remove the flights with the given indexes."""
    162166        model = self._model
    163167        idx = 0
     
    165169        while iter is not None:
    166170            nextIter = model.iter_next(iter)
    167             if model.get_value(iter, 0)==index:
     171            if model.get_value(iter, 0) in indexes:
    168172                model.remove(iter)
    169173            else:
     
    172176            iter = nextIter
    173177
     178    def _getIndexForPath(self, path):
     179        """Get the index for the given path."""
     180        iter = self._model.get_iter(path)
     181        return self._model.get_value(iter, 0)
     182
    174183    def _rowActivated(self, flightList, path, column):
    175184        """Called when a row is selected."""
    176         self.emit("row-activated", self.selectedIndex)
     185        self.emit("row-activated", self._getIndexForPath(path))
    177186
    178187    def _buttonPressEvent(self, widget, event):
     
    198207    def _selectionChanged(self, selection):
    199208        """Called when the selection has changed."""
    200         self.emit("selection-changed", self.selectedIndex)
     209        self.emit("selection-changed", self.selectedIndexes)
    201210
    202211#-------------------------------------------------------------------------------
     
    250259        self._flightList = FlightList(columnDescriptors =
    251260                                      PendingFlightsFrame.columnDescriptors,
    252                                       widthRequest = 500)
     261                                      widthRequest = 500, multiSelection = True)
    253262        self._flightList.connect("selection-changed", self._selectionChanged)
    254263
     
    290299        self._flightList.addFlight(flight)
    291300
    292     def _selectionChanged(self, flightList, selectedIndex):
     301    def _selectionChanged(self, flightList, selectedIndexes):
    293302        """Called when the selection in the list has changed."""
    294         sensitive = selectedIndex is not None
    295         self._editButton.set_sensitive(sensitive)
    296         self._reflyButton.set_sensitive(sensitive)
    297         self._deleteButton.set_sensitive(sensitive)
     303        self._editButton.set_sensitive(len(selectedIndexes)==1)
     304        self._reflyButton.set_sensitive(len(selectedIndexes)>0)
     305        self._deleteButton.set_sensitive(len(selectedIndexes)>0)
    298306
    299307    def _reflyClicked(self, button):
     
    303311        self.set_sensitive(False)
    304312
    305         flight = self._flights[self._flightList.selectedIndex]
    306         gui.webHandler.reflyFlights(self._reflyResultCallback, [flight.id])
     313        flightIDs = [self._flights[i].id
     314                     for i in self._flightList.selectedIndexes]
     315        gui.webHandler.reflyFlights(self._reflyResultCallback, flightIDs)
    307316
    308317    def _reflyResultCallback(self, returned, result):
     
    320329
    321330        if returned:
    322             index = self._flightList.selectedIndex
    323 
    324             flight = self._flights[index]
    325 
    326             self._flightList.removeFlight(index)
    327             del self._flights[index]
    328 
    329             self._wizard.reflyFlight(flight)
     331            indexes = self._flightList.selectedIndexes
     332
     333            flights = [self._flights[index] for index in indexes]
     334
     335            self._flightList.removeFlights(indexes)
     336            for index in indexes[::-1]:
     337                del self._flights[index]
     338
     339            for flight in flights:
     340                self._wizard.reflyFlight(flight)
    330341
    331342
Note: See TracChangeset for help on using the changeset viewer.