Changeset 84:40b2d74e74f4


Ignore:
Timestamp:
04/15/12 11:03:59 (12 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
hg-Phase:
(<MercurialRepository 1 'hg:/home/ivaradi/mlx/hg' '/'>, 'public')
Message:

Created an integer entry widget and made use of it for entering the cargo weight and the takeoff speeds.

Location:
src/mlx
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/flight.py

    r71 r84  
    3131        gui.resetFlightStatus()
    3232
    33         self.cruiseAltitude = None
    3433        self.flareTimeFromFS = False
    3534        self.entranceExam = False
    36         self.zfw = None
    3735
    3836        self.options = Options()
     
    4442        self._endCondition = threading.Condition()
    4543
    46         self.v1 = None
    47         self.vr = None
    48         self.v2 = None
    49 
    5044        self._flareStart = None
    5145        self._flareStartFS = None
     
    5650        return self._stage
    5751
     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
    5877    def setStage(self, timestamp, stage):
    5978        """Set the flight stage.
     
    6281        if stage!=self._stage:
    6382            self._stage = stage
     83            self._gui.setStage(stage)
    6484            self.logger.stage(timestamp, stage)
    65             self._gui.setStage(stage)
    6685            if stage==const.STAGE_END:
    6786                with self._endCondition:
  • src/mlx/gui/common.py

    r76 r84  
    7878
    7979#------------------------------------------------------------------------------
     80
     81class 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
     127gobject.signal_new("integer-changed", IntegerEntry, gobject.SIGNAL_RUN_FIRST,
     128                   None, (object,))
     129
     130#------------------------------------------------------------------------------
  • src/mlx/gui/flight.py

    r82 r84  
    684684        table.attach(label, 0, 1, 3, 4)
    685685
    686         self._cargoWeight = gtk.Entry()
     686        self._cargoWeight = IntegerEntry(defaultValue = 0)
    687687        self._cargoWeight.set_width_chars(6)
    688688        self._cargoWeight.set_alignment(1.0)
    689         self._cargoWeight.connect("changed", self._cargoWeightChanged)
     689        self._cargoWeight.connect("integer-changed", self._cargoWeightChanged)
    690690        self._cargoWeight.set_tooltip_text("The weight of the cargo for your flight.")
    691691        table.attach(self._cargoWeight, 1, 2, 3, 4)
    692         self._cargoWeightValue = 0       
    693692        label.set_mnemonic_widget(self._cargoWeight)
    694693
     
    745744        self._numPassengers.set_text(str(bookedFlight.numPassengers))
    746745        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)
    749747        self._cargoWeight.set_sensitive(True)
    750748        self._mailWeight.set_text(str(bookedFlight.mailWeight))
     
    757755        self._zfwButton.set_sensitive(False)
    758756
    759     def _calculateZFW(self):
     757    def calculateZFW(self):
    760758        """Calculate the ZFW value."""
    761759        zfw = self._wizard.gui._flight.aircraft.dow
     
    763761        zfw += (bookedFlight.numCrew + bookedFlight.numPassengers) * 82
    764762        zfw += bookedFlight.bagWeight
    765         zfw += self._cargoWeightValue
     763        zfw += self._cargoWeight.get_int()
    766764        zfw += bookedFlight.mailWeight
    767765        return zfw
     
    769767    def _updateCalculatedZFW(self):
    770768        """Update the calculated ZFW"""
    771         zfw = self._calculateZFW()
     769        zfw = self.calculateZFW()
    772770
    773771        markupBegin = "<b>"
     
    779777        self._calculatedZFW.set_markup(markupBegin + str(zfw) + markupEnd)
    780778
    781     def _cargoWeightChanged(self, entry):
     779    def _cargoWeightChanged(self, entry, weight):
    782780        """Called when the cargo weight has changed."""
    783         text = self._cargoWeight.get_text()
    784         if text=="":
    785             self._cargoWeightValue = 0
    786         else:
    787             try:
    788                 self._cargoWeightValue = int(text)
    789             except:
    790                 self._cargoWeight.set_text(str(self._cargoWeightValue))
    791781        self._updateCalculatedZFW()
    792782           
     
    816806    def _forwardClicked(self, button):
    817807        """Called when the forward button is clicked."""
    818         if not self._finalized:
    819             self._wizard._zfw = self._calculateZFW()
    820808        self._wizard.nextPage()
    821809
     
    10131001        self._button.connect("clicked", self._forwardClicked)
    10141002
     1003    @property
     1004    def cruiseLevel(self):
     1005        """Get the cruise level."""
     1006        return self._cruiseLevel.get_value_as_int()
     1007
    10151008    def activate(self):
    10161009        """Setup the route from the booked flight."""
     
    10531046            self._wizard.nextPage()
    10541047        else:
    1055             self._wizard._cruiseAltitude = self._cruiseLevel.get_value_as_int() * 100
    1056             self._wizard._route = self._getRoute()
    1057 
    10581048            self._backButton.set_sensitive(False)
    10591049            self._button.set_sensitive(False)
     
    12351225            if not self._finalized:
    12361226                self._wizard.gui.startMonitoring()
    1237                 self.finalize()
    12381227                self._finalized = True
    12391228
     
    12531242                                  xscale = 0.0, yscale = 0.0)
    12541243
    1255         table = gtk.Table(5, 3)
     1244        table = gtk.Table(5, 4)
    12561245        table.set_row_spacings(4)
    12571246        table.set_col_spacings(16)
     
    12681257        self._runway.set_width_chars(10)
    12691258        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)
    12721260        label.set_mnemonic_widget(self._runway)
    12731261       
     
    12801268        self._sid.set_width_chars(10)
    12811269        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)
    12841271        label.set_mnemonic_widget(self._sid)
    12851272       
     
    12901277        table.attach(label, 0, 1, 2, 3)
    12911278
    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)
    12971281        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)
    13001283        label.set_mnemonic_widget(self._v1)
    13011284       
    1302         table.attach(gtk.Label("knots"), 2, 3, 2, 3)
     1285        table.attach(gtk.Label("knots"), 3, 4, 2, 3)
    13031286       
    13041287        label = gtk.Label("V<sub>_r</sub>:")
     
    13081291        table.attach(label, 0, 1, 3, 4)
    13091292
    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)
    13151295        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)
    13181297        label.set_mnemonic_widget(self._vr)
    13191298       
    1320         table.attach(gtk.Label("knots"), 2, 3, 3, 4)
     1299        table.attach(gtk.Label("knots"), 3, 4, 3, 4)
    13211300       
    13221301        label = gtk.Label("V<sub>_2</sub>:")
     
    13261305        table.attach(label, 0, 1, 4, 5)
    13271306
    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)
    13331309        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)
    13361311        label.set_mnemonic_widget(self._v2)
    13371312       
    1338         table.attach(gtk.Label("knots"), 2, 3, 4, 5)
     1313        table.attach(gtk.Label("knots"), 3, 4, 4, 5)
    13391314       
    13401315        button = self.addButton(gtk.STOCK_GO_BACK)
     
    13451320        self._button.set_use_stock(True)
    13461321        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()
    13471337
    13481338    def activate(self):
     
    13521342        self._sid.set_text("")
    13531343        self._sid.set_sensitive(True)
     1344        self._v1.set_int(None)
    13541345        self._v1.set_sensitive(True)
    13551346        self._vr.set_sensitive(True)
    13561347        self._v2.set_sensitive(True)
    1357         self._updateForwardButton()
    1358        
    1359     def finalize(self):
    1360         """Finalize 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."""
    13611352        self._runway.set_sensitive(False)
    13621353        self._sid.set_sensitive(False)
     
    13641355        self._vr.set_sensitive(False)
    13651356        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       
    13791359    def _backClicked(self, button):
    13801360        """Called when the Back button is pressed."""
     
    15821562        self._pages.append(GateSelectionPage(self))
    15831563        self._pages.append(ConnectPage(self))
    1584         self._pages.append(PayloadPage(self))
     1564        self._payloadPage = PayloadPage(self)
     1565        self._pages.append(self._payloadPage)
    15851566        self._pages.append(TimePage(self))
    1586         self._pages.append(RoutePage(self))
     1567        self._routePage = RoutePage(self)
     1568        self._pages.append(self._routePage)
    15871569        self._pages.append(BriefingPage(self, True))
    15881570        self._pages.append(BriefingPage(self, False))
    1589         self._pages.append(TakeoffPage(self))
     1571        self._takeoffPage = TakeoffPage(self)
     1572        self._pages.append(self._takeoffPage)
    15901573        self._pages.append(LandingPage(self))
    15911574       
     
    16321615            self.grabDefault()
    16331616
     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
    16341643    def nextPage(self, finalize = True):
    16351644        """Go to the next page."""
     
    16551664        """Called when we have disconnected from the simulator."""
    16561665        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()
    16571671
    16581672    def _initialize(self):
     
    16651679        self._bookedFlight = None
    16661680        self._departureGate = "-"
    1667         self._zfw = None
    1668         self._cruiseAltitude = None
    1669         self._route = None
    16701681        self._departureNOTAMs = None
    16711682        self._departureMETAR = None
  • src/mlx/gui/gui.py

    r81 r84  
    108108        """Get the flight being performed."""
    109109        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
    110135       
    111136    def run(self):
     
    234259        self._statusbar.setStage(stage)
    235260        self._statusIcon.setStage(stage)
     261        self._wizard.setStage(stage)
    236262
    237263    def setRating(self, rating):
Note: See TracChangeset for help on using the changeset viewer.