controls/LogViewer.py
author Surkov Sergey <surkovsv93@gmail.com>
Tue, 10 Jan 2017 14:08:49 +0300
changeset 1621 4485e6478b91
parent 1576 6df9937f130b
child 1672 9298ba0cd70a
permissions -rw-r--r--
fix doubling search results in Search Result Panel

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