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