controls/LogViewer.py
author Laurent Bessard
Tue, 26 Mar 2013 23:26:13 +0100
changeset 1005 496a96e1dcb6
parent 999 cbab4c1635bd
child 1020 2d20f25cd39f
permissions -rw-r--r--
Updated internationalization french translations
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
     1
#!/usr/bin/env python
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
     3
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
     4
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
     5
#based on the plcopen standard. 
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
     6
#
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
     7
#Copyright (C) 2013: Edouard TISSERANT and Laurent BESSARD
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
     8
#
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
     9
#See COPYING file for copyrights details.
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    10
#
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    11
#This library is free software; you can redistribute it and/or
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    12
#modify it under the terms of the GNU General Public
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    13
#License as published by the Free Software Foundation; either
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    14
#version 2.1 of the License, or (at your option) any later version.
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    15
#
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    16
#This library is distributed in the hope that it will be useful,
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    17
#but WITHOUT ANY WARRANTY; without even the implied warranty of
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    18
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    19
#General Public License for more details.
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    20
#
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    21
#You should have received a copy of the GNU General Public
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    22
#License along with this library; if not, write to the Free Software
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    23
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    24
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    25
from datetime import datetime
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
    26
from time import time as gettime
982
e3c264099bd0 Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents: 981
diff changeset
    27
import numpy
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    28
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    29
import wx
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    30
993
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
    31
from graphics import DebugViewer, REFRESH_PERIOD, ToolTip, TOOLTIP_WAIT_PERIOD
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    32
from targets.typemapping import LogLevelsCount, LogLevels
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    33
from util.BitmapLibrary import GetBitmap
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    34
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
    35
THUMB_SIZE_RATIO = 1. / 8.
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    36
993
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
    37
def ArrowPoints(direction, width, height, xoffset, yoffset):
986
b663f099da8a Fixed LogViewer with improvements
Laurent Bessard
parents: 984
diff changeset
    38
    if direction == wx.TOP:
993
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
    39
        return [wx.Point(xoffset + 1, yoffset + height - 2),
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
    40
                wx.Point(xoffset + width / 2, yoffset + 1),
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
    41
                wx.Point(xoffset + width - 1, yoffset + height - 2)]
986
b663f099da8a Fixed LogViewer with improvements
Laurent Bessard
parents: 984
diff changeset
    42
    else:
993
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
    43
        return [wx.Point(xoffset + 1, yoffset - height + 1),
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
    44
                wx.Point(xoffset + width / 2, yoffset - 2),
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
    45
                wx.Point(xoffset + width - 1, yoffset - height + 1)]
986
b663f099da8a Fixed LogViewer with improvements
Laurent Bessard
parents: 984
diff changeset
    46
983
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
    47
class LogScrollBar(wx.Panel):
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    48
    
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    49
    def __init__(self, parent, size):
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    50
        wx.Panel.__init__(self, parent, size=size)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    51
        self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    52
        self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    53
        self.Bind(wx.EVT_MOTION, self.OnMotion)
988
30e7571c10d0 Reduced flicker on LogViewer and DebugGraphPanel on Windows
Laurent Bessard
parents: 987
diff changeset
    54
        self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    55
        self.Bind(wx.EVT_PAINT, self.OnPaint)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    56
        self.Bind(wx.EVT_SIZE, self.OnResize)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    57
        
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
    58
        self.ThumbPosition = 0. # -1 <= ThumbPosition <= 1
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
    59
        self.ThumbScrollingStartPos = None
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    60
    
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    61
    def GetRangeRect(self):
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    62
        width, height = self.GetClientSize()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    63
        return wx.Rect(0, width, width, height - 2 * width)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    64
    
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    65
    def GetThumbRect(self):
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    66
        width, height = self.GetClientSize()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    67
        range_rect = self.GetRangeRect()
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
    68
        thumb_size = range_rect.height * THUMB_SIZE_RATIO
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
    69
        thumb_range = range_rect.height - thumb_size
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
    70
        thumb_center_position = (thumb_size + (self.ThumbPosition + 1) * thumb_range) / 2.
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
    71
        thumb_start = int(thumb_center_position - thumb_size / 2.)
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
    72
        thumb_end = int(thumb_center_position + thumb_size / 2.)
987
7ca88194ae89 Improved graphics of LogViewer scrollbar to be anti-aliased
Laurent Bessard
parents: 986
diff changeset
    73
        return wx.Rect(0, range_rect.y + thumb_start, width, thumb_end - thumb_start)
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
    74
    
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
    75
    def RefreshThumbPosition(self, thumb_position=None):
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
    76
        if thumb_position is None:
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
    77
            thumb_position = self.ThumbPosition
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    78
        if self.Parent.IsMessagePanelTop():
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
    79
            thumb_position = max(0., thumb_position)
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    80
        if self.Parent.IsMessagePanelBottom():
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
    81
            thumb_position = min(0., thumb_position)
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
    82
        if thumb_position != self.ThumbPosition:
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
    83
            self.ThumbPosition = thumb_position
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
    84
            self.Parent.SetScrollSpeed(self.ThumbPosition)
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
    85
        self.Refresh()
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    86
    
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    87
    def OnLeftDown(self, event):
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    88
        self.CaptureMouse()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    89
        posx, posy = event.GetPosition()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    90
        width, height = self.GetClientSize()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    91
        range_rect = self.GetRangeRect()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    92
        thumb_rect = self.GetThumbRect()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    93
        if range_rect.InsideXY(posx, posy):
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    94
            if thumb_rect.InsideXY(posx, posy):
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
    95
                self.ThumbScrollingStartPos = wx.Point(posx, posy)
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    96
            elif posy < thumb_rect.y:
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
    97
                self.Parent.ScrollToLast()
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    98
            elif posy > thumb_rect.y + thumb_rect.height:
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
    99
                self.Parent.ScrollToFirst()
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   100
        elif posy < width:
986
b663f099da8a Fixed LogViewer with improvements
Laurent Bessard
parents: 984
diff changeset
   101
            self.Parent.ScrollMessagePanelByPage(1)
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   102
        elif posy > height - width:
986
b663f099da8a Fixed LogViewer with improvements
Laurent Bessard
parents: 984
diff changeset
   103
            self.Parent.ScrollMessagePanelByPage(-1)
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   104
        event.Skip()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   105
        
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   106
    def OnLeftUp(self, event):
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   107
        self.ThumbScrollingStartPos = None
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   108
        self.RefreshThumbPosition(0.)
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   109
        if self.HasCapture():
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   110
            self.ReleaseMouse()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   111
        event.Skip()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   112
        
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   113
    def OnMotion(self, event):
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   114
        if event.Dragging() and self.ThumbScrollingStartPos is not None:
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   115
            posx, posy = event.GetPosition()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   116
            width, height = self.GetClientSize()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   117
            range_rect = self.GetRangeRect()
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   118
            thumb_size = range_rect.height * THUMB_SIZE_RATIO
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   119
            thumb_range = range_rect.height - thumb_size
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   120
            self.RefreshThumbPosition(
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   121
                max(-1., min((posy - self.ThumbScrollingStartPos.y) * 2. / thumb_range, 1.)))
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   122
        event.Skip()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   123
    
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   124
    def OnResize(self, event):
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   125
        self.Refresh()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   126
        event.Skip()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   127
    
988
30e7571c10d0 Reduced flicker on LogViewer and DebugGraphPanel on Windows
Laurent Bessard
parents: 987
diff changeset
   128
    def OnEraseBackground(self, event):
30e7571c10d0 Reduced flicker on LogViewer and DebugGraphPanel on Windows
Laurent Bessard
parents: 987
diff changeset
   129
        pass
30e7571c10d0 Reduced flicker on LogViewer and DebugGraphPanel on Windows
Laurent Bessard
parents: 987
diff changeset
   130
    
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   131
    def OnPaint(self, event):
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   132
        dc = wx.BufferedPaintDC(self)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   133
        dc.Clear()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   134
        dc.BeginDrawing()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   135
        
987
7ca88194ae89 Improved graphics of LogViewer scrollbar to be anti-aliased
Laurent Bessard
parents: 986
diff changeset
   136
        gc = wx.GCDC(dc)
7ca88194ae89 Improved graphics of LogViewer scrollbar to be anti-aliased
Laurent Bessard
parents: 986
diff changeset
   137
        
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   138
        width, height = self.GetClientSize()
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   139
        
993
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   140
        gc.SetPen(wx.Pen(wx.NamedColour("GREY"), 3))
987
7ca88194ae89 Improved graphics of LogViewer scrollbar to be anti-aliased
Laurent Bessard
parents: 986
diff changeset
   141
        gc.SetBrush(wx.GREY_BRUSH)
7ca88194ae89 Improved graphics of LogViewer scrollbar to be anti-aliased
Laurent Bessard
parents: 986
diff changeset
   142
        
993
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   143
        gc.DrawLines(ArrowPoints(wx.TOP, width * 0.75, width * 0.5, 2, (width + height) / 4 - 3))
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   144
        gc.DrawLines(ArrowPoints(wx.TOP, width * 0.75, width * 0.5, 2, (width + height) / 4 + 3))
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   145
        
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   146
        gc.DrawLines(ArrowPoints(wx.BOTTOM, width * 0.75, width * 0.5, 2, (height * 3 - width) / 4 + 3))
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   147
        gc.DrawLines(ArrowPoints(wx.BOTTOM, width * 0.75, width * 0.5, 2, (height * 3 - width) / 4 - 3))
986
b663f099da8a Fixed LogViewer with improvements
Laurent Bessard
parents: 984
diff changeset
   148
        
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   149
        thumb_rect = self.GetThumbRect()
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   150
        exclusion_rect = wx.Rect(thumb_rect.x, thumb_rect.y,
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   151
                                 thumb_rect.width, thumb_rect.height)
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   152
        if self.Parent.IsMessagePanelTop():
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   153
            exclusion_rect.y, exclusion_rect.height = width, exclusion_rect.y + exclusion_rect.height - width
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   154
        if self.Parent.IsMessagePanelBottom():
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   155
            exclusion_rect.height = height - width - exclusion_rect.y
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   156
        if exclusion_rect != thumb_rect:
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   157
            colour = wx.NamedColour("LIGHT GREY")
987
7ca88194ae89 Improved graphics of LogViewer scrollbar to be anti-aliased
Laurent Bessard
parents: 986
diff changeset
   158
            gc.SetPen(wx.Pen(colour))
7ca88194ae89 Improved graphics of LogViewer scrollbar to be anti-aliased
Laurent Bessard
parents: 986
diff changeset
   159
            gc.SetBrush(wx.Brush(colour))
7ca88194ae89 Improved graphics of LogViewer scrollbar to be anti-aliased
Laurent Bessard
parents: 986
diff changeset
   160
        
7ca88194ae89 Improved graphics of LogViewer scrollbar to be anti-aliased
Laurent Bessard
parents: 986
diff changeset
   161
            gc.DrawRectangle(exclusion_rect.x, exclusion_rect.y, 
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   162
                             exclusion_rect.width, exclusion_rect.height)
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   163
        
987
7ca88194ae89 Improved graphics of LogViewer scrollbar to be anti-aliased
Laurent Bessard
parents: 986
diff changeset
   164
        gc.SetPen(wx.GREY_PEN)
7ca88194ae89 Improved graphics of LogViewer scrollbar to be anti-aliased
Laurent Bessard
parents: 986
diff changeset
   165
        gc.SetBrush(wx.GREY_BRUSH)
7ca88194ae89 Improved graphics of LogViewer scrollbar to be anti-aliased
Laurent Bessard
parents: 986
diff changeset
   166
        
993
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   167
        gc.DrawPolygon(ArrowPoints(wx.TOP, width, width, 0, 0))
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   168
        
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   169
        gc.DrawPolygon(ArrowPoints(wx.BOTTOM, width, width, 0, height))
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   170
            
987
7ca88194ae89 Improved graphics of LogViewer scrollbar to be anti-aliased
Laurent Bessard
parents: 986
diff changeset
   171
        gc.DrawRectangle(thumb_rect.x, thumb_rect.y, 
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   172
                         thumb_rect.width, thumb_rect.height)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   173
        
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   174
        dc.EndDrawing()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   175
        event.Skip()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   176
983
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   177
BUTTON_SIZE = (30, 15)
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   178
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   179
class LogButton():
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   180
    
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   181
    def __init__(self, label, callback):
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   182
        self.Position = wx.Point(0, 0)
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   183
        self.Size = wx.Size(*BUTTON_SIZE)
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   184
        self.Label = label
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   185
        self.Shown = True
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   186
        self.Callback = callback
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   187
    
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   188
    def __del__(self):
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   189
        self.callback = None
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   190
    
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   191
    def GetSize(self):
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   192
        return self.Size
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   193
    
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   194
    def SetPosition(self, x, y):
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   195
        self.Position = wx.Point(x, y)
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   196
    
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   197
    def HitTest(self, x, y):
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   198
        rect = wx.Rect(self.Position.x, self.Position.y, 
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   199
                       self.Size.width, self.Size.height)
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   200
        if rect.InsideXY(x, y):
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   201
            return True
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   202
        return False
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   203
    
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   204
    def ProcessCallback(self):
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   205
        if self.Callback is not None:
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   206
            wx.CallAfter(self.Callback)
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   207
            
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   208
    def Draw(self, dc):
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   209
        dc.SetPen(wx.TRANSPARENT_PEN)
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   210
        dc.SetBrush(wx.Brush(wx.NamedColour("LIGHT GREY")))
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   211
        
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   212
        dc.DrawRectangle(self.Position.x, self.Position.y, 
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   213
                         self.Size.width, self.Size.height)
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   214
        
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   215
        w, h = dc.GetTextExtent(self.Label)
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   216
        dc.DrawText(self.Label, 
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   217
            self.Position.x + (self.Size.width - w) / 2, 
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   218
            self.Position.y + (self.Size.height - h) / 2)
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   219
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   220
DATE_INFO_SIZE = 10
997
d6da2ccafca4 Reduced message line size in Log Viewer
Laurent Bessard
parents: 993
diff changeset
   221
MESSAGE_INFO_SIZE = 18
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   222
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   223
class LogMessage:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   224
    
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   225
    def __init__(self, tv_sec, tv_nsec, level, level_bitmap, msg):
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   226
        self.Date = datetime.fromtimestamp(tv_sec)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   227
        self.Seconds = self.Date.second + tv_nsec * 1e-9
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   228
        self.Date = self.Date.replace(second=0)
982
e3c264099bd0 Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents: 981
diff changeset
   229
        self.Timestamp = tv_sec + tv_nsec * 1e-9
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   230
        self.Level = level
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   231
        self.LevelBitmap = level_bitmap
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   232
        self.Message = msg
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   233
        self.DrawDate = True
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   234
    
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   235
    def __cmp__(self, other):
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   236
        if self.Date == other.Date:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   237
            return cmp(self.Seconds, other.Seconds)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   238
        return cmp(self.Date, other.Date)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   239
    
993
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   240
    def GetFullText(self):
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   241
        date = self.Date.replace(second=int(self.Seconds))
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   242
        nsec = (self.Seconds % 1.) * 1e9
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   243
        return "%s at %s.%9.9d:\n%s" % (
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   244
            LogLevels[self.Level],
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   245
            str(date), nsec,
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   246
            self.Message)
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   247
    
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   248
    def Draw(self, dc, offset, width, draw_date):
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   249
        if draw_date:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   250
            datetime_text = self.Date.strftime("%d/%m/%y %H:%M")
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   251
            dw, dh = dc.GetTextExtent(datetime_text)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   252
            dc.DrawText(datetime_text, (width - dw) / 2, offset + (DATE_INFO_SIZE - dh) / 2)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   253
            offset += DATE_INFO_SIZE
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   254
        
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   255
        seconds_text = "%12.9f" % self.Seconds
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   256
        sw, sh = dc.GetTextExtent(seconds_text)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   257
        dc.DrawText(seconds_text, 5, offset + (MESSAGE_INFO_SIZE - sh) / 2)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   258
        
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   259
        bw, bh = self.LevelBitmap.GetWidth(), self.LevelBitmap.GetHeight()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   260
        dc.DrawBitmap(self.LevelBitmap, 10 + sw, offset + (MESSAGE_INFO_SIZE - bh) / 2)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   261
        
993
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   262
        text = self.Message.replace("\n", " ")
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   263
        mw, mh = dc.GetTextExtent(text)
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   264
        dc.DrawText(text, 15 + sw + bw, offset + (MESSAGE_INFO_SIZE - mh) / 2)
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   265
        
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   266
    def GetHeight(self, draw_date):
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   267
        if draw_date:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   268
            return DATE_INFO_SIZE + MESSAGE_INFO_SIZE
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   269
        return MESSAGE_INFO_SIZE
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   270
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   271
SECOND = 1
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   272
MINUTE = 60 * SECOND
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   273
HOUR = 60 * MINUTE
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   274
DAY = 24 * HOUR
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   275
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   276
CHANGE_TIMESTAMP_BUTTONS = [(_("1d"), DAY),
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   277
                            (_("1h"), HOUR),
986
b663f099da8a Fixed LogViewer with improvements
Laurent Bessard
parents: 984
diff changeset
   278
                            (_("1m"), MINUTE),
b663f099da8a Fixed LogViewer with improvements
Laurent Bessard
parents: 984
diff changeset
   279
                            (_("1s"), SECOND)]
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   280
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   281
class LogViewer(DebugViewer, wx.Panel):
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   282
    
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   283
    def __init__(self, parent, window):
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   284
        wx.Panel.__init__(self, parent, style=wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   285
        DebugViewer.__init__(self, None, False, False)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   286
        
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   287
        main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   288
        main_sizer.AddGrowableCol(0)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   289
        main_sizer.AddGrowableRow(1)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   290
        
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   291
        filter_sizer = wx.BoxSizer(wx.HORIZONTAL)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   292
        main_sizer.AddSizer(filter_sizer, border=5, flag=wx.TOP|wx.LEFT|wx.RIGHT|wx.GROW)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   293
        
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   294
        self.MessageFilter = wx.ComboBox(self, style=wx.CB_READONLY)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   295
        self.MessageFilter.Append(_("All"))
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   296
        levels = LogLevels[:3]
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   297
        levels.reverse()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   298
        for level in levels:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   299
            self.MessageFilter.Append(_(level))
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   300
        self.Bind(wx.EVT_COMBOBOX, self.OnMessageFilterChanged, self.MessageFilter)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   301
        filter_sizer.AddWindow(self.MessageFilter, 1, border=5, flag=wx.RIGHT|wx.GROW)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   302
        
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   303
        self.SearchMessage = wx.SearchCtrl(self, style=wx.TE_PROCESS_ENTER)
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   304
        self.SearchMessage.ShowSearchButton(True)
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   305
        self.SearchMessage.ShowCancelButton(True)
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   306
        self.Bind(wx.EVT_TEXT_ENTER, self.OnSearchMessageChanged, self.SearchMessage)
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   307
        self.Bind(wx.EVT_SEARCHCTRL_SEARCH_BTN, 
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   308
              self.OnSearchMessageSearchButtonClick, self.SearchMessage)
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   309
        self.Bind(wx.EVT_SEARCHCTRL_CANCEL_BTN, 
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   310
              self.OnSearchMessageCancelButtonClick, self.SearchMessage)
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   311
        filter_sizer.AddWindow(self.SearchMessage, 3, flag=wx.GROW)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   312
        
983
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   313
        message_panel_sizer = wx.FlexGridSizer(cols=2, hgap=0, rows=1, vgap=0)
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   314
        message_panel_sizer.AddGrowableCol(0)
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   315
        message_panel_sizer.AddGrowableRow(0)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   316
        main_sizer.AddSizer(message_panel_sizer, border=5, flag=wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.GROW)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   317
        
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   318
        self.MessagePanel = wx.Panel(self)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   319
        if wx.Platform == '__WXMSW__':
993
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   320
            self.Font = wx.Font(8, wx.SWISS, wx.NORMAL, wx.NORMAL, faceName='Courier New')
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   321
        else:
993
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   322
            self.Font = wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL, faceName='Courier')
984
2d03056993f6 Fixed bugs with new buttons on Windows
Laurent Bessard
parents: 983
diff changeset
   323
        self.MessagePanel.Bind(wx.EVT_LEFT_UP, self.OnMessagePanelLeftUp)
993
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   324
        self.MessagePanel.Bind(wx.EVT_RIGHT_UP, self.OnMessagePanelRightUp)
986
b663f099da8a Fixed LogViewer with improvements
Laurent Bessard
parents: 984
diff changeset
   325
        self.MessagePanel.Bind(wx.EVT_LEFT_DCLICK, self.OnMessagePanelLeftDCLick)
993
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   326
        self.MessagePanel.Bind(wx.EVT_MOTION, self.OnMessagePanelMotion)
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   327
        self.MessagePanel.Bind(wx.EVT_LEAVE_WINDOW, self.OnMessagePanelLeaveWindow)
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   328
        self.MessagePanel.Bind(wx.EVT_MOUSEWHEEL, self.OnMessagePanelMouseWheel)
988
30e7571c10d0 Reduced flicker on LogViewer and DebugGraphPanel on Windows
Laurent Bessard
parents: 987
diff changeset
   329
        self.MessagePanel.Bind(wx.EVT_ERASE_BACKGROUND, self.OnMessagePanelEraseBackground)
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   330
        self.MessagePanel.Bind(wx.EVT_PAINT, self.OnMessagePanelPaint)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   331
        self.MessagePanel.Bind(wx.EVT_SIZE, self.OnMessagePanelResize)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   332
        message_panel_sizer.AddWindow(self.MessagePanel, flag=wx.GROW)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   333
        
983
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   334
        self.MessageScrollBar = LogScrollBar(self, wx.Size(16, -1))
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   335
        message_panel_sizer.AddWindow(self.MessageScrollBar, flag=wx.GROW)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   336
        
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   337
        self.SetSizer(main_sizer)
983
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   338
        
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   339
        self.LeftButtons = []
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   340
        for label, callback in [("+" + text, self.GenerateOnDurationButton(duration)) 
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   341
                                for text, duration in CHANGE_TIMESTAMP_BUTTONS]:
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   342
            self.LeftButtons.append(LogButton(label, callback))
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   343
        
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   344
        self.RightButtons = []
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   345
        for label, callback in [("-" + text, self.GenerateOnDurationButton(-duration)) 
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   346
                                for text, duration in CHANGE_TIMESTAMP_BUTTONS]:
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   347
            self.RightButtons.append(LogButton(label, callback))
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   348
        
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   349
        self.MessageFilter.SetSelection(0)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   350
        self.LogSource = None
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   351
        self.ResetLogMessages()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   352
        self.ParentWindow = window
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   353
    
979
1a68113a323d Fixed conflicting icon names on Windows
Laurent Bessard
parents: 978
diff changeset
   354
        self.LevelIcons = [GetBitmap("LOG_" + level) for level in LogLevels]
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   355
        self.LevelFilters = [range(i) for i in xrange(4, 0, -1)]
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   356
        self.CurrentFilter = self.LevelFilters[0]
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   357
        self.CurrentSearchValue = ""
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   358
        
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   359
        self.ScrollSpeed = 0.
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   360
        self.LastStartTime = None
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   361
        self.ScrollTimer = wx.Timer(self, -1)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   362
        self.Bind(wx.EVT_TIMER, self.OnScrollTimer, self.ScrollTimer)
993
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   363
        
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   364
        self.LastMousePos = None
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   365
        self.MessageToolTip = None
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   366
        self.MessageToolTipTimer = wx.Timer(self, -1)
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   367
        self.Bind(wx.EVT_TIMER, self.OnMessageToolTipTimer, self.MessageToolTipTimer)
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   368
    
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   369
    def __del__(self):
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   370
        self.ScrollTimer.Stop()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   371
    
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   372
    def ResetLogMessages(self):
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   373
        self.previous_log_count = [None]*LogLevelsCount
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   374
        self.OldestMessages = []
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   375
        self.LogMessages = []
982
e3c264099bd0 Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents: 981
diff changeset
   376
        self.LogMessagesTimestamp = numpy.array([])
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   377
        self.CurrentMessage = None
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   378
        self.HasNewData = False
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   379
    
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   380
    def SetLogSource(self, log_source):
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   381
        self.LogSource = log_source
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   382
        if log_source is not None:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   383
            self.ResetLogMessages()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   384
            self.RefreshView()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   385
    
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   386
    def GetLogMessageFromSource(self, msgidx, level):
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   387
        if self.LogSource is not None:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   388
            answer = self.LogSource.GetLogMessage(level, msgidx)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   389
            if answer is not None:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   390
                msg, tick, tv_sec, tv_nsec = answer
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   391
                return LogMessage(tv_sec, tv_nsec, level, self.LevelIcons[level], msg)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   392
        return None
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   393
    
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   394
    def SetLogCounters(self, log_count):
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   395
        new_messages = []
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   396
        for level, count, prev in zip(xrange(LogLevelsCount), log_count, self.previous_log_count):
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   397
            if count is not None and prev != count:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   398
                if prev is None:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   399
                    dump_end = count - 2
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   400
                else:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   401
                    dump_end = prev - 1
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   402
                for msgidx in xrange(count-1, dump_end,-1):
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   403
                    new_message = self.GetLogMessageFromSource(msgidx, level)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   404
                    if new_message is not None:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   405
                        if prev is None:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   406
                            self.OldestMessages.append((msgidx, new_message))
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   407
                            if len(new_messages) == 0 or new_message > new_messages[0]:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   408
                                new_messages = [new_message]
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   409
                        else:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   410
                            new_messages.insert(0, new_message)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   411
                    else:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   412
                        if prev is None:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   413
                            self.OldestMessages.append((-1, None))
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   414
                        break
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   415
                self.previous_log_count[level] = count
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   416
        new_messages.sort()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   417
        if len(new_messages) > 0:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   418
            self.HasNewData = True
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   419
            old_length = len(self.LogMessages)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   420
            for new_message in new_messages:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   421
                self.LogMessages.append(new_message)
982
e3c264099bd0 Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents: 981
diff changeset
   422
                self.LogMessagesTimestamp = numpy.append(self.LogMessagesTimestamp, [new_message.Timestamp])
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   423
            if self.CurrentMessage is None or self.CurrentMessage == old_length - 1:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   424
                self.CurrentMessage = len(self.LogMessages) - 1
993
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   425
                self.ResetMessageToolTip()
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   426
                self.MessageToolTipTimer.Stop()
999
cbab4c1635bd Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents: 997
diff changeset
   427
                self.ParentWindow.SelectTab(self)
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   428
            self.NewDataAvailable(None)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   429
    
982
e3c264099bd0 Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents: 981
diff changeset
   430
    def FilterLogMessage(self, message, timestamp=None):
e3c264099bd0 Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents: 981
diff changeset
   431
        return (message.Level in self.CurrentFilter and 
e3c264099bd0 Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents: 981
diff changeset
   432
                message.Message.find(self.CurrentSearchValue) != -1 and
e3c264099bd0 Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents: 981
diff changeset
   433
                (timestamp is None or message.Timestamp < timestamp))
e3c264099bd0 Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents: 981
diff changeset
   434
    
e3c264099bd0 Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents: 981
diff changeset
   435
    def GetMessageByTimestamp(self, timestamp):
e3c264099bd0 Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents: 981
diff changeset
   436
        if self.CurrentMessage is not None:
e3c264099bd0 Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents: 981
diff changeset
   437
            msgidx = numpy.argmin(abs(self.LogMessagesTimestamp - timestamp))
e3c264099bd0 Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents: 981
diff changeset
   438
            message = self.LogMessages[msgidx]
e3c264099bd0 Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents: 981
diff changeset
   439
            if self.FilterLogMessage(message) and message.Timestamp > timestamp:
e3c264099bd0 Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents: 981
diff changeset
   440
                return self.GetPreviousMessage(msgidx, timestamp)
e3c264099bd0 Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents: 981
diff changeset
   441
            return message, msgidx
e3c264099bd0 Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents: 981
diff changeset
   442
        return None, None
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   443
    
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   444
    def GetNextMessage(self, msgidx):
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   445
        while msgidx < len(self.LogMessages) - 1:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   446
            message = self.LogMessages[msgidx + 1]
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   447
            if self.FilterLogMessage(message):
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   448
                return message, msgidx + 1
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   449
            msgidx += 1
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   450
        return None, None
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   451
    
982
e3c264099bd0 Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents: 981
diff changeset
   452
    def GetPreviousMessage(self, msgidx, timestamp=None):
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   453
        message = None
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   454
        while 0 < msgidx < len(self.LogMessages):
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   455
            message = self.LogMessages[msgidx - 1]
982
e3c264099bd0 Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents: 981
diff changeset
   456
            if self.FilterLogMessage(message, timestamp):
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   457
                return message, msgidx - 1
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   458
            msgidx -= 1
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   459
        if len(self.LogMessages) > 0:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   460
            message = self.LogMessages[0]
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   461
            while message is not None:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   462
                level = message.Level
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   463
                oldest_msgidx, oldest_message = self.OldestMessages[level]
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   464
                if oldest_msgidx > 0:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   465
                    old_message = self.GetLogMessageFromSource(oldest_msgidx - 1, level)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   466
                    if old_message is not None:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   467
                        self.OldestMessages[level] = (oldest_msgidx - 1, old_message)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   468
                    else:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   469
                        self.OldestMessages[level] = (-1, None)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   470
                else:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   471
                    self.OldestMessages[level] = (-1, None)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   472
                message = None
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   473
                for idx, msg in self.OldestMessages:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   474
                    if msg is not None and (message is None or msg > message):
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   475
                        message = msg
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   476
                if message is not None:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   477
                    self.LogMessages.insert(0, message)
982
e3c264099bd0 Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents: 981
diff changeset
   478
                    self.LogMessagesTimestamp = numpy.insert(self.LogMessagesTimestamp, [0], [message.Timestamp])
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   479
                    if self.CurrentMessage is not None:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   480
                        self.CurrentMessage += 1
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   481
                    else:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   482
                        self.CurrentMessage = 0
982
e3c264099bd0 Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents: 981
diff changeset
   483
                    if self.FilterLogMessage(message, timestamp):
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   484
                        return message, 0
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   485
        return None, None
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   486
    
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   487
    def RefreshNewData(self, *args, **kwargs):
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   488
        if self.HasNewData:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   489
            self.HasNewData = False
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   490
            self.RefreshView()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   491
        DebugViewer.RefreshNewData(self, *args, **kwargs)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   492
    
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   493
    def RefreshView(self):
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   494
        width, height = self.MessagePanel.GetClientSize()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   495
        bitmap = wx.EmptyBitmap(width, height)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   496
        dc = wx.BufferedDC(wx.ClientDC(self.MessagePanel), bitmap)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   497
        dc.Clear()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   498
        dc.BeginDrawing()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   499
        
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   500
        if self.CurrentMessage is not None:
983
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   501
            
993
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   502
            dc.SetFont(self.Font)
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   503
            
983
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   504
            for button in self.LeftButtons + self.RightButtons:
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   505
                button.Draw(dc)
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   506
            
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   507
            message_idx = self.CurrentMessage
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   508
            message = self.LogMessages[message_idx]
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   509
            draw_date = True
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   510
            offset = 5
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   511
            while offset < height and message is not None:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   512
                message.Draw(dc, offset, width, draw_date)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   513
                offset += message.GetHeight(draw_date)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   514
                
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   515
                previous_message, message_idx = self.GetPreviousMessage(message_idx)
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   516
                if previous_message is not None:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   517
                    draw_date = message.Date != previous_message.Date
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   518
                message = previous_message
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   519
        
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   520
        dc.EndDrawing()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   521
        
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   522
        self.MessageScrollBar.RefreshThumbPosition()
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   523
    
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   524
    def IsMessagePanelTop(self, message_idx=None):
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   525
        if message_idx is None:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   526
            message_idx = self.CurrentMessage
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   527
        if message_idx is not None:
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   528
            return self.GetNextMessage(message_idx)[0] is None
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   529
        return True
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   530
    
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   531
    def IsMessagePanelBottom(self, message_idx=None):
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   532
        if message_idx is None:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   533
            message_idx = self.CurrentMessage
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   534
        if message_idx is not None:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   535
            width, height = self.MessagePanel.GetClientSize()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   536
            offset = 5
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   537
            message = self.LogMessages[message_idx]
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   538
            draw_date = True
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   539
            while message is not None and offset < height:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   540
                offset += message.GetHeight(draw_date)
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   541
                previous_message, message_idx = self.GetPreviousMessage(message_idx)
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   542
                if previous_message is not None:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   543
                    draw_date = message.Date != previous_message.Date
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   544
                message = previous_message
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   545
            return offset < height
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   546
        return True
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   547
    
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   548
    def ScrollMessagePanel(self, scroll):
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   549
        if self.CurrentMessage is not None:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   550
            message = self.LogMessages[self.CurrentMessage]
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   551
            while scroll > 0 and message is not None:
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   552
                message, msgidx = self.GetNextMessage(self.CurrentMessage)
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   553
                if message is not None:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   554
                    self.CurrentMessage = msgidx
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   555
                    scroll -= 1
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   556
            while scroll < 0 and message is not None and not self.IsMessagePanelBottom():
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   557
                message, msgidx = self.GetPreviousMessage(self.CurrentMessage)
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   558
                if message is not None:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   559
                    self.CurrentMessage = msgidx
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   560
                    scroll += 1
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   561
            self.RefreshView()
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   562
    
986
b663f099da8a Fixed LogViewer with improvements
Laurent Bessard
parents: 984
diff changeset
   563
    def ScrollMessagePanelByPage(self, page):
b663f099da8a Fixed LogViewer with improvements
Laurent Bessard
parents: 984
diff changeset
   564
        if self.CurrentMessage is not None:
b663f099da8a Fixed LogViewer with improvements
Laurent Bessard
parents: 984
diff changeset
   565
            width, height = self.MessagePanel.GetClientSize()
b663f099da8a Fixed LogViewer with improvements
Laurent Bessard
parents: 984
diff changeset
   566
            message_per_page = max(1, (height - DATE_INFO_SIZE) / MESSAGE_INFO_SIZE - 1)
b663f099da8a Fixed LogViewer with improvements
Laurent Bessard
parents: 984
diff changeset
   567
            self.ScrollMessagePanel(page * message_per_page)
b663f099da8a Fixed LogViewer with improvements
Laurent Bessard
parents: 984
diff changeset
   568
    
982
e3c264099bd0 Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents: 981
diff changeset
   569
    def ScrollMessagePanelByTimestamp(self, seconds):
e3c264099bd0 Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents: 981
diff changeset
   570
        if self.CurrentMessage is not None:
e3c264099bd0 Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents: 981
diff changeset
   571
            current_message = self.LogMessages[self.CurrentMessage]
e3c264099bd0 Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents: 981
diff changeset
   572
            message, msgidx = self.GetMessageByTimestamp(current_message.Timestamp + seconds)
e3c264099bd0 Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents: 981
diff changeset
   573
            if message is None or self.IsMessagePanelBottom(msgidx):
e3c264099bd0 Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents: 981
diff changeset
   574
                self.ScrollToFirst()
e3c264099bd0 Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents: 981
diff changeset
   575
            else:
e3c264099bd0 Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents: 981
diff changeset
   576
                self.CurrentMessage = msgidx
984
2d03056993f6 Fixed bugs with new buttons on Windows
Laurent Bessard
parents: 983
diff changeset
   577
                self.RefreshView()
982
e3c264099bd0 Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents: 981
diff changeset
   578
            
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   579
    def ResetMessagePanel(self):
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   580
        if len(self.LogMessages) > 0:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   581
            self.CurrentMessage = len(self.LogMessages) - 1
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   582
            message = self.LogMessages[self.CurrentMessage]
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   583
            while message is not None and not self.FilterLogMessage(message):
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   584
                message, self.CurrentMessage = self.GetPreviousMessage(self.CurrentMessage)
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   585
            self.RefreshView()
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   586
    
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   587
    def OnMessageFilterChanged(self, event):
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   588
        self.CurrentFilter = self.LevelFilters[self.MessageFilter.GetSelection()]
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   589
        self.ResetMessagePanel()
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   590
        event.Skip()
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   591
    
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   592
    def OnSearchMessageChanged(self, event):
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   593
        self.CurrentSearchValue = self.SearchMessage.GetValue()
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   594
        self.ResetMessagePanel()
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   595
        event.Skip()
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   596
        
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   597
    def OnSearchMessageSearchButtonClick(self, event):
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   598
        self.CurrentSearchValue = self.SearchMessage.GetValue()
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   599
        self.ResetMessagePanel()
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   600
        event.Skip()
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   601
    
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   602
    def OnSearchMessageCancelButtonClick(self, event):
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   603
        self.CurrentSearchValue = ""
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   604
        self.SearchMessage.SetValue("")
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   605
        self.ResetMessagePanel()
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   606
        event.Skip()
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   607
    
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   608
    def GenerateOnDurationButton(self, duration):
983
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   609
        def OnDurationButton():
982
e3c264099bd0 Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents: 981
diff changeset
   610
            self.ScrollMessagePanelByTimestamp(duration)
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   611
        return OnDurationButton
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   612
    
993
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   613
    def GetCopyMessageToClipboardFunction(self, message):
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   614
        def CopyMessageToClipboardFunction(event):
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   615
            self.ParentWindow.SetCopyBuffer(message.GetFullText())
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   616
        return CopyMessageToClipboardFunction
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   617
    
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   618
    def GetMessageByScreenPos(self, posx, posy):
983
7dd481eef3b5 Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents: 982
diff changeset
   619
        if self.CurrentMessage is not None:
986
b663f099da8a Fixed LogViewer with improvements
Laurent Bessard
parents: 984
diff changeset
   620
            width, height = self.MessagePanel.GetClientSize()
b663f099da8a Fixed LogViewer with improvements
Laurent Bessard
parents: 984
diff changeset
   621
            message_idx = self.CurrentMessage
b663f099da8a Fixed LogViewer with improvements
Laurent Bessard
parents: 984
diff changeset
   622
            message = self.LogMessages[message_idx]
b663f099da8a Fixed LogViewer with improvements
Laurent Bessard
parents: 984
diff changeset
   623
            draw_date = True
b663f099da8a Fixed LogViewer with improvements
Laurent Bessard
parents: 984
diff changeset
   624
            offset = 5
b663f099da8a Fixed LogViewer with improvements
Laurent Bessard
parents: 984
diff changeset
   625
            
b663f099da8a Fixed LogViewer with improvements
Laurent Bessard
parents: 984
diff changeset
   626
            while offset < height and message is not None:
b663f099da8a Fixed LogViewer with improvements
Laurent Bessard
parents: 984
diff changeset
   627
                if draw_date:
b663f099da8a Fixed LogViewer with improvements
Laurent Bessard
parents: 984
diff changeset
   628
                    offset += DATE_INFO_SIZE
993
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   629
    
986
b663f099da8a Fixed LogViewer with improvements
Laurent Bessard
parents: 984
diff changeset
   630
                if offset <= posy < offset + MESSAGE_INFO_SIZE:
993
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   631
                    return message
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   632
        
986
b663f099da8a Fixed LogViewer with improvements
Laurent Bessard
parents: 984
diff changeset
   633
                offset += MESSAGE_INFO_SIZE
b663f099da8a Fixed LogViewer with improvements
Laurent Bessard
parents: 984
diff changeset
   634
                
b663f099da8a Fixed LogViewer with improvements
Laurent Bessard
parents: 984
diff changeset
   635
                previous_message, message_idx = self.GetPreviousMessage(message_idx)
b663f099da8a Fixed LogViewer with improvements
Laurent Bessard
parents: 984
diff changeset
   636
                if previous_message is not None:
b663f099da8a Fixed LogViewer with improvements
Laurent Bessard
parents: 984
diff changeset
   637
                    draw_date = message.Date != previous_message.Date
b663f099da8a Fixed LogViewer with improvements
Laurent Bessard
parents: 984
diff changeset
   638
                message = previous_message
993
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   639
        return None
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   640
    
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   641
    def OnMessagePanelLeftUp(self, event):
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   642
        if self.CurrentMessage is not None:
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   643
            posx, posy = event.GetPosition()
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   644
            for button in self.LeftButtons + self.RightButtons:
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   645
                if button.HitTest(posx, posy):
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   646
                    button.ProcessCallback()
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   647
                    break
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   648
        event.Skip()
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   649
    
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   650
    def OnMessagePanelRightUp(self, event):
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   651
        message = self.GetMessageByScreenPos(*event.GetPosition())
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   652
        if message is not None:
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   653
            menu = wx.Menu(title='')
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   654
            
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   655
            new_id = wx.NewId()
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   656
            menu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Copy"))
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   657
            self.Bind(wx.EVT_MENU, self.GetCopyMessageToClipboardFunction(message), id=new_id)
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   658
    
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   659
            self.MessagePanel.PopupMenu(menu)
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   660
            menu.Destroy()
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   661
        event.Skip()
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   662
    
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   663
    def OnMessagePanelLeftDCLick(self, event):
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   664
        message = self.GetMessageByScreenPos(*event.GetPosition())
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   665
        if message is not None:
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   666
            self.SearchMessage.SetFocus()
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   667
            self.SearchMessage.SetValue(message.Message)
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   668
        event.Skip()
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   669
    
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   670
    def ResetMessageToolTip(self):
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   671
        if self.MessageToolTip is not None:
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   672
            self.MessageToolTip.Destroy()
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   673
            self.MessageToolTip = None
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   674
    
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   675
    def OnMessageToolTipTimer(self, event):
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   676
        if self.LastMousePos is not None:
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   677
            message = self.GetMessageByScreenPos(*self.LastMousePos)
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   678
            if message is not None:
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   679
                tooltip_pos = self.MessagePanel.ClientToScreen(self.LastMousePos)
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   680
                tooltip_pos.x += 10
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   681
                tooltip_pos.y += 10
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   682
                self.MessageToolTip = ToolTip(self.MessagePanel, message.GetFullText(), False)
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   683
                self.MessageToolTip.SetFont(self.Font)
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   684
                self.MessageToolTip.MoveToolTip(tooltip_pos)
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   685
                self.MessageToolTip.Show()
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   686
        event.Skip()
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   687
    
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   688
    def OnMessagePanelMotion(self, event):
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   689
        if not event.Dragging():
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   690
            self.ResetMessageToolTip()
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   691
            self.LastMousePos = event.GetPosition()
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   692
            self.MessageToolTipTimer.Start(int(TOOLTIP_WAIT_PERIOD * 1000), oneShot=True)
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   693
        event.Skip()
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   694
        
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   695
    def OnMessagePanelLeaveWindow(self, event):
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   696
        self.ResetMessageToolTip()
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   697
        self.LastMousePos = None
7fbde4a19ec3 Improved Log Viewer functionalities
Laurent Bessard
parents: 988
diff changeset
   698
        self.MessageToolTipTimer.Stop()
986
b663f099da8a Fixed LogViewer with improvements
Laurent Bessard
parents: 984
diff changeset
   699
        event.Skip()
b663f099da8a Fixed LogViewer with improvements
Laurent Bessard
parents: 984
diff changeset
   700
    
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   701
    def OnMessagePanelMouseWheel(self, event):
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   702
        self.ScrollMessagePanel(event.GetWheelRotation() / event.GetWheelDelta())
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   703
        event.Skip()
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   704
    
988
30e7571c10d0 Reduced flicker on LogViewer and DebugGraphPanel on Windows
Laurent Bessard
parents: 987
diff changeset
   705
    def OnMessagePanelEraseBackground(self, event):
30e7571c10d0 Reduced flicker on LogViewer and DebugGraphPanel on Windows
Laurent Bessard
parents: 987
diff changeset
   706
        pass
30e7571c10d0 Reduced flicker on LogViewer and DebugGraphPanel on Windows
Laurent Bessard
parents: 987
diff changeset
   707
    
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   708
    def OnMessagePanelPaint(self, event):
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   709
        self.RefreshView()
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   710
        event.Skip()
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   711
    
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   712
    def OnMessagePanelResize(self, event):
984
2d03056993f6 Fixed bugs with new buttons on Windows
Laurent Bessard
parents: 983
diff changeset
   713
        width, height = self.MessagePanel.GetClientSize()
2d03056993f6 Fixed bugs with new buttons on Windows
Laurent Bessard
parents: 983
diff changeset
   714
        offset = 2
2d03056993f6 Fixed bugs with new buttons on Windows
Laurent Bessard
parents: 983
diff changeset
   715
        for button in self.LeftButtons:
2d03056993f6 Fixed bugs with new buttons on Windows
Laurent Bessard
parents: 983
diff changeset
   716
            button.SetPosition(offset, 2)
2d03056993f6 Fixed bugs with new buttons on Windows
Laurent Bessard
parents: 983
diff changeset
   717
            w, h = button.GetSize()
2d03056993f6 Fixed bugs with new buttons on Windows
Laurent Bessard
parents: 983
diff changeset
   718
            offset += w + 2
2d03056993f6 Fixed bugs with new buttons on Windows
Laurent Bessard
parents: 983
diff changeset
   719
        offset = width - 2
2d03056993f6 Fixed bugs with new buttons on Windows
Laurent Bessard
parents: 983
diff changeset
   720
        for button in self.RightButtons:
2d03056993f6 Fixed bugs with new buttons on Windows
Laurent Bessard
parents: 983
diff changeset
   721
            w, h = button.GetSize()
2d03056993f6 Fixed bugs with new buttons on Windows
Laurent Bessard
parents: 983
diff changeset
   722
            button.SetPosition(offset - w, 2)
2d03056993f6 Fixed bugs with new buttons on Windows
Laurent Bessard
parents: 983
diff changeset
   723
            offset -= w + 2
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   724
        if self.IsMessagePanelBottom():
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   725
            self.ScrollToFirst()
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   726
        else:
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   727
            self.RefreshView()
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   728
        event.Skip()
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   729
    
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   730
    def OnScrollTimer(self, event):
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   731
        if self.ScrollSpeed != 0.:
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   732
            speed_norm = abs(self.ScrollSpeed)
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   733
            period = REFRESH_PERIOD / speed_norm
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   734
            self.ScrollMessagePanel(-speed_norm / self.ScrollSpeed)
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   735
            self.LastStartTime = gettime()
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   736
            self.ScrollTimer.Start(int(period * 1000), True)
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   737
        event.Skip()
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   738
    
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   739
    def SetScrollSpeed(self, speed):
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   740
        if speed == 0.:
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   741
            self.ScrollTimer.Stop()
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   742
        else:
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   743
            speed_norm = abs(speed)
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   744
            period = REFRESH_PERIOD / speed_norm
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   745
            current_time = gettime()
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   746
            if self.LastStartTime is not None:
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   747
                elapsed_time = current_time - self.LastStartTime
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   748
                if elapsed_time > period:
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   749
                    self.ScrollMessagePanel(-speed_norm / speed)
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   750
                    self.LastStartTime = current_time
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   751
                else:
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   752
                    period -= elapsed_time
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   753
            else:
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   754
                self.LastStartTime = current_time
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   755
            self.ScrollTimer.Start(int(period * 1000), True)
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   756
        self.ScrollSpeed = speed    
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   757
    
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   758
    def ScrollToLast(self):
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   759
        if len(self.LogMessages) > 0:
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   760
            self.CurrentMessage = len(self.LogMessages) - 1
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   761
            message = self.LogMessages[self.CurrentMessage]
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   762
            if not self.FilterLogMessage(message):
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   763
                message, self.CurrentMessage = self.GetPreviousMessage(self.CurrentMessage)
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   764
            self.RefreshView()
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   765
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   766
    def ScrollToFirst(self):
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   767
        if len(self.LogMessages) > 0:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   768
            message_idx = 0
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   769
            message = self.LogMessages[message_idx]
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   770
            if not self.FilterLogMessage(message):
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   771
                next_message, msgidx = self.GetNextMessage(message_idx)
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   772
                if next_message is not None:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   773
                    message_idx = msgidx
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   774
                    message = next_message
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   775
            while message is not None:
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   776
                message, msgidx = self.GetPreviousMessage(message_idx)
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   777
                if message is not None:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   778
                    message_idx = msgidx
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   779
            message = self.LogMessages[message_idx]
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   780
            if self.FilterLogMessage(message):
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   781
                while message is not None:
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   782
                    message, msgidx = self.GetNextMessage(message_idx)
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   783
                    if message is not None:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   784
                        if not self.IsMessagePanelBottom(msgidx):
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   785
                            break
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   786
                        message_idx = msgidx
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   787
                self.CurrentMessage = message_idx
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   788
            else:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   789
                self.CurrentMessage = None
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   790
            self.RefreshView()