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

The time page is implemented too.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.