Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
authorlaurent
Tue, 27 Mar 2012 23:57:51 +0200
changeset 660 30c0371ac086
parent 659 46c3d5410888
child 661 7891872e6fd7
Adding zoom and navigation in GraphicViewer and ToolBar containing basic menu items
GraphicViewer.py
PLCOpenEditor.py
--- a/GraphicViewer.py	Tue Mar 27 23:55:10 2012 +0200
+++ b/GraphicViewer.py	Tue Mar 27 23:57:51 2012 +0200
@@ -25,7 +25,8 @@
 import wx
 import wx.lib.plot as plot
 import numpy
-from graphics.GraphicCommons import DebugViewer
+import math
+from graphics.GraphicCommons import DebugViewer, MODE_SELECTION, MODE_MOTION
 from controls import EditorPanel
 
 colours = ['blue', 'red', 'green', 'yellow', 'orange', 'purple', 'brown', 'cyan',
@@ -41,16 +42,18 @@
 MINUTE = 60 * SECOND
 HOUR = 60 * MINUTE
 
-RANGE_VALUES = [(str(25 * 2 ** i), 25 * 2 ** i) for i in xrange(6)]
+ZOOM_VALUES = map(lambda x:("x %.1f" % x, x), [math.sqrt(2) ** i for i in xrange(8)])
+RANGE_VALUES = map(lambda x: (str(x), x), [25 * 2 ** i for i in xrange(6)])
 TIME_RANGE_VALUES = [("%ds" % i, i * SECOND) for i in (1, 2, 5, 10, 20, 30)] + \
                     [("%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_GRAPHICVIEWERCANVASPOSITION,
- ID_GRAPHICVIEWERRESETBUTTON, ID_GRAPHICVIEWERCURRENTBUTTON, 
- ID_GRAPHICVIEWERSTATICTEXT1, ID_GRAPHICVIEWERSTATICTEXT2,
-] = [wx.NewId() for _init_ctrls in range(8)]
+[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):
 
@@ -68,6 +71,8 @@
         # 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)
@@ -81,7 +86,7 @@
     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=6, hgap=0, rows=1, 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)
@@ -108,7 +113,11 @@
                 return plot.PlotCanvas._axisInterval(self.Canvas, spec, lower, upper)
         self.Canvas._axisInterval = _axisInterval
         self.Canvas.SetYSpec('border')
-
+        self.Canvas.canvas.Bind(wx.EVT_LEFT_DOWN, self.OnCanvasLeftDown)
+        self.Canvas.canvas.Bind(wx.EVT_LEFT_UP, self.OnCanvasLeftUp)
+        self.Canvas.canvas.Bind(wx.EVT_MOTION, self.OnCanvasMotion)
+        self.Canvas.canvas.Bind(wx.EVT_MOUSEWHEEL, self.OnCanvasMouseWheel)
+        
         self.staticbox1 = wx.StaticText(id=ID_GRAPHICVIEWERSTATICTEXT1,
               label=_('Range:'), name='staticText1', parent=self.Editor,
               pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
@@ -118,6 +127,15 @@
               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),
+              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)
@@ -155,14 +173,32 @@
         
         self.InstancePath = instancepath
         self.RangeValues = None
+        self.CursorIdx = None
+        self.LastCursor = None
+        self.CurrentMousePos = None
+        self.CurrentMotionValue = None
+        self.Dragging = False
+        
+        # Initialize Viewer mode to Selection mode
+        self.Mode = MODE_SELECTION
         
         self.Datas = []
-        self.StartValue = 0
-        self.EndValue = 0
+        self.StartTick = 0
+        self.EndTick = 0
+        self.StartIdx = 0
+        self.EndIdx = 0
+        self.MinValue = None
+        self.MaxValue = None
+        self.YCenter = 0
+        self.CurrentZoom = 1
         self.Fixed = False
         self.Ticktime = self.DataProducer.GetTicktime()
         self.RefreshCanvasRange()
         
+        for zoom_txt, zoom in ZOOM_VALUES:
+            self.CanvasZoom.Append(zoom_txt)
+        self.CanvasZoom.SetSelection(0)
+        
         self.AddDataConsumer(self.InstancePath.upper(), self)
     
     def __del__(self):
@@ -174,12 +210,25 @@
             return "..." + self.InstancePath[-12:]
         return self.InstancePath
     
-    def ResetView(self):
+    # Changes Viewer mode
+    def SetMode(self, mode):
+        if self.Mode != mode or mode == MODE_SELECTION:    
+            if self.Mode == MODE_MOTION:
+                wx.CallAfter(self.Canvas.canvas.SetCursor, wx.NullCursor)
+            self.Mode = mode
+        if self.Mode == MODE_MOTION:
+            wx.CallAfter(self.Canvas.canvas.SetCursor, wx.StockCursor(wx.CURSOR_HAND))
+        
+    def ResetView(self, register=False):
         self.Datas = []
-        self.StartValue = 0
-        self.EndValue = 0
+        self.StartTick = 0
+        self.EndTick = 0
+        self.StartIdx = 0
+        self.EndIdx = 0
         self.Fixed = False
         self.Ticktime = self.DataProducer.GetTicktime()
+        if register:
+            self.AddDataConsumer(self.InstancePath.upper(), self)
         self.RefreshCanvasRange()
         self.RefreshView()
     
@@ -187,47 +236,6 @@
         self.RefreshView(*args, **kwargs)
         DebugViewer.RefreshNewData(self)
     
-    def RefreshCanvasRange(self):
-        if self.Ticktime == 0 and self.RangeValues != RANGE_VALUES:
-            self.RangeValues = RANGE_VALUES
-            self.RangeValues_dict = dict(RANGE_VALUES)
-            self.CanvasRange.Clear()
-            for text, value in RANGE_VALUES:
-                self.CanvasRange.Append(text)
-            self.CanvasRange.SetStringSelection(RANGE_VALUES[0][0])
-            self.CurrentRange = RANGE_VALUES[0][1]
-        elif self.RangeValues != TIME_RANGE_VALUES:
-            self.RangeValues = TIME_RANGE_VALUES
-            self.RangeValues_dict = dict(TIME_RANGE_VALUES)
-            self.CanvasRange.Clear()
-            for text, value in TIME_RANGE_VALUES:
-                self.CanvasRange.Append(text)
-            self.CanvasRange.SetStringSelection(TIME_RANGE_VALUES[0][0])
-            self.CurrentRange = TIME_RANGE_VALUES[0][1] / self.Ticktime
-        
-    def RefreshView(self, force=True):
-        self.Freeze()
-        if force or not self.Fixed:
-            var_name = self.InstancePath.split(".")[-1]
-            
-            self.VariableGraphic = plot.PolyLine(self.Datas[self.StartValue:self.EndValue + 1], 
-                                                 legend=var_name, colour=colours[0])
-            self.GraphicsObject = plot.PlotGraphics([self.VariableGraphic], _("%s Graphics") % var_name, _("Tick"), _("Values"))
-            datas_length = len(self.Datas)
-            if datas_length > 1:
-                start = self.Datas[self.StartValue][0]
-            else:
-                start = 0.
-            self.Canvas.Draw(self.GraphicsObject, xAxis=(start, start + self.CurrentRange))
-        self.RefreshScrollBar()
-        self.Thaw()
-    
-    def GetInstancePath(self):
-        return self.InstancePath
-    
-    def IsViewing(self, tagname):
-        return self.InstancePath == tagname
-    
     def GetNearestData(self, tick, adjust):
         ticks = numpy.array(zip(*self.Datas)[0])
         new_cursor = numpy.argmin(abs(ticks - tick))
@@ -237,60 +245,269 @@
             new_cursor += 1
         return new_cursor
     
+    def GetBounds(self):
+        if self.StartIdx is None or self.EndIdx is None:
+            self.StartIdx = self.GetNearestData(self.StartTick, -1)
+            self.EndIdx = self.GetNearestData(self.EndTick, 1)
+    
+    def ResetBounds(self):
+        self.StartIdx = None
+        self.EndIdx = None
+    
+    def RefreshCanvasRange(self):
+        if self.Ticktime == 0 and self.RangeValues != RANGE_VALUES:
+            self.RangeValues = RANGE_VALUES
+            self.CanvasRange.Clear()
+            for text, value in RANGE_VALUES:
+                self.CanvasRange.Append(text)
+            self.CanvasRange.SetStringSelection(RANGE_VALUES[0][0])
+            self.CurrentRange = RANGE_VALUES[0][1]
+        elif self.RangeValues != TIME_RANGE_VALUES:
+            self.RangeValues = TIME_RANGE_VALUES
+            self.CanvasRange.Clear()
+            for text, value in TIME_RANGE_VALUES:
+                self.CanvasRange.Append(text)
+            self.CanvasRange.SetStringSelection(TIME_RANGE_VALUES[0][0])
+            self.CurrentRange = TIME_RANGE_VALUES[0][1] / self.Ticktime
+        
+    def RefreshView(self, force=True):
+        self.Freeze()
+        if force or not self.Fixed:
+            if (self.MinValue is not None and 
+                self.MaxValue is not None and 
+                self.MinValue != self.MaxValue):
+                Yrange = float(self.MaxValue - self.MinValue) / self.CurrentZoom
+            else:
+                Yrange = 2. / self.CurrentZoom
+            
+            if not self.Fixed and len(self.Datas) > 0:
+                self.YCenter = max(self.Datas[-1][1] - Yrange / 2, 
+                               min(self.YCenter, 
+                                   self.Datas[-1][1] + Yrange / 2))
+            
+            var_name = self.InstancePath.split(".")[-1]
+            
+            self.GetBounds()
+            self.VariableGraphic = plot.PolyLine(self.Datas[self.StartIdx:self.EndIdx + 1], 
+                                                 legend=var_name, colour=colours[0])
+            self.GraphicsObject = plot.PlotGraphics([self.VariableGraphic], _("%s Graphics") % var_name, _("Tick"), _("Values"))
+            datas_length = len(self.Datas)
+            if datas_length > 1:
+                start = self.Datas[self.StartIdx][0]
+            else:
+                start = 0.
+            self.Canvas.Draw(self.GraphicsObject, 
+                             xAxis=(start, start + self.CurrentRange),
+                             yAxis=(self.YCenter - Yrange * 1.1 / 2, self.YCenter + Yrange * 1.1 / 2))
+        self.RefreshScrollBar()
+        
+        # Reset and draw cursor 
+        self.ResetLastCursor()
+        self.RefreshCursor()
+        
+        self.Thaw()
+    
+    def GetInstancePath(self):
+        return self.InstancePath
+    
+    def IsViewing(self, tagname):
+        return self.InstancePath == tagname
+    
     def NewValue(self, tick, value, forced=False):
         self.Datas.append((float(tick), {True:1., False:0.}.get(value, float(value))))
+        if self.MinValue is None:
+            self.MinValue = value
+        else:
+            self.MinValue = min(self.MinValue, value)
+        if self.MaxValue is None:
+            self.MaxValue = value
+        else:
+            self.MaxValue = max(self.MaxValue, value)
         if not self.Fixed:
-            while int(self.Datas[self.StartValue][0]) < tick - self.CurrentRange:
-                self.StartValue += 1
-            self.EndValue += 1
+            self.GetBounds()
+            while int(self.Datas[self.StartIdx][0]) < tick - self.CurrentRange:
+                self.StartIdx += 1
+            self.EndIdx += 1
+            self.StartTick = self.Datas[self.StartIdx][0]
+            self.EndTick = self.StartTick + self.CurrentRange
         self.NewDataAvailable()
     
     def RefreshScrollBar(self):
         if len(self.Datas) > 0:
-            pos = int(self.Datas[self.StartValue][0] - self.Datas[0][0])
+            self.GetBounds()
+            pos = int(self.Datas[self.StartIdx][0] - self.Datas[0][0])
             range = int(self.Datas[-1][0] - self.Datas[0][0])
         else:
             pos = 0
             range = 0
         self.CanvasPosition.SetScrollbar(pos, self.CurrentRange, range, self.CurrentRange)
 
-    def OnRangeChanged(self, event):
-        old_range = self.CurrentRange
-        try:
-            if self.Ticktime == 0:
-                self.CurrentRange = self.RangeValues_dict[self.CanvasRange.GetValue()]
-            else:
-                self.CurrentRange = self.RangeValues_dict[self.CanvasRange.GetValue()] / self.Ticktime
-        except ValueError, e:
-            self.CanvasRange.SetValue(str(self.CurrentRange))
+    def RefreshRange(self):
         if len(self.Datas) > 0:
             if self.Fixed and self.Datas[-1][0] - self.Datas[0][0] < self.CurrentRange:
                 self.Fixed = False
+            self.ResetBounds()
             if self.Fixed:
-                self.StartValue = min(self.StartValue, self.GetNearestData(self.Datas[-1][0] - self.CurrentRange, -1))
-                self.EndValue = self.GetNearestData(self.StartValue + self.CurrentRange, 1)
+                self.StartTick = min(self.StartTick, self.Datas[-1][0] - self.CurrentRange)
             else:
-                self.StartValue = self.GetNearestData(self.Datas[-1][0] - self.CurrentRange - 1, -1)
-                self.EndValue = len(self.Datas) - 1
+                self.StartTick = max(self.Datas[0][0], self.EndTick - self.CurrentRange - 1)
+            self.EndTick = self.StartTick + self.CurrentRange
         self.NewDataAvailable(True)
+
+    def OnRangeChanged(self, event):
+        try:
+            if self.Ticktime == 0:
+                self.CurrentRange = self.RangeValues[self.CanvasRange.GetSelection()][1]
+            else:
+                self.CurrentRange = self.RangeValues[self.CanvasRange.GetSelection()][1] / self.Ticktime
+        except ValueError, e:
+            self.CanvasRange.SetValue(str(self.CurrentRange))
+        wx.CallAfter(self.RefreshRange)
+        event.Skip()
+    
+    def OnZoomChanged(self, event):
+        self.CurrentZoom = ZOOM_VALUES[self.CanvasZoom.GetSelection()][1]
+        wx.CallAfter(self.NewDataAvailable, True)
         event.Skip()
     
     def OnPositionChanging(self, event):
-        self.StartValue = self.GetNearestData(self.Datas[0][0] + event.GetPosition(), -1)
-        self.EndValue = self.GetNearestData(self.Datas[self.StartValue][0] + self.CurrentRange, 1)
+        self.ResetBounds()
+        self.StartTick = self.Datas[0][0] + event.GetPosition()
+        self.EndTick = self.StartTick + self.CurrentRange
         self.Fixed = True
         self.NewDataAvailable(True)
         event.Skip()
 
     def OnResetButton(self, event):
         self.Fixed = False
-        self.ResteView()
+        self.ResetView()
         event.Skip()
 
     def OnCurrentButton(self, event):
-        self.StartValue = self.GetNearestData(self.Datas[-1][0] - self.CurrentRange, -1)
-        self.EndValue = self.GetNearestData(self.Datas[self.StartValue][0] + self.CurrentRange, 1)
+        self.ResetBounds()
+        self.StartTick = max(self.Datas[0][0], self.Datas[-1][0] - self.CurrentRange)
+        self.EndTick = self.StartTick + self.CurrentRange
         self.Fixed = False
         self.NewDataAvailable(True)
         event.Skip()
 
+    def OnCanvasLeftDown(self, event):
+        self.Fixed = True
+        self.Canvas.canvas.CaptureMouse()
+        if self.Mode == MODE_SELECTION:
+            self.Dragging = True
+            pos = self.Canvas.PositionScreenToUser(event.GetPosition())
+            self.CursorIdx = self.GetNearestData(pos[0], -1)
+            self.RefreshCursor()
+        elif self.Mode == MODE_MOTION:
+            self.GetBounds()
+            self.CurrentMousePos = event.GetPosition()
+            self.CurrentMotionValue = self.Datas[self.StartIdx][0]
+        event.Skip()
+        
+    def OnCanvasLeftUp(self, event):
+        self.Dragging = False
+        if self.Mode == MODE_MOTION:
+            self.CurrentMousePos = None
+            self.CurrentMotionValue = None
+        if self.Canvas.canvas.HasCapture():
+            self.Canvas.canvas.ReleaseMouse()
+        event.Skip()
+        
+    def OnCanvasMotion(self, event):
+        if self.Mode == MODE_SELECTION and self.Dragging:
+            pos = self.Canvas.PositionScreenToUser(event.GetPosition())
+            graphics, xAxis, yAxis = self.Canvas.last_draw
+            self.CursorIdx = self.GetNearestData(max(xAxis[0], min(pos[0], xAxis[1])), -1)
+            self.RefreshCursor()
+        elif self.CurrentMousePos is not None:
+            oldpos = self.Canvas.PositionScreenToUser(self.CurrentMousePos)
+            newpos = self.Canvas.PositionScreenToUser(event.GetPosition())
+            self.CurrentMotionValue += oldpos[0] - newpos[0]
+            self.YCenter += oldpos[1] - newpos[1]
+            self.ResetBounds()
+            self.StartTick = self.CurrentMotionValue
+            self.EndTick = self.StartTick + self.CurrentRange
+            self.CurrentMousePos = event.GetPosition()
+            self.NewDataAvailable(True)
+        event.Skip()
+
+    def OnCanvasMouseWheel(self, event):
+        if self.CurrentMousePos is None:
+            rotation = event.GetWheelRotation() / event.GetWheelDelta()
+            if event.ShiftDown():
+                current = self.CanvasRange.GetSelection()
+                new = max(0, min(current - rotation, len(self.RangeValues) - 1))
+                if new != current:
+                    if self.Ticktime == 0:
+                        self.CurrentRange = self.RangeValues[new][1]
+                    else:
+                        self.CurrentRange = self.RangeValues[new][1] / self.Ticktime
+                    self.CanvasRange.SetStringSelection(self.RangeValues[new][0])
+                    wx.CallAfter(self.RefreshRange)
+            else:
+                current = self.CanvasZoom.GetSelection()
+                new = max(0, min(current - rotation, len(ZOOM_VALUES) - 1))
+                if new != current:
+                    self.CurrentZoom = ZOOM_VALUES[new][1]
+                    self.CanvasZoom.SetStringSelection(ZOOM_VALUES[new][0])
+                    wx.CallAfter(self.NewDataAvailable, True)
+        event.Skip()
+
+    ## Reset the last cursor
+    def ResetLastCursor(self):
+        self.LastCursor = None
+
+    ## Draw the cursor on graphic
+    #  @param dc The draw canvas
+    #  @param cursor The cursor parameters
+    def DrawCursor(self, dc, cursor, value):
+        if self.StartTick <= cursor <= self.EndTick:
+            # Prepare temporary dc for drawing
+            width = self.Canvas._Buffer.GetWidth()
+            height = self.Canvas._Buffer.GetHeight()
+            tmp_Buffer = wx.EmptyBitmap(width, height)
+            dcs = wx.MemoryDC()
+            dcs.SelectObject(tmp_Buffer)
+            dcs.Clear()
+            dcs.BeginDrawing()
+            
+            dcs.SetPen(wx.Pen(wx.RED))
+            dcs.SetBrush(wx.Brush(wx.RED, wx.SOLID))
+            dcs.SetFont(self.Canvas._getFont(self.Canvas._fontSizeAxis))
+            
+            # Calculate clipping region
+            graphics, xAxis, yAxis = self.Canvas.last_draw
+            p1 = numpy.array([xAxis[0], yAxis[0]])
+            p2 = numpy.array([xAxis[1], yAxis[1]])
+            cx, cy, cwidth, cheight = self.Canvas._point2ClientCoord(p1, p2)
+            
+            px, py = self.Canvas.PositionUserToScreen((float(cursor), 0.))
+            
+            # Draw line cross drawing for diaplaying time cursor
+            dcs.DrawLine(px, cy + 1, px, cy + cheight - 1)
+            
+            text = "X:%d\nY:%f"%(cursor, value)
+            w, h = dcs.GetTextExtent(text)
+            # Draw time cursor date
+            dcs.DrawText(text, min(px + 3, cx + cwidth - w), cy + 3)
+            
+            dcs.EndDrawing()
+    
+            #this will erase if called twice
+            dc.Blit(0, 0, width, height, dcs, 0, 0, wx.EQUIV)  #(NOT src) XOR dst
+    
+    ## Refresh the variable cursor.
+    #  @param dc The draw canvas
+    def RefreshCursor(self, dc=None):
+        if dc is None:
+            dc = wx.BufferedDC(wx.ClientDC(self.Canvas.canvas), self.Canvas._Buffer)
+        
+        # Erase previous time cursor if drawn
+        if self.LastCursor is not None:
+            self.DrawCursor(dc, *self.LastCursor)
+        
+        # Draw new time cursor
+        if self.CursorIdx is not None:
+            self.LastCursor = self.Datas[self.CursorIdx]
+            self.DrawCursor(dc, *self.LastCursor)
--- a/PLCOpenEditor.py	Tue Mar 27 23:55:10 2012 +0200
+++ b/PLCOpenEditor.py	Tue Mar 27 23:57:51 2012 +0200
@@ -124,10 +124,8 @@
  ID_PLCOPENEDITORTHIRDSPLITTER, ID_PLCOPENEDITORLIBRARYPANEL, 
  ID_PLCOPENEDITORLIBRARYTREE, ID_PLCOPENEDITORLIBRARYCOMMENT, 
  ID_PLCOPENEDITORTABSOPENED, ID_PLCOPENEDITORTABSOPENED,
- ID_PLCOPENEDITORTOOLBAR, ID_PLCOPENEDITORDEFAULTTOOLBAR, 
- ID_PLCOPENEDITORSFCTOOLBAR, ID_PLCOPENEDITORFBDTOOLBAR, 
- ID_PLCOPENEDITORLDTOOLBAR,
-] = [wx.NewId() for _init_ctrls in range(19)]
+ ID_PLCOPENEDITOREDITORMENUTOOLBAR, ID_PLCOPENEDITOREDITORTOOLBAR, 
+] = [wx.NewId() for _init_ctrls in range(16)]
 
 # Define PLCOpenEditor FileMenu extra items id
 [ID_PLCOPENEDITORFILEMENUGENERATE, 
@@ -142,20 +140,20 @@
 
 
 #-------------------------------------------------------------------------------
-#                            ToolBars definitions
+#                            EditorToolBar definitions
 #-------------------------------------------------------------------------------
 
 # Define PLCOpenEditor Toolbar items id
-[ID_PLCOPENEDITORTOOLBARSELECTION, ID_PLCOPENEDITORTOOLBARCOMMENT,
- ID_PLCOPENEDITORTOOLBARVARIABLE, ID_PLCOPENEDITORTOOLBARBLOCK,
- ID_PLCOPENEDITORTOOLBARCONNECTION, ID_PLCOPENEDITORTOOLBARWIRE,
- ID_PLCOPENEDITORTOOLBARPOWERRAIL, ID_PLCOPENEDITORTOOLBARRUNG,
- ID_PLCOPENEDITORTOOLBARCOIL, ID_PLCOPENEDITORTOOLBARCONTACT,
- ID_PLCOPENEDITORTOOLBARBRANCH, ID_PLCOPENEDITORTOOLBARINITIALSTEP,
- ID_PLCOPENEDITORTOOLBARSTEP, ID_PLCOPENEDITORTOOLBARTRANSITION,
- ID_PLCOPENEDITORTOOLBARACTIONBLOCK, ID_PLCOPENEDITORTOOLBARDIVERGENCE,
- ID_PLCOPENEDITORTOOLBARJUMP, ID_PLCOPENEDITORTOOLBARMOTION, 
-] = [wx.NewId() for _init_coll_DefaultToolBar_Items in range(18)]
+[ID_PLCOPENEDITOREDITORTOOLBARSELECTION, ID_PLCOPENEDITOREDITORTOOLBARCOMMENT,
+ ID_PLCOPENEDITOREDITORTOOLBARVARIABLE, ID_PLCOPENEDITOREDITORTOOLBARBLOCK,
+ ID_PLCOPENEDITOREDITORTOOLBARCONNECTION, ID_PLCOPENEDITOREDITORTOOLBARWIRE,
+ ID_PLCOPENEDITOREDITORTOOLBARPOWERRAIL, ID_PLCOPENEDITOREDITORTOOLBARRUNG,
+ ID_PLCOPENEDITOREDITORTOOLBARCOIL, ID_PLCOPENEDITOREDITORTOOLBARCONTACT,
+ ID_PLCOPENEDITOREDITORTOOLBARBRANCH, ID_PLCOPENEDITOREDITORTOOLBARINITIALSTEP,
+ ID_PLCOPENEDITOREDITORTOOLBARSTEP, ID_PLCOPENEDITOREDITORTOOLBARTRANSITION,
+ ID_PLCOPENEDITOREDITORTOOLBARACTIONBLOCK, ID_PLCOPENEDITOREDITORTOOLBARDIVERGENCE,
+ ID_PLCOPENEDITOREDITORTOOLBARJUMP, ID_PLCOPENEDITOREDITORTOOLBARMOTION, 
+] = [wx.NewId() for _init_coll_DefaultEditorToolBar_Items in range(18)]
 
 # Define behaviour of each Toolbar item according to current POU body type 
 # Informations meaning are in this order:
@@ -165,93 +163,96 @@
 #  - Item callback function name
 #  - Item icon filename
 #  - Item tooltip text
-ToolBarItems = {
+EditorToolBarItems = {
     "FBD" : [(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE,
-              ID_PLCOPENEDITORTOOLBARMOTION, "OnMotionTool",
+              ID_PLCOPENEDITOREDITORTOOLBARMOTION, "OnMotionTool",
               "move.png", _("Move the view")),
              (True, FREEDRAWING_MODE|DRIVENDRAWING_MODE,
-              ID_PLCOPENEDITORTOOLBARCOMMENT, "OnCommentTool",
+              ID_PLCOPENEDITOREDITORTOOLBARCOMMENT, "OnCommentTool",
               "add_comment.png", _("Create a new comment")),
              (True, FREEDRAWING_MODE|DRIVENDRAWING_MODE,
-              ID_PLCOPENEDITORTOOLBARVARIABLE, "OnVariableTool",
+              ID_PLCOPENEDITOREDITORTOOLBARVARIABLE, "OnVariableTool",
               "add_variable.png", _("Create a new variable")),
              (True, FREEDRAWING_MODE|DRIVENDRAWING_MODE,
-              ID_PLCOPENEDITORTOOLBARBLOCK, "OnBlockTool",
+              ID_PLCOPENEDITOREDITORTOOLBARBLOCK, "OnBlockTool",
               "add_block.png", _("Create a new block")),
              (True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, 
-              ID_PLCOPENEDITORTOOLBARCONNECTION, "OnConnectionTool", 
+              ID_PLCOPENEDITOREDITORTOOLBARCONNECTION, "OnConnectionTool", 
               "add_connection.png", _("Create a new connection"))],
     "LD"  : [(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE,
-              ID_PLCOPENEDITORTOOLBARMOTION, "OnMotionTool",
+              ID_PLCOPENEDITOREDITORTOOLBARMOTION, "OnMotionTool",
               "move.png", _("Move the view")),
              (True, FREEDRAWING_MODE, 
-              ID_PLCOPENEDITORTOOLBARCOMMENT, "OnCommentTool", 
+              ID_PLCOPENEDITOREDITORTOOLBARCOMMENT, "OnCommentTool", 
               "add_comment.png", _("Create a new comment")),
              (True, FREEDRAWING_MODE, 
-              ID_PLCOPENEDITORTOOLBARPOWERRAIL, "OnPowerRailTool", 
+              ID_PLCOPENEDITOREDITORTOOLBARPOWERRAIL, "OnPowerRailTool", 
               "add_powerrail.png", _("Create a new power rail")),
              (False, DRIVENDRAWING_MODE, 
-              ID_PLCOPENEDITORTOOLBARRUNG, "OnRungTool", 
+              ID_PLCOPENEDITOREDITORTOOLBARRUNG, "OnRungTool", 
               "add_rung.png", _("Create a new rung")),
              (True, FREEDRAWING_MODE, 
-              ID_PLCOPENEDITORTOOLBARCOIL, "OnCoilTool", 
+              ID_PLCOPENEDITOREDITORTOOLBARCOIL, "OnCoilTool", 
               "add_coil.png", _("Create a new coil")),
              (False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, 
-              ID_PLCOPENEDITORTOOLBARCONTACT, "OnContactTool", 
+              ID_PLCOPENEDITOREDITORTOOLBARCONTACT, "OnContactTool", 
               "add_contact.png", _("Create a new contact")),
              (False, DRIVENDRAWING_MODE, 
-              ID_PLCOPENEDITORTOOLBARBRANCH, "OnBranchTool", 
+              ID_PLCOPENEDITOREDITORTOOLBARBRANCH, "OnBranchTool", 
               "add_branch.png", _("Create a new branch")),
              (True, FREEDRAWING_MODE, 
-              ID_PLCOPENEDITORTOOLBARVARIABLE, "OnVariableTool", 
+              ID_PLCOPENEDITOREDITORTOOLBARVARIABLE, "OnVariableTool", 
               "add_variable.png", _("Create a new variable")),
              (False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, 
-              ID_PLCOPENEDITORTOOLBARBLOCK, "OnBlockTool", 
+              ID_PLCOPENEDITOREDITORTOOLBARBLOCK, "OnBlockTool", 
               "add_block.png", _("Create a new block")),
              (True, FREEDRAWING_MODE, 
-              ID_PLCOPENEDITORTOOLBARCONNECTION, "OnConnectionTool", 
+              ID_PLCOPENEDITOREDITORTOOLBARCONNECTION, "OnConnectionTool", 
               "add_connection.png", _("Create a new connection"))],
     "SFC" : [(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE,
-              ID_PLCOPENEDITORTOOLBARMOTION, "OnMotionTool",
+              ID_PLCOPENEDITOREDITORTOOLBARMOTION, "OnMotionTool",
               "move.png", _("Move the view")),
              (True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, 
-              ID_PLCOPENEDITORTOOLBARCOMMENT, "OnCommentTool", 
+              ID_PLCOPENEDITOREDITORTOOLBARCOMMENT, "OnCommentTool", 
               "add_comment.png", _("Create a new comment")),
              (True, FREEDRAWING_MODE|DRIVENDRAWING_MODE, 
-              ID_PLCOPENEDITORTOOLBARINITIALSTEP, "OnInitialStepTool", 
+              ID_PLCOPENEDITOREDITORTOOLBARINITIALSTEP, "OnInitialStepTool", 
               "add_initial_step.png", _("Create a new initial step")),
              (False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, 
-              ID_PLCOPENEDITORTOOLBARSTEP, "OnStepTool", 
+              ID_PLCOPENEDITOREDITORTOOLBARSTEP, "OnStepTool", 
               "add_step.png", _("Create a new step")),
              (True, FREEDRAWING_MODE, 
-              ID_PLCOPENEDITORTOOLBARTRANSITION, "OnTransitionTool", 
+              ID_PLCOPENEDITOREDITORTOOLBARTRANSITION, "OnTransitionTool", 
               "add_transition.png", _("Create a new transition")),
              (False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, 
-              ID_PLCOPENEDITORTOOLBARACTIONBLOCK, "OnActionBlockTool", 
+              ID_PLCOPENEDITOREDITORTOOLBARACTIONBLOCK, "OnActionBlockTool", 
               "add_action.png", _("Create a new action block")),
              (False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, 
-              ID_PLCOPENEDITORTOOLBARDIVERGENCE, "OnDivergenceTool", 
+              ID_PLCOPENEDITOREDITORTOOLBARDIVERGENCE, "OnDivergenceTool", 
               "add_divergence.png", _("Create a new divergence")),
              (False, FREEDRAWING_MODE|DRIVENDRAWING_MODE, 
-              ID_PLCOPENEDITORTOOLBARJUMP, "OnJumpTool", 
+              ID_PLCOPENEDITOREDITORTOOLBARJUMP, "OnJumpTool", 
               "add_jump.png", _("Create a new jump")),
              (True, FREEDRAWING_MODE, 
-              ID_PLCOPENEDITORTOOLBARVARIABLE, "OnVariableTool", 
+              ID_PLCOPENEDITOREDITORTOOLBARVARIABLE, "OnVariableTool", 
               "add_variable.png", _("Create a new variable")),
              (True, FREEDRAWING_MODE, 
-              ID_PLCOPENEDITORTOOLBARBLOCK, "OnBlockTool", 
+              ID_PLCOPENEDITOREDITORTOOLBARBLOCK, "OnBlockTool", 
               "add_block.png", _("Create a new block")),
              (True, FREEDRAWING_MODE, 
-              ID_PLCOPENEDITORTOOLBARCONNECTION, "OnConnectionTool", 
+              ID_PLCOPENEDITOREDITORTOOLBARCONNECTION, "OnConnectionTool", 
               "add_connection.png", _("Create a new connection")),
              (True, FREEDRAWING_MODE, 
-              ID_PLCOPENEDITORTOOLBARPOWERRAIL, "OnPowerRailTool", 
+              ID_PLCOPENEDITOREDITORTOOLBARPOWERRAIL, "OnPowerRailTool", 
               "add_powerrail.png", _("Create a new power rail")),
              (True, FREEDRAWING_MODE, 
-              ID_PLCOPENEDITORTOOLBARCONTACT, "OnContactTool", 
+              ID_PLCOPENEDITOREDITORTOOLBARCONTACT, "OnContactTool", 
               "add_contact.png", _("Create a new contact"))],
     "ST"  : [],
-    "IL"  : []
+    "IL"  : [],
+    "debug": [(True, FREEDRAWING_MODE|DRIVENDRAWING_MODE,
+              ID_PLCOPENEDITOREDITORTOOLBARMOTION, "OnMotionTool",
+              "move.png", _("Move the view"))],
 }
 
 #-------------------------------------------------------------------------------
@@ -265,7 +266,7 @@
     else:
         parent.Append(helpString=help, id=id, kind=kind, item=text)
 
-[TITLE, TOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, TYPESTREE, 
+[TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, TYPESTREE, 
  INSTANCESTREE, LIBRARYTREE, SCALING, PAGETITLES
 ] = range(10)
 
@@ -382,6 +383,13 @@
               id=ID_PLCOPENEDITOREDITMENUADDCONFIGURATION)
         self.Bind(wx.EVT_MENU, self.OnSelectAllMenu, id=wx.ID_SELECTALL)
         self.Bind(wx.EVT_MENU, self.OnDeleteMenu, id=wx.ID_DELETE)
+        
+        self.AddToMenuToolBar([(wx.ID_UNDO, wx.ART_UNDO, _(u'Undo'), None),
+                               (wx.ID_REDO, wx.ART_REDO, _(u'Redo'), None),
+                               None,
+                               (wx.ID_CUT, wx.ART_CUT, _(u'Cut'), None),
+                               (wx.ID_COPY, wx.ART_COPY, _(u'Copy'), None),
+                               (wx.ID_PASTE, wx.ART_PASTE, _(u'Paste'), None)])
 
     def _init_coll_DisplayMenu_Items(self, parent):
         AppendMenu(parent, help='', id=wx.ID_REFRESH,
@@ -438,9 +446,7 @@
         wx.Frame.__init__(self, id=ID_PLCOPENEDITOR, name='IDEFrame',
               parent=prnt, pos=wx.DefaultPosition, size=wx.Size(1000, 600),
               style=wx.DEFAULT_FRAME_STYLE)
-        self._init_utils()
         self.SetClientSize(wx.Size(1000, 600))
-        self.SetMenuBar(self.MenuBar)
         
         self.TabsImageList = wx.ImageList(31, 16)
         self.TabsImageListIndexes = {}
@@ -599,27 +605,38 @@
         #-----------------------------------------------------------------------
 
         if USE_AUI:
-            ToolBar = wx.ToolBar(self, ID_PLCOPENEDITORTOOLBAR, wx.DefaultPosition, wx.DefaultSize,
+            EditorToolBar = wx.ToolBar(self, ID_PLCOPENEDITOREDITORTOOLBAR, wx.DefaultPosition, wx.DefaultSize,
                     wx.TB_FLAT | wx.TB_NODIVIDER | wx.NO_BORDER)
-            ToolBar.SetToolBitmapSize(wx.Size(25, 25))
-            ToolBar.AddRadioTool(ID_PLCOPENEDITORTOOLBARSELECTION, 
+            EditorToolBar.SetToolBitmapSize(wx.Size(25, 25))
+            EditorToolBar.AddRadioTool(ID_PLCOPENEDITOREDITORTOOLBARSELECTION, 
                   wx.Bitmap(os.path.join(CWD, 'Images', 'select.png')), wx.NullBitmap, _("Select an object"))
-            ToolBar.Realize()
-            self.Panes["ToolBar"] = ToolBar
-            self.AUIManager.AddPane(ToolBar, wx.aui.AuiPaneInfo().
-                      Name("ToolBar").Caption(_("Toolbar")).
+            EditorToolBar.Realize()
+            self.Panes["EditorToolBar"] = EditorToolBar
+            self.AUIManager.AddPane(EditorToolBar, wx.aui.AuiPaneInfo().
+                      Name("EditorToolBar").Caption(_("Editor ToolBar")).
                       ToolbarPane().Top().
                       LeftDockable(False).RightDockable(False))
-        else:
-            self.ToolBar = self.CreateToolBar(wx.TB_HORIZONTAL|wx.TB_FLAT|wx.NO_BORDER, 
-                  ID_PLCOPENEDITORTOOLBAR, 'ToolBar')
-            self.ToolBar.SetToolBitmapSize(wx.Size(25, 25))
-            self.ToolBar.AddRadioTool(ID_PLCOPENEDITORTOOLBARSELECTION, 
+        
+            MenuToolBar = wx.ToolBar(self, ID_PLCOPENEDITOREDITORMENUTOOLBAR, wx.DefaultPosition, wx.DefaultSize,
+                    wx.TB_FLAT | wx.TB_NODIVIDER | wx.NO_BORDER)
+            MenuToolBar.SetToolBitmapSize(wx.Size(25, 25))
+            MenuToolBar.Realize()
+            self.Panes["MenuToolBar"] = MenuToolBar
+            self.AUIManager.AddPane(MenuToolBar, wx.aui.AuiPaneInfo().
+                      Name("MenuToolBar").Caption(_("Menu ToolBar")).
+                      ToolbarPane().Top().
+                      LeftDockable(False).RightDockable(False))
+            
+        else:
+            self.EditorToolBar = self.CreateToolBar(wx.TB_HORIZONTAL|wx.TB_FLAT|wx.NO_BORDER, 
+                  ID_PLCOPENEDITOREDITORTOOLBAR, 'EditorToolBar')
+            self.EditorToolBar.SetToolBitmapSize(wx.Size(25, 25))
+            self.EditorToolBar.AddRadioTool(ID_PLCOPENEDITOREDITORTOOLBARSELECTION, 
                   wx.Bitmap(os.path.join(CWD, 'Images', 'select.png')), wx.NullBitmap, _("Select an object"))
-            self.ToolBar.Realize()
+            self.EditorToolBar.Realize()
             
-        self.Bind(wx.EVT_TOOL, self.OnSelectionTool, 
-              id=ID_PLCOPENEDITORTOOLBARSELECTION)
+        self.Bind(wx.EVT_MENU, self.OnSelectionTool, 
+              id=ID_PLCOPENEDITOREDITORTOOLBARSELECTION)
         
         self.SearchResultPanel = SearchResultPanel(self.BottomNoteBook, self)
         self.BottomNoteBook.AddPage(self.SearchResultPanel, _("Search"))
@@ -643,6 +660,9 @@
               pos=wx.Point(0, 0), size=wx.Size(0, 160), 
               style=wx.TE_READONLY|wx.TE_MULTILINE)
         
+        self._init_utils()
+        self.SetMenuBar(self.MenuBar)
+        
         self._init_sizers()
         
         if self.EnableDebug:
@@ -706,8 +726,8 @@
         self.TypesTree.SetImageList(self.TreeImageList)
         self.InstancesTree.SetImageList(self.TreeImageList)
         
-        self.CurrentToolBar = []
-        self.CurrentLanguage = ""
+        self.CurrentEditorToolBar = []
+        self.CurrentMenu = None
         self.SelectedItem = None
         self.Highlights = {}
         self.DrawingMode = FREEDRAWING_MODE
@@ -753,7 +773,7 @@
     def SetRefreshFunctions(self):
         self.RefreshFunctions = {
             TITLE : self.RefreshTitle,
-            TOOLBAR : self.RefreshToolBar,
+            EDITORTOOLBAR : self.RefreshEditorToolBar,
             FILEMENU : self.RefreshFileMenu,
             EDITMENU : self.RefreshEditMenu,
             DISPLAYMENU : self.RefreshDisplayMenu,
@@ -773,7 +793,7 @@
     #  @param event AUINotebook Event.
     def OnPageClose(self, event):
         # Refresh all window elements that have changed
-        wx.CallAfter(self._Refresh, TITLE, TOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU)
+        wx.CallAfter(self._Refresh, TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU)
         wx.CallAfter(self.RefreshTabCtrlEvent)
         event.Skip()
 
@@ -814,7 +834,7 @@
             new_values["creationDateTime"] = old_values["creationDateTime"]
             if new_values != old_values:
                 self.Controler.SetProjectProperties(None, new_values)
-                self._Refresh(TITLE, TOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, 
+                self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, 
                               TYPESTREE, INSTANCESTREE, SCALING)
         dialog.Destroy()
 
@@ -950,7 +970,7 @@
                 new_index = min(selected, self.TabsOpened.GetPageCount() - 1)
                 self.TabsOpened.SetSelection(new_index)
         # Refresh all window elements that have changed
-        self._Refresh(TITLE, TOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU)
+        self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU)
         self.RefreshTabCtrlEvent()
 
     def OnPageSetupMenu(self, event):
@@ -1010,6 +1030,7 @@
 #-------------------------------------------------------------------------------
 
     def RefreshEditMenu(self):
+        MenuToolBar = self.Panes["MenuToolBar"]
         if self.Controler is not None:
             selected = self.TabsOpened.GetSelection()
             if selected > -1:
@@ -1018,7 +1039,9 @@
             else:
                 undo, redo = self.Controler.GetBufferState()
             self.EditMenu.Enable(wx.ID_UNDO, undo)
+            MenuToolBar.EnableTool(wx.ID_UNDO, undo)
             self.EditMenu.Enable(wx.ID_REDO, redo)
+            MenuToolBar.EnableTool(wx.ID_REDO, redo)
             #self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUENABLEUNDOREDO, True)
             #self.EditMenu.Check(ID_PLCOPENEDITOREDITMENUENABLEUNDOREDO, 
             #                self.Controler.IsProjectBufferEnabled())
@@ -1027,24 +1050,36 @@
             self.EditMenu.Enable(wx.ID_DELETE, True)
             if self.TabsOpened.GetPageCount() > 0:
                 self.EditMenu.Enable(wx.ID_CUT, True)
+                MenuToolBar.EnableTool(wx.ID_CUT, True)
                 self.EditMenu.Enable(wx.ID_COPY, True)
+                MenuToolBar.EnableTool(wx.ID_COPY, True)
                 if self.GetCopyBuffer() is not None:
                     self.EditMenu.Enable(wx.ID_PASTE, True)
+                    MenuToolBar.EnableTool(wx.ID_PASTE, True)
                 else:
                     self.EditMenu.Enable(wx.ID_PASTE, False)
+                    MenuToolBar.EnableTool(wx.ID_PASTE, False)
                 self.EditMenu.Enable(wx.ID_SELECTALL, True)
             else:
                 self.EditMenu.Enable(wx.ID_CUT, False)
+                MenuToolBar.EnableTool(wx.ID_CUT, False)
                 self.EditMenu.Enable(wx.ID_COPY, False)
+                MenuToolBar.EnableTool(wx.ID_COPY, False)
                 self.EditMenu.Enable(wx.ID_PASTE, False)
+                MenuToolBar.EnableTool(wx.ID_PASTE, False)
                 self.EditMenu.Enable(wx.ID_SELECTALL, False)
         else:
             self.EditMenu.Enable(wx.ID_UNDO, False)
+            MenuToolBar.EnableTool(wx.ID_UNDO, False)
             self.EditMenu.Enable(wx.ID_REDO, False)
+            MenuToolBar.EnableTool(wx.ID_REDO, False)
             #self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUENABLEUNDOREDO, False)
             self.EditMenu.Enable(wx.ID_CUT, False)
+            MenuToolBar.EnableTool(wx.ID_CUT, False)
             self.EditMenu.Enable(wx.ID_COPY, False)
+            MenuToolBar.EnableTool(wx.ID_COPY, False)
             self.EditMenu.Enable(wx.ID_PASTE, False)
+            MenuToolBar.EnableTool(wx.ID_PASTE, False)
             self.EditMenu.Enable(wx.ID_SELECTALL, False)
             self.EditMenu.Enable(ID_PLCOPENEDITOREDITMENUSEARCHINPROJECT, False)
             self.EditMenu.Enable(wx.ID_ADD, False)
@@ -1118,7 +1153,7 @@
                 if function is not None:
                     function(self, selected)
                     self.CloseTabsWithoutModel()
-                    self._Refresh(TITLE, TOOLBAR, FILEMENU, EDITMENU, TYPESTREE, 
+                    self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, TYPESTREE, 
                                   INSTANCESTREE, LIBRARYTREE)
         elif isinstance(window, (Viewer, TextViewer)):
             event = wx.KeyEvent(wx.EVT_CHAR._getEvtType())
@@ -1226,7 +1261,7 @@
                 window.RefreshView()
             else:
                 wx.CallAfter(self.SelectInstancesTreeItem, window.GetInstancePath())
-        wx.CallAfter(self._Refresh, FILEMENU, EDITMENU, DISPLAYMENU, TOOLBAR)
+        wx.CallAfter(self._Refresh, FILEMENU, EDITMENU, DISPLAYMENU, EDITORTOOLBAR)
         event.Skip()
 
     def RefreshEditor(self):
@@ -1563,7 +1598,7 @@
                 if old_selected >= 0:
                     self.TabsOpened.GetPage(old_selected).ResetBuffer()
                 self.TabsOpened.SetSelection(openedidx)
-            self._Refresh(FILEMENU, EDITMENU, TOOLBAR, PAGETITLES)
+            self._Refresh(FILEMENU, EDITMENU, EDITORTOOLBAR, PAGETITLES)
         elif not onlyopened:
             new_window = None
             if element == ITEM_CONFIGURATION:
@@ -1956,7 +1991,7 @@
                     if item is None:
                         self.TabsOpened.DeletePage(idx)
                     elif isinstance(editor, GraphicViewer):
-                        editor.ResetView()
+                        editor.ResetView(True)
                     else:
                         editor.RefreshView()
             self.DebugVariablePanel.UnregisterObsoleteData()
@@ -2047,66 +2082,86 @@
             dragSource.DoDragDrop()
 
 #-------------------------------------------------------------------------------
-#                          ToolBar Management Functions
-#-------------------------------------------------------------------------------
-
-    def ResetToolBar(self):
+#                          ToolBars Management Functions
+#-------------------------------------------------------------------------------
+
+    def AddToMenuToolBar(self, items):
+        MenuToolBar = self.Panes["MenuToolBar"]
+        if MenuToolBar.GetToolsCount() > 0:
+            MenuToolBar.AddSeparator()
+        for toolbar_item in items:
+            if toolbar_item is None:
+                MenuToolBar.AddSeparator()
+            else:
+                id, bitmap, help, callback = toolbar_item
+                if not isinstance(bitmap, wx.Bitmap):
+                    bitmap = wx.ArtProvider.GetBitmap(bitmap, wx.ART_TOOLBAR, (24, 24))
+                MenuToolBar.AddSimpleTool(id=id, shortHelpString=help, bitmap=bitmap)
+                if callback is not None:
+                    self.Bind(wx.EVT_TOOL, callback, id=id)
+        MenuToolBar.Realize()
         if USE_AUI:
-            ToolBar = self.Panes["ToolBar"]
-        else:
-            ToolBar = self.ToolBar
-        
-        for item in self.CurrentToolBar:
+            self.AUIManager.GetPane("MenuToolBar").BestSize(MenuToolBar.GetBestSize())
+
+    def ResetEditorToolBar(self):
+        if USE_AUI:
+            EditorToolBar = self.Panes["EditorToolBar"]
+        else:
+            EditorToolBar = self.EditorToolBar
+        
+        for item in self.CurrentEditorToolBar:
             if wx.VERSION >= (2, 6, 0):
                 self.Unbind(wx.EVT_MENU, id=item)
             else:
                 self.Disconnect(id=item, eventType=wx.wxEVT_COMMAND_MENU_SELECTED) 
         
-            if ToolBar:
-                ToolBar.DeleteTool(item)
-        
-        if ToolBar:
-            ToolBar.Realize()
+            if EditorToolBar:
+                EditorToolBar.DeleteTool(item)
+        
+        if EditorToolBar:
+            EditorToolBar.Realize()
             if USE_AUI:
-                self.AUIManager.GetPane("ToolBar").BestSize(ToolBar.GetBestSize())
+                self.AUIManager.GetPane("EditorToolBar").BestSize(EditorToolBar.GetBestSize())
                 self.AUIManager.Update()
 
-    def RefreshToolBar(self):
+    def RefreshEditorToolBar(self):
         selected = self.TabsOpened.GetSelection()
-        language = None
+        menu = None
         if selected != -1:
             window = self.TabsOpened.GetPage(selected)
             if not window.IsDebugging():
-                language = self.Controler.GetEditedElementBodyType(window.GetTagName())
-        if language is not None and language != self.CurrentLanguage:
-            self.ResetToolBar()
-            self.CurrentLanguage = language
-            self.CurrentToolBar = []
+                menu = self.Controler.GetEditedElementBodyType(window.GetTagName())
+            else:
+                menu = "debug"
+        if menu is not None and menu != self.CurrentMenu:
+            self.ResetEditorToolBar()
+            self.CurrentMenu = menu
+            self.CurrentEditorToolBar = []
             if USE_AUI:
-                ToolBar = self.Panes["ToolBar"]
+                EditorToolBar = self.Panes["EditorToolBar"]
             else:
-                ToolBar = self.ToolBar
-            if ToolBar:
-                for radio, modes, id, method, picture, help in ToolBarItems[language]:
+                EditorToolBar = self.EditorToolBar
+            if EditorToolBar:
+                for radio, modes, id, method, picture, help in EditorToolBarItems[menu]:
                     if modes & self.DrawingMode:
                         if radio or self.DrawingMode == FREEDRAWING_MODE:
-                            ToolBar.AddRadioTool(id, wx.Bitmap(os.path.join(CWD, "Images", picture)), wx.NullBitmap, help)
+                            EditorToolBar.AddRadioTool(id, wx.Bitmap(os.path.join(CWD, "Images", picture)), wx.NullBitmap, help)
                         else:
-                            ToolBar.AddSimpleTool(id, wx.Bitmap(os.path.join(CWD, "Images", picture)), help)
-                        self.Bind(wx.EVT_TOOL, getattr(self, method), id=id)
-                        self.CurrentToolBar.append(id)
-                ToolBar.Realize()
+                            EditorToolBar.AddSimpleTool(id, wx.Bitmap(os.path.join(CWD, "Images", picture)), help)
+                        self.Bind(wx.EVT_MENU, getattr(self, method), id=id)
+                        self.CurrentEditorToolBar.append(id)
+                EditorToolBar.Realize()
                 if USE_AUI:
-                    self.AUIManager.GetPane("ToolBar").BestSize(ToolBar.GetBestSize())
+                    self.AUIManager.GetPane("EditorToolBar").BestSize(EditorToolBar.GetBestSize())
                     self.AUIManager.Update()
-        elif not language:
-            self.ResetToolBar()
-            self.CurrentLanguage = language
+        elif not menu:
+            self.ResetEditorToolBar()
+            self.CurrentMenu = menu
         self.ResetCurrentMode()
 
 
 #-------------------------------------------------------------------------------
-#                           ToolBar Items Functions
+#                           EditorToolBar Items Functions
 #-------------------------------------------------------------------------------
 
     def ResetCurrentMode(self):
@@ -2115,18 +2170,18 @@
             window = self.TabsOpened.GetPage(selected)
             window.SetMode(MODE_SELECTION)
         if USE_AUI:
-            ToolBar = self.Panes["ToolBar"]
-        else:
-            ToolBar = self.ToolBar
-        if ToolBar:
-            ToolBar.ToggleTool(ID_PLCOPENEDITORTOOLBARSELECTION, False)
-            ToolBar.ToggleTool(ID_PLCOPENEDITORTOOLBARSELECTION, True)
+            EditorToolBar = self.Panes["EditorToolBar"]
+        else:
+            EditorToolBar = self.EditorToolBar
+        if EditorToolBar:
+            EditorToolBar.ToggleTool(ID_PLCOPENEDITOREDITORTOOLBARSELECTION, False)
+            EditorToolBar.ToggleTool(ID_PLCOPENEDITOREDITORTOOLBARSELECTION, True)
         
     def ResetToolToggle(self, id):
         if USE_AUI:
-            tool = self.Panes["ToolBar"].FindById(id)
-        else:
-            tool = self.ToolBar.FindById(id)
+            tool = self.Panes["EditorToolBar"].FindById(id)
+        else:
+            tool = self.EditorToolBar.FindById(id)
         tool.SetToggle(False)
 
     def OnSelectionTool(self, event):
@@ -2140,31 +2195,31 @@
             self.TabsOpened.GetPage(selected).SetMode(MODE_MOTION)
     
     def OnCommentTool(self, event):
-        self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARCOMMENT)
+        self.ResetToolToggle(ID_PLCOPENEDITOREDITORTOOLBARCOMMENT)
         selected = self.TabsOpened.GetSelection()
         if selected != -1:
             self.TabsOpened.GetPage(selected).SetMode(MODE_COMMENT)
     
     def OnVariableTool(self, event):
-        self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARVARIABLE)
+        self.ResetToolToggle(ID_PLCOPENEDITOREDITORTOOLBARVARIABLE)
         selected = self.TabsOpened.GetSelection()
         if selected != -1:
             self.TabsOpened.GetPage(selected).SetMode(MODE_VARIABLE)
     
     def OnBlockTool(self, event):
-        self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARBLOCK)
+        self.ResetToolToggle(ID_PLCOPENEDITOREDITORTOOLBARBLOCK)
         selected = self.TabsOpened.GetSelection()
         if selected != -1:
             self.TabsOpened.GetPage(selected).SetMode(MODE_BLOCK)
         
     def OnConnectionTool(self, event):
-        self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARCONNECTION)
+        self.ResetToolToggle(ID_PLCOPENEDITOREDITORTOOLBARCONNECTION)
         selected = self.TabsOpened.GetSelection()
         if selected != -1:
             self.TabsOpened.GetPage(selected).SetMode(MODE_CONNECTION)
     
     def OnPowerRailTool(self, event):
-        self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARPOWERRAIL)
+        self.ResetToolToggle(ID_PLCOPENEDITOREDITORTOOLBARPOWERRAIL)
         selected = self.TabsOpened.GetSelection()
         if selected != -1:
             self.TabsOpened.GetPage(selected).SetMode(MODE_POWERRAIL)
@@ -2176,7 +2231,7 @@
         event.Skip()
     
     def OnCoilTool(self, event):
-        self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARCOIL)
+        self.ResetToolToggle(ID_PLCOPENEDITOREDITORTOOLBARCOIL)
         selected = self.TabsOpened.GetSelection()
         if selected != -1:
             self.TabsOpened.GetPage(selected).SetMode(MODE_COIL)
@@ -2184,7 +2239,7 @@
     
     def OnContactTool(self, event):
         if self.DrawingMode == FREEDRAWING_MODE:
-            self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARCONTACT)
+            self.ResetToolToggle(ID_PLCOPENEDITOREDITORTOOLBARCONTACT)
         selected = self.TabsOpened.GetSelection()
         if selected != -1:
             if self.DrawingMode == FREEDRAWING_MODE:
@@ -2198,14 +2253,14 @@
             self.TabsOpened.GetPage(selected).AddLadderBranch()
     
     def OnInitialStepTool(self, event):
-        self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARINITIALSTEP)
+        self.ResetToolToggle(ID_PLCOPENEDITOREDITORTOOLBARINITIALSTEP)
         selected = self.TabsOpened.GetSelection()
         if selected != -1:
             self.TabsOpened.GetPage(selected).SetMode(MODE_INITIALSTEP)
     
     def OnStepTool(self, event):
         if self.GetDrawingMode() == FREEDRAWING_MODE:
-            self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARSTEP)
+            self.ResetToolToggle(ID_PLCOPENEDITOREDITORTOOLBARSTEP)
         selected = self.TabsOpened.GetSelection()
         if selected != -1:
             if self.GetDrawingMode() == FREEDRAWING_MODE:
@@ -2215,7 +2270,7 @@
     
     def OnActionBlockTool(self, event):
         if self.GetDrawingMode() == FREEDRAWING_MODE:
-            self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARACTIONBLOCK)
+            self.ResetToolToggle(ID_PLCOPENEDITOREDITORTOOLBARACTIONBLOCK)
         selected = self.TabsOpened.GetSelection()
         if selected != -1:
             if self.GetDrawingMode() == FREEDRAWING_MODE:
@@ -2224,14 +2279,14 @@
                 self.TabsOpened.GetPage(selected).AddStepAction()
     
     def OnTransitionTool(self, event):
-        self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARTRANSITION)
+        self.ResetToolToggle(ID_PLCOPENEDITOREDITORTOOLBARTRANSITION)
         selected = self.TabsOpened.GetSelection()
         if selected != -1:
             self.TabsOpened.GetPage(selected).SetMode(MODE_TRANSITION)
     
     def OnDivergenceTool(self, event):
         if self.GetDrawingMode() == FREEDRAWING_MODE:
-            self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARDIVERGENCE)
+            self.ResetToolToggle(ID_PLCOPENEDITOREDITORTOOLBARDIVERGENCE)
         selected = self.TabsOpened.GetSelection()
         if selected != -1:
             if self.GetDrawingMode() == FREEDRAWING_MODE:
@@ -2241,7 +2296,7 @@
     
     def OnJumpTool(self, event):
         if self.GetDrawingMode() == FREEDRAWING_MODE:
-            self.ResetToolToggle(ID_PLCOPENEDITORTOOLBARJUMP)
+            self.ResetToolToggle(ID_PLCOPENEDITOREDITORTOOLBARJUMP)
         selected = self.TabsOpened.GetSelection()
         if selected != -1:
             if self.GetDrawingMode() == FREEDRAWING_MODE:
@@ -2337,7 +2392,7 @@
             selected = self.TypesTree.GetSelection()
             if self.TypesTree.GetPyData(selected) == ITEM_POU: 
                 self.Controler.ProjectChangePouType(name, new_type)
-                self._Refresh(TITLE, TOOLBAR, FILEMENU, EDITMENU, TYPESTREE, LIBRARYTREE)
+                self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, TYPESTREE, LIBRARYTREE)
         return OnChangePouTypeMenu
 
     def OnCopyPou(self, event):
@@ -2365,7 +2420,7 @@
             message.ShowModal()
             message.Destroy()
         else:
-            self._Refresh(TITLE, TOOLBAR, FILEMENU, EDITMENU, TYPESTREE, LIBRARYTREE)
+            self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, TYPESTREE, LIBRARYTREE)
 
 #-------------------------------------------------------------------------------
 #                        Remove Project Elements Functions
@@ -2381,7 +2436,7 @@
                 idx = self.IsOpened(tagname)
                 if idx is not None:
                     self.TabsOpened.DeletePage(idx)
-                self._Refresh(TITLE, TOOLBAR, FILEMENU, EDITMENU, TYPESTREE)
+                self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, TYPESTREE)
             else:
                 self.ShowErrorMessage(_("\"%s\" is used by one or more POUs. It can't be removed!"))
 
@@ -2400,7 +2455,7 @@
                 idx = self.IsOpened(tagname)
                 if idx is not None:
                     self.TabsOpened.DeletePage(idx)
-                self._Refresh(TITLE, TOOLBAR, FILEMENU, EDITMENU, TYPESTREE, INSTANCESTREE, LIBRARYTREE)
+                self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, TYPESTREE, INSTANCESTREE, LIBRARYTREE)
             else:
                 self.ShowErrorMessage(_("\"%s\" is used by one or more POUs. It can't be removed!"))
 
@@ -2572,7 +2627,13 @@
         self.Bind(wx.EVT_MENU, self.OnPrintMenu, id=wx.ID_PRINT)
         self.Bind(wx.EVT_MENU, self.OnPropertiesMenu, id=wx.ID_PROPERTIES)
         self.Bind(wx.EVT_MENU, self.OnQuitMenu, id=wx.ID_EXIT)
-
+        
+        self.AddToMenuToolBar([(wx.ID_NEW, wx.ART_NEW, _(u'New'), None),
+                               (wx.ID_OPEN, wx.ART_FILE_OPEN, _(u'Open'), None),
+                               (wx.ID_SAVE, wx.ART_FILE_SAVE, _(u'Save'), None),
+                               (wx.ID_SAVEAS, wx.ART_FILE_SAVE_AS, _(u'Save As...'), None),
+                               (wx.ID_PRINT, wx.ART_PRINT, _(u'Print'), None)])
+            
     def _init_coll_HelpMenu_Items(self, parent):
         AppendMenu(parent, help='', id=wx.ID_HELP, 
             kind=wx.ITEM_NORMAL, text=_(u'PLCOpenEditor\tF1'))
@@ -2609,7 +2670,7 @@
 
         self.Bind(wx.EVT_CLOSE, self.OnCloseFrame)
         
-        self._Refresh(TITLE, TOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU)
+        self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU)
         
         if result is not None:
             self.ShowErrorMessage(result)
@@ -2637,6 +2698,7 @@
 #-------------------------------------------------------------------------------
 
     def RefreshFileMenu(self):
+        MenuToolBar = self.Panes["MenuToolBar"]
         if self.Controler is not None:
             selected = self.TabsOpened.GetSelection()
             if selected >= 0:
@@ -2648,28 +2710,37 @@
                 if graphic_viewer:
                     self.FileMenu.Enable(wx.ID_PREVIEW, True)
                     self.FileMenu.Enable(wx.ID_PRINT, True)
+                    MenuToolBar.EnableTool(wx.ID_PRINT, True)
                 else:
                     self.FileMenu.Enable(wx.ID_PREVIEW, False)
                     self.FileMenu.Enable(wx.ID_PRINT, False)
+                    MenuToolBar.EnableTool(wx.ID_PRINT, False)
             else:
                 self.FileMenu.Enable(wx.ID_CLOSE, False)
                 self.FileMenu.Enable(wx.ID_PREVIEW, False)
                 self.FileMenu.Enable(wx.ID_PRINT, False)
+                MenuToolBar.EnableTool(wx.ID_PRINT, False)
             self.FileMenu.Enable(wx.ID_PAGE_SETUP, True)
-            self.FileMenu.Enable(wx.ID_SAVE, True)
+            project_modified = not self.Controler.ProjectIsSaved()
+            self.FileMenu.Enable(wx.ID_SAVE, project_modified)
+            MenuToolBar.EnableTool(wx.ID_SAVE, project_modified)
             self.FileMenu.Enable(wx.ID_PROPERTIES, True)
             self.FileMenu.Enable(wx.ID_CLOSE_ALL, True)
             self.FileMenu.Enable(wx.ID_SAVEAS, True)
+            MenuToolBar.EnableTool(wx.ID_SAVEAS, True)
             self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUGENERATE, True)
         else:
             self.FileMenu.Enable(wx.ID_CLOSE, False)
             self.FileMenu.Enable(wx.ID_PAGE_SETUP, False)
             self.FileMenu.Enable(wx.ID_PREVIEW, False)
             self.FileMenu.Enable(wx.ID_PRINT, False)
+            MenuToolBar.EnableTool(wx.ID_PRINT, False)
             self.FileMenu.Enable(wx.ID_SAVE, False)
+            MenuToolBar.EnableTool(wx.ID_SAVE, False)
             self.FileMenu.Enable(wx.ID_PROPERTIES, False)
             self.FileMenu.Enable(wx.ID_CLOSE_ALL, False)
             self.FileMenu.Enable(wx.ID_SAVEAS, False)
+            MenuToolBar.EnableTool(wx.ID_SAVEAS, False)
             self.FileMenu.Enable(ID_PLCOPENEDITORFILEMENUGENERATE, False)
 
     def OnNewProjectMenu(self, event):
@@ -2706,7 +2777,7 @@
                 result = self.Controler.OpenXMLFile(filepath)
                 if result is None:
                     self._Refresh(TYPESTREE, INSTANCESTREE, LIBRARYTREE)
-            self._Refresh(TITLE, TOOLBAR, FILEMENU, EDITMENU)
+            self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU)
         dialog.Destroy()
         
         if result is not None:
@@ -2716,7 +2787,7 @@
         if not self.CheckSaveBeforeClosing():
             return
         self.ResetView()
-        self._Refresh(TITLE, TOOLBAR, FILEMENU, EDITMENU)
+        self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU)
 
     def OnSaveProjectMenu(self, event):
         self.SaveProject()