GraphicViewer.py
author lbessard
Thu, 09 Apr 2009 15:40:27 +0200
changeset 344 0acc2bd658f0
parent 338 87e5015330ae
child 361 62570186dad4
permissions -rw-r--r--
Bug while closing GraphicViewer and PLC running generating errors fixed
301
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
     1
#!/usr/bin/env python
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
     3
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
     4
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
     5
#based on the plcopen standard. 
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
     6
#
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
     7
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
     8
#
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
     9
#See COPYING file for copyrights details.
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    10
#
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    11
#This library is free software; you can redistribute it and/or
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    12
#modify it under the terms of the GNU General Public
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    13
#License as published by the Free Software Foundation; either
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    14
#version 2.1 of the License, or (at your option) any later version.
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    15
#
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    16
#This library is distributed in the hope that it will be useful,
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    17
#but WITHOUT ANY WARRANTY; without even the implied warranty of
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    18
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    19
#General Public License for more details.
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    20
#
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    21
#You should have received a copy of the GNU General Public
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    22
#License along with this library; if not, write to the Free Software
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    23
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    24
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    25
import wx
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    26
import wx.lib.plot as plot
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    27
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    28
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    29
colours = ['blue', 'red', 'green', 'yellow', 'orange', 'purple', 'brown', 'cyan',
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    30
           'pink', 'grey']
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    31
markers = ['circle', 'dot', 'square', 'triangle', 'triangle_down', 'cross', 'plus', 'circle']
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    32
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    33
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    34
#-------------------------------------------------------------------------------
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    35
#                       Debug Variable Graphic Viewer class
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    36
#-------------------------------------------------------------------------------
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    37
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    38
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    39
RANGE_VALUES = [str(25 * 2 ** i) for i in xrange(6)]
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    40
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    41
[ID_GRAPHICVIEWER, ID_GRAPHICVIEWERCANVAS,
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    42
 ID_GRAPHICVIEWERCANVASRANGE, ID_GRAPHICVIEWERCANVASPOSITION,
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    43
 ID_GRAPHICVIEWERRESETBUTTON, ID_GRAPHICVIEWERCURRENTBUTTON, 
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    44
 ID_GRAPHICVIEWERSTATICTEXT1, ID_GRAPHICVIEWERSTATICTEXT2,
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    45
] = [wx.NewId() for _init_ctrls in range(8)]
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    46
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    47
class GraphicViewer(wx.Panel):
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    48
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    49
    def _init_coll_MainGridSizer_Items(self, parent):
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    50
        # generated method, don't edit
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    51
        parent.AddWindow(self.Canvas, 0, border=0, flag=wx.GROW)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    52
        parent.AddSizer(self.RangeSizer, 0, border=0, flag=wx.GROW)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    53
    
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    54
    def _init_coll_MainGridSizer_Growables(self, parent):
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    55
        # generated method, don't edit
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    56
        parent.AddGrowableCol(0)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    57
        parent.AddGrowableRow(0)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    58
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    59
    def _init_coll_RangeSizer_Items(self, parent):
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    60
        # generated method, don't edit
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    61
        parent.AddWindow(self.staticbox1, 0, border=5, flag=wx.ALL)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    62
        parent.AddWindow(self.CanvasRange, 0, border=5, flag=wx.ALL)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    63
        parent.AddWindow(self.staticText2, 0, border=5, flag=wx.ALL)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    64
        parent.AddWindow(self.CanvasPosition, 0, border=5, flag=wx.GROW|wx.ALL)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    65
        parent.AddWindow(self.ResetButton, 0, border=5, flag=wx.ALL)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    66
        parent.AddWindow(self.CurrentButton, 0, border=5, flag=wx.ALL)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    67
        
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    68
    def _init_coll_RangeSizer_Growables(self, parent):
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    69
        # generated method, don't edit
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    70
        parent.AddGrowableCol(3)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    71
        parent.AddGrowableRow(0)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    72
        
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    73
    def _init_sizers(self):
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    74
        # generated method, don't edit
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    75
        self.MainGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    76
        self.RangeSizer = wx.FlexGridSizer(cols=6, hgap=0, rows=1, vgap=0)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    77
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    78
        self._init_coll_MainGridSizer_Items(self.MainGridSizer)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    79
        self._init_coll_MainGridSizer_Growables(self.MainGridSizer)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    80
        self._init_coll_RangeSizer_Items(self.RangeSizer)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    81
        self._init_coll_RangeSizer_Growables(self.RangeSizer)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    82
        
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    83
        self.SetSizer(self.MainGridSizer)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    84
    
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    85
    def _init_ctrls(self, prnt):
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    86
        wx.Panel.__init__(self, prnt, ID_GRAPHICVIEWER, wx.DefaultPosition, 
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    87
                 wx.DefaultSize, 0)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    88
        
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    89
        self.Canvas = plot.PlotCanvas(id=ID_GRAPHICVIEWERCANVAS, 
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    90
              name='Canvas', parent=self, pos=wx.Point(0, 0),
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    91
              size=wx.Size(0, 0), style=0)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    92
        def _axisInterval(spec, lower, upper):
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    93
            if spec == 'border':
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    94
                if lower == upper:
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    95
                    return lower - 0.5, upper + 0.5
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    96
                else:
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    97
                    border = (upper - lower) * 0.05
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    98
                    return lower - border, upper + border
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
    99
            else:
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   100
                return plot.PlotCanvas._axisInterval(self.Canvas, spec, lower, upper)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   101
        self.Canvas._axisInterval = _axisInterval
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   102
        self.Canvas.SetYSpec('border')
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   103
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   104
        self.staticbox1 = wx.StaticText(id=ID_GRAPHICVIEWERSTATICTEXT1,
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   105
              label='Range:', name='staticText1', parent=self,
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   106
              pos=wx.Point(0, 0), size=wx.Size(45, 17), style=0)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   107
        
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   108
        self.CanvasRange = wx.ComboBox(id=ID_GRAPHICVIEWERCANVASRANGE,
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   109
              name='CanvasRange', parent=self, pos=wx.Point(0, 0),
313
9266d1e6e3d4 Fix size of ComboBoxes
lbessard
parents: 301
diff changeset
   110
              size=wx.Size(100, 28), choices=RANGE_VALUES, style=0)
301
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   111
        self.CanvasRange.SetStringSelection("25")
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   112
        self.Bind(wx.EVT_COMBOBOX, self.OnRangeChanged, id=ID_GRAPHICVIEWERCANVASRANGE)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   113
        self.Bind(wx.EVT_TEXT_ENTER, self.OnRangeChanged, id=ID_GRAPHICVIEWERCANVASRANGE)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   114
        
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   115
        self.staticText2 = wx.StaticText(id=ID_GRAPHICVIEWERSTATICTEXT2,
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   116
              label='Position:', name='staticText2', parent=self,
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   117
              pos=wx.Point(0, 0), size=wx.Size(60, 17), style=0)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   118
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   119
        self.CanvasPosition = wx.ScrollBar(id=ID_GRAPHICVIEWERCANVASPOSITION,
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   120
              name='Position', parent=self, pos=wx.Point(0, 0),
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   121
              size=wx.Size(0, 16), style=wx.SB_HORIZONTAL)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   122
        self.CanvasPosition.SetScrollbar(0, 10, 100, 10)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   123
        self.CanvasPosition.Bind(wx.EVT_SCROLL_THUMBTRACK, self.OnPositionChanging, 
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   124
              id = ID_GRAPHICVIEWERCANVASPOSITION)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   125
        self.CanvasPosition.Bind(wx.EVT_SCROLL_LINEUP, self.OnPositionChanging, 
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   126
              id = ID_GRAPHICVIEWERCANVASPOSITION)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   127
        self.CanvasPosition.Bind(wx.EVT_SCROLL_LINEDOWN, self.OnPositionChanging, 
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   128
              id = ID_GRAPHICVIEWERCANVASPOSITION)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   129
        self.CanvasPosition.Bind(wx.EVT_SCROLL_PAGEUP, self.OnPositionChanging, 
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   130
              id = ID_GRAPHICVIEWERCANVASPOSITION)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   131
        self.CanvasPosition.Bind(wx.EVT_SCROLL_PAGEDOWN, self.OnPositionChanging, 
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   132
              id = ID_GRAPHICVIEWERCANVASPOSITION)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   133
        
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   134
        self.ResetButton = wx.Button(id=ID_GRAPHICVIEWERRESETBUTTON, label='Reset',
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   135
              name='ResetButton', parent=self, pos=wx.Point(0, 0),
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   136
              size=wx.Size(72, 24), style=0)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   137
        self.Bind(wx.EVT_BUTTON, self.OnResetButton, id=ID_GRAPHICVIEWERRESETBUTTON)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   138
        
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   139
        self.CurrentButton = wx.Button(id=ID_GRAPHICVIEWERCURRENTBUTTON, label='Current',
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   140
              name='CurrentButton', parent=self, pos=wx.Point(0, 0),
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   141
              size=wx.Size(72, 24), style=0)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   142
        self.Bind(wx.EVT_BUTTON, self.OnCurrentButton, id=ID_GRAPHICVIEWERCURRENTBUTTON)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   143
        
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   144
        self._init_sizers()
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   145
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   146
    def __init__(self, parent, window, controler, instancepath = ""):
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   147
        self._init_ctrls(parent)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   148
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   149
        self.ParentWindow = window
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   150
        self.Controler = controler
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   151
        self.InstancePath = instancepath
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   152
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   153
        self.Datas = []
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   154
        self.CurrentValue = 0
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   155
        self.CurrentRange = 25
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   156
        
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   157
        self.Controler.SubscribeDebugIECVariable(self.InstancePath.upper(), self)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   158
    
338
87e5015330ae Adding support for ToolTip on wire when debugging
lbessard
parents: 331
diff changeset
   159
    def __del__(self):
87e5015330ae Adding support for ToolTip on wire when debugging
lbessard
parents: 331
diff changeset
   160
        self.Controler.UnsubscribeDebugIECVariable(self.InstancePath.upper(), self)
87e5015330ae Adding support for ToolTip on wire when debugging
lbessard
parents: 331
diff changeset
   161
    
87e5015330ae Adding support for ToolTip on wire when debugging
lbessard
parents: 331
diff changeset
   162
    def ResetView(self):
87e5015330ae Adding support for ToolTip on wire when debugging
lbessard
parents: 331
diff changeset
   163
        self.Datas = []
87e5015330ae Adding support for ToolTip on wire when debugging
lbessard
parents: 331
diff changeset
   164
        self.CurrentValue = 0
87e5015330ae Adding support for ToolTip on wire when debugging
lbessard
parents: 331
diff changeset
   165
        self.RefreshView()
87e5015330ae Adding support for ToolTip on wire when debugging
lbessard
parents: 331
diff changeset
   166
    
301
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   167
    def RefreshView(self):
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   168
        var_name = self.InstancePath.split(".")[-1]
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   169
        
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   170
        self.VariableGraphic = plot.PolyLine(self.Datas[self.CurrentValue:self.CurrentValue + self.CurrentRange], 
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   171
                                             legend=var_name, colour=colours[0])
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   172
        self.GraphicsObject = plot.PlotGraphics([self.VariableGraphic], "%s Graphics" % var_name, "Tick", "Values")
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   173
        datas_length = len(self.Datas)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   174
        if datas_length > 1:
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   175
            start = self.Datas[self.CurrentValue][0]
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   176
            if self.CurrentValue + self.CurrentRange > datas_length:
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   177
                end = start + (self.Datas[datas_length - 1][0] - start) * self.CurrentRange / (datas_length - self.CurrentValue - 1)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   178
            else:
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   179
                end = self.Datas[self.CurrentValue + self.CurrentRange - 1][0]
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   180
        else:
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   181
            start = 0.
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   182
            end = 25.
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   183
        self.Canvas.Draw(self.GraphicsObject, xAxis=(start, end))
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   184
        
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   185
        self.RefreshScrollBar()
326
c82807b17128 Bugs with undefined functions fixed
lbessard
parents: 313
diff changeset
   186
    
c82807b17128 Bugs with undefined functions fixed
lbessard
parents: 313
diff changeset
   187
    def SetMode(self, mode):
c82807b17128 Bugs with undefined functions fixed
lbessard
parents: 313
diff changeset
   188
        pass
c82807b17128 Bugs with undefined functions fixed
lbessard
parents: 313
diff changeset
   189
    
301
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   190
    def GetTagName(self):
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   191
        return ""
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   192
    
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   193
    def GetInstancePath(self):
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   194
        return self.InstancePath
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   195
    
326
c82807b17128 Bugs with undefined functions fixed
lbessard
parents: 313
diff changeset
   196
    def IsViewing(self, tagname):
c82807b17128 Bugs with undefined functions fixed
lbessard
parents: 313
diff changeset
   197
        return self.InstancePath == tagname
c82807b17128 Bugs with undefined functions fixed
lbessard
parents: 313
diff changeset
   198
    
c82807b17128 Bugs with undefined functions fixed
lbessard
parents: 313
diff changeset
   199
    def ResetBuffer(self):
c82807b17128 Bugs with undefined functions fixed
lbessard
parents: 313
diff changeset
   200
        pass
c82807b17128 Bugs with undefined functions fixed
lbessard
parents: 313
diff changeset
   201
    
c82807b17128 Bugs with undefined functions fixed
lbessard
parents: 313
diff changeset
   202
    def RefreshScaling(self, refresh=True):
c82807b17128 Bugs with undefined functions fixed
lbessard
parents: 313
diff changeset
   203
        pass
c82807b17128 Bugs with undefined functions fixed
lbessard
parents: 313
diff changeset
   204
    
331
9106d66bd204 Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents: 326
diff changeset
   205
    def SelectAll(self):
9106d66bd204 Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents: 326
diff changeset
   206
        pass
9106d66bd204 Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents: 326
diff changeset
   207
    
301
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   208
    def AddPoint(self, tick, value):
344
0acc2bd658f0 Bug while closing GraphicViewer and PLC running generating errors fixed
lbessard
parents: 338
diff changeset
   209
        if self:
0acc2bd658f0 Bug while closing GraphicViewer and PLC running generating errors fixed
lbessard
parents: 338
diff changeset
   210
            self.Datas.append((float(tick), {True:1., False:0.}.get(value, float(value))))
0acc2bd658f0 Bug while closing GraphicViewer and PLC running generating errors fixed
lbessard
parents: 338
diff changeset
   211
            if self.CurrentValue + self.CurrentRange == len(self.Datas) - 1:
0acc2bd658f0 Bug while closing GraphicViewer and PLC running generating errors fixed
lbessard
parents: 338
diff changeset
   212
                self.CurrentValue += 1
0acc2bd658f0 Bug while closing GraphicViewer and PLC running generating errors fixed
lbessard
parents: 338
diff changeset
   213
                self.RefreshView()
0acc2bd658f0 Bug while closing GraphicViewer and PLC running generating errors fixed
lbessard
parents: 338
diff changeset
   214
            elif len(self.Datas) < self.CurrentValue + self.CurrentRange:
0acc2bd658f0 Bug while closing GraphicViewer and PLC running generating errors fixed
lbessard
parents: 338
diff changeset
   215
                self.RefreshView()
0acc2bd658f0 Bug while closing GraphicViewer and PLC running generating errors fixed
lbessard
parents: 338
diff changeset
   216
            else:
0acc2bd658f0 Bug while closing GraphicViewer and PLC running generating errors fixed
lbessard
parents: 338
diff changeset
   217
                self.RefreshScrollBar()
301
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   218
            
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   219
    def RefreshScrollBar(self):
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   220
        self.CanvasPosition.SetScrollbar(self.CurrentValue, self.CurrentRange, len(self.Datas), self.CurrentRange)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   221
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   222
    def OnRangeChanged(self, event):
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   223
        old_range = self.CurrentRange
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   224
        try:
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   225
            self.CurrentRange = int(self.CanvasRange.GetValue())
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   226
        except ValueError, e:
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   227
            self.CanvasRange.SetValue(str(self.CurrentRange))
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   228
        self.CurrentValue = max(0, min(self.CurrentValue + old_range - self.CurrentRange, 
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   229
                                       len(self.Datas) - self.CurrentRange))
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   230
        self.RefreshView()
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   231
        event.Skip()
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   232
    
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   233
    def OnPositionChanging(self, event):
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   234
        self.CurrentValue = event.GetPosition()
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   235
        self.RefreshView()
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   236
        event.Skip()
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   237
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   238
    def OnResetButton(self, event):
338
87e5015330ae Adding support for ToolTip on wire when debugging
lbessard
parents: 331
diff changeset
   239
        self.ResetView()
301
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   240
        event.Skip()
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   241
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   242
    def OnCurrentButton(self, event):
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   243
        self.CurrentValue = max(0, len(self.Datas) - self.CurrentRange)
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   244
        self.RefreshView()
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   245
        event.Skip()
b5e564608b9e Adding support for Graphic for variable in Debug mode
lbessard
parents:
diff changeset
   246