author | Andrey Skvortsov <andrej.skvortzov@gmail.com> |
Fri, 05 Oct 2018 13:11:28 +0300 | |
changeset 2435 | 925adaa2cd5c |
parent 2432 | dbc065a2f7a5 |
child 2437 | 105c20fdeb19 |
permissions | -rw-r--r-- |
978 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1441
diff
changeset
|
4 |
# This file is part of Beremiz, a Integrated Development Environment for |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1441
diff
changeset
|
5 |
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival. |
978 | 6 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1441
diff
changeset
|
7 |
# Copyright (C) 2013: Edouard TISSERANT and Laurent BESSARD |
978 | 8 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1441
diff
changeset
|
9 |
# See COPYING file for copyrights details. |
978 | 10 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1441
diff
changeset
|
11 |
# This program is free software; you can redistribute it and/or |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1441
diff
changeset
|
12 |
# modify it under the terms of the GNU General Public License |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1441
diff
changeset
|
13 |
# as published by the Free Software Foundation; either version 2 |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1441
diff
changeset
|
14 |
# of the License, or (at your option) any later version. |
978 | 15 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1441
diff
changeset
|
16 |
# This program is distributed in the hope that it will be useful, |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1441
diff
changeset
|
17 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1441
diff
changeset
|
18 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1441
diff
changeset
|
19 |
# GNU General Public License for more details. |
978 | 20 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1441
diff
changeset
|
21 |
# You should have received a copy of the GNU General Public License |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1441
diff
changeset
|
22 |
# along with this program; if not, write to the Free Software |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1441
diff
changeset
|
23 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1441
diff
changeset
|
24 |
|
978 | 25 |
|
1881
091005ec69c4
fix pylint py3k conversion warning: "(no-absolute-import) import missing `from __future__ import absolute_import`"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1878
diff
changeset
|
26 |
from __future__ import absolute_import |
978 | 27 |
from datetime import datetime |
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
28 |
from time import time as gettime |
1832
0f1081928d65
fix wrong-import-order. first standard modules are imported, then others
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1831
diff
changeset
|
29 |
from weakref import proxy |
0f1081928d65
fix wrong-import-order. first standard modules are imported, then others
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1831
diff
changeset
|
30 |
|
982
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
31 |
import numpy |
978 | 32 |
import wx |
2432
dbc065a2f7a5
python3 support: pylint, W1613 # (xrange-builtin) xrange built-in referenced
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1989
diff
changeset
|
33 |
from six.moves import xrange |
978 | 34 |
|
1169
53e4a2b775a7
Move CustomToolTip from GraphicCommons to controls
Laurent Bessard
parents:
1094
diff
changeset
|
35 |
from controls.CustomToolTip import CustomToolTip, TOOLTIP_WAIT_PERIOD |
1176
f4b434672204
Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents:
1170
diff
changeset
|
36 |
from editors.DebugViewer import DebugViewer, REFRESH_PERIOD |
1902
2b7e2db31d81
Clarify licensing, and packaging of runtime only files :
Edouard Tisserant
parents:
1881
diff
changeset
|
37 |
from runtime.loglevels import LogLevelsCount, LogLevels |
978 | 38 |
from util.BitmapLibrary import GetBitmap |
1832
0f1081928d65
fix wrong-import-order. first standard modules are imported, then others
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1831
diff
changeset
|
39 |
|
978 | 40 |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
41 |
THUMB_SIZE_RATIO = 1. / 8. |
978 | 42 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1735
diff
changeset
|
43 |
|
993 | 44 |
def ArrowPoints(direction, width, height, xoffset, yoffset): |
986 | 45 |
if direction == wx.TOP: |
993 | 46 |
return [wx.Point(xoffset + 1, yoffset + height - 2), |
47 |
wx.Point(xoffset + width / 2, yoffset + 1), |
|
48 |
wx.Point(xoffset + width - 1, yoffset + height - 2)] |
|
986 | 49 |
else: |
993 | 50 |
return [wx.Point(xoffset + 1, yoffset - height + 1), |
51 |
wx.Point(xoffset + width / 2, yoffset - 2), |
|
52 |
wx.Point(xoffset + width - 1, yoffset - height + 1)] |
|
986 | 53 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1735
diff
changeset
|
54 |
|
983
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
55 |
class LogScrollBar(wx.Panel): |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
56 |
|
978 | 57 |
def __init__(self, parent, size): |
58 |
wx.Panel.__init__(self, parent, size=size) |
|
59 |
self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown) |
|
60 |
self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp) |
|
61 |
self.Bind(wx.EVT_MOTION, self.OnMotion) |
|
988
30e7571c10d0
Reduced flicker on LogViewer and DebugGraphPanel on Windows
Laurent Bessard
parents:
987
diff
changeset
|
62 |
self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground) |
978 | 63 |
self.Bind(wx.EVT_PAINT, self.OnPaint) |
64 |
self.Bind(wx.EVT_SIZE, self.OnResize) |
|
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
65 |
|
1737
a39c2918c015
clean-up: fix PEP8 E261 at least two spaces before inline comment
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
66 |
self.ThumbPosition = 0. # -1 <= ThumbPosition <= 1 |
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
67 |
self.ThumbScrollingStartPos = None |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
68 |
|
978 | 69 |
def GetRangeRect(self): |
70 |
width, height = self.GetClientSize() |
|
71 |
return wx.Rect(0, width, width, height - 2 * width) |
|
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
72 |
|
978 | 73 |
def GetThumbRect(self): |
1847
6198190bc121
explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1846
diff
changeset
|
74 |
width, _height = self.GetClientSize() |
978 | 75 |
range_rect = self.GetRangeRect() |
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
76 |
thumb_size = range_rect.height * THUMB_SIZE_RATIO |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
77 |
thumb_range = range_rect.height - thumb_size |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
78 |
thumb_center_position = (thumb_size + (self.ThumbPosition + 1) * thumb_range) / 2. |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
79 |
thumb_start = int(thumb_center_position - thumb_size / 2.) |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
80 |
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
|
81 |
return wx.Rect(0, range_rect.y + thumb_start, width, thumb_end - thumb_start) |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
82 |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
83 |
def RefreshThumbPosition(self, thumb_position=None): |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
84 |
if thumb_position is None: |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
85 |
thumb_position = self.ThumbPosition |
978 | 86 |
if self.Parent.IsMessagePanelTop(): |
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
87 |
thumb_position = max(0., thumb_position) |
978 | 88 |
if self.Parent.IsMessagePanelBottom(): |
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
89 |
thumb_position = min(0., thumb_position) |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
90 |
if thumb_position != self.ThumbPosition: |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
91 |
self.ThumbPosition = thumb_position |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
92 |
self.Parent.SetScrollSpeed(self.ThumbPosition) |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
93 |
self.Refresh() |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
94 |
|
978 | 95 |
def OnLeftDown(self, event): |
96 |
self.CaptureMouse() |
|
97 |
posx, posy = event.GetPosition() |
|
98 |
width, height = self.GetClientSize() |
|
99 |
range_rect = self.GetRangeRect() |
|
100 |
thumb_rect = self.GetThumbRect() |
|
101 |
if range_rect.InsideXY(posx, posy): |
|
102 |
if thumb_rect.InsideXY(posx, posy): |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
103 |
self.ThumbScrollingStartPos = wx.Point(posx, posy) |
978 | 104 |
elif posy < thumb_rect.y: |
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
105 |
self.Parent.ScrollToLast() |
978 | 106 |
elif posy > thumb_rect.y + thumb_rect.height: |
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
107 |
self.Parent.ScrollToFirst() |
978 | 108 |
elif posy < width: |
986 | 109 |
self.Parent.ScrollMessagePanelByPage(1) |
978 | 110 |
elif posy > height - width: |
986 | 111 |
self.Parent.ScrollMessagePanelByPage(-1) |
978 | 112 |
event.Skip() |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
113 |
|
978 | 114 |
def OnLeftUp(self, event): |
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
115 |
self.ThumbScrollingStartPos = None |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
116 |
self.RefreshThumbPosition(0.) |
978 | 117 |
if self.HasCapture(): |
118 |
self.ReleaseMouse() |
|
119 |
event.Skip() |
|
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
120 |
|
978 | 121 |
def OnMotion(self, event): |
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
122 |
if event.Dragging() and self.ThumbScrollingStartPos is not None: |
1847
6198190bc121
explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1846
diff
changeset
|
123 |
_posx, posy = event.GetPosition() |
978 | 124 |
range_rect = self.GetRangeRect() |
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
125 |
thumb_size = range_rect.height * THUMB_SIZE_RATIO |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
126 |
thumb_range = range_rect.height - thumb_size |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
127 |
self.RefreshThumbPosition( |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
128 |
max(-1., min((posy - self.ThumbScrollingStartPos.y) * 2. / thumb_range, 1.))) |
978 | 129 |
event.Skip() |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
130 |
|
978 | 131 |
def OnResize(self, event): |
132 |
self.Refresh() |
|
133 |
event.Skip() |
|
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
134 |
|
988
30e7571c10d0
Reduced flicker on LogViewer and DebugGraphPanel on Windows
Laurent Bessard
parents:
987
diff
changeset
|
135 |
def OnEraseBackground(self, event): |
30e7571c10d0
Reduced flicker on LogViewer and DebugGraphPanel on Windows
Laurent Bessard
parents:
987
diff
changeset
|
136 |
pass |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
137 |
|
978 | 138 |
def OnPaint(self, event): |
139 |
dc = wx.BufferedPaintDC(self) |
|
140 |
dc.Clear() |
|
141 |
dc.BeginDrawing() |
|
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
142 |
|
987
7ca88194ae89
Improved graphics of LogViewer scrollbar to be anti-aliased
Laurent Bessard
parents:
986
diff
changeset
|
143 |
gc = wx.GCDC(dc) |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
144 |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
145 |
width, height = self.GetClientSize() |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
146 |
|
993 | 147 |
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
|
148 |
gc.SetBrush(wx.GREY_BRUSH) |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
149 |
|
993 | 150 |
gc.DrawLines(ArrowPoints(wx.TOP, width * 0.75, width * 0.5, 2, (width + height) / 4 - 3)) |
151 |
gc.DrawLines(ArrowPoints(wx.TOP, width * 0.75, width * 0.5, 2, (width + height) / 4 + 3)) |
|
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
152 |
|
993 | 153 |
gc.DrawLines(ArrowPoints(wx.BOTTOM, width * 0.75, width * 0.5, 2, (height * 3 - width) / 4 + 3)) |
154 |
gc.DrawLines(ArrowPoints(wx.BOTTOM, width * 0.75, width * 0.5, 2, (height * 3 - width) / 4 - 3)) |
|
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
155 |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
156 |
thumb_rect = self.GetThumbRect() |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
157 |
exclusion_rect = wx.Rect(thumb_rect.x, thumb_rect.y, |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
158 |
thumb_rect.width, thumb_rect.height) |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
159 |
if self.Parent.IsMessagePanelTop(): |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
160 |
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
|
161 |
if self.Parent.IsMessagePanelBottom(): |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
162 |
exclusion_rect.height = height - width - exclusion_rect.y |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
163 |
if exclusion_rect != thumb_rect: |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
164 |
colour = wx.NamedColour("LIGHT GREY") |
987
7ca88194ae89
Improved graphics of LogViewer scrollbar to be anti-aliased
Laurent Bessard
parents:
986
diff
changeset
|
165 |
gc.SetPen(wx.Pen(colour)) |
7ca88194ae89
Improved graphics of LogViewer scrollbar to be anti-aliased
Laurent Bessard
parents:
986
diff
changeset
|
166 |
gc.SetBrush(wx.Brush(colour)) |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
167 |
|
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
168 |
gc.DrawRectangle(exclusion_rect.x, exclusion_rect.y, |
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
169 |
exclusion_rect.width, exclusion_rect.height) |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
170 |
|
987
7ca88194ae89
Improved graphics of LogViewer scrollbar to be anti-aliased
Laurent Bessard
parents:
986
diff
changeset
|
171 |
gc.SetPen(wx.GREY_PEN) |
7ca88194ae89
Improved graphics of LogViewer scrollbar to be anti-aliased
Laurent Bessard
parents:
986
diff
changeset
|
172 |
gc.SetBrush(wx.GREY_BRUSH) |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
173 |
|
993 | 174 |
gc.DrawPolygon(ArrowPoints(wx.TOP, width, width, 0, 0)) |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
175 |
|
993 | 176 |
gc.DrawPolygon(ArrowPoints(wx.BOTTOM, width, width, 0, height)) |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
177 |
|
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
178 |
gc.DrawRectangle(thumb_rect.x, thumb_rect.y, |
978 | 179 |
thumb_rect.width, thumb_rect.height) |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
180 |
|
978 | 181 |
dc.EndDrawing() |
182 |
event.Skip() |
|
183 |
||
1749
d73b64672238
clean-up: fix PEP8 E305 expected 2 blank lines after class or function definition
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1745
diff
changeset
|
184 |
|
1576
6df9937f130b
increase size for time buttons in LogViewer
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
185 |
BUTTON_SIZE = (70, 15) |
983
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
186 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1735
diff
changeset
|
187 |
|
1831
56b48961cc68
fix (old-style-class) Old-style class defined error for most parts of
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
188 |
class LogButton(object): |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
189 |
|
983
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
190 |
def __init__(self, label, callback): |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
191 |
self.Position = wx.Point(0, 0) |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
192 |
self.Size = wx.Size(*BUTTON_SIZE) |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
193 |
self.Label = label |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
194 |
self.Shown = True |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
195 |
self.Callback = callback |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
196 |
|
983
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
197 |
def __del__(self): |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
198 |
self.callback = None |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
199 |
|
983
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
200 |
def GetSize(self): |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
201 |
return self.Size |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
202 |
|
983
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
203 |
def SetPosition(self, x, y): |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
204 |
self.Position = wx.Point(x, y) |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
205 |
|
983
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
206 |
def HitTest(self, x, y): |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
207 |
rect = wx.Rect(self.Position.x, self.Position.y, |
983
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
208 |
self.Size.width, self.Size.height) |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
209 |
if rect.InsideXY(x, y): |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
210 |
return True |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
211 |
return False |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
212 |
|
983
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
213 |
def ProcessCallback(self): |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
214 |
if self.Callback is not None: |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
215 |
wx.CallAfter(self.Callback) |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
216 |
|
983
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
217 |
def Draw(self, dc): |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
218 |
dc.SetPen(wx.TRANSPARENT_PEN) |
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
219 |
dc.SetBrush(wx.Brush(wx.NamedColour("LIGHT GREY"))) |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
220 |
|
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
221 |
dc.DrawRectangle(self.Position.x, self.Position.y, |
983
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
222 |
self.Size.width, self.Size.height) |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
223 |
|
983
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
224 |
w, h = dc.GetTextExtent(self.Label) |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
225 |
dc.DrawText(self.Label, |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1749
diff
changeset
|
226 |
self.Position.x + (self.Size.width - w) / 2, |
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1749
diff
changeset
|
227 |
self.Position.y + (self.Size.height - h) / 2) |
983
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
228 |
|
1749
d73b64672238
clean-up: fix PEP8 E305 expected 2 blank lines after class or function definition
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1745
diff
changeset
|
229 |
|
978 | 230 |
DATE_INFO_SIZE = 10 |
997 | 231 |
MESSAGE_INFO_SIZE = 18 |
978 | 232 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1735
diff
changeset
|
233 |
|
1831
56b48961cc68
fix (old-style-class) Old-style class defined error for most parts of
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1768
diff
changeset
|
234 |
class LogMessage(object): |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
235 |
|
978 | 236 |
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
|
237 |
self.Date = datetime.utcfromtimestamp(tv_sec) |
978 | 238 |
self.Seconds = self.Date.second + tv_nsec * 1e-9 |
239 |
self.Date = self.Date.replace(second=0) |
|
982
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
240 |
self.Timestamp = tv_sec + tv_nsec * 1e-9 |
978 | 241 |
self.Level = level |
242 |
self.LevelBitmap = level_bitmap |
|
243 |
self.Message = msg |
|
244 |
self.DrawDate = True |
|
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
245 |
|
978 | 246 |
def __cmp__(self, other): |
247 |
if self.Date == other.Date: |
|
248 |
return cmp(self.Seconds, other.Seconds) |
|
249 |
return cmp(self.Date, other.Date) |
|
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
250 |
|
993 | 251 |
def GetFullText(self): |
252 |
date = self.Date.replace(second=int(self.Seconds)) |
|
253 |
nsec = (self.Seconds % 1.) * 1e9 |
|
254 |
return "%s at %s.%9.9d:\n%s" % ( |
|
255 |
LogLevels[self.Level], |
|
256 |
str(date), nsec, |
|
257 |
self.Message) |
|
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
258 |
|
978 | 259 |
def Draw(self, dc, offset, width, draw_date): |
260 |
if draw_date: |
|
261 |
datetime_text = self.Date.strftime("%d/%m/%y %H:%M") |
|
262 |
dw, dh = dc.GetTextExtent(datetime_text) |
|
263 |
dc.DrawText(datetime_text, (width - dw) / 2, offset + (DATE_INFO_SIZE - dh) / 2) |
|
264 |
offset += DATE_INFO_SIZE |
|
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
265 |
|
978 | 266 |
seconds_text = "%12.9f" % self.Seconds |
267 |
sw, sh = dc.GetTextExtent(seconds_text) |
|
268 |
dc.DrawText(seconds_text, 5, offset + (MESSAGE_INFO_SIZE - sh) / 2) |
|
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
269 |
|
978 | 270 |
bw, bh = self.LevelBitmap.GetWidth(), self.LevelBitmap.GetHeight() |
271 |
dc.DrawBitmap(self.LevelBitmap, 10 + sw, offset + (MESSAGE_INFO_SIZE - bh) / 2) |
|
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
272 |
|
993 | 273 |
text = self.Message.replace("\n", " ") |
1847
6198190bc121
explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1846
diff
changeset
|
274 |
_mw, mh = dc.GetTextExtent(text) |
993 | 275 |
dc.DrawText(text, 15 + sw + bw, offset + (MESSAGE_INFO_SIZE - mh) / 2) |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
276 |
|
978 | 277 |
def GetHeight(self, draw_date): |
278 |
if draw_date: |
|
279 |
return DATE_INFO_SIZE + MESSAGE_INFO_SIZE |
|
280 |
return MESSAGE_INFO_SIZE |
|
281 |
||
1749
d73b64672238
clean-up: fix PEP8 E305 expected 2 blank lines after class or function definition
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1745
diff
changeset
|
282 |
|
978 | 283 |
SECOND = 1 |
284 |
MINUTE = 60 * SECOND |
|
285 |
HOUR = 60 * MINUTE |
|
286 |
DAY = 24 * HOUR |
|
287 |
||
288 |
CHANGE_TIMESTAMP_BUTTONS = [(_("1d"), DAY), |
|
289 |
(_("1h"), HOUR), |
|
986 | 290 |
(_("1m"), MINUTE), |
291 |
(_("1s"), SECOND)] |
|
978 | 292 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1735
diff
changeset
|
293 |
|
978 | 294 |
class LogViewer(DebugViewer, wx.Panel): |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
295 |
|
978 | 296 |
def __init__(self, parent, window): |
1745
f9d32913bad4
clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
297 |
wx.Panel.__init__(self, parent, style=wx.TAB_TRAVERSAL | wx.SUNKEN_BORDER) |
978 | 298 |
DebugViewer.__init__(self, None, False, False) |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
299 |
|
978 | 300 |
main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5) |
301 |
main_sizer.AddGrowableCol(0) |
|
302 |
main_sizer.AddGrowableRow(1) |
|
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
303 |
|
978 | 304 |
filter_sizer = wx.BoxSizer(wx.HORIZONTAL) |
1745
f9d32913bad4
clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
305 |
main_sizer.AddSizer(filter_sizer, border=5, flag=wx.TOP | wx.LEFT | wx.RIGHT | wx.GROW) |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
306 |
|
978 | 307 |
self.MessageFilter = wx.ComboBox(self, style=wx.CB_READONLY) |
308 |
self.MessageFilter.Append(_("All")) |
|
309 |
levels = LogLevels[:3] |
|
310 |
levels.reverse() |
|
311 |
for level in levels: |
|
312 |
self.MessageFilter.Append(_(level)) |
|
313 |
self.Bind(wx.EVT_COMBOBOX, self.OnMessageFilterChanged, self.MessageFilter) |
|
1745
f9d32913bad4
clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
314 |
filter_sizer.AddWindow(self.MessageFilter, 1, border=5, flag=wx.RIGHT | wx.ALIGN_CENTER_VERTICAL) |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
315 |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
316 |
self.SearchMessage = wx.SearchCtrl(self, style=wx.TE_PROCESS_ENTER) |
978 | 317 |
self.SearchMessage.ShowSearchButton(True) |
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
318 |
self.SearchMessage.ShowCancelButton(True) |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
319 |
self.Bind(wx.EVT_TEXT_ENTER, self.OnSearchMessageChanged, self.SearchMessage) |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
320 |
self.Bind(wx.EVT_SEARCHCTRL_SEARCH_BTN, |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1749
diff
changeset
|
321 |
self.OnSearchMessageSearchButtonClick, self.SearchMessage) |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
322 |
self.Bind(wx.EVT_SEARCHCTRL_CANCEL_BTN, |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1749
diff
changeset
|
323 |
self.OnSearchMessageCancelButtonClick, self.SearchMessage) |
1745
f9d32913bad4
clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
324 |
filter_sizer.AddWindow(self.SearchMessage, 3, border=5, flag=wx.RIGHT | wx.ALIGN_CENTER_VERTICAL) |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
325 |
|
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
326 |
self.CleanButton = wx.lib.buttons.GenBitmapButton(self, bitmap=GetBitmap("Clean"), |
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1749
diff
changeset
|
327 |
size=wx.Size(28, 28), style=wx.NO_BORDER) |
1093 | 328 |
self.CleanButton.SetToolTipString(_("Clean log messages")) |
329 |
self.Bind(wx.EVT_BUTTON, self.OnCleanButton, self.CleanButton) |
|
330 |
filter_sizer.AddWindow(self.CleanButton) |
|
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
331 |
|
983
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
332 |
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
|
333 |
message_panel_sizer.AddGrowableCol(0) |
978 | 334 |
message_panel_sizer.AddGrowableRow(0) |
1745
f9d32913bad4
clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
335 |
main_sizer.AddSizer(message_panel_sizer, border=5, flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.GROW) |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
336 |
|
978 | 337 |
self.MessagePanel = wx.Panel(self) |
338 |
if wx.Platform == '__WXMSW__': |
|
993 | 339 |
self.Font = wx.Font(8, wx.SWISS, wx.NORMAL, wx.NORMAL, faceName='Courier New') |
978 | 340 |
else: |
993 | 341 |
self.Font = wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL, faceName='Courier') |
984 | 342 |
self.MessagePanel.Bind(wx.EVT_LEFT_UP, self.OnMessagePanelLeftUp) |
993 | 343 |
self.MessagePanel.Bind(wx.EVT_RIGHT_UP, self.OnMessagePanelRightUp) |
986 | 344 |
self.MessagePanel.Bind(wx.EVT_LEFT_DCLICK, self.OnMessagePanelLeftDCLick) |
993 | 345 |
self.MessagePanel.Bind(wx.EVT_MOTION, self.OnMessagePanelMotion) |
346 |
self.MessagePanel.Bind(wx.EVT_LEAVE_WINDOW, self.OnMessagePanelLeaveWindow) |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
347 |
self.MessagePanel.Bind(wx.EVT_MOUSEWHEEL, self.OnMessagePanelMouseWheel) |
988
30e7571c10d0
Reduced flicker on LogViewer and DebugGraphPanel on Windows
Laurent Bessard
parents:
987
diff
changeset
|
348 |
self.MessagePanel.Bind(wx.EVT_ERASE_BACKGROUND, self.OnMessagePanelEraseBackground) |
978 | 349 |
self.MessagePanel.Bind(wx.EVT_PAINT, self.OnMessagePanelPaint) |
350 |
self.MessagePanel.Bind(wx.EVT_SIZE, self.OnMessagePanelResize) |
|
351 |
message_panel_sizer.AddWindow(self.MessagePanel, flag=wx.GROW) |
|
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
352 |
|
983
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
353 |
self.MessageScrollBar = LogScrollBar(self, wx.Size(16, -1)) |
978 | 354 |
message_panel_sizer.AddWindow(self.MessageScrollBar, flag=wx.GROW) |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
355 |
|
978 | 356 |
self.SetSizer(main_sizer) |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
357 |
|
983
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
358 |
self.LeftButtons = [] |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
359 |
for label, callback in [("+" + text, self.GenerateOnDurationButton(duration)) |
983
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
360 |
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
|
361 |
self.LeftButtons.append(LogButton(label, callback)) |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
362 |
|
983
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
363 |
self.RightButtons = [] |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
364 |
for label, callback in [("-" + text, self.GenerateOnDurationButton(-duration)) |
983
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
365 |
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
|
366 |
self.RightButtons.append(LogButton(label, callback)) |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
367 |
|
978 | 368 |
self.MessageFilter.SetSelection(0) |
369 |
self.LogSource = None |
|
370 |
self.ResetLogMessages() |
|
371 |
self.ParentWindow = window |
|
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
372 |
|
979 | 373 |
self.LevelIcons = [GetBitmap("LOG_" + level) for level in LogLevels] |
978 | 374 |
self.LevelFilters = [range(i) for i in xrange(4, 0, -1)] |
375 |
self.CurrentFilter = self.LevelFilters[0] |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
376 |
self.CurrentSearchValue = "" |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
377 |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
378 |
self.ScrollSpeed = 0. |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
379 |
self.LastStartTime = None |
978 | 380 |
self.ScrollTimer = wx.Timer(self, -1) |
381 |
self.Bind(wx.EVT_TIMER, self.OnScrollTimer, self.ScrollTimer) |
|
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
382 |
|
993 | 383 |
self.LastMousePos = None |
384 |
self.MessageToolTip = None |
|
385 |
self.MessageToolTipTimer = wx.Timer(self, -1) |
|
386 |
self.Bind(wx.EVT_TIMER, self.OnMessageToolTipTimer, self.MessageToolTipTimer) |
|
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
387 |
|
978 | 388 |
def __del__(self): |
389 |
self.ScrollTimer.Stop() |
|
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
390 |
|
978 | 391 |
def ResetLogMessages(self): |
1672
9298ba0cd70a
reset loaded messages counts on new PLC program trasnfer
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1576
diff
changeset
|
392 |
self.ResetLogCounters() |
978 | 393 |
self.OldestMessages = [] |
394 |
self.LogMessages = [] |
|
982
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
395 |
self.LogMessagesTimestamp = numpy.array([]) |
978 | 396 |
self.CurrentMessage = None |
397 |
self.HasNewData = False |
|
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
398 |
|
978 | 399 |
def SetLogSource(self, log_source): |
1989 | 400 |
self.LogSource = proxy(log_source) if log_source is not None else None |
1093 | 401 |
self.CleanButton.Enable(self.LogSource is not None) |
978 | 402 |
if log_source is not None: |
403 |
self.ResetLogMessages() |
|
1871
933fbe9a5e2c
fix problem happend when tests are running under python-coverage
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1847
diff
changeset
|
404 |
wx.CallAfter(self.RefreshView) |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
405 |
|
978 | 406 |
def GetLogMessageFromSource(self, msgidx, level): |
407 |
if self.LogSource is not None: |
|
408 |
answer = self.LogSource.GetLogMessage(level, msgidx) |
|
409 |
if answer is not None: |
|
1847
6198190bc121
explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1846
diff
changeset
|
410 |
msg, _tick, tv_sec, tv_nsec = answer |
978 | 411 |
return LogMessage(tv_sec, tv_nsec, level, self.LevelIcons[level], msg) |
412 |
return None |
|
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
413 |
|
1672
9298ba0cd70a
reset loaded messages counts on new PLC program trasnfer
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1576
diff
changeset
|
414 |
def ResetLogCounters(self): |
9298ba0cd70a
reset loaded messages counts on new PLC program trasnfer
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1576
diff
changeset
|
415 |
self.previous_log_count = [None]*LogLevelsCount |
1735
c02818d7e29f
clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1673
diff
changeset
|
416 |
|
978 | 417 |
def SetLogCounters(self, log_count): |
418 |
new_messages = [] |
|
419 |
for level, count, prev in zip(xrange(LogLevelsCount), log_count, self.previous_log_count): |
|
420 |
if count is not None and prev != count: |
|
421 |
if prev is None: |
|
1195
8f8d9859e9fc
Fixed bug when collecting log messages from connector history for LogViewer
Laurent Bessard
parents:
1176
diff
changeset
|
422 |
dump_end = max(-1, count - 10) |
8f8d9859e9fc
Fixed bug when collecting log messages from connector history for LogViewer
Laurent Bessard
parents:
1176
diff
changeset
|
423 |
oldest_message = (-1, None) |
978 | 424 |
else: |
425 |
dump_end = prev - 1 |
|
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1737
diff
changeset
|
426 |
for msgidx in xrange(count-1, dump_end, -1): |
978 | 427 |
new_message = self.GetLogMessageFromSource(msgidx, level) |
1093 | 428 |
if new_message is None: |
1195
8f8d9859e9fc
Fixed bug when collecting log messages from connector history for LogViewer
Laurent Bessard
parents:
1176
diff
changeset
|
429 |
if prev is None: |
8f8d9859e9fc
Fixed bug when collecting log messages from connector history for LogViewer
Laurent Bessard
parents:
1176
diff
changeset
|
430 |
oldest_message = (-1, None) |
1093 | 431 |
break |
432 |
if prev is None: |
|
1195
8f8d9859e9fc
Fixed bug when collecting log messages from connector history for LogViewer
Laurent Bessard
parents:
1176
diff
changeset
|
433 |
oldest_message = (msgidx, new_message) |
1093 | 434 |
if len(new_messages) == 0: |
435 |
new_messages = [new_message] |
|
978 | 436 |
else: |
437 |
new_messages.insert(0, new_message) |
|
1093 | 438 |
else: |
439 |
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
|
440 |
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
|
441 |
self.OldestMessages.append(oldest_message) |
978 | 442 |
self.previous_log_count[level] = count |
443 |
new_messages.sort() |
|
444 |
if len(new_messages) > 0: |
|
445 |
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
|
446 |
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
|
447 |
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
|
448 |
else: |
5e740fe71fbe
Fixed bug in LogViewer when view is filtered and displaying last message and new messages appears
Laurent Bessard
parents:
1020
diff
changeset
|
449 |
current_is_last = True |
978 | 450 |
for new_message in new_messages: |
451 |
self.LogMessages.append(new_message) |
|
982
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
452 |
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
|
453 |
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
|
454 |
self.ScrollToLast(False) |
993 | 455 |
self.ResetMessageToolTip() |
456 |
self.MessageToolTipTimer.Stop() |
|
999
cbab4c1635bd
Replaced LogConsole TextCtrl by StyledTextCtrl
Laurent Bessard
parents:
997
diff
changeset
|
457 |
self.ParentWindow.SelectTab(self) |
978 | 458 |
self.NewDataAvailable(None) |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
459 |
|
982
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
460 |
def FilterLogMessage(self, message, timestamp=None): |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
461 |
return (message.Level in self.CurrentFilter and |
982
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
462 |
message.Message.find(self.CurrentSearchValue) != -1 and |
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
463 |
(timestamp is None or message.Timestamp < timestamp)) |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
464 |
|
982
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
465 |
def GetMessageByTimestamp(self, timestamp): |
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
466 |
if self.CurrentMessage is not None: |
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
467 |
msgidx = numpy.argmin(abs(self.LogMessagesTimestamp - timestamp)) |
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
468 |
message = self.LogMessages[msgidx] |
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
469 |
if self.FilterLogMessage(message) and message.Timestamp > timestamp: |
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
470 |
return self.GetPreviousMessage(msgidx, timestamp) |
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
471 |
return message, msgidx |
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
472 |
return None, None |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
473 |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
474 |
def GetNextMessage(self, msgidx): |
978 | 475 |
while msgidx < len(self.LogMessages) - 1: |
476 |
message = self.LogMessages[msgidx + 1] |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
477 |
if self.FilterLogMessage(message): |
978 | 478 |
return message, msgidx + 1 |
479 |
msgidx += 1 |
|
480 |
return None, None |
|
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
481 |
|
982
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
482 |
def GetPreviousMessage(self, msgidx, timestamp=None): |
978 | 483 |
message = None |
484 |
while 0 < msgidx < len(self.LogMessages): |
|
485 |
message = self.LogMessages[msgidx - 1] |
|
982
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
486 |
if self.FilterLogMessage(message, timestamp): |
978 | 487 |
return message, msgidx - 1 |
488 |
msgidx -= 1 |
|
489 |
if len(self.LogMessages) > 0: |
|
490 |
message = self.LogMessages[0] |
|
1847
6198190bc121
explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1846
diff
changeset
|
491 |
for _idx, msg in self.OldestMessages: |
1195
8f8d9859e9fc
Fixed bug when collecting log messages from connector history for LogViewer
Laurent Bessard
parents:
1176
diff
changeset
|
492 |
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
|
493 |
message = msg |
978 | 494 |
while message is not None: |
495 |
level = message.Level |
|
1847
6198190bc121
explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1846
diff
changeset
|
496 |
oldest_msgidx, _oldest_message = self.OldestMessages[level] |
978 | 497 |
if oldest_msgidx > 0: |
1195
8f8d9859e9fc
Fixed bug when collecting log messages from connector history for LogViewer
Laurent Bessard
parents:
1176
diff
changeset
|
498 |
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
|
499 |
if message is not None: |
8f8d9859e9fc
Fixed bug when collecting log messages from connector history for LogViewer
Laurent Bessard
parents:
1176
diff
changeset
|
500 |
self.OldestMessages[level] = (oldest_msgidx - 1, message) |
978 | 501 |
else: |
502 |
self.OldestMessages[level] = (-1, None) |
|
503 |
else: |
|
1195
8f8d9859e9fc
Fixed bug when collecting log messages from connector history for LogViewer
Laurent Bessard
parents:
1176
diff
changeset
|
504 |
message = None |
978 | 505 |
self.OldestMessages[level] = (-1, None) |
1195
8f8d9859e9fc
Fixed bug when collecting log messages from connector history for LogViewer
Laurent Bessard
parents:
1176
diff
changeset
|
506 |
if message is not None: |
8f8d9859e9fc
Fixed bug when collecting log messages from connector history for LogViewer
Laurent Bessard
parents:
1176
diff
changeset
|
507 |
message_idx = 0 |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
508 |
while (message_idx < len(self.LogMessages) and |
1195
8f8d9859e9fc
Fixed bug when collecting log messages from connector history for LogViewer
Laurent Bessard
parents:
1176
diff
changeset
|
509 |
self.LogMessages[message_idx] < message): |
8f8d9859e9fc
Fixed bug when collecting log messages from connector history for LogViewer
Laurent Bessard
parents:
1176
diff
changeset
|
510 |
message_idx += 1 |
8f8d9859e9fc
Fixed bug when collecting log messages from connector history for LogViewer
Laurent Bessard
parents:
1176
diff
changeset
|
511 |
if len(self.LogMessages) > 0: |
8f8d9859e9fc
Fixed bug when collecting log messages from connector history for LogViewer
Laurent Bessard
parents:
1176
diff
changeset
|
512 |
current_message = self.LogMessages[self.CurrentMessage] |
8f8d9859e9fc
Fixed bug when collecting log messages from connector history for LogViewer
Laurent Bessard
parents:
1176
diff
changeset
|
513 |
else: |
8f8d9859e9fc
Fixed bug when collecting log messages from connector history for LogViewer
Laurent Bessard
parents:
1176
diff
changeset
|
514 |
current_message = message |
8f8d9859e9fc
Fixed bug when collecting log messages from connector history for LogViewer
Laurent Bessard
parents:
1176
diff
changeset
|
515 |
self.LogMessages.insert(message_idx, message) |
8f8d9859e9fc
Fixed bug when collecting log messages from connector history for LogViewer
Laurent Bessard
parents:
1176
diff
changeset
|
516 |
self.LogMessagesTimestamp = numpy.insert( |
1878
fb73a6b6622d
fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1871
diff
changeset
|
517 |
self.LogMessagesTimestamp, |
fb73a6b6622d
fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1871
diff
changeset
|
518 |
[message_idx], |
fb73a6b6622d
fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1871
diff
changeset
|
519 |
[message.Timestamp]) |
1195
8f8d9859e9fc
Fixed bug when collecting log messages from connector history for LogViewer
Laurent Bessard
parents:
1176
diff
changeset
|
520 |
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
|
521 |
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
|
522 |
return message, 0 |
1847
6198190bc121
explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1846
diff
changeset
|
523 |
for _idx, msg in self.OldestMessages: |
978 | 524 |
if msg is not None and (message is None or msg > message): |
525 |
message = msg |
|
526 |
return None, None |
|
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
527 |
|
978 | 528 |
def RefreshNewData(self, *args, **kwargs): |
529 |
if self.HasNewData: |
|
530 |
self.HasNewData = False |
|
531 |
self.RefreshView() |
|
532 |
DebugViewer.RefreshNewData(self, *args, **kwargs) |
|
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
533 |
|
978 | 534 |
def RefreshView(self): |
535 |
width, height = self.MessagePanel.GetClientSize() |
|
536 |
bitmap = wx.EmptyBitmap(width, height) |
|
537 |
dc = wx.BufferedDC(wx.ClientDC(self.MessagePanel), bitmap) |
|
538 |
dc.Clear() |
|
539 |
dc.BeginDrawing() |
|
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
540 |
|
978 | 541 |
if self.CurrentMessage is not None: |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
542 |
|
993 | 543 |
dc.SetFont(self.Font) |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
544 |
|
983
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
545 |
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
|
546 |
button.Draw(dc) |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
547 |
|
978 | 548 |
message_idx = self.CurrentMessage |
549 |
message = self.LogMessages[message_idx] |
|
550 |
draw_date = True |
|
551 |
offset = 5 |
|
552 |
while offset < height and message is not None: |
|
553 |
message.Draw(dc, offset, width, draw_date) |
|
554 |
offset += message.GetHeight(draw_date) |
|
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
555 |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
556 |
previous_message, message_idx = self.GetPreviousMessage(message_idx) |
978 | 557 |
if previous_message is not None: |
558 |
draw_date = message.Date != previous_message.Date |
|
559 |
message = previous_message |
|
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
560 |
|
978 | 561 |
dc.EndDrawing() |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
562 |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
563 |
self.MessageScrollBar.RefreshThumbPosition() |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
564 |
|
1673
fab1b8da6eba
clean PLC log only if there is something to clean
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1672
diff
changeset
|
565 |
def IsPLCLogEmpty(self): |
1742
92932cd370a4
clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1740
diff
changeset
|
566 |
empty = True |
1847
6198190bc121
explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1846
diff
changeset
|
567 |
for _level, prev in zip(xrange(LogLevelsCount), self.previous_log_count): |
1673
fab1b8da6eba
clean PLC log only if there is something to clean
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1672
diff
changeset
|
568 |
if prev is not None: |
1742
92932cd370a4
clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1740
diff
changeset
|
569 |
empty = False |
1673
fab1b8da6eba
clean PLC log only if there is something to clean
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1672
diff
changeset
|
570 |
break |
fab1b8da6eba
clean PLC log only if there is something to clean
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1672
diff
changeset
|
571 |
return empty |
1735
c02818d7e29f
clean-up: fix PEP8 W293 blank line contains whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1673
diff
changeset
|
572 |
|
978 | 573 |
def IsMessagePanelTop(self, message_idx=None): |
574 |
if message_idx is None: |
|
575 |
message_idx = self.CurrentMessage |
|
576 |
if message_idx is not None: |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
577 |
return self.GetNextMessage(message_idx)[0] is None |
978 | 578 |
return True |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
579 |
|
978 | 580 |
def IsMessagePanelBottom(self, message_idx=None): |
581 |
if message_idx is None: |
|
582 |
message_idx = self.CurrentMessage |
|
583 |
if message_idx is not None: |
|
1847
6198190bc121
explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1846
diff
changeset
|
584 |
_width, height = self.MessagePanel.GetClientSize() |
978 | 585 |
offset = 5 |
586 |
message = self.LogMessages[message_idx] |
|
587 |
draw_date = True |
|
588 |
while message is not None and offset < height: |
|
589 |
offset += message.GetHeight(draw_date) |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
590 |
previous_message, message_idx = self.GetPreviousMessage(message_idx) |
978 | 591 |
if previous_message is not None: |
592 |
draw_date = message.Date != previous_message.Date |
|
593 |
message = previous_message |
|
594 |
return offset < height |
|
595 |
return True |
|
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
596 |
|
978 | 597 |
def ScrollMessagePanel(self, scroll): |
598 |
if self.CurrentMessage is not None: |
|
599 |
message = self.LogMessages[self.CurrentMessage] |
|
600 |
while scroll > 0 and message is not None: |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
601 |
message, msgidx = self.GetNextMessage(self.CurrentMessage) |
978 | 602 |
if message is not None: |
603 |
self.CurrentMessage = msgidx |
|
604 |
scroll -= 1 |
|
605 |
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
|
606 |
message, msgidx = self.GetPreviousMessage(self.CurrentMessage) |
978 | 607 |
if message is not None: |
608 |
self.CurrentMessage = msgidx |
|
609 |
scroll += 1 |
|
610 |
self.RefreshView() |
|
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
611 |
|
986 | 612 |
def ScrollMessagePanelByPage(self, page): |
613 |
if self.CurrentMessage is not None: |
|
1847
6198190bc121
explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1846
diff
changeset
|
614 |
_width, height = self.MessagePanel.GetClientSize() |
986 | 615 |
message_per_page = max(1, (height - DATE_INFO_SIZE) / MESSAGE_INFO_SIZE - 1) |
616 |
self.ScrollMessagePanel(page * message_per_page) |
|
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
617 |
|
982
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
618 |
def ScrollMessagePanelByTimestamp(self, seconds): |
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
619 |
if self.CurrentMessage is not None: |
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
620 |
current_message = self.LogMessages[self.CurrentMessage] |
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
621 |
message, msgidx = self.GetMessageByTimestamp(current_message.Timestamp + seconds) |
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
622 |
if message is None or self.IsMessagePanelBottom(msgidx): |
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
623 |
self.ScrollToFirst() |
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
624 |
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
|
625 |
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
|
626 |
msgidx += 1 |
982
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
627 |
self.CurrentMessage = msgidx |
984 | 628 |
self.RefreshView() |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
629 |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
630 |
def ResetMessagePanel(self): |
978 | 631 |
if len(self.LogMessages) > 0: |
632 |
self.CurrentMessage = len(self.LogMessages) - 1 |
|
633 |
message = self.LogMessages[self.CurrentMessage] |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
634 |
while message is not None and not self.FilterLogMessage(message): |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
635 |
message, self.CurrentMessage = self.GetPreviousMessage(self.CurrentMessage) |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
636 |
self.RefreshView() |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
637 |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
638 |
def OnMessageFilterChanged(self, event): |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
639 |
self.CurrentFilter = self.LevelFilters[self.MessageFilter.GetSelection()] |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
640 |
self.ResetMessagePanel() |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
641 |
event.Skip() |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
642 |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
643 |
def OnSearchMessageChanged(self, event): |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
644 |
self.CurrentSearchValue = self.SearchMessage.GetValue() |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
645 |
self.ResetMessagePanel() |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
646 |
event.Skip() |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
647 |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
648 |
def OnSearchMessageSearchButtonClick(self, event): |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
649 |
self.CurrentSearchValue = self.SearchMessage.GetValue() |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
650 |
self.ResetMessagePanel() |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
651 |
event.Skip() |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
652 |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
653 |
def OnSearchMessageCancelButtonClick(self, event): |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
654 |
self.CurrentSearchValue = "" |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
655 |
self.SearchMessage.SetValue("") |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
656 |
self.ResetMessagePanel() |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
657 |
event.Skip() |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
658 |
|
1093 | 659 |
def OnCleanButton(self, event): |
1673
fab1b8da6eba
clean PLC log only if there is something to clean
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1672
diff
changeset
|
660 |
if self.LogSource is not None and not self.IsPLCLogEmpty(): |
1093 | 661 |
self.LogSource.ResetLogCount() |
662 |
self.ResetLogMessages() |
|
663 |
self.RefreshView() |
|
664 |
event.Skip() |
|
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
665 |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
666 |
def GenerateOnDurationButton(self, duration): |
983
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
667 |
def OnDurationButton(): |
982
e3c264099bd0
Added support in LogViewer for scrolling using relative timestamp
Laurent Bessard
parents:
981
diff
changeset
|
668 |
self.ScrollMessagePanelByTimestamp(duration) |
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
669 |
return OnDurationButton |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
670 |
|
993 | 671 |
def GetCopyMessageToClipboardFunction(self, message): |
672 |
def CopyMessageToClipboardFunction(event): |
|
673 |
self.ParentWindow.SetCopyBuffer(message.GetFullText()) |
|
674 |
return CopyMessageToClipboardFunction |
|
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
675 |
|
993 | 676 |
def GetMessageByScreenPos(self, posx, posy): |
983
7dd481eef3b5
Replaced left ugly buttons in LogViewer by custom buttons inside MessagePanel
Laurent Bessard
parents:
982
diff
changeset
|
677 |
if self.CurrentMessage is not None: |
1847
6198190bc121
explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1846
diff
changeset
|
678 |
_width, height = self.MessagePanel.GetClientSize() |
986 | 679 |
message_idx = self.CurrentMessage |
680 |
message = self.LogMessages[message_idx] |
|
681 |
draw_date = True |
|
682 |
offset = 5 |
|
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
683 |
|
986 | 684 |
while offset < height and message is not None: |
685 |
if draw_date: |
|
686 |
offset += DATE_INFO_SIZE |
|
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
687 |
|
986 | 688 |
if offset <= posy < offset + MESSAGE_INFO_SIZE: |
993 | 689 |
return message |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
690 |
|
986 | 691 |
offset += MESSAGE_INFO_SIZE |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
692 |
|
986 | 693 |
previous_message, message_idx = self.GetPreviousMessage(message_idx) |
694 |
if previous_message is not None: |
|
695 |
draw_date = message.Date != previous_message.Date |
|
696 |
message = previous_message |
|
993 | 697 |
return None |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
698 |
|
993 | 699 |
def OnMessagePanelLeftUp(self, event): |
700 |
if self.CurrentMessage is not None: |
|
701 |
posx, posy = event.GetPosition() |
|
702 |
for button in self.LeftButtons + self.RightButtons: |
|
703 |
if button.HitTest(posx, posy): |
|
704 |
button.ProcessCallback() |
|
705 |
break |
|
706 |
event.Skip() |
|
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
707 |
|
993 | 708 |
def OnMessagePanelRightUp(self, event): |
709 |
message = self.GetMessageByScreenPos(*event.GetPosition()) |
|
710 |
if message is not None: |
|
711 |
menu = wx.Menu(title='') |
|
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
712 |
|
993 | 713 |
new_id = wx.NewId() |
714 |
menu.Append(help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Copy")) |
|
715 |
self.Bind(wx.EVT_MENU, self.GetCopyMessageToClipboardFunction(message), id=new_id) |
|
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
716 |
|
993 | 717 |
self.MessagePanel.PopupMenu(menu) |
718 |
menu.Destroy() |
|
719 |
event.Skip() |
|
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
720 |
|
993 | 721 |
def OnMessagePanelLeftDCLick(self, event): |
722 |
message = self.GetMessageByScreenPos(*event.GetPosition()) |
|
723 |
if message is not None: |
|
724 |
self.SearchMessage.SetFocus() |
|
725 |
self.SearchMessage.SetValue(message.Message) |
|
726 |
event.Skip() |
|
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
727 |
|
993 | 728 |
def ResetMessageToolTip(self): |
729 |
if self.MessageToolTip is not None: |
|
730 |
self.MessageToolTip.Destroy() |
|
731 |
self.MessageToolTip = None |
|
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
732 |
|
993 | 733 |
def OnMessageToolTipTimer(self, event): |
734 |
if self.LastMousePos is not None: |
|
735 |
message = self.GetMessageByScreenPos(*self.LastMousePos) |
|
736 |
if message is not None: |
|
737 |
tooltip_pos = self.MessagePanel.ClientToScreen(self.LastMousePos) |
|
738 |
tooltip_pos.x += 10 |
|
739 |
tooltip_pos.y += 10 |
|
1169
53e4a2b775a7
Move CustomToolTip from GraphicCommons to controls
Laurent Bessard
parents:
1094
diff
changeset
|
740 |
self.MessageToolTip = CustomToolTip(self.MessagePanel, message.GetFullText(), False) |
993 | 741 |
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
|
742 |
self.MessageToolTip.SetToolTipPosition(tooltip_pos) |
993 | 743 |
self.MessageToolTip.Show() |
744 |
event.Skip() |
|
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
745 |
|
993 | 746 |
def OnMessagePanelMotion(self, event): |
747 |
if not event.Dragging(): |
|
748 |
self.ResetMessageToolTip() |
|
749 |
self.LastMousePos = event.GetPosition() |
|
750 |
self.MessageToolTipTimer.Start(int(TOOLTIP_WAIT_PERIOD * 1000), oneShot=True) |
|
751 |
event.Skip() |
|
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
752 |
|
993 | 753 |
def OnMessagePanelLeaveWindow(self, event): |
754 |
self.ResetMessageToolTip() |
|
755 |
self.LastMousePos = None |
|
756 |
self.MessageToolTipTimer.Stop() |
|
986 | 757 |
event.Skip() |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
758 |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
759 |
def OnMessagePanelMouseWheel(self, event): |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
760 |
self.ScrollMessagePanel(event.GetWheelRotation() / event.GetWheelDelta()) |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
761 |
event.Skip() |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
762 |
|
988
30e7571c10d0
Reduced flicker on LogViewer and DebugGraphPanel on Windows
Laurent Bessard
parents:
987
diff
changeset
|
763 |
def OnMessagePanelEraseBackground(self, event): |
30e7571c10d0
Reduced flicker on LogViewer and DebugGraphPanel on Windows
Laurent Bessard
parents:
987
diff
changeset
|
764 |
pass |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
765 |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
766 |
def OnMessagePanelPaint(self, event): |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
767 |
self.RefreshView() |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
768 |
event.Skip() |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
769 |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
770 |
def OnMessagePanelResize(self, event): |
1847
6198190bc121
explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1846
diff
changeset
|
771 |
width, _height = self.MessagePanel.GetClientSize() |
984 | 772 |
offset = 2 |
773 |
for button in self.LeftButtons: |
|
774 |
button.SetPosition(offset, 2) |
|
1847
6198190bc121
explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1846
diff
changeset
|
775 |
w, _h = button.GetSize() |
984 | 776 |
offset += w + 2 |
777 |
offset = width - 2 |
|
778 |
for button in self.RightButtons: |
|
1847
6198190bc121
explicitly mark unused variables found by pylint with _ or dummy
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1846
diff
changeset
|
779 |
w, _h = button.GetSize() |
984 | 780 |
button.SetPosition(offset - w, 2) |
781 |
offset -= w + 2 |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
782 |
if self.IsMessagePanelBottom(): |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
783 |
self.ScrollToFirst() |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
784 |
else: |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
785 |
self.RefreshView() |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
786 |
event.Skip() |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
787 |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
788 |
def OnScrollTimer(self, event): |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
789 |
if self.ScrollSpeed != 0.: |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
790 |
speed_norm = abs(self.ScrollSpeed) |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
791 |
period = REFRESH_PERIOD / speed_norm |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
792 |
self.ScrollMessagePanel(-speed_norm / self.ScrollSpeed) |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
793 |
self.LastStartTime = gettime() |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
794 |
self.ScrollTimer.Start(int(period * 1000), True) |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
795 |
event.Skip() |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
796 |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
797 |
def SetScrollSpeed(self, speed): |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
798 |
if speed == 0.: |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
799 |
self.ScrollTimer.Stop() |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
800 |
else: |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
801 |
speed_norm = abs(speed) |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
802 |
period = REFRESH_PERIOD / speed_norm |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
803 |
current_time = gettime() |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
804 |
if self.LastStartTime is not None: |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
805 |
elapsed_time = current_time - self.LastStartTime |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
806 |
if elapsed_time > period: |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
807 |
self.ScrollMessagePanel(-speed_norm / speed) |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
808 |
self.LastStartTime = current_time |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
809 |
else: |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
810 |
period -= elapsed_time |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
811 |
else: |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
812 |
self.LastStartTime = current_time |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
813 |
self.ScrollTimer.Start(int(period * 1000), True) |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
814 |
self.ScrollSpeed = speed |
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1195
diff
changeset
|
815 |
|
1071
5e740fe71fbe
Fixed bug in LogViewer when view is filtered and displaying last message and new messages appears
Laurent Bessard
parents:
1020
diff
changeset
|
816 |
def ScrollToLast(self, refresh=True): |
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
817 |
if len(self.LogMessages) > 0: |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
818 |
self.CurrentMessage = len(self.LogMessages) - 1 |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
819 |
message = self.LogMessages[self.CurrentMessage] |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
820 |
if not self.FilterLogMessage(message): |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
821 |
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
|
822 |
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
|
823 |
self.RefreshView() |
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
824 |
|
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
825 |
def ScrollToFirst(self): |
978 | 826 |
if len(self.LogMessages) > 0: |
827 |
message_idx = 0 |
|
828 |
message = self.LogMessages[message_idx] |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
829 |
if not self.FilterLogMessage(message): |
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
830 |
next_message, msgidx = self.GetNextMessage(message_idx) |
978 | 831 |
if next_message is not None: |
832 |
message_idx = msgidx |
|
833 |
message = next_message |
|
834 |
while message is not None: |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
835 |
message, msgidx = self.GetPreviousMessage(message_idx) |
978 | 836 |
if message is not None: |
837 |
message_idx = msgidx |
|
838 |
message = self.LogMessages[message_idx] |
|
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
839 |
if self.FilterLogMessage(message): |
978 | 840 |
while message is not None: |
981
fc671a3e95a9
Fixed LogViewer scrollbar and scroll methods
Laurent Bessard
parents:
979
diff
changeset
|
841 |
message, msgidx = self.GetNextMessage(message_idx) |
978 | 842 |
if message is not None: |
843 |
if not self.IsMessagePanelBottom(msgidx): |
|
844 |
break |
|
845 |
message_idx = msgidx |
|
846 |
self.CurrentMessage = message_idx |
|
847 |
else: |
|
848 |
self.CurrentMessage = None |
|
849 |
self.RefreshView() |