Changeset 819:024e8697000e for src
- Timestamp:
- 09/25/16 06:40:16 (8 years ago)
- Branch:
- default
- Phase:
- public
- Location:
- src/mlx/gui
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mlx/gui/flight.py
r818 r819 2 2 from mlx.gui.common import * 3 3 import mlx.gui.cef as cef 4 from mlx.gui.flightlist import ColumnDescriptor, FlightList 4 from mlx.gui.flightlist import ColumnDescriptor, FlightList, PendingFlightsWindow 5 5 6 6 import mlx.const as const … … 453 453 self.setMainWidget(self._flightList) 454 454 455 self._pendingButton = self.addButton(xstr("flightsel_pending"), 456 sensitive = False, 457 clicked = self._pendingClicked, 458 tooltip = xstr("flightsel_pending_tooltip")) 459 455 460 self._saveButton = self.addButton(xstr("flightsel_save"), 456 461 sensitive = False, … … 474 479 475 480 self._flights = [] 481 482 self._pendingFlightsWindow = PendingFlightsWindow(self._wizard) 483 self._pendingFlightsWindowShown = False 484 self._pendingFlightsWindow.connect("delete-event", 485 self._deletePendingFlightsWindow) 476 486 477 487 def activate(self): … … 514 524 self._flights = [] 515 525 self._flightList.clear() 526 self._pendingFlightsWindow.clear() 527 loginResult = self._wizard.loginResult 516 528 if self._wizard.loggedIn: 517 for flight in self._wizard.loginResult.flights:529 for flight in loginResult.flights: 518 530 self._addFlight(flight) 531 for flight in loginResult.reportedFlights: 532 self._pendingFlightsWindow.addReportedFlight(flight) 533 for flight in loginResult.rejectedFlights: 534 self._pendingFlightsWindow.addRejectedFlight(flight) 535 536 self._updatePendingButton() 519 537 520 538 def _addFlight(self, flight): … … 522 540 self._flights.append(flight) 523 541 self._flightList.addFlight(flight) 542 543 def _pendingClicked(self, button): 544 """Called when the Pending flights button is clicked.""" 545 self._pendingFlightsWindow.show_all() 546 self._pendingFlightsWindowShown = True 547 self._updateNextButton() 548 549 def _deletePendingFlightsWindow(self, window, event): 550 """Called when the pending flights window is closed.""" 551 self._pendingFlightsWindow.hide() 552 self._pendingFlightsWindowShown = False 553 self._updateNextButton() 554 return True 524 555 525 556 def _saveClicked(self, button): … … 575 606 selected = index is not None 576 607 self._saveButton.set_sensitive(selected) 577 self._button.set_sensitive(selected) 608 self._updateNextButton() 609 610 def _updatePendingButton(self): 611 """Update the senstivity of the Pending button.""" 612 self._pendingButton.set_sensitive(self._pendingFlightsWindow.hasFlights) 613 614 def _updateNextButton(self): 615 """Update the sensitivity of the Next button.""" 616 sensitive = self._flightList.selectedIndex is not None and \ 617 not self._pendingFlightsWindowShown 618 self._button.set_sensitive(sensitive) 578 619 579 620 def _loadButtonClicked(self, loadButton): -
src/mlx/gui/flightlist.py
r818 r819 4 4 5 5 from mlx.gui.common import * 6 7 import mlx.const as const 6 8 7 9 #----------------------------------------------------------------------------- … … 50 52 value = getattr(flight, self._attribute) 51 53 return self._type(value) if self._convertFn is None \ 52 else self._convertFn(value )54 else self._convertFn(value, flight) 53 55 54 56 #----------------------------------------------------------------------------- … … 195 197 196 198 #----------------------------------------------------------------------------- 199 200 class PendingFlightsFrame(gtk.Frame): 201 """A frame for a list of pending (reported or rejected) flights. 202 203 It contains the list and the buttons available.""" 204 def getAircraft(tailNumber, bookedFlight): 205 """Get the aircraft from the given booked flight. 206 207 This is the tail number followed by the ICAO code of the aircraft's 208 type.""" 209 return tailNumber + \ 210 " (" + const.icaoCodes[bookedFlight.aircraftType] + ")" 211 212 columnDescriptors = [ 213 ColumnDescriptor("callsign", xstr("flightsel_no")), 214 ColumnDescriptor("departureTime", xstr("flightsel_deptime"), 215 sortable = True), 216 ColumnDescriptor("departureICAO", xstr("flightsel_from"), 217 sortable = True), 218 ColumnDescriptor("arrivalICAO", xstr("flightsel_to"), 219 sortable = True), 220 ColumnDescriptor("tailNumber", xstr("pendflt_acft"), 221 convertFn = getAircraft) 222 ] 223 224 def __init__(self, which, wizard): 225 """Construct the frame with the given title.""" 226 super(PendingFlightsFrame, self).__init__(xstr("pendflt_title_" + which)) 227 228 self._which = which 229 self._wizard = wizard 230 231 alignment = gtk.Alignment(xscale = 1.0, yscale = 1.0) 232 alignment.set_padding(padding_top = 2, padding_bottom = 8, 233 padding_left = 4, padding_right = 4) 234 235 hbox = gtk.HBox() 236 237 self._flights = [] 238 self._flightList = FlightList(columnDescriptors = 239 PendingFlightsFrame.columnDescriptors, 240 widthRequest = 500) 241 self._flightList.connect("selection-changed", self._selectionChanged) 242 243 hbox.pack_start(self._flightList, True, True, 4) 244 245 buttonBox = gtk.VBox() 246 247 self._editButton = gtk.Button(xstr("pendflt_edit_" + which)) 248 self._editButton.set_sensitive(False) 249 buttonBox.pack_start(self._editButton, False, False, 2) 250 251 self._reflyButton = gtk.Button(xstr("pendflt_refly_" + which)) 252 self._reflyButton.set_sensitive(False) 253 buttonBox.pack_start(self._reflyButton, False, False, 2) 254 255 self._deleteButton = gtk.Button(xstr("pendflt_delete_" + which)) 256 self._deleteButton.set_sensitive(False) 257 buttonBox.pack_start(self._deleteButton, False, False, 2) 258 259 hbox.pack_start(buttonBox, False, False, 4) 260 261 alignment.add(hbox) 262 self.add(alignment) 263 264 @property 265 def hasFlights(self): 266 """Determine if there are any flights in the list.""" 267 return self._flightList.hasFlights 268 269 def clear(self): 270 """Clear the lists.""" 271 self._flights = [] 272 self._flightList.clear() 273 274 def addFlight(self, flight): 275 """Add a flight to the list.""" 276 self._flights.append(flight) 277 self._flightList.addFlight(flight) 278 279 def _selectionChanged(self, flightList, selectedIndex): 280 """Called when the selection in the list has changed.""" 281 sensitive = selectedIndex is not None 282 self._editButton.set_sensitive(sensitive) 283 self._reflyButton.set_sensitive(sensitive) 284 self._deleteButton.set_sensitive(sensitive) 285 286 #----------------------------------------------------------------------------- 287 288 class PendingFlightsWindow(gtk.Window): 289 """The window to display the lists of the pending (reported or rejected) 290 flights.""" 291 def __init__(self, wizard): 292 """Construct the window""" 293 super(PendingFlightsWindow, self).__init__() 294 295 gui = wizard.gui 296 297 self.set_title(WINDOW_TITLE_BASE + " - " + xstr("pendflt_title")) 298 self.set_size_request(-1, 450) 299 self.set_transient_for(gui.mainWindow) 300 self.set_modal(True) 301 302 mainAlignment = gtk.Alignment(xalign = 0.5, yalign = 0.5, 303 xscale = 1.0, yscale = 1.0) 304 mainAlignment.set_padding(padding_top = 0, padding_bottom = 12, 305 padding_left = 8, padding_right = 8) 306 307 vbox = gtk.VBox() 308 309 self._reportedFrame = PendingFlightsFrame("reported", wizard) 310 vbox.pack_start(self._reportedFrame, True, True, 2) 311 312 self._rejectedFrame = PendingFlightsFrame("rejected", wizard) 313 vbox.pack_start(self._rejectedFrame, True, True, 2) 314 315 alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5, 316 xscale = 0.0, yscale = 0.0) 317 self._closeButton = gtk.Button(xstr("button_ok")) 318 self._closeButton.connect("clicked", self._closeClicked) 319 alignment.add(self._closeButton) 320 vbox.pack_start(alignment, False, False, 2) 321 322 mainAlignment.add(vbox) 323 324 self.add(mainAlignment) 325 326 self.connect("key-press-event", self._keyPressed) 327 328 @property 329 def hasFlights(self): 330 """Determine if the window has any flights.""" 331 return self._reportedFrame.hasFlights or self._rejectedFrame.hasFlights 332 333 def clear(self): 334 """Clear the lists.""" 335 self._reportedFrame.clear() 336 self._rejectedFrame.clear() 337 338 def addReportedFlight(self, flight): 339 """Add a reported flight.""" 340 self._reportedFrame.addFlight(flight) 341 342 def addRejectedFlight(self, flight): 343 """Add a rejected flight.""" 344 self._rejectedFrame.addFlight(flight) 345 346 def _closeClicked(self, button): 347 """Called when the Close button is clicked. 348 349 A 'delete-event' is emitted to close the window.""" 350 self.emit("delete-event", None) 351 352 def _keyPressed(self, window, event): 353 """Called when a key is pressed in the window. 354 355 If the Escape key is pressed, 'delete-event' is emitted to close the 356 window.""" 357 if gdk.keyval_name(event.keyval) == "Escape": 358 self.emit("delete-event", None) 359 return True 360 361 #-----------------------------------------------------------------------------
Note:
See TracChangeset
for help on using the changeset viewer.