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