clean PLC log only if there is something to clean
authorAndrey Skvortsov <andrej.skvortzov@gmail.com>
Wed, 05 Apr 2017 14:24:52 +0300
changeset 1673 fab1b8da6eba
parent 1672 9298ba0cd70a
child 1674 85e22d514c05
clean PLC log only if there is something to clean

Otherwise exception happens in Beremiz service.

Traceback (most recent call last):
File "/home/developer/WorkData/PLC/beremiz/beremiz/connectors/PYRO/_init_.py", line 113, in catcher_func
return func(*args, **kwargs)
File "/home/developer/WorkData/PLC/beremiz/beremiz/connectors/PYRO/_init_.py", line 194, in my_local_func
return RemotePLCObjectProxy._getattr_(attrName)(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/Pyro/core.py", line 381, in _call_
return self._send(self._name, args, kwargs)
File "/usr/lib/python2.7/dist-packages/Pyro/core.py", line 456, in _invokePYRO
return self.adapter.remoteInvocation(name, Pyro.constants.RIF_VarargsAndKeywords, vargs, kargs)
File "/usr/lib/python2.7/dist-packages/Pyro/protocol.py", line 457, in remoteInvocation
return self._remoteInvocation(method, flags, *args)
File "/usr/lib/python2.7/dist-packages/Pyro/protocol.py", line 532, in _remoteInvocation
answer.raiseEx()
File "/usr/lib/python2.7/dist-packages/Pyro/errors.py", line 72, in raiseEx
raise self.excObj
AttributeError: 'PLCObject' object has no attribute '_ResetLogCount'
+--- This exception occured remotely (Pyro) - Remote traceback:
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/Pyro/protocol.py", line 719, in _handleInvocation2
res = obj.Pyro_dyncall(req[1],flags,req[3]) # (method,flags,args)
File "/usr/lib/python2.7/dist-packages/Pyro/core.py", line 108, in Pyro_dyncall
return getattr(self.delegate or self,method) (args,*keywords)
File "/home/developer/WorkData/PLC/beremiz/beremiz/runtime/PLCObject.py", line 101, in ResetLogCount
if self._ResetLogCount is not None:
AttributeError: 'PLCObject' object has no attribute '_ResetLogCount'
+--- End of remote traceback
controls/LogViewer.py
--- a/controls/LogViewer.py	Wed Apr 05 14:17:02 2017 +0300
+++ b/controls/LogViewer.py	Wed Apr 05 14:24:52 2017 +0300
@@ -552,6 +552,14 @@
 
         self.MessageScrollBar.RefreshThumbPosition()
 
+    def IsPLCLogEmpty(self):
+        empty=True
+        for level, prev in zip(xrange(LogLevelsCount), self.previous_log_count):
+            if prev is not None:
+                empty=False
+                break
+        return empty
+        
     def IsMessagePanelTop(self, message_idx=None):
         if message_idx is None:
             message_idx = self.CurrentMessage
@@ -639,7 +647,7 @@
         event.Skip()
 
     def OnCleanButton(self, event):
-        if self.LogSource is not None:
+        if self.LogSource is not None and not self.IsPLCLogEmpty():
             self.LogSource.ResetLogCount()
         self.ResetLogMessages()
         self.RefreshView()