Changeset 1173:6611a47528bb for src/mlx


Ignore:
Timestamp:
10/20/24 13:00:41 (2 days ago)
Author:
István Váradi <ivaradi@…>
Branch:
python3
Phase:
public
Message:

Offline flight-specific login result with fleet and gate data read from local JSON files (re #391)

File:
1 edited

Legend:

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

    r1168 r1173  
    442442        """Called when the offline button was clicked."""
    443443        print("mlx.flight.LoginPage: offline flight selected")
     444        self._wizard.setupOfflineFlight()
    444445        self._wizard.nextPage()
    445446
     
    68196820        self.gui.webHandler.login(self._loginResultCallback,
    68206821                                  pilotID, password)
     6822
     6823    def setupOfflineFlight(self):
     6824        """Setup an offline flight."""
     6825        #import pickle
     6826        import random
     6827        import json
     6828        from mlx.rpccommon import Fleet
     6829        from mlx.gates import Gates
     6830
     6831        # with open(os.path.join(self.gui.programDirectory,
     6832        #                        "fleet.pickle"), "rb") as f:
     6833        #     fleet = pickle.load(f)
     6834        # with open(os.path.join(self.gui.programDirectory,
     6835        #                        "fleet.json"), "wt") as f:
     6836        #     json.dump(fleet.toJSON(), f, sort_keys = True, indent = 4)
     6837        with open(os.path.join(self.gui.programDirectory,
     6838                               "fleet.json"), "rt") as f:
     6839            fleet = Fleet.fromJSON(json.load(f))
     6840        # with open(os.path.join(self.gui.programDirectory,
     6841        #                        "fleet1.json"), "wt") as f:
     6842        #     json.dump(fleet.toJSON(), f, sort_keys = True, indent = 4)
     6843
     6844        # with open(os.path.join(self.gui.programDirectory,
     6845        #                        "gates.pickle"), "rb") as f:
     6846        #     gates = pickle.load(f)
     6847        # with open(os.path.join(self.gui.programDirectory,
     6848        #                        "gates.json"), "wt") as f:
     6849        #     json.dump(gates.toJSON(), f, sort_keys = True, indent = 4)
     6850        with open(os.path.join(self.gui.programDirectory,
     6851                               "gates.json"), "rt") as f:
     6852            gates = Gates.fromJSON(json.load(f))
     6853        # with open(os.path.join(self.gui.programDirectory,
     6854        #                        "gates1.json"), "wt") as f:
     6855        #     json.dump(gates.toJSON(), f, sort_keys = True, indent = 4)
     6856
     6857        class OfflineLoginResult:
     6858            def __init__(self, fleet, gates, gui):
     6859                self.loggedIn = False
     6860                if gui.config and gui.config.pilotID:
     6861                    self.pilotID = gui.config.pilotID
     6862                else:
     6863                    self.pilotID = "P999"
     6864                self.pilotName = "Joe Captain"
     6865                self.fleet = fleet
     6866                self.gates = gates
     6867                self.reportedFlights = []
     6868                self.rejectedFlights = []
     6869                self.flights = []
     6870                self.sessionID = "".join(random.choices("0123456789", k = 16))
     6871        self._loginResult = OfflineLoginResult(fleet, gates, self.gui)
    68216872
    68226873    def reloadFlights(self, callback):
Note: See TracChangeset for help on using the changeset viewer.