Moved some code from PLCController.py to other modules. Added necessary imports.
--- a/PLCControler.py Sat Feb 17 23:58:47 2018 +0100
+++ b/PLCControler.py Sun Feb 18 21:30:48 2018 +0100
@@ -38,6 +38,8 @@
import util.paths as paths
from util.TranslationCatalogs import NoTranslate
from plcopen import *
+from plcopen.types_enums import *
+from plcopen.XSLTModelQuery import _StringValue, _BoolValue, _translate_args
from plcopen.InstancesPathCollector import InstancesPathCollector
from plcopen.POUVariablesCollector import POUVariablesCollector
from graphics.GraphicCommons import *
@@ -45,77 +47,8 @@
duration_model = re.compile("(?:([0-9]{1,2})h)?(?:([0-9]{1,2})m(?!s))?(?:([0-9]{1,2})s)?(?:([0-9]{1,3}(?:\.[0-9]*)?)ms)?")
-ITEMS_EDITABLE = [
- ITEM_PROJECT,
- ITEM_POU,
- ITEM_VARIABLE,
- ITEM_TRANSITION,
- ITEM_ACTION,
- ITEM_CONFIGURATION,
- ITEM_RESOURCE,
- ITEM_DATATYPE
-] = range(8)
-
-ITEMS_UNEDITABLE = [
- ITEM_DATATYPES,
- ITEM_FUNCTION,
- ITEM_FUNCTIONBLOCK,
- ITEM_PROGRAM,
- ITEM_TRANSITIONS,
- ITEM_ACTIONS,
- ITEM_CONFIGURATIONS,
- ITEM_RESOURCES,
- ITEM_PROPERTIES
-] = range(8, 17)
-
-ITEMS_VARIABLE = [
- ITEM_VAR_LOCAL,
- ITEM_VAR_GLOBAL,
- ITEM_VAR_EXTERNAL,
- ITEM_VAR_TEMP,
- ITEM_VAR_INPUT,
- ITEM_VAR_OUTPUT,
- ITEM_VAR_INOUT
-] = range(17, 24)
-
-VAR_CLASS_INFOS = {
- "Local": ("localVars", ITEM_VAR_LOCAL),
- "Global": ("globalVars", ITEM_VAR_GLOBAL),
- "External": ("externalVars", ITEM_VAR_EXTERNAL),
- "Temp": ("tempVars", ITEM_VAR_TEMP),
- "Input": ("inputVars", ITEM_VAR_INPUT),
- "Output": ("outputVars", ITEM_VAR_OUTPUT),
- "InOut": ("inOutVars", ITEM_VAR_INOUT)}
-
-POU_TYPES = {
- "program": ITEM_PROGRAM,
- "functionBlock": ITEM_FUNCTIONBLOCK,
- "function": ITEM_FUNCTION,
-}
-
-LOCATIONS_ITEMS = [LOCATION_CONFNODE,
- LOCATION_MODULE,
- LOCATION_GROUP,
- LOCATION_VAR_INPUT,
- LOCATION_VAR_OUTPUT,
- LOCATION_VAR_MEMORY] = range(6)
-
ScriptDirectory = paths.AbsDir(__file__)
-
-def GetUneditableNames():
- _ = NoTranslate
- return [_("User-defined POUs"), _("Functions"), _("Function Blocks"),
- _("Programs"), _("Data Types"), _("Transitions"), _("Actions"),
- _("Configurations"), _("Resources"), _("Properties")]
-
-
-UNEDITABLE_NAMES = GetUneditableNames()
-[USER_DEFINED_POUS, FUNCTIONS, FUNCTION_BLOCKS, PROGRAMS,
- DATA_TYPES, TRANSITIONS, ACTIONS, CONFIGURATIONS,
- RESOURCES, PROPERTIES] = UNEDITABLE_NAMES
-
-
class LibraryResolver(etree.Resolver):
"""Helper object for loading library in xslt stylesheets"""
@@ -138,24 +71,6 @@
lib_el.append(deepcopy(ctn["types"]))
return self.resolve_string(etree.tostring(lib_el), context)
-# -------------------------------------------------------------------------------
-# Helpers functions for translating list of arguments
-# from xslt to valid arguments
-# -------------------------------------------------------------------------------
-
-
-def _StringValue(x):
- return x
-
-
-def _BoolValue(x):
- return x in ["true", "0"]
-
-
-def _translate_args(translations, args):
- return [translate(arg[0]) if len(arg) > 0 else None
- for translate, arg in
- zip(translations, args)]
# -------------------------------------------------------------------------------
# Helpers object for generating pou var list
--- a/plcopen/POUVariablesCollector.py Sat Feb 17 23:58:47 2018 +0100
+++ b/plcopen/POUVariablesCollector.py Sun Feb 18 21:30:48 2018 +0100
@@ -4,15 +4,11 @@
# See COPYING file for copyrights details.
from __future__ import absolute_import
-from plcopen.XSLTModelQuery import XSLTModelQuery
+from plcopen.XSLTModelQuery import XSLTModelQuery, _StringValue, _BoolValue, _translate_args
+from plcopen.types_enums import CLASS_TYPES, POU_TYPES, VAR_CLASS_INFOS
def class_extraction(value):
- class_type = {
- "configuration": ITEM_CONFIGURATION,
- "resource": ITEM_RESOURCE,
- "action": ITEM_ACTION,
- "transition": ITEM_TRANSITION,
- "program": ITEM_PROGRAM}.get(value)
+ class_type = CLASS_TYPES.get(value)
if class_type is not None:
return class_type
--- a/plcopen/XSLTModelQuery.py Sat Feb 17 23:58:47 2018 +0100
+++ b/plcopen/XSLTModelQuery.py Sun Feb 18 21:30:48 2018 +0100
@@ -11,6 +11,7 @@
ScriptDirectory = paths.AbsDir(__file__)
+
class XSLTModelQuery(object):
""" a class to handle XSLT queries on project and libs """
def __init__(self, controller, xsltpath, ext = []):
@@ -39,3 +40,24 @@
res = self.xslt(root,**{k:etree.XSLT.strparam(v) for k,v in kwargs.iteritems()})
# print(self.xslt.error_log)
return res
+
+
+# -------------------------------------------------------------------------------
+# Helpers functions for translating list of arguments
+# from xslt to valid arguments
+# -------------------------------------------------------------------------------
+
+
+def _StringValue(x):
+ return x
+
+
+def _BoolValue(x):
+ return x in ["true", "0"]
+
+
+def _translate_args(translations, args):
+ return [translate(arg[0]) if len(arg) > 0 else None
+ for translate, arg in
+ zip(translations, args)]
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/plcopen/types_enums.py Sun Feb 18 21:30:48 2018 +0100
@@ -0,0 +1,82 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+# This file is part of Beremiz
+# See COPYING file for copyrights details.
+
+from __future__ import absolute_import
+from util.TranslationCatalogs import NoTranslate
+_ = NoTranslate
+
+ITEMS_EDITABLE = [
+ ITEM_PROJECT,
+ ITEM_POU,
+ ITEM_VARIABLE,
+ ITEM_TRANSITION,
+ ITEM_ACTION,
+ ITEM_CONFIGURATION,
+ ITEM_RESOURCE,
+ ITEM_DATATYPE
+] = range(8)
+
+ITEMS_UNEDITABLE = [
+ ITEM_DATATYPES,
+ ITEM_FUNCTION,
+ ITEM_FUNCTIONBLOCK,
+ ITEM_PROGRAM,
+ ITEM_TRANSITIONS,
+ ITEM_ACTIONS,
+ ITEM_CONFIGURATIONS,
+ ITEM_RESOURCES,
+ ITEM_PROPERTIES
+] = range(8, 17)
+
+ITEMS_VARIABLE = [
+ ITEM_VAR_LOCAL,
+ ITEM_VAR_GLOBAL,
+ ITEM_VAR_EXTERNAL,
+ ITEM_VAR_TEMP,
+ ITEM_VAR_INPUT,
+ ITEM_VAR_OUTPUT,
+ ITEM_VAR_INOUT
+] = range(17, 24)
+
+VAR_CLASS_INFOS = {
+ "Local": ("localVars", ITEM_VAR_LOCAL),
+ "Global": ("globalVars", ITEM_VAR_GLOBAL),
+ "External": ("externalVars", ITEM_VAR_EXTERNAL),
+ "Temp": ("tempVars", ITEM_VAR_TEMP),
+ "Input": ("inputVars", ITEM_VAR_INPUT),
+ "Output": ("outputVars", ITEM_VAR_OUTPUT),
+ "InOut": ("inOutVars", ITEM_VAR_INOUT)}
+
+POU_TYPES = {
+ "program": ITEM_PROGRAM,
+ "functionBlock": ITEM_FUNCTIONBLOCK,
+ "function": ITEM_FUNCTION,
+}
+
+CLASS_TYPES = {
+ "configuration": ITEM_CONFIGURATION,
+ "resource": ITEM_RESOURCE,
+ "action": ITEM_ACTION,
+ "transition": ITEM_TRANSITION,
+ "program": ITEM_PROGRAM
+}
+
+LOCATIONS_ITEMS = [LOCATION_CONFNODE,
+ LOCATION_MODULE,
+ LOCATION_GROUP,
+ LOCATION_VAR_INPUT,
+ LOCATION_VAR_OUTPUT,
+ LOCATION_VAR_MEMORY] = range(6)
+
+UNEDITABLE_NAMES = [_("User-defined POUs"), _("Functions"), _("Function Blocks"),
+ _("Programs"), _("Data Types"), _("Transitions"), _("Actions"),
+ _("Configurations"), _("Resources"), _("Properties")]
+
+[USER_DEFINED_POUS, FUNCTIONS, FUNCTION_BLOCKS, PROGRAMS,
+ DATA_TYPES, TRANSITIONS, ACTIONS, CONFIGURATIONS,
+ RESOURCES, PROPERTIES] = UNEDITABLE_NAMES
+
+# remove gettext override
+del _