Added LogViewer panel in bottom notebook
authorLaurent Bessard
Wed, 13 Mar 2013 23:17:30 +0100
changeset 978 3290eff761f1
parent 976 0ba3d9cd61e8
child 979 1a68113a323d
Added LogViewer panel in bottom notebook
Beremiz.py
ProjectController.py
controls/LogViewer.py
controls/__init__.py
images/CRITICAL.png
images/DEBUG.png
images/INFO.png
images/WARNING.png
images/icons.svg
--- a/Beremiz.py	Wed Mar 13 12:34:25 2013 +0900
+++ b/Beremiz.py	Wed Mar 13 23:17:30 2013 +0100
@@ -146,6 +146,7 @@
 from editors.DataTypeEditor import DataTypeEditor
 from util.MiniTextControler import MiniTextControler
 from util.ProcessLogger import ProcessLogger
+from controls.LogViewer import LogViewer
 
 from PLCControler import LOCATION_CONFNODE, LOCATION_MODULE, LOCATION_GROUP, LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY, ITEM_PROJECT, ITEM_RESOURCE
 from ProjectController import ProjectController, MATIEC_ERROR_MODEL, ITEM_CONFNODE
@@ -287,7 +288,7 @@
 CONFNODEMENU_POSITION = 3
 
 class Beremiz(IDEFrame):
-	
+    
     def _init_utils(self):
         self.ConfNodeMenu = wx.Menu(title='')
         self.RecentProjectsMenu = wx.Menu(title='')
@@ -385,7 +386,12 @@
         self.MainTabs["LogConsole"] = (self.LogConsole, _("Log Console"))
         self.BottomNoteBook.AddPage(*self.MainTabs["LogConsole"])
         #self.BottomNoteBook.Split(self.BottomNoteBook.GetPageIndex(self.LogConsole), wx.RIGHT)
-
+        
+        self.LogViewer = LogViewer(self.BottomNoteBook, self)
+        self.MainTabs["LogViewer"] = (self.LogViewer, _("Log Viewer"))
+        self.BottomNoteBook.AddPage(*self.MainTabs["LogViewer"])
+        self.BottomNoteBook.Split(self.BottomNoteBook.GetPageIndex(self.LogViewer), wx.RIGHT)
+        
         StatusToolBar = wx.ToolBar(self, -1, wx.DefaultPosition, wx.DefaultSize,
                 wx.TB_FLAT | wx.TB_NODIVIDER | wx.NO_BORDER)
         StatusToolBar.SetToolBitmapSize(wx.Size(25, 25))
@@ -541,7 +547,7 @@
                 infos = self.CTR.ShowError(self.Log,
                                                   (int(first_line), int(first_column)), 
                                                   (int(last_line), int(last_column)))
-	
+    
     ## Function displaying an Error dialog in PLCOpenEditor.
     #  @return False if closing cancelled.
     def CheckSaveBeforeClosing(self, title=_("Close Project")):
--- a/ProjectController.py	Wed Mar 13 12:34:25 2013 +0900
+++ b/ProjectController.py	Wed Mar 13 23:17:30 2013 +0100
@@ -85,9 +85,9 @@
         PLCControler.__init__(self)
 
         self.MandatoryParams = None
-        self.SetAppFrame(frame, logger)
         self._builder = None
         self._connector = None
+        self.SetAppFrame(frame, logger)
         
         self.iec2c_path = os.path.join(base_folder, "matiec", "iec2c"+(".exe" if wx.Platform == '__WXMSW__' else ""))
         self.ieclib_path = os.path.join(base_folder, "matiec", "lib")
@@ -113,7 +113,6 @@
         self.DebugThread = None
         self.debug_break = False
         self.previous_plcstate = None
-        self.previous_log_count = [None]*LogLevelsCount
         # copy ConfNodeMethods so that it can be later customized
         self.StatusMethods = [dic.copy() for dic in self.StatusMethods]
 
@@ -137,6 +136,8 @@
         self.StatusTimer = None
         
         if frame is not None:
+            frame.LogViewer.SetLogSource(self._connector)
+            
             # Timer to pull PLC status
             ID_STATUSTIMER = wx.NewId()
             self.StatusTimer = wx.Timer(self.AppFrame, ID_STATUSTIMER)
@@ -281,7 +282,7 @@
         """
         if os.path.basename(ProjectPath) == "":
             ProjectPath = os.path.dirname(ProjectPath)
-		# Verify that project contains a PLCOpen program
+        # Verify that project contains a PLCOpen program
         plc_file = os.path.join(ProjectPath, "plc.xml")
         if not os.path.isfile(plc_file):
             return _("Chosen folder doesn't contain a program. It's not a valid project!")
@@ -1077,36 +1078,10 @@
         self.CompareLocalAndRemotePLC()
 
     def UpdatePLCLog(self, log_count):
-        if log_count :
-            to_console = []
-            for level, count, prev in zip(xrange(LogLevelsCount), log_count,self.previous_log_count):
-                if count is not None and prev != count:
-                    # XXX replace dump to console with dedicated log panel.
-                    dump_end = max( # request message sent after the last one we already got
-                        prev - 1 if prev is not None else -1,
-                        count - 100) # 100 is purely arbitrary number
-                        # dedicated panel should only ask for a small range, 
-                        # depending on how user navigate in the panel
-                        # and only ask for last one in follow mode
-                    for msgidx in xrange(count-1, dump_end,-1):
-                        answer = self._connector.GetLogMessage(level, msgidx)
-                        if answer is not None :
-                            msg, tick, tv_sec, tv_nsec = answer 
-                            to_console.insert(0,(
-                                (tv_sec, tv_nsec),
-                                '%d|%s.%9.9d|%s(%s)'%(
-                                    int(tick),
-                                    str(datetime.fromtimestamp(tv_sec)),
-                                    tv_nsec,
-                                    msg,
-                                    LogLevels[level])))
-                        else:
-                            break;
-                    self.previous_log_count[level] = count
-            if to_console:
-                to_console.sort()
-                self.logger.write("\n".join(zip(*to_console)[1]+('',)))
-
+        if log_count:
+            if self.AppFrame is not None:
+                self.AppFrame.LogViewer.SetLogCounters(log_count)
+    
     def UpdateMethodsFromPLCStatus(self):
         status = None
         if self._connector is not None:
@@ -1115,7 +1090,7 @@
                 status, log_count = PLCstatus
                 self.UpdatePLCLog(log_count)
         if status is None:
-            self._connector = None
+            self._SetConnector(None)
             status = "Disconnected"
         if(self.previous_plcstate != status):
             for args in {
@@ -1303,6 +1278,7 @@
             else:
                 plc_status = None
             debug_getvar_retry += 1
+            #print [dict.keys() for IECPath, (dict, log, status, fvalue) in self.IECdebug_datas.items()]
             if plc_status == "Started":
                 self.IECdebug_lock.acquire()
                 if len(debug_vars) == len(self.TracedIECPath):
@@ -1341,7 +1317,6 @@
 
     def _connect_debug(self): 
         self.previous_plcstate = None
-        self.previous_log_count = [None]*LogLevelsCount
         if self.AppFrame:
             self.AppFrame.ResetGraphicViewers()
         self.RegisterDebugVarToConnector()
@@ -1373,6 +1348,11 @@
         
         wx.CallAfter(self.UpdateMethodsFromPLCStatus)
 
+    def _SetConnector(self, connector):
+        self._connector = connector
+        if self.AppFrame is not None:
+            self.AppFrame.LogViewer.SetLogSource(connector)
+            
     def _Connect(self):
         # don't accept re-connetion if already connected
         if self._connector is not None:
@@ -1417,7 +1397,7 @@
                            
         # Get connector from uri
         try:
-            self._connector = connectors.ConnectorFactory(uri, self)
+            self._SetConnector(connectors.ConnectorFactory(uri, self))
         except Exception, msg:
             self.logger.write_error(_("Exception while connecting %s!\n")%uri)
             self.logger.write_error(traceback.format_exc())
@@ -1477,7 +1457,7 @@
 
 
     def _Disconnect(self):
-        self._connector = None
+        self._SetConnector(None)
         self.StatusTimer.Stop()
         wx.CallAfter(self.UpdateMethodsFromPLCStatus)
         
@@ -1522,8 +1502,6 @@
             else:
                 self.logger.write_error(_("No PLC to transfer (did build succeed ?)\n"))
 
-        self.previous_log_count = [None]*LogLevelsCount
-
         wx.CallAfter(self.UpdateMethodsFromPLCStatus)
 
     StatusMethods = [
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/controls/LogViewer.py	Wed Mar 13 23:17:30 2013 +0100
@@ -0,0 +1,532 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
+#based on the plcopen standard. 
+#
+#Copyright (C) 2013: Edouard TISSERANT and Laurent BESSARD
+#
+#See COPYING file for copyrights details.
+#
+#This library is free software; you can redistribute it and/or
+#modify it under the terms of the GNU General Public
+#License as published by the Free Software Foundation; either
+#version 2.1 of the License, or (at your option) any later version.
+#
+#This library is distributed in the hope that it will be useful,
+#but WITHOUT ANY WARRANTY; without even the implied warranty of
+#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+#General Public License for more details.
+#
+#You should have received a copy of the GNU General Public
+#License along with this library; if not, write to the Free Software
+#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+from datetime import datetime
+
+import wx
+
+from graphics import DebugViewer, REFRESH_PERIOD
+from targets.typemapping import LogLevelsCount, LogLevels
+from util.BitmapLibrary import GetBitmap
+
+SPEED_VALUES = [10, 5, 2, 1, 0, -1, -2, -5, -10]
+
+class MyScrollBar(wx.Panel):
+    
+    def __init__(self, parent, size):
+        wx.Panel.__init__(self, parent, size=size)
+        self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
+        self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
+        self.Bind(wx.EVT_MOTION, self.OnMotion)
+        self.Bind(wx.EVT_PAINT, self.OnPaint)
+        self.Bind(wx.EVT_SIZE, self.OnResize)
+        
+        self.ThumbPosition = SPEED_VALUES.index(0)
+        self.ThumbScrolling = False
+    
+    def GetRangeRect(self):
+        width, height = self.GetClientSize()
+        return wx.Rect(0, width, width, height - 2 * width)
+    
+    def GetThumbRect(self):
+        width, height = self.GetClientSize()
+        range_rect = self.GetRangeRect()
+        if self.Parent.IsMessagePanelTop():
+            thumb_start = 0
+        else:
+            thumb_start = int(float(self.ThumbPosition * range_rect.height) / len(SPEED_VALUES))
+        if self.Parent.IsMessagePanelBottom():
+            thumb_end = range_rect.height
+        else:
+            thumb_end = int(float((self.ThumbPosition + 1) * range_rect.height) / len(SPEED_VALUES))
+        return wx.Rect(1, range_rect.y + thumb_start, width - 1, thumb_end - thumb_start)
+    
+    def OnLeftDown(self, event):
+        self.CaptureMouse()
+        posx, posy = event.GetPosition()
+        width, height = self.GetClientSize()
+        range_rect = self.GetRangeRect()
+        thumb_rect = self.GetThumbRect()
+        if range_rect.InsideXY(posx, posy):
+            if thumb_rect.InsideXY(posx, posy):
+                self.ThumbScrolling = True
+            elif posy < thumb_rect.y:
+                self.Parent.ScrollPageUp()
+            elif posy > thumb_rect.y + thumb_rect.height:
+                self.Parent.ScrollPageDown()
+        elif posy < width:
+            self.Parent.SetScrollSpeed(1)
+        elif posy > height - width:
+            self.Parent.SetScrollSpeed(-1)
+        event.Skip()
+        
+    def OnLeftUp(self, event):
+        self.ThumbScrolling = False
+        self.ThumbPosition = SPEED_VALUES.index(0)
+        self.Parent.SetScrollSpeed(SPEED_VALUES[self.ThumbPosition])
+        self.Refresh()
+        if self.HasCapture():
+            self.ReleaseMouse()
+        event.Skip()
+        
+    def OnMotion(self, event):
+        if event.Dragging() and self.ThumbScrolling:
+            posx, posy = event.GetPosition()
+            width, height = self.GetClientSize()
+            range_rect = self.GetRangeRect()
+            if range_rect.InsideXY(posx, posy):
+                new_thumb_position = int(float(posy - range_rect.y) * len(SPEED_VALUES) / range_rect.height)
+                thumb_rect = self.GetThumbRect()
+                if self.ThumbPosition == SPEED_VALUES.index(0):
+                    if thumb_rect.y == width:
+                        new_thumb_position = max(new_thumb_position, SPEED_VALUES.index(0))
+                    if thumb_rect.y + thumb_rect.height == height - width:
+                        new_thumb_position = min(new_thumb_position, SPEED_VALUES.index(0))
+                if new_thumb_position != self.ThumbPosition:
+                    self.ThumbPosition = new_thumb_position
+                    self.Parent.SetScrollSpeed(SPEED_VALUES[new_thumb_position])
+                    self.Refresh()
+        event.Skip()
+    
+    def OnResize(self, event):
+        self.Refresh()
+        event.Skip()
+    
+    def OnPaint(self, event):
+        dc = wx.BufferedPaintDC(self)
+        dc.Clear()
+        dc.BeginDrawing()
+        
+        dc.SetPen(wx.GREY_PEN)
+        dc.SetBrush(wx.GREY_BRUSH)
+        
+        width, height = self.GetClientSize()
+        
+        dc.DrawPolygon([wx.Point(width / 2, 1),
+                        wx.Point(1, width - 2),
+                        wx.Point(width - 1, width - 2)])
+        
+        dc.DrawPolygon([wx.Point(width / 2, height - 1),
+                        wx.Point(2, height - width + 1),
+                        wx.Point(width - 1, height - width + 1)])
+        
+        thumb_rect = self.GetThumbRect()
+        dc.DrawRectangle(thumb_rect.x, thumb_rect.y, 
+                         thumb_rect.width, thumb_rect.height)
+        
+        dc.EndDrawing()
+        event.Skip()
+
+DATE_INFO_SIZE = 10
+MESSAGE_INFO_SIZE = 30
+
+class LogMessage:
+    
+    def __init__(self, tv_sec, tv_nsec, level, level_bitmap, msg):
+        self.Date = datetime.fromtimestamp(tv_sec)
+        self.Seconds = self.Date.second + tv_nsec * 1e-9
+        self.Date = self.Date.replace(second=0)
+        self.Level = level
+        self.LevelBitmap = level_bitmap
+        self.Message = msg
+        self.DrawDate = True
+    
+    def __cmp__(self, other):
+        if self.Date == other.Date:
+            return cmp(self.Seconds, other.Seconds)
+        return cmp(self.Date, other.Date)
+    
+    def Draw(self, dc, offset, width, draw_date):
+        if draw_date:
+            datetime_text = self.Date.strftime("%d/%m/%y %H:%M")
+            dw, dh = dc.GetTextExtent(datetime_text)
+            dc.DrawText(datetime_text, (width - dw) / 2, offset + (DATE_INFO_SIZE - dh) / 2)
+            offset += DATE_INFO_SIZE
+        
+        seconds_text = "%12.9f" % self.Seconds
+        sw, sh = dc.GetTextExtent(seconds_text)
+        dc.DrawText(seconds_text, 5, offset + (MESSAGE_INFO_SIZE - sh) / 2)
+        
+        bw, bh = self.LevelBitmap.GetWidth(), self.LevelBitmap.GetHeight()
+        dc.DrawBitmap(self.LevelBitmap, 10 + sw, offset + (MESSAGE_INFO_SIZE - bh) / 2)
+        
+        mw, mh = dc.GetTextExtent(self.Message)
+        dc.DrawText(self.Message, 15 + sw + bw, offset + (MESSAGE_INFO_SIZE - mh) / 2)
+        
+    def GetHeight(self, draw_date):
+        if draw_date:
+            return DATE_INFO_SIZE + MESSAGE_INFO_SIZE
+        return MESSAGE_INFO_SIZE
+
+SECOND = 1
+MINUTE = 60 * SECOND
+HOUR = 60 * MINUTE
+DAY = 24 * HOUR
+
+CHANGE_TIMESTAMP_BUTTONS = [(_("1d"), DAY),
+                            (_("1h"), HOUR),
+                            (_("1m"), MINUTE),
+                            (_("1s"), SECOND)]
+REVERSE_CHANGE_TIMESTAMP_BUTTONS = CHANGE_TIMESTAMP_BUTTONS[:]
+REVERSE_CHANGE_TIMESTAMP_BUTTONS.reverse()
+
+class LogViewer(DebugViewer, wx.Panel):
+    
+    def __init__(self, parent, window):
+        wx.Panel.__init__(self, parent, style=wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER)
+        DebugViewer.__init__(self, None, False, False)
+        
+        main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5)
+        main_sizer.AddGrowableCol(0)
+        main_sizer.AddGrowableRow(1)
+        
+        filter_sizer = wx.BoxSizer(wx.HORIZONTAL)
+        main_sizer.AddSizer(filter_sizer, border=5, flag=wx.TOP|wx.LEFT|wx.RIGHT|wx.GROW)
+        
+        self.MessageFilter = wx.ComboBox(self, style=wx.CB_READONLY)
+        self.MessageFilter.Append(_("All"))
+        levels = LogLevels[:3]
+        levels.reverse()
+        for level in levels:
+            self.MessageFilter.Append(_(level))
+        self.Bind(wx.EVT_COMBOBOX, self.OnMessageFilterChanged, self.MessageFilter)
+        filter_sizer.AddWindow(self.MessageFilter, 1, border=5, flag=wx.RIGHT|wx.GROW)
+        
+        self.SearchMessage = wx.SearchCtrl(self)
+        self.SearchMessage.ShowSearchButton(True)
+        self.Bind(wx.EVT_TEXT, self.OnSearchMessageChanged, self.SearchMessage)
+        self.Bind(wx.EVT_SEARCHCTRL_SEARCH_BTN, 
+              self.OnSearchMessageButtonClick, self.SearchMessage)
+        filter_sizer.AddWindow(self.SearchMessage, 3, flag=wx.GROW)
+        
+        message_panel_sizer = wx.FlexGridSizer(cols=3, hgap=0, rows=1, vgap=0)
+        message_panel_sizer.AddGrowableCol(1)
+        message_panel_sizer.AddGrowableRow(0)
+        main_sizer.AddSizer(message_panel_sizer, border=5, flag=wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.GROW)
+        
+        buttons_sizer = wx.BoxSizer(wx.VERTICAL)
+        for label, callback in [(_("First"), self.OnFirstButton)] + \
+                               [("+" + text, self.GenerateOnDurationButton(duration)) 
+                                for text, duration in CHANGE_TIMESTAMP_BUTTONS] +\
+                               [("-" + text, self.GenerateOnDurationButton(-duration)) 
+                                for text, duration in REVERSE_CHANGE_TIMESTAMP_BUTTONS] + \
+                               [(_("Last"), self.OnLastButton)]:
+            button = wx.Button(self, label=label)
+            self.Bind(wx.EVT_BUTTON, callback, button)
+            buttons_sizer.AddWindow(button, 1, wx.ALIGN_CENTER_VERTICAL)
+        message_panel_sizer.AddSizer(buttons_sizer, flag=wx.GROW)
+        
+        self.MessagePanel = wx.Panel(self)
+        if wx.Platform == '__WXMSW__':
+            self.Font = wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL, faceName='Courier New')
+        else:
+            self.Font = wx.Font(12, wx.SWISS, wx.NORMAL, wx.NORMAL, faceName='Courier')    
+        self.MessagePanel.Bind(wx.EVT_PAINT, self.OnMessagePanelPaint)
+        self.MessagePanel.Bind(wx.EVT_SIZE, self.OnMessagePanelResize)
+        message_panel_sizer.AddWindow(self.MessagePanel, flag=wx.GROW)
+        
+        self.MessageScrollBar = MyScrollBar(self, wx.Size(16, -1))
+        message_panel_sizer.AddWindow(self.MessageScrollBar, flag=wx.GROW)
+        
+        self.SetSizer(main_sizer)
+    
+        self.MessageFilter.SetSelection(0)
+        self.LogSource = None
+        self.ResetLogMessages()
+        self.ParentWindow = window
+    
+        self.LevelIcons = [GetBitmap(level) for level in LogLevels]
+        self.LevelFilters = [range(i) for i in xrange(4, 0, -1)]
+        self.CurrentFilter = self.LevelFilters[0]
+        
+        self.ScrollSpeed = 0
+        self.ScrollTimer = wx.Timer(self, -1)
+        self.Bind(wx.EVT_TIMER, self.OnScrollTimer, self.ScrollTimer)
+    
+    def __del__(self):
+        self.ScrollTimer.Stop()
+    
+    def ResetLogMessages(self):
+        self.previous_log_count = [None]*LogLevelsCount
+        self.OldestMessages = []
+        self.LogMessages = []
+        self.CurrentMessage = None
+        self.HasNewData = False
+    
+    def SetLogSource(self, log_source):
+        self.LogSource = log_source
+        if log_source is not None:
+            self.ResetLogMessages()
+            self.RefreshView()
+    
+    def GetLogMessageFromSource(self, msgidx, level):
+        if self.LogSource is not None:
+            answer = self.LogSource.GetLogMessage(level, msgidx)
+            if answer is not None:
+                msg, tick, tv_sec, tv_nsec = answer
+                return LogMessage(tv_sec, tv_nsec, level, self.LevelIcons[level], msg)
+        return None
+    
+    def SetLogCounters(self, log_count):
+        new_messages = []
+        for level, count, prev in zip(xrange(LogLevelsCount), log_count, self.previous_log_count):
+            if count is not None and prev != count:
+                if prev is None:
+                    dump_end = count - 2
+                else:
+                    dump_end = prev - 1
+                for msgidx in xrange(count-1, dump_end,-1):
+                    new_message = self.GetLogMessageFromSource(msgidx, level)
+                    if new_message is not None:
+                        if prev is None:
+                            self.OldestMessages.append((msgidx, new_message))
+                            if len(new_messages) == 0 or new_message > new_messages[0]:
+                                new_messages = [new_message]
+                        else:
+                            new_messages.insert(0, new_message)
+                    else:
+                        if prev is None:
+                            self.OldestMessages.append((-1, None))
+                        break
+                self.previous_log_count[level] = count
+        new_messages.sort()
+        if len(new_messages) > 0:
+            self.HasNewData = True
+            old_length = len(self.LogMessages)
+            for new_message in new_messages:
+                self.LogMessages.append(new_message)
+            if self.CurrentMessage is None or self.CurrentMessage == old_length - 1:
+                self.CurrentMessage = len(self.LogMessages) - 1
+            self.NewDataAvailable(None)
+    
+    def GetNextMessage(self, msgidx, levels=range(4)):
+        while msgidx < len(self.LogMessages) - 1:
+            message = self.LogMessages[msgidx + 1]
+            if message.Level in levels:
+                return message, msgidx + 1
+            msgidx += 1
+        return None, None
+            
+    def GetPreviousMessage(self, msgidx, levels=range(4)):
+        message = None
+        while 0 < msgidx < len(self.LogMessages):
+            message = self.LogMessages[msgidx - 1]
+            if message.Level in levels:
+                return message, msgidx - 1
+            msgidx -= 1
+        if len(self.LogMessages) > 0:
+            message = self.LogMessages[0]
+            while message is not None:
+                level = message.Level
+                oldest_msgidx, oldest_message = self.OldestMessages[level]
+                if oldest_msgidx > 0:
+                    old_message = self.GetLogMessageFromSource(oldest_msgidx - 1, level)
+                    if old_message is not None:
+                        self.OldestMessages[level] = (oldest_msgidx - 1, old_message)
+                    else:
+                        self.OldestMessages[level] = (-1, None)
+                else:
+                    self.OldestMessages[level] = (-1, None)
+                message = None
+                for idx, msg in self.OldestMessages:
+                    if msg is not None and (message is None or msg > message):
+                        message = msg
+                if message is not None:
+                    self.LogMessages.insert(0, message)
+                    if self.CurrentMessage is not None:
+                        self.CurrentMessage += 1
+                    else:
+                        self.CurrentMessage = 0
+                    if message.Level in levels:
+                        return message, 0
+        return None, None
+    
+    def RefreshNewData(self, *args, **kwargs):
+        if self.HasNewData:
+            self.HasNewData = False
+            self.RefreshView()
+        DebugViewer.RefreshNewData(self, *args, **kwargs)
+    
+    def RefreshView(self):
+        width, height = self.MessagePanel.GetClientSize()
+        bitmap = wx.EmptyBitmap(width, height)
+        dc = wx.BufferedDC(wx.ClientDC(self.MessagePanel), bitmap)
+        dc.Clear()
+        dc.SetFont(self.Font)
+        dc.BeginDrawing()
+        
+        if self.CurrentMessage is not None:
+            message_idx = self.CurrentMessage
+            message = self.LogMessages[message_idx]
+            draw_date = True
+            offset = 5
+            while offset < height and message is not None:
+                message.Draw(dc, offset, width, draw_date)
+                offset += message.GetHeight(draw_date)
+                
+                previous_message, message_idx = self.GetPreviousMessage(message_idx, self.CurrentFilter)
+                if previous_message is not None:
+                    draw_date = message.Date != previous_message.Date
+                message = previous_message
+        
+        dc.EndDrawing()
+        
+        self.MessageScrollBar.Refresh()
+    
+    def OnMessageFilterChanged(self, event):
+        self.CurrentFilter = self.LevelFilters[self.MessageFilter.GetSelection()]
+        if len(self.LogMessages) > 0:
+            self.CurrentMessage = len(self.LogMessages) - 1
+            message = self.LogMessages[self.CurrentMessage]
+            while message is not None and message.Level not in self.CurrentFilter:
+                message, self.CurrentMessage = self.GetPreviousMessage(self.CurrentMessage, self.CurrentFilter)
+            self.RefreshView()
+        event.Skip()
+    
+    def IsMessagePanelTop(self, message_idx=None):
+        if message_idx is None:
+            message_idx = self.CurrentMessage
+        if message_idx is not None:
+            return self.GetNextMessage(message_idx, self.CurrentFilter)[0] is None
+        return True
+    
+    def IsMessagePanelBottom(self, message_idx=None):
+        if message_idx is None:
+            message_idx = self.CurrentMessage
+        if message_idx is not None:
+            width, height = self.MessagePanel.GetClientSize()
+            offset = 5
+            message = self.LogMessages[message_idx]
+            draw_date = True
+            while message is not None and offset < height:
+                offset += message.GetHeight(draw_date)
+                previous_message, message_idx = self.GetPreviousMessage(message_idx, self.CurrentFilter)
+                if previous_message is not None:
+                    draw_date = message.Date != previous_message.Date
+                message = previous_message
+            return offset < height
+        return True
+    
+    def ScrollMessagePanel(self, scroll):
+        if self.CurrentMessage is not None:
+            message = self.LogMessages[self.CurrentMessage]
+            while scroll > 0 and message is not None:
+                message, msgidx = self.GetNextMessage(self.CurrentMessage, self.CurrentFilter)
+                if message is not None:
+                    self.CurrentMessage = msgidx
+                    scroll -= 1
+            while scroll < 0 and message is not None and not self.IsMessagePanelBottom():
+                message, msgidx = self.GetPreviousMessage(self.CurrentMessage, self.CurrentFilter)
+                if message is not None:
+                    self.CurrentMessage = msgidx
+                    scroll += 1
+            self.RefreshView()
+        
+    def OnSearchMessageChanged(self, event):
+        event.Skip()
+        
+    def OnSearchMessageButtonClick(self, event):
+        event.Skip()
+    
+    def OnFirstButton(self, event):
+        if len(self.LogMessages) > 0:
+            self.CurrentMessage = len(self.LogMessages) - 1
+            message = self.LogMessages[self.CurrentMessage]
+            if message.Level not in self.CurrentFilter:
+                message, self.CurrentMessage = self.GetPreviousMessage(self.CurrentMessage, self.CurrentFilter)
+            self.RefreshView()
+        event.Skip()
+        
+    def OnLastButton(self, event):
+        if len(self.LogMessages) > 0:
+            message_idx = 0
+            message = self.LogMessages[message_idx]
+            if message.Level not in self.CurrentFilter:
+                next_message, msgidx = self.GetNextMessage(message_idx, self.CurrentFilter)
+                if next_message is not None:
+                    message_idx = msgidx
+                    message = next_message
+            while message is not None:
+                message, msgidx = self.GetPreviousMessage(message_idx, self.CurrentFilter)
+                if message is not None:
+                    message_idx = msgidx
+            message = self.LogMessages[message_idx]
+            if message.Level in self.CurrentFilter:
+                while message is not None:
+                    message, msgidx = self.GetNextMessage(message_idx, self.CurrentFilter)
+                    if message is not None:
+                        if not self.IsMessagePanelBottom(msgidx):
+                            break
+                        message_idx = msgidx
+                self.CurrentMessage = message_idx
+            else:
+                self.CurrentMessage = None
+            self.RefreshView()
+        event.Skip()
+    
+    def GenerateOnDurationButton(self, duration):
+        def OnDurationButton(event):
+            event.Skip()
+        return OnDurationButton
+    
+    def OnMessagePanelPaint(self, event):
+        self.RefreshView()
+        event.Skip()
+    
+    def OnMessagePanelResize(self, event):
+        self.RefreshView()
+        event.Skip()
+    
+    def OnScrollTimer(self, event):
+        if self.ScrollSpeed != 0:
+            speed_norm = abs(self.ScrollSpeed)
+            if speed_norm <= 5:
+                self.ScrollMessagePanel(speed_norm / self.ScrollSpeed)
+                period = REFRESH_PERIOD * 5000 / speed_norm
+            else:
+                self.ScrollMessagePanel(self.ScrollSpeed / 5)
+                period = REFRESH_PERIOD * 1000
+            self.ScrollTimer.Start(period, True)
+        event.Skip()
+    
+    def SetScrollSpeed(self, speed):
+        if speed == 0:
+            self.ScrollTimer.Stop()
+        else:
+            if not self.ScrollTimer.IsRunning():
+                speed_norm = abs(speed)
+                if speed_norm <= 5:
+                    self.ScrollMessagePanel(speed_norm / speed)
+                    period = REFRESH_PERIOD * 5000 / speed_norm
+                else:
+                    period = REFRESH_PERIOD * 1000
+                    self.ScrollMessagePanel(speed / 5)
+                self.ScrollTimer.Start(period, True)
+        self.ScrollSpeed = speed    
+    
+    def ScrollPageUp(self):
+        pass
+
+    def ScrollPageDown(self):
+        pass
--- a/controls/__init__.py	Wed Mar 13 12:34:25 2013 +0900
+++ b/controls/__init__.py	Wed Mar 13 23:17:30 2013 +0100
@@ -38,3 +38,4 @@
 from SearchResultPanel import SearchResultPanel
 from TextCtrlAutoComplete import TextCtrlAutoComplete
 from FolderTree import FolderTree
+from LogViewer import LogViewer
Binary file images/CRITICAL.png has changed
Binary file images/DEBUG.png has changed
Binary file images/INFO.png has changed
Binary file images/WARNING.png has changed
--- a/images/icons.svg	Wed Mar 13 12:34:25 2013 +0900
+++ b/images/icons.svg	Wed Mar 13 23:17:30 2013 +0100
@@ -16,7 +16,7 @@
    id="svg2"
    sodipodi:version="0.32"
    inkscape:version="0.48.3.1 r9886"
-   sodipodi:docname="icons.svg.2013_02_08_17_20_04.0.svg"
+   sodipodi:docname="icons.svg"
    inkscape:output_extension="org.inkscape.output.svg.inkscape">
   <metadata
      id="metadata13810">
@@ -26,7 +26,7 @@
         <dc:format>image/svg+xml</dc:format>
         <dc:type
            rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
-        <dc:title></dc:title>
+        <dc:title />
       </cc:Work>
     </rdf:RDF>
   </metadata>
@@ -44,9 +44,9 @@
      id="base"
      showgrid="false"
      inkscape:zoom="1"
-     inkscape:cx="590.30324"
-     inkscape:cy="563.15477"
-     inkscape:window-x="1920"
+     inkscape:cx="301.65135"
+     inkscape:cy="426.18259"
+     inkscape:window-x="0"
      inkscape:window-y="24"
      inkscape:current-layer="svg2"
      showguides="true"
@@ -93515,4 +93515,132 @@
      id="path18458"
      inkscape:connector-curvature="0"
      sodipodi:nodetypes="ccccccccccccccccccccccccccccc" />
+  <text
+     style="font-size:20px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans"
+     xml:space="preserve"
+     id="text18383-2-5"
+     y="379.81824"
+     x="170.02246"><tspan
+       id="tspan18385-7-6"
+       y="379.81824"
+       x="170.02246">Log levels icons</tspan></text>
+  <text
+     sodipodi:linespacing="125%"
+     style="font-size:12.76000023px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans;-inkscape-font-specification:Bitstream Vera Sans"
+     xml:space="preserve"
+     id="text60407-68-0"
+     y="360.20483"
+     x="365.61026"><tspan
+       y="360.20483"
+       x="365.61026"
+       id="tspan16195-3-3"
+       sodipodi:role="line">%% CRITICAL WARNING INFO DEBUG %%</tspan></text>
+  <rect
+     style="fill:#000000;fill-opacity:0;fill-rule:evenodd;stroke:none;stroke-width:1;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
+     id="CRITICAL"
+     y="368.36218"
+     x="409"
+     height="23.999981"
+     width="23.999981" />
+  <rect
+     style="fill:#000000;fill-opacity:0;fill-rule:evenodd;stroke:none;stroke-width:1;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
+     id="WARNING"
+     y="367.86218"
+     x="473"
+     height="23.999981"
+     width="23.999981" />
+  <rect
+     style="fill:#000000;fill-opacity:0;fill-rule:evenodd;stroke:none;stroke-width:1;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
+     id="INFO"
+     y="367.36218"
+     x="525"
+     height="23.999981"
+     width="23.999981" />
+  <rect
+     style="fill:#000000;fill-opacity:0;fill-rule:evenodd;stroke:none;stroke-width:1;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
+     id="DEBUG"
+     y="367.36218"
+     x="568"
+     height="23.999981"
+     width="23.999981" />
+  <path
+     sodipodi:type="arc"
+     style="color:#000000;fill:#ff0000;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.80000001;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
+     id="path18473"
+     sodipodi:cx="420.25"
+     sodipodi:cy="379.61218"
+     sodipodi:rx="6.25"
+     sodipodi:ry="6.25"
+     d="m 426.5,379.61218 a 6.25,6.25 0 1 1 -12.5,0 6.25,6.25 0 1 1 12.5,0 z"
+     transform="matrix(1.8061017,0,0,1.8061017,-338.01425,-305.25604)" />
+  <path
+     style="font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-indent:0;text-align:start;text-decoration:none;line-height:normal;letter-spacing:normal;word-spacing:normal;text-transform:none;direction:ltr;block-progression:tb;writing-mode:lr-tb;text-anchor:start;baseline-shift:baseline;color:#000000;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:4;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate;font-family:Sans;-inkscape-font-specification:Sans"
+     d="m 417.26562,373.92467 -2.78125,2.875 3.65625,3.5625 -3.65625,3.5625 2.78125,2.875 3.71875,-3.65625 3.75,3.65625 2.78125,-2.875 -3.65625,-3.5625 3.65625,-3.5625 -2.78125,-2.875 -3.75,3.65625 -3.71875,-3.65625 z"
+     id="path18476"
+     inkscape:connector-curvature="0" />
+  <path
+     sodipodi:type="star"
+     style="color:#000000;fill:#ffcc00;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
+     id="path19290"
+     sodipodi:sides="3"
+     sodipodi:cx="485.4288"
+     sodipodi:cy="371.94867"
+     sodipodi:r1="12.432317"
+     sodipodi:r2="6.3169394"
+     sodipodi:arg1="0.52090978"
+     sodipodi:arg2="1.568032"
+     inkscape:flatsided="false"
+     inkscape:rounded="0"
+     inkscape:randomized="0"
+     d="m 496.21218,378.13585 -10.76592,0.12973 -10.76741,-0.0718 5.27061,-9.38843 5.44591,-9.28893 5.49531,9.25869 z"
+     inkscape:transform-center-x="-0.016715197"
+     inkscape:transform-center-y="-2.9692899"
+     transform="translate(-0.44552723,10.971182)" />
+  <text
+     xml:space="preserve"
+     style="font-size:18.60616684px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Sans"
+     x="403.38782"
+     y="461.09991"
+     id="text19292"
+     sodipodi:linespacing="125%"
+     transform="scale(1.191303,0.839417)"><tspan
+       sodipodi:role="line"
+       id="tspan19294"
+       x="403.38782"
+       y="461.09991">!</tspan></text>
+  <path
+     sodipodi:type="arc"
+     style="color:#000000;fill:#0000ff;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.80000001;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
+     id="path18473-1"
+     sodipodi:cx="420.25"
+     sodipodi:cy="379.61218"
+     sodipodi:rx="6.25"
+     sodipodi:ry="6.25"
+     d="m 426.5,379.61218 a 6.25,6.25 0 1 1 -12.5,0 6.25,6.25 0 1 1 12.5,0 z"
+     transform="matrix(1.8061017,0,0,1.8061017,-222.01425,-306.25604)" />
+  <text
+     xml:space="preserve"
+     style="font-size:23.34662056px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#ffffff;fill-opacity:1;stroke:none;font-family:Sans"
+     x="412.4111"
+     y="498.97501"
+     id="text19314"
+     sodipodi:linespacing="125%"
+     transform="scale(1.2919212,0.77404101)"><tspan
+       sodipodi:role="line"
+       id="tspan19316"
+       x="412.4111"
+       y="498.97501">i</tspan></text>
+  <rect
+     style="color:#000000;fill:#008000;fill-opacity:1;fill-rule:nonzero;stroke:#c8c8c8;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
+     id="rect19318"
+     width="21.38998"
+     height="19.622213"
+     x="569.30499"
+     y="369.55106" />
+  <path
+     style="fill:none;stroke:#ffffff;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
+     d="m 569.81323,379.69702 6.40816,0 2.17016,-3.75883 3.95368,6.84797 2.08109,-3.60455 5.76043,0"
+     id="path19324"
+     inkscape:connector-curvature="0"
+     sodipodi:nodetypes="cccccc" />
 </svg>