[811] | 1 | # A widget which is a generic list of flights
|
---|
| 2 |
|
---|
| 3 | #-----------------------------------------------------------------------------
|
---|
| 4 |
|
---|
| 5 | from mlx.gui.common import *
|
---|
| 6 |
|
---|
[819] | 7 | import mlx.const as const
|
---|
| 8 |
|
---|
[811] | 9 | #-----------------------------------------------------------------------------
|
---|
| 10 |
|
---|
| 11 | class ColumnDescriptor(object):
|
---|
| 12 | """A descriptor for a column in the list."""
|
---|
| 13 | def __init__(self, attribute, heading, type = str,
|
---|
[854] | 14 | convertFn = None, renderer = None,
|
---|
[822] | 15 | extraColumnAttributes = None, sortable = False,
|
---|
[854] | 16 | defaultSortable = False, defaultDescending = False,
|
---|
| 17 | cellDataFn = None):
|
---|
[811] | 18 | """Construct the descriptor."""
|
---|
| 19 | self._attribute = attribute
|
---|
| 20 | self._heading = heading
|
---|
| 21 | self._type = type
|
---|
| 22 | self._convertFn = convertFn
|
---|
[854] | 23 | self._renderer = \
|
---|
[996] | 24 | Gtk.CellRendererText() if renderer is None else renderer
|
---|
[811] | 25 | self._extraColumnAttributes = extraColumnAttributes
|
---|
[814] | 26 | self._sortable = sortable
|
---|
[822] | 27 | self._defaultSortable = defaultSortable
|
---|
[854] | 28 | self._defaultDescending = defaultDescending
|
---|
| 29 | self._cellDataFn = cellDataFn
|
---|
[822] | 30 |
|
---|
| 31 | @property
|
---|
[859] | 32 | def attribute(self):
|
---|
| 33 | """Get the attribute the column belongs to."""
|
---|
| 34 | return self._attribute
|
---|
| 35 |
|
---|
| 36 | @property
|
---|
[822] | 37 | def defaultSortable(self):
|
---|
| 38 | """Determine if this column is the default sortable one."""
|
---|
| 39 | return self._defaultSortable
|
---|
[811] | 40 |
|
---|
| 41 | def appendType(self, types):
|
---|
| 42 | """Append the type of this column to the given list of types."""
|
---|
| 43 | types.append(self._type)
|
---|
| 44 |
|
---|
| 45 | def getViewColumn(self, index):
|
---|
| 46 | """Get a new column object for a tree view.
|
---|
| 47 |
|
---|
| 48 | @param index is the 0-based index of the column."""
|
---|
[996] | 49 | if isinstance(self._renderer, Gtk.CellRendererText):
|
---|
| 50 | column = Gtk.TreeViewColumn(self._heading, self._renderer,
|
---|
[858] | 51 | text = index)
|
---|
[996] | 52 | elif isinstance(self._renderer, Gtk.CellRendererToggle):
|
---|
| 53 | column = Gtk.TreeViewColumn(self._heading, self._renderer,
|
---|
[858] | 54 | active = index)
|
---|
| 55 | else:
|
---|
[996] | 56 | column = Gtk.TreeViewColumn(self._heading, self._renderer)
|
---|
[811] | 57 | column.set_expand(True)
|
---|
[814] | 58 | if self._sortable:
|
---|
| 59 | column.set_sort_column_id(index)
|
---|
| 60 | column.set_sort_indicator(True)
|
---|
[811] | 61 |
|
---|
[854] | 62 | if self._extraColumnAttributes is not None:
|
---|
[919] | 63 | for (key, value) in self._extraColumnAttributes.items():
|
---|
[854] | 64 | if key=="alignment":
|
---|
| 65 | self._renderer.set_alignment(value, 0.5)
|
---|
| 66 | else:
|
---|
| 67 | raise Exception("unhandled extra column attribute '" +
|
---|
| 68 | key + "'")
|
---|
| 69 | if self._cellDataFn is not None:
|
---|
| 70 | column.set_cell_data_func(self._renderer, self._cellDataFn)
|
---|
| 71 |
|
---|
[811] | 72 | return column
|
---|
| 73 |
|
---|
| 74 | def getValueFrom(self, flight):
|
---|
| 75 | """Get the value from the given flight."""
|
---|
[854] | 76 | attributes = self._attribute.split(".")
|
---|
| 77 | value = getattr(flight, attributes[0])
|
---|
| 78 | for attr in attributes[1:]:
|
---|
| 79 | value = getattr(value, attr)
|
---|
[811] | 80 | return self._type(value) if self._convertFn is None \
|
---|
[819] | 81 | else self._convertFn(value, flight)
|
---|
[811] | 82 |
|
---|
| 83 | #-----------------------------------------------------------------------------
|
---|
| 84 |
|
---|
[996] | 85 | class FlightList(Gtk.Alignment):
|
---|
[811] | 86 | """Construct the flight list.
|
---|
| 87 |
|
---|
| 88 | This is a complete widget with a scroll window. It is alignment centered
|
---|
| 89 | horizontally and expandable vertically."""
|
---|
[818] | 90 |
|
---|
| 91 | defaultColumnDescriptors = [
|
---|
| 92 | ColumnDescriptor("callsign", xstr("flightsel_no")),
|
---|
| 93 | ColumnDescriptor("departureTime", xstr("flightsel_deptime"),
|
---|
[822] | 94 | sortable = True, defaultSortable = True),
|
---|
[818] | 95 | ColumnDescriptor("departureICAO", xstr("flightsel_from"),
|
---|
| 96 | sortable = True),
|
---|
| 97 | ColumnDescriptor("arrivalICAO", xstr("flightsel_to"), sortable = True)
|
---|
| 98 | ]
|
---|
| 99 |
|
---|
| 100 | def __init__(self, columnDescriptors = defaultColumnDescriptors,
|
---|
[823] | 101 | popupMenuProducer = None, widthRequest = None,
|
---|
| 102 | multiSelection = False):
|
---|
[811] | 103 | """Construct the flight list with the given column descriptors."""
|
---|
| 104 |
|
---|
| 105 | self._columnDescriptors = columnDescriptors
|
---|
| 106 | self._popupMenuProducer = popupMenuProducer
|
---|
| 107 | self._popupMenu = None
|
---|
| 108 |
|
---|
[814] | 109 | types = [int]
|
---|
[822] | 110 | defaultSortableIndex = None
|
---|
[811] | 111 | for columnDescriptor in self._columnDescriptors:
|
---|
[822] | 112 | if columnDescriptor.defaultSortable:
|
---|
| 113 | defaultSortableIndex = len(types)
|
---|
[811] | 114 | columnDescriptor.appendType(types)
|
---|
| 115 |
|
---|
[996] | 116 | self._model = Gtk.ListStore(*types)
|
---|
[822] | 117 | if defaultSortableIndex is not None:
|
---|
[999] | 118 | sortOrder = Gtk.SortType.DESCENDING \
|
---|
[854] | 119 | if self._columnDescriptors[defaultSortableIndex-1]._defaultDescending \
|
---|
[999] | 120 | else Gtk.SortType.ASCENDING
|
---|
[854] | 121 | self._model.set_sort_column_id(defaultSortableIndex, sortOrder)
|
---|
[996] | 122 | self._view = Gtk.TreeView(self._model)
|
---|
[811] | 123 |
|
---|
[996] | 124 | flightIndexColumn = Gtk.TreeViewColumn()
|
---|
[814] | 125 | flightIndexColumn.set_visible(False)
|
---|
| 126 | self._view.append_column(flightIndexColumn)
|
---|
| 127 |
|
---|
| 128 | index = 1
|
---|
[811] | 129 | for columnDescriptor in self._columnDescriptors:
|
---|
| 130 | column = columnDescriptor.getViewColumn(index)
|
---|
| 131 | self._view.append_column(column)
|
---|
| 132 | index += 1
|
---|
| 133 |
|
---|
| 134 | self._view.connect("row-activated", self._rowActivated)
|
---|
| 135 | self._view.connect("button-press-event", self._buttonPressEvent)
|
---|
| 136 |
|
---|
| 137 | selection = self._view.get_selection()
|
---|
| 138 | selection.connect("changed", self._selectionChanged)
|
---|
[823] | 139 | if multiSelection:
|
---|
[999] | 140 | selection.set_mode(Gtk.SelectionMode.MULTIPLE)
|
---|
[811] | 141 |
|
---|
[996] | 142 | scrolledWindow = Gtk.ScrolledWindow()
|
---|
[811] | 143 | scrolledWindow.add(self._view)
|
---|
| 144 | if widthRequest is not None:
|
---|
| 145 | scrolledWindow.set_size_request(widthRequest, -1)
|
---|
| 146 | # FIXME: these should be constants in common.py
|
---|
[996] | 147 | scrolledWindow.set_policy(Gtk.PolicyType.AUTOMATIC,
|
---|
| 148 | Gtk.PolicyType.AUTOMATIC)
|
---|
| 149 | scrolledWindow.set_shadow_type(Gtk.ShadowType.IN)
|
---|
[811] | 150 |
|
---|
| 151 | super(FlightList, self).__init__(xalign = 0.5, yalign = 0.0,
|
---|
| 152 | xscale = 0.0, yscale = 1.0)
|
---|
| 153 | self.add(scrolledWindow)
|
---|
| 154 |
|
---|
| 155 | @property
|
---|
[823] | 156 | def selectedIndexes(self):
|
---|
| 157 | """Get the indexes of the selected entries, if any.
|
---|
| 158 |
|
---|
| 159 | The indexes are sorted."""
|
---|
[811] | 160 | selection = self._view.get_selection()
|
---|
[823] | 161 | (model, rows) = selection.get_selected_rows()
|
---|
| 162 |
|
---|
| 163 | indexes = [self._getIndexForPath(path) for path in rows]
|
---|
| 164 | indexes.sort()
|
---|
| 165 | return indexes
|
---|
[811] | 166 |
|
---|
[815] | 167 | @property
|
---|
| 168 | def hasFlights(self):
|
---|
| 169 | """Determine if there are any flights in the list."""
|
---|
[927] | 170 | return self._model.get_iter_first() is not None
|
---|
[815] | 171 |
|
---|
[811] | 172 | def clear(self):
|
---|
| 173 | """Clear the model."""
|
---|
| 174 | self._model.clear()
|
---|
| 175 |
|
---|
| 176 | def addFlight(self, flight):
|
---|
| 177 | """Add the given booked flight."""
|
---|
[814] | 178 | values = [self._model.iter_n_children(None)]
|
---|
[811] | 179 | for columnDescriptor in self._columnDescriptors:
|
---|
| 180 | values.append(columnDescriptor.getValueFrom(flight))
|
---|
| 181 | self._model.append(values)
|
---|
| 182 |
|
---|
[823] | 183 | def removeFlights(self, indexes):
|
---|
| 184 | """Remove the flights with the given indexes."""
|
---|
[816] | 185 | model = self._model
|
---|
| 186 | idx = 0
|
---|
| 187 | iter = model.get_iter_first()
|
---|
| 188 | while iter is not None:
|
---|
| 189 | nextIter = model.iter_next(iter)
|
---|
[823] | 190 | if model.get_value(iter, 0) in indexes:
|
---|
[816] | 191 | model.remove(iter)
|
---|
| 192 | else:
|
---|
| 193 | model.set_value(iter, 0, idx)
|
---|
| 194 | idx += 1
|
---|
| 195 | iter = nextIter
|
---|
| 196 |
|
---|
[823] | 197 | def _getIndexForPath(self, path):
|
---|
| 198 | """Get the index for the given path."""
|
---|
| 199 | iter = self._model.get_iter(path)
|
---|
| 200 | return self._model.get_value(iter, 0)
|
---|
| 201 |
|
---|
[811] | 202 | def _rowActivated(self, flightList, path, column):
|
---|
| 203 | """Called when a row is selected."""
|
---|
[823] | 204 | self.emit("row-activated", self._getIndexForPath(path))
|
---|
[811] | 205 |
|
---|
| 206 | def _buttonPressEvent(self, widget, event):
|
---|
| 207 | """Called when a mouse button is pressed or released."""
|
---|
[999] | 208 | if event.type!=Gdk.EventType.BUTTON_PRESS or event.button!=3 or \
|
---|
[817] | 209 | self._popupMenuProducer is None:
|
---|
[811] | 210 | return
|
---|
| 211 |
|
---|
| 212 | (path, _, _, _) = self._view.get_path_at_pos(int(event.x),
|
---|
| 213 | int(event.y))
|
---|
| 214 | selection = self._view.get_selection()
|
---|
| 215 | selection.unselect_all()
|
---|
| 216 | selection.select_path(path)
|
---|
| 217 |
|
---|
| 218 | if self._popupMenu is None:
|
---|
| 219 | self._popupMenu = self._popupMenuProducer()
|
---|
| 220 | menu = self._popupMenu
|
---|
[994] | 221 | menu.popup(None, None, None, None, event.button, event.time)
|
---|
[811] | 222 |
|
---|
| 223 | def _selectionChanged(self, selection):
|
---|
| 224 | """Called when the selection has changed."""
|
---|
[823] | 225 | self.emit("selection-changed", self.selectedIndexes)
|
---|
[811] | 226 |
|
---|
| 227 | #-------------------------------------------------------------------------------
|
---|
| 228 |
|
---|
[995] | 229 | GObject.signal_new("row-activated", FlightList, GObject.SIGNAL_RUN_FIRST,
|
---|
[811] | 230 | None, (int,))
|
---|
| 231 |
|
---|
[995] | 232 | GObject.signal_new("selection-changed", FlightList, GObject.SIGNAL_RUN_FIRST,
|
---|
[811] | 233 | None, (object,))
|
---|
| 234 |
|
---|
| 235 | #-----------------------------------------------------------------------------
|
---|
[819] | 236 |
|
---|
[996] | 237 | class PendingFlightsFrame(Gtk.Frame):
|
---|
[819] | 238 | """A frame for a list of pending (reported or rejected) flights.
|
---|
| 239 |
|
---|
| 240 | It contains the list and the buttons available."""
|
---|
[854] | 241 | @staticmethod
|
---|
[819] | 242 | def getAircraft(tailNumber, bookedFlight):
|
---|
| 243 | """Get the aircraft from the given booked flight.
|
---|
| 244 |
|
---|
| 245 | This is the tail number followed by the ICAO code of the aircraft's
|
---|
| 246 | type."""
|
---|
| 247 | return tailNumber + \
|
---|
[1184] | 248 | " (" + const.extendedICAOCodes[bookedFlight.aircraftType] + ")"
|
---|
[819] | 249 |
|
---|
[854] | 250 | def _getAcft(tailNumber, bookedFlight):
|
---|
| 251 | return PendingFlightsFrame.getAircraft(tailNumber, bookedFlight)
|
---|
| 252 |
|
---|
[819] | 253 | columnDescriptors = [
|
---|
| 254 | ColumnDescriptor("callsign", xstr("flightsel_no")),
|
---|
| 255 | ColumnDescriptor("departureTime", xstr("flightsel_deptime"),
|
---|
[822] | 256 | sortable = True, defaultSortable = True),
|
---|
[819] | 257 | ColumnDescriptor("departureICAO", xstr("flightsel_from"),
|
---|
| 258 | sortable = True),
|
---|
| 259 | ColumnDescriptor("arrivalICAO", xstr("flightsel_to"),
|
---|
| 260 | sortable = True),
|
---|
| 261 | ColumnDescriptor("tailNumber", xstr("pendflt_acft"),
|
---|
[854] | 262 | convertFn = _getAcft)
|
---|
[819] | 263 | ]
|
---|
| 264 |
|
---|
[830] | 265 | def __init__(self, which, wizard, window, pirepEditable = False):
|
---|
[819] | 266 | """Construct the frame with the given title."""
|
---|
[927] | 267 | super(PendingFlightsFrame, self).__init__()
|
---|
| 268 | self.set_label(xstr("pendflt_title_" + which))
|
---|
[819] | 269 |
|
---|
| 270 | self._which = which
|
---|
| 271 | self._wizard = wizard
|
---|
[824] | 272 | self._window = window
|
---|
[830] | 273 | self._pirepEditable = pirepEditable
|
---|
[819] | 274 |
|
---|
[996] | 275 | alignment = Gtk.Alignment(xscale = 1.0, yscale = 1.0)
|
---|
[819] | 276 | alignment.set_padding(padding_top = 2, padding_bottom = 8,
|
---|
| 277 | padding_left = 4, padding_right = 4)
|
---|
| 278 |
|
---|
[996] | 279 | hbox = Gtk.HBox()
|
---|
[819] | 280 |
|
---|
| 281 | self._flights = []
|
---|
| 282 | self._flightList = FlightList(columnDescriptors =
|
---|
| 283 | PendingFlightsFrame.columnDescriptors,
|
---|
[867] | 284 | widthRequest = 500, multiSelection = True,
|
---|
| 285 | popupMenuProducer =
|
---|
| 286 | self._producePopupMenu)
|
---|
[819] | 287 | self._flightList.connect("selection-changed", self._selectionChanged)
|
---|
| 288 |
|
---|
| 289 | hbox.pack_start(self._flightList, True, True, 4)
|
---|
| 290 |
|
---|
[996] | 291 | buttonBox = Gtk.VBox()
|
---|
[819] | 292 |
|
---|
[996] | 293 | self._editButton = Gtk.Button(xstr("pendflt_" +
|
---|
[830] | 294 | ("edit" if pirepEditable else
|
---|
| 295 | "view") + "_" + which))
|
---|
[819] | 296 | self._editButton.set_sensitive(False)
|
---|
[867] | 297 | self._editButton.set_use_underline(True)
|
---|
[830] | 298 | self._editButton.connect("clicked", self._editClicked)
|
---|
[819] | 299 | buttonBox.pack_start(self._editButton, False, False, 2)
|
---|
| 300 |
|
---|
[996] | 301 | self._reflyButton = Gtk.Button(xstr("pendflt_refly_" + which))
|
---|
[819] | 302 | self._reflyButton.set_sensitive(False)
|
---|
[867] | 303 | self._reflyButton.set_use_underline(True)
|
---|
[821] | 304 | self._reflyButton.connect("clicked", self._reflyClicked)
|
---|
[819] | 305 | buttonBox.pack_start(self._reflyButton, False, False, 2)
|
---|
| 306 |
|
---|
[996] | 307 | self._deleteButton = Gtk.Button(xstr("pendflt_delete_" + which))
|
---|
[819] | 308 | self._deleteButton.set_sensitive(False)
|
---|
[867] | 309 | self._deleteButton.set_use_underline(True)
|
---|
[824] | 310 | self._deleteButton.connect("clicked", self._deleteClicked)
|
---|
[819] | 311 | buttonBox.pack_start(self._deleteButton, False, False, 2)
|
---|
| 312 |
|
---|
| 313 | hbox.pack_start(buttonBox, False, False, 4)
|
---|
| 314 |
|
---|
| 315 | alignment.add(hbox)
|
---|
| 316 | self.add(alignment)
|
---|
| 317 |
|
---|
| 318 | @property
|
---|
| 319 | def hasFlights(self):
|
---|
| 320 | """Determine if there are any flights in the list."""
|
---|
| 321 | return self._flightList.hasFlights
|
---|
| 322 |
|
---|
| 323 | def clear(self):
|
---|
| 324 | """Clear the lists."""
|
---|
| 325 | self._flights = []
|
---|
| 326 | self._flightList.clear()
|
---|
| 327 |
|
---|
| 328 | def addFlight(self, flight):
|
---|
| 329 | """Add a flight to the list."""
|
---|
| 330 | self._flights.append(flight)
|
---|
| 331 | self._flightList.addFlight(flight)
|
---|
| 332 |
|
---|
[823] | 333 | def _selectionChanged(self, flightList, selectedIndexes):
|
---|
[819] | 334 | """Called when the selection in the list has changed."""
|
---|
[823] | 335 | self._editButton.set_sensitive(len(selectedIndexes)==1)
|
---|
| 336 | self._reflyButton.set_sensitive(len(selectedIndexes)>0)
|
---|
| 337 | self._deleteButton.set_sensitive(len(selectedIndexes)>0)
|
---|
[819] | 338 |
|
---|
[830] | 339 | def _editClicked(self, button):
|
---|
| 340 | """Called when the Edit button is clicked."""
|
---|
[867] | 341 | self._editSelected()
|
---|
| 342 |
|
---|
| 343 | def _editSelected(self):
|
---|
| 344 | """Edit or view the selected flight."""
|
---|
[830] | 345 | gui = self._wizard.gui
|
---|
| 346 | gui.beginBusy(xstr("pendflt_pirep_busy"))
|
---|
| 347 | self.set_sensitive(False)
|
---|
| 348 |
|
---|
| 349 | indexes = self._flightList.selectedIndexes
|
---|
| 350 | assert(len(indexes)==1)
|
---|
| 351 |
|
---|
| 352 | flightID = self._flights[indexes[0]].id
|
---|
| 353 | gui.webHandler.getPIREP(self._pirepResultCallback, flightID)
|
---|
| 354 |
|
---|
| 355 | def _pirepResultCallback(self, returned, result):
|
---|
| 356 | """Called when the PIREP query result is available."""
|
---|
[995] | 357 | GObject.idle_add(self._handlePIREPResult, returned, result)
|
---|
[830] | 358 |
|
---|
| 359 | def _handlePIREPResult(self, returned, result):
|
---|
| 360 | """Handle the refly result."""
|
---|
| 361 |
|
---|
| 362 | self.set_sensitive(True)
|
---|
| 363 | gui = self._wizard.gui
|
---|
| 364 | gui.endBusy()
|
---|
| 365 |
|
---|
| 366 | if returned:
|
---|
| 367 | if self._pirepEditable:
|
---|
| 368 | gui.editPIREP(result.pirep)
|
---|
| 369 | else:
|
---|
[857] | 370 | gui.viewMessagedPIREP(result.pirep)
|
---|
[830] | 371 |
|
---|
[821] | 372 | def _reflyClicked(self, button):
|
---|
| 373 | """Called when the Refly button is clicked."""
|
---|
[867] | 374 | self._reflySelected()
|
---|
| 375 |
|
---|
| 376 | def _reflySelected(self):
|
---|
| 377 | """Mark the selected flight(s) to refly."""
|
---|
[827] | 378 | if askYesNo(xstr("pendflt_refly_question"), parent = self._window):
|
---|
[825] | 379 | gui = self._wizard.gui
|
---|
| 380 | gui.beginBusy(xstr("pendflt_refly_busy"))
|
---|
| 381 | self.set_sensitive(False)
|
---|
| 382 |
|
---|
| 383 | flightIDs = [self._flights[i].id
|
---|
| 384 | for i in self._flightList.selectedIndexes]
|
---|
| 385 | gui.webHandler.reflyFlights(self._reflyResultCallback, flightIDs)
|
---|
[821] | 386 |
|
---|
| 387 | def _reflyResultCallback(self, returned, result):
|
---|
| 388 | """Called when the refly result is available."""
|
---|
[995] | 389 | GObject.idle_add(self._handleReflyResult, returned, result)
|
---|
[821] | 390 |
|
---|
| 391 | def _handleReflyResult(self, returned, result):
|
---|
| 392 | """Handle the refly result."""
|
---|
| 393 |
|
---|
| 394 | self.set_sensitive(True)
|
---|
| 395 | gui = self._wizard.gui
|
---|
| 396 | gui.endBusy()
|
---|
| 397 |
|
---|
[919] | 398 | print("PendingFlightsFrame._handleReflyResult", returned, result)
|
---|
[821] | 399 |
|
---|
| 400 | if returned:
|
---|
[823] | 401 | indexes = self._flightList.selectedIndexes
|
---|
[821] | 402 |
|
---|
[823] | 403 | flights = [self._flights[index] for index in indexes]
|
---|
[821] | 404 |
|
---|
[823] | 405 | self._flightList.removeFlights(indexes)
|
---|
| 406 | for index in indexes[::-1]:
|
---|
| 407 | del self._flights[index]
|
---|
[821] | 408 |
|
---|
[823] | 409 | for flight in flights:
|
---|
| 410 | self._wizard.reflyFlight(flight)
|
---|
[828] | 411 | self._window.checkFlights()
|
---|
| 412 | else:
|
---|
| 413 | communicationErrorDialog()
|
---|
[821] | 414 |
|
---|
[824] | 415 | def _deleteClicked(self, button):
|
---|
| 416 | """Called when the Delete button is clicked."""
|
---|
[867] | 417 | self._deleteSelected()
|
---|
| 418 |
|
---|
| 419 | def _deleteSelected(self):
|
---|
| 420 | """Delete the selected flight."""
|
---|
[827] | 421 | if askYesNo(xstr("flight_delete_question"), parent = self._window):
|
---|
[824] | 422 | gui = self._wizard.gui
|
---|
| 423 | gui.beginBusy(xstr("pendflt_refly_busy"))
|
---|
| 424 | self.set_sensitive(False)
|
---|
| 425 |
|
---|
| 426 | flightIDs = [self._flights[i].id
|
---|
| 427 | for i in self._flightList.selectedIndexes]
|
---|
| 428 | gui.webHandler.deleteFlights(self._deleteResultCallback, flightIDs)
|
---|
| 429 |
|
---|
| 430 | def _deleteResultCallback(self, returned, result):
|
---|
| 431 | """Called when the deletion result is available."""
|
---|
[995] | 432 | GObject.idle_add(self._handleDeleteResult, returned, result)
|
---|
[824] | 433 |
|
---|
| 434 | def _handleDeleteResult(self, returned, result):
|
---|
| 435 | """Handle the delete result."""
|
---|
| 436 |
|
---|
| 437 | self.set_sensitive(True)
|
---|
| 438 | gui = self._wizard.gui
|
---|
| 439 | gui.endBusy()
|
---|
| 440 |
|
---|
[919] | 441 | print("PendingFlightsFrame._handleDeleteResult", returned, result)
|
---|
[824] | 442 |
|
---|
| 443 | if returned:
|
---|
| 444 | indexes = self._flightList.selectedIndexes
|
---|
| 445 |
|
---|
| 446 | flights = [self._flights[index] for index in indexes]
|
---|
| 447 |
|
---|
| 448 | self._flightList.removeFlights(indexes)
|
---|
| 449 | for index in indexes[::-1]:
|
---|
| 450 | del self._flights[index]
|
---|
| 451 |
|
---|
| 452 | for flight in flights:
|
---|
| 453 | self._wizard.deleteFlight(flight)
|
---|
[828] | 454 | self._window.checkFlights()
|
---|
| 455 | else:
|
---|
| 456 | communicationErrorDialog()
|
---|
[821] | 457 |
|
---|
[867] | 458 | def _producePopupMenu(self):
|
---|
| 459 | """Create the popup menu for the flights."""
|
---|
[996] | 460 | menu = Gtk.Menu()
|
---|
[867] | 461 |
|
---|
[996] | 462 | menuItem = Gtk.MenuItem()
|
---|
[867] | 463 | menuItem.set_label(xstr("pendflt_" +
|
---|
| 464 | ("edit" if self._pirepEditable else "view") +
|
---|
| 465 | "_" + self._which))
|
---|
| 466 | menuItem.set_use_underline(True)
|
---|
| 467 | menuItem.connect("activate", self._popupEdit)
|
---|
| 468 | menuItem.show()
|
---|
| 469 |
|
---|
| 470 | menu.append(menuItem)
|
---|
| 471 |
|
---|
[996] | 472 | menuItem = Gtk.MenuItem()
|
---|
[867] | 473 | menuItem.set_label(xstr("pendflt_refly_" + self._which))
|
---|
| 474 | menuItem.set_use_underline(True)
|
---|
| 475 | menuItem.connect("activate", self._popupRefly)
|
---|
| 476 | menuItem.show()
|
---|
| 477 |
|
---|
| 478 | menu.append(menuItem)
|
---|
| 479 |
|
---|
[996] | 480 | menuItem = Gtk.MenuItem()
|
---|
[867] | 481 | menuItem.set_label(xstr("pendflt_delete_" + self._which))
|
---|
| 482 | menuItem.set_use_underline(True)
|
---|
| 483 | menuItem.connect("activate", self._popupDelete)
|
---|
| 484 | menuItem.show()
|
---|
| 485 |
|
---|
| 486 | menu.append(menuItem)
|
---|
| 487 |
|
---|
| 488 | return menu
|
---|
| 489 |
|
---|
| 490 | def _popupEdit(self, menuitem):
|
---|
| 491 | """Called when the Edit or View menu item is selected from the popup
|
---|
| 492 | menu."""
|
---|
| 493 | self._editSelected()
|
---|
| 494 |
|
---|
| 495 | def _popupRefly(self, menuitem):
|
---|
| 496 | """Called when the Refly menu item is selected from the popup menu."""
|
---|
| 497 | self._reflySelected()
|
---|
| 498 |
|
---|
| 499 | def _popupDelete(self, menuitem):
|
---|
| 500 | """Called when the Delete menu item is selected from the popup menu."""
|
---|
| 501 | self._deleteSelected()
|
---|
| 502 |
|
---|
[819] | 503 | #-----------------------------------------------------------------------------
|
---|
| 504 |
|
---|
[996] | 505 | class PendingFlightsWindow(Gtk.Window):
|
---|
[819] | 506 | """The window to display the lists of the pending (reported or rejected)
|
---|
| 507 | flights."""
|
---|
| 508 | def __init__(self, wizard):
|
---|
| 509 | """Construct the window"""
|
---|
| 510 | super(PendingFlightsWindow, self).__init__()
|
---|
| 511 |
|
---|
| 512 | gui = wizard.gui
|
---|
| 513 |
|
---|
| 514 | self.set_title(WINDOW_TITLE_BASE + " - " + xstr("pendflt_title"))
|
---|
| 515 | self.set_size_request(-1, 450)
|
---|
| 516 | self.set_transient_for(gui.mainWindow)
|
---|
| 517 | self.set_modal(True)
|
---|
| 518 |
|
---|
[996] | 519 | mainAlignment = Gtk.Alignment(xalign = 0.5, yalign = 0.5,
|
---|
[819] | 520 | xscale = 1.0, yscale = 1.0)
|
---|
| 521 | mainAlignment.set_padding(padding_top = 0, padding_bottom = 12,
|
---|
| 522 | padding_left = 8, padding_right = 8)
|
---|
| 523 |
|
---|
[996] | 524 | vbox = Gtk.VBox()
|
---|
[819] | 525 |
|
---|
[830] | 526 | self._reportedFrame = PendingFlightsFrame("reported", wizard, self,
|
---|
| 527 | True)
|
---|
[819] | 528 | vbox.pack_start(self._reportedFrame, True, True, 2)
|
---|
| 529 |
|
---|
[824] | 530 | self._rejectedFrame = PendingFlightsFrame("rejected", wizard, self)
|
---|
[819] | 531 | vbox.pack_start(self._rejectedFrame, True, True, 2)
|
---|
| 532 |
|
---|
[996] | 533 | alignment = Gtk.Alignment(xalign = 0.5, yalign = 0.5,
|
---|
[819] | 534 | xscale = 0.0, yscale = 0.0)
|
---|
[996] | 535 | self._closeButton = Gtk.Button(xstr("button_ok"))
|
---|
[819] | 536 | self._closeButton.connect("clicked", self._closeClicked)
|
---|
[982] | 537 | self._closeButton.set_use_underline(True)
|
---|
[819] | 538 | alignment.add(self._closeButton)
|
---|
| 539 | vbox.pack_start(alignment, False, False, 2)
|
---|
| 540 |
|
---|
| 541 | mainAlignment.add(vbox)
|
---|
| 542 |
|
---|
| 543 | self.add(mainAlignment)
|
---|
| 544 |
|
---|
| 545 | self.connect("key-press-event", self._keyPressed)
|
---|
| 546 |
|
---|
| 547 | @property
|
---|
| 548 | def hasFlights(self):
|
---|
| 549 | """Determine if the window has any flights."""
|
---|
| 550 | return self._reportedFrame.hasFlights or self._rejectedFrame.hasFlights
|
---|
| 551 |
|
---|
| 552 | def clear(self):
|
---|
| 553 | """Clear the lists."""
|
---|
| 554 | self._reportedFrame.clear()
|
---|
| 555 | self._rejectedFrame.clear()
|
---|
| 556 |
|
---|
| 557 | def addReportedFlight(self, flight):
|
---|
| 558 | """Add a reported flight."""
|
---|
| 559 | self._reportedFrame.addFlight(flight)
|
---|
| 560 |
|
---|
| 561 | def addRejectedFlight(self, flight):
|
---|
| 562 | """Add a rejected flight."""
|
---|
| 563 | self._rejectedFrame.addFlight(flight)
|
---|
| 564 |
|
---|
[828] | 565 | def checkFlights(self):
|
---|
| 566 | """Check if there are any flights in any of the lists, and close the
|
---|
| 567 | window if not."""
|
---|
| 568 | if not self.hasFlights:
|
---|
| 569 | self.emit("delete-event", None)
|
---|
| 570 |
|
---|
[819] | 571 | def _closeClicked(self, button):
|
---|
| 572 | """Called when the Close button is clicked.
|
---|
| 573 |
|
---|
| 574 | A 'delete-event' is emitted to close the window."""
|
---|
| 575 | self.emit("delete-event", None)
|
---|
| 576 |
|
---|
| 577 | def _keyPressed(self, window, event):
|
---|
| 578 | """Called when a key is pressed in the window.
|
---|
| 579 |
|
---|
| 580 | If the Escape key is pressed, 'delete-event' is emitted to close the
|
---|
| 581 | window."""
|
---|
[997] | 582 | if Gdk.keyval_name(event.keyval) == "Escape":
|
---|
[819] | 583 | self.emit("delete-event", None)
|
---|
| 584 | return True
|
---|
| 585 |
|
---|
| 586 | #-----------------------------------------------------------------------------
|
---|
[854] | 587 |
|
---|
[996] | 588 | class AcceptedFlightsWindow(Gtk.Window):
|
---|
[854] | 589 | """A window for a list of accepted flights."""
|
---|
| 590 | def getFlightDuration(flightTimeStart, flight):
|
---|
| 591 | """Get the flight duration for the given flight."""
|
---|
| 592 | minutes = int(round((flight.flightTimeEnd - flightTimeStart)/60.0))
|
---|
| 593 | return "%02d:%02d" % (minutes/60, minutes%60)
|
---|
| 594 |
|
---|
| 595 | columnDescriptors = [
|
---|
| 596 | ColumnDescriptor("bookedFlight.callsign", xstr("flightsel_no")),
|
---|
| 597 | ColumnDescriptor("bookedFlight.departureTime", xstr("flightsel_deptime"),
|
---|
| 598 | sortable = True, defaultSortable = True,
|
---|
| 599 | defaultDescending = True),
|
---|
| 600 | ColumnDescriptor("bookedFlight.departureICAO", xstr("flightsel_from"),
|
---|
| 601 | sortable = True),
|
---|
| 602 | ColumnDescriptor("bookedFlight.arrivalICAO", xstr("flightsel_to"),
|
---|
| 603 | sortable = True),
|
---|
| 604 | ColumnDescriptor("bookedFlight.tailNumber", xstr("pendflt_acft"),
|
---|
| 605 | convertFn = lambda value, flight:
|
---|
| 606 | PendingFlightsFrame.getAircraft(value,
|
---|
| 607 | flight.bookedFlight)),
|
---|
| 608 | ColumnDescriptor("flightTimeStart", xstr("acceptedflt_flight_duration"),
|
---|
| 609 | convertFn = getFlightDuration, sortable = True,
|
---|
| 610 | extraColumnAttributes =
|
---|
| 611 | { "alignment": 0.5 } ),
|
---|
[1033] | 612 | ColumnDescriptor("totalNumPassengers", xstr("acceptedflt_num_pax"),
|
---|
[854] | 613 | type = int, sortable = True,
|
---|
| 614 | extraColumnAttributes =
|
---|
| 615 | { "alignment": 1.0 } ),
|
---|
| 616 | ColumnDescriptor("fuelUsed", xstr("acceptedflt_fuel"),
|
---|
| 617 | type = int, sortable = True,
|
---|
| 618 | extraColumnAttributes =
|
---|
| 619 | { "alignment": 1.0 } ),
|
---|
| 620 | ColumnDescriptor("rating", xstr("acceptedflt_rating"),
|
---|
| 621 | type = float, sortable = True,
|
---|
| 622 | extraColumnAttributes =
|
---|
| 623 | { "alignment": 1.0 },
|
---|
[983] | 624 | cellDataFn = lambda col, cell, model, iter, data:
|
---|
[854] | 625 | cell.set_property("text",
|
---|
| 626 | "%.0f" %
|
---|
| 627 | (model.get(iter, 9)[0],)))
|
---|
| 628 | ]
|
---|
| 629 |
|
---|
| 630 | def __init__(self, gui):
|
---|
| 631 | """Construct the window."""
|
---|
| 632 | super(AcceptedFlightsWindow, self).__init__()
|
---|
| 633 |
|
---|
| 634 | self._gui = gui
|
---|
| 635 |
|
---|
| 636 | self.set_title(WINDOW_TITLE_BASE + " - " + xstr("acceptedflt_title"))
|
---|
| 637 | self.set_size_request(-1, 700)
|
---|
| 638 | self.set_transient_for(gui.mainWindow)
|
---|
| 639 |
|
---|
[996] | 640 | alignment = Gtk.Alignment(xscale = 1.0, yscale = 1.0)
|
---|
[854] | 641 | alignment.set_padding(padding_top = 2, padding_bottom = 8,
|
---|
| 642 | padding_left = 4, padding_right = 4)
|
---|
| 643 |
|
---|
[996] | 644 | vbox = Gtk.VBox()
|
---|
[854] | 645 |
|
---|
[996] | 646 | hbox = Gtk.HBox()
|
---|
[854] | 647 | vbox.pack_start(hbox, True, True, 4)
|
---|
| 648 |
|
---|
| 649 | self._flights = []
|
---|
| 650 | self._flightList = FlightList(columnDescriptors =
|
---|
| 651 | AcceptedFlightsWindow.columnDescriptors,
|
---|
| 652 | widthRequest = 750,
|
---|
| 653 | multiSelection = False)
|
---|
| 654 | self._flightList.connect("selection-changed", self._selectionChanged)
|
---|
[868] | 655 | self._flightList.connect("row-activated", self._rowActivated)
|
---|
[854] | 656 |
|
---|
| 657 | hbox.pack_start(self._flightList, True, True, 4)
|
---|
| 658 |
|
---|
[996] | 659 | buttonBox = Gtk.VBox()
|
---|
[854] | 660 |
|
---|
[996] | 661 | self._refreshButton = Gtk.Button(xstr("acceptedflt_refresh"))
|
---|
[854] | 662 | self._refreshButton.set_sensitive(True)
|
---|
[982] | 663 | self._refreshButton.set_use_underline(True)
|
---|
[854] | 664 | self._refreshButton.connect("clicked", self._refreshClicked)
|
---|
| 665 | buttonBox.pack_start(self._refreshButton, False, False, 2)
|
---|
| 666 |
|
---|
[996] | 667 | filler = Gtk.Alignment(xalign = 0.0, yalign = 0.0,
|
---|
[854] | 668 | xscale = 1.0, yscale = 1.0)
|
---|
| 669 | filler.set_size_request(-1, 4)
|
---|
| 670 | buttonBox.pack_start(filler, False, False, 0)
|
---|
| 671 |
|
---|
[996] | 672 | self._viewButton = Gtk.Button(xstr("acceptedflt_view"))
|
---|
[854] | 673 | self._viewButton.set_sensitive(False)
|
---|
[982] | 674 | self._viewButton.set_use_underline(True)
|
---|
[854] | 675 | self._viewButton.connect("clicked", self._viewClicked)
|
---|
| 676 | buttonBox.pack_start(self._viewButton, False, False, 2)
|
---|
| 677 |
|
---|
| 678 | hbox.pack_start(buttonBox, False, False, 4)
|
---|
| 679 |
|
---|
[996] | 680 | buttonAlignment = Gtk.Alignment(xscale = 0.0, yscale = 0.0,
|
---|
[854] | 681 | xalign = 0.5, yalign = 0.5)
|
---|
| 682 |
|
---|
[996] | 683 | self._closeButton = Gtk.Button(xstr("button_ok"))
|
---|
[854] | 684 | self._closeButton.connect("clicked", self._closeClicked)
|
---|
[982] | 685 | self._closeButton.set_use_underline(True)
|
---|
[854] | 686 |
|
---|
| 687 | buttonAlignment.add(self._closeButton)
|
---|
| 688 | vbox.pack_start(buttonAlignment, False, False, 2)
|
---|
| 689 |
|
---|
| 690 | alignment.add(vbox)
|
---|
| 691 |
|
---|
| 692 | self.add(alignment)
|
---|
| 693 |
|
---|
| 694 | self.connect("key-press-event", self._keyPressed)
|
---|
| 695 |
|
---|
| 696 | @property
|
---|
| 697 | def hasFlights(self):
|
---|
| 698 | """Determine if there are any flights that we know of."""
|
---|
| 699 | return len(self._flights)>0
|
---|
| 700 |
|
---|
| 701 | def clear(self):
|
---|
| 702 | """Clear the flight list."""
|
---|
| 703 | self._flights = []
|
---|
| 704 | self._flightList.clear()
|
---|
| 705 |
|
---|
| 706 | def addFlight(self, flight):
|
---|
| 707 | """Add the given flight."""
|
---|
| 708 | self._flights.append(flight)
|
---|
| 709 | self._flightList.addFlight(flight)
|
---|
| 710 |
|
---|
| 711 | def _selectionChanged(self, flightList, selectedIndexes):
|
---|
| 712 | """Called when the selection has changed."""
|
---|
| 713 | self._viewButton.set_sensitive(len(selectedIndexes)==1)
|
---|
| 714 |
|
---|
[868] | 715 | def _rowActivated(self, timetable, index):
|
---|
| 716 | """Called when a row has been activated (e.g. double-clicked) in the
|
---|
| 717 | flight list."""
|
---|
| 718 | self._viewSelected()
|
---|
| 719 |
|
---|
[854] | 720 | def _refreshClicked(self, button):
|
---|
| 721 | """Called when the refresh button has been clicked."""
|
---|
| 722 | self.clear()
|
---|
| 723 | self._gui.showFlights(None)
|
---|
| 724 |
|
---|
| 725 | def _viewClicked(self, button):
|
---|
| 726 | """Called when the view button has been clicked."""
|
---|
[868] | 727 | self._viewSelected()
|
---|
| 728 |
|
---|
| 729 | def _viewSelected(self):
|
---|
| 730 | """View the selected flight."""
|
---|
[854] | 731 | gui = self._gui
|
---|
| 732 | gui.beginBusy(xstr("pendflt_pirep_busy"))
|
---|
| 733 | self.set_sensitive(False)
|
---|
| 734 |
|
---|
| 735 | indexes = self._flightList.selectedIndexes
|
---|
| 736 | assert(len(indexes)==1)
|
---|
| 737 |
|
---|
| 738 | flightID = self._flights[indexes[0]].bookedFlight.id
|
---|
| 739 | gui.webHandler.getPIREP(self._pirepResultCallback, flightID)
|
---|
| 740 |
|
---|
| 741 | def _pirepResultCallback(self, returned, result):
|
---|
| 742 | """Called when the PIREP query result is available."""
|
---|
[995] | 743 | GObject.idle_add(self._handlePIREPResult, returned, result)
|
---|
[854] | 744 |
|
---|
| 745 | def _handlePIREPResult(self, returned, result):
|
---|
| 746 | """Handle the refly result."""
|
---|
| 747 | self.set_sensitive(True)
|
---|
| 748 | gui = self._gui
|
---|
| 749 | gui.endBusy()
|
---|
| 750 |
|
---|
| 751 | if returned:
|
---|
[855] | 752 | gui.viewMessagedPIREP(result.pirep)
|
---|
[854] | 753 |
|
---|
| 754 | def _closeClicked(self, button):
|
---|
| 755 | """Called when the Close button is clicked.
|
---|
| 756 |
|
---|
| 757 | A 'delete-event' is emitted to close the window."""
|
---|
| 758 | self.emit("delete-event", None)
|
---|
| 759 |
|
---|
| 760 | def _keyPressed(self, window, event):
|
---|
| 761 | """Called when a key is pressed in the window.
|
---|
| 762 |
|
---|
| 763 | If the Escape key is pressed, 'delete-event' is emitted to close the
|
---|
| 764 | window."""
|
---|
[997] | 765 | if Gdk.keyval_name(event.keyval) == "Escape":
|
---|
[854] | 766 | self.emit("delete-event", None)
|
---|
| 767 | return True
|
---|
| 768 |
|
---|
| 769 | #-----------------------------------------------------------------------------
|
---|