author | Laurent Bessard |
Fri, 15 Mar 2013 12:07:39 +0100 | |
changeset 987 | 7ca88194ae89 |
parent 986 | b663f099da8a |
child 988 | 30e7571c10d0 |
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) |
|
54 |
self.Bind(wx.EVT_PAINT, self.OnPaint) |
|
55 |
self.Bind(wx.EVT_SIZE, self.OnResize) |
|
56 |
||
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
57 |
self.ThumbPosition = 0. # -1 <= ThumbPosition <= 1 |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
58 |
self.ThumbScrollingStartPos = None |
978 | 59 |
|
60 |
def GetRangeRect(self): |
|
61 |
width, height = self.GetClientSize() |
|
62 |
return wx.Rect(0, width, width, height - 2 * width) |
|
63 |
||
64 |
def GetThumbRect(self): |
|
65 |
width, height = self.GetClientSize() |
|
66 |
range_rect = self.GetRangeRect() |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
67 |
thumb_size = range_rect.height * THUMB_SIZE_RATIO |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
68 |
thumb_range = range_rect.height - thumb_size |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
69 |
thumb_center_position = (thumb_size + (self.ThumbPosition + 1) * thumb_range) / 2. |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
70 |
thumb_start = int(thumb_center_position - thumb_size / 2.) |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
71 |
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
|
72 |
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
|
73 |
|
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
74 |
def RefreshThumbPosition(self, thumb_position=None): |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
75 |
if thumb_position is None: |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
76 |
thumb_position = self.ThumbPosition |
978 | 77 |
if self.Parent.IsMessagePanelTop(): |
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
78 |
thumb_position = max(0., thumb_position) |
978 | 79 |
if self.Parent.IsMessagePanelBottom(): |
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
80 |
thumb_position = min(0., thumb_position) |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
81 |
if thumb_position != self.ThumbPosition: |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
82 |
self.ThumbPosition = thumb_position |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
83 |
self.Parent.SetScrollSpeed(self.ThumbPosition) |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
84 |
self.Refresh() |
978 | 85 |
|
86 |
def OnLeftDown(self, event): |
|
87 |
self.CaptureMouse() |
|
88 |
posx, posy = event.GetPosition() |
|
89 |
width, height = self.GetClientSize() |
|
90 |
range_rect = self.GetRangeRect() |
|
91 |
thumb_rect = self.GetThumbRect() |
|
92 |
if range_rect.InsideXY(posx, posy): |
|
93 |
if thumb_rect.InsideXY(posx, posy): |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
94 |
self.ThumbScrollingStartPos = wx.Point(posx, posy) |
978 | 95 |
elif posy < thumb_rect.y: |
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
96 |
self.Parent.ScrollToLast() |
978 | 97 |
elif posy > thumb_rect.y + thumb_rect.height: |
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
98 |
self.Parent.ScrollToFirst() |
978 | 99 |
elif posy < width: |
986 | 100 |
self.Parent.ScrollMessagePanelByPage(1) |
978 | 101 |
elif posy > height - width: |
986 | 102 |
self.Parent.ScrollMessagePanelByPage(-1) |
978 | 103 |
event.Skip() |
104 |
||
105 |
def OnLeftUp(self, event): |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
106 |
self.ThumbScrollingStartPos = None |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
107 |
self.RefreshThumbPosition(0.) |
978 | 108 |
if self.HasCapture(): |
109 |
self.ReleaseMouse() |
|
110 |
event.Skip() |
|
111 |
||
112 |
def OnMotion(self, event): |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
113 |
if event.Dragging() and self.ThumbScrollingStartPos is not None: |
978 | 114 |
posx, posy = event.GetPosition() |
115 |
width, height = self.GetClientSize() |
|
116 |
range_rect = self.GetRangeRect() |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
117 |
thumb_size = range_rect.height * THUMB_SIZE_RATIO |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
118 |
thumb_range = range_rect.height - thumb_size |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
119 |
self.RefreshThumbPosition( |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
120 |
max(-1., min((posy - self.ThumbScrollingStartPos.y) * 2. / thumb_range, 1.))) |
978 | 121 |
event.Skip() |
122 |
||
123 |
def OnResize(self, event): |
|
124 |
self.Refresh() |
|
125 |
event.Skip() |
|
126 |
||
127 |
def OnPaint(self, event): |
|
128 |
dc = wx.BufferedPaintDC(self) |
|
129 |
dc.Clear() |
|
130 |
dc.BeginDrawing() |
|
131 |
||
987
7ca88194ae89
Improved graphics of LogViewer scrollbar to be anti-aliased
Laurent Bessard
parents:
986
diff
changeset
|
132 |
gc = wx.GCDC(dc) |
7ca88194ae89
Improved graphics of LogViewer scrollbar to be anti-aliased
Laurent Bessard
parents:
986
diff
changeset
|
133 |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
134 |
width, height = self.GetClientSize() |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
135 |
|
987
7ca88194ae89
Improved graphics of LogViewer scrollbar to be anti-aliased
Laurent Bessard
parents:
986
diff
changeset
|
136 |
gc.SetPen(wx.Pen(wx.NamedColour("GREY"), 2)) |
7ca88194ae89
Improved graphics of LogViewer scrollbar to be anti-aliased
Laurent Bessard
parents:
986
diff
changeset
|
137 |
gc.SetBrush(wx.GREY_BRUSH) |
7ca88194ae89
Improved graphics of LogViewer scrollbar to be anti-aliased
Laurent Bessard
parents:
986
diff
changeset
|
138 |
|
7ca88194ae89
Improved graphics of LogViewer scrollbar to be anti-aliased
Laurent Bessard
parents:
986
diff
changeset
|
139 |
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
|
140 |
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
|
141 |
|
7ca88194ae89
Improved graphics of LogViewer scrollbar to be anti-aliased
Laurent Bessard
parents:
986
diff
changeset
|
142 |
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
|
143 |
gc.DrawLines(ArrowPoints(wx.BOTTOM, width, width * 0.75, height - 2 * width - 6)) |
986 | 144 |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
145 |
thumb_rect = self.GetThumbRect() |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
146 |
exclusion_rect = wx.Rect(thumb_rect.x, thumb_rect.y, |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
147 |
thumb_rect.width, thumb_rect.height) |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
148 |
if self.Parent.IsMessagePanelTop(): |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
149 |
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
|
150 |
if self.Parent.IsMessagePanelBottom(): |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
151 |
exclusion_rect.height = height - width - exclusion_rect.y |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
152 |
if exclusion_rect != thumb_rect: |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
153 |
colour = wx.NamedColour("LIGHT GREY") |
987
7ca88194ae89
Improved graphics of LogViewer scrollbar to be anti-aliased
Laurent Bessard
parents:
986
diff
changeset
|
154 |
gc.SetPen(wx.Pen(colour)) |
7ca88194ae89
Improved graphics of LogViewer scrollbar to be anti-aliased
Laurent Bessard
parents:
986
diff
changeset
|
155 |
gc.SetBrush(wx.Brush(colour)) |
7ca88194ae89
Improved graphics of LogViewer scrollbar to be anti-aliased
Laurent Bessard
parents:
986
diff
changeset
|
156 |
|
7ca88194ae89
Improved graphics of LogViewer scrollbar to be anti-aliased
Laurent Bessard
parents:
986
diff
changeset
|
157 |
gc.DrawRectangle(exclusion_rect.x, exclusion_rect.y, |
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
158 |
exclusion_rect.width, exclusion_rect.height) |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
159 |
|
987
7ca88194ae89
Improved graphics of LogViewer scrollbar to be anti-aliased
Laurent Bessard
parents:
986
diff
changeset
|
160 |
gc.SetPen(wx.GREY_PEN) |
7ca88194ae89
Improved graphics of LogViewer scrollbar to be anti-aliased
Laurent Bessard
parents:
986
diff
changeset
|
161 |
gc.SetBrush(wx.GREY_BRUSH) |
7ca88194ae89
Improved graphics of LogViewer scrollbar to be anti-aliased
Laurent Bessard
parents:
986
diff
changeset
|
162 |
|
7ca88194ae89
Improved graphics of LogViewer scrollbar to be anti-aliased
Laurent Bessard
parents:
986
diff
changeset
|
163 |
gc.DrawPolygon(ArrowPoints(wx.TOP, width, width, 0)) |
7ca88194ae89
Improved graphics of LogViewer scrollbar to be anti-aliased
Laurent Bessard
parents:
986
diff
changeset
|
164 |
|
7ca88194ae89
Improved graphics of LogViewer scrollbar to be anti-aliased
Laurent Bessard
parents:
986
diff
changeset
|
165 |
gc.DrawPolygon(ArrowPoints(wx.BOTTOM, width, width, height)) |
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
166 |
|
987
7ca88194ae89
Improved graphics of LogViewer scrollbar to be anti-aliased
Laurent Bessard
parents:
986
diff
changeset
|
167 |
gc.DrawRectangle(thumb_rect.x, thumb_rect.y, |
978 | 168 |
thumb_rect.width, thumb_rect.height) |
169 |
||
170 |
dc.EndDrawing() |
|
171 |
event.Skip() |
|
172 |
||
983
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
173 |
BUTTON_SIZE = (30, 15) |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
174 |
|
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
175 |
class LogButton(): |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
176 |
|
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
177 |
def __init__(self, label, callback): |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
178 |
self.Position = wx.Point(0, 0) |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
179 |
self.Size = wx.Size(*BUTTON_SIZE) |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
180 |
if wx.Platform == '__WXMSW__': |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
181 |
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
|
182 |
else: |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
183 |
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
|
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 |
dc.SetFont(self.Font) |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
216 |
|
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
217 |
w, h = dc.GetTextExtent(self.Label) |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
218 |
dc.DrawText(self.Label, |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
219 |
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
|
220 |
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
|
221 |
|
978 | 222 |
DATE_INFO_SIZE = 10 |
223 |
MESSAGE_INFO_SIZE = 30 |
|
224 |
||
225 |
class LogMessage: |
|
226 |
||
227 |
def __init__(self, tv_sec, tv_nsec, level, level_bitmap, msg): |
|
228 |
self.Date = datetime.fromtimestamp(tv_sec) |
|
229 |
self.Seconds = self.Date.second + tv_nsec * 1e-9 |
|
230 |
self.Date = self.Date.replace(second=0) |
|
982
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
231 |
self.Timestamp = tv_sec + tv_nsec * 1e-9 |
978 | 232 |
self.Level = level |
233 |
self.LevelBitmap = level_bitmap |
|
234 |
self.Message = msg |
|
235 |
self.DrawDate = True |
|
236 |
||
237 |
def __cmp__(self, other): |
|
238 |
if self.Date == other.Date: |
|
239 |
return cmp(self.Seconds, other.Seconds) |
|
240 |
return cmp(self.Date, other.Date) |
|
241 |
||
242 |
def Draw(self, dc, offset, width, draw_date): |
|
243 |
if draw_date: |
|
244 |
datetime_text = self.Date.strftime("%d/%m/%y %H:%M") |
|
245 |
dw, dh = dc.GetTextExtent(datetime_text) |
|
246 |
dc.DrawText(datetime_text, (width - dw) / 2, offset + (DATE_INFO_SIZE - dh) / 2) |
|
247 |
offset += DATE_INFO_SIZE |
|
248 |
||
249 |
seconds_text = "%12.9f" % self.Seconds |
|
250 |
sw, sh = dc.GetTextExtent(seconds_text) |
|
251 |
dc.DrawText(seconds_text, 5, offset + (MESSAGE_INFO_SIZE - sh) / 2) |
|
252 |
||
253 |
bw, bh = self.LevelBitmap.GetWidth(), self.LevelBitmap.GetHeight() |
|
254 |
dc.DrawBitmap(self.LevelBitmap, 10 + sw, offset + (MESSAGE_INFO_SIZE - bh) / 2) |
|
255 |
||
256 |
mw, mh = dc.GetTextExtent(self.Message) |
|
257 |
dc.DrawText(self.Message, 15 + sw + bw, offset + (MESSAGE_INFO_SIZE - mh) / 2) |
|
258 |
||
259 |
def GetHeight(self, draw_date): |
|
260 |
if draw_date: |
|
261 |
return DATE_INFO_SIZE + MESSAGE_INFO_SIZE |
|
262 |
return MESSAGE_INFO_SIZE |
|
263 |
||
264 |
SECOND = 1 |
|
265 |
MINUTE = 60 * SECOND |
|
266 |
HOUR = 60 * MINUTE |
|
267 |
DAY = 24 * HOUR |
|
268 |
||
269 |
CHANGE_TIMESTAMP_BUTTONS = [(_("1d"), DAY), |
|
270 |
(_("1h"), HOUR), |
|
986 | 271 |
(_("1m"), MINUTE), |
272 |
(_("1s"), SECOND)] |
|
978 | 273 |
|
274 |
class LogViewer(DebugViewer, wx.Panel): |
|
275 |
||
276 |
def __init__(self, parent, window): |
|
277 |
wx.Panel.__init__(self, parent, style=wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER) |
|
278 |
DebugViewer.__init__(self, None, False, False) |
|
279 |
||
280 |
main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5) |
|
281 |
main_sizer.AddGrowableCol(0) |
|
282 |
main_sizer.AddGrowableRow(1) |
|
283 |
||
284 |
filter_sizer = wx.BoxSizer(wx.HORIZONTAL) |
|
285 |
main_sizer.AddSizer(filter_sizer, border=5, flag=wx.TOP|wx.LEFT|wx.RIGHT|wx.GROW) |
|
286 |
||
287 |
self.MessageFilter = wx.ComboBox(self, style=wx.CB_READONLY) |
|
288 |
self.MessageFilter.Append(_("All")) |
|
289 |
levels = LogLevels[:3] |
|
290 |
levels.reverse() |
|
291 |
for level in levels: |
|
292 |
self.MessageFilter.Append(_(level)) |
|
293 |
self.Bind(wx.EVT_COMBOBOX, self.OnMessageFilterChanged, self.MessageFilter) |
|
294 |
filter_sizer.AddWindow(self.MessageFilter, 1, border=5, flag=wx.RIGHT|wx.GROW) |
|
295 |
||
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
296 |
self.SearchMessage = wx.SearchCtrl(self, style=wx.TE_PROCESS_ENTER) |
978 | 297 |
self.SearchMessage.ShowSearchButton(True) |
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
298 |
self.SearchMessage.ShowCancelButton(True) |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
299 |
self.Bind(wx.EVT_TEXT_ENTER, self.OnSearchMessageChanged, self.SearchMessage) |
978 | 300 |
self.Bind(wx.EVT_SEARCHCTRL_SEARCH_BTN, |
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
301 |
self.OnSearchMessageSearchButtonClick, self.SearchMessage) |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
302 |
self.Bind(wx.EVT_SEARCHCTRL_CANCEL_BTN, |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
303 |
self.OnSearchMessageCancelButtonClick, self.SearchMessage) |
978 | 304 |
filter_sizer.AddWindow(self.SearchMessage, 3, flag=wx.GROW) |
305 |
||
983
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
306 |
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
|
307 |
message_panel_sizer.AddGrowableCol(0) |
978 | 308 |
message_panel_sizer.AddGrowableRow(0) |
309 |
main_sizer.AddSizer(message_panel_sizer, border=5, flag=wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.GROW) |
|
310 |
||
311 |
self.MessagePanel = wx.Panel(self) |
|
312 |
if wx.Platform == '__WXMSW__': |
|
313 |
self.Font = wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL, faceName='Courier New') |
|
314 |
else: |
|
983
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
315 |
self.Font = wx.Font(12, wx.SWISS, wx.NORMAL, wx.NORMAL, faceName='Courier') |
984 | 316 |
self.MessagePanel.Bind(wx.EVT_LEFT_UP, self.OnMessagePanelLeftUp) |
986 | 317 |
self.MessagePanel.Bind(wx.EVT_LEFT_DCLICK, self.OnMessagePanelLeftDCLick) |
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
318 |
self.MessagePanel.Bind(wx.EVT_MOUSEWHEEL, self.OnMessagePanelMouseWheel) |
978 | 319 |
self.MessagePanel.Bind(wx.EVT_PAINT, self.OnMessagePanelPaint) |
320 |
self.MessagePanel.Bind(wx.EVT_SIZE, self.OnMessagePanelResize) |
|
321 |
message_panel_sizer.AddWindow(self.MessagePanel, flag=wx.GROW) |
|
322 |
||
983
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
323 |
self.MessageScrollBar = LogScrollBar(self, wx.Size(16, -1)) |
978 | 324 |
message_panel_sizer.AddWindow(self.MessageScrollBar, flag=wx.GROW) |
325 |
||
326 |
self.SetSizer(main_sizer) |
|
983
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
327 |
|
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
328 |
self.LeftButtons = [] |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
329 |
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
|
330 |
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
|
331 |
self.LeftButtons.append(LogButton(label, callback)) |
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.RightButtons = [] |
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.RightButtons.append(LogButton(label, callback)) |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
337 |
|
978 | 338 |
self.MessageFilter.SetSelection(0) |
339 |
self.LogSource = None |
|
340 |
self.ResetLogMessages() |
|
341 |
self.ParentWindow = window |
|
342 |
||
979 | 343 |
self.LevelIcons = [GetBitmap("LOG_" + level) for level in LogLevels] |
978 | 344 |
self.LevelFilters = [range(i) for i in xrange(4, 0, -1)] |
345 |
self.CurrentFilter = self.LevelFilters[0] |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
346 |
self.CurrentSearchValue = "" |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
347 |
|
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
348 |
self.ScrollSpeed = 0. |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
349 |
self.LastStartTime = None |
978 | 350 |
self.ScrollTimer = wx.Timer(self, -1) |
351 |
self.Bind(wx.EVT_TIMER, self.OnScrollTimer, self.ScrollTimer) |
|
352 |
||
353 |
def __del__(self): |
|
354 |
self.ScrollTimer.Stop() |
|
355 |
||
356 |
def ResetLogMessages(self): |
|
357 |
self.previous_log_count = [None]*LogLevelsCount |
|
358 |
self.OldestMessages = [] |
|
359 |
self.LogMessages = [] |
|
982
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
360 |
self.LogMessagesTimestamp = numpy.array([]) |
978 | 361 |
self.CurrentMessage = None |
362 |
self.HasNewData = False |
|
363 |
||
364 |
def SetLogSource(self, log_source): |
|
365 |
self.LogSource = log_source |
|
366 |
if log_source is not None: |
|
367 |
self.ResetLogMessages() |
|
368 |
self.RefreshView() |
|
369 |
||
370 |
def GetLogMessageFromSource(self, msgidx, level): |
|
371 |
if self.LogSource is not None: |
|
372 |
answer = self.LogSource.GetLogMessage(level, msgidx) |
|
373 |
if answer is not None: |
|
374 |
msg, tick, tv_sec, tv_nsec = answer |
|
375 |
return LogMessage(tv_sec, tv_nsec, level, self.LevelIcons[level], msg) |
|
376 |
return None |
|
377 |
||
378 |
def SetLogCounters(self, log_count): |
|
379 |
new_messages = [] |
|
380 |
for level, count, prev in zip(xrange(LogLevelsCount), log_count, self.previous_log_count): |
|
381 |
if count is not None and prev != count: |
|
382 |
if prev is None: |
|
383 |
dump_end = count - 2 |
|
384 |
else: |
|
385 |
dump_end = prev - 1 |
|
386 |
for msgidx in xrange(count-1, dump_end,-1): |
|
387 |
new_message = self.GetLogMessageFromSource(msgidx, level) |
|
388 |
if new_message is not None: |
|
389 |
if prev is None: |
|
390 |
self.OldestMessages.append((msgidx, new_message)) |
|
391 |
if len(new_messages) == 0 or new_message > new_messages[0]: |
|
392 |
new_messages = [new_message] |
|
393 |
else: |
|
394 |
new_messages.insert(0, new_message) |
|
395 |
else: |
|
396 |
if prev is None: |
|
397 |
self.OldestMessages.append((-1, None)) |
|
398 |
break |
|
399 |
self.previous_log_count[level] = count |
|
400 |
new_messages.sort() |
|
401 |
if len(new_messages) > 0: |
|
402 |
self.HasNewData = True |
|
403 |
old_length = len(self.LogMessages) |
|
404 |
for new_message in new_messages: |
|
405 |
self.LogMessages.append(new_message) |
|
982
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
406 |
self.LogMessagesTimestamp = numpy.append(self.LogMessagesTimestamp, [new_message.Timestamp]) |
978 | 407 |
if self.CurrentMessage is None or self.CurrentMessage == old_length - 1: |
408 |
self.CurrentMessage = len(self.LogMessages) - 1 |
|
409 |
self.NewDataAvailable(None) |
|
410 |
||
982
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
411 |
def FilterLogMessage(self, message, timestamp=None): |
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
412 |
return (message.Level in self.CurrentFilter and |
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
413 |
message.Message.find(self.CurrentSearchValue) != -1 and |
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
414 |
(timestamp is None or message.Timestamp < timestamp)) |
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
415 |
|
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
416 |
def GetMessageByTimestamp(self, timestamp): |
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
417 |
if self.CurrentMessage is not None: |
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
418 |
msgidx = numpy.argmin(abs(self.LogMessagesTimestamp - timestamp)) |
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
419 |
message = self.LogMessages[msgidx] |
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
420 |
if self.FilterLogMessage(message) and message.Timestamp > timestamp: |
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
421 |
return self.GetPreviousMessage(msgidx, timestamp) |
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
422 |
return message, msgidx |
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
423 |
return None, None |
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
424 |
|
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
425 |
def GetNextMessage(self, msgidx): |
978 | 426 |
while msgidx < len(self.LogMessages) - 1: |
427 |
message = self.LogMessages[msgidx + 1] |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
428 |
if self.FilterLogMessage(message): |
978 | 429 |
return message, msgidx + 1 |
430 |
msgidx += 1 |
|
431 |
return None, None |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
432 |
|
982
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
433 |
def GetPreviousMessage(self, msgidx, timestamp=None): |
978 | 434 |
message = None |
435 |
while 0 < msgidx < len(self.LogMessages): |
|
436 |
message = self.LogMessages[msgidx - 1] |
|
982
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
437 |
if self.FilterLogMessage(message, timestamp): |
978 | 438 |
return message, msgidx - 1 |
439 |
msgidx -= 1 |
|
440 |
if len(self.LogMessages) > 0: |
|
441 |
message = self.LogMessages[0] |
|
442 |
while message is not None: |
|
443 |
level = message.Level |
|
444 |
oldest_msgidx, oldest_message = self.OldestMessages[level] |
|
445 |
if oldest_msgidx > 0: |
|
446 |
old_message = self.GetLogMessageFromSource(oldest_msgidx - 1, level) |
|
447 |
if old_message is not None: |
|
448 |
self.OldestMessages[level] = (oldest_msgidx - 1, old_message) |
|
449 |
else: |
|
450 |
self.OldestMessages[level] = (-1, None) |
|
451 |
else: |
|
452 |
self.OldestMessages[level] = (-1, None) |
|
453 |
message = None |
|
454 |
for idx, msg in self.OldestMessages: |
|
455 |
if msg is not None and (message is None or msg > message): |
|
456 |
message = msg |
|
457 |
if message is not None: |
|
458 |
self.LogMessages.insert(0, message) |
|
982
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
459 |
self.LogMessagesTimestamp = numpy.insert(self.LogMessagesTimestamp, [0], [message.Timestamp]) |
978 | 460 |
if self.CurrentMessage is not None: |
461 |
self.CurrentMessage += 1 |
|
462 |
else: |
|
463 |
self.CurrentMessage = 0 |
|
982
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
464 |
if self.FilterLogMessage(message, timestamp): |
978 | 465 |
return message, 0 |
466 |
return None, None |
|
467 |
||
468 |
def RefreshNewData(self, *args, **kwargs): |
|
469 |
if self.HasNewData: |
|
470 |
self.HasNewData = False |
|
471 |
self.RefreshView() |
|
472 |
DebugViewer.RefreshNewData(self, *args, **kwargs) |
|
473 |
||
474 |
def RefreshView(self): |
|
475 |
width, height = self.MessagePanel.GetClientSize() |
|
476 |
bitmap = wx.EmptyBitmap(width, height) |
|
477 |
dc = wx.BufferedDC(wx.ClientDC(self.MessagePanel), bitmap) |
|
478 |
dc.Clear() |
|
479 |
dc.BeginDrawing() |
|
480 |
||
481 |
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
|
482 |
|
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
483 |
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
|
484 |
button.Draw(dc) |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
485 |
|
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
486 |
dc.SetFont(self.Font) |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
487 |
|
978 | 488 |
message_idx = self.CurrentMessage |
489 |
message = self.LogMessages[message_idx] |
|
490 |
draw_date = True |
|
491 |
offset = 5 |
|
492 |
while offset < height and message is not None: |
|
493 |
message.Draw(dc, offset, width, draw_date) |
|
494 |
offset += message.GetHeight(draw_date) |
|
495 |
||
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
496 |
previous_message, message_idx = self.GetPreviousMessage(message_idx) |
978 | 497 |
if previous_message is not None: |
498 |
draw_date = message.Date != previous_message.Date |
|
499 |
message = previous_message |
|
500 |
||
501 |
dc.EndDrawing() |
|
502 |
||
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
503 |
self.MessageScrollBar.RefreshThumbPosition() |
978 | 504 |
|
505 |
def IsMessagePanelTop(self, message_idx=None): |
|
506 |
if message_idx is None: |
|
507 |
message_idx = self.CurrentMessage |
|
508 |
if message_idx is not None: |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
509 |
return self.GetNextMessage(message_idx)[0] is None |
978 | 510 |
return True |
511 |
||
512 |
def IsMessagePanelBottom(self, message_idx=None): |
|
513 |
if message_idx is None: |
|
514 |
message_idx = self.CurrentMessage |
|
515 |
if message_idx is not None: |
|
516 |
width, height = self.MessagePanel.GetClientSize() |
|
517 |
offset = 5 |
|
518 |
message = self.LogMessages[message_idx] |
|
519 |
draw_date = True |
|
520 |
while message is not None and offset < height: |
|
521 |
offset += message.GetHeight(draw_date) |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
522 |
previous_message, message_idx = self.GetPreviousMessage(message_idx) |
978 | 523 |
if previous_message is not None: |
524 |
draw_date = message.Date != previous_message.Date |
|
525 |
message = previous_message |
|
526 |
return offset < height |
|
527 |
return True |
|
528 |
||
529 |
def ScrollMessagePanel(self, scroll): |
|
530 |
if self.CurrentMessage is not None: |
|
531 |
message = self.LogMessages[self.CurrentMessage] |
|
532 |
while scroll > 0 and message is not None: |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
533 |
message, msgidx = self.GetNextMessage(self.CurrentMessage) |
978 | 534 |
if message is not None: |
535 |
self.CurrentMessage = msgidx |
|
536 |
scroll -= 1 |
|
537 |
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
|
538 |
message, msgidx = self.GetPreviousMessage(self.CurrentMessage) |
978 | 539 |
if message is not None: |
540 |
self.CurrentMessage = msgidx |
|
541 |
scroll += 1 |
|
542 |
self.RefreshView() |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
543 |
|
986 | 544 |
def ScrollMessagePanelByPage(self, page): |
545 |
if self.CurrentMessage is not None: |
|
546 |
width, height = self.MessagePanel.GetClientSize() |
|
547 |
message_per_page = max(1, (height - DATE_INFO_SIZE) / MESSAGE_INFO_SIZE - 1) |
|
548 |
self.ScrollMessagePanel(page * message_per_page) |
|
549 |
||
982
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
550 |
def ScrollMessagePanelByTimestamp(self, seconds): |
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
551 |
if self.CurrentMessage is not None: |
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
552 |
current_message = self.LogMessages[self.CurrentMessage] |
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
553 |
message, msgidx = self.GetMessageByTimestamp(current_message.Timestamp + seconds) |
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
554 |
if message is None or self.IsMessagePanelBottom(msgidx): |
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
555 |
self.ScrollToFirst() |
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
556 |
else: |
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
557 |
self.CurrentMessage = msgidx |
984 | 558 |
self.RefreshView() |
982
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
559 |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
560 |
def ResetMessagePanel(self): |
978 | 561 |
if len(self.LogMessages) > 0: |
562 |
self.CurrentMessage = len(self.LogMessages) - 1 |
|
563 |
message = self.LogMessages[self.CurrentMessage] |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
564 |
while message is not None and not self.FilterLogMessage(message): |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
565 |
message, self.CurrentMessage = self.GetPreviousMessage(self.CurrentMessage) |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
566 |
self.RefreshView() |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
567 |
|
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
568 |
def OnMessageFilterChanged(self, event): |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
569 |
self.CurrentFilter = self.LevelFilters[self.MessageFilter.GetSelection()] |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
570 |
self.ResetMessagePanel() |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
571 |
event.Skip() |
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 OnSearchMessageChanged(self, event): |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
574 |
self.CurrentSearchValue = self.SearchMessage.GetValue() |
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 OnSearchMessageSearchButtonClick(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 OnSearchMessageCancelButtonClick(self, event): |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
584 |
self.CurrentSearchValue = "" |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
585 |
self.SearchMessage.SetValue("") |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
586 |
self.ResetMessagePanel() |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
587 |
event.Skip() |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
588 |
|
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
589 |
def GenerateOnDurationButton(self, duration): |
983
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
590 |
def OnDurationButton(): |
982
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
591 |
self.ScrollMessagePanelByTimestamp(duration) |
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
592 |
return OnDurationButton |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
593 |
|
984 | 594 |
def OnMessagePanelLeftUp(self, event): |
983
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
595 |
if self.CurrentMessage is not None: |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
596 |
posx, posy = event.GetPosition() |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
597 |
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
|
598 |
if button.HitTest(posx, posy): |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
599 |
button.ProcessCallback() |
984 | 600 |
break |
983
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
601 |
event.Skip() |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
602 |
|
986 | 603 |
def OnMessagePanelLeftDCLick(self, event): |
604 |
if self.CurrentMessage is not None: |
|
605 |
posx, posy = event.GetPosition() |
|
606 |
width, height = self.MessagePanel.GetClientSize() |
|
607 |
message_idx = self.CurrentMessage |
|
608 |
message = self.LogMessages[message_idx] |
|
609 |
draw_date = True |
|
610 |
offset = 5 |
|
611 |
||
612 |
while offset < height and message is not None: |
|
613 |
if draw_date: |
|
614 |
offset += DATE_INFO_SIZE |
|
615 |
||
616 |
if offset <= posy < offset + MESSAGE_INFO_SIZE: |
|
617 |
self.CurrentSearchValue = message.Message |
|
618 |
self.SearchMessage.SetValue(message.Message) |
|
619 |
self.ResetMessagePanel() |
|
620 |
break |
|
621 |
||
622 |
offset += MESSAGE_INFO_SIZE |
|
623 |
||
624 |
previous_message, message_idx = self.GetPreviousMessage(message_idx) |
|
625 |
if previous_message is not None: |
|
626 |
draw_date = message.Date != previous_message.Date |
|
627 |
message = previous_message |
|
628 |
event.Skip() |
|
629 |
||
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
630 |
def OnMessagePanelMouseWheel(self, event): |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
631 |
self.ScrollMessagePanel(event.GetWheelRotation() / event.GetWheelDelta()) |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
632 |
event.Skip() |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
633 |
|
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
634 |
def OnMessagePanelPaint(self, event): |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
635 |
self.RefreshView() |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
636 |
event.Skip() |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
637 |
|
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
638 |
def OnMessagePanelResize(self, event): |
984 | 639 |
width, height = self.MessagePanel.GetClientSize() |
640 |
offset = 2 |
|
641 |
for button in self.LeftButtons: |
|
642 |
button.SetPosition(offset, 2) |
|
643 |
w, h = button.GetSize() |
|
644 |
offset += w + 2 |
|
645 |
offset = width - 2 |
|
646 |
for button in self.RightButtons: |
|
647 |
w, h = button.GetSize() |
|
648 |
button.SetPosition(offset - w, 2) |
|
649 |
offset -= w + 2 |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
650 |
if self.IsMessagePanelBottom(): |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
651 |
self.ScrollToFirst() |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
652 |
else: |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
653 |
self.RefreshView() |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
654 |
event.Skip() |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
655 |
|
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
656 |
def OnScrollTimer(self, event): |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
657 |
if self.ScrollSpeed != 0.: |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
658 |
speed_norm = abs(self.ScrollSpeed) |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
659 |
period = REFRESH_PERIOD / speed_norm |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
660 |
self.ScrollMessagePanel(-speed_norm / self.ScrollSpeed) |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
661 |
self.LastStartTime = gettime() |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
662 |
self.ScrollTimer.Start(int(period * 1000), True) |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
663 |
event.Skip() |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
664 |
|
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
665 |
def SetScrollSpeed(self, speed): |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
666 |
if speed == 0.: |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
667 |
self.ScrollTimer.Stop() |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
668 |
else: |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
669 |
speed_norm = abs(speed) |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
670 |
period = REFRESH_PERIOD / speed_norm |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
671 |
current_time = gettime() |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
672 |
if self.LastStartTime is not None: |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
673 |
elapsed_time = current_time - self.LastStartTime |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
674 |
if elapsed_time > period: |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
675 |
self.ScrollMessagePanel(-speed_norm / speed) |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
676 |
self.LastStartTime = current_time |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
677 |
else: |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
678 |
period -= elapsed_time |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
679 |
else: |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
680 |
self.LastStartTime = current_time |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
681 |
self.ScrollTimer.Start(int(period * 1000), True) |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
682 |
self.ScrollSpeed = speed |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
683 |
|
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
684 |
def ScrollToLast(self): |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
685 |
if len(self.LogMessages) > 0: |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
686 |
self.CurrentMessage = len(self.LogMessages) - 1 |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
687 |
message = self.LogMessages[self.CurrentMessage] |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
688 |
if not self.FilterLogMessage(message): |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
689 |
message, self.CurrentMessage = self.GetPreviousMessage(self.CurrentMessage) |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
690 |
self.RefreshView() |
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 ScrollToFirst(self): |
978 | 693 |
if len(self.LogMessages) > 0: |
694 |
message_idx = 0 |
|
695 |
message = self.LogMessages[message_idx] |
|
981
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 |
next_message, msgidx = self.GetNextMessage(message_idx) |
978 | 698 |
if next_message is not None: |
699 |
message_idx = msgidx |
|
700 |
message = next_message |
|
701 |
while message is not None: |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
702 |
message, msgidx = self.GetPreviousMessage(message_idx) |
978 | 703 |
if message is not None: |
704 |
message_idx = msgidx |
|
705 |
message = self.LogMessages[message_idx] |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
706 |
if self.FilterLogMessage(message): |
978 | 707 |
while message is not None: |
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
708 |
message, msgidx = self.GetNextMessage(message_idx) |
978 | 709 |
if message is not None: |
710 |
if not self.IsMessagePanelBottom(msgidx): |
|
711 |
break |
|
712 |
message_idx = msgidx |
|
713 |
self.CurrentMessage = message_idx |
|
714 |
else: |
|
715 |
self.CurrentMessage = None |
|
716 |
self.RefreshView() |