controls/LogViewer.py
author Laurent Bessard
Thu, 14 Mar 2013 17:51:30 +0100
changeset 981 fc671a3e95a9
parent 979 1a68113a323d
child 982 e3c264099bd0
permissions -rw-r--r--
Fixed LogViewer scrollbar and scroll methods
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
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    27
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    28
import wx
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    29
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    30
from graphics import DebugViewer, REFRESH_PERIOD
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    31
from targets.typemapping import LogLevelsCount, LogLevels
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    32
from util.BitmapLibrary import GetBitmap
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    33
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
    34
THUMB_SIZE_RATIO = 1. / 8.
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    35
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    36
class MyScrollBar(wx.Panel):
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    37
    
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    38
    def __init__(self, parent, size):
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    39
        wx.Panel.__init__(self, parent, size=size)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    40
        self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    41
        self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    42
        self.Bind(wx.EVT_MOTION, self.OnMotion)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    43
        self.Bind(wx.EVT_PAINT, self.OnPaint)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    44
        self.Bind(wx.EVT_SIZE, self.OnResize)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    45
        
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
    46
        self.ThumbPosition = 0. # -1 <= ThumbPosition <= 1
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
    47
        self.ThumbScrollingStartPos = None
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 GetRangeRect(self):
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    50
        width, height = self.GetClientSize()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    51
        return wx.Rect(0, width, width, height - 2 * width)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    52
    
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    53
    def GetThumbRect(self):
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    54
        width, height = self.GetClientSize()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    55
        range_rect = self.GetRangeRect()
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
    56
        thumb_size = range_rect.height * THUMB_SIZE_RATIO
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
    57
        thumb_range = range_rect.height - thumb_size
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
    58
        thumb_center_position = (thumb_size + (self.ThumbPosition + 1) * thumb_range) / 2.
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
    59
        thumb_start = int(thumb_center_position - thumb_size / 2.)
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
    60
        thumb_end = int(thumb_center_position + thumb_size / 2.)
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
    61
        return wx.Rect(1, range_rect.y + thumb_start, width - 1, thumb_end - thumb_start)
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
    62
    
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
    63
    def RefreshThumbPosition(self, thumb_position=None):
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
    64
        if thumb_position is None:
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
    65
            thumb_position = self.ThumbPosition
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    66
        if self.Parent.IsMessagePanelTop():
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
    67
            thumb_position = max(0., thumb_position)
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    68
        if self.Parent.IsMessagePanelBottom():
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
    69
            thumb_position = min(0., thumb_position)
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
    70
        if thumb_position != self.ThumbPosition:
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
    71
            self.ThumbPosition = thumb_position
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
    72
            self.Parent.SetScrollSpeed(self.ThumbPosition)
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
    73
        self.Refresh()
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    74
    
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    75
    def OnLeftDown(self, event):
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    76
        self.CaptureMouse()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    77
        posx, posy = event.GetPosition()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    78
        width, height = self.GetClientSize()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    79
        range_rect = self.GetRangeRect()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    80
        thumb_rect = self.GetThumbRect()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    81
        if range_rect.InsideXY(posx, posy):
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    82
            if thumb_rect.InsideXY(posx, posy):
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
    83
                self.ThumbScrollingStartPos = wx.Point(posx, posy)
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    84
            elif posy < thumb_rect.y:
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
    85
                self.Parent.ScrollToLast()
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    86
            elif posy > thumb_rect.y + thumb_rect.height:
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
    87
                self.Parent.ScrollToFirst()
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    88
        elif posy < width:
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
    89
            pass
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    90
        elif posy > height - width:
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
    91
            pass
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    92
        event.Skip()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    93
        
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    94
    def OnLeftUp(self, event):
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
    95
        self.ThumbScrollingStartPos = None
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
    96
        self.RefreshThumbPosition(0.)
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    97
        if self.HasCapture():
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    98
            self.ReleaseMouse()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
    99
        event.Skip()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   100
        
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   101
    def OnMotion(self, event):
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   102
        if event.Dragging() and self.ThumbScrollingStartPos is not None:
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   103
            posx, posy = event.GetPosition()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   104
            width, height = self.GetClientSize()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   105
            range_rect = self.GetRangeRect()
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   106
            thumb_size = range_rect.height * THUMB_SIZE_RATIO
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   107
            thumb_range = range_rect.height - thumb_size
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   108
            self.RefreshThumbPosition(
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   109
                max(-1., min((posy - self.ThumbScrollingStartPos.y) * 2. / thumb_range, 1.)))
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   110
        event.Skip()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   111
    
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   112
    def OnResize(self, event):
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   113
        self.Refresh()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   114
        event.Skip()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   115
    
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   116
    def OnPaint(self, event):
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   117
        dc = wx.BufferedPaintDC(self)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   118
        dc.Clear()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   119
        dc.BeginDrawing()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   120
        
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   121
        width, height = self.GetClientSize()
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   122
        
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   123
        thumb_rect = self.GetThumbRect()
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   124
        exclusion_rect = wx.Rect(thumb_rect.x, thumb_rect.y,
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   125
                                 thumb_rect.width, thumb_rect.height)
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   126
        if self.Parent.IsMessagePanelTop():
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   127
            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
   128
        if self.Parent.IsMessagePanelBottom():
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   129
            exclusion_rect.height = height - width - exclusion_rect.y
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   130
        if exclusion_rect != thumb_rect:
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   131
            colour = wx.NamedColour("LIGHT GREY")
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   132
            dc.SetPen(wx.Pen(colour))
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   133
            dc.SetBrush(wx.Brush(colour))
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   134
        
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   135
            dc.DrawRectangle(exclusion_rect.x, exclusion_rect.y, 
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   136
                             exclusion_rect.width, exclusion_rect.height)
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   137
        
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   138
        dc.SetPen(wx.GREY_PEN)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   139
        dc.SetBrush(wx.GREY_BRUSH)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   140
        
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   141
        dc.DrawPolygon([wx.Point(width / 2, 1),
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   142
                        wx.Point(1, width - 2),
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   143
                        wx.Point(width - 1, width - 2)])
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   144
        
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   145
        dc.DrawPolygon([wx.Point(width / 2, height - 1),
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   146
                        wx.Point(2, height - width + 1),
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   147
                        wx.Point(width - 1, height - width + 1)])
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   148
            
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   149
        dc.DrawRectangle(thumb_rect.x, thumb_rect.y, 
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   150
                         thumb_rect.width, thumb_rect.height)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   151
        
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   152
        dc.EndDrawing()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   153
        event.Skip()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   154
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   155
DATE_INFO_SIZE = 10
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   156
MESSAGE_INFO_SIZE = 30
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   157
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   158
class LogMessage:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   159
    
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   160
    def __init__(self, tv_sec, tv_nsec, level, level_bitmap, msg):
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   161
        self.Date = datetime.fromtimestamp(tv_sec)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   162
        self.Seconds = self.Date.second + tv_nsec * 1e-9
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   163
        self.Date = self.Date.replace(second=0)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   164
        self.Level = level
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   165
        self.LevelBitmap = level_bitmap
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   166
        self.Message = msg
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   167
        self.DrawDate = True
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   168
    
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   169
    def __cmp__(self, other):
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   170
        if self.Date == other.Date:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   171
            return cmp(self.Seconds, other.Seconds)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   172
        return cmp(self.Date, other.Date)
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
    def Draw(self, dc, offset, width, draw_date):
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   175
        if draw_date:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   176
            datetime_text = self.Date.strftime("%d/%m/%y %H:%M")
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   177
            dw, dh = dc.GetTextExtent(datetime_text)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   178
            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
   179
            offset += DATE_INFO_SIZE
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   180
        
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   181
        seconds_text = "%12.9f" % self.Seconds
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   182
        sw, sh = dc.GetTextExtent(seconds_text)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   183
        dc.DrawText(seconds_text, 5, offset + (MESSAGE_INFO_SIZE - sh) / 2)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   184
        
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   185
        bw, bh = self.LevelBitmap.GetWidth(), self.LevelBitmap.GetHeight()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   186
        dc.DrawBitmap(self.LevelBitmap, 10 + sw, offset + (MESSAGE_INFO_SIZE - bh) / 2)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   187
        
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   188
        mw, mh = dc.GetTextExtent(self.Message)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   189
        dc.DrawText(self.Message, 15 + sw + bw, offset + (MESSAGE_INFO_SIZE - mh) / 2)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   190
        
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   191
    def GetHeight(self, draw_date):
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   192
        if draw_date:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   193
            return DATE_INFO_SIZE + MESSAGE_INFO_SIZE
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   194
        return MESSAGE_INFO_SIZE
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   195
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   196
SECOND = 1
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   197
MINUTE = 60 * SECOND
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   198
HOUR = 60 * MINUTE
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   199
DAY = 24 * HOUR
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   200
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   201
CHANGE_TIMESTAMP_BUTTONS = [(_("1d"), DAY),
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   202
                            (_("1h"), HOUR),
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   203
                            (_("1m"), MINUTE),
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   204
                            (_("1s"), SECOND)]
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   205
REVERSE_CHANGE_TIMESTAMP_BUTTONS = CHANGE_TIMESTAMP_BUTTONS[:]
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   206
REVERSE_CHANGE_TIMESTAMP_BUTTONS.reverse()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   207
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   208
class LogViewer(DebugViewer, wx.Panel):
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   209
    
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   210
    def __init__(self, parent, window):
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   211
        wx.Panel.__init__(self, parent, style=wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   212
        DebugViewer.__init__(self, None, False, False)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   213
        
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   214
        main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   215
        main_sizer.AddGrowableCol(0)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   216
        main_sizer.AddGrowableRow(1)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   217
        
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   218
        filter_sizer = wx.BoxSizer(wx.HORIZONTAL)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   219
        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
   220
        
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   221
        self.MessageFilter = wx.ComboBox(self, style=wx.CB_READONLY)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   222
        self.MessageFilter.Append(_("All"))
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   223
        levels = LogLevels[:3]
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   224
        levels.reverse()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   225
        for level in levels:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   226
            self.MessageFilter.Append(_(level))
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   227
        self.Bind(wx.EVT_COMBOBOX, self.OnMessageFilterChanged, self.MessageFilter)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   228
        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
   229
        
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   230
        self.SearchMessage = wx.SearchCtrl(self, style=wx.TE_PROCESS_ENTER)
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   231
        self.SearchMessage.ShowSearchButton(True)
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   232
        self.SearchMessage.ShowCancelButton(True)
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   233
        self.Bind(wx.EVT_TEXT_ENTER, self.OnSearchMessageChanged, self.SearchMessage)
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   234
        self.Bind(wx.EVT_SEARCHCTRL_SEARCH_BTN, 
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   235
              self.OnSearchMessageSearchButtonClick, self.SearchMessage)
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   236
        self.Bind(wx.EVT_SEARCHCTRL_CANCEL_BTN, 
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   237
              self.OnSearchMessageCancelButtonClick, self.SearchMessage)
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   238
        filter_sizer.AddWindow(self.SearchMessage, 3, flag=wx.GROW)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   239
        
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   240
        message_panel_sizer = wx.FlexGridSizer(cols=3, hgap=0, rows=1, vgap=0)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   241
        message_panel_sizer.AddGrowableCol(1)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   242
        message_panel_sizer.AddGrowableRow(0)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   243
        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
   244
        
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   245
        buttons_sizer = wx.BoxSizer(wx.VERTICAL)
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   246
        for label, callback in [("+" + text, self.GenerateOnDurationButton(duration)) 
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   247
                                for text, duration in CHANGE_TIMESTAMP_BUTTONS] +\
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   248
                               [("-" + text, self.GenerateOnDurationButton(-duration)) 
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   249
                                for text, duration in REVERSE_CHANGE_TIMESTAMP_BUTTONS]:
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   250
            button = wx.Button(self, label=label)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   251
            self.Bind(wx.EVT_BUTTON, callback, button)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   252
            buttons_sizer.AddWindow(button, 1, wx.ALIGN_CENTER_VERTICAL)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   253
        message_panel_sizer.AddSizer(buttons_sizer, flag=wx.GROW)
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
        self.MessagePanel = wx.Panel(self)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   256
        if wx.Platform == '__WXMSW__':
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   257
            self.Font = wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL, faceName='Courier New')
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   258
        else:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   259
            self.Font = wx.Font(12, wx.SWISS, wx.NORMAL, wx.NORMAL, faceName='Courier')    
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   260
        self.MessagePanel.Bind(wx.EVT_MOUSEWHEEL, self.OnMessagePanelMouseWheel)
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   261
        self.MessagePanel.Bind(wx.EVT_PAINT, self.OnMessagePanelPaint)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   262
        self.MessagePanel.Bind(wx.EVT_SIZE, self.OnMessagePanelResize)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   263
        message_panel_sizer.AddWindow(self.MessagePanel, flag=wx.GROW)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   264
        
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   265
        self.MessageScrollBar = MyScrollBar(self, wx.Size(16, -1))
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   266
        message_panel_sizer.AddWindow(self.MessageScrollBar, flag=wx.GROW)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   267
        
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   268
        self.SetSizer(main_sizer)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   269
    
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   270
        self.MessageFilter.SetSelection(0)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   271
        self.LogSource = None
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   272
        self.ResetLogMessages()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   273
        self.ParentWindow = window
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   274
    
979
1a68113a323d Fixed conflicting icon names on Windows
Laurent Bessard
parents: 978
diff changeset
   275
        self.LevelIcons = [GetBitmap("LOG_" + level) for level in LogLevels]
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   276
        self.LevelFilters = [range(i) for i in xrange(4, 0, -1)]
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   277
        self.CurrentFilter = self.LevelFilters[0]
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   278
        self.CurrentSearchValue = ""
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   279
        
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   280
        self.ScrollSpeed = 0.
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   281
        self.LastStartTime = None
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   282
        self.ScrollTimer = wx.Timer(self, -1)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   283
        self.Bind(wx.EVT_TIMER, self.OnScrollTimer, self.ScrollTimer)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   284
    
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   285
    def __del__(self):
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   286
        self.ScrollTimer.Stop()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   287
    
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   288
    def ResetLogMessages(self):
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   289
        self.previous_log_count = [None]*LogLevelsCount
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   290
        self.OldestMessages = []
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   291
        self.LogMessages = []
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   292
        self.CurrentMessage = None
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   293
        self.HasNewData = False
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   294
    
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   295
    def SetLogSource(self, log_source):
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   296
        self.LogSource = log_source
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   297
        if log_source is not None:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   298
            self.ResetLogMessages()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   299
            self.RefreshView()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   300
    
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   301
    def GetLogMessageFromSource(self, msgidx, level):
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   302
        if self.LogSource is not None:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   303
            answer = self.LogSource.GetLogMessage(level, msgidx)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   304
            if answer is not None:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   305
                msg, tick, tv_sec, tv_nsec = answer
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   306
                return LogMessage(tv_sec, tv_nsec, level, self.LevelIcons[level], msg)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   307
        return None
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   308
    
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   309
    def SetLogCounters(self, log_count):
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   310
        new_messages = []
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   311
        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
   312
            if count is not None and prev != count:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   313
                if prev is None:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   314
                    dump_end = count - 2
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   315
                else:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   316
                    dump_end = prev - 1
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   317
                for msgidx in xrange(count-1, dump_end,-1):
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   318
                    new_message = self.GetLogMessageFromSource(msgidx, level)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   319
                    if new_message is not None:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   320
                        if prev is None:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   321
                            self.OldestMessages.append((msgidx, new_message))
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   322
                            if len(new_messages) == 0 or new_message > new_messages[0]:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   323
                                new_messages = [new_message]
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   324
                        else:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   325
                            new_messages.insert(0, new_message)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   326
                    else:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   327
                        if prev is None:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   328
                            self.OldestMessages.append((-1, None))
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   329
                        break
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   330
                self.previous_log_count[level] = count
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   331
        new_messages.sort()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   332
        if len(new_messages) > 0:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   333
            self.HasNewData = True
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   334
            old_length = len(self.LogMessages)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   335
            for new_message in new_messages:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   336
                self.LogMessages.append(new_message)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   337
            if self.CurrentMessage is None or self.CurrentMessage == old_length - 1:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   338
                self.CurrentMessage = len(self.LogMessages) - 1
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   339
            self.NewDataAvailable(None)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   340
    
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   341
    def FilterLogMessage(self, message):
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   342
        return message.Level in self.CurrentFilter and message.Message.find(self.CurrentSearchValue) != -1
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   343
    
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   344
    def GetNextMessage(self, msgidx):
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   345
        while msgidx < len(self.LogMessages) - 1:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   346
            message = self.LogMessages[msgidx + 1]
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   347
            if self.FilterLogMessage(message):
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   348
                return message, msgidx + 1
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   349
            msgidx += 1
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   350
        return None, None
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   351
    
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   352
    def GetPreviousMessage(self, msgidx):
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   353
        message = None
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   354
        while 0 < msgidx < len(self.LogMessages):
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   355
            message = self.LogMessages[msgidx - 1]
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   356
            if self.FilterLogMessage(message):
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   357
                return message, msgidx - 1
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   358
            msgidx -= 1
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   359
        if len(self.LogMessages) > 0:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   360
            message = self.LogMessages[0]
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   361
            while message is not None:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   362
                level = message.Level
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   363
                oldest_msgidx, oldest_message = self.OldestMessages[level]
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   364
                if oldest_msgidx > 0:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   365
                    old_message = self.GetLogMessageFromSource(oldest_msgidx - 1, level)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   366
                    if old_message is not None:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   367
                        self.OldestMessages[level] = (oldest_msgidx - 1, old_message)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   368
                    else:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   369
                        self.OldestMessages[level] = (-1, None)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   370
                else:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   371
                    self.OldestMessages[level] = (-1, None)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   372
                message = None
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   373
                for idx, msg in self.OldestMessages:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   374
                    if msg is not None and (message is None or msg > message):
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   375
                        message = msg
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   376
                if message is not None:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   377
                    self.LogMessages.insert(0, message)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   378
                    if self.CurrentMessage is not None:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   379
                        self.CurrentMessage += 1
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   380
                    else:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   381
                        self.CurrentMessage = 0
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   382
                    if self.FilterLogMessage(message):
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   383
                        return message, 0
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   384
        return None, None
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 RefreshNewData(self, *args, **kwargs):
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   387
        if self.HasNewData:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   388
            self.HasNewData = False
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   389
            self.RefreshView()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   390
        DebugViewer.RefreshNewData(self, *args, **kwargs)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   391
    
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   392
    def RefreshView(self):
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   393
        width, height = self.MessagePanel.GetClientSize()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   394
        bitmap = wx.EmptyBitmap(width, height)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   395
        dc = wx.BufferedDC(wx.ClientDC(self.MessagePanel), bitmap)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   396
        dc.Clear()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   397
        dc.SetFont(self.Font)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   398
        dc.BeginDrawing()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   399
        
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   400
        if self.CurrentMessage is not None:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   401
            message_idx = self.CurrentMessage
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   402
            message = self.LogMessages[message_idx]
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   403
            draw_date = True
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   404
            offset = 5
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   405
            while offset < height and message is not None:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   406
                message.Draw(dc, offset, width, draw_date)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   407
                offset += message.GetHeight(draw_date)
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   408
                
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   409
                previous_message, message_idx = self.GetPreviousMessage(message_idx)
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   410
                if previous_message is not None:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   411
                    draw_date = message.Date != previous_message.Date
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   412
                message = previous_message
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   413
        
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   414
        dc.EndDrawing()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   415
        
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   416
        self.MessageScrollBar.RefreshThumbPosition()
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   417
    
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   418
    def IsMessagePanelTop(self, message_idx=None):
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   419
        if message_idx is None:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   420
            message_idx = self.CurrentMessage
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   421
        if message_idx is not None:
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   422
            return self.GetNextMessage(message_idx)[0] is None
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   423
        return True
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   424
    
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   425
    def IsMessagePanelBottom(self, message_idx=None):
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   426
        if message_idx is None:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   427
            message_idx = self.CurrentMessage
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   428
        if message_idx is not None:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   429
            width, height = self.MessagePanel.GetClientSize()
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   430
            offset = 5
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   431
            message = self.LogMessages[message_idx]
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   432
            draw_date = True
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   433
            while message is not None and offset < height:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   434
                offset += message.GetHeight(draw_date)
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   435
                previous_message, message_idx = self.GetPreviousMessage(message_idx)
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   436
                if previous_message is not None:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   437
                    draw_date = message.Date != previous_message.Date
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   438
                message = previous_message
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   439
            return offset < height
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   440
        return True
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   441
    
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   442
    def ScrollMessagePanel(self, scroll):
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   443
        if self.CurrentMessage is not None:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   444
            message = self.LogMessages[self.CurrentMessage]
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   445
            while scroll > 0 and message is not None:
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   446
                message, msgidx = self.GetNextMessage(self.CurrentMessage)
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   447
                if message is not None:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   448
                    self.CurrentMessage = msgidx
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   449
                    scroll -= 1
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   450
            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
   451
                message, msgidx = self.GetPreviousMessage(self.CurrentMessage)
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   452
                if message is not None:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   453
                    self.CurrentMessage = msgidx
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   454
                    scroll += 1
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   455
            self.RefreshView()
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   456
    
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   457
    def ResetMessagePanel(self):
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   458
        if len(self.LogMessages) > 0:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   459
            self.CurrentMessage = len(self.LogMessages) - 1
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   460
            message = self.LogMessages[self.CurrentMessage]
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   461
            while message is not None and not self.FilterLogMessage(message):
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   462
                message, self.CurrentMessage = self.GetPreviousMessage(self.CurrentMessage)
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   463
            self.RefreshView()
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   464
    
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   465
    def OnMessageFilterChanged(self, event):
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   466
        self.CurrentFilter = self.LevelFilters[self.MessageFilter.GetSelection()]
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   467
        self.ResetMessagePanel()
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   468
        event.Skip()
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   469
    
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   470
    def OnSearchMessageChanged(self, event):
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   471
        self.CurrentSearchValue = self.SearchMessage.GetValue()
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   472
        self.ResetMessagePanel()
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   473
        event.Skip()
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   474
        
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   475
    def OnSearchMessageSearchButtonClick(self, event):
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   476
        self.CurrentSearchValue = self.SearchMessage.GetValue()
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   477
        self.ResetMessagePanel()
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   478
        event.Skip()
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   479
    
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   480
    def OnSearchMessageCancelButtonClick(self, event):
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   481
        self.CurrentSearchValue = ""
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   482
        self.SearchMessage.SetValue("")
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   483
        self.ResetMessagePanel()
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   484
        event.Skip()
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   485
    
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   486
    def GenerateOnDurationButton(self, duration):
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   487
        def OnDurationButton(event):
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   488
            event.Skip()
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   489
        return OnDurationButton
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   490
    
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   491
    def OnMessagePanelMouseWheel(self, event):
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   492
        self.ScrollMessagePanel(event.GetWheelRotation() / event.GetWheelDelta())
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   493
        event.Skip()
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   494
    
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   495
    def OnMessagePanelPaint(self, event):
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   496
        self.RefreshView()
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   497
        event.Skip()
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   498
    
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   499
    def OnMessagePanelResize(self, event):
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   500
        if self.IsMessagePanelBottom():
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   501
            self.ScrollToFirst()
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   502
        else:
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   503
            self.RefreshView()
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   504
        event.Skip()
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   505
    
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   506
    def OnScrollTimer(self, event):
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   507
        if self.ScrollSpeed != 0.:
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   508
            speed_norm = abs(self.ScrollSpeed)
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   509
            period = REFRESH_PERIOD / speed_norm
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   510
            self.ScrollMessagePanel(-speed_norm / self.ScrollSpeed)
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   511
            self.LastStartTime = gettime()
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   512
            self.ScrollTimer.Start(int(period * 1000), True)
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   513
        event.Skip()
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   514
    
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   515
    def SetScrollSpeed(self, speed):
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   516
        if speed == 0.:
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   517
            self.ScrollTimer.Stop()
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   518
        else:
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   519
            speed_norm = abs(speed)
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   520
            period = REFRESH_PERIOD / speed_norm
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   521
            current_time = gettime()
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   522
            if self.LastStartTime is not None:
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   523
                elapsed_time = current_time - self.LastStartTime
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   524
                if elapsed_time > period:
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   525
                    self.ScrollMessagePanel(-speed_norm / speed)
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   526
                    self.LastStartTime = current_time
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   527
                else:
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   528
                    period -= elapsed_time
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   529
            else:
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   530
                self.LastStartTime = current_time
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   531
            self.ScrollTimer.Start(int(period * 1000), True)
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   532
        self.ScrollSpeed = speed    
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   533
    
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   534
    def ScrollToLast(self):
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   535
        if len(self.LogMessages) > 0:
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   536
            self.CurrentMessage = len(self.LogMessages) - 1
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   537
            message = self.LogMessages[self.CurrentMessage]
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   538
            if not self.FilterLogMessage(message):
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   539
                message, self.CurrentMessage = self.GetPreviousMessage(self.CurrentMessage)
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   540
            self.RefreshView()
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   541
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   542
    def ScrollToFirst(self):
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   543
        if len(self.LogMessages) > 0:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   544
            message_idx = 0
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   545
            message = self.LogMessages[message_idx]
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   546
            if not self.FilterLogMessage(message):
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   547
                next_message, msgidx = self.GetNextMessage(message_idx)
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   548
                if next_message is not None:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   549
                    message_idx = msgidx
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   550
                    message = next_message
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   551
            while message is not None:
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   552
                message, msgidx = self.GetPreviousMessage(message_idx)
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
                    message_idx = msgidx
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   555
            message = self.LogMessages[message_idx]
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   556
            if self.FilterLogMessage(message):
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   557
                while message is not None:
981
fc671a3e95a9 Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents: 979
diff changeset
   558
                    message, msgidx = self.GetNextMessage(message_idx)
978
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   559
                    if message is not None:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   560
                        if not self.IsMessagePanelBottom(msgidx):
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   561
                            break
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   562
                        message_idx = msgidx
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   563
                self.CurrentMessage = message_idx
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   564
            else:
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   565
                self.CurrentMessage = None
3290eff761f1 Added LogViewer panel in bottom notebook
Laurent Bessard
parents:
diff changeset
   566
            self.RefreshView()