Ignore:
Timestamp:
03/14/22 08:46:34 (2 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
python3
hg-Phase:
(<MercurialRepository 1 'hg:/home/ivaradi/mlx/hg' '/'>, 'public')
Message:

Updates for the new crew and passenger handling (re #357)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/gui/flight.py

    r1008 r1033  
    1515from mlx.i18n import xstr, getLanguage
    1616from mlx.sound import startSound
     17from mlx.rpc import BookedFlight
    1718import mlx.web as web
    1819
     
    21052106        super(PayloadPage, self).__init__(wizard, "payload",
    21062107                                          xstr("payload_title"),
    2107                                           xstr("payload_help"),
     2108                                          xstr("payload_help") + "\n\n \n \n",
    21082109                                          completedHelp = xstr("payload_chelp"))
    21092110
     
    21182119        self.setMainWidget(alignment)
    21192120
    2120         label = Gtk.Label(xstr("payload_crew"))
     2121        self._crewLabel = label = Gtk.Label(xstr("payload_crew"))
    21212122        label.set_use_underline(True)
    21222123        label.set_alignment(0.0, 0.5)
    21232124        table.attach(label, 0, 1, 0, 1)
    21242125
    2125         self._numCrew = IntegerEntry(defaultValue = 0)
    2126         self._numCrew.set_width_chars(6)
    2127         self._numCrew.connect("integer-changed", self._weightChanged)
    2128         self._numCrew.set_tooltip_text(xstr("payload_crew_tooltip"))
    2129         table.attach(self._numCrew, 1, 2, 0, 1)
    2130         label.set_mnemonic_widget(self._numCrew)
    2131 
    2132         label = Gtk.Label(xstr("payload_pax"))
     2126        self._numCockpitCrew = Gtk.Label()
     2127
     2128        self._numCabinCrew = IntegerEntry(defaultValue = 0)
     2129        self._numCabinCrew.set_width_chars(6)
     2130        self._numCabinCrew.connect("integer-changed", self._weightChanged)
     2131        self._numCabinCrew.set_tooltip_text(xstr("payload_crew_tooltip"))
     2132
     2133        crewBox = Gtk.HBox()
     2134        crewBox.pack_start(self._numCockpitCrew, False, False, 0)
     2135        crewBox.pack_start(Gtk.Label("+"), False, False, 4)
     2136        crewBox.pack_start(self._numCabinCrew, False, False, 0)
     2137        crewBox.set_halign(Gtk.Align.END)
     2138
     2139        table.attach(crewBox, 1, 2, 0, 1)
     2140        label.set_mnemonic_widget(self._numCabinCrew)
     2141
     2142        label = Gtk.Label(xstr("payload_crew_info"))
     2143        label.set_halign(Gtk.Align.START)
     2144        table.attach(label, 2, 3, 0, 1)
     2145
     2146        self._paxLabel = label = Gtk.Label(xstr("payload_pax"))
    21332147        label.set_use_underline(True)
    21342148        label.set_alignment(0.0, 0.5)
     
    21392153        self._numPassengers.connect("integer-changed", self._weightChanged)
    21402154        self._numPassengers.set_tooltip_text(xstr("payload_pax_tooltip"))
    2141         table.attach(self._numPassengers, 1, 2, 1, 2)
     2155
     2156        self._numChildren = IntegerEntry(defaultValue = 0)
     2157        self._numChildren.set_width_chars(6)
     2158        self._numChildren.connect("integer-changed", self._weightChanged)
     2159        self._numChildren.set_tooltip_text(xstr("payload_pax_children_tooltip"))
     2160
     2161        self._numInfants = IntegerEntry(defaultValue = 0)
     2162        self._numInfants.set_width_chars(6)
     2163        self._numInfants.connect("integer-changed", self._weightChanged)
     2164        self._numInfants.set_tooltip_text(xstr("payload_pax_infants_tooltip"))
     2165
     2166        paxBox = Gtk.HBox()
     2167        paxBox.pack_start(self._numPassengers, False, False, 0)
     2168        paxBox.pack_start(Gtk.Label("+"), False, False, 4)
     2169        paxBox.pack_start(self._numChildren, False, False, 0)
     2170        paxBox.pack_start(Gtk.Label("+"), False, False, 4)
     2171        paxBox.pack_start(self._numInfants, False, False, 0)
     2172
     2173        table.attach(paxBox, 1, 2, 1, 2)
    21422174        label.set_mnemonic_widget(self._numPassengers)
     2175
     2176        label = Gtk.Label(xstr("payload_pax_info"))
     2177        label.set_halign(Gtk.Align.START)
     2178        table.attach(label, 2, 3, 1, 2)
    21432179
    21442180        label = Gtk.Label(xstr("payload_bag"))
     
    21512187        self._bagWeight.connect("integer-changed", self._weightChanged)
    21522188        self._bagWeight.set_tooltip_text(xstr("payload_bag_tooltip"))
     2189        self._bagWeight.set_hexpand(False)
     2190        self._bagWeight.set_halign(Gtk.Align.END)
    21532191        table.attach(self._bagWeight, 1, 2, 2, 3)
    21542192        label.set_mnemonic_widget(self._bagWeight)
    21552193
    2156         table.attach(Gtk.Label("kg"), 2, 3, 2, 3)
     2194        label = Gtk.Label("kg")
     2195        label.set_halign(Gtk.Align.START)
     2196        table.attach(label, 2, 3, 2, 3)
    21572197
    21582198        label = Gtk.Label(xstr("payload_cargo"))
     
    21652205        self._cargoWeight.connect("integer-changed", self._weightChanged)
    21662206        self._cargoWeight.set_tooltip_text(xstr("payload_cargo_tooltip"))
     2207        self._cargoWeight.set_hexpand(False)
     2208        self._cargoWeight.set_halign(Gtk.Align.END)
    21672209        table.attach(self._cargoWeight, 1, 2, 3, 4)
    21682210        label.set_mnemonic_widget(self._cargoWeight)
    21692211
    2170         table.attach(Gtk.Label("kg"), 2, 3, 3, 4)
     2212        label = Gtk.Label("kg")
     2213        label.set_halign(Gtk.Align.START)
     2214        table.attach(label, 2, 3, 3, 4)
    21712215
    21722216        label = Gtk.Label(xstr("payload_mail"))
     
    21792223        self._mailWeight.connect("integer-changed", self._weightChanged)
    21802224        self._mailWeight.set_tooltip_text(xstr("payload_mail_tooltip"))
     2225        self._mailWeight.set_hexpand(False)
     2226        self._mailWeight.set_halign(Gtk.Align.END)
    21812227        table.attach(self._mailWeight, 1, 2, 4, 5)
    21822228        label.set_mnemonic_widget(self._mailWeight)
    21832229
    2184         table.attach(Gtk.Label("kg"), 2, 3, 4, 5)
     2230        label = Gtk.Label("kg")
     2231        label.set_halign(Gtk.Align.START)
     2232        table.attach(label, 2, 3, 4, 5)
    21852233
    21862234        label = Gtk.Label("<b>" + xstr("payload_zfw") + "</b>")
     
    21942242        table.attach(self._calculatedZFW, 1, 2, 5, 6)
    21952243
    2196         table.attach(Gtk.Label("kg"), 2, 3, 5, 6)
     2244        label = Gtk.Label("kg")
     2245        label.set_halign(Gtk.Align.START)
     2246        table.attach(label, 2, 3, 5, 6)
    21972247
    21982248        self._zfwButton = Gtk.Button(xstr("payload_fszfw"))
     
    22082258        self._simulatorZFWValue = None
    22092259
    2210         table.attach(Gtk.Label("kg"), 2, 3, 6, 7)
     2260        label = Gtk.Label("kg")
     2261        label.set_halign(Gtk.Align.START)
     2262        table.attach(label, 2, 3, 6, 7)
    22112263
    22122264        self.addCancelFlightButton()
     
    22152267
    22162268    @property
    2217     def numCrew(self):
    2218         """The number of the crew members on the flight."""
    2219         return self._numCrew.get_int()
     2269    def numCockpitCrew(self):
     2270        """The number of the cockpit crew members on the flight."""
     2271        return self._wizard._bookedFlight.numCockpitCrew
     2272
     2273    @property
     2274    def numCabinCrew(self):
     2275        """The number of the cabin members on the flight."""
     2276        return self._numCabinCrew.get_int()
    22202277
    22212278    @property
    22222279    def numPassengers(self):
    2223         """The number of the passengers on the flight."""
     2280        """The number of the adult passengers on the flight."""
    22242281        return self._numPassengers.get_int()
     2282
     2283    @property
     2284    def numChildren(self):
     2285        """The number of the child passengers on the flight."""
     2286        return self._numChildren.get_int()
     2287
     2288    @property
     2289    def numInfants(self):
     2290        """The number of the infant passengers on the flight."""
     2291        return self._numInfants.get_int()
    22252292
    22262293    @property
     
    22432310        bookedFlight = self._wizard._bookedFlight
    22442311
    2245         self._numCrew.set_int(bookedFlight.numCrew)
    2246         self._numCrew.set_sensitive(True)
     2312        self._numCockpitCrew.set_markup("<b>" +
     2313                                        str(bookedFlight.numCockpitCrew) +
     2314                                        "</b>")
     2315        self._numCabinCrew.set_int(bookedFlight.numCabinCrew)
     2316        self._numCabinCrew.set_sensitive(True)
     2317
     2318
    22472319        self._numPassengers.set_int(bookedFlight.numPassengers)
    22482320        self._numPassengers.set_sensitive(True)
    22492321
     2322        self._numChildren.set_int(bookedFlight.numChildren)
     2323        self._numChildren.set_sensitive(True)
     2324
     2325        self._numInfants.set_int(bookedFlight.numInfants)
     2326        self._numInfants.set_sensitive(True)
     2327
    22502328        self._bagWeight.set_int(bookedFlight.bagWeight)
    22512329        self._bagWeight.set_sensitive(True)
    2252         self._cargoWeight.set_int(bookedFlight.cargoWeight)
    2253         self._cargoWeight.set_sensitive(True)
    2254         self._mailWeight.set_int(bookedFlight.mailWeight)
    2255         self._mailWeight.set_sensitive(True)
     2330
     2331        if bookedFlight.flightType==BookedFlight.FLIGHT_TYPE_CHARTER:
     2332            self._cargoWeight.set_int(0)
     2333            self._cargoWeight.set_sensitive(False)
     2334            self._mailWeight.set_int(0)
     2335            self._mailWeight.set_sensitive(False)
     2336        else:
     2337            self._cargoWeight.set_int(bookedFlight.cargoWeight)
     2338            self._cargoWeight.set_sensitive(True)
     2339            self._mailWeight.set_int(bookedFlight.mailWeight)
     2340            self._mailWeight.set_sensitive(True)
    22562341
    22572342        self._simulatorZFW.set_text("-")
     
    22622347    def finalize(self):
    22632348        """Finalize the payload page."""
    2264         self._numCrew.set_sensitive(False)
     2349        self._numCabinCrew.set_sensitive(False)
    22652350        self._numPassengers.set_sensitive(False)
     2351        self._numChildren.set_sensitive(False)
     2352        self._numInfants.set_sensitive(False)
    22662353        self._bagWeight.set_sensitive(False)
    22672354        self._cargoWeight.set_sensitive(False)
     
    22712358    def calculateZFW(self):
    22722359        """Calculate the ZFW value."""
    2273         zfw = self._wizard.gui._flight.aircraft.dow
    2274         zfw += (self._numCrew.get_int() + self._numPassengers.get_int()) * 82
     2360        bookedFlight = self._wizard._bookedFlight
     2361
     2362        zfw = bookedFlight.dow
     2363        zfw += (self._numCabinCrew.get_int() - bookedFlight.dowNumCabinCrew) *  \
     2364            const.WEIGHT_CABIN_CREW
     2365        zfw += self._numPassengers.get_int() * \
     2366            (const.WEIGHT_PASSENGER_CHARTER
     2367             if bookedFlight.flightType==BookedFlight.FLIGHT_TYPE_CHARTER
     2368             else const.WEIGHT_PASSENGER)
     2369        zfw += self._numChildren.get_int() * const.WEIGHT_CHILD
     2370        zfw += self._numInfants.get_int() * const.WEIGHT_INFANT
    22752371        zfw += self._bagWeight.get_int()
    22762372        zfw += self._cargoWeight.get_int()
     
    22912387
    22922388    def _weightChanged(self, entry, weight):
    2293         """Called when one of the weight values or humanm counts has changed."""
     2389        """Called when one of the weight values or humanm counts has
     2390        changed."""
     2391        bookedFlight = self._wizard._bookedFlight
     2392        numPassengers = \
     2393            self._numPassengers.get_int() + \
     2394            self._numChildren.get_int() + \
     2395            self._numInfants.get_int()
     2396        minCabinCrew = 0 if numPassengers==0 else \
     2397            (bookedFlight.maxPassengers // 50) + 1
     2398
     2399        extraHelp = []
     2400        enoughCrew = self._numCabinCrew.get_int() >= minCabinCrew
     2401        if enoughCrew:
     2402            self._crewLabel.set_text(xstr("payload_crew"))
     2403            self.setHelp(xstr("payload_help"))
     2404        else:
     2405            self._crewLabel.set_markup("<b><span foreground=\"red\">" +
     2406                                       xstr("payload_crew") +
     2407                                       "</span></b>")
     2408            extraHelp.append(xstr("payload_help_few_crew") % (minCabinCrew,))
     2409        self._crewLabel.set_use_underline(True)
     2410
     2411        tooManyPassengers = numPassengers>bookedFlight.maxPassengers
     2412        if tooManyPassengers:
     2413            self._paxLabel.set_markup("<b><span foreground=\"red\">" +
     2414                                      xstr("payload_pax") +
     2415                                      "</span></b>")
     2416            extraHelp.append(xstr("payload_help_many_pax") % (bookedFlight.maxPassengers,))
     2417        else:
     2418            self._paxLabel.set_text(xstr("payload_pax"))
     2419        self._paxLabel.set_use_underline(True)
     2420
     2421        hlp = xstr("payload_help") + "\n\n"
     2422        for eh in extraHelp:
     2423            hlp += "<b><span foreground=\"red\">" + eh + "</span></b>\n"
     2424        hlp += " \n" * (2-len(extraHelp))
     2425        self.setHelp(hlp)
     2426
     2427        self._button.set_sensitive(enoughCrew and not tooManyPassengers)
     2428
     2429
    22942430        self._updateCalculatedZFW()
    22952431
     
    55395675
    55405676    @property
    5541     def numCrew(self):
    5542         """Get the number of crew members."""
    5543         return self._payloadPage.numCrew
     5677    def numCockpitCrew(self):
     5678        """Get the number of cockpit crew members."""
     5679        return self._payloadPage.numCockpitCrew
     5680
     5681    @property
     5682    def numCabinCrew(self):
     5683        """Get the number of cabin crew members."""
     5684        return self._payloadPage.numCabinCrew
    55445685
    55455686    @property
     
    55475688        """Get the number of passengers."""
    55485689        return self._payloadPage.numPassengers
     5690
     5691    @property
     5692    def numChildren(self):
     5693        """Get the number of child passengers."""
     5694        return self._payloadPage.numChildren
     5695
     5696    @property
     5697    def numInfants(self):
     5698        """Get the number of infant passengers."""
     5699        return self._payloadPage.numInfants
    55495700
    55505701    @property
Note: See TracChangeset for help on using the changeset viewer.