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