controls/LogViewer.py
changeset 2437 105c20fdeb19
parent 2432 dbc065a2f7a5
child 2704 4ba3bdc7d71f
equal deleted inserted replaced
2436:82bfc75bcd9d 2437:105c20fdeb19
    22 # along with this program; if not, write to the Free Software
    22 # along with this program; if not, write to the Free Software
    23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    24 
    24 
    25 
    25 
    26 from __future__ import absolute_import
    26 from __future__ import absolute_import
       
    27 from __future__ import division
    27 from datetime import datetime
    28 from datetime import datetime
    28 from time import time as gettime
    29 from time import time as gettime
    29 from weakref import proxy
    30 from weakref import proxy
    30 
    31 
    31 import numpy
    32 import numpy
    42 
    43 
    43 
    44 
    44 def ArrowPoints(direction, width, height, xoffset, yoffset):
    45 def ArrowPoints(direction, width, height, xoffset, yoffset):
    45     if direction == wx.TOP:
    46     if direction == wx.TOP:
    46         return [wx.Point(xoffset + 1, yoffset + height - 2),
    47         return [wx.Point(xoffset + 1, yoffset + height - 2),
    47                 wx.Point(xoffset + width / 2, yoffset + 1),
    48                 wx.Point(xoffset + width // 2, yoffset + 1),
    48                 wx.Point(xoffset + width - 1, yoffset + height - 2)]
    49                 wx.Point(xoffset + width - 1, yoffset + height - 2)]
    49     else:
    50     else:
    50         return [wx.Point(xoffset + 1, yoffset - height + 1),
    51         return [wx.Point(xoffset + 1, yoffset - height + 1),
    51                 wx.Point(xoffset + width / 2, yoffset - 2),
    52                 wx.Point(xoffset + width // 2, yoffset - 2),
    52                 wx.Point(xoffset + width - 1, yoffset - height + 1)]
    53                 wx.Point(xoffset + width - 1, yoffset - height + 1)]
    53 
    54 
    54 
    55 
    55 class LogScrollBar(wx.Panel):
    56 class LogScrollBar(wx.Panel):
    56 
    57 
   123             _posx, posy = event.GetPosition()
   124             _posx, posy = event.GetPosition()
   124             range_rect = self.GetRangeRect()
   125             range_rect = self.GetRangeRect()
   125             thumb_size = range_rect.height * THUMB_SIZE_RATIO
   126             thumb_size = range_rect.height * THUMB_SIZE_RATIO
   126             thumb_range = range_rect.height - thumb_size
   127             thumb_range = range_rect.height - thumb_size
   127             self.RefreshThumbPosition(
   128             self.RefreshThumbPosition(
   128                 max(-1., min((posy - self.ThumbScrollingStartPos.y) * 2. / thumb_range, 1.)))
   129                 max(-1., min((posy - self.ThumbScrollingStartPos.y) * 2. // thumb_range, 1.)))
   129         event.Skip()
   130         event.Skip()
   130 
   131 
   131     def OnResize(self, event):
   132     def OnResize(self, event):
   132         self.Refresh()
   133         self.Refresh()
   133         event.Skip()
   134         event.Skip()
   145         width, height = self.GetClientSize()
   146         width, height = self.GetClientSize()
   146 
   147 
   147         gc.SetPen(wx.Pen(wx.NamedColour("GREY"), 3))
   148         gc.SetPen(wx.Pen(wx.NamedColour("GREY"), 3))
   148         gc.SetBrush(wx.GREY_BRUSH)
   149         gc.SetBrush(wx.GREY_BRUSH)
   149 
   150 
   150         gc.DrawLines(ArrowPoints(wx.TOP, width * 0.75, width * 0.5, 2, (width + height) / 4 - 3))
   151         gc.DrawLines(ArrowPoints(wx.TOP, width * 0.75, width * 0.5, 2, (width + height) // 4 - 3))
   151         gc.DrawLines(ArrowPoints(wx.TOP, width * 0.75, width * 0.5, 2, (width + height) / 4 + 3))
   152         gc.DrawLines(ArrowPoints(wx.TOP, width * 0.75, width * 0.5, 2, (width + height) // 4 + 3))
   152 
   153 
   153         gc.DrawLines(ArrowPoints(wx.BOTTOM, width * 0.75, width * 0.5, 2, (height * 3 - width) / 4 + 3))
   154         gc.DrawLines(ArrowPoints(wx.BOTTOM, width * 0.75, width * 0.5, 2, (height * 3 - width) // 4 + 3))
   154         gc.DrawLines(ArrowPoints(wx.BOTTOM, width * 0.75, width * 0.5, 2, (height * 3 - width) / 4 - 3))
   155         gc.DrawLines(ArrowPoints(wx.BOTTOM, width * 0.75, width * 0.5, 2, (height * 3 - width) // 4 - 3))
   155 
   156 
   156         thumb_rect = self.GetThumbRect()
   157         thumb_rect = self.GetThumbRect()
   157         exclusion_rect = wx.Rect(thumb_rect.x, thumb_rect.y,
   158         exclusion_rect = wx.Rect(thumb_rect.x, thumb_rect.y,
   158                                  thumb_rect.width, thumb_rect.height)
   159                                  thumb_rect.width, thumb_rect.height)
   159         if self.Parent.IsMessagePanelTop():
   160         if self.Parent.IsMessagePanelTop():
   221         dc.DrawRectangle(self.Position.x, self.Position.y,
   222         dc.DrawRectangle(self.Position.x, self.Position.y,
   222                          self.Size.width, self.Size.height)
   223                          self.Size.width, self.Size.height)
   223 
   224 
   224         w, h = dc.GetTextExtent(self.Label)
   225         w, h = dc.GetTextExtent(self.Label)
   225         dc.DrawText(self.Label,
   226         dc.DrawText(self.Label,
   226                     self.Position.x + (self.Size.width - w) / 2,
   227                     self.Position.x + (self.Size.width - w) // 2,
   227                     self.Position.y + (self.Size.height - h) / 2)
   228                     self.Position.y + (self.Size.height - h) // 2)
   228 
   229 
   229 
   230 
   230 DATE_INFO_SIZE = 10
   231 DATE_INFO_SIZE = 10
   231 MESSAGE_INFO_SIZE = 18
   232 MESSAGE_INFO_SIZE = 18
   232 
   233 
   258 
   259 
   259     def Draw(self, dc, offset, width, draw_date):
   260     def Draw(self, dc, offset, width, draw_date):
   260         if draw_date:
   261         if draw_date:
   261             datetime_text = self.Date.strftime("%d/%m/%y %H:%M")
   262             datetime_text = self.Date.strftime("%d/%m/%y %H:%M")
   262             dw, dh = dc.GetTextExtent(datetime_text)
   263             dw, dh = dc.GetTextExtent(datetime_text)
   263             dc.DrawText(datetime_text, (width - dw) / 2, offset + (DATE_INFO_SIZE - dh) / 2)
   264             dc.DrawText(datetime_text, (width - dw) // 2, offset + (DATE_INFO_SIZE - dh) // 2)
   264             offset += DATE_INFO_SIZE
   265             offset += DATE_INFO_SIZE
   265 
   266 
   266         seconds_text = "%12.9f" % self.Seconds
   267         seconds_text = "%12.9f" % self.Seconds
   267         sw, sh = dc.GetTextExtent(seconds_text)
   268         sw, sh = dc.GetTextExtent(seconds_text)
   268         dc.DrawText(seconds_text, 5, offset + (MESSAGE_INFO_SIZE - sh) / 2)
   269         dc.DrawText(seconds_text, 5, offset + (MESSAGE_INFO_SIZE - sh) // 2)
   269 
   270 
   270         bw, bh = self.LevelBitmap.GetWidth(), self.LevelBitmap.GetHeight()
   271         bw, bh = self.LevelBitmap.GetWidth(), self.LevelBitmap.GetHeight()
   271         dc.DrawBitmap(self.LevelBitmap, 10 + sw, offset + (MESSAGE_INFO_SIZE - bh) / 2)
   272         dc.DrawBitmap(self.LevelBitmap, 10 + sw, offset + (MESSAGE_INFO_SIZE - bh) // 2)
   272 
   273 
   273         text = self.Message.replace("\n", " ")
   274         text = self.Message.replace("\n", " ")
   274         _mw, mh = dc.GetTextExtent(text)
   275         _mw, mh = dc.GetTextExtent(text)
   275         dc.DrawText(text, 15 + sw + bw, offset + (MESSAGE_INFO_SIZE - mh) / 2)
   276         dc.DrawText(text, 15 + sw + bw, offset + (MESSAGE_INFO_SIZE - mh) // 2)
   276 
   277 
   277     def GetHeight(self, draw_date):
   278     def GetHeight(self, draw_date):
   278         if draw_date:
   279         if draw_date:
   279             return DATE_INFO_SIZE + MESSAGE_INFO_SIZE
   280             return DATE_INFO_SIZE + MESSAGE_INFO_SIZE
   280         return MESSAGE_INFO_SIZE
   281         return MESSAGE_INFO_SIZE
   610             self.RefreshView()
   611             self.RefreshView()
   611 
   612 
   612     def ScrollMessagePanelByPage(self, page):
   613     def ScrollMessagePanelByPage(self, page):
   613         if self.CurrentMessage is not None:
   614         if self.CurrentMessage is not None:
   614             _width, height = self.MessagePanel.GetClientSize()
   615             _width, height = self.MessagePanel.GetClientSize()
   615             message_per_page = max(1, (height - DATE_INFO_SIZE) / MESSAGE_INFO_SIZE - 1)
   616             message_per_page = max(1, (height - DATE_INFO_SIZE) // MESSAGE_INFO_SIZE - 1)
   616             self.ScrollMessagePanel(page * message_per_page)
   617             self.ScrollMessagePanel(page * message_per_page)
   617 
   618 
   618     def ScrollMessagePanelByTimestamp(self, seconds):
   619     def ScrollMessagePanelByTimestamp(self, seconds):
   619         if self.CurrentMessage is not None:
   620         if self.CurrentMessage is not None:
   620             current_message = self.LogMessages[self.CurrentMessage]
   621             current_message = self.LogMessages[self.CurrentMessage]
   755         self.LastMousePos = None
   756         self.LastMousePos = None
   756         self.MessageToolTipTimer.Stop()
   757         self.MessageToolTipTimer.Stop()
   757         event.Skip()
   758         event.Skip()
   758 
   759 
   759     def OnMessagePanelMouseWheel(self, event):
   760     def OnMessagePanelMouseWheel(self, event):
   760         self.ScrollMessagePanel(event.GetWheelRotation() / event.GetWheelDelta())
   761         self.ScrollMessagePanel(event.GetWheelRotation() // event.GetWheelDelta())
   761         event.Skip()
   762         event.Skip()
   762 
   763 
   763     def OnMessagePanelEraseBackground(self, event):
   764     def OnMessagePanelEraseBackground(self, event):
   764         pass
   765         pass
   765 
   766