Ignore:
Timestamp:
04/07/12 08:48:34 (12 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

Implemented better connection and connection failure handling.

File:
1 edited

Legend:

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

    r58 r59  
    494494#-----------------------------------------------------------------------------
    495495
     496class PayloadPage(Page):
     497    """Page to allow setting up the payload."""
     498    def __init__(self, wizard):
     499        """Construct the page."""
     500        help = "The briefing contains the weights below.\n" \
     501               "Setup the cargo weight and check if the simulator\n" \
     502               "reports the expected Zero Fuel Weight."
     503        super(PayloadPage, self).__init__(wizard, "Payload", help)
     504
     505        button = gtk.Button("_Query ZFW")
     506        button.connect("clicked", self._zfwRequested)
     507        self.setMainWidget(button)
     508
     509    def _zfwRequested(self, button):
     510        """Called when the ZFW is requested from the simulator."""
     511        self._wizard.gui.simulator.requestZFW(self._handleZFW)
     512
     513    def _handleZFW(self, zfw):
     514        """Called when the ZFW value is retrieved."""
     515        print "ZFW", zfw
     516
     517#-----------------------------------------------------------------------------
     518
    496519class Wizard(gtk.VBox):
    497520    """The flight wizard."""
     
    509532        self._pages.append(GateSelectionPage(self))
    510533        self._pages.append(ConnectPage(self))
     534        self._pages.append(PayloadPage(self))
    511535
    512536        maxWidth = 0
     
    523547        self.set_size_request(maxWidth, maxHeight)
    524548
    525         self._fleet = None
    526         self._fleetCallback = None
    527         self._updatePlaneCallback = None
    528        
    529         self._loginResult = None
    530         self._bookedFlight = None
    531         self._departureGate = "-"
    532 
    533         self._logger = Logger(output = gui)
    534         self._flight = None
    535         self._simulator = None
    536        
    537         self.setCurrentPage(0)
     549        self._initialize()
    538550       
    539551    @property
     
    567579        self._pages[self._currentPage].grabDefault()
    568580
     581    def connected(self, fsType, descriptor):
     582        """Called when the connection could be made to the simulator."""
     583        self.nextPage()
     584
     585    def connectionFailed(self):
     586        """Called when the connection could not be made to the simulator."""
     587        self._initialize()
     588
     589    def disconnected(self):
     590        """Called when we have disconnected from the simulator."""
     591        self._initialize()
     592
     593    def _initialize(self):
     594        """Initialize the wizard."""
     595        self._fleet = None
     596        self._fleetCallback = None
     597        self._updatePlaneCallback = None
     598       
     599        self._loginResult = None
     600        self._bookedFlight = None
     601        self._departureGate = "-"
     602
     603        self.setCurrentPage(0)
     604       
    569605    def _getFleet(self, callback, force = False):
    570606        """Get the fleet, if needed.
     
    634670    def _connectSimulator(self):
    635671        """Connect to the simulator."""
    636         self._logger.reset()
    637         self._flight = Flight(self.gui._logger, self.gui)
    638 
    639         self._flight.aircraftType = self._bookedFlight.aircraftType
    640         aircraft = self._flight.aircraft = Aircraft.create(self._flight)
    641         self._flight.aircraft._checkers.append(self.gui)
    642        
    643         self._flight.cruiseAltitude = -1       
    644         self._flight.zfw = -1
    645 
    646         if self._simulator is None:
    647             self._simulator = fs.createSimulator(const.SIM_MSFS9, self.gui)
    648 
    649         self._flight.simulator = self._simulator
    650         self._simulator.connect(aircraft)
    651         #self._simulator.startMonitoring()
     672        self.gui.connectSimulator(self._bookedFlight.aircraftType)
    652673   
    653674#-----------------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.