Changeset 846:d11ea8564da8 for src/mlx


Ignore:
Timestamp:
05/10/17 17:41:17 (8 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

The values are checked and the OK button is updated accordingly (re #307)

Location:
src/mlx
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/flight.py

    r635 r846  
    4040
    4141    @staticmethod
     42    def getMinutesDifference(minutes1, minutes2):
     43        """Get the difference in minutes between the given two time
     44        instances."""
     45        diff1 = minutes1 - minutes2
     46        diff2 = -1 * diff1
     47
     48        if diff1 < 0: diff1 += 60*24
     49        else: diff2 += 60*24
     50
     51        diff = min(diff1, diff2)
     52
     53        return -1*diff if diff2<diff1 else diff
     54
     55    @staticmethod
    4256    def isTimeDifferenceTooMuch(scheduledTime, realTimestamp):
    4357        """Determine if the given real time differs to much from the scheduled
     
    5468        realMinute = realTime.tm_hour * 60 + realTime.tm_min
    5569
    56         diff1 = scheduledMinute - realMinute
    57         diff2 = -1 * diff1
    58 
    59         if diff1 < 0: diff1 += 60*24
    60         else: diff2 += 60*24
    61 
    62         diff = min(diff1, diff2)
     70        diff = abs(Flight.getMinutesDifference(scheduledMinute, realMinute))
    6371
    6472        return (diff>Flight.TIME_WARNING_DIFFERENCE,
  • src/mlx/gui/common.py

    r837 r846  
    326326        else:
    327327            return 0
     328
     329    @property
     330    def minutes(self):
     331        """Get the time in minutes, i.e. hour*60+minute."""
     332        return self.hour * 60 + self.minute
    328333
    329334    def setTimestamp(self, timestamp):
  • src/mlx/gui/info.py

    r844 r846  
    5454        return (frame, comments)
    5555
    56     def __init__(self, gui, mainInstance = True):
     56    def __init__(self, gui, callbackObject = None):
    5757        """Construct the flight info tab."""
    5858        super(FlightInfo, self).__init__()
    5959        self._gui = gui
    60         self._mainInstance = mainInstance
     60        self._callbackObject = callbackObject
    6161
    6262        self._commentsAlignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
     
    184184    def delayCodesChanged(self):
    185185        """Callewd when the delay codes have changed."""
    186         if self._mainInstance:
     186        if self._callbackObject is None:
    187187            self._gui.delayCodesChanged()
     188        else:
     189            self._callbackObject.delayCodesChanged()
    188190
    189191    def _commentsChanged(self, textbuffer):
    190192        """Called when the comments have changed."""
    191         if self._mainInstance:
     193        if self._callbackObject is None:
    192194            self._gui.commentsChanged()
     195        else:
     196            self._callbackObject.commentsChanged()
    193197
    194198    def _faultExplanationsChanged(self, faultExplainWidget, fullyExplained):
    195199        """Called when the status of the fault explanations has changed."""
    196         if self._mainInstance:
     200        if self._callbackObject is None:
    197201            self._gui.faultExplanationsChanged()
     202        else:
     203            self._callbackObject.faultExplanationsChanged()
  • src/mlx/gui/pirep.py

    r845 r846  
    66
    77from mlx.pirep import PIREP
     8from mlx.flight import Flight
    89from mlx.const import *
    910
     
    692693        self._gui = gui
    693694
     695        self._pirep = None
     696
    694697        contentArea = self.get_content_area()
    695698
     
    715718        self._notebook.append_page(logTab, label)
    716719
     720        self.add_button(xstr("button_cancel"), RESPONSETYPE_CANCEL)
     721
    717722        self._okButton = self.add_button(xstr("button_ok"), RESPONSETYPE_OK)
    718723        self._okButton.set_can_default(True)
     
    720725    def setPIREP(self, pirep):
    721726        """Setup the data in the dialog from the given PIREP."""
     727        self._pirep = pirep
     728
    722729        bookedFlight = pirep.bookedFlight
    723730
     
    835842        self._okButton.grab_default()
    836843
     844        self._updateButtons()
     845
     846    def delayCodesChanged(self):
     847        """Called when the delay codes have changed."""
     848        self._updateButtons()
     849
     850    def commentsChanged(self):
     851        """Called when the comments have changed."""
     852        self._updateButtons()
     853
     854    def faultExplanationsChanged(self):
     855        """Called when the fault explanations have changed."""
     856        self._updateButtons()
     857
    837858    def _buildDataTab(self):
    838859        """Build the data tab of the viewer."""
     
    932953                                    xstr("pirepView_numPassengers"),
    933954                                    width = 4)
    934 
    935955        self._numCrew = \
    936956            PIREPViewer.tableAttach(table, 1, 0,
     
    9811001        #self._filedCruiseLevel.set_tooltip_text(xstr("route_level_tooltip"))
    9821002        self._filedCruiseLevel.set_numeric(True)
     1003        self._filedCruiseLevel.connect("value-changed", self._updateButtons)
    9831004
    9841005        levelBox.pack_start(self._filedCruiseLevel, False, False, 0)
     
    9951016        #self._modifiedCruiseLevel.set_tooltip_text(xstr("route_level_tooltip"))
    9961017        self._modifiedCruiseLevel.set_numeric(True)
     1018        self._modifiedCruiseLevel.connect("value-changed", self._updateButtons)
    9971019
    9981020        levelBox.pack_start(self._modifiedCruiseLevel, False, False, 0)
     
    10031025          PIREPViewer.getTextWindow(editable = True)
    10041026        mainBox.pack_start(routeWindow, False, False, 0)
     1027        self._userRoute.get_buffer().connect("changed", self._updateButtons)
    10051028
    10061029        return frame
     
    10151038            PIREPViewer.getTextWindow(heightRequest = -1,
    10161039                                      editable = True)
     1040        self._departureMETAR.get_buffer().connect("changed", self._updateButtons)
    10171041        mainBox.pack_start(metarWindow, True, True, 0)
    10181042
     
    10621086            PIREPViewer.getTextWindow(heightRequest = -1,
    10631087                                      editable = True)
     1088        self._arrivalMETAR.get_buffer().connect("changed", self._updateButtons)
    10641089        mainBox.pack_start(metarWindow, True, True, 0)
    10651090
     
    11371162            PIREPEditor.tableAttachTimeEntry(table, 0, 0,
    11381163                                             xstr("pirepView_blockTimeStart"))
     1164        self._blockTimeStart.connect("changed", self._updateButtons)
    11391165
    11401166        self._blockTimeEnd = \
    11411167            PIREPEditor.tableAttachTimeEntry(table, 2, 0,
    11421168                                             xstr("pirepView_blockTimeEnd"))
     1169        self._blockTimeEnd.connect("changed", self._updateButtons)
    11431170
    11441171        self._flightTimeStart = \
    11451172            PIREPEditor.tableAttachTimeEntry(table, 0, 1,
    11461173                                             xstr("pirepView_flightTimeStart"))
     1174        self._flightTimeStart.connect("changed", self._updateButtons)
    11471175
    11481176        self._flightTimeEnd = \
    11491177            PIREPEditor.tableAttachTimeEntry(table, 2, 1,
    11501178                                             xstr("pirepView_flightTimeEnd"))
     1179        self._flightTimeEnd.connect("changed", self._updateButtons)
    11511180
    11521181        self._flownDistance = PIREPViewer.getDataLabel(width = 3)
     
    11591188                                              xstr("pirepView_fuelUsed"),
    11601189                                              1000000)
    1161 
     1190        self._fuelUsed.connect("value-changed", self._updateButtons)
    11621191
    11631192        self._rating = PIREPViewer.getDataLabel(width = 3)
     
    11811210                                              xstr("pirepView_numPassengers"),
    11821211                                              300)
     1212        self._flownNumPassengers.connect("value-changed", self._updateButtons)
    11831213
    11841214        self._flownNumCrew = \
     
    11861216                                              xstr("pirepView_numCrew"),
    11871217                                              10)
     1218        self._flownNumCrew.connect("value-changed", self._updateButtons)
    11881219
    11891220        self._flownBagWeight = \
     
    12221253    def _buildCommentsTab(self):
    12231254        """Build the tab with the comments and flight defects."""
    1224         return FlightInfo(self._gui, mainInstance = False)
     1255        return FlightInfo(self._gui, callbackObject = self)
    12251256
    12261257    def _buildLogTab(self):
     
    12381269        should be converted to uppercase."""
    12391270        entry.set_text(entry.get_text().upper())
     1271        self._updateButtons()
    12401272        #self._valueChanged(entry, arg)
    12411273
     
    12451277        if comboBox.get_active()==-1:
    12461278            entry.set_text(entry.get_text().upper())
     1279        self._updateButtons()
    12471280        #self._valueChanged(entry)
    12481281
     1282    def _updateButtons(self, *kwargs):
     1283        """Update the activity state of the buttons."""
     1284        pirep = self._pirep
     1285        bookedFlight = pirep.bookedFlight
     1286
     1287        departureMinutes = \
     1288            bookedFlight.departureTime.hour*60 + bookedFlight.departureTime.minute
     1289        departureDifference = abs(Flight.getMinutesDifference(self._blockTimeStart.minutes,
     1290                                                              departureMinutes))
     1291        flightStartDifference = \
     1292            Flight.getMinutesDifference(self._flightTimeStart.minutes,
     1293                                        self._blockTimeStart.minutes)
     1294        arrivalMinutes = \
     1295            bookedFlight.arrivalTime.hour*60 + bookedFlight.arrivalTime.minute
     1296        arrivalDifference = abs(Flight.getMinutesDifference(self._blockTimeEnd.minutes,
     1297                                                            arrivalMinutes))
     1298        flightEndDifference = \
     1299            Flight.getMinutesDifference(self._blockTimeEnd.minutes,
     1300                                        self._flightTimeEnd.minutes)
     1301
     1302        timesOK = self._flightInfo.hasComments or \
     1303                  self._flightInfo.hasDelayCode or \
     1304                  (departureDifference<=Flight.TIME_ERROR_DIFFERENCE and
     1305                   arrivalDifference<=Flight.TIME_ERROR_DIFFERENCE and
     1306                   flightStartDifference>=0 and flightStartDifference<30 and
     1307                   flightEndDifference>=0 and flightEndDifference<30)
     1308
     1309        text = self._sid.get_child().get_text()
     1310        sid = text if self._sid.get_active()!=0 and text and text!="N/A" \
     1311               else None
     1312
     1313        text = self._star.get_child().get_text()
     1314        star = text if self._star.get_active()!=0 and text and text!="N/A" \
     1315               else None
     1316
     1317        text = self._transition.get_child().get_text()
     1318        transition = text if self._transition.get_active()!=0 \
     1319                     and text and text!="N/A" else None
     1320
     1321
     1322        buffer = self._userRoute.get_buffer()
     1323        route =  buffer.get_text(buffer.get_start_iter(),
     1324                                 buffer.get_end_iter(), True)
     1325
     1326        self._okButton.set_sensitive(timesOK and
     1327                                     self._flightInfo.faultsFullyExplained and
     1328                                     self._flownNumPassengers.get_value_as_int()>0 and
     1329                                     self._flownNumCrew.get_value_as_int()>2 and
     1330                                     self._fuelUsed.get_value_as_int()>0 and
     1331                                     self._departureRunway.get_text_length()>0 and
     1332                                     self._arrivalRunway.get_text_length()>0 and
     1333                                     self._departureMETAR.get_buffer().get_char_count()>0 and
     1334                                     self._arrivalMETAR.get_buffer().get_char_count()>0 and
     1335                                     self._filedCruiseLevel.get_value_as_int()>=50 and
     1336                                     self._modifiedCruiseLevel.get_value_as_int()>=50 and
     1337                                     sid is not None and (star is not None or
     1338                                     transition is not None) and route!="" and
     1339                                     self._approachType.get_text()!="")
     1340
    12491341#------------------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.