author | Laurent Bessard |
Thu, 16 May 2013 15:45:45 +0200 | |
changeset 1161 | 2d6ec60c48de |
parent 1094 | fe6dd066fd95 |
child 1169 | 53e4a2b775a7 |
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 |
||
993 | 31 |
from graphics import DebugViewer, REFRESH_PERIOD, ToolTip, TOOLTIP_WAIT_PERIOD |
978 | 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 |
|
993 | 37 |
def ArrowPoints(direction, width, height, xoffset, yoffset): |
986 | 38 |
if direction == wx.TOP: |
993 | 39 |
return [wx.Point(xoffset + 1, yoffset + height - 2), |
40 |
wx.Point(xoffset + width / 2, yoffset + 1), |
|
41 |
wx.Point(xoffset + width - 1, yoffset + height - 2)] |
|
986 | 42 |
else: |
993 | 43 |
return [wx.Point(xoffset + 1, yoffset - height + 1), |
44 |
wx.Point(xoffset + width / 2, yoffset - 2), |
|
45 |
wx.Point(xoffset + width - 1, yoffset - height + 1)] |
|
986 | 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 |
|
993 | 140 |
gc.SetPen(wx.Pen(wx.NamedColour("GREY"), 3)) |
987
7ca88194ae89
Improved graphics of LogViewer scrollbar to be anti-aliased
Laurent Bessard
parents:
986
diff
changeset
|
141 |
gc.SetBrush(wx.GREY_BRUSH) |
7ca88194ae89
Improved graphics of LogViewer scrollbar to be anti-aliased
Laurent Bessard
parents:
986
diff
changeset
|
142 |
|
993 | 143 |
gc.DrawLines(ArrowPoints(wx.TOP, width * 0.75, width * 0.5, 2, (width + height) / 4 - 3)) |
144 |
gc.DrawLines(ArrowPoints(wx.TOP, width * 0.75, width * 0.5, 2, (width + height) / 4 + 3)) |
|
145 |
||
146 |
gc.DrawLines(ArrowPoints(wx.BOTTOM, width * 0.75, width * 0.5, 2, (height * 3 - width) / 4 + 3)) |
|
147 |
gc.DrawLines(ArrowPoints(wx.BOTTOM, width * 0.75, width * 0.5, 2, (height * 3 - width) / 4 - 3)) |
|
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 |
|
993 | 167 |
gc.DrawPolygon(ArrowPoints(wx.TOP, width, width, 0, 0)) |
168 |
||
169 |
gc.DrawPolygon(ArrowPoints(wx.BOTTOM, width, width, 0, height)) |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
170 |
|
987
7ca88194ae89
Improved graphics of LogViewer scrollbar to be anti-aliased
Laurent Bessard
parents:
986
diff
changeset
|
171 |
gc.DrawRectangle(thumb_rect.x, thumb_rect.y, |
978 | 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 |
self.Label = label |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
185 |
self.Shown = True |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
186 |
self.Callback = callback |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
187 |
|
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
188 |
def __del__(self): |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
189 |
self.callback = None |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
190 |
|
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
191 |
def GetSize(self): |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
192 |
return self.Size |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
193 |
|
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
194 |
def SetPosition(self, x, y): |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
195 |
self.Position = wx.Point(x, y) |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
196 |
|
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
197 |
def HitTest(self, x, y): |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
198 |
rect = wx.Rect(self.Position.x, self.Position.y, |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
199 |
self.Size.width, self.Size.height) |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
200 |
if rect.InsideXY(x, y): |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
201 |
return True |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
202 |
return False |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
203 |
|
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
204 |
def ProcessCallback(self): |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
205 |
if self.Callback is not None: |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
206 |
wx.CallAfter(self.Callback) |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
207 |
|
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
208 |
def Draw(self, dc): |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
209 |
dc.SetPen(wx.TRANSPARENT_PEN) |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
210 |
dc.SetBrush(wx.Brush(wx.NamedColour("LIGHT GREY"))) |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
211 |
|
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
212 |
dc.DrawRectangle(self.Position.x, self.Position.y, |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
213 |
self.Size.width, self.Size.height) |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
214 |
|
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
215 |
w, h = dc.GetTextExtent(self.Label) |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
216 |
dc.DrawText(self.Label, |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
217 |
self.Position.x + (self.Size.width - w) / 2, |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
218 |
self.Position.y + (self.Size.height - h) / 2) |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
219 |
|
978 | 220 |
DATE_INFO_SIZE = 10 |
997 | 221 |
MESSAGE_INFO_SIZE = 18 |
978 | 222 |
|
223 |
class LogMessage: |
|
224 |
||
225 |
def __init__(self, tv_sec, tv_nsec, level, level_bitmap, msg): |
|
1076
2a02c6404124
Fixed bug in displayed datetime, using local timezone instead of UTC
Laurent Bessard
parents:
1071
diff
changeset
|
226 |
self.Date = datetime.utcfromtimestamp(tv_sec) |
978 | 227 |
self.Seconds = self.Date.second + tv_nsec * 1e-9 |
228 |
self.Date = self.Date.replace(second=0) |
|
982
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
229 |
self.Timestamp = tv_sec + tv_nsec * 1e-9 |
978 | 230 |
self.Level = level |
231 |
self.LevelBitmap = level_bitmap |
|
232 |
self.Message = msg |
|
233 |
self.DrawDate = True |
|
234 |
||
235 |
def __cmp__(self, other): |
|
236 |
if self.Date == other.Date: |
|
237 |
return cmp(self.Seconds, other.Seconds) |
|
238 |
return cmp(self.Date, other.Date) |
|
239 |
||
993 | 240 |
def GetFullText(self): |
241 |
date = self.Date.replace(second=int(self.Seconds)) |
|
242 |
nsec = (self.Seconds % 1.) * 1e9 |
|
243 |
return "%s at %s.%9.9d:\n%s" % ( |
|
244 |
LogLevels[self.Level], |
|
245 |
str(date), nsec, |
|
246 |
self.Message) |
|
247 |
||
978 | 248 |
def Draw(self, dc, offset, width, draw_date): |
249 |
if draw_date: |
|
250 |
datetime_text = self.Date.strftime("%d/%m/%y %H:%M") |
|
251 |
dw, dh = dc.GetTextExtent(datetime_text) |
|
252 |
dc.DrawText(datetime_text, (width - dw) / 2, offset + (DATE_INFO_SIZE - dh) / 2) |
|
253 |
offset += DATE_INFO_SIZE |
|
254 |
||
255 |
seconds_text = "%12.9f" % self.Seconds |
|
256 |
sw, sh = dc.GetTextExtent(seconds_text) |
|
257 |
dc.DrawText(seconds_text, 5, offset + (MESSAGE_INFO_SIZE - sh) / 2) |
|
258 |
||
259 |
bw, bh = self.LevelBitmap.GetWidth(), self.LevelBitmap.GetHeight() |
|
260 |
dc.DrawBitmap(self.LevelBitmap, 10 + sw, offset + (MESSAGE_INFO_SIZE - bh) / 2) |
|
261 |
||
993 | 262 |
text = self.Message.replace("\n", " ") |
263 |
mw, mh = dc.GetTextExtent(text) |
|
264 |
dc.DrawText(text, 15 + sw + bw, offset + (MESSAGE_INFO_SIZE - mh) / 2) |
|
978 | 265 |
|
266 |
def GetHeight(self, draw_date): |
|
267 |
if draw_date: |
|
268 |
return DATE_INFO_SIZE + MESSAGE_INFO_SIZE |
|
269 |
return MESSAGE_INFO_SIZE |
|
270 |
||
271 |
SECOND = 1 |
|
272 |
MINUTE = 60 * SECOND |
|
273 |
HOUR = 60 * MINUTE |
|
274 |
DAY = 24 * HOUR |
|
275 |
||
276 |
CHANGE_TIMESTAMP_BUTTONS = [(_("1d"), DAY), |
|
277 |
(_("1h"), HOUR), |
|
986 | 278 |
(_("1m"), MINUTE), |
279 |
(_("1s"), SECOND)] |
|
978 | 280 |
|
281 |
class LogViewer(DebugViewer, wx.Panel): |
|
282 |
||
283 |
def __init__(self, parent, window): |
|
284 |
wx.Panel.__init__(self, parent, style=wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER) |
|
285 |
DebugViewer.__init__(self, None, False, False) |
|
286 |
||
287 |
main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5) |
|
288 |
main_sizer.AddGrowableCol(0) |
|
289 |
main_sizer.AddGrowableRow(1) |
|
290 |
||
291 |
filter_sizer = wx.BoxSizer(wx.HORIZONTAL) |
|
292 |
main_sizer.AddSizer(filter_sizer, border=5, flag=wx.TOP|wx.LEFT|wx.RIGHT|wx.GROW) |
|
293 |
||
294 |
self.MessageFilter = wx.ComboBox(self, style=wx.CB_READONLY) |
|
295 |
self.MessageFilter.Append(_("All")) |
|
296 |
levels = LogLevels[:3] |
|
297 |
levels.reverse() |
|
298 |
for level in levels: |
|
299 |
self.MessageFilter.Append(_(level)) |
|
300 |
self.Bind(wx.EVT_COMBOBOX, self.OnMessageFilterChanged, self.MessageFilter) |
|
1094 | 301 |
filter_sizer.AddWindow(self.MessageFilter, 1, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) |
978 | 302 |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
303 |
self.SearchMessage = wx.SearchCtrl(self, style=wx.TE_PROCESS_ENTER) |
978 | 304 |
self.SearchMessage.ShowSearchButton(True) |
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
305 |
self.SearchMessage.ShowCancelButton(True) |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
306 |
self.Bind(wx.EVT_TEXT_ENTER, self.OnSearchMessageChanged, self.SearchMessage) |
978 | 307 |
self.Bind(wx.EVT_SEARCHCTRL_SEARCH_BTN, |
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
308 |
self.OnSearchMessageSearchButtonClick, self.SearchMessage) |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
309 |
self.Bind(wx.EVT_SEARCHCTRL_CANCEL_BTN, |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
310 |
self.OnSearchMessageCancelButtonClick, self.SearchMessage) |
1094 | 311 |
filter_sizer.AddWindow(self.SearchMessage, 3, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) |
1093 | 312 |
|
313 |
self.CleanButton = wx.lib.buttons.GenBitmapButton(self, bitmap=GetBitmap("Clean"), |
|
314 |
size=wx.Size(28, 28), style=wx.NO_BORDER) |
|
315 |
self.CleanButton.SetToolTipString(_("Clean log messages")) |
|
316 |
self.Bind(wx.EVT_BUTTON, self.OnCleanButton, self.CleanButton) |
|
317 |
filter_sizer.AddWindow(self.CleanButton) |
|
978 | 318 |
|
983
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
319 |
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
|
320 |
message_panel_sizer.AddGrowableCol(0) |
978 | 321 |
message_panel_sizer.AddGrowableRow(0) |
322 |
main_sizer.AddSizer(message_panel_sizer, border=5, flag=wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.GROW) |
|
323 |
||
324 |
self.MessagePanel = wx.Panel(self) |
|
325 |
if wx.Platform == '__WXMSW__': |
|
993 | 326 |
self.Font = wx.Font(8, wx.SWISS, wx.NORMAL, wx.NORMAL, faceName='Courier New') |
978 | 327 |
else: |
993 | 328 |
self.Font = wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL, faceName='Courier') |
984 | 329 |
self.MessagePanel.Bind(wx.EVT_LEFT_UP, self.OnMessagePanelLeftUp) |
993 | 330 |
self.MessagePanel.Bind(wx.EVT_RIGHT_UP, self.OnMessagePanelRightUp) |
986 | 331 |
self.MessagePanel.Bind(wx.EVT_LEFT_DCLICK, self.OnMessagePanelLeftDCLick) |
993 | 332 |
self.MessagePanel.Bind(wx.EVT_MOTION, self.OnMessagePanelMotion) |
333 |
self.MessagePanel.Bind(wx.EVT_LEAVE_WINDOW, self.OnMessagePanelLeaveWindow) |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
334 |
self.MessagePanel.Bind(wx.EVT_MOUSEWHEEL, self.OnMessagePanelMouseWheel) |
988
30e7571c10d0
Reduced flicker on LogViewer and DebugGraphPanel on Windows
Laurent Bessard
parents:
987
diff
changeset
|
335 |
self.MessagePanel.Bind(wx.EVT_ERASE_BACKGROUND, self.OnMessagePanelEraseBackground) |
978 | 336 |
self.MessagePanel.Bind(wx.EVT_PAINT, self.OnMessagePanelPaint) |
337 |
self.MessagePanel.Bind(wx.EVT_SIZE, self.OnMessagePanelResize) |
|
338 |
message_panel_sizer.AddWindow(self.MessagePanel, flag=wx.GROW) |
|
339 |
||
983
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
340 |
self.MessageScrollBar = LogScrollBar(self, wx.Size(16, -1)) |
978 | 341 |
message_panel_sizer.AddWindow(self.MessageScrollBar, flag=wx.GROW) |
342 |
||
343 |
self.SetSizer(main_sizer) |
|
983
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
344 |
|
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
345 |
self.LeftButtons = [] |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
346 |
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
|
347 |
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
|
348 |
self.LeftButtons.append(LogButton(label, callback)) |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
349 |
|
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
350 |
self.RightButtons = [] |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
351 |
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
|
352 |
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
|
353 |
self.RightButtons.append(LogButton(label, callback)) |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
354 |
|
978 | 355 |
self.MessageFilter.SetSelection(0) |
356 |
self.LogSource = None |
|
357 |
self.ResetLogMessages() |
|
358 |
self.ParentWindow = window |
|
359 |
||
979 | 360 |
self.LevelIcons = [GetBitmap("LOG_" + level) for level in LogLevels] |
978 | 361 |
self.LevelFilters = [range(i) for i in xrange(4, 0, -1)] |
362 |
self.CurrentFilter = self.LevelFilters[0] |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
363 |
self.CurrentSearchValue = "" |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
364 |
|
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
365 |
self.ScrollSpeed = 0. |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
366 |
self.LastStartTime = None |
978 | 367 |
self.ScrollTimer = wx.Timer(self, -1) |
368 |
self.Bind(wx.EVT_TIMER, self.OnScrollTimer, self.ScrollTimer) |
|
993 | 369 |
|
370 |
self.LastMousePos = None |
|
371 |
self.MessageToolTip = None |
|
372 |
self.MessageToolTipTimer = wx.Timer(self, -1) |
|
373 |
self.Bind(wx.EVT_TIMER, self.OnMessageToolTipTimer, self.MessageToolTipTimer) |
|
978 | 374 |
|
375 |
def __del__(self): |
|
376 |
self.ScrollTimer.Stop() |
|
377 |
||
378 |
def ResetLogMessages(self): |
|
379 |
self.previous_log_count = [None]*LogLevelsCount |
|
380 |
self.OldestMessages = [] |
|
381 |
self.LogMessages = [] |
|
982
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
382 |
self.LogMessagesTimestamp = numpy.array([]) |
978 | 383 |
self.CurrentMessage = None |
384 |
self.HasNewData = False |
|
385 |
||
386 |
def SetLogSource(self, log_source): |
|
387 |
self.LogSource = log_source |
|
1093 | 388 |
self.CleanButton.Enable(self.LogSource is not None) |
978 | 389 |
if log_source is not None: |
390 |
self.ResetLogMessages() |
|
391 |
self.RefreshView() |
|
392 |
||
393 |
def GetLogMessageFromSource(self, msgidx, level): |
|
394 |
if self.LogSource is not None: |
|
395 |
answer = self.LogSource.GetLogMessage(level, msgidx) |
|
396 |
if answer is not None: |
|
397 |
msg, tick, tv_sec, tv_nsec = answer |
|
398 |
return LogMessage(tv_sec, tv_nsec, level, self.LevelIcons[level], msg) |
|
399 |
return None |
|
400 |
||
401 |
def SetLogCounters(self, log_count): |
|
402 |
new_messages = [] |
|
403 |
for level, count, prev in zip(xrange(LogLevelsCount), log_count, self.previous_log_count): |
|
404 |
if count is not None and prev != count: |
|
405 |
if prev is None: |
|
1093 | 406 |
dump_end = -1 |
978 | 407 |
else: |
408 |
dump_end = prev - 1 |
|
409 |
for msgidx in xrange(count-1, dump_end,-1): |
|
410 |
new_message = self.GetLogMessageFromSource(msgidx, level) |
|
1093 | 411 |
if new_message is None: |
412 |
break |
|
413 |
if prev is None: |
|
414 |
self.OldestMessages.append((msgidx, new_message)) |
|
415 |
if len(new_messages) == 0: |
|
416 |
new_messages = [new_message] |
|
978 | 417 |
else: |
418 |
new_messages.insert(0, new_message) |
|
1093 | 419 |
else: |
420 |
new_messages.insert(0, new_message) |
|
1079
6c8dfc4fc23b
Fixed bug in LogViewer when no Log Messages are available when first SetLogCounters
Laurent Bessard
parents:
1077
diff
changeset
|
421 |
if prev is None and len(self.OldestMessages) <= level: |
6c8dfc4fc23b
Fixed bug in LogViewer when no Log Messages are available when first SetLogCounters
Laurent Bessard
parents:
1077
diff
changeset
|
422 |
self.OldestMessages.append((-1, None)) |
978 | 423 |
self.previous_log_count[level] = count |
424 |
new_messages.sort() |
|
425 |
if len(new_messages) > 0: |
|
426 |
self.HasNewData = True |
|
1071
5e740fe71fbe
Fixed bug in LogViewer when view is filtered and displaying last message and new messages appears
Laurent Bessard
parents:
1020
diff
changeset
|
427 |
if self.CurrentMessage is not None: |
5e740fe71fbe
Fixed bug in LogViewer when view is filtered and displaying last message and new messages appears
Laurent Bessard
parents:
1020
diff
changeset
|
428 |
current_is_last = self.GetNextMessage(self.CurrentMessage)[0] is None |
5e740fe71fbe
Fixed bug in LogViewer when view is filtered and displaying last message and new messages appears
Laurent Bessard
parents:
1020
diff
changeset
|
429 |
else: |
5e740fe71fbe
Fixed bug in LogViewer when view is filtered and displaying last message and new messages appears
Laurent Bessard
parents:
1020
diff
changeset
|
430 |
current_is_last = True |
978 | 431 |
for new_message in new_messages: |
432 |
self.LogMessages.append(new_message) |
|
982
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
433 |
self.LogMessagesTimestamp = numpy.append(self.LogMessagesTimestamp, [new_message.Timestamp]) |
1071
5e740fe71fbe
Fixed bug in LogViewer when view is filtered and displaying last message and new messages appears
Laurent Bessard
parents:
1020
diff
changeset
|
434 |
if current_is_last: |
5e740fe71fbe
Fixed bug in LogViewer when view is filtered and displaying last message and new messages appears
Laurent Bessard
parents:
1020
diff
changeset
|
435 |
self.ScrollToLast(False) |
993 | 436 |
self.ResetMessageToolTip() |
437 |
self.MessageToolTipTimer.Stop() |
|
999
cbab4c1635bd
Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents:
997
diff
changeset
|
438 |
self.ParentWindow.SelectTab(self) |
978 | 439 |
self.NewDataAvailable(None) |
440 |
||
982
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
441 |
def FilterLogMessage(self, message, timestamp=None): |
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
442 |
return (message.Level in self.CurrentFilter and |
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
443 |
message.Message.find(self.CurrentSearchValue) != -1 and |
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
444 |
(timestamp is None or message.Timestamp < timestamp)) |
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
445 |
|
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
446 |
def GetMessageByTimestamp(self, timestamp): |
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
447 |
if self.CurrentMessage is not None: |
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
448 |
msgidx = numpy.argmin(abs(self.LogMessagesTimestamp - timestamp)) |
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
449 |
message = self.LogMessages[msgidx] |
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
450 |
if self.FilterLogMessage(message) and message.Timestamp > timestamp: |
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
451 |
return self.GetPreviousMessage(msgidx, timestamp) |
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
452 |
return message, msgidx |
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
453 |
return None, None |
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
454 |
|
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
455 |
def GetNextMessage(self, msgidx): |
978 | 456 |
while msgidx < len(self.LogMessages) - 1: |
457 |
message = self.LogMessages[msgidx + 1] |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
458 |
if self.FilterLogMessage(message): |
978 | 459 |
return message, msgidx + 1 |
460 |
msgidx += 1 |
|
461 |
return None, None |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
462 |
|
982
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
463 |
def GetPreviousMessage(self, msgidx, timestamp=None): |
978 | 464 |
message = None |
465 |
while 0 < msgidx < len(self.LogMessages): |
|
466 |
message = self.LogMessages[msgidx - 1] |
|
982
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
467 |
if self.FilterLogMessage(message, timestamp): |
978 | 468 |
return message, msgidx - 1 |
469 |
msgidx -= 1 |
|
470 |
if len(self.LogMessages) > 0: |
|
471 |
message = self.LogMessages[0] |
|
472 |
while message is not None: |
|
473 |
level = message.Level |
|
474 |
oldest_msgidx, oldest_message = self.OldestMessages[level] |
|
475 |
if oldest_msgidx > 0: |
|
476 |
old_message = self.GetLogMessageFromSource(oldest_msgidx - 1, level) |
|
477 |
if old_message is not None: |
|
478 |
self.OldestMessages[level] = (oldest_msgidx - 1, old_message) |
|
479 |
else: |
|
480 |
self.OldestMessages[level] = (-1, None) |
|
481 |
else: |
|
482 |
self.OldestMessages[level] = (-1, None) |
|
483 |
message = None |
|
484 |
for idx, msg in self.OldestMessages: |
|
485 |
if msg is not None and (message is None or msg > message): |
|
486 |
message = msg |
|
487 |
if message is not None: |
|
488 |
self.LogMessages.insert(0, message) |
|
982
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
489 |
self.LogMessagesTimestamp = numpy.insert(self.LogMessagesTimestamp, [0], [message.Timestamp]) |
978 | 490 |
if self.CurrentMessage is not None: |
491 |
self.CurrentMessage += 1 |
|
492 |
else: |
|
493 |
self.CurrentMessage = 0 |
|
982
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
494 |
if self.FilterLogMessage(message, timestamp): |
978 | 495 |
return message, 0 |
496 |
return None, None |
|
497 |
||
498 |
def RefreshNewData(self, *args, **kwargs): |
|
499 |
if self.HasNewData: |
|
500 |
self.HasNewData = False |
|
501 |
self.RefreshView() |
|
502 |
DebugViewer.RefreshNewData(self, *args, **kwargs) |
|
503 |
||
504 |
def RefreshView(self): |
|
505 |
width, height = self.MessagePanel.GetClientSize() |
|
506 |
bitmap = wx.EmptyBitmap(width, height) |
|
507 |
dc = wx.BufferedDC(wx.ClientDC(self.MessagePanel), bitmap) |
|
508 |
dc.Clear() |
|
509 |
dc.BeginDrawing() |
|
510 |
||
511 |
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
|
512 |
|
993 | 513 |
dc.SetFont(self.Font) |
514 |
||
983
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
515 |
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
|
516 |
button.Draw(dc) |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
517 |
|
978 | 518 |
message_idx = self.CurrentMessage |
519 |
message = self.LogMessages[message_idx] |
|
520 |
draw_date = True |
|
521 |
offset = 5 |
|
522 |
while offset < height and message is not None: |
|
523 |
message.Draw(dc, offset, width, draw_date) |
|
524 |
offset += message.GetHeight(draw_date) |
|
525 |
||
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
526 |
previous_message, message_idx = self.GetPreviousMessage(message_idx) |
978 | 527 |
if previous_message is not None: |
528 |
draw_date = message.Date != previous_message.Date |
|
529 |
message = previous_message |
|
530 |
||
531 |
dc.EndDrawing() |
|
532 |
||
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
533 |
self.MessageScrollBar.RefreshThumbPosition() |
978 | 534 |
|
535 |
def IsMessagePanelTop(self, message_idx=None): |
|
536 |
if message_idx is None: |
|
537 |
message_idx = self.CurrentMessage |
|
538 |
if message_idx is not None: |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
539 |
return self.GetNextMessage(message_idx)[0] is None |
978 | 540 |
return True |
541 |
||
542 |
def IsMessagePanelBottom(self, message_idx=None): |
|
543 |
if message_idx is None: |
|
544 |
message_idx = self.CurrentMessage |
|
545 |
if message_idx is not None: |
|
546 |
width, height = self.MessagePanel.GetClientSize() |
|
547 |
offset = 5 |
|
548 |
message = self.LogMessages[message_idx] |
|
549 |
draw_date = True |
|
550 |
while message is not None and offset < height: |
|
551 |
offset += message.GetHeight(draw_date) |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
552 |
previous_message, message_idx = self.GetPreviousMessage(message_idx) |
978 | 553 |
if previous_message is not None: |
554 |
draw_date = message.Date != previous_message.Date |
|
555 |
message = previous_message |
|
556 |
return offset < height |
|
557 |
return True |
|
558 |
||
559 |
def ScrollMessagePanel(self, scroll): |
|
560 |
if self.CurrentMessage is not None: |
|
561 |
message = self.LogMessages[self.CurrentMessage] |
|
562 |
while scroll > 0 and message is not None: |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
563 |
message, msgidx = self.GetNextMessage(self.CurrentMessage) |
978 | 564 |
if message is not None: |
565 |
self.CurrentMessage = msgidx |
|
566 |
scroll -= 1 |
|
567 |
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
|
568 |
message, msgidx = self.GetPreviousMessage(self.CurrentMessage) |
978 | 569 |
if message is not None: |
570 |
self.CurrentMessage = msgidx |
|
571 |
scroll += 1 |
|
572 |
self.RefreshView() |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
573 |
|
986 | 574 |
def ScrollMessagePanelByPage(self, page): |
575 |
if self.CurrentMessage is not None: |
|
576 |
width, height = self.MessagePanel.GetClientSize() |
|
577 |
message_per_page = max(1, (height - DATE_INFO_SIZE) / MESSAGE_INFO_SIZE - 1) |
|
578 |
self.ScrollMessagePanel(page * message_per_page) |
|
579 |
||
982
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
580 |
def ScrollMessagePanelByTimestamp(self, seconds): |
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
581 |
if self.CurrentMessage is not None: |
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
582 |
current_message = self.LogMessages[self.CurrentMessage] |
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
583 |
message, msgidx = self.GetMessageByTimestamp(current_message.Timestamp + seconds) |
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
584 |
if message is None or self.IsMessagePanelBottom(msgidx): |
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
585 |
self.ScrollToFirst() |
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
586 |
else: |
1020
2d20f25cd39f
Fixed bug log viewer not scrolling when clicking on +1s and +1m when time between 2 message is greater than 1s or 1m
Laurent Bessard
parents:
999
diff
changeset
|
587 |
if seconds > 0 and self.CurrentMessage == msgidx and msgidx < len(self.LogMessages) - 1: |
2d20f25cd39f
Fixed bug log viewer not scrolling when clicking on +1s and +1m when time between 2 message is greater than 1s or 1m
Laurent Bessard
parents:
999
diff
changeset
|
588 |
msgidx += 1 |
982
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
589 |
self.CurrentMessage = msgidx |
984 | 590 |
self.RefreshView() |
982
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
591 |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
592 |
def ResetMessagePanel(self): |
978 | 593 |
if len(self.LogMessages) > 0: |
594 |
self.CurrentMessage = len(self.LogMessages) - 1 |
|
595 |
message = self.LogMessages[self.CurrentMessage] |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
596 |
while message is not None and not self.FilterLogMessage(message): |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
597 |
message, self.CurrentMessage = self.GetPreviousMessage(self.CurrentMessage) |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
598 |
self.RefreshView() |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
599 |
|
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
600 |
def OnMessageFilterChanged(self, event): |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
601 |
self.CurrentFilter = self.LevelFilters[self.MessageFilter.GetSelection()] |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
602 |
self.ResetMessagePanel() |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
603 |
event.Skip() |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
604 |
|
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
605 |
def OnSearchMessageChanged(self, event): |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
606 |
self.CurrentSearchValue = self.SearchMessage.GetValue() |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
607 |
self.ResetMessagePanel() |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
608 |
event.Skip() |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
609 |
|
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
610 |
def OnSearchMessageSearchButtonClick(self, event): |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
611 |
self.CurrentSearchValue = self.SearchMessage.GetValue() |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
612 |
self.ResetMessagePanel() |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
613 |
event.Skip() |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
614 |
|
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
615 |
def OnSearchMessageCancelButtonClick(self, event): |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
616 |
self.CurrentSearchValue = "" |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
617 |
self.SearchMessage.SetValue("") |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
618 |
self.ResetMessagePanel() |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
619 |
event.Skip() |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
620 |
|
1093 | 621 |
def OnCleanButton(self, event): |
622 |
if self.LogSource is not None: |
|
623 |
self.LogSource.ResetLogCount() |
|
624 |
self.ResetLogMessages() |
|
625 |
self.RefreshView() |
|
626 |
event.Skip() |
|
627 |
||
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
628 |
def GenerateOnDurationButton(self, duration): |
983
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
629 |
def OnDurationButton(): |
982
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
630 |
self.ScrollMessagePanelByTimestamp(duration) |
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
631 |
return OnDurationButton |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
632 |
|
993 | 633 |
def GetCopyMessageToClipboardFunction(self, message): |
634 |
def CopyMessageToClipboardFunction(event): |
|
635 |
self.ParentWindow.SetCopyBuffer(message.GetFullText()) |
|
636 |
return CopyMessageToClipboardFunction |
|
637 |
||
638 |
def GetMessageByScreenPos(self, posx, posy): |
|
983
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
639 |
if self.CurrentMessage is not None: |
986 | 640 |
width, height = self.MessagePanel.GetClientSize() |
641 |
message_idx = self.CurrentMessage |
|
642 |
message = self.LogMessages[message_idx] |
|
643 |
draw_date = True |
|
644 |
offset = 5 |
|
645 |
||
646 |
while offset < height and message is not None: |
|
647 |
if draw_date: |
|
648 |
offset += DATE_INFO_SIZE |
|
993 | 649 |
|
986 | 650 |
if offset <= posy < offset + MESSAGE_INFO_SIZE: |
993 | 651 |
return message |
652 |
||
986 | 653 |
offset += MESSAGE_INFO_SIZE |
654 |
||
655 |
previous_message, message_idx = self.GetPreviousMessage(message_idx) |
|
656 |
if previous_message is not None: |
|
657 |
draw_date = message.Date != previous_message.Date |
|
658 |
message = previous_message |
|
993 | 659 |
return None |
660 |
||
661 |
def OnMessagePanelLeftUp(self, event): |
|
662 |
if self.CurrentMessage is not None: |
|
663 |
posx, posy = event.GetPosition() |
|
664 |
for button in self.LeftButtons + self.RightButtons: |
|
665 |
if button.HitTest(posx, posy): |
|
666 |
button.ProcessCallback() |
|
667 |
break |
|
668 |
event.Skip() |
|
669 |
||
670 |
def OnMessagePanelRightUp(self, event): |
|
671 |
message = self.GetMessageByScreenPos(*event.GetPosition()) |
|
672 |
if message is not None: |
|
673 |
menu = wx.Menu(title='') |
|
674 |
||
675 |
new_id = wx.NewId() |
|
676 |
menu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Copy")) |
|
677 |
self.Bind(wx.EVT_MENU, self.GetCopyMessageToClipboardFunction(message), id=new_id) |
|
678 |
||
679 |
self.MessagePanel.PopupMenu(menu) |
|
680 |
menu.Destroy() |
|
681 |
event.Skip() |
|
682 |
||
683 |
def OnMessagePanelLeftDCLick(self, event): |
|
684 |
message = self.GetMessageByScreenPos(*event.GetPosition()) |
|
685 |
if message is not None: |
|
686 |
self.SearchMessage.SetFocus() |
|
687 |
self.SearchMessage.SetValue(message.Message) |
|
688 |
event.Skip() |
|
689 |
||
690 |
def ResetMessageToolTip(self): |
|
691 |
if self.MessageToolTip is not None: |
|
692 |
self.MessageToolTip.Destroy() |
|
693 |
self.MessageToolTip = None |
|
694 |
||
695 |
def OnMessageToolTipTimer(self, event): |
|
696 |
if self.LastMousePos is not None: |
|
697 |
message = self.GetMessageByScreenPos(*self.LastMousePos) |
|
698 |
if message is not None: |
|
699 |
tooltip_pos = self.MessagePanel.ClientToScreen(self.LastMousePos) |
|
700 |
tooltip_pos.x += 10 |
|
701 |
tooltip_pos.y += 10 |
|
702 |
self.MessageToolTip = ToolTip(self.MessagePanel, message.GetFullText(), False) |
|
703 |
self.MessageToolTip.SetFont(self.Font) |
|
704 |
self.MessageToolTip.MoveToolTip(tooltip_pos) |
|
705 |
self.MessageToolTip.Show() |
|
706 |
event.Skip() |
|
707 |
||
708 |
def OnMessagePanelMotion(self, event): |
|
709 |
if not event.Dragging(): |
|
710 |
self.ResetMessageToolTip() |
|
711 |
self.LastMousePos = event.GetPosition() |
|
712 |
self.MessageToolTipTimer.Start(int(TOOLTIP_WAIT_PERIOD * 1000), oneShot=True) |
|
713 |
event.Skip() |
|
714 |
||
715 |
def OnMessagePanelLeaveWindow(self, event): |
|
716 |
self.ResetMessageToolTip() |
|
717 |
self.LastMousePos = None |
|
718 |
self.MessageToolTipTimer.Stop() |
|
986 | 719 |
event.Skip() |
720 |
||
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
721 |
def OnMessagePanelMouseWheel(self, event): |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
722 |
self.ScrollMessagePanel(event.GetWheelRotation() / event.GetWheelDelta()) |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
723 |
event.Skip() |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
724 |
|
988
30e7571c10d0
Reduced flicker on LogViewer and DebugGraphPanel on Windows
Laurent Bessard
parents:
987
diff
changeset
|
725 |
def OnMessagePanelEraseBackground(self, event): |
30e7571c10d0
Reduced flicker on LogViewer and DebugGraphPanel on Windows
Laurent Bessard
parents:
987
diff
changeset
|
726 |
pass |
30e7571c10d0
Reduced flicker on LogViewer and DebugGraphPanel on Windows
Laurent Bessard
parents:
987
diff
changeset
|
727 |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
728 |
def OnMessagePanelPaint(self, event): |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
729 |
self.RefreshView() |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
730 |
event.Skip() |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
731 |
|
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
732 |
def OnMessagePanelResize(self, event): |
984 | 733 |
width, height = self.MessagePanel.GetClientSize() |
734 |
offset = 2 |
|
735 |
for button in self.LeftButtons: |
|
736 |
button.SetPosition(offset, 2) |
|
737 |
w, h = button.GetSize() |
|
738 |
offset += w + 2 |
|
739 |
offset = width - 2 |
|
740 |
for button in self.RightButtons: |
|
741 |
w, h = button.GetSize() |
|
742 |
button.SetPosition(offset - w, 2) |
|
743 |
offset -= w + 2 |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
744 |
if self.IsMessagePanelBottom(): |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
745 |
self.ScrollToFirst() |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
746 |
else: |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
747 |
self.RefreshView() |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
748 |
event.Skip() |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
749 |
|
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
750 |
def OnScrollTimer(self, event): |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
751 |
if self.ScrollSpeed != 0.: |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
752 |
speed_norm = abs(self.ScrollSpeed) |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
753 |
period = REFRESH_PERIOD / speed_norm |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
754 |
self.ScrollMessagePanel(-speed_norm / self.ScrollSpeed) |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
755 |
self.LastStartTime = gettime() |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
756 |
self.ScrollTimer.Start(int(period * 1000), True) |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
757 |
event.Skip() |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
758 |
|
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
759 |
def SetScrollSpeed(self, speed): |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
760 |
if speed == 0.: |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
761 |
self.ScrollTimer.Stop() |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
762 |
else: |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
763 |
speed_norm = abs(speed) |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
764 |
period = REFRESH_PERIOD / speed_norm |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
765 |
current_time = gettime() |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
766 |
if self.LastStartTime is not None: |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
767 |
elapsed_time = current_time - self.LastStartTime |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
768 |
if elapsed_time > period: |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
769 |
self.ScrollMessagePanel(-speed_norm / speed) |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
770 |
self.LastStartTime = current_time |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
771 |
else: |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
772 |
period -= elapsed_time |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
773 |
else: |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
774 |
self.LastStartTime = current_time |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
775 |
self.ScrollTimer.Start(int(period * 1000), True) |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
776 |
self.ScrollSpeed = speed |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
777 |
|
1071
5e740fe71fbe
Fixed bug in LogViewer when view is filtered and displaying last message and new messages appears
Laurent Bessard
parents:
1020
diff
changeset
|
778 |
def ScrollToLast(self, refresh=True): |
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
779 |
if len(self.LogMessages) > 0: |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
780 |
self.CurrentMessage = len(self.LogMessages) - 1 |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
781 |
message = self.LogMessages[self.CurrentMessage] |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
782 |
if not self.FilterLogMessage(message): |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
783 |
message, self.CurrentMessage = self.GetPreviousMessage(self.CurrentMessage) |
1071
5e740fe71fbe
Fixed bug in LogViewer when view is filtered and displaying last message and new messages appears
Laurent Bessard
parents:
1020
diff
changeset
|
784 |
if refresh: |
5e740fe71fbe
Fixed bug in LogViewer when view is filtered and displaying last message and new messages appears
Laurent Bessard
parents:
1020
diff
changeset
|
785 |
self.RefreshView() |
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
786 |
|
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
787 |
def ScrollToFirst(self): |
978 | 788 |
if len(self.LogMessages) > 0: |
789 |
message_idx = 0 |
|
790 |
message = self.LogMessages[message_idx] |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
791 |
if not self.FilterLogMessage(message): |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
792 |
next_message, msgidx = self.GetNextMessage(message_idx) |
978 | 793 |
if next_message is not None: |
794 |
message_idx = msgidx |
|
795 |
message = next_message |
|
796 |
while message is not None: |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
797 |
message, msgidx = self.GetPreviousMessage(message_idx) |
978 | 798 |
if message is not None: |
799 |
message_idx = msgidx |
|
800 |
message = self.LogMessages[message_idx] |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
801 |
if self.FilterLogMessage(message): |
978 | 802 |
while message is not None: |
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
803 |
message, msgidx = self.GetNextMessage(message_idx) |
978 | 804 |
if message is not None: |
805 |
if not self.IsMessagePanelBottom(msgidx): |
|
806 |
break |
|
807 |
message_idx = msgidx |
|
808 |
self.CurrentMessage = message_idx |
|
809 |
else: |
|
810 |
self.CurrentMessage = None |
|
811 |
self.RefreshView() |