Changeset 819:024e8697000e for src/mlx/gui/flightlist.py
- Timestamp:
- 09/25/16 06:40:16 (8 years ago)
- Branch:
- default
- hg-Phase:
- (<MercurialRepository 1 'hg:/home/ivaradi/mlx/hg' '/'>, 'public')
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.