--- a/LPCExtension.py Thu Nov 05 14:31:30 2020 +0100
+++ b/LPCExtension.py Thu Nov 12 11:02:32 2020 +0100
@@ -105,8 +105,21 @@
# --------- special OnChange behavior ------------
+# ----- on load options and OnChange colums fix -------- from py_ext.PythonFileCTNMixin import PythonFileCTNMixin
-from OnChangeFromOptions import GetVarOnChangeContent
+from OnChangeFromOptions import GetVarOnChangeContent, FixOptions PythonFileCTNMixin.GetVarOnChangeContent = GetVarOnChangeContent
+old_PythonFileCTNMixin__init__ = PythonFileCTNMixin.__init__ +def PythonFileCTNMixin__init__with_FixOptions(self): + old_PythonFileCTNMixin__init__(self) +PythonFileCTNMixin.__init__ = PythonFileCTNMixin__init__with_FixOptions --- a/OnChangeFromOptions.py Thu Nov 05 14:31:30 2020 +0100
+++ b/OnChangeFromOptions.py Thu Nov 12 11:02:32 2020 +0100
@@ -3,25 +3,38 @@
from __future__ import absolute_import
-from OptionsParsing import ParseOptions
+from OptionsParsing import ParseOptions, GenOptions def GetVarOnChangeContent(var):
- opts = variable.getopts()
- parsed_opts = re.findall(opt_parser,opts)
- needs_onChange = ('onchange', '') in parsed_opts
- existing_onchanges = [onchange.strip() for onchange in var.getonchange().split(',')]
- for unwanted in ["Alarm", "StoredValue"]:
- existing_onchanges.remove[unwanted]
- new_onchange = existing_onchange[:]
- if ('Static', '') in parsed_opts :
+ Function to overide the way PythonFileCTNMixin access OnChange column when + opts = ParseOptions(var.getopts()) + onchange.strip() for onchange in var.getonchange().split(',')] + if opts.variable_type_selection == 1 : # "Static" new_onchange += ["StoredValue"]
- elif ('Alarm', '') in parsed_opts :
+ elif opts.variable_type_selection == 3 : # "Alarm" new_onchange += ["Alarm"]
return ','.join(new_onchange)
+ Function to be called at the end of PythonFileCTNMixin.__init__() + for var in self.CodeFile.variables.variable: + onchange.strip() for onchange in var.getonchange().split(',')] + opts = ParseOptions(var.getopts()) + for unwanted in ["Alarm", "StoredValue"]: + if unwanted in onchanges: + opts.is_onchange = True + onchanges.remove(unwanted) + var.setonchange(','.join(onchanges)) + var.setopts(GenOptions(opts)) --- a/OptionsParsing.py Thu Nov 05 14:31:30 2020 +0100
+++ b/OptionsParsing.py Thu Nov 12 11:02:32 2020 +0100
@@ -4,31 +4,66 @@
VARIABLETYPE = ["None", "Static", "Session", "Alarm"]
-opt_parser = re.compile(r'(\w+)\s*(?:=\s*"([^"]+)"\s*)?')
+opt_parser = re.compile(r'(\w+)\s*(?:=\s*"([^"]+)"\s*|=([^\s]+)\s*)?') +class OptionsType(dict): + variable_type_selection = 0, + options = VARIABLETYPE[opts.variable_type_selection] + if opts.min is not None or opts.max is not None: + options += ' min="' + str(opts.min if opts.min is not None else 0) + '"' + options += ' max="' + str(opts.max if opts.min is not None else 0) + '"' + options += ' precision="' + str(opts.precision) + '"' + for name in ['subgroup', 'unit', 'other', 'tags']: + if content is not None: + options += ' ' + name + '="' + content + '"'
- def __init__(self, *args, **kwargs):
- dict.__init__(self, *args, **kwargs)
- variable_type_selection = 0,
options = re.findall(opt_parser,opts)
- for key,value in options:
+ for key,dblquote_value,smpl_value in options: + # sometime there is a dblquote at the end only of the value + # because of old bug in previous version, fix for backward compatibility + if len(smpl_value) > 0 and smpl_value[-1] == '"': + smpl_value = smpl_value[:-1] + value = dblquote_value+smpl_value --- a/WampOptionsEditor.py Thu Nov 05 14:31:30 2020 +0100
+++ b/WampOptionsEditor.py Thu Nov 12 11:02:32 2020 +0100
@@ -5,7 +5,7 @@
from collections import namedtuple
-from OptionsParsing import ParseOptions, VARIABLETYPE
+from OptionsParsing import ParseOptions, VARIABLETYPE, GenOptions, OptionsType [ID_OPTIONSWIZARDDIALOG,ID_ONCHANGE,ID_OPTIONSTYPECHOICE,ID_SUBGROUPTEXT,ID_UNITTEXT,ID_VALUECHECKBOX,ID_MINSPIN,ID_MAXSPIN,ID_PRECISIONSPIN, ID_INITIALSPIN,ID_SCADACHECKBOX,ID_OTHERTEXT,ID_DESCRIPTION,ID_STATIC] = [wx.NewId() for _init_ctrls in range(14)]
@@ -220,28 +220,18 @@
- TypeSelected = self.OptionsTypeChoice.GetSelection()
- options = VARIABLETYPE[TypeSelected]
- if self.OnChangeCheckbox.GetValue():
- if self.ScadaCheckbox.GetValue():
- if self.StaticCheckbox.GetValue():
+ opts.variable_type_selection = max(self.OptionsTypeChoice.GetSelection(), 0) + opts.is_onchange = self.OnChangeCheckbox.GetValue() + opts.is_scada = self.ScadaCheckbox.GetValue() + opts.is_static = self.StaticCheckbox.GetValue() if self.MinSpin.IsEnabled():
- options += ' min="' + str(self.MinSpin.GetValue()) + '"'
- options += ' max="' + str(self.MaxSpin.GetValue()) + '"'
+ opts.min = self.MinSpin.GetValue() + opts.max = self.MaxSpin.GetValue() - if self.PrecisionSpin.GetValue() != 0:
- options += ' precision=' + str(self.PrecisionSpin.GetValue()) + '"'
+ opts.precision = self.PrecisionSpin.GetValue() for name, ctrl in [('subgroup', self.SubgroupText),
@@ -249,9 +239,10 @@
content = ctrl.GetValue().encode('ascii','ignore')
- options += ' ' + name + '="' + content.translate(sanitizer, eraser) + '"'
+ return GenOptions(opts) class WampOptionsCellControl(wx.PyControl):
@@ -301,6 +292,9 @@
def OnEditButtonClick(self, event):
# pop up the Duration Editor dialog
options = self.GetValue()
+ # backward compatibility dialog = WampOptionsEditor(self.parent, options)
answer = dialog.ShowModal()
opt = dialog.GetOptions()
@@ -327,7 +321,7 @@
class WampOptionsCellEditor(wx.grid.PyGridCellEditor):
- Grid cell editor that uses DurationCellControl to display an edit button.
+ Grid cell editor that uses WampOptionsCellControl to display an edit button. def __init__(self, table, row, col):