Changeset 96:aa6a0b79c073


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

The contents of log lines can be modified after they are written, and we are using it for Vref

Location:
src/mlx
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/acft.py

    r95 r96  
    2525        self._maxVS = -10000.0
    2626        self._minVS = 10000.0
     27
     28        self._vrefLineIndex = None
    2729
    2830        self._checkers = []
     
    189191                            "Altimeter setting: %.0f hPa" % \
    190192                            (self._aircraftState.altimeter,))
    191         self.logger.message(self._aircraftState.timestamp,
    192                             "VRef speed calculated by the pilot: %s" % \
    193                             ("-" if self._flight.vref is None
    194                              else str(self._flight.vref)))
     193        self._vrefLineIndex = \
     194            self.logger.message(self._aircraftState.timestamp,
     195                                "VRef speed calculated by the pilot: %s" % \
     196                                ("-" if self._flight.vref is None
     197                                 else str(self._flight.vref)))
    195198        self.flight.flareStarted(flareStart, flareStartFS)
    196199         
     
    230233            if n1>=0.5: return False
    231234        return True
     235
     236    def updateVRef(self):
     237        """Update the Vref value from the flight, if the Vref value has already
     238        been logged."""
     239        if self._vrefLineIndex is not None:
     240            self._logVRef()
     241
     242    def _logVRef(self):
     243        """Log the Vref value either newly, or by updating the corresponding
     244        line."""
     245        message = "VRef speed calculated by the pilot: %s" % \
     246                  ("-" if self._flight.vref is None else str(self._flight.vref))
     247        if self._vrefLineIndex is None:
     248            self._vrefLineIndex = \
     249                self.logger.message(self._aircraftState.timestamp, message)
     250        else:
     251            self.logger.updateLine(self._vrefLineIndex, message)
    232252
    233253#---------------------------------------------------------------------------------------
  • src/mlx/gui/flight.py

    r94 r96  
    15571557
    15581558        self._vref.set_sensitive(False)
     1559        self._wizard.gui.flight.aircraft.updateVRef()
    15591560        # FIXME: Perhaps a separate initialize() call which would set up
    1560         # defaults?
     1561        # defaults? -> use reset()
    15611562        self._flightEnded = False
    15621563
     
    16181619                                  xscale = 0.0, yscale = 0.0)
    16191620
    1620         table = gtk.Table(5, 2)
     1621        table = gtk.Table(7, 2)
    16211622        table.set_row_spacings(4)
    16221623        table.set_col_spacings(16)
    1623         table.set_homogeneous(True)
     1624        table.set_homogeneous(False)
    16241625        alignment.add(table)
    16251626        self.setMainWidget(alignment)
     
    16891690        labelAlignment.add(self._fuelUsed)
    16901691        table.attach(labelAlignment, 1, 2, 4, 5)
     1692
     1693        labelAlignment = gtk.Alignment(xalign=1.0, xscale=0.0)
     1694        label = gtk.Label("_Type:")
     1695        label.set_use_underline(True)
     1696        labelAlignment.add(label)
     1697        table.attach(labelAlignment, 0, 1, 5, 6)
     1698
     1699        flightTypeModel = gtk.ListStore(str, int)
     1700        index = 1
     1701        for type in ["scheduled", "old-timer", "VIP", "charter"]:
     1702            flightTypeModel.append([type, index])
     1703            index += 1
     1704
     1705        self._flightType = gtk.ComboBox(model = flightTypeModel)
     1706        renderer = gtk.CellRendererText()
     1707        self._flightType.pack_start(renderer, True)
     1708        self._flightType.add_attribute(renderer, "text", 0)
     1709        self._flightType.set_tooltip_text("Select the type of the flight.")
     1710        self._flightType.set_active(0)
     1711        self._flightType.connect("changed", self._flightTypeChanged)
     1712        flightTypeAlignment = gtk.Alignment(xalign=0.0, xscale=0.0)
     1713        flightTypeAlignment.add(self._flightType)
     1714        table.attach(flightTypeAlignment, 1, 2, 5, 6)
     1715        label.set_mnemonic_widget(self._flightType)       
     1716
     1717        self._onlineFlight = gtk.CheckButton("_Online flight")
     1718        self._onlineFlight.set_use_underline(True)
     1719        self._onlineFlight.set_tooltip_text("Check if your flight was online, uncheck otherwise.")
     1720        onlineFlightAlignment = gtk.Alignment(xalign=0.0, xscale=0.0)
     1721        onlineFlightAlignment.add(self._onlineFlight)
     1722        table.attach(onlineFlightAlignment, 1, 2, 6, 7)
    16911723
    16921724        button = self.addButton(gtk.STOCK_GO_BACK)
     
    17271759                                  (flight.endFuel - flight.startFuel,))
    17281760
     1761        self._flightType.set_active(-1)
     1762        self._onlineFlight.set_active(True)
     1763
    17291764    def _backClicked(self, button):
    17301765        """Called when the Back button is pressed."""
    17311766        self.goBack()
     1767
     1768    def _flightTypeChanged(self, comboBox):
     1769        """Called when the flight type has changed."""
     1770        index = self._flightType.get_active()
     1771        flightTypeIsValid = index>=0
     1772        self._saveButton.set_sensitive(flightTypeIsValid)
     1773        self._sendButton.set_sensitive(flightTypeIsValid)
    17321774       
    17331775#-----------------------------------------------------------------------------
  • src/mlx/gui/gui.py

    r93 r96  
    2424class GUI(fs.ConnectionListener):
    2525    """The main GUI class."""
     26    @staticmethod
     27    def _formatFlightLogLine(timeStr, line):
     28        """Format the given line for flight logging."""
     29        if timeStr is not None:
     30            line = timeStr + ": " + line
     31        return line + "\n"
     32       
    2633    def __init__(self, programDirectory, config):
    2734        """Construct the GUI."""
     
    3340        self._reconnecting = False
    3441        self._connected = False
    35         self._logger = logger.Logger(output = self)
     42        self._logger = logger.Logger(self)
    3643        self._flight = None
    3744        self._simulator = None
     
    272279        self._statusbar.updateConnection(False, False)
    273280           
    274     def write(self, msg):
    275         """Write the given message to the log."""
    276         gobject.idle_add(self._writeLog, msg, self._logView)
    277        
     281    def addFlightLogLine(self, timeStr, line):
     282        """Write the given message line to the log."""
     283        gobject.idle_add(self._writeLog,
     284                         GUI._formatFlightLogLine(timeStr, line),
     285                         self._logView)
     286
     287    def updateFlightLogLine(self, index, timeStr, line):
     288        """Update the line with the given index."""
     289        gobject.idle_add(self._updateFlightLogLine, index,
     290                         GUI._formatFlightLogLine(timeStr, line))
     291
     292    def _updateFlightLogLine(self, index, line):
     293        """Replace the contents of the given line in the log."""
     294        buffer = self._logView.get_buffer()
     295        startIter = buffer.get_iter_at_line(index)
     296        endIter = buffer.get_iter_at_line(index + 1)
     297        buffer.delete(startIter, endIter)
     298        buffer.insert(startIter, line)
     299        self._logView.scroll_mark_onscreen(buffer.get_insert())
     300
    278301    def check(self, flight, aircraft, logger, oldState, state):
    279302        """Update the data."""
     
    428451           
    429452        for line in lines:
    430             print >> sys.__stdout__, line
     453            #print >> sys.__stdout__, line
    431454            self._writeLog(line + "\n", self._debugLogView)
    432455
    433456        if text:
    434             print >> sys.__stdout__, line,
     457            #print >> sys.__stdout__, text,
    435458            self._writeLog(text, self._debugLogView)
    436459
  • src/mlx/logger.py

    r87 r96  
    2828    NO_GO_SCORE = 10000
    2929
    30     def __init__(self, output = sys.stdout):
     30    def __init__(self, output):
    3131        """Construct the logger."""
     32        self._lines = []
    3233        self._faults = {}
    3334        self._output = output
     
    4243
    4344        The faults logged so far will be cleared."""
     45        self._lines = []
    4446        self._faults.clear()
    4547               
     
    4749        """Put a simple textual message into the log with the given timestamp."""
    4850        timeStr = Logger._getTimeStr(timestamp)
    49         print >> self._output, timeStr + ":", msg
     51        return self._logLine(msg, timeStr)
    5052
    5153    def untimedMessage(self, msg):
    5254        """Put an untimed message into the log."""
    53         print >> self._output, msg
     55        return self._logLine(msg)
    5456
    5557    def debug(self, msg):
     
    9395                totalScore -= score
    9496        return totalScore
     97
     98    def updateLine(self, index, line):
     99        """Update the line at the given index with the given string."""
     100        (timeStr, _line) = self._lines[index]
     101        self._lines[index] = (timeStr, line)
     102        self._output.updateFlightLogLine(index, timeStr, line)
     103
     104    def _logLine(self, line, timeStr = None):
     105        """Log the given line."""
     106        index = len(self._lines)
     107        self._lines.append((timeStr, line))
     108        self._output.addFlightLogLine(timeStr, line)
     109        return index
    95110       
    96111#--------------------------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.