Changeset 84:40b2d74e74f4 for src/mlx
- Timestamp:
- 04/15/12 11:03:59 (13 years ago)
- Branch:
- default
- Phase:
- public
- Location:
- src/mlx
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mlx/flight.py
r71 r84 31 31 gui.resetFlightStatus() 32 32 33 self.cruiseAltitude = None34 33 self.flareTimeFromFS = False 35 34 self.entranceExam = False 36 self.zfw = None37 35 38 36 self.options = Options() … … 44 42 self._endCondition = threading.Condition() 45 43 46 self.v1 = None47 self.vr = None48 self.v2 = None49 50 44 self._flareStart = None 51 45 self._flareStartFS = None … … 56 50 return self._stage 57 51 52 @property 53 def zfw(self): 54 """Get the Zero-Fuel Weight of the flight.""" 55 return self._gui.zfw 56 57 @property 58 def cruiseAltitude(self): 59 """Get the cruise altitude of the flight.""" 60 return self._gui.cruiseAltitude 61 62 @property 63 def v1(self): 64 """Get the V1 speed of the flight.""" 65 return self._gui.v1 66 67 @property 68 def vr(self): 69 """Get the Vr speed of the flight.""" 70 return self._gui.vr 71 72 @property 73 def v2(self): 74 """Get the V2 speed of the flight.""" 75 return self._gui.v2 76 58 77 def setStage(self, timestamp, stage): 59 78 """Set the flight stage. … … 62 81 if stage!=self._stage: 63 82 self._stage = stage 83 self._gui.setStage(stage) 64 84 self.logger.stage(timestamp, stage) 65 self._gui.setStage(stage)66 85 if stage==const.STAGE_END: 67 86 with self._endCondition: -
src/mlx/gui/common.py
r76 r84 78 78 79 79 #------------------------------------------------------------------------------ 80 81 class IntegerEntry(gtk.Entry): 82 """An entry that allows only either an empty value, or an integer.""" 83 def __init__(self, defaultValue = None): 84 """Construct the entry.""" 85 gtk.Entry.__init__(self) 86 87 self._defaultValue = defaultValue 88 self._currentInteger = defaultValue 89 self._selfSetting = False 90 self._set_text() 91 92 self.connect("changed", self._handle_changed) 93 94 def get_int(self): 95 """Get the integer.""" 96 return self._currentInteger 97 98 def set_int(self, value): 99 """Set the integer.""" 100 if value!=self._currentInteger: 101 self._currentInteger = value 102 self.emit("integer-changed", self._currentInteger) 103 self._set_text() 104 105 def _handle_changed(self, widget): 106 """Handle the changed signal.""" 107 if self._selfSetting: 108 return 109 text = self.get_text() 110 if text=="": 111 self.set_int(self._defaultValue) 112 else: 113 try: 114 self.set_int(int(text)) 115 except: 116 self._set_text() 117 118 def _set_text(self): 119 """Set the text value from the current integer.""" 120 self._selfSetting = True 121 self.set_text("" if self._currentInteger is None 122 else str(self._currentInteger)) 123 self._selfSetting = False 124 125 #------------------------------------------------------------------------------ 126 127 gobject.signal_new("integer-changed", IntegerEntry, gobject.SIGNAL_RUN_FIRST, 128 None, (object,)) 129 130 #------------------------------------------------------------------------------ -
src/mlx/gui/flight.py
r82 r84 684 684 table.attach(label, 0, 1, 3, 4) 685 685 686 self._cargoWeight = gtk.Entry()686 self._cargoWeight = IntegerEntry(defaultValue = 0) 687 687 self._cargoWeight.set_width_chars(6) 688 688 self._cargoWeight.set_alignment(1.0) 689 self._cargoWeight.connect(" changed", self._cargoWeightChanged)689 self._cargoWeight.connect("integer-changed", self._cargoWeightChanged) 690 690 self._cargoWeight.set_tooltip_text("The weight of the cargo for your flight.") 691 691 table.attach(self._cargoWeight, 1, 2, 3, 4) 692 self._cargoWeightValue = 0693 692 label.set_mnemonic_widget(self._cargoWeight) 694 693 … … 745 744 self._numPassengers.set_text(str(bookedFlight.numPassengers)) 746 745 self._bagWeight.set_text(str(bookedFlight.bagWeight)) 747 self._cargoWeightValue = bookedFlight.cargoWeight 748 self._cargoWeight.set_text(str(bookedFlight.cargoWeight)) 746 self._cargoWeight.set_int(bookedFlight.cargoWeight) 749 747 self._cargoWeight.set_sensitive(True) 750 748 self._mailWeight.set_text(str(bookedFlight.mailWeight)) … … 757 755 self._zfwButton.set_sensitive(False) 758 756 759 def _calculateZFW(self):757 def calculateZFW(self): 760 758 """Calculate the ZFW value.""" 761 759 zfw = self._wizard.gui._flight.aircraft.dow … … 763 761 zfw += (bookedFlight.numCrew + bookedFlight.numPassengers) * 82 764 762 zfw += bookedFlight.bagWeight 765 zfw += self._cargoWeight Value763 zfw += self._cargoWeight.get_int() 766 764 zfw += bookedFlight.mailWeight 767 765 return zfw … … 769 767 def _updateCalculatedZFW(self): 770 768 """Update the calculated ZFW""" 771 zfw = self. _calculateZFW()769 zfw = self.calculateZFW() 772 770 773 771 markupBegin = "<b>" … … 779 777 self._calculatedZFW.set_markup(markupBegin + str(zfw) + markupEnd) 780 778 781 def _cargoWeightChanged(self, entry ):779 def _cargoWeightChanged(self, entry, weight): 782 780 """Called when the cargo weight has changed.""" 783 text = self._cargoWeight.get_text()784 if text=="":785 self._cargoWeightValue = 0786 else:787 try:788 self._cargoWeightValue = int(text)789 except:790 self._cargoWeight.set_text(str(self._cargoWeightValue))791 781 self._updateCalculatedZFW() 792 782 … … 816 806 def _forwardClicked(self, button): 817 807 """Called when the forward button is clicked.""" 818 if not self._finalized:819 self._wizard._zfw = self._calculateZFW()820 808 self._wizard.nextPage() 821 809 … … 1013 1001 self._button.connect("clicked", self._forwardClicked) 1014 1002 1003 @property 1004 def cruiseLevel(self): 1005 """Get the cruise level.""" 1006 return self._cruiseLevel.get_value_as_int() 1007 1015 1008 def activate(self): 1016 1009 """Setup the route from the booked flight.""" … … 1053 1046 self._wizard.nextPage() 1054 1047 else: 1055 self._wizard._cruiseAltitude = self._cruiseLevel.get_value_as_int() * 1001056 self._wizard._route = self._getRoute()1057 1058 1048 self._backButton.set_sensitive(False) 1059 1049 self._button.set_sensitive(False) … … 1235 1225 if not self._finalized: 1236 1226 self._wizard.gui.startMonitoring() 1237 self.finalize()1238 1227 self._finalized = True 1239 1228 … … 1253 1242 xscale = 0.0, yscale = 0.0) 1254 1243 1255 table = gtk.Table(5, 3)1244 table = gtk.Table(5, 4) 1256 1245 table.set_row_spacings(4) 1257 1246 table.set_col_spacings(16) … … 1268 1257 self._runway.set_width_chars(10) 1269 1258 self._runway.set_tooltip_text("The runway the takeoff is performed from.") 1270 self._runway.connect("changed", self._updateForwardButton) 1271 table.attach(self._runway, 1, 2, 0, 1) 1259 table.attach(self._runway, 1, 3, 0, 1) 1272 1260 label.set_mnemonic_widget(self._runway) 1273 1261 … … 1280 1268 self._sid.set_width_chars(10) 1281 1269 self._sid.set_tooltip_text("The name of the Standard Instrument Deparature procedure followed.") 1282 self._sid.connect("changed", self._updateForwardButton) 1283 table.attach(self._sid, 1, 2, 1, 2) 1270 table.attach(self._sid, 1, 3, 1, 2) 1284 1271 label.set_mnemonic_widget(self._sid) 1285 1272 … … 1290 1277 table.attach(label, 0, 1, 2, 3) 1291 1278 1292 self._v1 = gtk.SpinButton() 1293 self._v1.set_increments(step = 1, page = 10) 1294 self._v1.set_range(min = 50, max = 300) 1295 self._v1.set_value(100) 1296 self._v1.set_numeric(True) 1279 self._v1 = IntegerEntry() 1280 self._v1.set_width_chars(1) 1297 1281 self._v1.set_tooltip_markup("The takeoff decision speed in knots.") 1298 self._v1.connect("changed", self._updateForwardButton) 1299 table.attach(self._v1, 1, 2, 2, 3) 1282 table.attach(self._v1, 2, 3, 2, 3) 1300 1283 label.set_mnemonic_widget(self._v1) 1301 1284 1302 table.attach(gtk.Label("knots"), 2, 3, 2, 3)1285 table.attach(gtk.Label("knots"), 3, 4, 2, 3) 1303 1286 1304 1287 label = gtk.Label("V<sub>_r</sub>:") … … 1308 1291 table.attach(label, 0, 1, 3, 4) 1309 1292 1310 self._vr = gtk.SpinButton() 1311 self._vr.set_increments(step = 1, page = 10) 1312 self._vr.set_range(min = 50, max = 300) 1313 self._vr.set_value(110) 1314 self._vr.set_numeric(True) 1293 self._vr = IntegerEntry() 1294 self._vr.set_width_chars(1) 1315 1295 self._vr.set_tooltip_markup("The takeoff rotation speed in knots.") 1316 self._vr.connect("changed", self._updateForwardButton) 1317 table.attach(self._vr, 1, 2, 3, 4) 1296 table.attach(self._vr, 2, 3, 3, 4) 1318 1297 label.set_mnemonic_widget(self._vr) 1319 1298 1320 table.attach(gtk.Label("knots"), 2, 3, 3, 4)1299 table.attach(gtk.Label("knots"), 3, 4, 3, 4) 1321 1300 1322 1301 label = gtk.Label("V<sub>_2</sub>:") … … 1326 1305 table.attach(label, 0, 1, 4, 5) 1327 1306 1328 self._v2 = gtk.SpinButton() 1329 self._v2.set_increments(step = 1, page = 10) 1330 self._v2.set_range(min = 50, max = 300) 1331 self._v2.set_value(120) 1332 self._v2.set_numeric(True) 1307 self._v2 = IntegerEntry() 1308 self._v2.set_width_chars(1) 1333 1309 self._v2.set_tooltip_markup("The takeoff safety speed in knots.") 1334 self._v2.connect("changed", self._updateForwardButton) 1335 table.attach(self._v2, 1, 2, 4, 5) 1310 table.attach(self._v2, 2, 3, 4, 5) 1336 1311 label.set_mnemonic_widget(self._v2) 1337 1312 1338 table.attach(gtk.Label("knots"), 2, 3, 4, 5)1313 table.attach(gtk.Label("knots"), 3, 4, 4, 5) 1339 1314 1340 1315 button = self.addButton(gtk.STOCK_GO_BACK) … … 1345 1320 self._button.set_use_stock(True) 1346 1321 self._button.connect("clicked", self._forwardClicked) 1322 1323 @property 1324 def v1(self): 1325 """Get the v1 speed.""" 1326 return self._v1.get_int() 1327 1328 @property 1329 def vr(self): 1330 """Get the vr speed.""" 1331 return self._vr.get_int() 1332 1333 @property 1334 def v2(self): 1335 """Get the v2 speed.""" 1336 return self._v2.get_int() 1347 1337 1348 1338 def activate(self): … … 1352 1342 self._sid.set_text("") 1353 1343 self._sid.set_sensitive(True) 1344 self._v1.set_int(None) 1354 1345 self._v1.set_sensitive(True) 1355 1346 self._vr.set_sensitive(True) 1356 1347 self._v2.set_sensitive(True) 1357 self._ updateForwardButton()1358 1359 def f inalize(self):1360 """F inalize the page."""1348 self._button.set_sensitive(False) 1349 1350 def freezeValues(self): 1351 """Freeze the values on the page, and enable the forward button.""" 1361 1352 self._runway.set_sensitive(False) 1362 1353 self._sid.set_sensitive(False) … … 1364 1355 self._vr.set_sensitive(False) 1365 1356 self._v2.set_sensitive(False) 1366 1367 flight = self._wizard.gui.flight 1368 flight.v1 = self._v1.get_value_as_int() 1369 flight.vr = self._vr.get_value_as_int() 1370 flight.v2 = self._v2.get_value_as_int() 1371 1372 def _updateForwardButton(self, widget = None): 1373 """Update the Forward buttons sensitivity.""" 1374 self._button.set_sensitive(self._runway.get_text()!="" and 1375 self._sid.get_text()!="" and 1376 self._v1.get_value_as_int()<=self._vr.get_value_as_int() and 1377 self._vr.get_value_as_int()<=self._v2.get_value_as_int()) 1378 1357 self._button.set_sensitive(True) 1358 1379 1359 def _backClicked(self, button): 1380 1360 """Called when the Back button is pressed.""" … … 1582 1562 self._pages.append(GateSelectionPage(self)) 1583 1563 self._pages.append(ConnectPage(self)) 1584 self._pages.append(PayloadPage(self)) 1564 self._payloadPage = PayloadPage(self) 1565 self._pages.append(self._payloadPage) 1585 1566 self._pages.append(TimePage(self)) 1586 self._pages.append(RoutePage(self)) 1567 self._routePage = RoutePage(self) 1568 self._pages.append(self._routePage) 1587 1569 self._pages.append(BriefingPage(self, True)) 1588 1570 self._pages.append(BriefingPage(self, False)) 1589 self._pages.append(TakeoffPage(self)) 1571 self._takeoffPage = TakeoffPage(self) 1572 self._pages.append(self._takeoffPage) 1590 1573 self._pages.append(LandingPage(self)) 1591 1574 … … 1632 1615 self.grabDefault() 1633 1616 1617 @property 1618 def zfw(self): 1619 """Get the calculated ZFW value.""" 1620 return 0 if self._bookedFlight is None \ 1621 else self._payloadPage.calculateZFW() 1622 1623 @property 1624 def cruiseAltitude(self): 1625 """Get the cruise altitude.""" 1626 return self._routePage.cruiseLevel * 100 1627 1628 @property 1629 def v1(self): 1630 """Get the V1 speed.""" 1631 return None if self._bookedFlight is None else self._takeoffPage.v1 1632 1633 @property 1634 def vr(self): 1635 """Get the Vr speed.""" 1636 return None if self._bookedFlight is None else self._takeoffPage.vr 1637 1638 @property 1639 def v2(self): 1640 """Get the V2 speed.""" 1641 return None if self._bookedFlight is None else self._takeoffPage.v2 1642 1634 1643 def nextPage(self, finalize = True): 1635 1644 """Go to the next page.""" … … 1655 1664 """Called when we have disconnected from the simulator.""" 1656 1665 self._initialize() 1666 1667 def setStage(self, stage): 1668 """Set the flight stage to the given one.""" 1669 if stage==const.STAGE_TAKEOFF: 1670 self._takeoffPage.freezeValues() 1657 1671 1658 1672 def _initialize(self): … … 1665 1679 self._bookedFlight = None 1666 1680 self._departureGate = "-" 1667 self._zfw = None1668 self._cruiseAltitude = None1669 self._route = None1670 1681 self._departureNOTAMs = None 1671 1682 self._departureMETAR = None -
src/mlx/gui/gui.py
r81 r84 108 108 """Get the flight being performed.""" 109 109 return self._flight 110 111 @property 112 def zfw(self): 113 """Get Zero-Fuel Weight calculated for the current flight.""" 114 return self._wizard.zfw 115 116 @property 117 def cruiseAltitude(self): 118 """Get cruise altitude calculated for the current flight.""" 119 return self._wizard.cruiseAltitude 120 121 @property 122 def v1(self): 123 """Get the V1 speed calculated for the flight.""" 124 return self._wizard.v1 125 126 @property 127 def vr(self): 128 """Get the Vr speed calculated for the flight.""" 129 return self._wizard.vr 130 131 @property 132 def v2(self): 133 """Get the V2 speed calculated for the flight.""" 134 return self._wizard.v2 110 135 111 136 def run(self): … … 234 259 self._statusbar.setStage(stage) 235 260 self._statusIcon.setStage(stage) 261 self._wizard.setStage(stage) 236 262 237 263 def setRating(self, rating):
Note:
See TracChangeset
for help on using the changeset viewer.