controls/DebugVariablePanel/DebugVariablePanel.py
changeset 1649 3291024e00da
parent 1578 f8e2a04c4445
child 1730 64d8f52bc8c8
equal deleted inserted replaced
1648:6431f26aa501 1649:3291024e00da
     1 #!/usr/bin/env python
     1 #!/usr/bin/env python
     2 # -*- coding: utf-8 -*-
     2 # -*- coding: utf-8 -*-
     3 
     3 
     4 #This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
     4 # This file is part of Beremiz, a Integrated Development Environment for
     5 #based on the plcopen standard. 
     5 # programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
     6 #
     6 #
     7 #Copyright (C) 2012: Edouard TISSERANT and Laurent BESSARD
     7 # Copyright (C) 2012: Edouard TISSERANT and Laurent BESSARD
     8 #
     8 #
     9 #See COPYING file for copyrights details.
     9 # See COPYING file for copyrights details.
    10 #
    10 #
    11 #This library is free software; you can redistribute it and/or
    11 # This program is free software; you can redistribute it and/or
    12 #modify it under the terms of the GNU General Public
    12 # modify it under the terms of the GNU General Public License
    13 #License as published by the Free Software Foundation; either
    13 # as published by the Free Software Foundation; either version 2
    14 #version 2.1 of the License, or (at your option) any later version.
    14 # of the License, or (at your option) any later version.
    15 #
    15 #
    16 #This library is distributed in the hope that it will be useful,
    16 # This program is distributed in the hope that it will be useful,
    17 #but WITHOUT ANY WARRANTY; without even the implied warranty of
    17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
    18 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    19 #General Public License for more details.
    19 # GNU General Public License for more details.
    20 #
    20 #
    21 #You should have received a copy of the GNU General Public
    21 # You should have received a copy of the GNU General Public License
    22 #License along with this library; if not, write to the Free Software
    22 # along with this program; if not, write to the Free Software
    23 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    24 
    24 
    25 from types import TupleType
    25 from types import TupleType
    26 import math
    26 import math
    27 import numpy
    27 import numpy
    28 
    28 
    48 DAY = 24 * HOUR             # Number of nanosecond in a day
    48 DAY = 24 * HOUR             # Number of nanosecond in a day
    49 
    49 
    50 # List of values possible for graph range
    50 # List of values possible for graph range
    51 # Format is [(time_in_plain_text, value_in_nanosecond),...]
    51 # Format is [(time_in_plain_text, value_in_nanosecond),...]
    52 RANGE_VALUES = \
    52 RANGE_VALUES = \
    53     [("%dms" % i, i * MILLISECOND) for i in (10, 20, 50, 100, 200, 500)] + \
    53     [(_("%dms") % i, i * MILLISECOND) for i in (10, 20, 50, 100, 200, 500)] + \
    54     [("%ds" % i, i * SECOND) for i in (1, 2, 5, 10, 20, 30)] + \
    54     [(_("%ds") % i, i * SECOND) for i in (1, 2, 5, 10, 20, 30)] + \
    55     [("%dm" % i, i * MINUTE) for i in (1, 2, 5, 10, 20, 30)] + \
    55     [(_("%dm") % i, i * MINUTE) for i in (1, 2, 5, 10, 20, 30)] + \
    56     [("%dh" % i, i * HOUR) for i in (1, 2, 3, 6, 12, 24)]
    56     [(_("%dh") % i, i * HOUR) for i in (1, 2, 3, 6, 12, 24)]
    57 
    57 
    58 # Scrollbar increment in pixel
    58 # Scrollbar increment in pixel
    59 SCROLLBAR_UNIT = 10
    59 SCROLLBAR_UNIT = 10
    60 
    60 
    61 def compute_mask(x, y):
    61 def compute_mask(x, y):
   289         self.GraphicsWindow.SetSizer(self.GraphicsSizer)
   289         self.GraphicsWindow.SetSizer(self.GraphicsSizer)
   290     
   290     
   291         DebugViewer.__init__(self, producer, True)
   291         DebugViewer.__init__(self, producer, True)
   292         
   292         
   293         self.SetSizer(main_sizer)
   293         self.SetSizer(main_sizer)
       
   294         self.SetTickTime()
   294     
   295     
   295     def SetTickTime(self, ticktime=0):
   296     def SetTickTime(self, ticktime=0):
   296         """
   297         """
   297         Set Ticktime for calculate data range according to time range selected
   298         Set Ticktime for calculate data range according to time range selected
   298         @param ticktime: Ticktime to apply to range (default: 0)
   299         @param ticktime: Ticktime to apply to range (default: 0)
   559         elif len(self.Ticks) > 0:
   560         elif len(self.Ticks) > 0:
   560             tick = self.Ticks[-1]
   561             tick = self.Ticks[-1]
   561         else:
   562         else:
   562             tick = None
   563             tick = None
   563         if tick is not None:
   564         if tick is not None:
   564             self.TickLabel.SetLabel("Tick: %d" % tick)
   565             self.TickLabel.SetLabel(label=_("Tick: %d") % tick)
   565             tick_duration = int(tick * self.Ticktime)
   566             tick_duration = int(tick * self.Ticktime)
   566             not_null = False
   567             not_null = False
   567             duration = ""
   568             duration = ""
   568             for value, format in [(tick_duration / DAY, "%dd"),
   569             for value, format in [(tick_duration / DAY, _("%dd")),
   569                                   ((tick_duration % DAY) / HOUR, "%dh"),
   570                                   ((tick_duration % DAY) / HOUR, _("%dh")),
   570                                   ((tick_duration % HOUR) / MINUTE, "%dm"),
   571                                   ((tick_duration % HOUR) / MINUTE, _("%dm")),
   571                                   ((tick_duration % MINUTE) / SECOND, "%ds")]:
   572                                   ((tick_duration % MINUTE) / SECOND, _("%ds"))]:
   572                 
   573                 
   573                 if value > 0 or not_null:
   574                 if value > 0 or not_null:
   574                     duration += format % value
   575                     duration += format % value
   575                     not_null = True
   576                     not_null = True
   576             
   577             
   577             duration += "%gms" % (float(tick_duration % SECOND) / MILLISECOND) 
   578             duration += _("%03gms") % (float(tick_duration % SECOND) / MILLISECOND) 
   578             self.TickTimeLabel.SetLabel("t: %s" % duration)
   579             self.TickTimeLabel.SetLabel("t: %s" % duration)
   579         else:
   580         else:
   580             self.TickLabel.SetLabel("")
   581             self.TickLabel.SetLabel("")
   581             self.TickTimeLabel.SetLabel("")
   582             self.TickTimeLabel.SetLabel("")
   582         self.TickSizer.Layout()
   583         self.TickSizer.Layout()