Ignore:
Timestamp:
02/01/14 09:18:39 (11 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

The departure and arrival times are displayed on the finish page and if one of the differences is greater than 15 minutes, the PIREP cannot be saved or sent unless a delay code or a comment is provided (re #224)

Location:
src/mlx/gui
Files:
4 edited

Legend:

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

    r439 r555  
    233233class DelayCodeTable(DelayCodeTableBase):
    234234    """The delay code table."""
    235     def __init__(self):
     235    def __init__(self, info):
    236236        """Construct the delay code table."""
    237237        super(DelayCodeTable, self).__init__()
     238
     239        self._info = info
    238240
    239241        self._delayCodeData = None
     
    271273
    272274        return codes
     275
     276    @property
     277    def hasDelayCode(self):
     278        """Determine if there is at least one delay code selected."""
     279        if self._delayCodeData is not None:
     280            for checkButton in self._checkButtons:
     281                if checkButton.get_active():
     282                    return True
     283
     284        return False
    273285
    274286    def allocate_column_sizes(self, allocation):
     
    332344            elif type==DELAYCODE:
    333345                checkButton = CheckButton(elements)
     346                checkButton.connect("toggled", self._delayCodesChanged)
    334347                self._checkButtons.append(checkButton)
    335348                alignment = Alignment(xalign = 0.5, yalign = 0.5, xscale = 1.0)
     
    366379        self.show_all()
    367380
    368 #------------------------------------------------------------------------------
     381    def _delayCodesChanged(self, button):
     382        """Called when one of the delay codes have changed."""
     383        self._info.delayCodesChanged()
     384
     385#------------------------------------------------------------------------------
  • src/mlx/gui/flight.py

    r554 r555  
    28212821        self.setMainWidget(alignment)
    28222822
     2823        row = 0
     2824
    28232825        labelAlignment = gtk.Alignment(xalign=1.0, xscale=0.0)
    28242826        label = gtk.Label(xstr("finish_rating"))
    28252827        labelAlignment.add(label)
    2826         table.attach(labelAlignment, 0, 1, 0, 1)
     2828        table.attach(labelAlignment, 0, 1, row, row+1)
    28272829
    28282830        labelAlignment = gtk.Alignment(xalign=0.0, xscale=0.0)
     
    28322834        self._flightRating.set_use_markup(True)
    28332835        labelAlignment.add(self._flightRating)
    2834         table.attach(labelAlignment, 1, 2, 0, 1)
     2836        table.attach(labelAlignment, 1, 2, row, row+1)
     2837
     2838        row += 1
     2839
     2840        labelAlignment = gtk.Alignment(xalign=1.0, xscale=0.0)
     2841        label = gtk.Label(xstr("finish_dep_time"))
     2842        labelAlignment.add(label)
     2843        table.attach(labelAlignment, 0, 1, row, row+1)
     2844
     2845        labelAlignment = gtk.Alignment(xalign=0.0, xscale=0.0)
     2846        self._depTime = gtk.Label()
     2847        self._depTime.set_width_chars(10)
     2848        self._depTime.set_alignment(0.0, 0.5)
     2849        self._depTime.set_use_markup(True)
     2850        labelAlignment.add(self._depTime)
     2851        table.attach(labelAlignment, 1, 2, row, row+1)
     2852
     2853        row += 1
    28352854
    28362855        labelAlignment = gtk.Alignment(xalign=1.0, xscale=0.0)
    28372856        label = gtk.Label(xstr("finish_flight_time"))
    28382857        labelAlignment.add(label)
    2839         table.attach(labelAlignment, 0, 1, 1, 2)
     2858        table.attach(labelAlignment, 0, 1, row, row+1)
    28402859
    28412860        labelAlignment = gtk.Alignment(xalign=0.0, xscale=0.0)
     
    28452864        self._flightTime.set_use_markup(True)
    28462865        labelAlignment.add(self._flightTime)
    2847         table.attach(labelAlignment, 1, 2, 1, 2)
     2866        table.attach(labelAlignment, 1, 2, row, row+1)
     2867
     2868        row += 1
    28482869
    28492870        labelAlignment = gtk.Alignment(xalign=1.0, xscale=0.0)
    28502871        label = gtk.Label(xstr("finish_block_time"))
    28512872        labelAlignment.add(label)
    2852         table.attach(labelAlignment, 0, 1, 2, 3)
     2873        table.attach(labelAlignment, 0, 1, row, row+1)
    28532874
    28542875        labelAlignment = gtk.Alignment(xalign=0.0, xscale=0.0)
     
    28582879        self._blockTime.set_use_markup(True)
    28592880        labelAlignment.add(self._blockTime)
    2860         table.attach(labelAlignment, 1, 2, 2, 3)
     2881        table.attach(labelAlignment, 1, 2, row, row+1)
     2882
     2883        row += 1
     2884
     2885        labelAlignment = gtk.Alignment(xalign=1.0, xscale=0.0)
     2886        label = gtk.Label(xstr("finish_arr_time"))
     2887        labelAlignment.add(label)
     2888        table.attach(labelAlignment, 0, 1, row, row+1)
     2889
     2890        labelAlignment = gtk.Alignment(xalign=0.0, xscale=0.0)
     2891        self._arrTime = gtk.Label()
     2892        self._arrTime.set_width_chars(10)
     2893        self._arrTime.set_alignment(0.0, 0.5)
     2894        self._arrTime.set_use_markup(True)
     2895        labelAlignment.add(self._arrTime)
     2896        table.attach(labelAlignment, 1, 2, row, row+1)
     2897
     2898        row += 1
    28612899
    28622900        labelAlignment = gtk.Alignment(xalign=1.0, xscale=0.0)
    28632901        label = gtk.Label(xstr("finish_distance"))
    28642902        labelAlignment.add(label)
    2865         table.attach(labelAlignment, 0, 1, 3, 4)
     2903        table.attach(labelAlignment, 0, 1, row, row+1)
    28662904
    28672905        labelAlignment = gtk.Alignment(xalign=0.0, xscale=0.0)
     
    28712909        self._distanceFlown.set_use_markup(True)
    28722910        labelAlignment.add(self._distanceFlown)
    2873         table.attach(labelAlignment, 1, 2, 3, 4)
     2911        table.attach(labelAlignment, 1, 2, row, row+1)
     2912
     2913        row += 1
    28742914
    28752915        labelAlignment = gtk.Alignment(xalign=1.0, xscale=0.0)
    28762916        label = gtk.Label(xstr("finish_fuel"))
    28772917        labelAlignment.add(label)
    2878         table.attach(labelAlignment, 0, 1, 4, 5)
     2918        table.attach(labelAlignment, 0, 1, row, row+1)
    28792919
    28802920        labelAlignment = gtk.Alignment(xalign=0.0, xscale=0.0)
     
    28842924        self._fuelUsed.set_use_markup(True)
    28852925        labelAlignment.add(self._fuelUsed)
    2886         table.attach(labelAlignment, 1, 2, 4, 5)
     2926        table.attach(labelAlignment, 1, 2, row, row+1)
     2927
     2928        row += 1
    28872929
    28882930        labelAlignment = gtk.Alignment(xalign = 1.0, xscale = 0.0,
     
    28912933        label.set_use_underline(True)
    28922934        labelAlignment.add(label)
    2893         table.attach(labelAlignment, 0, 1, 5, 6)
     2935        table.attach(labelAlignment, 0, 1, row, row+1)
    28942936
    28952937        flightTypeModel = gtk.ListStore(str, int)
     
    29062948        flightTypeAlignment = gtk.Alignment(xalign=0.0, xscale=0.0)
    29072949        flightTypeAlignment.add(self._flightType)
    2908         table.attach(flightTypeAlignment, 1, 2, 5, 6)
     2950        table.attach(flightTypeAlignment, 1, 2, row, row+1)
    29092951        label.set_mnemonic_widget(self._flightType)
     2952
     2953        row += 1
    29102954
    29112955        self._onlineFlight = gtk.CheckButton(xstr("finish_online"))
     
    29142958        onlineFlightAlignment = gtk.Alignment(xalign=0.0, xscale=0.0)
    29152959        onlineFlightAlignment.add(self._onlineFlight)
    2916         table.attach(onlineFlightAlignment, 1, 2, 6, 7)
     2960        table.attach(onlineFlightAlignment, 1, 2, row, row + 1)
     2961
     2962        row += 1
    29172963
    29182964        labelAlignment = gtk.Alignment(xalign = 1.0, xscale = 0.0,
     
    29212967        self._gateLabel.set_use_underline(True)
    29222968        labelAlignment.add(self._gateLabel)
    2923         table.attach(labelAlignment, 0, 1, 7, 8)
     2969        table.attach(labelAlignment, 0, 1, row, row+1)
    29242970
    29252971        self._gatesModel = gtk.ListStore(str)
     
    29332979        gateAlignment = gtk.Alignment(xalign=0.0, xscale=1.0)
    29342980        gateAlignment.add(self._gate)
    2935         table.attach(gateAlignment, 1, 2, 7, 8)
     2981        table.attach(gateAlignment, 1, 2, row, row+1)
    29362982        self._gateLabel.set_mnemonic_widget(self._gate)
    29372983
     
    29512997        self._lastSavePath = None
    29522998
     2999        self._tooBigTimeDifference = False
     3000        self._deferredAutoSave = False
    29533001        self._pirepSaved = False
    29543002        self._pirepSent = False
     
    29593007                                          tooltip = xstr("sendPIREP_tooltip"))
    29603008
     3009        # self._formatTime(datetime.datetime(1970, 1, 1, 0, 10), 10*60.0)
     3010        # self._formatTime(datetime.datetime(1970, 1, 1, 0, 10), 20*60.0)
     3011        # self._formatTime(datetime.datetime(1970, 1, 1, 0, 10), 0*60.0)
     3012        # self._formatTime(datetime.datetime(1970, 1, 1, 0, 10), (23*60.0+50)*60.0)
     3013        # self._formatTime(datetime.datetime(1970, 1, 1, 1, 0), (1*60.0+5)*60.0)
     3014        # self._formatTime(datetime.datetime(1970, 1, 1, 1, 0), (0*60.0+50)*60.0)
     3015        # self._formatTime(datetime.datetime(1970, 1, 1, 23, 55), (0*60.0+5)*60.0)
     3016        # self._formatTime(datetime.datetime(1970, 1, 1, 23, 55), (23*60.0+45)*60.0)
     3017
    29613018    @property
    29623019    def flightType(self):
     
    29723029    def activate(self):
    29733030        """Activate the page."""
     3031        self._deferredAutoSave = False
    29743032        self._pirepSaved = False
    29753033        self._pirepSent = False
     
    29823040            self._flightRating.set_markup("<b>%.1f %%</b>" % (rating,))
    29833041
     3042        bookedFlight = self._wizard.bookedFlight
     3043
     3044        (markup, tooBigDeparture) = \
     3045            self._formatTime(bookedFlight.departureTime, flight.blockTimeStart)
     3046
     3047        self._depTime.set_markup(markup)
     3048
    29843049        flightLength = flight.flightTimeEnd - flight.flightTimeStart
    29853050        self._flightTime.set_markup("<b>%s</b>" % \
     
    29893054        self._blockTime.set_markup("<b>%s</b>" % \
    29903055                                   (util.getTimeIntervalString(blockLength),))
     3056
     3057        (markup, tooBigArrival) = \
     3058            self._formatTime(bookedFlight.arrivalTime, flight.blockTimeEnd)
     3059
     3060        self._tooBigTimeDifference = tooBigDeparture or tooBigArrival
     3061
     3062        self._arrTime.set_markup(markup)
    29913063
    29923064        self._distanceFlown.set_markup("<b>%.2f NM</b>" % \
     
    30153087            self._gate.set_sensitive(False)
    30163088
     3089        self.updateButtons()
     3090
     3091    def updateButtons(self):
     3092        """Update the sensitivity state of the buttons."""
     3093        gui = self._wizard.gui
     3094        sensitive = self._flightType.get_active()>=0 and \
     3095                    (self._gatesModel.get_iter_first() is None or
     3096                     self._gate.get_active()>=0) and \
     3097                    (not self._tooBigTimeDifference or
     3098                     gui.hasComments or gui.hasDelayCode)
     3099
     3100        wasSensitive = self._saveButton.get_sensitive()
     3101
     3102        if gui.config.pirepAutoSave and sensitive and not wasSensitive:
     3103            if gui.isWizardActive():
     3104                self._autoSavePIREP()
     3105            else:
     3106                self._deferredAutoSave = True
     3107
     3108        if not sensitive:
     3109            self._deferredAutoSave = False
     3110
     3111        self._saveButton.set_sensitive(sensitive)
     3112        self._sendButton.set_sensitive(sensitive and
     3113                                       self._wizard.bookedFlight.id is not None)
     3114
     3115    def grabDefault(self):
     3116        """If the page has a default button, make it the default one."""
     3117        super(FinishPage, self).grabDefault()
     3118        if self._deferredAutoSave:
     3119            self._autoSavePIREP()
     3120            self._deferredAutoSave = False
     3121
     3122    def _autoSavePIREP(self):
     3123        """Perform the automatic saving of the PIREP."""
     3124        self._lastSavePath = os.path.join(self._wizard.gui.config.pirepDirectory,
     3125                                          self._getDefaultPIREPName())
     3126        self._lastSavePath = text2unicode(self._lastSavePath)
     3127        self._savePIREP(automatic = True)
     3128
    30173129    def _backClicked(self, button):
    30183130        """Called when the Back button is pressed."""
    30193131        self.goBack()
    30203132
    3021     def _updateButtons(self):
    3022         """Update the sensitivity state of the buttons."""
    3023         sensitive = self._flightType.get_active()>=0 and \
    3024                     (self._gatesModel.get_iter_first() is None or
    3025                      self._gate.get_active()>=0)
    3026 
    3027         wasSensitive = self._saveButton.get_sensitive()
    3028 
    3029         gui = self._wizard.gui
    3030         config = gui.config
    3031         if config.pirepAutoSave and sensitive and not wasSensitive:
    3032             self._lastSavePath = os.path.join(config.pirepDirectory,
    3033                                               self._getDefaultPIREPName())
    3034             self._lastSavePath = text2unicode(self._lastSavePath)
    3035             self._savePIREP(automatic = True)
    3036 
    3037         self._saveButton.set_sensitive(sensitive)
    3038         self._sendButton.set_sensitive(sensitive and
    3039                                        self._wizard.bookedFlight.id is not None)
    3040 
    30413133    def _flightTypeChanged(self, comboBox):
    30423134        """Called when the flight type has changed."""
    3043         self._updateButtons()
     3135        self.updateButtons()
    30443136
    30453137    def _gateChanged(self, comboBox):
    30463138        """Called when the arrival gate has changed."""
    3047         self._updateButtons()
     3139        self.updateButtons()
    30483140
    30493141    def _newFlightClicked(self, button):
     
    32033295        """Callback for the plane updating."""
    32043296        pass
     3297
     3298    def _formatTime(self, scheduledTime, realTimestamp):
     3299        """Format the departure or arrival time based on the given data as a
     3300        markup for a label.
     3301
     3302        If the difference is greater than 15 minutes, the text should be
     3303        red. Otherwise, if the difference is greater that 5 minutes, the text
     3304        should be yellow. Otherwise it should be black.
     3305
     3306        scheduledTime is the scheduled time as a datetime object
     3307        realTimestamp is the real time as a timestamp (i.e. seconds
     3308        since the epoch)
     3309
     3310        Returns a tuple consisting of:
     3311        - the markup,
     3312        - a boolean indicating if the difference is greater than 15 minutes."""
     3313        realTime = time.gmtime(realTimestamp)
     3314
     3315        scheduledMinute = scheduledTime.hour * 60 + scheduledTime.minute
     3316        realMinute = realTime.tm_hour * 60 + realTime.tm_min
     3317
     3318        diff1 = scheduledMinute - realMinute
     3319        diff2 = -1 * diff1
     3320
     3321        if diff1 < 0: diff1 += 60*24
     3322        else: diff2 += 60*24
     3323
     3324        diff = min(diff1, diff2)
     3325
     3326        if diff>5:
     3327            colour = "red" if diff>15 else "orange"
     3328            markupBegin = '<span foreground="%s">' % (colour,)
     3329            markupEnd = '</span>'
     3330        else:
     3331            markupBegin = markupEnd = ""
     3332
     3333        markup = "<b>%s%02d:%02d [%02d:%02d]%s</b>" % \
     3334                 (markupBegin,
     3335                  realTime.tm_hour, realTime.tm_min,
     3336                  scheduledTime.hour, scheduledTime.minute,
     3337                  markupEnd)
     3338
     3339        # print "mlx.gui.flight.FinishPage._formatTime: markup='%s', diff=%d" % \
     3340        #       (markup, diff)
     3341
     3342        return (markup, diff>15)
    32053343
    32063344#-----------------------------------------------------------------------------
     
    35633701        """Handle the login result."""
    35643702        self.gui.endBusy()
     3703        returned = True
     3704        result.pilotID = "P096"
     3705        result.password = "V5fwj"
     3706        result.loggedIn = True
     3707        result.flights = []
    35653708        isReload = self._loginResult is not None
    35663709        if returned:
     
    36343777        self._takeoffPage.setRTOEnabled(rtoEnabled)
    36353778
     3779    def commentsChanged(self):
     3780        """Called when the comments have changed."""
     3781        self.updateRTO()
     3782        self._finishPage.updateButtons()
     3783
     3784    def delayCodesChanged(self):
     3785        """Called when the delay codes have changed."""
     3786        self._finishPage.updateButtons()
     3787
    36363788    def rtoToggled(self, indicated):
    36373789        """Called when the RTO indication has changed."""
  • src/mlx/gui/gui.py

    r501 r555  
    403403        return self._flightInfo.delayCodes
    404404
     405    @property
     406    def hasDelayCode(self):
     407        """Determine if there is at least one delay code selected."""
     408        return self._flightInfo.hasDelayCode
     409
    405410    def run(self):
    406411        """Run the GUI."""
     
    782787        else:
    783788            callback(self._fleet)
     789
     790    def commentsChanged(self):
     791        """Indicate that the comments have changed."""
     792        self._wizard.commentsChanged()
     793
     794    def delayCodesChanged(self):
     795        """Called when the delay codes have changed."""
     796        self._wizard.delayCodesChanged()
    784797
    785798    def updateRTO(self, inLoop = False):
     
    11331146        else:
    11341147            self._mainWindow.set_default(None)
     1148
     1149    def isWizardActive(self):
     1150        """Determine if the flight wizard is active."""
     1151        return self._notebook.get_current_page()==0
    11351152
    11361153    def _editChecklist(self, menuItem):
  • src/mlx/gui/info.py

    r441 r555  
    8282                              padding_left = 8, padding_right = 8)
    8383
    84         self._delayCodeTable = table = DelayCodeTable()
     84        self._delayCodeTable = table = DelayCodeTable(self)
    8585        self._delayWindow = scrolledWindow = gtk.ScrolledWindow()
    8686        scrolledWindow.add(table)
     
    124124        return self._delayCodeTable.delayCodes
    125125
     126    @property
     127    def hasDelayCode(self):
     128        """Determine if there is at least one delay code selected."""
     129        return self._delayCodeTable.hasDelayCode
     130
    126131    def enable(self, aircraftType):
    127132        """Enable the flight info tab."""
     
    145150        self._delayCodeTable.reset()
    146151
     152    def delayCodesChanged(self):
     153        """Callewd when the delay codes have changed."""
     154        self._gui.delayCodesChanged()
     155
    147156    def _commentsChanged(self, textbuffer):
    148157        """Called when the comments have changed."""
    149         self._gui.updateRTO(inLoop = True)
     158        self._gui.commentsChanged()
Note: See TracChangeset for help on using the changeset viewer.