Changeset 226:473bbc9d355f for src/mlx


Ignore:
Timestamp:
06/05/12 15:42:34 (12 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

Faults are logged highlighted

Location:
src/mlx/gui
Files:
3 edited

Legend:

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

    r225 r226  
    5757
    5858    POLICY_AUTOMATIC = gtk.POLICY_AUTOMATIC
     59
     60    WEIGHT_BOLD = pango.WEIGHT_BOLD
    5961
    6062    def text2unicode(text):
     
    105107    POLICY_AUTOMATIC = gtk.PolicyType.AUTOMATIC
    106108
     109    WEIGHT_BOLD = pango.Weight.BOLD
     110
    107111    import codecs
    108112    _utf8Decoder = codecs.getdecoder("utf-8")
     
    228232#------------------------------------------------------------------------------
    229233
    230 def formatFlightLogLine(timeStr, line, isFault = False):
     234def formatFlightLogLine(timeStr, line):
    231235    """Format the given flight log line."""
    232236    """Format the given line for flight logging."""
    233237    if timeStr is not None:
    234238        line = timeStr + ": " + line
    235     #if isFault:
    236     #    line = "<b>" + line + "</b>"
    237239    return line + "\n"
    238240
    239241#------------------------------------------------------------------------------
     242
     243def addFaultTag(buffer):
     244    """Add a tag named 'fault' to the given buffer."""
     245    faultTag = gtk.TextTag(name = "fault")
     246    faultTag.set_property("foreground", "red")
     247    faultTag.set_property("weight", WEIGHT_BOLD)
     248    buffer.get_tag_table().add(faultTag)   
     249
     250#------------------------------------------------------------------------------
     251
     252def appendTextBuffer(buffer, text, isFault = False):
     253    """Append the given line at the end of the given text buffer.
     254
     255    If isFault is set, use the tag named 'fault'."""
     256    if isFault:
     257        buffer.insert_with_tags_by_name(buffer.get_end_iter(), text,
     258                                        "fault")
     259    else:
     260        buffer.insert(buffer.get_end_iter(), text)
     261
     262#------------------------------------------------------------------------------
  • src/mlx/gui/gui.py

    r225 r226  
    112112       
    113113        (logWidget, self._logView)  = self._buildLogWidget()
     114        addFaultTag(self._logView.get_buffer())       
    114115        label = gtk.Label(xstr("tab_log"))
    115116        label.set_use_underline(True)
     
    466467        """Write the given message line to the log."""
    467468        gobject.idle_add(self._writeLog,
    468                          formatFlightLogLine(timeStr, line, isFault = isFault),
    469                          self._logView)
    470 
    471     def updateFlightLogLine(self, index, timeStr, line, isFault = False):
     469                         formatFlightLogLine(timeStr, line),
     470                         self._logView, isFault)
     471
     472    def updateFlightLogLine(self, index, timeStr, line):
    472473        """Update the line with the given index."""
    473474        gobject.idle_add(self._updateFlightLogLine, index,
    474                          formatFlightLogLine(timeStr, line,
    475                                              isFault = isFault))
     475                         formatFlightLogLine(timeStr, line))
    476476
    477477    def _updateFlightLogLine(self, index, line):
     
    914914        return (alignment, logView)
    915915
    916     def _writeLog(self, msg, logView):
     916    def _writeLog(self, msg, logView, isFault = False):
    917917        """Write the given message to the log."""
    918918        buffer = logView.get_buffer()
    919         buffer.insert(buffer.get_end_iter(), msg)
     919        appendTextBuffer(buffer, msg, isFault = isFault)
    920920        logView.scroll_mark_onscreen(buffer.get_insert())
    921921
  • src/mlx/gui/pirep.py

    r225 r226  
    239239        for (timeStr, line) in pirep.logLines:
    240240            isFault = lineIndex in pirep.faultLineIndexes
    241             logBuffer.insert(logBuffer.get_end_iter(),
    242                              formatFlightLogLine(timeStr, line,
    243                                                  isFault = isFault))
     241            appendTextBuffer(logBuffer,
     242                             formatFlightLogLine(timeStr, line),
     243                             isFault = isFault)
    244244            lineIndex += 1
    245245
     
    573573
    574574        (logWindow, self._log) = PIREPViewer.getTextWindow(heightRequest = -1)
     575        addFaultTag(self._log.get_buffer())
    575576        mainBox.pack_start(logWindow, True, True, 0)
    576577       
Note: See TracChangeset for help on using the changeset viewer.