diff -r c02818d7e29f -r 7e61baa047f0 PLCControler.py --- a/PLCControler.py Mon Aug 14 22:30:41 2017 +0300 +++ b/PLCControler.py Mon Aug 14 23:27:15 2017 +0300 @@ -94,6 +94,7 @@ ScriptDirectory = paths.AbsDir(__file__) + def GetUneditableNames(): _ = lambda x:x return [_("User-defined POUs"), _("Functions"), _("Function Blocks"), @@ -108,6 +109,7 @@ # Helper object for loading library in xslt stylesheets #------------------------------------------------------------------------------- + class LibraryResolver(etree.Resolver): def __init__(self, controller, debug=False): @@ -136,6 +138,7 @@ _StringValue = lambda x: x _BoolValue = lambda x: x in ["true", "0"] + def _translate_args(translations, args): return [translate(arg[0]) if len(arg) > 0 else None for translate, arg in @@ -145,6 +148,7 @@ # Helpers object for generating pou var list #------------------------------------------------------------------------------- + class _VariableInfos(object): __slots__ = ["Name", "Class", "Option", "Location", "InitialValue", "Edit", "Documentation", "Type", "Tree", "Number"] @@ -154,6 +158,7 @@ def copy(self): return _VariableInfos(*[getattr(self, attr) for attr in self.__slots__]) + class VariablesInfosFactory: def __init__(self, variables): @@ -194,6 +199,7 @@ # Helpers object for generating pou variable instance list #------------------------------------------------------------------------------- + def class_extraction(value): class_type = { "configuration": ITEM_CONFIGURATION, @@ -214,6 +220,7 @@ return None + class _VariablesTreeItemInfos(object): __slots__ = ["name", "var_class", "type", "edit", "debug", "variables"] def __init__(self, *args): @@ -222,6 +229,7 @@ def copy(self): return _VariableTreeItem(*[getattr(self, attr) for attr in self.__slots__]) + class VariablesTreeInfosFactory: def __init__(self): @@ -247,6 +255,7 @@ # Helpers object for generating instances path list #------------------------------------------------------------------------------- + class InstancesPathFactory: def __init__(self, instances): @@ -259,6 +268,7 @@ # Helpers object for generating instance tagname #------------------------------------------------------------------------------- + class InstanceTagName: def __init__(self, controller): @@ -355,6 +365,7 @@ _ConnectionLinkInfos = namedtuple("ConnectionLinkInfos", ["refLocalId", "formalParameter", "points"]) + class _ActionInfos(object): __slots__ = ["qualifier", "type", "value", "duration", "indicator"] def __init__(self, *args): @@ -363,6 +374,7 @@ def copy(self): return _ActionInfos(*[getattr(self, attr) for attr in self.__slots__]) + class BlockInstanceFactory: def __init__(self, block_instances): @@ -438,13 +450,16 @@ # 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 + """ + Class implementing a buffer of changes made on the current editing model + """ + def __init__(self, currentstate, issaved = False): + """ + Constructor initialising buffer + """ self.Buffer = [] self.CurrentIndex = -1 self.MinIndex = -1 @@ -466,8 +481,11 @@ else: self.LastSave = -1 - # Add a new state in buffer + def Buffering(self, currentstate): + """ + Add a new state in buffer + """ self.CurrentIndex = (self.CurrentIndex + 1) % UNDO_BUFFER_LENGTH self.Buffer[self.CurrentIndex] = currentstate # Actualising buffer limits @@ -479,8 +497,11 @@ self.MinIndex = (self.MinIndex + 1) % UNDO_BUFFER_LENGTH self.MinIndex = max(self.MinIndex, 0) - # Return current state of buffer + def Current(self): + """ + Return current state of buffer + """ return self.Buffer[self.CurrentIndex] # Change current state to previous in buffer and return new current state @@ -518,10 +539,11 @@ # Controler for PLCOpenEditor #------------------------------------------------------------------------------- -""" -Class which controls the operations made on the plcopen model and answers to view requests -""" + class PLCControler: + """ + Class which controls the operations made on the plcopen model and answers to view requests + """ # Create a new PLCControler def __init__(self):