# HG changeset patch
# User Laurent Bessard
# Date 1339690412 -7200
# Node ID 5f6a743dcde572aabf25f8813cb8a962f003f0cf
# Parent 365bb7496697efeeee9ec6fd08631fd91eae26a6
Adding support for exporting graph value to csv formatted string to clipboard
diff -r 365bb7496697 -r 5f6a743dcde5 GraphicViewer.py
--- a/GraphicViewer.py Mon Jun 11 01:30:03 2012 +0200
+++ b/GraphicViewer.py Thu Jun 14 18:13:32 2012 +0200
@@ -22,10 +22,13 @@
#License along with this library; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+import numpy
+import math
+
import wx
import wx.lib.plot as plot
-import numpy
-import math
+import wx.lib.buttons
+
from graphics.GraphicCommons import DebugViewer, MODE_SELECTION, MODE_MOTION
from controls import EditorPanel
@@ -48,60 +51,16 @@
[("%dm" % i, i * MINUTE) for i in (1, 2, 5, 10, 20, 30)] + \
[("%dh" % i, i * HOUR) for i in (1, 2, 3, 6, 12, 24)]
-[ID_GRAPHICVIEWER, ID_GRAPHICVIEWERCANVAS,
- ID_GRAPHICVIEWERCANVASRANGE, ID_GRAPHICVIEWERCANVASZOOM,
- ID_GRAPHICVIEWERCANVASPOSITION, ID_GRAPHICVIEWERRESETBUTTON,
- ID_GRAPHICVIEWERCURRENTBUTTON, ID_GRAPHICVIEWERSTATICTEXT1,
- ID_GRAPHICVIEWERSTATICTEXT2, ID_GRAPHICVIEWERSTATICTEXT3,
-] = [wx.NewId() for _init_ctrls in range(10)]
-
class GraphicViewer(EditorPanel, DebugViewer):
- def _init_coll_MainGridSizer_Items(self, parent):
- # generated method, don't edit
- parent.AddWindow(self.Canvas, 0, border=0, flag=wx.GROW)
- parent.AddSizer(self.RangeSizer, 0, border=0, flag=wx.GROW)
-
- def _init_coll_MainGridSizer_Growables(self, parent):
- # generated method, don't edit
- parent.AddGrowableCol(0)
- parent.AddGrowableRow(0)
-
- def _init_coll_RangeSizer_Items(self, parent):
- # generated method, don't edit
- parent.AddWindow(self.staticbox1, 0, border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL)
- parent.AddWindow(self.CanvasRange, 0, border=5, flag=wx.ALL)
- parent.AddWindow(self.staticbox3, 0, border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL)
- parent.AddWindow(self.CanvasZoom, 0, border=5, flag=wx.ALL)
- parent.AddWindow(self.staticText2, 0, border=5, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL)
- parent.AddWindow(self.CanvasPosition, 0, border=5, flag=wx.GROW|wx.ALL)
- parent.AddWindow(self.ResetButton, 0, border=5, flag=wx.ALL)
- parent.AddWindow(self.CurrentButton, 0, border=5, flag=wx.ALL)
-
- def _init_coll_RangeSizer_Growables(self, parent):
- # generated method, don't edit
- parent.AddGrowableCol(5)
- parent.AddGrowableRow(0)
-
- def _init_sizers(self):
- # generated method, don't edit
- self.MainGridSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
- self.RangeSizer = wx.FlexGridSizer(cols=8, hgap=0, rows=1, vgap=0)
-
- self._init_coll_MainGridSizer_Items(self.MainGridSizer)
- self._init_coll_MainGridSizer_Growables(self.MainGridSizer)
- self._init_coll_RangeSizer_Items(self.RangeSizer)
- self._init_coll_RangeSizer_Growables(self.RangeSizer)
-
- self.Editor.SetSizer(self.MainGridSizer)
-
def _init_Editor(self, prnt):
- self.Editor = wx.Panel(prnt, ID_GRAPHICVIEWER, wx.DefaultPosition,
- wx.DefaultSize, 0)
-
- self.Canvas = plot.PlotCanvas(id=ID_GRAPHICVIEWERCANVAS,
- name='Canvas', parent=self.Editor, pos=wx.Point(0, 0),
- size=wx.Size(0, 0), style=0)
+ self.Editor = wx.Panel(prnt)
+
+ main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
+ main_sizer.AddGrowableCol(0)
+ main_sizer.AddGrowableRow(0)
+
+ self.Canvas = plot.PlotCanvas(self.Editor, name='Canvas')
def _axisInterval(spec, lower, upper):
if spec == 'border':
if lower == upper:
@@ -118,55 +77,63 @@
self.Canvas.canvas.Bind(wx.EVT_MOTION, self.OnCanvasMotion)
self.Canvas.canvas.Bind(wx.EVT_MOUSEWHEEL, self.OnCanvasMouseWheel)
self.Canvas.canvas.Bind(wx.EVT_SIZE, self.OnCanvasResize)
-
- self.staticbox1 = wx.StaticText(id=ID_GRAPHICVIEWERSTATICTEXT1,
- label=_('Range:'), name='staticText1', parent=self.Editor,
- pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
-
- self.CanvasRange = wx.ComboBox(id=ID_GRAPHICVIEWERCANVASRANGE,
- name='CanvasRange', parent=self.Editor, pos=wx.Point(0, 0),
+ main_sizer.AddWindow(self.Canvas, 0, border=0, flag=wx.GROW)
+
+ range_sizer = wx.FlexGridSizer(cols=9, hgap=5, rows=1, vgap=0)
+ range_sizer.AddGrowableCol(5)
+ range_sizer.AddGrowableRow(0)
+ main_sizer.AddSizer(range_sizer, 0, border=5, flag=wx.GROW|wx.ALL)
+
+ range_label = wx.StaticText(self.Editor, label=_('Range:'))
+ range_sizer.AddWindow(range_label, 0, border=0, flag=wx.ALIGN_CENTER_VERTICAL)
+
+ self.CanvasRange = wx.ComboBox(self.Editor,
size=wx.Size(100, 28), style=wx.CB_READONLY)
- self.Bind(wx.EVT_COMBOBOX, self.OnRangeChanged, id=ID_GRAPHICVIEWERCANVASRANGE)
-
- self.staticbox3 = wx.StaticText(id=ID_GRAPHICVIEWERSTATICTEXT3,
- label=_('Zoom:'), name='staticText3', parent=self.Editor,
- pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
-
- self.CanvasZoom = wx.ComboBox(id=ID_GRAPHICVIEWERCANVASZOOM,
- name='CanvasZoom', parent=self.Editor, pos=wx.Point(0, 0),
+ self.Bind(wx.EVT_COMBOBOX, self.OnRangeChanged, self.CanvasRange)
+ range_sizer.AddWindow(self.CanvasRange, 0, border=0, flag=0)
+
+ zoom_label = wx.StaticText(self.Editor, label=_('Zoom:'))
+ range_sizer.AddWindow(zoom_label, 0, border=0, flag=wx.ALIGN_CENTER_VERTICAL)
+
+ self.CanvasZoom = wx.ComboBox(self.Editor,
size=wx.Size(70, 28), style=wx.CB_READONLY)
- self.Bind(wx.EVT_COMBOBOX, self.OnZoomChanged, id=ID_GRAPHICVIEWERCANVASZOOM)
-
- self.staticText2 = wx.StaticText(id=ID_GRAPHICVIEWERSTATICTEXT2,
- label=_('Position:'), name='staticText2', parent=self.Editor,
- pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
-
- self.CanvasPosition = wx.ScrollBar(id=ID_GRAPHICVIEWERCANVASPOSITION,
- name='Position', parent=self.Editor, pos=wx.Point(0, 0),
+ self.Bind(wx.EVT_COMBOBOX, self.OnZoomChanged, self.CanvasZoom)
+ range_sizer.AddWindow(self.CanvasZoom, 0, border=0, flag=0)
+
+ position_label = wx.StaticText(self.Editor, label=_('Position:'))
+ range_sizer.AddWindow(position_label, 0, border=0, flag=wx.ALIGN_CENTER_VERTICAL)
+
+ self.CanvasPosition = wx.ScrollBar(self.Editor,
size=wx.Size(0, 16), style=wx.SB_HORIZONTAL)
self.CanvasPosition.SetScrollbar(0, 10, 100, 10)
- self.CanvasPosition.Bind(wx.EVT_SCROLL_THUMBTRACK, self.OnPositionChanging,
- id = ID_GRAPHICVIEWERCANVASPOSITION)
- self.CanvasPosition.Bind(wx.EVT_SCROLL_LINEUP, self.OnPositionChanging,
- id = ID_GRAPHICVIEWERCANVASPOSITION)
- self.CanvasPosition.Bind(wx.EVT_SCROLL_LINEDOWN, self.OnPositionChanging,
- id = ID_GRAPHICVIEWERCANVASPOSITION)
- self.CanvasPosition.Bind(wx.EVT_SCROLL_PAGEUP, self.OnPositionChanging,
- id = ID_GRAPHICVIEWERCANVASPOSITION)
- self.CanvasPosition.Bind(wx.EVT_SCROLL_PAGEDOWN, self.OnPositionChanging,
- id = ID_GRAPHICVIEWERCANVASPOSITION)
-
- self.ResetButton = wx.Button(id=ID_GRAPHICVIEWERRESETBUTTON, label='Reset',
- name='ResetButton', parent=self.Editor, pos=wx.Point(0, 0),
- size=wx.Size(72, 24), style=0)
- self.Bind(wx.EVT_BUTTON, self.OnResetButton, id=ID_GRAPHICVIEWERRESETBUTTON)
-
- self.CurrentButton = wx.Button(id=ID_GRAPHICVIEWERCURRENTBUTTON, label='Current',
- name='CurrentButton', parent=self.Editor, pos=wx.Point(0, 0),
- size=wx.Size(72, 24), style=0)
- self.Bind(wx.EVT_BUTTON, self.OnCurrentButton, id=ID_GRAPHICVIEWERCURRENTBUTTON)
-
- self._init_sizers()
+ self.CanvasPosition.Bind(wx.EVT_SCROLL_THUMBTRACK,
+ self.OnPositionChanging, self.CanvasPosition)
+ self.CanvasPosition.Bind(wx.EVT_SCROLL_LINEUP,
+ self.OnPositionChanging, self.CanvasPosition)
+ self.CanvasPosition.Bind(wx.EVT_SCROLL_LINEDOWN,
+ self.OnPositionChanging, self.CanvasPosition)
+ self.CanvasPosition.Bind(wx.EVT_SCROLL_PAGEUP,
+ self.OnPositionChanging, self.CanvasPosition)
+ self.CanvasPosition.Bind(wx.EVT_SCROLL_PAGEDOWN,
+ self.OnPositionChanging, self.CanvasPosition)
+ range_sizer.AddWindow(self.CanvasPosition, 0, border=5, flag=wx.GROW|wx.ALL)
+
+ self.ResetButton = wx.Button(self.Editor, label='Reset', size=wx.Size(72, 24))
+ self.Bind(wx.EVT_BUTTON, self.OnResetButton, self.ResetButton)
+ range_sizer.AddWindow(self.ResetButton, 0, border=0, flag=0)
+
+ self.CurrentButton = wx.Button(self.Editor, label='Current', size=wx.Size(72, 24))
+ self.Bind(wx.EVT_BUTTON, self.OnCurrentButton, self.CurrentButton)
+ range_sizer.AddWindow(self.CurrentButton, 0, border=0, flag=0)
+
+ self.ExportGraphButton = wx.lib.buttons.GenBitmapButton(self.Editor,
+ bitmap=self.ParentWindow.GenerateBitmap("export_graph"),
+ size=wx.Size(28, 28), style=wx.NO_BORDER)
+ self.Bind(wx.EVT_BUTTON, self.OnExportGraphButtonClick,
+ self.ExportGraphButton)
+ range_sizer.AddWindow(self.ExportGraphButton, 0, border=0, flag=0)
+
+ self.Editor.SetSizer(main_sizer)
def __init__(self, parent, window, producer, instancepath = ""):
EditorPanel.__init__(self, parent, "", window, None)
@@ -385,6 +352,14 @@
self.Fixed = False
self.NewDataAvailable(True)
event.Skip()
+
+ def OnExportGraphButtonClick(self, event):
+ data_copy = self.Datas[:]
+ text = "tick;%s;\n" % self.InstancePath
+ for tick, value in data_copy:
+ text += "%d;%.3f;\n" % (tick, value)
+ self.ParentWindow.SetCopyBuffer(text)
+ event.Skip()
def OnCanvasLeftDown(self, event):
self.Fixed = True
diff -r 365bb7496697 -r 5f6a743dcde5 Images/export_graph.png
Binary file Images/export_graph.png has changed
diff -r 365bb7496697 -r 5f6a743dcde5 Images/icons.svg
--- a/Images/icons.svg Mon Jun 11 01:30:03 2012 +0200
+++ b/Images/icons.svg Thu Jun 14 18:13:32 2012 +0200
@@ -23,6247 +23,5735 @@
sodipodi:docname="icons.svg"
inkscape:output_extension="org.inkscape.output.svg.inkscape">
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
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
-
-
+ id="rect62-8"
+ height="12.2285"
+ width="14.9803"
+ y="84.120903"
+ x="95.370201"
+ style="fill:url(#id13-7)" />
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+ id="rect54-5"
+ height="5.1496"
+ width="5.0612001"
+ y="84.219101"
+ x="41.313301"
+ style="fill:url(#id11-4)" />
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+ id="rect46-5"
+ height="12.1484"
+ width="14.1734"
+ y="83.799202"
+ x="35.501099"
+ style="fill:url(#id9-1)" />
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+ id="rect38-6"
+ height="14.4522"
+ width="30.0107"
+ y="82.615097"
+ x="81.5317"
+ style="fill:url(#id7-7)" />
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+ id="rect30-3"
+ height="14.4522"
+ width="29.992701"
+ y="82.615097"
+ x="34.748901"
+ style="fill:url(#id5-4)" />
-
+
+
+
+
-
-
-
-
-
-
-
-
-
+ id="id2-0">
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+ id="id36">
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+ id="rect150"
+ height="5.5662"
+ width="2.7627"
+ y="77.8422"
+ x="228.163"
+ style="fill:url(#id35)" />
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+ id="rect142"
+ height="4.0761"
+ width="4.8685"
+ y="78.3475"
+ x="236.134"
+ style="fill:url(#id33)" />
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+ id="rect134"
+ height="6.5337"
+ width="7.9827"
+ y="78.3129"
+ x="234.974"
+ style="fill:url(#id31)" />
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+ id="rect126"
+ height="2.8062"
+ width="2.7598"
+ y="78.3646"
+ x="206.51"
+ style="fill:url(#id29)" />
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+ id="rect118"
+ height="6.4915"
+ width="7.5579"
+ y="78.1435"
+ x="203.449"
+ style="fill:url(#id27)" />
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+ id="rect110"
+ height="7.6123"
+ width="15.8048"
+ y="77.5661"
+ x="227.733"
+ style="fill:url(#id25)" />
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+ id="rect102"
+ height="7.6123"
+ width="15.7954"
+ y="77.5661"
+ x="203.099"
+ style="fill:url(#id23)" />
-
-
-
-
-
-
-
-
-
-
+ id="id20">
+
+
+
+
+
-
-
-
-
-
-
-
-
+ id="id18">
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+ id="rect86"
+ height="5.2005"
+ width="4.3832"
+ y="85.4893"
+ x="223.819"
+ style="fill:url(#id19)" />
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+ id="rect78"
+ height="10.3911"
+ width="5.0669"
+ y="83.227"
+ x="82.4355"
+ style="fill:url(#id17)" />
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+ id="rect70"
+ height="7.5611"
+ width="9.066"
+ y="84.1867"
+ x="97.5725"
+ style="fill:url(#id15)" />
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+ id="rect62"
+ height="12.2285"
+ width="14.9803"
+ y="84.1209"
+ x="95.3702"
+ style="fill:url(#id13)" />
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+ id="rect54"
+ height="5.1496"
+ width="5.0612"
+ y="84.2191"
+ x="41.3133"
+ style="fill:url(#id11)" />
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+ id="rect46"
+ height="12.1484"
+ width="14.1734"
+ y="83.7992"
+ x="35.5011"
+ style="fill:url(#id9)" />
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+ id="rect38"
+ height="14.4522"
+ width="30.0107"
+ y="82.6151"
+ x="81.5317"
+ style="fill:url(#id7)" />
-
-
-
-
-
-
-
-
-
-
+ id="id4">
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
%%graph%%
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ %%export_graph%%
diff -r 365bb7496697 -r 5f6a743dcde5 PLCOpenEditor.py
--- a/PLCOpenEditor.py Mon Jun 11 01:30:03 2012 +0200
+++ b/PLCOpenEditor.py Thu Jun 14 18:13:32 2012 +0200
@@ -108,7 +108,7 @@
from DataTypeEditor import *
from PLCControler import *
from SearchResultPanel import SearchResultPanel
-from controls import CustomGrid, CustomTable, CustomTree, LibraryPanel, PouInstanceVariablesPanel
+from controls import CustomTree, LibraryPanel, PouInstanceVariablesPanel, DebugVariablePanel
from dialogs import ProjectDialog, PouTransitionDialog, PouActionDialog
# Define PLCOpenEditor controls id
@@ -562,13 +562,13 @@
self.TabsOpened = wx.aui.AuiNotebook(self, ID_PLCOPENEDITORTABSOPENED,
style=wx.aui.AUI_NB_DEFAULT_STYLE|wx.aui.AUI_NB_WINDOWLIST_BUTTON)
self.TabsOpened.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CHANGING,
- self.OnPouSelectedChanging)
+ self.OnPouSelectedChanging)
self.TabsOpened.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CHANGED,
- self.OnPouSelectedChanged)
+ self.OnPouSelectedChanged)
self.TabsOpened.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE,
- self.OnPageClose)
+ self.OnPageClose)
self.TabsOpened.Bind(wx.aui.EVT_AUINOTEBOOK_END_DRAG,
- self.OnPageDragged)
+ self.OnPageDragged)
self.AUIManager.AddPane(self.TabsOpened,
wx.aui.AuiPaneInfo().CentrePane().Name("TabsPane"))
@@ -670,7 +670,7 @@
self.SetMenuBar(self.MenuBar)
if self.EnableDebug:
- self.DebugVariablePanel = DebugVariablePanel(self.RightNoteBook, self.Controler)
+ self.DebugVariablePanel = DebugVariablePanel(self.RightNoteBook, self, self.Controler)
self.MainTabs["DebugVariablePanel"] = (self.DebugVariablePanel, _("Debugger"))
self.RightNoteBook.AddPage(*self.MainTabs["DebugVariablePanel"])
@@ -2888,327 +2888,6 @@
# Debug Variables Panel
#-------------------------------------------------------------------------------
-def GetDebugVariablesTableColnames():
- _ = lambda x : x
- return [_("Variable"), _("Value")]
-
-class VariableTableItem(DebugDataConsumer):
-
- def __init__(self, parent, variable, value):
- DebugDataConsumer.__init__(self)
- self.Parent = parent
- self.Variable = variable
- self.Value = value
-
- def __del__(self):
- self.Parent = None
-
- def SetVariable(self, variable):
- if self.Parent and self.Variable != variable:
- self.Variable = variable
- self.Parent.RefreshGrid()
-
- def GetVariable(self):
- return self.Variable
-
- def SetForced(self, forced):
- if self.Forced != forced:
- self.Forced = forced
- self.Parent.HasNewData = True
-
- def SetValue(self, value):
- if self.Value != value:
- self.Value = value
- self.Parent.HasNewData = True
-
- def GetValue(self):
- return self.Value
-
-class DebugVariableTable(CustomTable):
-
- def GetValue(self, row, col):
- if row < self.GetNumberRows():
- return self.GetValueByName(row, self.GetColLabelValue(col, False))
- return ""
-
- def SetValue(self, row, col, value):
- if col < len(self.colnames):
- self.SetValueByName(row, self.GetColLabelValue(col, False), value)
-
- def GetValueByName(self, row, colname):
- if row < self.GetNumberRows():
- if colname == "Variable":
- return self.data[row].GetVariable()
- elif colname == "Value":
- return self.data[row].GetValue()
- return ""
-
- def SetValueByName(self, row, colname, value):
- if row < self.GetNumberRows():
- if colname == "Variable":
- self.data[row].SetVariable(value)
- elif colname == "Value":
- self.data[row].SetValue(value)
-
- def IsForced(self, row):
- if row < self.GetNumberRows():
- return self.data[row].IsForced()
- return False
-
- def _updateColAttrs(self, grid):
- """
- wx.grid.Grid -> update the column attributes to add the
- appropriate renderer given the column name.
-
- Otherwise default to the default renderer.
- """
-
- for row in range(self.GetNumberRows()):
- for col in range(self.GetNumberCols()):
- if self.GetColLabelValue(col, False) == "Value":
- if self.IsForced(row):
- grid.SetCellTextColour(row, col, wx.BLUE)
- else:
- grid.SetCellTextColour(row, col, wx.BLACK)
- grid.SetReadOnly(row, col, True)
- self.ResizeRow(grid, row)
-
- def AppendItem(self, data):
- self.data.append(data)
-
- def InsertItem(self, idx, data):
- self.data.insert(idx, data)
-
- def RemoveItem(self, idx):
- self.data.pop(idx)
-
- def MoveItem(self, idx, new_idx):
- self.data.insert(new_idx, self.data.pop(idx))
-
- def GetItem(self, idx):
- return self.data[idx]
-
-
-class DebugVariableDropTarget(wx.TextDropTarget):
-
- def __init__(self, parent):
- wx.TextDropTarget.__init__(self)
- self.ParentWindow = parent
-
- def OnDropText(self, x, y, data):
- x, y = self.ParentWindow.VariablesGrid.CalcUnscrolledPosition(x, y)
- row = self.ParentWindow.VariablesGrid.YToRow(y - self.ParentWindow.VariablesGrid.GetColLabelSize())
- if row == wx.NOT_FOUND:
- row = self.ParentWindow.Table.GetNumberRows()
- message = None
- try:
- values = eval(data)
- except:
- message = _("Invalid value \"%s\" for debug variable")%data
- values = None
- if not isinstance(values, TupleType):
- message = _("Invalid value \"%s\" for debug variable")%data
- values = None
- if values is not None and values[1] == "debug":
- self.ParentWindow.InsertValue(values[0], row)
- if message is not None:
- wx.CallAfter(self.ShowMessage, message)
-
- def ShowMessage(self, message):
- message = wx.MessageDialog(self.ParentWindow, message, _("Error"), wx.OK|wx.ICON_ERROR)
- message.ShowModal()
- message.Destroy()
-
-[ID_DEBUGVARIABLEPANEL, ID_DEBUGVARIABLEPANELVARIABLESGRID,
- ID_DEBUGVARIABLEPANELUPBUTTON, ID_DEBUGVARIABLEPANELDOWNBUTTON,
- ID_DEBUGVARIABLEPANELDELETEBUTTON,
-] = [wx.NewId() for _init_ctrls in range(5)]
-
-class DebugVariablePanel(wx.Panel, DebugViewer):
-
- if wx.VERSION < (2, 6, 0):
- def Bind(self, event, function, id = None):
- if id is not None:
- event(self, id, function)
- else:
- event(self, function)
-
- def _init_coll_MainSizer_Items(self, parent):
- parent.AddSizer(self.ButtonPanelSizer, 0, border=5, flag=wx.ALIGN_RIGHT|wx.ALL)
- parent.AddWindow(self.VariablesGrid, 0, border=0, flag=wx.GROW)
-
- def _init_coll_MainSizer_Growables(self, parent):
- parent.AddGrowableCol(0)
- parent.AddGrowableRow(1)
-
- def _init_coll_ButtonPanelSizer_Items(self, parent):
- parent.AddWindow(self.UpButton, 0, border=5, flag=wx.RIGHT)
- parent.AddWindow(self.DownButton, 0, border=5, flag=wx.RIGHT)
- parent.AddWindow(self.DeleteButton, 0, border=0, flag=0)
-
- def _init_sizers(self):
- self.MainSizer = wx.FlexGridSizer(cols=1, hgap=10, rows=2, vgap=0)
- self.ButtonPanelSizer = wx.BoxSizer(wx.HORIZONTAL)
-
- self._init_coll_MainSizer_Items(self.MainSizer)
- self._init_coll_MainSizer_Growables(self.MainSizer)
- self._init_coll_ButtonPanelSizer_Items(self.ButtonPanelSizer)
-
- self.SetSizer(self.MainSizer)
-
- def _init_ctrls(self, prnt):
- wx.Panel.__init__(self, id=ID_DEBUGVARIABLEPANEL,
- name='DebugVariablePanel', parent=prnt, pos=wx.Point(0, 0),
- size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL)
-
- self.VariablesGrid = CustomGrid(id=ID_DEBUGVARIABLEPANELVARIABLESGRID,
- name='VariablesGrid', parent=self, pos=wx.Point(0, 0),
- size=wx.Size(0, 150), style=wx.VSCROLL)
- self.VariablesGrid.SetDropTarget(DebugVariableDropTarget(self))
- if wx.VERSION >= (2, 6, 0):
- self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_RIGHT_CLICK, self.OnVariablesGridCellRightClick)
- else:
- wx.grid.EVT_GRID_CELL_RIGHT_CLICK(self.VariablesGrid, self.OnVariablesGridCellRightClick)
-
- self.UpButton = wx.Button(id=ID_DEBUGVARIABLEPANELUPBUTTON, label='^',
- name='UpButton', parent=self, pos=wx.Point(0, 0),
- size=wx.Size(32, 32), style=0)
-
- self.DownButton = wx.Button(id=ID_DEBUGVARIABLEPANELDOWNBUTTON, label='v',
- name='DownButton', parent=self, pos=wx.Point(0, 0),
- size=wx.Size(32, 32), style=0)
-
- self.DeleteButton = wx.Button(id=ID_DEBUGVARIABLEPANELDELETEBUTTON, label=_('Delete'),
- name='DeleteButton', parent=self, pos=wx.Point(0, 0),
- size=wx.DefaultSize, style=0)
-
- self._init_sizers()
-
- def __init__(self, parent, producer):
- self._init_ctrls(parent)
- DebugViewer.__init__(self, producer, True)
- self.HasNewData = False
-
- self.Table = DebugVariableTable(self, [], GetDebugVariablesTableColnames())
- self.VariablesGrid.SetTable(self.Table)
- self.VariablesGrid.SetButtons({"Delete": self.DeleteButton,
- "Up": self.UpButton,
- "Down": self.DownButton})
-
- def _AddVariable(new_row):
- return self.VariablesGrid.GetGridCursorRow()
- setattr(self.VariablesGrid, "_AddRow", _AddVariable)
-
- def _DeleteVariable(row):
- item = self.Table.GetItem(row)
- self.RemoveDataConsumer(item)
- self.Table.RemoveItem(row)
- self.RefreshGrid()
- setattr(self.VariablesGrid, "_DeleteRow", _DeleteVariable)
-
- def _MoveVariable(row, move):
- new_row = max(0, min(row + move, self.Table.GetNumberRows() - 1))
- if new_row != row:
- self.Table.MoveItem(row, new_row)
- self.RefreshGrid()
- return new_row
- setattr(self.VariablesGrid, "_MoveRow", _MoveVariable)
-
- self.VariablesGrid.SetRowLabelSize(0)
-
- for col in range(self.Table.GetNumberCols()):
- attr = wx.grid.GridCellAttr()
- attr.SetAlignment(wx.ALIGN_RIGHT, wx.ALIGN_CENTER)
- self.VariablesGrid.SetColAttr(col, attr)
- self.VariablesGrid.SetColSize(col, 100)
-
- self.Table.ResetView(self.VariablesGrid)
- self.VariablesGrid.RefreshButtons()
-
- def RefreshNewData(self):
- if self.HasNewData:
- self.HasNewData = False
- self.RefreshGrid()
- DebugViewer.RefreshNewData(self)
-
- def RefreshGrid(self):
- self.Freeze()
- self.Table.ResetView(self.VariablesGrid)
- self.VariablesGrid.RefreshButtons()
- self.Thaw()
-
- def UnregisterObsoleteData(self):
- items = [(idx, item) for idx, item in enumerate(self.Table.GetData())]
- items.reverse()
- for idx, item in items:
- iec_path = item.GetVariable().upper()
- if self.GetDataType(iec_path) is None:
- self.RemoveDataConsumer(item)
- self.Table.RemoveItem(idx)
- else:
- self.AddDataConsumer(iec_path, item)
- self.Freeze()
- self.Table.ResetView(self.VariablesGrid)
- self.VariablesGrid.RefreshButtons()
- self.Thaw()
-
- def ResetGrid(self):
- self.DeleteDataConsumers()
- self.Table.Empty()
- self.Freeze()
- self.Table.ResetView(self.VariablesGrid)
- self.VariablesGrid.RefreshButtons()
- self.Thaw()
-
- def GetForceVariableMenuFunction(self, iec_path, item):
- iec_type = self.GetDataType(iec_path)
- def ForceVariableFunction(event):
- if iec_type is not None:
- dialog = ForceVariableDialog(self, iec_type, str(item.GetValue()))
- if dialog.ShowModal() == wx.ID_OK:
- self.ForceDataValue(iec_path, dialog.GetValue())
- return ForceVariableFunction
-
- def GetReleaseVariableMenuFunction(self, iec_path):
- def ReleaseVariableFunction(event):
- self.ReleaseDataValue(iec_path)
- return ReleaseVariableFunction
-
- def OnVariablesGridCellRightClick(self, event):
- row, col = event.GetRow(), event.GetCol()
- if self.Table.GetColLabelValue(col, False) == "Value":
- iec_path = self.Table.GetValueByName(row, "Variable").upper()
-
- menu = wx.Menu(title='')
- new_id = wx.NewId()
- AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Force value"))
- self.Bind(wx.EVT_MENU, self.GetForceVariableMenuFunction(iec_path.upper(), self.Table.GetItem(row)), id=new_id)
- new_id = wx.NewId()
- AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Release value"))
- self.Bind(wx.EVT_MENU, self.GetReleaseVariableMenuFunction(iec_path.upper()), id=new_id)
- if self.Table.IsForced(row):
- menu.Enable(new_id, True)
- else:
- menu.Enable(new_id, False)
- self.PopupMenu(menu)
- menu.Destroy()
- event.Skip()
-
- def InsertValue(self, iec_path, idx = None, force=False):
- if idx is None:
- idx = self.Table.GetNumberRows()
- for item in self.Table.GetData():
- if iec_path == item.GetVariable():
- return
- item = VariableTableItem(self, iec_path, "")
- result = self.AddDataConsumer(iec_path.upper(), item)
- if result is not None or force:
- self.Table.InsertItem(idx, item)
- self.RefreshGrid()
-
- def GetDebugVariables(self):
- return [item.GetVariable() for item in self.Table.GetData()]
-
#-------------------------------------------------------------------------------
# Viewer Printout
#-------------------------------------------------------------------------------
diff -r 365bb7496697 -r 5f6a743dcde5 controls/DebugVariablePanel.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/controls/DebugVariablePanel.py Thu Jun 14 18:13:32 2012 +0200
@@ -0,0 +1,316 @@
+#!/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) 2012: 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
+
+import wx
+
+from graphics import DebugDataConsumer, DebugViewer
+from controls import CustomGrid, CustomTable
+
+def GetDebugVariablesTableColnames():
+ _ = lambda x : x
+ return [_("Variable"), _("Value")]
+
+class VariableTableItem(DebugDataConsumer):
+
+ def __init__(self, parent, variable, value):
+ DebugDataConsumer.__init__(self)
+ self.Parent = parent
+ self.Variable = variable
+ self.Value = value
+
+ def __del__(self):
+ self.Parent = None
+
+ def SetVariable(self, variable):
+ if self.Parent and self.Variable != variable:
+ self.Variable = variable
+ self.Parent.RefreshGrid()
+
+ def GetVariable(self):
+ return self.Variable
+
+ def SetForced(self, forced):
+ if self.Forced != forced:
+ self.Forced = forced
+ self.Parent.HasNewData = True
+
+ def SetValue(self, value):
+ if self.Value != value:
+ self.Value = value
+ self.Parent.HasNewData = True
+
+ def GetValue(self):
+ return self.Value
+
+class DebugVariableTable(CustomTable):
+
+ def GetValue(self, row, col):
+ if row < self.GetNumberRows():
+ return self.GetValueByName(row, self.GetColLabelValue(col, False))
+ return ""
+
+ def SetValue(self, row, col, value):
+ if col < len(self.colnames):
+ self.SetValueByName(row, self.GetColLabelValue(col, False), value)
+
+ def GetValueByName(self, row, colname):
+ if row < self.GetNumberRows():
+ if colname == "Variable":
+ return self.data[row].GetVariable()
+ elif colname == "Value":
+ return self.data[row].GetValue()
+ return ""
+
+ def SetValueByName(self, row, colname, value):
+ if row < self.GetNumberRows():
+ if colname == "Variable":
+ self.data[row].SetVariable(value)
+ elif colname == "Value":
+ self.data[row].SetValue(value)
+
+ def IsForced(self, row):
+ if row < self.GetNumberRows():
+ return self.data[row].IsForced()
+ return False
+
+ def _updateColAttrs(self, grid):
+ """
+ wx.grid.Grid -> update the column attributes to add the
+ appropriate renderer given the column name.
+
+ Otherwise default to the default renderer.
+ """
+
+ for row in range(self.GetNumberRows()):
+ for col in range(self.GetNumberCols()):
+ if self.GetColLabelValue(col, False) == "Value":
+ if self.IsForced(row):
+ grid.SetCellTextColour(row, col, wx.BLUE)
+ else:
+ grid.SetCellTextColour(row, col, wx.BLACK)
+ grid.SetReadOnly(row, col, True)
+ self.ResizeRow(grid, row)
+
+ def AppendItem(self, data):
+ self.data.append(data)
+
+ def InsertItem(self, idx, data):
+ self.data.insert(idx, data)
+
+ def RemoveItem(self, idx):
+ self.data.pop(idx)
+
+ def MoveItem(self, idx, new_idx):
+ self.data.insert(new_idx, self.data.pop(idx))
+
+ def GetItem(self, idx):
+ return self.data[idx]
+
+class DebugVariableDropTarget(wx.TextDropTarget):
+
+ def __init__(self, parent):
+ wx.TextDropTarget.__init__(self)
+ self.ParentWindow = parent
+
+ def OnDropText(self, x, y, data):
+ x, y = self.ParentWindow.VariablesGrid.CalcUnscrolledPosition(x, y)
+ row = self.ParentWindow.VariablesGrid.YToRow(y - self.ParentWindow.VariablesGrid.GetColLabelSize())
+ if row == wx.NOT_FOUND:
+ row = self.ParentWindow.Table.GetNumberRows()
+ message = None
+ try:
+ values = eval(data)
+ except:
+ message = _("Invalid value \"%s\" for debug variable")%data
+ values = None
+ if not isinstance(values, TupleType):
+ message = _("Invalid value \"%s\" for debug variable")%data
+ values = None
+ if values is not None and values[1] == "debug":
+ self.ParentWindow.InsertValue(values[0], row)
+ if message is not None:
+ wx.CallAfter(self.ShowMessage, message)
+
+ def ShowMessage(self, message):
+ dialog = wx.MessageDialog(self.ParentWindow, message, _("Error"), wx.OK|wx.ICON_ERROR)
+ dialog.ShowModal()
+ dialog.Destroy()
+
+class DebugVariablePanel(wx.Panel, DebugViewer):
+
+ def __init__(self, parent, window, producer):
+ wx.Panel.__init__(self, parent, style=wx.TAB_TRAVERSAL)
+ DebugViewer.__init__(self, producer, True)
+
+ main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0)
+ main_sizer.AddGrowableCol(0)
+ main_sizer.AddGrowableRow(1)
+
+ button_sizer = wx.BoxSizer(wx.HORIZONTAL)
+ main_sizer.AddSizer(button_sizer, border=5,
+ flag=wx.ALIGN_RIGHT|wx.ALL)
+
+ up_button = wx.Button(self, label='^', size=wx.Size(28, 28))
+ button_sizer.AddWindow(up_button, border=5, flag=wx.RIGHT)
+
+ down_button = wx.Button(self, label='v', size=wx.Size(28, 28))
+ button_sizer.AddWindow(down_button, border=5, flag=wx.RIGHT)
+
+ delete_button = wx.Button(self, label=_('Delete'), size=wx.DefaultSize)
+ button_sizer.AddWindow(delete_button)
+
+ self.VariablesGrid = CustomGrid(self, size=wx.Size(0, 150), style=wx.VSCROLL)
+ self.VariablesGrid.SetDropTarget(DebugVariableDropTarget(self))
+ self.VariablesGrid.Bind(wx.grid.EVT_GRID_CELL_RIGHT_CLICK,
+ self.OnVariablesGridCellRightClick)
+ main_sizer.AddWindow(self.VariablesGrid, flag=wx.GROW)
+
+ self.SetSizer(main_sizer)
+
+ self.HasNewData = False
+
+ self.Table = DebugVariableTable(self, [], GetDebugVariablesTableColnames())
+ self.VariablesGrid.SetTable(self.Table)
+ self.VariablesGrid.SetButtons({"Delete": delete_button,
+ "Up": up_button,
+ "Down": down_button})
+
+ def _AddVariable(new_row):
+ return self.VariablesGrid.GetGridCursorRow()
+ setattr(self.VariablesGrid, "_AddRow", _AddVariable)
+
+ def _DeleteVariable(row):
+ item = self.Table.GetItem(row)
+ self.RemoveDataConsumer(item)
+ self.Table.RemoveItem(row)
+ self.RefreshGrid()
+ setattr(self.VariablesGrid, "_DeleteRow", _DeleteVariable)
+
+ def _MoveVariable(row, move):
+ new_row = max(0, min(row + move, self.Table.GetNumberRows() - 1))
+ if new_row != row:
+ self.Table.MoveItem(row, new_row)
+ self.RefreshGrid()
+ return new_row
+ setattr(self.VariablesGrid, "_MoveRow", _MoveVariable)
+
+ self.VariablesGrid.SetRowLabelSize(0)
+
+ for col in range(self.Table.GetNumberCols()):
+ attr = wx.grid.GridCellAttr()
+ attr.SetAlignment(wx.ALIGN_RIGHT, wx.ALIGN_CENTER)
+ self.VariablesGrid.SetColAttr(col, attr)
+ self.VariablesGrid.SetColSize(col, 100)
+
+ self.Table.ResetView(self.VariablesGrid)
+ self.VariablesGrid.RefreshButtons()
+
+ def RefreshNewData(self):
+ if self.HasNewData:
+ self.HasNewData = False
+ self.RefreshGrid()
+ DebugViewer.RefreshNewData(self)
+
+ def RefreshGrid(self):
+ self.Freeze()
+ self.Table.ResetView(self.VariablesGrid)
+ self.VariablesGrid.RefreshButtons()
+ self.Thaw()
+
+ def UnregisterObsoleteData(self):
+ items = [(idx, item) for idx, item in enumerate(self.Table.GetData())]
+ items.reverse()
+ for idx, item in items:
+ iec_path = item.GetVariable().upper()
+ if self.GetDataType(iec_path) is None:
+ self.RemoveDataConsumer(item)
+ self.Table.RemoveItem(idx)
+ else:
+ self.AddDataConsumer(iec_path, item)
+ self.Freeze()
+ self.Table.ResetView(self.VariablesGrid)
+ self.VariablesGrid.RefreshButtons()
+ self.Thaw()
+
+ def ResetGrid(self):
+ self.DeleteDataConsumers()
+ self.Table.Empty()
+ self.Freeze()
+ self.Table.ResetView(self.VariablesGrid)
+ self.VariablesGrid.RefreshButtons()
+ self.Thaw()
+
+ def GetForceVariableMenuFunction(self, iec_path, item):
+ iec_type = self.GetDataType(iec_path)
+ def ForceVariableFunction(event):
+ if iec_type is not None:
+ dialog = ForceVariableDialog(self, iec_type, str(item.GetValue()))
+ if dialog.ShowModal() == wx.ID_OK:
+ self.ForceDataValue(iec_path, dialog.GetValue())
+ return ForceVariableFunction
+
+ def GetReleaseVariableMenuFunction(self, iec_path):
+ def ReleaseVariableFunction(event):
+ self.ReleaseDataValue(iec_path)
+ return ReleaseVariableFunction
+
+ def OnVariablesGridCellRightClick(self, event):
+ row, col = event.GetRow(), event.GetCol()
+ if self.Table.GetColLabelValue(col, False) == "Value":
+ iec_path = self.Table.GetValueByName(row, "Variable").upper()
+
+ menu = wx.Menu(title='')
+
+ new_id = wx.NewId()
+ AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Force value"))
+ self.Bind(wx.EVT_MENU, self.GetForceVariableMenuFunction(iec_path.upper(), self.Table.GetItem(row)), id=new_id)
+
+ new_id = wx.NewId()
+ AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=_("Release value"))
+ self.Bind(wx.EVT_MENU, self.GetReleaseVariableMenuFunction(iec_path.upper()), id=new_id)
+
+ if self.Table.IsForced(row):
+ menu.Enable(new_id, True)
+ else:
+ menu.Enable(new_id, False)
+
+ self.PopupMenu(menu)
+
+ menu.Destroy()
+ event.Skip()
+
+ def InsertValue(self, iec_path, idx = None, force=False):
+ if idx is None:
+ idx = self.Table.GetNumberRows()
+ for item in self.Table.GetData():
+ if iec_path == item.GetVariable():
+ return
+ item = VariableTableItem(self, iec_path, "")
+ result = self.AddDataConsumer(iec_path.upper(), item)
+ if result is not None or force:
+ self.Table.InsertItem(idx, item)
+ self.RefreshGrid()
+
+ def GetDebugVariables(self):
+ return [item.GetVariable() for item in self.Table.GetData()]
diff -r 365bb7496697 -r 5f6a743dcde5 controls/ProjectPropertiesPanel.py
--- a/controls/ProjectPropertiesPanel.py Mon Jun 11 01:30:03 2012 +0200
+++ b/controls/ProjectPropertiesPanel.py Thu Jun 14 18:13:32 2012 +0200
@@ -353,7 +353,6 @@
new_value = self.Language.GetStringSelection()
if new_value == "":
new_value = None
- print old_value, new_value
if old_value != new_value:
self.Controller.SetProjectProperties(properties={"language": new_value})
self.ParentWindow.RefreshTitle()
diff -r 365bb7496697 -r 5f6a743dcde5 controls/__init__.py
--- a/controls/__init__.py Mon Jun 11 01:30:03 2012 +0200
+++ b/controls/__init__.py Thu Jun 14 18:13:32 2012 +0200
@@ -28,6 +28,7 @@
from CustomGrid import CustomGrid
from CustomTable import CustomTable
from CustomTree import CustomTree
+from DebugVariablePanel import DebugVariablePanel
from DurationCellEditor import DurationCellEditor
from EditorPanel import EditorPanel
from LibraryPanel import LibraryPanel