Changeset 61:7deb4cf7dd78


Ignore:
Timestamp:
04/07/12 11:03:47 (13 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

The time page is implemented too.

Location:
src/mlx
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/fsuipc.py

    r59 r61  
    428428    via FSUIPC."""
    429429    # The basic data that should be queried all the time once we are connected
    430     normalData = [ (0x0240, "H"),            # Year
    431                    (0x023e, "H"),            # Number of day in year
    432                    (0x023b, "b"),            # UTC hour
    433                    (0x023c, "b"),            # UTC minute
    434                    (0x023a, "b"),            # seconds
    435                    (0x3d00, -256),           # The name of the current aircraft
     430    timeData = [ (0x0240, "H"),            # Year
     431                 (0x023e, "H"),            # Number of day in year
     432                 (0x023b, "b"),            # UTC hour
     433                 (0x023c, "b"),            # UTC minute
     434                 (0x023a, "b") ]           # seconds
     435   
     436    normalData = timeData + \
     437                 [ (0x3d00, -256),           # The name of the current aircraft
    436438                   (0x3c00, -256) ]          # The path of the current AIR file
    437439
     
    452454                   (0x057c, "d"),            # Bank
    453455                   (0x0580, "d") ]           # Heading
     456
     457    @staticmethod
     458    def _getTimestamp(data):
     459        """Convert the given data into a timestamp."""
     460        timestamp = calendar.timegm(time.struct_time([data[0],
     461                                                      1, 1, 0, 0, 0, -1, 1, 0]))
     462        timestamp += data[1] * 24 * 3600
     463        timestamp += data[2] * 3600
     464        timestamp += data[3] * 60
     465        timestamp += data[4]       
     466
     467        return timestamp
    454468
    455469    def __init__(self, connectionListener, connectAttempts = -1,
     
    516530        """Send a request for the ZFW."""
    517531        self._handler.requestRead([(0x3bfc, "d")], self._handleZFW, extra = callback)
     532
     533    def requestTime(self, callback):
     534        """Request the time from the simulator."""
     535        self._handler.requestRead(Simulator.timeData, self._handleTime,
     536                                  extra = callback)
    518537                                                           
    519538    def startMonitoring(self):
     
    583602        aircraft-specific values.
    584603        """
    585         timestamp = calendar.timegm(time.struct_time([data[0],
    586                                                       1, 1, 0, 0, 0, -1, 1, 0]))
    587         timestamp += data[1] * 24 * 3600
    588         timestamp += data[2] * 3600
    589         timestamp += data[3] * 60
    590         timestamp += data[4]       
     604        timestamp = Simulator._getTimestamp(data)
    591605
    592606        createdNewModel = self._setAircraftName(timestamp, data[5], data[6])
     
    719733        zfw = data[0] * const.LBSTOKG / 256.0
    720734        callback(zfw)
     735                                                 
     736    def _handleTime(self, data, callback):
     737        """Callback for a time retrieval request."""
     738        callback(Simulator._getTimestamp(data))
    721739                                                 
    722740#------------------------------------------------------------------------------
  • src/mlx/gui/flight.py

    r60 r61  
    66import mlx.fs as fs
    77from mlx.checks import PayloadChecker
     8
     9import datetime
     10import time
    811
    912#-----------------------------------------------------------------------------
     
    642645    def _zfwRequested(self, button):
    643646        """Called when the ZFW is requested from the simulator."""
     647        self._wizard.gui.beginBusy("Querying ZFW...")
    644648        self._wizard.gui.simulator.requestZFW(self._handleZFW)
    645649
     
    650654    def _processZFW(self, zfw):
    651655        """Process the given ZFW value received from the simulator."""
     656        self._wizard.gui.endBusy()
    652657        self._simulatorZFWValue = zfw
    653658        self._simulatorZFW.set_text("%.0f" % (zfw,))
     
    657662        """Called when the forward button is clicked."""
    658663        self._wizard._zfw = self._calculateZFW()
     664        self._wizard.nextPage()
     665       
     666#-----------------------------------------------------------------------------
     667
     668class TimePage(Page):
     669    """Page displaying the departure and arrival times and allows querying the
     670    current time from the flight simulator."""
     671    def __init__(self, wizard):
     672        help = "The departure and arrival times are displayed below in UTC.\n\n" \
     673               "You can also query the current UTC time from the simulator.\n" \
     674               "Ensure that you have enough time to properly prepare for the flight."
     675               
     676        super(TimePage, self).__init__(wizard, "Time", help)
     677
     678        alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
     679                                  xscale = 0.0, yscale = 0.0)
     680
     681        table = gtk.Table(3, 2)
     682        table.set_row_spacings(4)
     683        table.set_col_spacings(16)
     684        table.set_homogeneous(False)
     685        alignment.add(table)
     686        self.setMainWidget(alignment)
     687
     688        label = gtk.Label("Departure:")
     689        label.set_alignment(0.0, 0.5)
     690        table.attach(label, 0, 1, 0, 1)
     691
     692        self._departure = gtk.Label()
     693        self._departure.set_alignment(0.0, 0.5)
     694        table.attach(self._departure, 1, 2, 0, 1)
     695       
     696        label = gtk.Label("Arrival:")
     697        label.set_alignment(0.0, 0.5)
     698        table.attach(label, 0, 1, 1, 2)
     699
     700        self._arrival = gtk.Label()
     701        self._arrival.set_alignment(0.0, 0.5)
     702        table.attach(self._arrival, 1, 2, 1, 2)
     703
     704        button = gtk.Button("_Time from FS:")
     705        button.set_use_underline(True)
     706        button.connect("clicked", self._timeRequested)
     707        table.attach(button, 0, 1, 2, 3)
     708
     709        self._simulatorTime = gtk.Label("-")
     710        self._simulatorTime.set_alignment(0.0, 0.5)
     711        table.attach(self._simulatorTime, 1, 2, 2, 3)
     712
     713        self._button = self.addButton(gtk.STOCK_GO_FORWARD, default = True)
     714        self._button.set_use_stock(True)
     715        self._button.connect("clicked", self._forwardClicked)
     716
     717    def activate(self):
     718        """Activate the page."""
     719        bookedFlight = self._wizard._bookedFlight
     720        self._departure.set_text(str(bookedFlight.departureTime.time()))
     721        self._arrival.set_text(str(bookedFlight.arrivalTime.time()))
     722
     723    def _timeRequested(self, button):
     724        """Request the time from the simulator."""
     725        self._wizard.gui.beginBusy("Querying time...")
     726        self._wizard.gui.simulator.requestTime(self._handleTime)
     727
     728    def _handleTime(self, timestamp):
     729        """Handle the result of a time retrieval."""
     730        gobject.idle_add(self._processTime, timestamp)
     731
     732    def _processTime(self, timestamp):
     733        """Process the given time."""
     734        self._wizard.gui.endBusy()
     735        tm = time.gmtime(timestamp)
     736        t = datetime.time(tm.tm_hour, tm.tm_min, tm.tm_sec)
     737        self._simulatorTime.set_text(str(t))
     738
     739        ts = tm.tm_hour * 3600 + tm.tm_min * 60 + tm.tm_sec
     740        dt = self._wizard._bookedFlight.departureTime.time()
     741        dts = dt.hour * 3600 + dt.minute * 60 + dt.second
     742        diff = dts-ts
     743
     744        markupBegin = ""
     745        markupEnd = ""
     746        if diff < 0:
     747            markupBegin = '<b><span foreground="red">'
     748            markupEnd = '</span></b>'
     749        elif diff < 3*60 or diff > 30*60:
     750            markupBegin = '<b><span foreground="orange">'
     751            markupEnd = '</span></b>'
     752
     753        self._departure.set_markup(markupBegin + str(dt) + markupEnd)
     754
     755    def _forwardClicked(self, button):
     756        """Called when the forward button is clicked."""
    659757        self._wizard.nextPage()
    660758       
     
    677775        self._pages.append(ConnectPage(self))
    678776        self._pages.append(PayloadPage(self))
     777        self._pages.append(TimePage(self))
    679778
    680779        maxWidth = 0
  • src/mlx/pyuipc_sim.py

    r59 r61  
    668668def read(data):
    669669    """Read the given data."""
    670     print "opened", opened
    671670    if opened:
    672671        return [values.read(offset) for (offset, type) in data]
Note: See TracChangeset for help on using the changeset viewer.