# HG changeset patch # User laurent # Date 1324072513 -3600 # Node ID 9f6c091c316c80107f4c5db65d8fd2ceb7589ead # Parent 21a572d80bd7e947ab91a1f12fc1d03fc6f1344f Removing multiple definition of UndoBuffer diff -r 21a572d80bd7 -r 9f6c091c316c plugins/python/PythonEditor.py --- a/plugins/python/PythonEditor.py Fri Dec 16 22:54:24 2011 +0100 +++ b/plugins/python/PythonEditor.py Fri Dec 16 22:55:13 2011 +0100 @@ -571,6 +571,9 @@ # Edit Project Menu Functions #------------------------------------------------------------------------------- + def RefreshFileMenu(self): + pass + def RefreshEditMenu(self): undo, redo = self.Controler.GetBufferState() self.EditMenu.Enable(wx.ID_UNDO, undo) diff -r 21a572d80bd7 -r 9f6c091c316c plugins/python/python.py --- a/plugins/python/python.py Fri Dec 16 22:54:24 2011 +0100 +++ b/plugins/python/python.py Fri Dec 16 22:55:13 2011 +0100 @@ -2,6 +2,7 @@ import os import modules from plugger import PlugTemplate, opjimg +from PLCControler import UndoBuffer from PythonEditor import PythonEditorFrame from xml.dom import minidom @@ -10,88 +11,6 @@ PythonClasses = GenerateClassesFromXSD(os.path.join(os.path.dirname(__file__), "python_xsd.xsd")) -#------------------------------------------------------------------------------- -# Undo Buffer for PythonCode -#------------------------------------------------------------------------------- - -# Length of the buffer -UNDO_BUFFER_LENGTH = 20 - -""" -Class implementing a buffer of changes made on the current editing model -""" -class UndoBuffer: - - # Constructor initialising buffer - def __init__(self, currentstate, issaved = False): - self.Buffer = [] - self.CurrentIndex = -1 - self.MinIndex = -1 - self.MaxIndex = -1 - # if current state is defined - if currentstate: - self.CurrentIndex = 0 - self.MinIndex = 0 - self.MaxIndex = 0 - # Initialising buffer with currentstate at the first place - for i in xrange(UNDO_BUFFER_LENGTH): - if i == 0: - self.Buffer.append(currentstate) - else: - self.Buffer.append(None) - # Initialising index of state saved - if issaved: - self.LastSave = 0 - else: - self.LastSave = -1 - - # Add a new state in buffer - def Buffering(self, currentstate): - self.CurrentIndex = (self.CurrentIndex + 1) % UNDO_BUFFER_LENGTH - self.Buffer[self.CurrentIndex] = currentstate - # Actualising buffer limits - self.MaxIndex = self.CurrentIndex - if self.MinIndex == self.CurrentIndex: - # If the removed state was the state saved, there is no state saved in the buffer - if self.LastSave == self.MinIndex: - self.LastSave = -1 - self.MinIndex = (self.MinIndex + 1) % UNDO_BUFFER_LENGTH - self.MinIndex = max(self.MinIndex, 0) - - # Return current state of buffer - def Current(self): - return self.Buffer[self.CurrentIndex] - - # Change current state to previous in buffer and return new current state - def Previous(self): - if self.CurrentIndex != self.MinIndex: - self.CurrentIndex = (self.CurrentIndex - 1) % UNDO_BUFFER_LENGTH - return self.Buffer[self.CurrentIndex] - return None - - # Change current state to next in buffer and return new current state - def Next(self): - if self.CurrentIndex != self.MaxIndex: - self.CurrentIndex = (self.CurrentIndex + 1) % UNDO_BUFFER_LENGTH - return self.Buffer[self.CurrentIndex] - return None - - # Return True if current state is the first in buffer - def IsFirst(self): - return self.CurrentIndex == self.MinIndex - - # Return True if current state is the last in buffer - def IsLast(self): - return self.CurrentIndex == self.MaxIndex - - # Note that current state is saved - def CurrentSaved(self): - self.LastSave = self.CurrentIndex - - # Return True if current state is saved - def IsCurrentSaved(self): - return self.LastSave == self.CurrentIndex - class PythonCodeTemplate: def __init__(self):