Changeset 823:7a9ce7d89ece for src/mlx
- Timestamp:
- 09/25/16 07:08:29 (8 years ago)
- Branch:
- default
- Phase:
- public
- Location:
- src/mlx/gui
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mlx/gui/common.py
r790 r823 101 101 102 102 UPDATE_IF_VALID = gtk.UPDATE_IF_VALID 103 104 SELECTION_MULTIPLE = gtk.SELECTION_MULTIPLE 103 105 104 106 pixbuf_new_from_file = gdk.pixbuf_new_from_file … … 177 179 178 180 UPDATE_IF_VALID = gtk.SpinButtonUpdatePolicy.IF_VALID 181 182 SELECTION_MULTIPLE = gtk.SelectionMode.MULTIPLE 179 183 180 184 pixbuf_new_from_file = gdkPixbuf.Pixbuf.new_from_file -
src/mlx/gui/flight.py
r821 r823 608 608 self._buildFlights() 609 609 610 def _selectionChanged(self, flightList, index ):610 def _selectionChanged(self, flightList, indexes): 611 611 """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) 614 613 self._updateNextButton() 615 614 … … 620 619 def _updateNextButton(self): 621 620 """Update the sensitivity of the Next button.""" 622 sensitive = self._flightList.selectedIndex is not Noneand \621 sensitive = len(self._flightList.selectedIndexes)==1 and \ 623 622 not self._pendingFlightsWindowShown 624 623 self._button.set_sensitive(sensitive) … … 674 673 def _getSelectedFlight(self): 675 674 """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]] 678 678 679 679 def _updateDepartureGate(self): -
src/mlx/gui/flightlist.py
r822 r823 79 79 80 80 def __init__(self, columnDescriptors = defaultColumnDescriptors, 81 popupMenuProducer = None, widthRequest = None): 81 popupMenuProducer = None, widthRequest = None, 82 multiSelection = False): 82 83 """Construct the flight list with the given column descriptors.""" 83 84 … … 114 115 selection = self._view.get_selection() 115 116 selection.connect("changed", self._selectionChanged) 117 if multiSelection: 118 selection.set_mode(SELECTION_MULTIPLE) 116 119 117 120 scrolledWindow = gtk.ScrolledWindow() … … 132 135 133 136 @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.""" 136 141 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 143 147 144 148 @property … … 158 162 self._model.append(values) 159 163 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.""" 162 166 model = self._model 163 167 idx = 0 … … 165 169 while iter is not None: 166 170 nextIter = model.iter_next(iter) 167 if model.get_value(iter, 0) ==index:171 if model.get_value(iter, 0) in indexes: 168 172 model.remove(iter) 169 173 else: … … 172 176 iter = nextIter 173 177 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 174 183 def _rowActivated(self, flightList, path, column): 175 184 """Called when a row is selected.""" 176 self.emit("row-activated", self. selectedIndex)185 self.emit("row-activated", self._getIndexForPath(path)) 177 186 178 187 def _buttonPressEvent(self, widget, event): … … 198 207 def _selectionChanged(self, selection): 199 208 """Called when the selection has changed.""" 200 self.emit("selection-changed", self.selectedIndex )209 self.emit("selection-changed", self.selectedIndexes) 201 210 202 211 #------------------------------------------------------------------------------- … … 250 259 self._flightList = FlightList(columnDescriptors = 251 260 PendingFlightsFrame.columnDescriptors, 252 widthRequest = 500 )261 widthRequest = 500, multiSelection = True) 253 262 self._flightList.connect("selection-changed", self._selectionChanged) 254 263 … … 290 299 self._flightList.addFlight(flight) 291 300 292 def _selectionChanged(self, flightList, selectedIndex ):301 def _selectionChanged(self, flightList, selectedIndexes): 293 302 """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) 298 306 299 307 def _reflyClicked(self, button): … … 303 311 self.set_sensitive(False) 304 312 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) 307 316 308 317 def _reflyResultCallback(self, returned, result): … … 320 329 321 330 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) 330 341 331 342
Note:
See TracChangeset
for help on using the changeset viewer.